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

Commit 32edbf20 authored by Felipe Leme's avatar Felipe Leme Committed by Android (Google) Code Review
Browse files

Merge "Further fixes on VIMS.onPreCreatedUserConversion()"

parents f9309d86 63da68c1
Loading
Loading
Loading
Loading
+19 −25
Original line number Diff line number Diff line
@@ -136,9 +136,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;
@@ -309,25 +306,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;
@@ -809,8 +796,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);
        }

@@ -818,8 +807,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) {
@@ -1917,7 +1907,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) {
@@ -2031,6 +2020,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
@@ -2041,9 +2035,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;
                    }
                }