Loading services/core/java/com/android/server/audio/AudioService.java +67 −13 Original line number Diff line number Diff line Loading @@ -36,6 +36,8 @@ import android.app.AppGlobals; import android.app.AppOpsManager; import android.app.IUidObserver; import android.app.NotificationManager; import android.app.role.OnRoleHoldersChangedListener; import android.app.role.RoleManager; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothHeadset; Loading Loading @@ -158,6 +160,7 @@ import java.util.Iterator; import java.util.List; import java.util.NoSuchElementException; import java.util.Objects; import java.util.concurrent.Executor; /** * The implementation of the volume manager service. Loading Loading @@ -889,9 +892,48 @@ public class AudioService extends IAudioService.Stub 0 : SAFE_VOLUME_CONFIGURE_TIMEOUT_MS); initA11yMonitoring(); mRoleObserver = new RoleObserver(); mRoleObserver.register(); onIndicateSystemReady(); } RoleObserver mRoleObserver; class RoleObserver implements OnRoleHoldersChangedListener { private RoleManager mRm; private final Executor mExecutor; RoleObserver() { mExecutor = mContext.getMainExecutor(); } public void register() { mRm = (RoleManager) mContext.getSystemService(Context.ROLE_SERVICE); if (mRm != null) { mRm.addOnRoleHoldersChangedListenerAsUser(mExecutor, this, UserHandle.ALL); updateAssistantUId(true); } } @Override public void onRoleHoldersChanged(@NonNull String roleName, @NonNull UserHandle user) { if (RoleManager.ROLE_ASSISTANT.equals(roleName)) { updateAssistantUId(false); } } public String getAssistantRoleHolder() { String assitantPackage = ""; if (mRm != null) { List<String> assistants = mRm.getRoleHolders(RoleManager.ROLE_ASSISTANT); assitantPackage = assistants.size() == 0 ? "" : assistants.get(0); } return assitantPackage; } } void onIndicateSystemReady() { if (AudioSystem.systemReady() == AudioSystem.SUCCESS) { return; Loading Loading @@ -1391,8 +1433,15 @@ public class AudioService extends IAudioService.Stub int assistantUid = 0; // Consider assistants in the following order of priority: // 1) voice interaction service // 2) assistant // 1) apk in assistant role // 2) voice interaction service // 3) assistant service String packageName = ""; if (mRoleObserver != null) { packageName = mRoleObserver.getAssistantRoleHolder(); } if (TextUtils.isEmpty(packageName)) { String assistantName = Settings.Secure.getStringForUser( mContentResolver, Settings.Secure.VOICE_INTERACTION_SERVICE, UserHandle.USER_CURRENT); Loading @@ -1402,10 +1451,15 @@ public class AudioService extends IAudioService.Stub Settings.Secure.ASSISTANT, UserHandle.USER_CURRENT); } if (!TextUtils.isEmpty(assistantName)) { String packageName = ComponentName.unflattenFromString(assistantName).getPackageName(); packageName = ComponentName.unflattenFromString(assistantName).getPackageName(); } } if (!TextUtils.isEmpty(packageName)) { PackageManager pm = mContext.getPackageManager(); if (pm.checkPermission(Manifest.permission.CAPTURE_AUDIO_HOTWORD, packageName) == PackageManager.PERMISSION_GRANTED) { try { assistantUid = mContext.getPackageManager().getPackageUid(packageName, 0); assistantUid = pm.getPackageUid(packageName, 0); } catch (PackageManager.NameNotFoundException e) { Log.e(TAG, "updateAssistantUId() could not find UID for package: " + packageName); Loading Loading
services/core/java/com/android/server/audio/AudioService.java +67 −13 Original line number Diff line number Diff line Loading @@ -36,6 +36,8 @@ import android.app.AppGlobals; import android.app.AppOpsManager; import android.app.IUidObserver; import android.app.NotificationManager; import android.app.role.OnRoleHoldersChangedListener; import android.app.role.RoleManager; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothHeadset; Loading Loading @@ -158,6 +160,7 @@ import java.util.Iterator; import java.util.List; import java.util.NoSuchElementException; import java.util.Objects; import java.util.concurrent.Executor; /** * The implementation of the volume manager service. Loading Loading @@ -889,9 +892,48 @@ public class AudioService extends IAudioService.Stub 0 : SAFE_VOLUME_CONFIGURE_TIMEOUT_MS); initA11yMonitoring(); mRoleObserver = new RoleObserver(); mRoleObserver.register(); onIndicateSystemReady(); } RoleObserver mRoleObserver; class RoleObserver implements OnRoleHoldersChangedListener { private RoleManager mRm; private final Executor mExecutor; RoleObserver() { mExecutor = mContext.getMainExecutor(); } public void register() { mRm = (RoleManager) mContext.getSystemService(Context.ROLE_SERVICE); if (mRm != null) { mRm.addOnRoleHoldersChangedListenerAsUser(mExecutor, this, UserHandle.ALL); updateAssistantUId(true); } } @Override public void onRoleHoldersChanged(@NonNull String roleName, @NonNull UserHandle user) { if (RoleManager.ROLE_ASSISTANT.equals(roleName)) { updateAssistantUId(false); } } public String getAssistantRoleHolder() { String assitantPackage = ""; if (mRm != null) { List<String> assistants = mRm.getRoleHolders(RoleManager.ROLE_ASSISTANT); assitantPackage = assistants.size() == 0 ? "" : assistants.get(0); } return assitantPackage; } } void onIndicateSystemReady() { if (AudioSystem.systemReady() == AudioSystem.SUCCESS) { return; Loading Loading @@ -1391,8 +1433,15 @@ public class AudioService extends IAudioService.Stub int assistantUid = 0; // Consider assistants in the following order of priority: // 1) voice interaction service // 2) assistant // 1) apk in assistant role // 2) voice interaction service // 3) assistant service String packageName = ""; if (mRoleObserver != null) { packageName = mRoleObserver.getAssistantRoleHolder(); } if (TextUtils.isEmpty(packageName)) { String assistantName = Settings.Secure.getStringForUser( mContentResolver, Settings.Secure.VOICE_INTERACTION_SERVICE, UserHandle.USER_CURRENT); Loading @@ -1402,10 +1451,15 @@ public class AudioService extends IAudioService.Stub Settings.Secure.ASSISTANT, UserHandle.USER_CURRENT); } if (!TextUtils.isEmpty(assistantName)) { String packageName = ComponentName.unflattenFromString(assistantName).getPackageName(); packageName = ComponentName.unflattenFromString(assistantName).getPackageName(); } } if (!TextUtils.isEmpty(packageName)) { PackageManager pm = mContext.getPackageManager(); if (pm.checkPermission(Manifest.permission.CAPTURE_AUDIO_HOTWORD, packageName) == PackageManager.PERMISSION_GRANTED) { try { assistantUid = mContext.getPackageManager().getPackageUid(packageName, 0); assistantUid = pm.getPackageUid(packageName, 0); } catch (PackageManager.NameNotFoundException e) { Log.e(TAG, "updateAssistantUId() could not find UID for package: " + packageName); Loading