Merge "Background data notification, API clean up."
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;
|
||||||
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;
|
||||||
@@ -503,16 +504,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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -525,11 +529,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) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
@@ -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(),
|
||||||
@@ -1208,35 +1196,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()
|
||||||
*/
|
*/
|
||||||
@@ -2273,12 +2232,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);
|
||||||
|
|||||||
Reference in New Issue
Block a user