Restrict access to background networks to CHANGE_NETWORK_STATE.

When a network goes into the background, tell netd to set the
network's permission to NETWORK. Also, close all TCP sockets on
that network, to prevent long-lived TCP connections from staying
on it and possibly continuing to use metered data.

Bug: 23113288
Change-Id: Ie89c1940b6739160e25c6e9022b8b977afb3e16e
This commit is contained in:
Lorenzo Colitti
2016-07-28 17:14:11 +09:00
parent 73e97b9fdb
commit b8d9f52adb
2 changed files with 37 additions and 10 deletions

View File

@@ -1825,6 +1825,16 @@ public class ConnectivityManager {
return (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
}
/* TODO: These permissions checks don't belong in client-side code. Move them to
* services.jar, possibly in com.android.server.net. */
/** {@hide} */
public static final boolean checkChangePermission(Context context) {
int uid = Binder.getCallingUid();
return Settings.checkAndNoteChangeNetworkStateOperation(context, uid, Settings
.getPackageNameForUid(context, uid), false /* throwException */);
}
/** {@hide} */
public static final void enforceChangePermission(Context context) {
int uid = Binder.getCallingUid();