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

Commit 4a78b8b4 authored by Robin Vinterbladh's avatar Robin Vinterbladh Committed by Fabián Kozynski
Browse files

Add a System Update option to PowerKey menu.

Some carriers require a System Update entry in Global Actions.
Add an option to create a System Update button in PowerKey
menu to facilitate this requirement.

Flag: NA
Test: atest GlobalActionsDialogLiteTest
Test: 1) add system_update to config_globalActionsList
      2) enter PowerKey menu
      Verify that the System Update button is available and works
Bug: 311241400
(cherry picked from https://partner-android-review.googlesource.com/q/commit:7f41434964edb58d16861b0ea357841915c5986b)

Merged-In: I5af8217b7cf310f21abe4b06ec785f89d2e41f2a
Change-Id: I5af8217b7cf310f21abe4b06ec785f89d2e41f2a
parent f0694c53
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -3656,6 +3656,7 @@
         "emergency" = Launch emergency dialer
         "lockdown" = Lock down device until the user authenticates
         "logout" =  Logout the current user
         "system_update" = Launch System Update screen
         -->
    <string-array translatable="false" name="config_globalActionsList">
        <item>emergency</item>
+3 −0
Original line number Diff line number Diff line
@@ -1745,4 +1745,7 @@
    <string name="feminine">Feminine</string>
    <!-- List entry in developer settings to set the grammatical gender to Masculine [CHAR LIMIT=30]-->
    <string name="masculine">Masculine</string>

    <!-- The name of the screen for seeing and installing system updates. [CHAR LIMIT=40]-->
    <string name="system_update_settings_list_item_title">System Updates</string>
</resources>
+45 −1
Original line number Diff line number Diff line
@@ -123,6 +123,7 @@ import com.android.systemui.colorextraction.SysuiColorExtractor;
import com.android.systemui.dagger.qualifiers.Background;
import com.android.systemui.dagger.qualifiers.Main;
import com.android.systemui.globalactions.domain.interactor.GlobalActionsInteractor;
import com.android.systemui.plugins.ActivityStarter;
import com.android.systemui.plugins.GlobalActions.GlobalActionsManager;
import com.android.systemui.plugins.GlobalActionsPanelPlugin;
import com.android.systemui.scrim.ScrimDrawable;
@@ -186,6 +187,7 @@ public class GlobalActionsDialogLite implements DialogInterface.OnDismissListene
    private static final String GLOBAL_ACTION_KEY_LOGOUT = "logout";
    static final String GLOBAL_ACTION_KEY_EMERGENCY = "emergency";
    static final String GLOBAL_ACTION_KEY_SCREENSHOT = "screenshot";
    static final String GLOBAL_ACTION_KEY_SYSTEM_UPDATE = "system_update";

    // See NotificationManagerService#scheduleDurationReachedLocked
    private static final long TOAST_FADE_TIME = 333;
@@ -213,6 +215,7 @@ public class GlobalActionsDialogLite implements DialogInterface.OnDismissListene
    private final TelecomManager mTelecomManager;
    private final MetricsLogger mMetricsLogger;
    private final UiEventLogger mUiEventLogger;
    private final ActivityStarter mActivityStarter;

    // Used for RingerModeTracker
    private final LifecycleRegistry mLifecycle = new LifecycleRegistry(this);
@@ -317,7 +320,10 @@ public class GlobalActionsDialogLite implements DialogInterface.OnDismissListene
        GA_CLOSE_TAP_OUTSIDE(810),

        @UiEvent(doc = "Power menu was closed via power + volume up.")
        GA_CLOSE_POWER_VOLUP(811);
        GA_CLOSE_POWER_VOLUP(811),

        @UiEvent(doc = "System Update button was pressed.")
        GA_SYSTEM_UPDATE_PRESS(1716);

        private final int mId;

@@ -349,6 +355,7 @@ public class GlobalActionsDialogLite implements DialogInterface.OnDismissListene
            @NonNull VibratorHelper vibrator,
            @Main Resources resources,
            ConfigurationController configurationController,
            ActivityStarter activityStarter,
            UserTracker userTracker,
            KeyguardStateController keyguardStateController,
            UserManager userManager,
@@ -385,6 +392,7 @@ public class GlobalActionsDialogLite implements DialogInterface.OnDismissListene
        mSecureSettings = secureSettings;
        mResources = resources;
        mConfigurationController = configurationController;
        mActivityStarter = activityStarter;
        mUserTracker = userTracker;
        mUserManager = userManager;
        mTrustManager = trustManager;
@@ -659,6 +667,8 @@ public class GlobalActionsDialogLite implements DialogInterface.OnDismissListene
                if (shouldDisplayEmergency()) {
                    addIfShouldShowAction(tempActions, new EmergencyDialerAction());
                }
            } else if (GLOBAL_ACTION_KEY_SYSTEM_UPDATE.equals(actionKey)) {
                addIfShouldShowAction(tempActions, new SystemUpdateAction());
            } else {
                Log.e(TAG, "Invalid global action key " + actionKey);
            }
@@ -1145,6 +1155,40 @@ public class GlobalActionsDialogLite implements DialogInterface.OnDismissListene
        }
    }

    @VisibleForTesting
    final class SystemUpdateAction extends SinglePressAction {

        SystemUpdateAction() {
            super(com.android.settingslib.R.drawable.ic_system_update,
                    com.android.settingslib.R.string.system_update_settings_list_item_title);
        }

        @Override
        public void onPress() {
            mUiEventLogger.log(GlobalActionsEvent.GA_SYSTEM_UPDATE_PRESS);
            launchSystemUpdate();
        }

        @Override
        public boolean showDuringKeyguard() {
            return true;
        }

        @Override
        public boolean showBeforeProvisioning() {
            return false;
        }

        private void launchSystemUpdate() {
            Intent intent = new Intent(Settings.ACTION_SYSTEM_UPDATE_SETTINGS);
            intent.addFlags(
                    Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
            // postStartActivityDismissingKeyguard is used for showing keyguard
            // input/pin/password screen if lockscreen is secured, before sending the intent.
            mActivityStarter.postStartActivityDismissingKeyguard(intent, 0);
        }
    }

    private Action getSettingsAction() {
        return new SinglePressAction(R.drawable.ic_settings,
                R.string.global_action_settings) {
+122 −0
Original line number Diff line number Diff line
@@ -67,6 +67,7 @@ import com.android.systemui.broadcast.BroadcastDispatcher;
import com.android.systemui.colorextraction.SysuiColorExtractor;
import com.android.systemui.globalactions.domain.interactor.GlobalActionsInteractor;
import com.android.systemui.kosmos.KosmosJavaAdapter;
import com.android.systemui.plugins.ActivityStarter;
import com.android.systemui.plugins.GlobalActions;
import com.android.systemui.settings.UserContextProvider;
import com.android.systemui.settings.UserTracker;
@@ -114,6 +115,7 @@ public class GlobalActionsDialogLiteTest extends SysuiTestCase {
    private SecureSettings mSecureSettings;
    @Mock private Resources mResources;
    @Mock private ConfigurationController mConfigurationController;
    @Mock private ActivityStarter mActivityStarter;
    @Mock private UserTracker mUserTracker;
    @Mock private KeyguardStateController mKeyguardStateController;
    @Mock private UserManager mUserManager;
@@ -173,6 +175,7 @@ public class GlobalActionsDialogLiteTest extends SysuiTestCase {
                mVibratorHelper,
                mResources,
                mConfigurationController,
                mActivityStarter,
                mUserTracker,
                mKeyguardStateController,
                mUserManager,
@@ -458,6 +461,18 @@ public class GlobalActionsDialogLiteTest extends SysuiTestCase {
        }
    }

    private static <T> void assertNoItemsOfType(List<T> stuff, Class<? extends T> klass) {
        for (int i = 0; i < stuff.size(); i++) {
            assertThat(stuff.get(i)).isNotInstanceOf(klass);
        }
    }

    private static <T> void assertOneItemOfType(List<T> stuff, Class<? extends T> klass) {
        List<?> classes = stuff.stream().map((item) -> item.getClass()).toList();
        assertThat(classes).containsNoDuplicates();
        assertThat(classes).contains(klass);
    }

    @Test
    public void testCreateActionItems_lockdownEnabled_doesShowLockdown() {
        mGlobalActionsDialogLite = spy(mGlobalActionsDialogLite);
@@ -641,6 +656,113 @@ public class GlobalActionsDialogLiteTest extends SysuiTestCase {
        assertThat(mInteractor.isVisible().getValue()).isFalse();
    }

    @Test
    public void testShouldLogSystemUpdatePress() {
        GlobalActionsDialogLite.SystemUpdateAction systemUpdateAction =
                mGlobalActionsDialogLite.new SystemUpdateAction();
        systemUpdateAction.onPress();
        verifyLogPosted(GlobalActionsDialogLite.GlobalActionsEvent.GA_SYSTEM_UPDATE_PRESS);
    }

    @Test
    public void testCreateActionItems_systemUpdateEnabled_doesShowSystemUpdate() {
        mGlobalActionsDialogLite = spy(mGlobalActionsDialogLite);
        doReturn(5).when(mGlobalActionsDialogLite).getMaxShownPowerItems();
        doReturn(true).when(mGlobalActionsDialogLite).shouldDisplayEmergency();
        doReturn(true).when(mGlobalActionsDialogLite).shouldDisplayLockdown(any());
        doReturn(true).when(mGlobalActionsDialogLite).shouldShowAction(any());
        String[] actions = {
                GlobalActionsDialogLite.GLOBAL_ACTION_KEY_EMERGENCY,
                GlobalActionsDialogLite.GLOBAL_ACTION_KEY_LOCKDOWN,
                GlobalActionsDialogLite.GLOBAL_ACTION_KEY_POWER,
                GlobalActionsDialogLite.GLOBAL_ACTION_KEY_RESTART,
                GlobalActionsDialogLite.GLOBAL_ACTION_KEY_SYSTEM_UPDATE
        };
        doReturn(actions).when(mGlobalActionsDialogLite).getDefaultActions();
        mGlobalActionsDialogLite.createActionItems();

        assertItemsOfType(mGlobalActionsDialogLite.mItems,
                GlobalActionsDialogLite.EmergencyAction.class,
                GlobalActionsDialogLite.LockDownAction.class,
                GlobalActionsDialogLite.ShutDownAction.class,
                GlobalActionsDialogLite.RestartAction.class,
                GlobalActionsDialogLite.SystemUpdateAction.class);
        assertThat(mGlobalActionsDialogLite.mOverflowItems).isEmpty();
        assertThat(mGlobalActionsDialogLite.mPowerItems).isEmpty();
    }

    @Test
    public void testCreateActionItems_systemUpdateDisabled_doesntShowSystemUpdateAction() {
        mGlobalActionsDialogLite = spy(mGlobalActionsDialogLite);
        doReturn(5).when(mGlobalActionsDialogLite).getMaxShownPowerItems();
        doReturn(true).when(mGlobalActionsDialogLite).shouldDisplayEmergency();
        doReturn(true).when(mGlobalActionsDialogLite).shouldDisplayLockdown(any());
        doReturn(true).when(mGlobalActionsDialogLite).shouldShowAction(any());
        String[] actions = {
                GlobalActionsDialogLite.GLOBAL_ACTION_KEY_EMERGENCY,
                GlobalActionsDialogLite.GLOBAL_ACTION_KEY_LOCKDOWN,
                GlobalActionsDialogLite.GLOBAL_ACTION_KEY_POWER,
                GlobalActionsDialogLite.GLOBAL_ACTION_KEY_RESTART
        };
        doReturn(actions).when(mGlobalActionsDialogLite).getDefaultActions();
        mGlobalActionsDialogLite.createActionItems();

        assertNoItemsOfType(mGlobalActionsDialogLite.mItems,
                GlobalActionsDialogLite.SystemUpdateAction.class);
        assertThat(mGlobalActionsDialogLite.mOverflowItems).isEmpty();
        assertThat(mGlobalActionsDialogLite.mPowerItems).isEmpty();
    }

    @Test
    public void testCreateActionItems_systemUpdateEnabled_locked_showsSystemUpdate() {
        mGlobalActionsDialogLite = spy(mGlobalActionsDialogLite);
        doReturn(5).when(mGlobalActionsDialogLite).getMaxShownPowerItems();
        doReturn(true).when(mGlobalActionsDialogLite).shouldDisplayEmergency();
        doReturn(true).when(mGlobalActionsDialogLite).shouldDisplayLockdown(any());
        String[] actions = {
                GlobalActionsDialogLite.GLOBAL_ACTION_KEY_EMERGENCY,
                GlobalActionsDialogLite.GLOBAL_ACTION_KEY_LOCKDOWN,
                GlobalActionsDialogLite.GLOBAL_ACTION_KEY_POWER,
                GlobalActionsDialogLite.GLOBAL_ACTION_KEY_RESTART,
                GlobalActionsDialogLite.GLOBAL_ACTION_KEY_SYSTEM_UPDATE
        };
        doReturn(actions).when(mGlobalActionsDialogLite).getDefaultActions();

        // Show dialog with keyguard showing
        mGlobalActionsDialogLite.showOrHideDialog(true, true, null);

        assertOneItemOfType(mGlobalActionsDialogLite.mItems,
                GlobalActionsDialogLite.SystemUpdateAction.class);

        // Hide dialog
        mGlobalActionsDialogLite.showOrHideDialog(true, true, null);
    }

    @Test
    public void testCreateActionItems_systemUpdateEnabled_notProvisioned_noSystemUpdate() {
        mGlobalActionsDialogLite = spy(mGlobalActionsDialogLite);
        doReturn(5).when(mGlobalActionsDialogLite).getMaxShownPowerItems();
        doReturn(true).when(mGlobalActionsDialogLite).shouldDisplayEmergency();
        doReturn(true).when(mGlobalActionsDialogLite).shouldDisplayLockdown(any());
        String[] actions = {
                GlobalActionsDialogLite.GLOBAL_ACTION_KEY_EMERGENCY,
                GlobalActionsDialogLite.GLOBAL_ACTION_KEY_LOCKDOWN,
                GlobalActionsDialogLite.GLOBAL_ACTION_KEY_POWER,
                GlobalActionsDialogLite.GLOBAL_ACTION_KEY_RESTART,
                GlobalActionsDialogLite.GLOBAL_ACTION_KEY_SYSTEM_UPDATE
        };
        doReturn(actions).when(mGlobalActionsDialogLite).getDefaultActions();

        // Show dialog with keyguard showing
        mGlobalActionsDialogLite.showOrHideDialog(false, false, null);

        assertNoItemsOfType(mGlobalActionsDialogLite.mItems,
                GlobalActionsDialogLite.SystemUpdateAction.class);

        // Hide dialog
        mGlobalActionsDialogLite.showOrHideDialog(false, false, null);
    }

    private UserInfo mockCurrentUser(int flags) {
        return new UserInfo(10, "A User", flags);