diff --git a/core/java/android/net/ConnectivityManager.java b/core/java/android/net/ConnectivityManager.java
index 280ded6bcc94d..63352968322f3 100644
--- a/core/java/android/net/ConnectivityManager.java
+++ b/core/java/android/net/ConnectivityManager.java
@@ -524,5 +524,20 @@ public class ConnectivityManager
} catch (RemoteException e) {
return TETHER_ERROR_SERVICE_UNAVAIL;
}
- }
+ }
+
+ /**
+ * Ensure the device stays awake until we connect with the next network
+ * @param forWhome The name of the network going down for logging purposes
+ * @return {@code true} on success, {@code false} on failure
+ * {@hide}
+ */
+ public boolean requestNetworkTransitionWakelock(String forWhom) {
+ try {
+ mService.requestNetworkTransitionWakelock(forWhom);
+ return true;
+ } catch (RemoteException e) {
+ return false;
+ }
+ }
}
diff --git a/core/java/android/net/IConnectivityManager.aidl b/core/java/android/net/IConnectivityManager.aidl
index b05c2edd103ba..5a14cc9a090b5 100644
--- a/core/java/android/net/IConnectivityManager.aidl
+++ b/core/java/android/net/IConnectivityManager.aidl
@@ -72,4 +72,6 @@ interface IConnectivityManager
String[] getTetherableUsbRegexs();
String[] getTetherableWifiRegexs();
+
+ void requestNetworkTransitionWakelock(in String forWhom);
}
diff --git a/core/java/android/net/NetworkStateTracker.java b/core/java/android/net/NetworkStateTracker.java
index d5bcfcd3d1998..cd8e7f1464dd6 100644
--- a/core/java/android/net/NetworkStateTracker.java
+++ b/core/java/android/net/NetworkStateTracker.java
@@ -38,6 +38,7 @@ public interface NetworkStateTracker {
public static final int EVENT_ROAMING_CHANGED = 5;
public static final int EVENT_NETWORK_SUBTYPE_CHANGED = 6;
public static final int EVENT_RESTORE_DEFAULT_NETWORK = 7;
+ public static final int EVENT_CLEAR_NET_TRANSITION_WAKELOCK = 8;
/**
* Fetch NetworkInfo for the network
@@ -95,12 +96,6 @@ public interface NetworkStateTracker {
*/
public boolean isTeardownRequested();
- /**
- * Release the wakelock, if any, that may be held while handling a
- * disconnect operation.
- */
- public void releaseWakeLock();
-
public void startMonitoring();
/**
diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml
index a9dbaedf20d55..5cdfc1d7758e1 100644
--- a/core/res/AndroidManifest.xml
+++ b/core/res/AndroidManifest.xml
@@ -344,6 +344,13 @@
android:description="@string/permdesc_accountManagerService"
android:label="@string/permlab_accountManagerService" />
+
+
- * See {@link android.provider.Settings.Secure#WIFI_MOBILE_DATA_TRANSITION_WAKELOCK_TIMEOUT_MS}. - * This is the default value if a Settings.Secure value is not present. - */ - private static final int DEFAULT_WAKELOCK_TIMEOUT = 8000; - - // Wake lock used by driver-stop operation - private static PowerManager.WakeLock sDriverStopWakeLock; // Wake lock used by other operations private static PowerManager.WakeLock sWakeLock; @@ -164,7 +151,6 @@ public class WifiService extends IWifiManager.Stub { private static final int MESSAGE_DISABLE_WIFI = 1; private static final int MESSAGE_STOP_WIFI = 2; private static final int MESSAGE_START_WIFI = 3; - private static final int MESSAGE_RELEASE_WAKELOCK = 4; private static final int MESSAGE_UPDATE_STATE = 5; private static final int MESSAGE_START_ACCESS_POINT = 6; private static final int MESSAGE_STOP_ACCESS_POINT = 7; @@ -238,7 +224,6 @@ public class WifiService extends IWifiManager.Stub { PowerManager powerManager = (PowerManager)mContext.getSystemService(Context.POWER_SERVICE); sWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, WAKELOCK_TAG); - sDriverStopWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, WAKELOCK_TAG); mContext.registerReceiver( new BroadcastReceiver() { @@ -293,7 +278,10 @@ public class WifiService extends IWifiManager.Stub { IBinder b = ServiceManager.getService(Context.NETWORKMANAGEMENT_SERVICE); INetworkManagementService service = INetworkManagementService.Stub.asInterface(b); - mCm = (ConnectivityManager)mContext.getSystemService(Context.CONNECTIVITY_SERVICE); + if (mCm == null) { + mCm = (ConnectivityManager)mContext.getSystemService(Context.CONNECTIVITY_SERVICE); + } + mWifiRegexs = mCm.getTetherableWifiRegexs(); for (String intf : available) { @@ -1827,19 +1815,12 @@ public class WifiService extends IWifiManager.Stub { sWakeLock.acquire(); sendStartMessage(strongestLockMode == WifiManager.WIFI_MODE_SCAN_ONLY); } else if (!mWifiStateTracker.isDriverStopped()) { - int wakeLockTimeout = - Settings.Secure.getInt( - mContext.getContentResolver(), - Settings.Secure.WIFI_MOBILE_DATA_TRANSITION_WAKELOCK_TIMEOUT_MS, - DEFAULT_WAKELOCK_TIMEOUT); - /* - * We are assuming that ConnectivityService can make - * a transition to cellular data within wakeLockTimeout time. - * The wakelock is released by the delayed message. - */ - sDriverStopWakeLock.acquire(); + if (mCm == null) { + mCm = (ConnectivityManager)mContext. + getSystemService(Context.CONNECTIVITY_SERVICE); + } + mCm.requestNetworkTransitionWakelock(TAG); mWifiHandler.sendEmptyMessage(MESSAGE_STOP_WIFI); - mWifiHandler.sendEmptyMessageDelayed(MESSAGE_RELEASE_WAKELOCK, wakeLockTimeout); } } else { sWakeLock.acquire(); @@ -1925,10 +1906,6 @@ public class WifiService extends IWifiManager.Stub { // don't release wakelock break; - case MESSAGE_RELEASE_WAKELOCK: - sDriverStopWakeLock.release(); - break; - case MESSAGE_START_ACCESS_POINT: setWifiApEnabledBlocking(true, msg.arg1, diff --git a/wifi/java/android/net/wifi/WifiStateTracker.java b/wifi/java/android/net/wifi/WifiStateTracker.java index 73cba9383dae0..2bd5640e60528 100644 --- a/wifi/java/android/net/wifi/WifiStateTracker.java +++ b/wifi/java/android/net/wifi/WifiStateTracker.java @@ -763,21 +763,6 @@ public class WifiStateTracker extends Handler implements NetworkStateTracker { } } - /** - * We release the wakelock in WifiService - * using a timer. - * - * TODO: - * Releasing wakelock using both timer and - * a call from ConnectivityService requires - * a rethink. We had problems where WifiService - * could keep a wakelock forever if we delete - * messages in the asynchronous call - * from ConnectivityService - */ - public void releaseWakeLock() { - } - /** * Tracks the WPA supplicant states to detect "loop" situations. * @param newSupplicantState The new WPA supplicant state.