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

Commit c9d834d0 authored by Christopher Tate's avatar Christopher Tate Committed by The Android Automerger
Browse files

Update airplane-mode manipulation for the new Settings namespace

Quick Settings and global actions (aka longpress-Power) toggles are
included in this CL.  The Settings app manipulations are updated in
a different CL because that's a different git package.

Bug 7132230

Change-Id: I50838f5e8d7b25a750d2bcae90bf384b09816dbb
parent e29b24b1
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ import android.os.Message;
import android.os.PowerManager;
import android.os.ServiceManager;
import android.os.SystemClock;
import android.os.UserHandle;
import android.provider.Settings;
import android.util.Log;
import android.view.KeyEvent;
@@ -696,12 +697,12 @@ public class ConnectivityManagerTestActivity extends Activity {
     */
    public void setAirplaneMode(Context context, boolean enableAM) {
        //set the airplane mode
        Settings.System.putInt(context.getContentResolver(), Settings.System.AIRPLANE_MODE_ON,
        Settings.Global.putInt(context.getContentResolver(), Settings.Global.AIRPLANE_MODE_ON,
                enableAM ? 1 : 0);
        // Post the intent
        Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
        intent.putExtra("state", enableAM);
        context.sendBroadcast(intent);
        context.sendBroadcastAsUser(intent, UserHandle.ALL);
    }

    protected static String convertToQuotedString(String string) {
+4 −4
Original line number Diff line number Diff line
@@ -59,8 +59,8 @@ public class ConnectivityManagerMobileTest extends
        wl = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "CMWakeLock");
        wl.acquire();
        // Each test case will start with cellular connection
        if (Settings.System.getInt(getInstrumentation().getContext().getContentResolver(),
                Settings.System.AIRPLANE_MODE_ON) == 1) {
        if (Settings.Global.getInt(getInstrumentation().getContext().getContentResolver(),
                Settings.Global.AIRPLANE_MODE_ON) == 1) {
            log("airplane is not disabled, disable it.");
            cmActivity.setAirplaneMode(getInstrumentation().getContext(), false);
        }
@@ -84,8 +84,8 @@ public class ConnectivityManagerMobileTest extends
        wl.release();
        cmActivity.removeConfiguredNetworksAndDisableWifi();
        // if airplane mode is set, disable it.
        if (Settings.System.getInt(getInstrumentation().getContext().getContentResolver(),
                Settings.System.AIRPLANE_MODE_ON) == 1) {
        if (Settings.Global.getInt(getInstrumentation().getContext().getContentResolver(),
                Settings.Global.AIRPLANE_MODE_ON) == 1) {
            log("disable airplane mode if it is enabled");
            cmActivity.setAirplaneMode(getInstrumentation().getContext(), false);
        }
+5 −4
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import android.net.Uri;
import android.net.wifi.WifiManager;
import android.os.Environment;
import android.os.ParcelFileDescriptor;
import android.os.UserHandle;
import android.os.ParcelFileDescriptor.AutoCloseInputStream;
import android.os.SystemClock;
import android.provider.Settings;
@@ -553,7 +554,7 @@ public class DownloadManagerBaseTest extends InstrumentationTestCase {
        int state = enable ? 1 : 0;

        // Change the system setting
        Settings.System.putInt(mContext.getContentResolver(), Settings.System.AIRPLANE_MODE_ON,
        Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.AIRPLANE_MODE_ON,
                state);

        String timeoutMessage = "Timed out waiting for airplane mode to be " +
@@ -561,8 +562,8 @@ public class DownloadManagerBaseTest extends InstrumentationTestCase {

        // wait for airplane mode to change state
        int currentWaitTime = 0;
        while (Settings.System.getInt(mContext.getContentResolver(),
                Settings.System.AIRPLANE_MODE_ON, -1) != state) {
        while (Settings.Global.getInt(mContext.getContentResolver(),
                Settings.Global.AIRPLANE_MODE_ON, -1) != state) {
            timeoutWait(currentWaitTime, DEFAULT_WAIT_POLL_TIME, DEFAULT_MAX_WAIT_TIME,
                    timeoutMessage);
        }
@@ -570,7 +571,7 @@ public class DownloadManagerBaseTest extends InstrumentationTestCase {
        // Post the intent
        Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
        intent.putExtra("state", true);
        mContext.sendBroadcast(intent);
        mContext.sendBroadcastAsUser(intent, UserHandle.ALL);
    }

    /**
+3 −2
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import android.hardware.display.DisplayManager;
import android.hardware.display.WifiDisplay;
import android.hardware.display.WifiDisplayStatus;
import android.net.Uri;
import android.os.UserHandle;
import android.provider.ContactsContract;
import android.provider.Settings;
import android.view.LayoutInflater;
@@ -147,7 +148,7 @@ class QuickSettingsModel implements BluetoothStateChangeCallback,
        // TODO: Sets the view to be "awaiting" if not already awaiting

        // Change the system setting
        Settings.System.putInt(mContext.getContentResolver(), Settings.System.AIRPLANE_MODE_ON,
        Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.AIRPLANE_MODE_ON,
                                enabled ? 1 : 0);

        // TODO: Update the UI to reflect system setting
@@ -156,7 +157,7 @@ class QuickSettingsModel implements BluetoothStateChangeCallback,
        // Post the intent
        Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
        intent.putExtra("state", enabled);
        mContext.sendBroadcast(intent);
        mContext.sendBroadcastAsUser(intent, UserHandle.ALL);
    }
    // NetworkSignalChanged callback
    @Override
+3 −3
Original line number Diff line number Diff line
@@ -74,7 +74,7 @@ public class AirplaneModeController extends BroadcastReceiver

    private boolean getAirplaneMode() {
        ContentResolver cr = mContext.getContentResolver();
        return 0 != Settings.System.getInt(cr, Settings.System.AIRPLANE_MODE_ON, 0);
        return 0 != Settings.Global.getInt(cr, Settings.Global.AIRPLANE_MODE_ON, 0);
    }

    // TODO: Fix this racy API by adding something better to TelephonyManager or
@@ -82,9 +82,9 @@ public class AirplaneModeController extends BroadcastReceiver
    private void unsafe(final boolean enabled) {
        AsyncTask.execute(new Runnable() {
                public void run() {
                    Settings.System.putInt(
                    Settings.Global.putInt(
                            mContext.getContentResolver(),
                            Settings.System.AIRPLANE_MODE_ON,
                            Settings.Global.AIRPLANE_MODE_ON,
                            enabled ? 1 : 0);
                    Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
                    intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
Loading