Added logic to reset assistant UIDs on audio crash
On native audioserver recovery the assistant UIDs will reset to an empty list, followed by adding the current role or setting holder for assistant. Also added a settings lock around the update assistant method. Added remove assistant UID for reset hotword detection connection. Bug: 222584963 Bug: 222777782 Test: atest VoiceInteractionTest Test: atest AudioManagerTest Test: atest HotwordDetectionServiceBasicTest Test: kill audio server and verify assistant UIDs is not increasing unbounded. Test: adb shell cmd voiceinteraction restart-detection, verify assistant UIDs list is not increasing unbounded. Change-Id: I475bfee1f0bcd56a750e4fef8aa8a2b93fe090fc
This commit is contained in:
@@ -8393,6 +8393,12 @@ public class AudioManager {
|
||||
* {@link #addAssistantServicesUids(int[])} and not yet removed with
|
||||
* {@link #removeAssistantServicesUids(int[])}
|
||||
*
|
||||
* <p> Note that during native audioserver crash and after boot up the list of assistant
|
||||
* UIDs will be reset to an empty list (i.e. no UID will be considered as assistant)
|
||||
* Just after user switch, the list of assistant will also reset to empty.
|
||||
* In both cases,The component's UID of the assistiant role or assistant setting will be
|
||||
* automitically added to the list by the audio service.
|
||||
*
|
||||
* @return array of assistants UIDs
|
||||
*
|
||||
* @hide
|
||||
|
||||
@@ -1325,14 +1325,18 @@ public class AudioService extends IAudioService.Stub
|
||||
mRm = (RoleManager) mContext.getSystemService(Context.ROLE_SERVICE);
|
||||
if (mRm != null) {
|
||||
mRm.addOnRoleHoldersChangedListenerAsUser(mExecutor, this, UserHandle.ALL);
|
||||
updateAssistantUId(true);
|
||||
synchronized (mSettingsLock) {
|
||||
updateAssistantUIdLocked(/* forceUpdate= */ true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRoleHoldersChanged(@NonNull String roleName, @NonNull UserHandle user) {
|
||||
if (RoleManager.ROLE_ASSISTANT.equals(roleName)) {
|
||||
updateAssistantUId(false);
|
||||
synchronized (mSettingsLock) {
|
||||
updateAssistantUIdLocked(/* forceUpdate= */ false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1431,7 +1435,7 @@ public class AudioService extends IAudioService.Stub
|
||||
sendEncodedSurroundMode(mContentResolver, "onAudioServerDied");
|
||||
sendEnabledSurroundFormats(mContentResolver, true);
|
||||
AudioSystem.setRttEnabled(mRttEnabled);
|
||||
updateAssistantServicesUidsLocked();
|
||||
resetAssistantServicesUidsLocked();
|
||||
}
|
||||
|
||||
synchronized (mAccessibilityServiceUidsLock) {
|
||||
@@ -1559,6 +1563,12 @@ public class AudioService extends IAudioService.Stub
|
||||
}
|
||||
}
|
||||
|
||||
@GuardedBy("mSettingsLock")
|
||||
private void resetAssistantServicesUidsLocked() {
|
||||
mAssistantUids.clear();
|
||||
updateAssistantUIdLocked(/* forceUpdate= */ true);
|
||||
}
|
||||
|
||||
@GuardedBy("mSettingsLock")
|
||||
private void updateAssistantServicesUidsLocked() {
|
||||
int[] assistantUids = mAssistantUids.stream().mapToInt(Integer::intValue).toArray();
|
||||
@@ -2343,7 +2353,7 @@ public class AudioService extends IAudioService.Stub
|
||||
}
|
||||
|
||||
@GuardedBy("mSettingsLock")
|
||||
private void updateAssistantUId(boolean forceUpdate) {
|
||||
private void updateAssistantUIdLocked(boolean forceUpdate) {
|
||||
int assistantUid = INVALID_UID;
|
||||
// Consider assistants in the following order of priority:
|
||||
// 1) apk in assistant role
|
||||
@@ -2441,7 +2451,7 @@ public class AudioService extends IAudioService.Stub
|
||||
readDockAudioSettings(cr);
|
||||
sendEncodedSurroundMode(cr, "readPersistedSettings");
|
||||
sendEnabledSurroundFormats(cr, true);
|
||||
updateAssistantUId(true);
|
||||
updateAssistantUIdLocked(/* forceUpdate= */ true);
|
||||
resetActiveAssistantUidsLocked();
|
||||
AudioSystem.setRttEnabled(mRttEnabled);
|
||||
}
|
||||
@@ -8153,7 +8163,7 @@ public class AudioService extends IAudioService.Stub
|
||||
updateMasterBalance(mContentResolver);
|
||||
updateEncodedSurroundOutput();
|
||||
sendEnabledSurroundFormats(mContentResolver, mSurroundModeChanged);
|
||||
updateAssistantUId(false);
|
||||
updateAssistantUIdLocked(/* forceUpdate= */ false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -679,6 +679,7 @@ final class HotwordDetectionConnection {
|
||||
private void restartProcessLocked() {
|
||||
Slog.v(TAG, "Restarting hotword detection process");
|
||||
ServiceConnection oldConnection = mRemoteHotwordDetectionService;
|
||||
HotwordDetectionServiceIdentity previousIdentity = mIdentity;
|
||||
|
||||
// TODO(volnov): this can be done after connect() has been successful.
|
||||
if (mValidatingDspTrigger) {
|
||||
@@ -722,6 +723,9 @@ final class HotwordDetectionConnection {
|
||||
}
|
||||
oldConnection.ignoreConnectionStatusEvents();
|
||||
oldConnection.unbind();
|
||||
if (previousIdentity != null) {
|
||||
removeServiceUidForAudioPolicy(previousIdentity.getIsolatedUid());
|
||||
}
|
||||
}
|
||||
|
||||
static final class SoundTriggerCallback extends IRecognitionStatusCallback.Stub {
|
||||
|
||||
Reference in New Issue
Block a user