Merge "Background data notification, API clean up."

This commit is contained in:
Jeff Sharkey
2011-08-18 15:01:10 -07:00
committed by Android (Google) Code Review
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.SdkConstantType;
import android.os.Binder;
import android.os.Build.VERSION_CODES;
import android.os.RemoteException;
import java.net.InetAddress;
@@ -503,16 +504,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;
}
/**
@@ -525,11 +529,9 @@ public class ConnectivityManager {
* @see #getBackgroundDataSetting()
* @hide
*/
@Deprecated
public void setBackgroundDataSetting(boolean allowBackgroundData) {
try {
mService.setBackgroundDataSetting(allowBackgroundData);
} catch (RemoteException e) {
}
// ignored
}
/**

View File

@@ -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);

View File

@@ -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(),
@@ -1208,35 +1196,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()
*/
@@ -2273,12 +2232,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);