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

Commit 759dcd64 authored by Chris Göllner's avatar Chris Göllner Committed by Android (Google) Code Review
Browse files

Merge "Shortcut Helper: dismiss when switching to a different user" into main

parents 185dbdef cc613890
Loading
Loading
Loading
Loading
+0 −25
Original line number Diff line number Diff line
@@ -23,10 +23,7 @@ import static com.android.systemui.Flags.validateKeyboardShortcutHelperIconUri;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.ActivityManager;
import android.app.AppGlobals;
import android.app.SynchronousUserSwitchObserver;
import android.app.UserSwitchObserver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
@@ -151,13 +148,6 @@ public final class KeyboardShortcutListSearch {
    private KeyCharacterMap mKeyCharacterMap;
    private KeyCharacterMap mBackupKeyCharacterMap;

    private final UserSwitchObserver mUserSwitchObserver = new SynchronousUserSwitchObserver() {
            @Override
            public void onUserSwitching(int newUserId) throws RemoteException {
                dismiss();
            }
    };

    @VisibleForTesting
    KeyboardShortcutListSearch(Context context, WindowManager windowManager) {
        this.mContext = new ContextThemeWrapper(
@@ -474,14 +464,6 @@ public final class KeyboardShortcutListSearch {
            mBackgroundHandler = new Handler(mHandlerThread.getLooper());
        }

        if (validateKeyboardShortcutHelperIconUri()) {
            try {
                ActivityManager.getService().registerUserSwitchObserver(mUserSwitchObserver, TAG);
            } catch (RemoteException e) {
                Log.e(TAG, "could not register user switch observer", e);
            }
        }

        retrieveKeyCharacterMap(deviceId);
        mAppShortcutsReceived = false;
        mImeShortcutsReceived = false;
@@ -563,13 +545,6 @@ public final class KeyboardShortcutListSearch {
            mKeyboardShortcutsBottomSheetDialog = null;
        }
        mHandlerThread.quit();
        if (validateKeyboardShortcutHelperIconUri()) {
            try {
                ActivityManager.getService().unregisterUserSwitchObserver(mUserSwitchObserver);
            } catch (RemoteException e) {
                Log.e(TAG, "Could not unregister user switch observer", e);
            }
        }
    }

    private KeyboardShortcutMultiMappingGroup getMultiMappingSystemShortcuts(Context context) {
+0 −25
Original line number Diff line number Diff line
@@ -24,12 +24,9 @@ import static com.android.systemui.Flags.validateKeyboardShortcutHelperIconUri;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.ActivityManager;
import android.app.AlertDialog;
import android.app.AppGlobals;
import android.app.Dialog;
import android.app.SynchronousUserSwitchObserver;
import android.app.UserSwitchObserver;
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
@@ -137,13 +134,6 @@ public final class KeyboardShortcuts {
    @Nullable private List<KeyboardShortcutGroup> mReceivedAppShortcutGroups = null;
    @Nullable private List<KeyboardShortcutGroup> mReceivedImeShortcutGroups = null;

    private final UserSwitchObserver mUserSwitchObserver = new SynchronousUserSwitchObserver() {
            @Override
            public void onUserSwitching(int newUserId) throws RemoteException {
                dismiss();
            }
    };

    @VisibleForTesting
    KeyboardShortcuts(Context context, WindowManager windowManager) {
        this.mContext = new ContextThemeWrapper(
@@ -394,14 +384,6 @@ public final class KeyboardShortcuts {
            mBackgroundHandler = new Handler(mHandlerThread.getLooper());
        }

        if (validateKeyboardShortcutHelperIconUri()) {
            try {
                ActivityManager.getService().registerUserSwitchObserver(mUserSwitchObserver, TAG);
            } catch (RemoteException e) {
                Log.e(TAG, "could not register user switch observer", e);
            }
        }

        retrieveKeyCharacterMap(deviceId);

        mReceivedAppShortcutGroups = null;
@@ -476,13 +458,6 @@ public final class KeyboardShortcuts {
            mKeyboardShortcutsDialog = null;
        }
        mHandlerThread.quit();
        if (validateKeyboardShortcutHelperIconUri()) {
            try {
                ActivityManager.getService().unregisterUserSwitchObserver(mUserSwitchObserver);
            } catch (RemoteException e) {
                Log.e(TAG, "Could not unregister user switch observer", e);
            }
        }
    }

    private KeyboardShortcutGroup getSystemShortcuts() {
+4 −1
Original line number Diff line number Diff line
@@ -486,7 +486,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {

    boolean mBootMessageNeedsHiding;
    volatile boolean mBootAnimationDismissable;
    private KeyguardServiceDelegate mKeyguardDelegate;
    @VisibleForTesting KeyguardServiceDelegate mKeyguardDelegate;
    private boolean mKeyguardBound;
    final DrawnListener mKeyguardDrawnCallback = new DrawnListener() {
        @Override
@@ -6516,6 +6516,9 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    @Override
    public void setSwitchingUser(boolean switching) {
        mKeyguardDelegate.setSwitchingUser(switching);
        if (switching) {
            dismissKeyboardShortcutsMenu();
        }
    }

    @Override
+22 −1
Original line number Diff line number Diff line
@@ -54,6 +54,8 @@ import androidx.test.filters.SmallTest;

import com.android.server.LocalServices;
import com.android.server.pm.UserManagerInternal;
import com.android.server.policy.keyguard.KeyguardServiceDelegate;
import com.android.server.statusbar.StatusBarManagerInternal;
import com.android.server.wm.ActivityTaskManagerInternal;
import com.android.server.wm.DisplayPolicy;
import com.android.server.wm.DisplayRotation;
@@ -78,6 +80,7 @@ public class PhoneWindowManagerTests {

    PhoneWindowManager mPhoneWindowManager;
    private ActivityTaskManagerInternal mAtmInternal;
    private StatusBarManagerInternal mStatusBarManagerInternal;
    private Context mContext;

    @Before
@@ -90,6 +93,9 @@ public class PhoneWindowManagerTests {
        LocalServices.addService(ActivityTaskManagerInternal.class, mAtmInternal);
        mPhoneWindowManager.mActivityTaskManagerInternal = mAtmInternal;
        LocalServices.addService(WindowManagerInternal.class, mock(WindowManagerInternal.class));
        mStatusBarManagerInternal = mock(StatusBarManagerInternal.class);
        LocalServices.addService(StatusBarManagerInternal.class, mStatusBarManagerInternal);
        mPhoneWindowManager.mKeyguardDelegate = mock(KeyguardServiceDelegate.class);
    }

    @After
@@ -98,6 +104,7 @@ public class PhoneWindowManagerTests {
        reset(mContext);
        LocalServices.removeServiceForTest(ActivityTaskManagerInternal.class);
        LocalServices.removeServiceForTest(WindowManagerInternal.class);
        LocalServices.removeServiceForTest(StatusBarManagerInternal.class);
    }

    @Test
@@ -206,6 +213,20 @@ public class PhoneWindowManagerTests {
        assertThat(outAppOp[0]).isEqualTo(AppOpsManager.OP_NONE);
    }

    @Test
    public void userSwitching_keyboardShortcutHelperDismissed() {
        mPhoneWindowManager.setSwitchingUser(true);

        verify(mStatusBarManagerInternal).dismissKeyboardShortcutsMenu();
    }

    @Test
    public void userNotSwitching_keyboardShortcutHelperDismissed() {
        mPhoneWindowManager.setSwitchingUser(false);

        verify(mStatusBarManagerInternal, never()).dismissKeyboardShortcutsMenu();
    }

    private void mockStartDockOrHome() throws Exception {
        doNothing().when(ActivityManager.getService()).stopAppSwitches();
        when(mAtmInternal.startHomeOnDisplay(