OSDN Git Service

GlobalActions: Set the initial status of airplane mode toggle
authorCristoforo Cataldo <cristoforo.cataldo@gmail.com>
Fri, 31 Jan 2014 06:36:29 +0000 (07:36 +0100)
committerArne Coucheron <arco68@gmail.com>
Tue, 20 Sep 2016 04:33:09 +0000 (06:33 +0200)
Actually, the initial status of airplane mode toggle is set to false
when the power menu dialog is initialized.
This causes an issue if you set airplane mode and then reboot.
After the reboot, the dialog displays the wrong airplane mode status,
eg. "Airplane mode is not active", and if you toggle that option, a wrong
intent is sent again to put ON the airplane mode, instead of OFF, the
toggle (that is in transition state) will be set disabled.

This commit fixes this issue.

Change-Id: Id30355c1e090355645c437086c79ab59093c27a8

services/core/java/com/android/server/policy/GlobalActions.java

index 38ab369..32d665d 100644 (file)
@@ -163,6 +163,9 @@ class GlobalActions implements DialogInterface.OnDismissListener, DialogInterfac
         mShowSilentToggle = SHOW_SILENT_TOGGLE && !mContext.getResources().getBoolean(
                 com.android.internal.R.bool.config_useFixedVolume);
 
+        // Set the initial status of airplane mode toggle
+        mAirplaneState = getUpdatedAirplaneToggleState();
+
         updatePowerMenuActions();
     }
 
@@ -1262,15 +1265,17 @@ class GlobalActions implements DialogInterface.OnDismissListener, DialogInterfac
         }
     };
 
+    private ToggleAction.State getUpdatedAirplaneToggleState() {
+        return (Settings.Global.getInt(mContext.getContentResolver(),
+                    Settings.Global.AIRPLANE_MODE_ON, 0) == 1) ?
+                ToggleAction.State.On : ToggleAction.State.Off;
+    }
+
     private void onAirplaneModeChanged() {
         // Let the service state callbacks handle the state.
         if (mHasTelephony) return;
 
-        boolean airplaneModeOn = Settings.Global.getInt(
-                mContext.getContentResolver(),
-                Settings.Global.AIRPLANE_MODE_ON,
-                0) == 1;
-        mAirplaneState = airplaneModeOn ? ToggleAction.State.On : ToggleAction.State.Off;
+        mAirplaneState = getUpdatedAirplaneToggleState();
         mAirplaneModeOn.updateState(mAirplaneState);
     }