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

Commit 8d5cf40e authored by Felipe Leme's avatar Felipe Leme
Browse files

Further fixes on VIMS.onPreCreatedUserConversion()

Previously, when onRoleHoldersChanged() was called in a pre-created
user, VoiceInteractionManagerService (A.K.A. VIMS) would store that
user id and call the method again when the pre-converted user is
converted to a real user (on onPreCreatedUserConversion()), as the
assistant role holders is not available for pre-created users.

But if the system restarts between the user pre-creation and
conversion, onPreCreatedUserConversion() would log a warning and
do nothing.

So, this CL gets rids of the "save the user id" part, and simply
re-call onRoleHoldersChanged() whenever a pre-created user is
converted.

Test: manual verification on automotive builds
Fixes: 242254421

Merged-In: Id933b2bc4f887da8b2f4959955bd174ed5879a47
Change-Id: Id933b2bc4f887da8b2f4959955bd174ed5879a47
(cherry picked from commit 63da68c1)
parent bff2fa5f
Loading
Loading
Loading
Loading
+19 −25
Original line number Diff line number Diff line
@@ -135,9 +135,6 @@ public class VoiceInteractionManagerService extends SystemService {
    private final RemoteCallbackList<IVoiceInteractionSessionListener>
            mVoiceInteractionSessionListeners = new RemoteCallbackList<>();

    // TODO(b/226201975): remove once RoleService supports pre-created users
    private final ArrayList<UserHandle> mIgnoredPreCreatedUsers = new ArrayList<>();

    public VoiceInteractionManagerService(Context context) {
        super(context);
        mContext = context;
@@ -305,25 +302,15 @@ public class VoiceInteractionManagerService extends SystemService {
            return hotwordDetectionConnection.mIdentity;
        }

        // TODO(b/226201975): remove this method once RoleService supports pre-created users
        @Override
        public void onPreCreatedUserConversion(int userId) {
            Slogf.d(TAG, "onPreCreatedUserConversion(%d)", userId);

            for (int i = 0; i < mIgnoredPreCreatedUsers.size(); i++) {
                UserHandle preCreatedUser = mIgnoredPreCreatedUsers.get(i);
                if (preCreatedUser.getIdentifier() == userId) {
                    Slogf.d(TAG, "Updating role on pre-created user %d", userId);
            Slogf.d(TAG, "onPreCreatedUserConversion(%d): calling onRoleHoldersChanged() again",
                    userId);
            mServiceStub.mRoleObserver.onRoleHoldersChanged(RoleManager.ROLE_ASSISTANT,
                            preCreatedUser);
                    mIgnoredPreCreatedUsers.remove(i);
                    return;
                                                UserHandle.of(userId));
        }
    }
            Slogf.w(TAG, "onPreCreatedUserConversion(%d): not available on "
                    + "mIgnoredPreCreatedUserIds (%s)", userId, mIgnoredPreCreatedUsers);
        }

    }

    // implementation entry point and binder service
    private final VoiceInteractionManagerServiceStub mServiceStub;
@@ -804,8 +791,10 @@ public class VoiceInteractionManagerService extends SystemService {
            if (TextUtils.isEmpty(curInteractor)) {
                return null;
            }
            if (DEBUG) Slog.d(TAG, "getCurInteractor curInteractor=" + curInteractor
            if (DEBUG) {
                Slog.d(TAG, "getCurInteractor curInteractor=" + curInteractor
                    + " user=" + userHandle);
            }
            return ComponentName.unflattenFromString(curInteractor);
        }

@@ -813,8 +802,9 @@ public class VoiceInteractionManagerService extends SystemService {
            Settings.Secure.putStringForUser(mContext.getContentResolver(),
                    Settings.Secure.VOICE_INTERACTION_SERVICE,
                    comp != null ? comp.flattenToShortString() : "", userHandle);
            if (DEBUG) Slog.d(TAG, "setCurInteractor comp=" + comp
                    + " user=" + userHandle);
            if (DEBUG) {
                Slog.d(TAG, "setCurInteractor comp=" + comp + " user=" + userHandle);
            }
        }

        ComponentName findAvailRecognizer(String prefPackage, int userHandle) {
@@ -1909,7 +1899,6 @@ public class VoiceInteractionManagerService extends SystemService {
                pw.println("  mTemporarilyDisabled: " + mTemporarilyDisabled);
                pw.println("  mCurUser: " + mCurUser);
                pw.println("  mCurUserSupported: " + mCurUserSupported);
                pw.println("  mIgnoredPreCreatedUsers: " + mIgnoredPreCreatedUsers);
                dumpSupportedUsers(pw, "  ");
                mDbHelper.dump(pw);
                if (mImpl == null) {
@@ -2023,6 +2012,11 @@ public class VoiceInteractionManagerService extends SystemService {

                List<String> roleHolders = mRm.getRoleHoldersAsUser(roleName, user);

                if (DEBUG) {
                    Slogf.d(TAG, "onRoleHoldersChanged(%s, %s): roleHolders=%s", roleName, user,
                            roleHolders);
                }

                // TODO(b/226201975): this method is beling called when a pre-created user is added,
                // at which point it doesn't have any role holders. But it's not called again when
                // the actual user is added (i.e., when the  pre-created user is converted), so we
@@ -2033,9 +2027,9 @@ public class VoiceInteractionManagerService extends SystemService {
                if (roleHolders.isEmpty()) {
                    UserInfo userInfo = mUserManagerInternal.getUserInfo(user.getIdentifier());
                    if (userInfo != null && userInfo.preCreated) {
                        Slogf.d(TAG, "onRoleHoldersChanged(): ignoring pre-created user %s for now",
                                userInfo.toFullString());
                        mIgnoredPreCreatedUsers.add(user);
                        Slogf.d(TAG, "onRoleHoldersChanged(): ignoring pre-created user %s for now,"
                                + " this method will be called again when it's converted to a real"
                                + " user", userInfo.toFullString());
                        return;
                    }
                }