Skip to content

Commit c09cdce

Browse files
author
Christopher Tate
committed
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
1 parent 009ea5a commit c09cdce

File tree

10 files changed

+44
-41
lines changed

10 files changed

+44
-41
lines changed

core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/ConnectivityManagerTestActivity.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import android.os.PowerManager;
3737
import android.os.ServiceManager;
3838
import android.os.SystemClock;
39+
import android.os.UserHandle;
3940
import android.provider.Settings;
4041
import android.util.Log;
4142
import android.view.KeyEvent;
@@ -696,12 +697,12 @@ private void sleep(long sleeptime) {
696697
*/
697698
public void setAirplaneMode(Context context, boolean enableAM) {
698699
//set the airplane mode
699-
Settings.System.putInt(context.getContentResolver(), Settings.System.AIRPLANE_MODE_ON,
700+
Settings.Global.putInt(context.getContentResolver(), Settings.Global.AIRPLANE_MODE_ON,
700701
enableAM ? 1 : 0);
701702
// Post the intent
702703
Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
703704
intent.putExtra("state", enableAM);
704-
context.sendBroadcast(intent);
705+
context.sendBroadcastAsUser(intent, UserHandle.ALL);
705706
}
706707

707708
protected static String convertToQuotedString(String string) {

core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/functional/ConnectivityManagerMobileTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ public void setUp() throws Exception {
5959
wl = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "CMWakeLock");
6060
wl.acquire();
6161
// Each test case will start with cellular connection
62-
if (Settings.System.getInt(getInstrumentation().getContext().getContentResolver(),
63-
Settings.System.AIRPLANE_MODE_ON) == 1) {
62+
if (Settings.Global.getInt(getInstrumentation().getContext().getContentResolver(),
63+
Settings.Global.AIRPLANE_MODE_ON) == 1) {
6464
log("airplane is not disabled, disable it.");
6565
cmActivity.setAirplaneMode(getInstrumentation().getContext(), false);
6666
}
@@ -84,8 +84,8 @@ public void tearDown() throws Exception {
8484
wl.release();
8585
cmActivity.removeConfiguredNetworksAndDisableWifi();
8686
// if airplane mode is set, disable it.
87-
if (Settings.System.getInt(getInstrumentation().getContext().getContentResolver(),
88-
Settings.System.AIRPLANE_MODE_ON) == 1) {
87+
if (Settings.Global.getInt(getInstrumentation().getContext().getContentResolver(),
88+
Settings.Global.AIRPLANE_MODE_ON) == 1) {
8989
log("disable airplane mode if it is enabled");
9090
cmActivity.setAirplaneMode(getInstrumentation().getContext(), false);
9191
}

core/tests/coretests/src/android/app/DownloadManagerBaseTest.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import android.net.wifi.WifiManager;
3030
import android.os.Environment;
3131
import android.os.ParcelFileDescriptor;
32+
import android.os.UserHandle;
3233
import android.os.ParcelFileDescriptor.AutoCloseInputStream;
3334
import android.os.SystemClock;
3435
import android.provider.Settings;
@@ -553,24 +554,24 @@ protected void setAirplaneModeOn(boolean enable) throws Exception {
553554
int state = enable ? 1 : 0;
554555

555556
// Change the system setting
556-
Settings.System.putInt(mContext.getContentResolver(), Settings.System.AIRPLANE_MODE_ON,
557+
Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.AIRPLANE_MODE_ON,
557558
state);
558559

559560
String timeoutMessage = "Timed out waiting for airplane mode to be " +
560561
(enable ? "enabled!" : "disabled!");
561562

562563
// wait for airplane mode to change state
563564
int currentWaitTime = 0;
564-
while (Settings.System.getInt(mContext.getContentResolver(),
565-
Settings.System.AIRPLANE_MODE_ON, -1) != state) {
565+
while (Settings.Global.getInt(mContext.getContentResolver(),
566+
Settings.Global.AIRPLANE_MODE_ON, -1) != state) {
566567
timeoutWait(currentWaitTime, DEFAULT_WAIT_POLL_TIME, DEFAULT_MAX_WAIT_TIME,
567568
timeoutMessage);
568569
}
569570

570571
// Post the intent
571572
Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
572573
intent.putExtra("state", true);
573-
mContext.sendBroadcast(intent);
574+
mContext.sendBroadcastAsUser(intent, UserHandle.ALL);
574575
}
575576

576577
/**

packages/SystemUI/src/com/android/systemui/statusbar/phone/QuickSettings.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import android.hardware.display.WifiDisplay;
3333
import android.hardware.display.WifiDisplayStatus;
3434
import android.net.Uri;
35+
import android.os.UserHandle;
3536
import android.provider.ContactsContract;
3637
import android.provider.Settings;
3738
import android.view.LayoutInflater;
@@ -147,7 +148,7 @@ private void setAirplaneModeState(boolean enabled) {
147148
// TODO: Sets the view to be "awaiting" if not already awaiting
148149

149150
// Change the system setting
150-
Settings.System.putInt(mContext.getContentResolver(), Settings.System.AIRPLANE_MODE_ON,
151+
Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.AIRPLANE_MODE_ON,
151152
enabled ? 1 : 0);
152153

153154
// TODO: Update the UI to reflect system setting
@@ -156,7 +157,7 @@ private void setAirplaneModeState(boolean enabled) {
156157
// Post the intent
157158
Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
158159
intent.putExtra("state", enabled);
159-
mContext.sendBroadcast(intent);
160+
mContext.sendBroadcastAsUser(intent, UserHandle.ALL);
160161
}
161162
// NetworkSignalChanged callback
162163
@Override

packages/SystemUI/src/com/android/systemui/statusbar/policy/AirplaneModeController.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,17 @@ public void onReceive(Context context, Intent intent) {
7474

7575
private boolean getAirplaneMode() {
7676
ContentResolver cr = mContext.getContentResolver();
77-
return 0 != Settings.System.getInt(cr, Settings.System.AIRPLANE_MODE_ON, 0);
77+
return 0 != Settings.Global.getInt(cr, Settings.Global.AIRPLANE_MODE_ON, 0);
7878
}
7979

8080
// TODO: Fix this racy API by adding something better to TelephonyManager or
8181
// ConnectivityService.
8282
private void unsafe(final boolean enabled) {
8383
AsyncTask.execute(new Runnable() {
8484
public void run() {
85-
Settings.System.putInt(
85+
Settings.Global.putInt(
8686
mContext.getContentResolver(),
87-
Settings.System.AIRPLANE_MODE_ON,
87+
Settings.Global.AIRPLANE_MODE_ON,
8888
enabled ? 1 : 0);
8989
Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
9090
intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);

packages/SystemUI/src/com/android/systemui/statusbar/policy/NetworkController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -509,8 +509,8 @@ private boolean hasService() {
509509
}
510510

511511
private void updateAirplaneMode() {
512-
mAirplaneMode = (Settings.System.getInt(mContext.getContentResolver(),
513-
Settings.System.AIRPLANE_MODE_ON, 0) == 1);
512+
mAirplaneMode = (Settings.Global.getInt(mContext.getContentResolver(),
513+
Settings.Global.AIRPLANE_MODE_ON, 0) == 1);
514514
}
515515

516516
private final void updateTelephonySignalStrength() {

policy/src/com/android/internal/policy/impl/GlobalActions.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public GlobalActions(Context context, WindowManagerFuncs windowManagerFuncs) {
115115
context.getSystemService(Context.CONNECTIVITY_SERVICE);
116116
mHasTelephony = cm.isNetworkSupported(ConnectivityManager.TYPE_MOBILE);
117117
mContext.getContentResolver().registerContentObserver(
118-
Settings.System.getUriFor(Settings.System.AIRPLANE_MODE_ON), true,
118+
Settings.Global.getUriFor(Settings.Global.AIRPLANE_MODE_ON), true,
119119
mAirplaneModeObserver);
120120
Vibrator vibrator = (Vibrator) mContext.getSystemService(Context.VIBRATOR_SERVICE);
121121
mHasVibrator = vibrator != null && vibrator.hasVibrator();
@@ -849,9 +849,9 @@ private void onAirplaneModeChanged() {
849849
// Let the service state callbacks handle the state.
850850
if (mHasTelephony) return;
851851

852-
boolean airplaneModeOn = Settings.System.getInt(
852+
boolean airplaneModeOn = Settings.Global.getInt(
853853
mContext.getContentResolver(),
854-
Settings.System.AIRPLANE_MODE_ON,
854+
Settings.Global.AIRPLANE_MODE_ON,
855855
0) == 1;
856856
mAirplaneState = airplaneModeOn ? ToggleAction.State.On : ToggleAction.State.Off;
857857
mAirplaneModeOn.updateState(mAirplaneState);
@@ -861,9 +861,9 @@ private void onAirplaneModeChanged() {
861861
* Change the airplane mode system setting
862862
*/
863863
private void changeAirplaneModeSystemSetting(boolean on) {
864-
Settings.System.putInt(
864+
Settings.Global.putInt(
865865
mContext.getContentResolver(),
866-
Settings.System.AIRPLANE_MODE_ON,
866+
Settings.Global.AIRPLANE_MODE_ON,
867867
on ? 1 : 0);
868868
Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
869869
intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);

services/java/com/android/server/BluetoothManagerService.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,12 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
7575

7676
private void registerForAirplaneMode(IntentFilter filter) {
7777
final ContentResolver resolver = mContext.getContentResolver();
78-
final String airplaneModeRadios = Settings.System.getString(resolver,
79-
Settings.System.AIRPLANE_MODE_RADIOS);
80-
final String toggleableRadios = Settings.System.getString(resolver,
81-
Settings.System.AIRPLANE_MODE_TOGGLEABLE_RADIOS);
78+
final String airplaneModeRadios = Settings.Global.getString(resolver,
79+
Settings.Global.AIRPLANE_MODE_RADIOS);
80+
final String toggleableRadios = Settings.Global.getString(resolver,
81+
Settings.Global.AIRPLANE_MODE_TOGGLEABLE_RADIOS);
8282
boolean mIsAirplaneSensitive = airplaneModeRadios == null ? true :
83-
airplaneModeRadios.contains(Settings.System.RADIO_BLUETOOTH);
83+
airplaneModeRadios.contains(Settings.Global.RADIO_BLUETOOTH);
8484
if (mIsAirplaneSensitive) {
8585
filter.addAction(Intent.ACTION_AIRPLANE_MODE_CHANGED);
8686
}
@@ -151,8 +151,8 @@ public void onReceive(Context context, Intent intent) {
151151
* Returns true if airplane mode is currently on
152152
*/
153153
private final boolean isAirplaneModeOn() {
154-
return Settings.System.getInt(mContext.getContentResolver(),
155-
Settings.System.AIRPLANE_MODE_ON, 0) == 1;
154+
return Settings.Global.getInt(mContext.getContentResolver(),
155+
Settings.Global.AIRPLANE_MODE_ON, 0) == 1;
156156
}
157157

158158
/**

services/java/com/android/server/WifiService.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,17 +1179,17 @@ private void registerForBroadcasts() {
11791179
}
11801180

11811181
private boolean isAirplaneSensitive() {
1182-
String airplaneModeRadios = Settings.System.getString(mContext.getContentResolver(),
1183-
Settings.System.AIRPLANE_MODE_RADIOS);
1182+
String airplaneModeRadios = Settings.Global.getString(mContext.getContentResolver(),
1183+
Settings.Global.AIRPLANE_MODE_RADIOS);
11841184
return airplaneModeRadios == null
1185-
|| airplaneModeRadios.contains(Settings.System.RADIO_WIFI);
1185+
|| airplaneModeRadios.contains(Settings.Global.RADIO_WIFI);
11861186
}
11871187

11881188
private boolean isAirplaneToggleable() {
1189-
String toggleableRadios = Settings.System.getString(mContext.getContentResolver(),
1190-
Settings.System.AIRPLANE_MODE_TOGGLEABLE_RADIOS);
1189+
String toggleableRadios = Settings.Global.getString(mContext.getContentResolver(),
1190+
Settings.Global.AIRPLANE_MODE_TOGGLEABLE_RADIOS);
11911191
return toggleableRadios != null
1192-
&& toggleableRadios.contains(Settings.System.RADIO_WIFI);
1192+
&& toggleableRadios.contains(Settings.Global.RADIO_WIFI);
11931193
}
11941194

11951195
/**
@@ -1198,8 +1198,8 @@ private boolean isAirplaneToggleable() {
11981198
* @return {@code true} if airplane mode is on.
11991199
*/
12001200
private boolean isAirplaneModeOn() {
1201-
return isAirplaneSensitive() && Settings.System.getInt(mContext.getContentResolver(),
1202-
Settings.System.AIRPLANE_MODE_ON, 0) == 1;
1201+
return isAirplaneSensitive() && Settings.Global.getInt(mContext.getContentResolver(),
1202+
Settings.Global.AIRPLANE_MODE_ON, 0) == 1;
12031203
}
12041204

12051205
@Override
@@ -1213,8 +1213,8 @@ protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
12131213
}
12141214
pw.println("Wi-Fi is " + mWifiStateMachine.syncGetWifiStateByName());
12151215
pw.println("Stay-awake conditions: " +
1216-
Settings.System.getInt(mContext.getContentResolver(),
1217-
Settings.System.STAY_ON_WHILE_PLUGGED_IN, 0));
1216+
Settings.Global.getInt(mContext.getContentResolver(),
1217+
Settings.Global.STAY_ON_WHILE_PLUGGED_IN, 0));
12181218
pw.println();
12191219

12201220
pw.println("Internal state:");

services/java/com/android/server/location/ComprehensiveCountryDetector.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,8 +384,8 @@ protected CountryDetectorBase createLocationBasedCountryDetector() {
384384
}
385385

386386
protected boolean isAirplaneModeOff() {
387-
return Settings.System.getInt(
388-
mContext.getContentResolver(), Settings.System.AIRPLANE_MODE_ON, 0) == 0;
387+
return Settings.Global.getInt(
388+
mContext.getContentResolver(), Settings.Global.AIRPLANE_MODE_ON, 0) == 0;
389389
}
390390

391391
/**

0 commit comments

Comments
 (0)