Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
b90e32fe
Commit
b90e32fe
authored
Aug 18, 2022
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Android/Context: look up methods once during startup
parent
1f4df2a6
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
18 deletions
+29
-18
Main.cxx
src/Main.cxx
+3
-0
Context.cxx
src/android/Context.cxx
+20
-18
Context.hxx
src/android/Context.hxx
+6
-0
No files found.
src/Main.cxx
View file @
b90e32fe
...
...
@@ -614,9 +614,12 @@ Java_org_musicpd_Bridge_run(JNIEnv *env, jclass, jobject _context, jobject _logL
Java
::
Init
(
env
);
Java
::
Object
::
Initialise
(
env
);
Java
::
File
::
Initialise
(
env
);
Environment
::
Initialise
(
env
);
AtScopeExit
(
env
)
{
Environment
::
Deinitialise
(
env
);
};
Context
::
Initialise
(
env
);
context
=
new
Context
(
env
,
_context
);
AtScopeExit
()
{
delete
context
;
};
...
...
src/android/Context.cxx
View file @
b90e32fe
...
...
@@ -26,19 +26,31 @@
#include "AudioManager.hxx"
static
jmethodID
getExternalFilesDir_method
,
getCacheDir_method
,
getSystemService_method
;
void
Context
::
Initialise
(
JNIEnv
*
env
)
noexcept
{
Java
::
Class
cls
{
env
,
"android/content/Context"
};
getExternalFilesDir_method
=
env
->
GetMethodID
(
cls
,
"getExternalFilesDir"
,
"(Ljava/lang/String;)Ljava/io/File;"
);
getCacheDir_method
=
env
->
GetMethodID
(
cls
,
"getCacheDir"
,
"()Ljava/io/File;"
);
getSystemService_method
=
env
->
GetMethodID
(
cls
,
"getSystemService"
,
"(Ljava/lang/String;)Ljava/lang/Object;"
);
}
AllocatedPath
Context
::
GetExternalFilesDir
(
JNIEnv
*
env
,
const
char
*
_type
)
noexcept
{
assert
(
_type
!=
nullptr
);
Java
::
Class
cls
{
env
,
env
->
GetObjectClass
(
Get
())};
jmethodID
method
=
env
->
GetMethodID
(
cls
,
"getExternalFilesDir"
,
"(Ljava/lang/String;)Ljava/io/File;"
);
assert
(
method
);
Java
::
String
type
{
env
,
_type
};
jobject
file
=
env
->
CallObjectMethod
(
Get
(),
method
,
type
.
Get
());
jobject
file
=
env
->
CallObjectMethod
(
Get
(),
getExternalFilesDir_
method
,
type
.
Get
());
if
(
Java
::
DiscardException
(
env
)
||
file
==
nullptr
)
return
nullptr
;
...
...
@@ -50,12 +62,7 @@ Context::GetCacheDir(JNIEnv *env) const noexcept
{
assert
(
env
!=
nullptr
);
Java
::
Class
cls
(
env
,
env
->
GetObjectClass
(
Get
()));
jmethodID
method
=
env
->
GetMethodID
(
cls
,
"getCacheDir"
,
"()Ljava/io/File;"
);
assert
(
method
);
jobject
file
=
env
->
CallObjectMethod
(
Get
(),
method
);
jobject
file
=
env
->
CallObjectMethod
(
Get
(),
getCacheDir_method
);
if
(
Java
::
DiscardException
(
env
)
||
file
==
nullptr
)
return
nullptr
;
...
...
@@ -67,13 +74,8 @@ Context::GetAudioManager(JNIEnv *env) noexcept
{
assert
(
env
!=
nullptr
);
Java
::
Class
cls
(
env
,
env
->
GetObjectClass
(
Get
()));
jmethodID
method
=
env
->
GetMethodID
(
cls
,
"getSystemService"
,
"(Ljava/lang/String;)Ljava/lang/Object;"
);
assert
(
method
);
Java
::
String
name
(
env
,
"audio"
);
jobject
am
=
env
->
CallObjectMethod
(
Get
(),
method
,
name
.
Get
());
jobject
am
=
env
->
CallObjectMethod
(
Get
(),
getSystemService_
method
,
name
.
Get
());
if
(
Java
::
DiscardException
(
env
)
||
am
==
nullptr
)
return
nullptr
;
...
...
src/android/Context.hxx
View file @
b90e32fe
...
...
@@ -27,6 +27,12 @@ class AudioManager;
class
Context
:
public
Java
::
GlobalObject
{
public
:
/**
* Global initialisation. Looks up the methods of the
* Context Java class.
*/
static
void
Initialise
(
JNIEnv
*
env
)
noexcept
;
Context
(
JNIEnv
*
env
,
jobject
obj
)
noexcept
:
Java
::
GlobalObject
(
env
,
obj
)
{}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment