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

Commit 332eb8c1 authored by Yohei Yukawa's avatar Yohei Yukawa
Browse files

Remove UserLifecycleListener deps from SecureSettingsWrapper (2nd try)

This is the 2nd attempt to submit my original CL [1], which got
reverted [2] to verify whether it was causing jank benchmark
regression discussed in Bug 355334507 or not. As reverting my original
CL did not affect the benchmark, I am now submitting this again.

As part of removing the dependency on UserLifecycleListener from
random utility classes under com.android.server.inputmethod.*, this CL
updates SecureSettingsWrapper so that it does not need to register
UserLifecycleListener by itself.

This is a mechanical refactoring CL. The observable semantics should
remain unchanged.

 [1]: If903fe15e7e71eed2fccb45c082d8efb8176f26c
      1a7311fe
 [2]: Ib4ce3cb283f5165cff0e66c9a6ddc29910abd911
      44a859a6

Fix: 352354308
Test: presubmit
Flag: EXEMPT refactor
Change-Id: I7f1502d19df95e6ba5228dd8b501e7e98d210cfd
parent 2e7481d1
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -1001,6 +1001,8 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
                    Process.THREAD_PRIORITY_FOREGROUND, true /* allowIo */);
            ioThread.start();

            SecureSettingsWrapper.setContentResolver(context.getContentResolver());

            return new InputMethodManagerService(context,
                    shouldEnableConcurrentMultiUserMode(context), thread.getLooper(),
                    Handler.createAsync(ioThread.getLooper()),
@@ -1059,6 +1061,7 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
        public void onUserRemoved(UserInfo user) {
            // Called directly from UserManagerService. Do not block the calling thread.
            final int userId = user.id;
            SecureSettingsWrapper.onUserRemoved(userId);
            AdditionalSubtypeMapRepository.remove(userId);
            InputMethodSettingsRepository.remove(userId);
            mService.mUserDataRepository.remove(userId);
@@ -1185,7 +1188,6 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
            mConcurrentMultiUserModeEnabled = concurrentMultiUserModeEnabled;
            mContext = context;
            mRes = context.getResources();
            SecureSettingsWrapper.onStart(mContext);

            mHandler = Handler.createAsync(uiLooper, this);
            mIoHandler = ioHandler;
+16 −24
Original line number Diff line number Diff line
@@ -20,10 +20,7 @@ import android.annotation.AnyThread;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.UserIdInt;
import android.app.ActivityManagerInternal;
import android.content.ContentResolver;
import android.content.Context;
import android.content.pm.UserInfo;
import android.provider.Settings;
import android.util.ArrayMap;
import android.util.ArraySet;
@@ -321,30 +318,13 @@ final class SecureSettingsWrapper {
    }

    /**
     * Called when {@link InputMethodManagerService} is starting.
     * Called when the system is starting.
     *
     * @param context the {@link Context} to be used.
     * @param contentResolver the {@link ContentResolver} to be used
     */
    @AnyThread
    static void onStart(@NonNull Context context) {
        sContentResolver = context.getContentResolver();

        final int userId = LocalServices.getService(ActivityManagerInternal.class)
                .getCurrentUserId();
        final UserManagerInternal userManagerInternal =
                LocalServices.getService(UserManagerInternal.class);
        putOrGet(userId, createImpl(userManagerInternal, userId));

        userManagerInternal.addUserLifecycleListener(
                new UserManagerInternal.UserLifecycleListener() {
                    @Override
                    public void onUserRemoved(UserInfo user) {
                        synchronized (sMutationLock) {
                            sUserMap = sUserMap.cloneWithRemoveOrSelf(user.id);
                        }
                    }
                }
        );
    static void setContentResolver(@NonNull ContentResolver contentResolver) {
        sContentResolver = contentResolver;
    }

    /**
@@ -393,6 +373,18 @@ final class SecureSettingsWrapper {
        }
    }

    /**
     * Called when a user is being removed.
     *
     * @param userId the ID of the user whose storage is being removed
     */
    @AnyThread
    static void onUserRemoved(@UserIdInt int userId) {
        synchronized (sMutationLock) {
            sUserMap = sUserMap.cloneWithRemoveOrSelf(userId);
        }
    }

    /**
     * Put the given string {@code value} to {@code key}.
     *