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

Commit 3d5d3b30 authored by Winson Chung's avatar Winson Chung
Browse files

Only migrate 2-button setting if set

- We have only shipped configurations with:
  default=3 button + setting to opt in
  default=2 button + no setting to opt out

  So to prevent migrating in the case where a user has restored from
  a device (1) to a device (2) where the setting may be false (but
  previously showed 2 button nav), we only migrate the nav bar mode
  to the 2 button overlay whenever the setting is set. This means
  that the user will fallback to the device default nav bar mode
  which corresponds to the previous default modes for each device.
- Also remove temporary nav bar mode migration for dogfood users

Bug: 128548249
Test: Migrate from P to Q with swipe up setting set to false

Change-Id: I7218eeb13fec50b2fe3e89f75ef0d2d4ab67aff1
parent 5bcdc825
Loading
Loading
Loading
Loading
+8 −45
Original line number Original line Diff line number Diff line
@@ -20,12 +20,7 @@ import static android.os.Process.INVALID_UID;
import static android.os.Process.ROOT_UID;
import static android.os.Process.ROOT_UID;
import static android.os.Process.SHELL_UID;
import static android.os.Process.SHELL_UID;
import static android.os.Process.SYSTEM_UID;
import static android.os.Process.SYSTEM_UID;
import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_2BUTTON;
import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_2BUTTON_OVERLAY;
import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_2BUTTON_OVERLAY;
import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_3BUTTON;
import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_3BUTTON_OVERLAY;
import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_GESTURAL;
import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_GESTURAL_OVERLAY;


import android.Manifest;
import android.Manifest;
import android.annotation.NonNull;
import android.annotation.NonNull;
@@ -41,7 +36,6 @@ import android.content.Context;
import android.content.Intent;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.IntentFilter;
import android.content.om.IOverlayManager;
import android.content.om.IOverlayManager;
import android.content.om.OverlayInfo;
import android.content.pm.ApplicationInfo;
import android.content.pm.ApplicationInfo;
import android.content.pm.IPackageManager;
import android.content.pm.IPackageManager;
import android.content.pm.PackageInfo;
import android.content.pm.PackageInfo;
@@ -4321,50 +4315,19 @@ public class SettingsProvider extends ContentProvider {


                if (currentVersion == 176) {
                if (currentVersion == 176) {
                    // Version 176: Migrate the existing swipe up setting into the resource overlay
                    // Version 176: Migrate the existing swipe up setting into the resource overlay
                    //              for the navigation bar interaction mode.
                    //              for the navigation bar interaction mode.  We do so only if the
                    //              setting is set.


                    final IOverlayManager overlayManager = IOverlayManager.Stub.asInterface(
                            ServiceManager.getService(Context.OVERLAY_SERVICE));
                    int navBarMode = -1;

                    // Migrate the swipe up setting only if it is set
                    final SettingsState secureSettings = getSecureSettingsLocked(userId);
                    final SettingsState secureSettings = getSecureSettingsLocked(userId);
                    final Setting swipeUpSetting = secureSettings.getSettingLocked(
                    final Setting swipeUpSetting = secureSettings.getSettingLocked(
                            "swipe_up_to_switch_apps_enabled");
                            "swipe_up_to_switch_apps_enabled");
                    if (swipeUpSetting != null && !swipeUpSetting.isNull()) {
                    if (swipeUpSetting != null && !swipeUpSetting.isNull()
                        navBarMode = swipeUpSetting.getValue().equals("1")
                            && swipeUpSetting.getValue().equals("1")) {
                                ? NAV_BAR_MODE_2BUTTON
                        final IOverlayManager overlayManager = IOverlayManager.Stub.asInterface(
                                : NAV_BAR_MODE_3BUTTON;
                                ServiceManager.getService(Context.OVERLAY_SERVICE));
                    }

                    // Temporary: Only for migration for dogfooders, to be removed
                    try {
                        final OverlayInfo info = overlayManager.getOverlayInfo(
                                "com.android.internal.experiment.navbar.type.inset",
                                UserHandle.USER_CURRENT);
                        if (info != null && info.isEnabled()) {
                            navBarMode = NAV_BAR_MODE_GESTURAL;
                        }
                    } catch (RemoteException e) {
                        // Ingore, fall through
                    }

                    if (navBarMode != -1) {
                        String overlayPackage = "";
                        try {
                        try {
                            switch (navBarMode) {
                            overlayManager.setEnabledExclusiveInCategory(
                                case NAV_BAR_MODE_3BUTTON:
                                    NAV_BAR_MODE_2BUTTON_OVERLAY, UserHandle.USER_CURRENT);
                                    overlayPackage = NAV_BAR_MODE_3BUTTON_OVERLAY;
                                    break;
                                case NAV_BAR_MODE_2BUTTON:
                                    overlayPackage = NAV_BAR_MODE_2BUTTON_OVERLAY;
                                    break;
                                case NAV_BAR_MODE_GESTURAL:
                                    overlayPackage = NAV_BAR_MODE_GESTURAL_OVERLAY;
                                    break;
                            }
                            overlayManager.setEnabledExclusiveInCategory(overlayPackage,
                                    UserHandle.USER_CURRENT);
                        } catch (RemoteException e) {
                        } catch (RemoteException e) {
                            throw new IllegalStateException(
                            throw new IllegalStateException(
                                    "Failed to set nav bar interaction mode overlay");
                                    "Failed to set nav bar interaction mode overlay");