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

Commit ad1b1cd6 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Clean up fix_missing_user_change_callbacks flag usages" into main

parents 13b039d6 ee6aa297
Loading
Loading
Loading
Loading
+0 −4
Original line number Diff line number Diff line
@@ -725,10 +725,6 @@ public class PipController implements PipTransitionController.PipTransitionCallb
                    });
        });

        if (!ShellController.FIX_MISSING_USER_CHANGE_CALLBACKS_FLAG.isTrue()) {
            mMediaController.registerSessionListenerForCurrentUser();
        }

        mShellController.addConfigurationChangeListener(this);
        mShellController.addKeyguardChangeListener(this);
        mShellController.addUserChangeListener(this);
+11 −24
Original line number Diff line number Diff line
@@ -22,7 +22,6 @@ import static android.content.pm.ActivityInfo.CONFIG_LAYOUT_DIRECTION;
import static android.content.pm.ActivityInfo.CONFIG_LOCALE;
import static android.content.pm.ActivityInfo.CONFIG_SMALLEST_SCREEN_SIZE;
import static android.content.pm.ActivityInfo.CONFIG_UI_MODE;
import static android.window.DesktopExperienceFlags.DesktopExperienceFlag;

import static com.android.wm.shell.protolog.ShellProtoLogGroup.WM_SHELL_INIT;
import static com.android.wm.shell.protolog.ShellProtoLogGroup.WM_SHELL_SYSUI_EVENTS;
@@ -45,7 +44,6 @@ import androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting;

import com.android.internal.protolog.ProtoLog;
import com.android.wm.shell.Flags;
import com.android.wm.shell.common.DisplayInsetsController;
import com.android.wm.shell.common.DisplayInsetsController.OnInsetsChangedListener;
import com.android.wm.shell.common.ExternalInterfaceBinder;
@@ -67,10 +65,6 @@ import java.util.function.Supplier;
public class ShellController {
    private static final String TAG = ShellController.class.getSimpleName();

    public static final DesktopExperienceFlag FIX_MISSING_USER_CHANGE_CALLBACKS_FLAG =
            new DesktopExperienceFlag(Flags::fixMissingUserChangeCallbacks, true,
                    Flags.FLAG_FIX_MISSING_USER_CHANGE_CALLBACKS);

    private final Context mContext;
    private final ShellInit mShellInit;
    private final ShellCommandHandler mShellCommandHandler;
@@ -154,25 +148,21 @@ public class ShellController {
        mUserManager = userManager;
        mMainExecutor = mainExecutor;
        shellInit.addInitCallback(this::onInit, this);
        if (FIX_MISSING_USER_CHANGE_CALLBACKS_FLAG.isTrue()) {
        final int currentUserId = ActivityManager.getCurrentUser();
        updateCurrentUser(currentUserId, getOrCreateUserContext(currentUserId));
        updateProfiles(getUserProfiles(currentUserId));
    }
    }

    private void onInit() {
        mShellCommandHandler.addCommandCallback("dump", mDumpCommandHandler, this);
        mShellCommandHandler.addDumpCallback(this::dump, this);
        mDisplayInsetsController.addInsetsChangedListener(
                mContext.getDisplayId(), mInsetsChangeListener);
        if (FIX_MISSING_USER_CHANGE_CALLBACKS_FLAG.isTrue()) {
        // Update current user again, in case it changed between the constructor and |onInit|.
        final int currentUserId = ActivityManager.getCurrentUser();
        updateCurrentUser(currentUserId, getOrCreateUserContext(currentUserId));
        updateProfiles(getUserProfiles(currentUserId));
    }
    }

    /**
     * Returns the external interface to this controller.
@@ -220,11 +210,9 @@ public class ShellController {
    public void addUserChangeListener(UserChangeListener listener) {
        mUserChangeListeners.remove(listener);
        mUserChangeListeners.add(listener);
        if (FIX_MISSING_USER_CHANGE_CALLBACKS_FLAG.isTrue()) {
        listener.onUserChanged(mUserId, mUserContext);
        listener.onUserProfilesChanged(mProfiles);
    }
    }

    /**
     * Removes an existing user-change listener.
@@ -348,8 +336,7 @@ public class ShellController {

    @VisibleForTesting
    void onUserChanged(int newUserId, @NonNull Context userContext) {
        if (FIX_MISSING_USER_CHANGE_CALLBACKS_FLAG.isTrue()
                && !updateCurrentUser(newUserId, userContext)) {
        if (!updateCurrentUser(newUserId, userContext)) {
            // No change, do not notify listeners.
            return;
        }
@@ -365,7 +352,7 @@ public class ShellController {

    @VisibleForTesting
    void onUserProfilesChanged(@NonNull List<UserInfo> profiles) {
        if (FIX_MISSING_USER_CHANGE_CALLBACKS_FLAG.isTrue() && !updateProfiles(profiles)) {
        if (!updateProfiles(profiles)) {
            // No change, do not notify listeners.
            return;
        }
+0 −18
Original line number Diff line number Diff line
@@ -31,8 +31,6 @@ import android.os.Binder;
import android.os.Bundle;
import android.os.IBinder;
import android.os.UserManager;
import android.platform.test.annotations.DisableFlags;
import android.platform.test.annotations.EnableFlags;
import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper;

@@ -40,7 +38,6 @@ import androidx.annotation.NonNull;
import androidx.test.filters.SmallTest;
import androidx.test.platform.app.InstrumentationRegistry;

import com.android.wm.shell.Flags;
import com.android.wm.shell.ShellTestCase;
import com.android.wm.shell.TestShellExecutor;
import com.android.wm.shell.common.DisplayInsetsController;
@@ -108,7 +105,6 @@ public class ShellControllerTest extends ShellTestCase {
    }

    @Test
    @EnableFlags(Flags.FLAG_FIX_MISSING_USER_CHANGE_CALLBACKS)
    public void testOnInit_updatesCurrentUser() {
        mController.onUserChanged(TEST_SECOND_USER_ID, mTestSecondUserContext);
        final List<UserInfo> profiles = new ArrayList<>();
@@ -207,17 +203,6 @@ public class ShellControllerTest extends ShellTestCase {
    }

    @Test
    @DisableFlags(Flags.FLAG_FIX_MISSING_USER_CHANGE_CALLBACKS)
    public void testAddUserChangeListener_ensureCallback() {
        mController.addUserChangeListener(mUserChangeListener);

        mController.onUserChanged(TEST_USER_ID, mTestUserContext);
        assertTrue(mUserChangeListener.userChanged == 1);
        assertTrue(mUserChangeListener.lastUserContext == mTestUserContext);
    }

    @Test
    @EnableFlags(Flags.FLAG_FIX_MISSING_USER_CHANGE_CALLBACKS)
    public void testAddUserChangeListener_changed_ensureCallback() {
        mController.addUserChangeListener(mUserChangeListener);

@@ -228,7 +213,6 @@ public class ShellControllerTest extends ShellTestCase {
    }

    @Test
    @EnableFlags(Flags.FLAG_FIX_MISSING_USER_CHANGE_CALLBACKS)
    public void testAddUserChangeListener_ensureCallbacksWithCurrentUser() {
        mController.addUserChangeListener(mUserChangeListener);

@@ -260,7 +244,6 @@ public class ShellControllerTest extends ShellTestCase {
    }

    @Test
    @EnableFlags(Flags.FLAG_FIX_MISSING_USER_CHANGE_CALLBACKS)
    public void testUserChanged_noChange_ensureNoCallback() {
        mController.addUserChangeListener(mUserChangeListener);
        mController.onUserChanged(TEST_SECOND_USER_ID, mTestSecondUserContext);
@@ -283,7 +266,6 @@ public class ShellControllerTest extends ShellTestCase {
    }

    @Test
    @EnableFlags(Flags.FLAG_FIX_MISSING_USER_CHANGE_CALLBACKS)
    public void testUserProfilesChanged_noChange_ensureNoCallback() {
        ArrayList<UserInfo> profiles = new ArrayList<>();
        profiles.add(mock(UserInfo.class));
+0 −2
Original line number Diff line number Diff line
@@ -52,7 +52,6 @@ import com.android.systemui.statusbar.policy.keyguardStateController
import com.android.systemui.testKosmos
import com.android.systemui.user.data.repository.fakeUserRepository
import com.android.systemui.util.kotlin.javaAdapter
import com.android.wm.shell.Flags.FLAG_FIX_MISSING_USER_CHANGE_CALLBACKS
import com.android.wm.shell.desktopmode.DesktopMode
import com.android.wm.shell.desktopmode.data.DesktopRepository.VisibleTasksListener
import com.android.wm.shell.onehanded.OneHanded
@@ -188,7 +187,6 @@ class WMShellTest : SysuiTestCase() {
        }

    @Test
    @EnableFlags(FLAG_FIX_MISSING_USER_CHANGE_CALLBACKS)
    fun init_ensureUserChangeCallback() =
        kosmos.runTest {
            val userId = userTracker.userId
+3 −6
Original line number Diff line number Diff line
@@ -28,7 +28,6 @@ import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_O
import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_QUICK_SETTINGS_EXPANDED;
import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_STATUS_BAR_KEYGUARD_SHOWING;
import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_STATUS_BAR_KEYGUARD_SHOWING_OCCLUDED;
import static com.android.wm.shell.sysui.ShellController.FIX_MISSING_USER_CHANGE_CALLBACKS_FLAG;

import android.content.Context;
import android.content.pm.UserInfo;
@@ -257,11 +256,9 @@ public final class WMShell implements

        // Subscribe to user changes
        mUserTracker.addCallback(mUserChangedCallback, mContext.getMainExecutor());
        if (FIX_MISSING_USER_CHANGE_CALLBACKS_FLAG.isTrue()) {
        mUserChangedCallback.onUserChanged(mUserTracker.getUserId(),
                mContext.createContextAsUser(mUserTracker.getUserHandle(), 0 /* flags */));
        mUserChangedCallback.onProfilesChanged(mUserTracker.getUserProfiles());
        }

        mCommandQueue.addCallback(this);
        mCommandRegistry.registerCommand("wmshell-passthrough", () -> mShellCommand);