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:
@@ -21,6 +21,7 @@ import static com.android.internal.util.Preconditions.checkNotNull;
|
||||
import android.annotation.SdkConstant;
|
||||
import android.annotation.SdkConstant.SdkConstantType;
|
||||
import android.os.Binder;
|
||||
import android.os.Build.VERSION_CODES;
|
||||
import android.os.RemoteException;
|
||||
|
||||
import java.net.InetAddress;
|
||||
@@ -494,16 +495,19 @@ public class ConnectivityManager {
|
||||
* <p>
|
||||
* All applications that have background services that use the network
|
||||
* 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.
|
||||
*/
|
||||
@Deprecated
|
||||
public boolean getBackgroundDataSetting() {
|
||||
try {
|
||||
return mService.getBackgroundDataSetting();
|
||||
} catch (RemoteException e) {
|
||||
// Err on the side of safety
|
||||
return false;
|
||||
}
|
||||
// assume that background data is allowed; final authority is
|
||||
// NetworkInfo which may be blocked.
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -516,11 +520,9 @@ public class ConnectivityManager {
|
||||
* @see #getBackgroundDataSetting()
|
||||
* @hide
|
||||
*/
|
||||
@Deprecated
|
||||
public void setBackgroundDataSetting(boolean allowBackgroundData) {
|
||||
try {
|
||||
mService.setBackgroundDataSetting(allowBackgroundData);
|
||||
} catch (RemoteException e) {
|
||||
}
|
||||
// ignored
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -63,10 +63,6 @@ interface IConnectivityManager
|
||||
|
||||
boolean requestRouteToHostAddress(int networkType, in byte[] hostAddress);
|
||||
|
||||
boolean getBackgroundDataSetting();
|
||||
|
||||
void setBackgroundDataSetting(boolean allowBackgroundData);
|
||||
|
||||
boolean getMobileDataEnabled();
|
||||
|
||||
void setMobileDataEnabled(boolean enabled);
|
||||
|
||||
@@ -163,8 +163,6 @@ public class ConnectivityService extends IConnectivityManager.Stub {
|
||||
private boolean mTestMode;
|
||||
private static ConnectivityService sServiceInstance;
|
||||
|
||||
private AtomicBoolean mBackgroundDataEnabled = new AtomicBoolean(true);
|
||||
|
||||
private INetworkManagementService mNetd;
|
||||
private INetworkPolicyManager mPolicyManager;
|
||||
|
||||
@@ -212,13 +210,6 @@ public class ConnectivityService extends IConnectivityManager.Stub {
|
||||
private static final int EVENT_INET_CONDITION_HOLD_END =
|
||||
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
|
||||
* arg1 = ENBALED or DISABLED
|
||||
@@ -317,9 +308,6 @@ public class ConnectivityService extends IConnectivityManager.Stub {
|
||||
handlerThread.start();
|
||||
mHandler = new MyHandler(handlerThread.getLooper());
|
||||
|
||||
mBackgroundDataEnabled.set(Settings.Secure.getInt(context.getContentResolver(),
|
||||
Settings.Secure.BACKGROUND_DATA, 1) == 1);
|
||||
|
||||
// setup our unique device name
|
||||
if (TextUtils.isEmpty(SystemProperties.get("net.hostname"))) {
|
||||
String id = Settings.Secure.getString(context.getContentResolver(),
|
||||
@@ -1225,35 +1213,6 @@ public class ConnectivityService extends IConnectivityManager.Stub {
|
||||
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()
|
||||
*/
|
||||
@@ -2268,12 +2227,6 @@ public class ConnectivityService extends IConnectivityManager.Stub {
|
||||
handleSetNetworkPreference(preference);
|
||||
break;
|
||||
}
|
||||
case EVENT_SET_BACKGROUND_DATA:
|
||||
{
|
||||
boolean enabled = (msg.arg1 == ENABLED);
|
||||
handleSetBackgroundData(enabled);
|
||||
break;
|
||||
}
|
||||
case EVENT_SET_MOBILE_DATA:
|
||||
{
|
||||
boolean enabled = (msg.arg1 == ENABLED);
|
||||
|
||||
Reference in New Issue
Block a user