Loading core/jni/android_media_AudioSystem.cpp +31 −0 Original line number Diff line number Diff line Loading @@ -2032,6 +2032,35 @@ static jint android_media_AudioSystem_get_FCC_8(JNIEnv *env, jobject thiz) { return FCC_8; } static jint android_media_AudioSystem_setAssistantUid(JNIEnv *env, jobject thiz, jint uid) { status_t status = AudioSystem::setAssistantUid(uid); return (jint)nativeToJavaStatus(status); } static jint android_media_AudioSystem_setA11yServicesUids(JNIEnv *env, jobject thiz, jintArray uids) { std::vector<uid_t> nativeUidsVector; if (uids != nullptr) { jsize len = env->GetArrayLength(uids); if (len > 0) { int *nativeUids = nullptr; nativeUids = env->GetIntArrayElements(uids, 0); if (nativeUids != nullptr) { for (size_t i = 0; i < len; i++) { nativeUidsVector.push_back(nativeUids[i]); } env->ReleaseIntArrayElements(uids, nativeUids, 0); } } } status_t status = AudioSystem::setA11yServicesUids(nativeUidsVector); return (jint)nativeToJavaStatus(status); } // ---------------------------------------------------------------------------- static const JNINativeMethod gMethods[] = { Loading Loading @@ -2092,6 +2121,8 @@ static const JNINativeMethod gMethods[] = { {"getMicrophones", "(Ljava/util/ArrayList;)I", (void *)android_media_AudioSystem_getMicrophones}, {"getSurroundFormats", "(Ljava/util/Map;Z)I", (void *)android_media_AudioSystem_getSurroundFormats}, {"setSurroundFormatEnabled", "(IZ)I", (void *)android_media_AudioSystem_setSurroundFormatEnabled}, {"setAssistantUid", "(I)I", (void *)android_media_AudioSystem_setAssistantUid}, {"setA11yServicesUids", "([I)I", (void *)android_media_AudioSystem_setA11yServicesUids}, }; static const JNINativeMethod gEventHandlerMethods[] = { Loading media/java/android/media/AudioSystem.java +9 −0 Original line number Diff line number Diff line Loading @@ -924,6 +924,15 @@ public class AudioSystem public static native int setSurroundFormatEnabled(int audioFormat, boolean enabled); /** * Communicate UID of active assistant to audio policy service. */ public static native int setAssistantUid(int uid); /** * Communicate UIDs of active accessibility services to audio policy service. */ public static native int setA11yServicesUids(int[] uids); // Items shared with audio service /** Loading services/core/java/com/android/server/audio/AudioService.java +46 −0 Original line number Diff line number Diff line Loading @@ -649,6 +649,9 @@ public class AudioService extends IAudioService.Stub private String mEnabledSurroundFormats; private boolean mSurroundModeChanged; @GuardedBy("mSettingsLock") private int mAssistantUid; // Intent "extra" data keys. public static final String CONNECT_INTENT_KEY_PORT_NAME = "portName"; public static final String CONNECT_INTENT_KEY_STATE = "state"; Loading Loading @@ -1079,6 +1082,10 @@ public class AudioService extends IAudioService.Stub AudioSystem.setForceUse(AudioSystem.FOR_DOCK, forDock); sendEncodedSurroundMode(mContentResolver, "onAudioServerDied"); sendEnabledSurroundFormats(mContentResolver, true); updateAssistantUId(true); } synchronized (mAccessibilityServiceUidsLock) { AudioSystem.setA11yServicesUids(mAccessibilityServiceUids); } synchronized (mHdmiClientLock) { if (mHdmiManager != null && mHdmiTvClient != null) { Loading Loading @@ -1404,6 +1411,39 @@ public class AudioService extends IAudioService.Stub } } @GuardedBy("mSettingsLock") private void updateAssistantUId(boolean forceUpdate) { int assistantUid = 0; // Consider assistants in the following order of priority: // 1) voice interaction service // 2) assistant String assistantName = Settings.Secure.getStringForUser( mContentResolver, Settings.Secure.VOICE_INTERACTION_SERVICE, UserHandle.USER_CURRENT); if (TextUtils.isEmpty(assistantName)) { assistantName = Settings.Secure.getStringForUser( mContentResolver, Settings.Secure.ASSISTANT, UserHandle.USER_CURRENT); } if (!TextUtils.isEmpty(assistantName)) { String packageName = ComponentName.unflattenFromString(assistantName).getPackageName(); if (!TextUtils.isEmpty(packageName)) { try { assistantUid = mContext.getPackageManager().getPackageUid(packageName, 0); } catch (PackageManager.NameNotFoundException e) { Log.e(TAG, "updateAssistantUId() could not find UID for package: " + packageName); } } } if (assistantUid != mAssistantUid || forceUpdate) { AudioSystem.setAssistantUid(assistantUid); mAssistantUid = assistantUid; } } private void readPersistedSettings() { final ContentResolver cr = mContentResolver; Loading Loading @@ -1447,6 +1487,7 @@ public class AudioService extends IAudioService.Stub readDockAudioSettings(cr); sendEncodedSurroundMode(cr, "readPersistedSettings"); sendEnabledSurroundFormats(cr, true); updateAssistantUId(true); } mMuteAffectedStreams = System.getIntForUser(cr, Loading Loading @@ -5811,6 +5852,9 @@ public class AudioService extends IAudioService.Stub mContentResolver, Settings.Global.ENCODED_SURROUND_OUTPUT_ENABLED_FORMATS); mContentResolver.registerContentObserver(Settings.Global.getUriFor( Settings.Global.ENCODED_SURROUND_OUTPUT_ENABLED_FORMATS), false, this); mContentResolver.registerContentObserver(Settings.Secure.getUriFor( Settings.Secure.VOICE_INTERACTION_SERVICE), false, this); } @Override Loading @@ -5832,6 +5876,7 @@ public class AudioService extends IAudioService.Stub updateMasterMono(mContentResolver); updateEncodedSurroundOutput(); sendEnabledSurroundFormats(mContentResolver, mSurroundModeChanged); updateAssistantUId(false); } } Loading Loading @@ -7658,6 +7703,7 @@ public class AudioService extends IAudioService.Stub mAccessibilityServiceUids = uids.toArray(); } } AudioSystem.setA11yServicesUids(mAccessibilityServiceUids); } } } Loading Loading
core/jni/android_media_AudioSystem.cpp +31 −0 Original line number Diff line number Diff line Loading @@ -2032,6 +2032,35 @@ static jint android_media_AudioSystem_get_FCC_8(JNIEnv *env, jobject thiz) { return FCC_8; } static jint android_media_AudioSystem_setAssistantUid(JNIEnv *env, jobject thiz, jint uid) { status_t status = AudioSystem::setAssistantUid(uid); return (jint)nativeToJavaStatus(status); } static jint android_media_AudioSystem_setA11yServicesUids(JNIEnv *env, jobject thiz, jintArray uids) { std::vector<uid_t> nativeUidsVector; if (uids != nullptr) { jsize len = env->GetArrayLength(uids); if (len > 0) { int *nativeUids = nullptr; nativeUids = env->GetIntArrayElements(uids, 0); if (nativeUids != nullptr) { for (size_t i = 0; i < len; i++) { nativeUidsVector.push_back(nativeUids[i]); } env->ReleaseIntArrayElements(uids, nativeUids, 0); } } } status_t status = AudioSystem::setA11yServicesUids(nativeUidsVector); return (jint)nativeToJavaStatus(status); } // ---------------------------------------------------------------------------- static const JNINativeMethod gMethods[] = { Loading Loading @@ -2092,6 +2121,8 @@ static const JNINativeMethod gMethods[] = { {"getMicrophones", "(Ljava/util/ArrayList;)I", (void *)android_media_AudioSystem_getMicrophones}, {"getSurroundFormats", "(Ljava/util/Map;Z)I", (void *)android_media_AudioSystem_getSurroundFormats}, {"setSurroundFormatEnabled", "(IZ)I", (void *)android_media_AudioSystem_setSurroundFormatEnabled}, {"setAssistantUid", "(I)I", (void *)android_media_AudioSystem_setAssistantUid}, {"setA11yServicesUids", "([I)I", (void *)android_media_AudioSystem_setA11yServicesUids}, }; static const JNINativeMethod gEventHandlerMethods[] = { Loading
media/java/android/media/AudioSystem.java +9 −0 Original line number Diff line number Diff line Loading @@ -924,6 +924,15 @@ public class AudioSystem public static native int setSurroundFormatEnabled(int audioFormat, boolean enabled); /** * Communicate UID of active assistant to audio policy service. */ public static native int setAssistantUid(int uid); /** * Communicate UIDs of active accessibility services to audio policy service. */ public static native int setA11yServicesUids(int[] uids); // Items shared with audio service /** Loading
services/core/java/com/android/server/audio/AudioService.java +46 −0 Original line number Diff line number Diff line Loading @@ -649,6 +649,9 @@ public class AudioService extends IAudioService.Stub private String mEnabledSurroundFormats; private boolean mSurroundModeChanged; @GuardedBy("mSettingsLock") private int mAssistantUid; // Intent "extra" data keys. public static final String CONNECT_INTENT_KEY_PORT_NAME = "portName"; public static final String CONNECT_INTENT_KEY_STATE = "state"; Loading Loading @@ -1079,6 +1082,10 @@ public class AudioService extends IAudioService.Stub AudioSystem.setForceUse(AudioSystem.FOR_DOCK, forDock); sendEncodedSurroundMode(mContentResolver, "onAudioServerDied"); sendEnabledSurroundFormats(mContentResolver, true); updateAssistantUId(true); } synchronized (mAccessibilityServiceUidsLock) { AudioSystem.setA11yServicesUids(mAccessibilityServiceUids); } synchronized (mHdmiClientLock) { if (mHdmiManager != null && mHdmiTvClient != null) { Loading Loading @@ -1404,6 +1411,39 @@ public class AudioService extends IAudioService.Stub } } @GuardedBy("mSettingsLock") private void updateAssistantUId(boolean forceUpdate) { int assistantUid = 0; // Consider assistants in the following order of priority: // 1) voice interaction service // 2) assistant String assistantName = Settings.Secure.getStringForUser( mContentResolver, Settings.Secure.VOICE_INTERACTION_SERVICE, UserHandle.USER_CURRENT); if (TextUtils.isEmpty(assistantName)) { assistantName = Settings.Secure.getStringForUser( mContentResolver, Settings.Secure.ASSISTANT, UserHandle.USER_CURRENT); } if (!TextUtils.isEmpty(assistantName)) { String packageName = ComponentName.unflattenFromString(assistantName).getPackageName(); if (!TextUtils.isEmpty(packageName)) { try { assistantUid = mContext.getPackageManager().getPackageUid(packageName, 0); } catch (PackageManager.NameNotFoundException e) { Log.e(TAG, "updateAssistantUId() could not find UID for package: " + packageName); } } } if (assistantUid != mAssistantUid || forceUpdate) { AudioSystem.setAssistantUid(assistantUid); mAssistantUid = assistantUid; } } private void readPersistedSettings() { final ContentResolver cr = mContentResolver; Loading Loading @@ -1447,6 +1487,7 @@ public class AudioService extends IAudioService.Stub readDockAudioSettings(cr); sendEncodedSurroundMode(cr, "readPersistedSettings"); sendEnabledSurroundFormats(cr, true); updateAssistantUId(true); } mMuteAffectedStreams = System.getIntForUser(cr, Loading Loading @@ -5811,6 +5852,9 @@ public class AudioService extends IAudioService.Stub mContentResolver, Settings.Global.ENCODED_SURROUND_OUTPUT_ENABLED_FORMATS); mContentResolver.registerContentObserver(Settings.Global.getUriFor( Settings.Global.ENCODED_SURROUND_OUTPUT_ENABLED_FORMATS), false, this); mContentResolver.registerContentObserver(Settings.Secure.getUriFor( Settings.Secure.VOICE_INTERACTION_SERVICE), false, this); } @Override Loading @@ -5832,6 +5876,7 @@ public class AudioService extends IAudioService.Stub updateMasterMono(mContentResolver); updateEncodedSurroundOutput(); sendEnabledSurroundFormats(mContentResolver, mSurroundModeChanged); updateAssistantUId(false); } } Loading Loading @@ -7658,6 +7703,7 @@ public class AudioService extends IAudioService.Stub mAccessibilityServiceUids = uids.toArray(); } } AudioSystem.setA11yServicesUids(mAccessibilityServiceUids); } } } Loading