Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a6a40124 authored by Oscar Azucena's avatar Oscar Azucena Committed by Automerger Merge Worker
Browse files

Merge "Added logic to reset assistant UIDs on audio crash" into tm-dev am: cb7a1fe9

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/17078332

Change-Id: I466c8a8a252036fa625d2fc6973fc1530068335b
parents 85ce2b31 cb7a1fe9
Loading
Loading
Loading
Loading
+6 −0
Original line number Original line Diff line number Diff line
@@ -8402,6 +8402,12 @@ public class AudioManager {
     * {@link #addAssistantServicesUids(int[])} and not yet removed with
     * {@link #addAssistantServicesUids(int[])} and not yet removed with
     * {@link #removeAssistantServicesUids(int[])}
     * {@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
     * @return array of assistants UIDs
     *
     *
     * @hide
     * @hide
+16 −6
Original line number Original line Diff line number Diff line
@@ -1368,14 +1368,18 @@ public class AudioService extends IAudioService.Stub
            mRm = (RoleManager) mContext.getSystemService(Context.ROLE_SERVICE);
            mRm = (RoleManager) mContext.getSystemService(Context.ROLE_SERVICE);
            if (mRm != null) {
            if (mRm != null) {
                mRm.addOnRoleHoldersChangedListenerAsUser(mExecutor, this, UserHandle.ALL);
                mRm.addOnRoleHoldersChangedListenerAsUser(mExecutor, this, UserHandle.ALL);
                updateAssistantUId(true);
                synchronized (mSettingsLock) {
                    updateAssistantUIdLocked(/* forceUpdate= */ true);
                }
            }
            }
        }
        }


        @Override
        @Override
        public void onRoleHoldersChanged(@NonNull String roleName, @NonNull UserHandle user) {
        public void onRoleHoldersChanged(@NonNull String roleName, @NonNull UserHandle user) {
            if (RoleManager.ROLE_ASSISTANT.equals(roleName)) {
            if (RoleManager.ROLE_ASSISTANT.equals(roleName)) {
                updateAssistantUId(false);
                synchronized (mSettingsLock) {
                    updateAssistantUIdLocked(/* forceUpdate= */ false);
                }
            }
            }
        }
        }


@@ -1474,7 +1478,7 @@ public class AudioService extends IAudioService.Stub
            sendEncodedSurroundMode(mContentResolver, "onAudioServerDied");
            sendEncodedSurroundMode(mContentResolver, "onAudioServerDied");
            sendEnabledSurroundFormats(mContentResolver, true);
            sendEnabledSurroundFormats(mContentResolver, true);
            AudioSystem.setRttEnabled(mRttEnabled);
            AudioSystem.setRttEnabled(mRttEnabled);
            updateAssistantServicesUidsLocked();
            resetAssistantServicesUidsLocked();
        }
        }


        synchronized (mAccessibilityServiceUidsLock) {
        synchronized (mAccessibilityServiceUidsLock) {
@@ -1602,6 +1606,12 @@ public class AudioService extends IAudioService.Stub
        }
        }
    }
    }


    @GuardedBy("mSettingsLock")
    private void resetAssistantServicesUidsLocked() {
        mAssistantUids.clear();
        updateAssistantUIdLocked(/* forceUpdate= */ true);
    }

    @GuardedBy("mSettingsLock")
    @GuardedBy("mSettingsLock")
    private void updateAssistantServicesUidsLocked() {
    private void updateAssistantServicesUidsLocked() {
        int[] assistantUids = mAssistantUids.stream().mapToInt(Integer::intValue).toArray();
        int[] assistantUids = mAssistantUids.stream().mapToInt(Integer::intValue).toArray();
@@ -2386,7 +2396,7 @@ public class AudioService extends IAudioService.Stub
    }
    }


    @GuardedBy("mSettingsLock")
    @GuardedBy("mSettingsLock")
    private void updateAssistantUId(boolean forceUpdate) {
    private void updateAssistantUIdLocked(boolean forceUpdate) {
        int assistantUid = INVALID_UID;
        int assistantUid = INVALID_UID;
        // Consider assistants in the following order of priority:
        // Consider assistants in the following order of priority:
        // 1) apk in assistant role
        // 1) apk in assistant role
@@ -2484,7 +2494,7 @@ public class AudioService extends IAudioService.Stub
            readDockAudioSettings(cr);
            readDockAudioSettings(cr);
            sendEncodedSurroundMode(cr, "readPersistedSettings");
            sendEncodedSurroundMode(cr, "readPersistedSettings");
            sendEnabledSurroundFormats(cr, true);
            sendEnabledSurroundFormats(cr, true);
            updateAssistantUId(true);
            updateAssistantUIdLocked(/* forceUpdate= */ true);
            resetActiveAssistantUidsLocked();
            resetActiveAssistantUidsLocked();
            AudioSystem.setRttEnabled(mRttEnabled);
            AudioSystem.setRttEnabled(mRttEnabled);
        }
        }
@@ -8317,7 +8327,7 @@ public class AudioService extends IAudioService.Stub
                updateMasterBalance(mContentResolver);
                updateMasterBalance(mContentResolver);
                updateEncodedSurroundOutput();
                updateEncodedSurroundOutput();
                sendEnabledSurroundFormats(mContentResolver, mSurroundModeChanged);
                sendEnabledSurroundFormats(mContentResolver, mSurroundModeChanged);
                updateAssistantUId(false);
                updateAssistantUIdLocked(/* forceUpdate= */ false);
            }
            }
        }
        }


+4 −0
Original line number Original line Diff line number Diff line
@@ -679,6 +679,7 @@ final class HotwordDetectionConnection {
    private void restartProcessLocked() {
    private void restartProcessLocked() {
        Slog.v(TAG, "Restarting hotword detection process");
        Slog.v(TAG, "Restarting hotword detection process");
        ServiceConnection oldConnection = mRemoteHotwordDetectionService;
        ServiceConnection oldConnection = mRemoteHotwordDetectionService;
        HotwordDetectionServiceIdentity previousIdentity = mIdentity;


        // TODO(volnov): this can be done after connect() has been successful.
        // TODO(volnov): this can be done after connect() has been successful.
        if (mValidatingDspTrigger) {
        if (mValidatingDspTrigger) {
@@ -722,6 +723,9 @@ final class HotwordDetectionConnection {
        }
        }
        oldConnection.ignoreConnectionStatusEvents();
        oldConnection.ignoreConnectionStatusEvents();
        oldConnection.unbind();
        oldConnection.unbind();
        if (previousIdentity != null) {
            removeServiceUidForAudioPolicy(previousIdentity.getIsolatedUid());
        }
    }
    }


    static final class SoundTriggerCallback extends IRecognitionStatusCallback.Stub {
    static final class SoundTriggerCallback extends IRecognitionStatusCallback.Stub {