Background data notification, API clean up.

When restricting background data, show ongoing notification to give
easy access to re-enable. Deprecate getBackgroundDataSetting() API
to always return true, since NetworkInfo.isConnected() is new source
of truth. Handle upgrade path by reading from existing secure value,
and kick one last broadcast when changing value. Remove background
data code from ConnectivityService.

Remove warning alerts, since they push ifaces into restricted list;
should only happen when iface has limit.

Bug: 5163559, 5129421
Change-Id: I0064d9d643656a4d32aaae51d4a58bce49fe295f
This commit is contained in:
Jeff Sharkey
2011-08-16 14:37:57 -07:00
parent 9c11e89fe2
commit 39c01ebcce
3 changed files with 12 additions and 61 deletions

View File

@@ -21,6 +21,7 @@ import static com.android.internal.util.Preconditions.checkNotNull;
import android.annotation.SdkConstant; import android.annotation.SdkConstant;
import android.annotation.SdkConstant.SdkConstantType; import android.annotation.SdkConstant.SdkConstantType;
import android.os.Binder; import android.os.Binder;
import android.os.Build.VERSION_CODES;
import android.os.RemoteException; import android.os.RemoteException;
import java.net.InetAddress; import java.net.InetAddress;
@@ -494,16 +495,19 @@ public class ConnectivityManager {
* <p> * <p>
* All applications that have background services that use the network * All applications that have background services that use the network
* should listen to {@link #ACTION_BACKGROUND_DATA_SETTING_CHANGED}. * should listen to {@link #ACTION_BACKGROUND_DATA_SETTING_CHANGED}.
* <p>
* As of {@link VERSION_CODES#ICE_CREAM_SANDWICH}, availability of
* background data depends on several combined factors, and this method will
* always return {@code true}. Instead, when background data is unavailable,
* {@link #getActiveNetworkInfo()} will now appear disconnected.
* *
* @return Whether background data usage is allowed. * @return Whether background data usage is allowed.
*/ */
@Deprecated
public boolean getBackgroundDataSetting() { public boolean getBackgroundDataSetting() {
try { // assume that background data is allowed; final authority is
return mService.getBackgroundDataSetting(); // NetworkInfo which may be blocked.
} catch (RemoteException e) { return true;
// Err on the side of safety
return false;
}
} }
/** /**
@@ -516,11 +520,9 @@ public class ConnectivityManager {
* @see #getBackgroundDataSetting() * @see #getBackgroundDataSetting()
* @hide * @hide
*/ */
@Deprecated
public void setBackgroundDataSetting(boolean allowBackgroundData) { public void setBackgroundDataSetting(boolean allowBackgroundData) {
try { // ignored
mService.setBackgroundDataSetting(allowBackgroundData);
} catch (RemoteException e) {
}
} }
/** /**

View File

@@ -63,10 +63,6 @@ interface IConnectivityManager
boolean requestRouteToHostAddress(int networkType, in byte[] hostAddress); boolean requestRouteToHostAddress(int networkType, in byte[] hostAddress);
boolean getBackgroundDataSetting();
void setBackgroundDataSetting(boolean allowBackgroundData);
boolean getMobileDataEnabled(); boolean getMobileDataEnabled();
void setMobileDataEnabled(boolean enabled); void setMobileDataEnabled(boolean enabled);

View File

@@ -163,8 +163,6 @@ public class ConnectivityService extends IConnectivityManager.Stub {
private boolean mTestMode; private boolean mTestMode;
private static ConnectivityService sServiceInstance; private static ConnectivityService sServiceInstance;
private AtomicBoolean mBackgroundDataEnabled = new AtomicBoolean(true);
private INetworkManagementService mNetd; private INetworkManagementService mNetd;
private INetworkPolicyManager mPolicyManager; private INetworkPolicyManager mPolicyManager;
@@ -212,13 +210,6 @@ public class ConnectivityService extends IConnectivityManager.Stub {
private static final int EVENT_INET_CONDITION_HOLD_END = private static final int EVENT_INET_CONDITION_HOLD_END =
MAX_NETWORK_STATE_TRACKER_EVENT + 5; MAX_NETWORK_STATE_TRACKER_EVENT + 5;
/**
* used internally to set the background data preference
* arg1 = TRUE for enabled, FALSE for disabled
*/
private static final int EVENT_SET_BACKGROUND_DATA =
MAX_NETWORK_STATE_TRACKER_EVENT + 6;
/** /**
* used internally to set enable/disable cellular data * used internally to set enable/disable cellular data
* arg1 = ENBALED or DISABLED * arg1 = ENBALED or DISABLED
@@ -317,9 +308,6 @@ public class ConnectivityService extends IConnectivityManager.Stub {
handlerThread.start(); handlerThread.start();
mHandler = new MyHandler(handlerThread.getLooper()); mHandler = new MyHandler(handlerThread.getLooper());
mBackgroundDataEnabled.set(Settings.Secure.getInt(context.getContentResolver(),
Settings.Secure.BACKGROUND_DATA, 1) == 1);
// setup our unique device name // setup our unique device name
if (TextUtils.isEmpty(SystemProperties.get("net.hostname"))) { if (TextUtils.isEmpty(SystemProperties.get("net.hostname"))) {
String id = Settings.Secure.getString(context.getContentResolver(), String id = Settings.Secure.getString(context.getContentResolver(),
@@ -1225,35 +1213,6 @@ public class ConnectivityService extends IConnectivityManager.Stub {
return true; return true;
} }
/**
* @see ConnectivityManager#getBackgroundDataSetting()
*/
public boolean getBackgroundDataSetting() {
return mBackgroundDataEnabled.get();
}
/**
* @see ConnectivityManager#setBackgroundDataSetting(boolean)
*/
public void setBackgroundDataSetting(boolean allowBackgroundDataUsage) {
mContext.enforceCallingOrSelfPermission(
android.Manifest.permission.CHANGE_BACKGROUND_DATA_SETTING,
"ConnectivityService");
mBackgroundDataEnabled.set(allowBackgroundDataUsage);
mHandler.sendMessage(mHandler.obtainMessage(EVENT_SET_BACKGROUND_DATA,
(allowBackgroundDataUsage ? ENABLED : DISABLED), 0));
}
private void handleSetBackgroundData(boolean enabled) {
Settings.Secure.putInt(mContext.getContentResolver(),
Settings.Secure.BACKGROUND_DATA, enabled ? 1 : 0);
Intent broadcast = new Intent(
ConnectivityManager.ACTION_BACKGROUND_DATA_SETTING_CHANGED);
mContext.sendBroadcast(broadcast);
}
/** /**
* @see ConnectivityManager#getMobileDataEnabled() * @see ConnectivityManager#getMobileDataEnabled()
*/ */
@@ -2268,12 +2227,6 @@ public class ConnectivityService extends IConnectivityManager.Stub {
handleSetNetworkPreference(preference); handleSetNetworkPreference(preference);
break; break;
} }
case EVENT_SET_BACKGROUND_DATA:
{
boolean enabled = (msg.arg1 == ENABLED);
handleSetBackgroundData(enabled);
break;
}
case EVENT_SET_MOBILE_DATA: case EVENT_SET_MOBILE_DATA:
{ {
boolean enabled = (msg.arg1 == ENABLED); boolean enabled = (msg.arg1 == ENABLED);