Merge change 9097
* changes: Wifi: Add support for enabling Wifi while in airplane mode.
This commit is contained in:
@@ -878,6 +878,17 @@ public final class Settings {
|
||||
*/
|
||||
public static final String AIRPLANE_MODE_RADIOS = "airplane_mode_radios";
|
||||
|
||||
/**
|
||||
* A comma separated list of radios that should to be disabled when airplane mode
|
||||
* is on, but can be manually reenabled by the user. For example, if RADIO_WIFI is
|
||||
* added to both AIRPLANE_MODE_RADIOS and AIRPLANE_MODE_TOGGLEABLE_RADIOS, then Wifi
|
||||
* will be turned off when entering airplane mode, but the user will be able to reenable
|
||||
* Wifi in the Settings app.
|
||||
*
|
||||
* {@hide}
|
||||
*/
|
||||
public static final String AIRPLANE_MODE_TOGGLEABLE_RADIOS = "airplane_mode_toggleable_radios";
|
||||
|
||||
/**
|
||||
* The policy for deciding when Wi-Fi should go to sleep (which will in
|
||||
* turn switch to using the mobile data as an Internet connection).
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
<bool name="def_airplane_mode_on">false</bool>
|
||||
<!-- Comma-separated list of bluetooth, wifi, and cell. -->
|
||||
<string name="def_airplane_mode_radios" translatable="false">cell,bluetooth,wifi</string>
|
||||
<string name="airplane_mode_toggleable_radios" translatable="false">wifi</string>
|
||||
<bool name="def_auto_time">true</bool>
|
||||
<bool name="def_accelerometer_rotation">true</bool>
|
||||
<!-- Default screen brightness, from 0 to 255. 102 is 40%. -->
|
||||
|
||||
@@ -64,7 +64,7 @@ public class DatabaseHelper extends SQLiteOpenHelper {
|
||||
|
||||
private static final String TAG = "SettingsProvider";
|
||||
private static final String DATABASE_NAME = "settings.db";
|
||||
private static final int DATABASE_VERSION = 37;
|
||||
private static final int DATABASE_VERSION = 38;
|
||||
|
||||
private Context mContext;
|
||||
|
||||
@@ -435,6 +435,21 @@ public class DatabaseHelper extends SQLiteOpenHelper {
|
||||
upgradeVersion = 36;
|
||||
}
|
||||
|
||||
if (upgradeVersion == 37) {
|
||||
db.beginTransaction();
|
||||
try {
|
||||
SQLiteStatement stmt = db.compileStatement("INSERT OR IGNORE INTO system(name,value)"
|
||||
+ " VALUES(?,?);");
|
||||
loadStringSetting(stmt, Settings.System.AIRPLANE_MODE_TOGGLEABLE_RADIOS,
|
||||
R.string.airplane_mode_toggleable_radios);
|
||||
stmt.close();
|
||||
db.setTransactionSuccessful();
|
||||
} finally {
|
||||
db.endTransaction();
|
||||
}
|
||||
upgradeVersion = 38;
|
||||
}
|
||||
|
||||
if (upgradeVersion != currentVersion) {
|
||||
Log.w(TAG, "Got stuck trying to upgrade from version " + upgradeVersion
|
||||
+ ", must wipe the settings provider");
|
||||
@@ -662,6 +677,9 @@ public class DatabaseHelper extends SQLiteOpenHelper {
|
||||
loadStringSetting(stmt, Settings.System.AIRPLANE_MODE_RADIOS,
|
||||
R.string.def_airplane_mode_radios);
|
||||
|
||||
loadStringSetting(stmt, Settings.System.AIRPLANE_MODE_TOGGLEABLE_RADIOS,
|
||||
R.string.airplane_mode_toggleable_radios);
|
||||
|
||||
loadBooleanSetting(stmt, Settings.System.AUTO_TIME,
|
||||
R.bool.def_auto_time); // Sync time to NITZ
|
||||
|
||||
|
||||
@@ -93,6 +93,9 @@ public class WifiService extends IWifiManager.Stub {
|
||||
private boolean mDeviceIdle;
|
||||
private int mPluggedType;
|
||||
|
||||
// true if the user enabled Wifi while in airplane mode
|
||||
private boolean mAirplaneModeOverwridden;
|
||||
|
||||
private final LockList mLocks = new LockList();
|
||||
// some wifi lock statistics
|
||||
private int mFullLocksAcquired;
|
||||
@@ -219,6 +222,8 @@ public class WifiService extends IWifiManager.Stub {
|
||||
new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
// clear our flag indicating the user has overwridden airplane mode
|
||||
mAirplaneModeOverwridden = false;
|
||||
updateWifiState();
|
||||
}
|
||||
},
|
||||
@@ -292,6 +297,8 @@ public class WifiService extends IWifiManager.Stub {
|
||||
synchronized (mWifiHandler) {
|
||||
sWakeLock.acquire();
|
||||
mLastEnableUid = Binder.getCallingUid();
|
||||
// set a flag if the user is enabling Wifi while in airplane mode
|
||||
mAirplaneModeOverwridden = (enable && isAirplaneModeOn() && isAirplaneToggleable());
|
||||
sendEnableMessage(enable, true, Binder.getCallingUid());
|
||||
}
|
||||
|
||||
@@ -312,7 +319,7 @@ public class WifiService extends IWifiManager.Stub {
|
||||
if (mWifiState == eventualWifiState) {
|
||||
return true;
|
||||
}
|
||||
if (enable && isAirplaneModeOn()) {
|
||||
if (enable && isAirplaneModeOn() && !mAirplaneModeOverwridden) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1495,7 +1502,7 @@ public class WifiService extends IWifiManager.Stub {
|
||||
|
||||
private void updateWifiState() {
|
||||
boolean wifiEnabled = getPersistedWifiEnabled();
|
||||
boolean airplaneMode = isAirplaneModeOn();
|
||||
boolean airplaneMode = isAirplaneModeOn() && !mAirplaneModeOverwridden;
|
||||
boolean lockHeld = mLocks.hasLocks();
|
||||
int strongestLockMode;
|
||||
boolean wifiShouldBeEnabled = wifiEnabled && !airplaneMode;
|
||||
@@ -1559,6 +1566,13 @@ public class WifiService extends IWifiManager.Stub {
|
||||
|| airplaneModeRadios.contains(Settings.System.RADIO_WIFI);
|
||||
}
|
||||
|
||||
private boolean isAirplaneToggleable() {
|
||||
String toggleableRadios = Settings.System.getString(mContext.getContentResolver(),
|
||||
Settings.System.AIRPLANE_MODE_TOGGLEABLE_RADIOS);
|
||||
return toggleableRadios != null
|
||||
&& toggleableRadios.contains(Settings.System.RADIO_WIFI);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if Wi-Fi is sensitive to airplane mode, and airplane mode is
|
||||
* currently on.
|
||||
|
||||
Reference in New Issue
Block a user