android: Context: add GetAudioManager
This commit is contained in:
		
				
					committed by
					
						
						Max Kellermann
					
				
			
			
				
	
			
			
			
						parent
						
							200258c7c3
						
					
				
				
					commit
					5619fd0bba
				
			@@ -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
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	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 @@
 | 
				
			|||||||
#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:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	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
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user