Commit 5619fd0b authored by Thomas Guillem's avatar Thomas Guillem Committed by Max Kellermann

android: Context: add GetAudioManager

parent 200258c7
...@@ -20,8 +20,11 @@ ...@@ -20,8 +20,11 @@
#include "Context.hxx" #include "Context.hxx"
#include "java/Class.hxx" #include "java/Class.hxx"
#include "java/File.hxx" #include "java/File.hxx"
#include "java/String.hxx"
#include "fs/AllocatedPath.hxx" #include "fs/AllocatedPath.hxx"
#include "AudioManager.hxx"
AllocatedPath AllocatedPath
Context::GetCacheDir(JNIEnv *env) const noexcept Context::GetCacheDir(JNIEnv *env) const noexcept
{ {
...@@ -40,3 +43,21 @@ Context::GetCacheDir(JNIEnv *env) const noexcept ...@@ -40,3 +43,21 @@ Context::GetCacheDir(JNIEnv *env) const noexcept
return Java::File::ToAbsolutePath(env, file); return Java::File::ToAbsolutePath(env, file);
} }
AudioManager *
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());
if (Java::DiscardException(env) || am == nullptr)
return nullptr;
return new AudioManager(env, am);
}
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include "java/Object.hxx" #include "java/Object.hxx"
class AllocatedPath; class AllocatedPath;
class AudioManager;
class Context : public Java::GlobalObject { class Context : public Java::GlobalObject {
public: public:
...@@ -31,6 +32,9 @@ public: ...@@ -31,6 +32,9 @@ public:
gcc_pure gcc_pure
AllocatedPath GetCacheDir(JNIEnv *env) const noexcept; AllocatedPath GetCacheDir(JNIEnv *env) const noexcept;
gcc_pure
AudioManager *GetAudioManager(JNIEnv *env) noexcept;
}; };
#endif #endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment