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
This commit is contained in:
@ -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) {
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
@ -509,8 +509,8 @@ public class NetworkController extends BroadcastReceiver {
|
||||
}
|
||||
|
||||
private void updateAirplaneMode() {
|
||||
mAirplaneMode = (Settings.System.getInt(mContext.getContentResolver(),
|
||||
Settings.System.AIRPLANE_MODE_ON, 0) == 1);
|
||||
mAirplaneMode = (Settings.Global.getInt(mContext.getContentResolver(),
|
||||
Settings.Global.AIRPLANE_MODE_ON, 0) == 1);
|
||||
}
|
||||
|
||||
private final void updateTelephonySignalStrength() {
|
||||
|
@ -115,7 +115,7 @@ class GlobalActions implements DialogInterface.OnDismissListener, DialogInterfac
|
||||
context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
mHasTelephony = cm.isNetworkSupported(ConnectivityManager.TYPE_MOBILE);
|
||||
mContext.getContentResolver().registerContentObserver(
|
||||
Settings.System.getUriFor(Settings.System.AIRPLANE_MODE_ON), true,
|
||||
Settings.Global.getUriFor(Settings.Global.AIRPLANE_MODE_ON), true,
|
||||
mAirplaneModeObserver);
|
||||
Vibrator vibrator = (Vibrator) mContext.getSystemService(Context.VIBRATOR_SERVICE);
|
||||
mHasVibrator = vibrator != null && vibrator.hasVibrator();
|
||||
@ -849,9 +849,9 @@ class GlobalActions implements DialogInterface.OnDismissListener, DialogInterfac
|
||||
// Let the service state callbacks handle the state.
|
||||
if (mHasTelephony) return;
|
||||
|
||||
boolean airplaneModeOn = Settings.System.getInt(
|
||||
boolean airplaneModeOn = Settings.Global.getInt(
|
||||
mContext.getContentResolver(),
|
||||
Settings.System.AIRPLANE_MODE_ON,
|
||||
Settings.Global.AIRPLANE_MODE_ON,
|
||||
0) == 1;
|
||||
mAirplaneState = airplaneModeOn ? ToggleAction.State.On : ToggleAction.State.Off;
|
||||
mAirplaneModeOn.updateState(mAirplaneState);
|
||||
@ -861,9 +861,9 @@ class GlobalActions implements DialogInterface.OnDismissListener, DialogInterfac
|
||||
* Change the airplane mode system setting
|
||||
*/
|
||||
private void changeAirplaneModeSystemSetting(boolean on) {
|
||||
Settings.System.putInt(
|
||||
Settings.Global.putInt(
|
||||
mContext.getContentResolver(),
|
||||
Settings.System.AIRPLANE_MODE_ON,
|
||||
Settings.Global.AIRPLANE_MODE_ON,
|
||||
on ? 1 : 0);
|
||||
Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
|
||||
intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
|
||||
|
@ -75,12 +75,12 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
|
||||
|
||||
private void registerForAirplaneMode(IntentFilter filter) {
|
||||
final ContentResolver resolver = mContext.getContentResolver();
|
||||
final String airplaneModeRadios = Settings.System.getString(resolver,
|
||||
Settings.System.AIRPLANE_MODE_RADIOS);
|
||||
final String toggleableRadios = Settings.System.getString(resolver,
|
||||
Settings.System.AIRPLANE_MODE_TOGGLEABLE_RADIOS);
|
||||
final String airplaneModeRadios = Settings.Global.getString(resolver,
|
||||
Settings.Global.AIRPLANE_MODE_RADIOS);
|
||||
final String toggleableRadios = Settings.Global.getString(resolver,
|
||||
Settings.Global.AIRPLANE_MODE_TOGGLEABLE_RADIOS);
|
||||
boolean mIsAirplaneSensitive = airplaneModeRadios == null ? true :
|
||||
airplaneModeRadios.contains(Settings.System.RADIO_BLUETOOTH);
|
||||
airplaneModeRadios.contains(Settings.Global.RADIO_BLUETOOTH);
|
||||
if (mIsAirplaneSensitive) {
|
||||
filter.addAction(Intent.ACTION_AIRPLANE_MODE_CHANGED);
|
||||
}
|
||||
@ -151,8 +151,8 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
|
||||
* Returns true if airplane mode is currently on
|
||||
*/
|
||||
private final boolean isAirplaneModeOn() {
|
||||
return Settings.System.getInt(mContext.getContentResolver(),
|
||||
Settings.System.AIRPLANE_MODE_ON, 0) == 1;
|
||||
return Settings.Global.getInt(mContext.getContentResolver(),
|
||||
Settings.Global.AIRPLANE_MODE_ON, 0) == 1;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1179,17 +1179,17 @@ public class WifiService extends IWifiManager.Stub {
|
||||
}
|
||||
|
||||
private boolean isAirplaneSensitive() {
|
||||
String airplaneModeRadios = Settings.System.getString(mContext.getContentResolver(),
|
||||
Settings.System.AIRPLANE_MODE_RADIOS);
|
||||
String airplaneModeRadios = Settings.Global.getString(mContext.getContentResolver(),
|
||||
Settings.Global.AIRPLANE_MODE_RADIOS);
|
||||
return airplaneModeRadios == null
|
||||
|| airplaneModeRadios.contains(Settings.System.RADIO_WIFI);
|
||||
|| airplaneModeRadios.contains(Settings.Global.RADIO_WIFI);
|
||||
}
|
||||
|
||||
private boolean isAirplaneToggleable() {
|
||||
String toggleableRadios = Settings.System.getString(mContext.getContentResolver(),
|
||||
Settings.System.AIRPLANE_MODE_TOGGLEABLE_RADIOS);
|
||||
String toggleableRadios = Settings.Global.getString(mContext.getContentResolver(),
|
||||
Settings.Global.AIRPLANE_MODE_TOGGLEABLE_RADIOS);
|
||||
return toggleableRadios != null
|
||||
&& toggleableRadios.contains(Settings.System.RADIO_WIFI);
|
||||
&& toggleableRadios.contains(Settings.Global.RADIO_WIFI);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1198,8 +1198,8 @@ public class WifiService extends IWifiManager.Stub {
|
||||
* @return {@code true} if airplane mode is on.
|
||||
*/
|
||||
private boolean isAirplaneModeOn() {
|
||||
return isAirplaneSensitive() && Settings.System.getInt(mContext.getContentResolver(),
|
||||
Settings.System.AIRPLANE_MODE_ON, 0) == 1;
|
||||
return isAirplaneSensitive() && Settings.Global.getInt(mContext.getContentResolver(),
|
||||
Settings.Global.AIRPLANE_MODE_ON, 0) == 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -1213,8 +1213,8 @@ public class WifiService extends IWifiManager.Stub {
|
||||
}
|
||||
pw.println("Wi-Fi is " + mWifiStateMachine.syncGetWifiStateByName());
|
||||
pw.println("Stay-awake conditions: " +
|
||||
Settings.System.getInt(mContext.getContentResolver(),
|
||||
Settings.System.STAY_ON_WHILE_PLUGGED_IN, 0));
|
||||
Settings.Global.getInt(mContext.getContentResolver(),
|
||||
Settings.Global.STAY_ON_WHILE_PLUGGED_IN, 0));
|
||||
pw.println();
|
||||
|
||||
pw.println("Internal state:");
|
||||
|
@ -384,8 +384,8 @@ public class ComprehensiveCountryDetector extends CountryDetectorBase {
|
||||
}
|
||||
|
||||
protected boolean isAirplaneModeOff() {
|
||||
return Settings.System.getInt(
|
||||
mContext.getContentResolver(), Settings.System.AIRPLANE_MODE_ON, 0) == 0;
|
||||
return Settings.Global.getInt(
|
||||
mContext.getContentResolver(), Settings.Global.AIRPLANE_MODE_ON, 0) == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user