summaryrefslogtreecommitdiffstats
path: root/packages/SettingsProvider
diff options
context:
space:
mode:
authorChris Tate <ctate@android.com>2015-08-10 22:59:28 +0000
committerAndroid Git Automerger <android-git-automerger@android.com>2015-08-10 22:59:28 +0000
commitd4c0b52e2a425dbc6e3794aae33595959453e777 (patch)
tree919bfb04d0c27f83c4301b171a7ee02592d71e70 /packages/SettingsProvider
parent53c8948044a92a1fc84b273252a3c2a7a6ff971c (diff)
parent1e05bc6f77b9e609df598ef0aed20a0ef81848a1 (diff)
downloadframeworks_base-d4c0b52e2a425dbc6e3794aae33595959453e777.zip
frameworks_base-d4c0b52e2a425dbc6e3794aae33595959453e777.tar.gz
frameworks_base-d4c0b52e2a425dbc6e3794aae33595959453e777.tar.bz2
am 1e05bc6f: am 5ca842ae: am 5d05a24c: Merge "Fix wifi disable during restore" into mnc-dev
* commit '1e05bc6f77b9e609df598ef0aed20a0ef81848a1': Fix wifi disable during restore
Diffstat (limited to 'packages/SettingsProvider')
-rw-r--r--packages/SettingsProvider/src/com/android/providers/settings/SettingsBackupAgent.java65
1 files changed, 49 insertions, 16 deletions
diff --git a/packages/SettingsProvider/src/com/android/providers/settings/SettingsBackupAgent.java b/packages/SettingsProvider/src/com/android/providers/settings/SettingsBackupAgent.java
index e74334b..b9a9c24 100644
--- a/packages/SettingsProvider/src/com/android/providers/settings/SettingsBackupAgent.java
+++ b/packages/SettingsProvider/src/com/android/providers/settings/SettingsBackupAgent.java
@@ -148,7 +148,10 @@ public class SettingsBackupAgent extends BackupAgentHelper {
private WifiManager mWfm;
private static String mWifiConfigFile;
+ // Chain of asynchronous operations used when rewriting the wifi supplicant config file
+ WifiDisableRunnable mWifiDisable = null;
WifiRestoreRunnable mWifiRestore = null;
+ int mRetainedWifiState; // used only during config file rewrite
// Class for capturing a network definition from the wifi supplicant config file
static class Network {
@@ -407,9 +410,47 @@ public class SettingsBackupAgent extends BackupAgentHelper {
writeNewChecksums(stateChecksums, newState);
}
+ class WifiDisableRunnable implements Runnable {
+ final WifiRestoreRunnable mNextPhase;
+
+ public WifiDisableRunnable(WifiRestoreRunnable next) {
+ mNextPhase = next;
+ }
+
+ @Override
+ public void run() {
+ if (DEBUG_BACKUP) {
+ Log.v(TAG, "Disabling wifi during restore");
+ }
+ final ContentResolver cr = getContentResolver();
+ final int scanAlways = Settings.Global.getInt(cr,
+ Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE, 0);
+ final int retainedWifiState = enableWifi(false);
+ if (scanAlways != 0) {
+ Settings.Global.putInt(cr,
+ Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE, 0);
+ }
+
+ // Tell the final stage how to clean up after itself
+ mNextPhase.setPriorState(retainedWifiState, scanAlways);
+
+ // And run it after a modest pause to give broadcasts and content
+ // observers time an opportunity to run on this looper thread, so
+ // that the wifi stack actually goes all the way down.
+ new Handler(getMainLooper()).postDelayed(mNextPhase, 2500);
+ }
+ }
+
class WifiRestoreRunnable implements Runnable {
private byte[] restoredSupplicantData;
private byte[] restoredWifiConfigFile;
+ private int retainedWifiState; // provided by disable stage
+ private int scanAlways; // provided by disable stage
+
+ void setPriorState(int retainedState, int always) {
+ retainedWifiState = retainedState;
+ scanAlways = always;
+ }
void incorporateWifiSupplicant(BackupDataInput data) {
restoredSupplicantData = new byte[data.getDataSize()];
@@ -437,20 +478,8 @@ public class SettingsBackupAgent extends BackupAgentHelper {
public void run() {
if (restoredSupplicantData != null || restoredWifiConfigFile != null) {
if (DEBUG_BACKUP) {
- Log.v(TAG, "Starting deferred restore of wifi data");
- }
- final ContentResolver cr = getContentResolver();
- final int scanAlways = Settings.Global.getInt(cr,
- Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE, 0);
- final int retainedWifiState = enableWifi(false);
- if (scanAlways != 0) {
- Settings.Global.putInt(cr,
- Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE, 0);
+ Log.v(TAG, "Applying restored wifi data");
}
- // !!! Give the wifi stack a moment to quiesce. We've observed the
- // response to disabling WIFI_SCAN_ALWAYS_AVAILABLE taking more
- // than 1500ms, so we wait a generous 2500 here before proceeding.
- try { Thread.sleep(2500); } catch (InterruptedException e) {}
if (restoredSupplicantData != null) {
restoreWifiSupplicant(FILE_WIFI_SUPPLICANT,
restoredSupplicantData, restoredSupplicantData.length);
@@ -465,7 +494,7 @@ public class SettingsBackupAgent extends BackupAgentHelper {
}
// restore the previous WIFI state.
if (scanAlways != 0) {
- Settings.Global.putInt(cr,
+ Settings.Global.putInt(getContentResolver(),
Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE, scanAlways);
}
enableWifi(retainedWifiState == WifiManager.WIFI_STATE_ENABLED ||
@@ -479,6 +508,7 @@ public class SettingsBackupAgent extends BackupAgentHelper {
void initWifiRestoreIfNecessary() {
if (mWifiRestore == null) {
mWifiRestore = new WifiRestoreRunnable();
+ mWifiDisable = new WifiDisableRunnable(mWifiRestore);
}
}
@@ -518,13 +548,16 @@ public class SettingsBackupAgent extends BackupAgentHelper {
}
// If we have wifi data to restore, post a runnable to perform the
- // bounce-and-update operation a little ways in the future.
+ // bounce-and-update operation a little ways in the future. The
+ // 'disable' runnable brings down the stack and remembers its state,
+ // and in turn schedules the 'restore' runnable to do the rewrite
+ // and cleanup operations.
if (mWifiRestore != null) {
long wifiBounceDelayMillis = Settings.Global.getLong(
getContentResolver(),
Settings.Global.WIFI_BOUNCE_DELAY_OVERRIDE_MS,
WIFI_BOUNCE_DELAY_MILLIS);
- new Handler(getMainLooper()).postDelayed(mWifiRestore, wifiBounceDelayMillis);
+ new Handler(getMainLooper()).postDelayed(mWifiDisable, wifiBounceDelayMillis);
}
}