Merge "Tethering and Data Saver: There Can Be Only One!" into nyc-dev
am: 0db93ce
* commit '0db93cea0fef6aa73caa0ef422b8e0a4e45a24e5':
Tethering and Data Saver: There Can Be Only One!
Change-Id: I876c9a30e9451b1c346296c233068bdfb579f584
This commit is contained in:
@@ -52,6 +52,9 @@ interface INetworkPolicyManager {
|
||||
void setRestrictBackground(boolean restrictBackground);
|
||||
boolean getRestrictBackground();
|
||||
|
||||
/** Callback used to change internal state on tethering */
|
||||
void onTetheringChanged(String iface, boolean tethering);
|
||||
|
||||
/** Control which applications can be exempt from background data restrictions */
|
||||
void addRestrictBackgroundWhitelistedUid(int uid);
|
||||
void removeRestrictBackgroundWhitelistedUid(int uid);
|
||||
|
||||
@@ -31,7 +31,6 @@ import static android.net.NetworkCapabilities.NET_CAPABILITY_VALIDATED;
|
||||
import static android.net.NetworkPolicyManager.RULE_ALLOW_ALL;
|
||||
import static android.net.NetworkPolicyManager.RULE_REJECT_ALL;
|
||||
import static android.net.NetworkPolicyManager.RULE_REJECT_METERED;
|
||||
|
||||
import android.annotation.Nullable;
|
||||
import android.app.BroadcastOptions;
|
||||
import android.app.Notification;
|
||||
@@ -1382,6 +1381,10 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
||||
if (LOGD_RULES) {
|
||||
log("onRestrictBackgroundChanged(restrictBackground=" + restrictBackground + ")");
|
||||
}
|
||||
if (restrictBackground) {
|
||||
log("onRestrictBackgroundChanged(true): disabling tethering");
|
||||
mTethering.untetherAll();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1813,6 +1816,14 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
||||
pw.decreaseIndent();
|
||||
pw.println();
|
||||
|
||||
pw.println("Metered Interfaces:");
|
||||
pw.increaseIndent();
|
||||
for (String value : mMeteredIfaces) {
|
||||
pw.println(value);
|
||||
}
|
||||
pw.decreaseIndent();
|
||||
pw.println();
|
||||
|
||||
pw.println("Network Requests:");
|
||||
pw.increaseIndent();
|
||||
for (NetworkRequestInfo nri : mNetworkRequests.values()) {
|
||||
@@ -2568,7 +2579,14 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
||||
public int tether(String iface) {
|
||||
ConnectivityManager.enforceTetherChangePermission(mContext);
|
||||
if (isTetheringSupported()) {
|
||||
return mTethering.tether(iface);
|
||||
final int status = mTethering.tether(iface);
|
||||
if (status == ConnectivityManager.TETHER_ERROR_NO_ERROR) {
|
||||
try {
|
||||
mPolicyManager.onTetheringChanged(iface, true);
|
||||
} catch (RemoteException e) {
|
||||
}
|
||||
}
|
||||
return status;
|
||||
} else {
|
||||
return ConnectivityManager.TETHER_ERROR_UNSUPPORTED;
|
||||
}
|
||||
@@ -2579,7 +2597,14 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
||||
ConnectivityManager.enforceTetherChangePermission(mContext);
|
||||
|
||||
if (isTetheringSupported()) {
|
||||
return mTethering.untether(iface);
|
||||
final int status = mTethering.untether(iface);
|
||||
if (status == ConnectivityManager.TETHER_ERROR_NO_ERROR) {
|
||||
try {
|
||||
mPolicyManager.onTetheringChanged(iface, false);
|
||||
} catch (RemoteException e) {
|
||||
}
|
||||
}
|
||||
return status;
|
||||
} else {
|
||||
return ConnectivityManager.TETHER_ERROR_UNSUPPORTED;
|
||||
}
|
||||
|
||||
@@ -610,6 +610,13 @@ public class Tethering extends BaseNetworkObserver {
|
||||
return ConnectivityManager.TETHER_ERROR_NO_ERROR;
|
||||
}
|
||||
|
||||
public void untetherAll() {
|
||||
if (DBG) Log.d(TAG, "Untethering " + mIfaces);
|
||||
for (String iface : mIfaces.keySet()) {
|
||||
untether(iface);
|
||||
}
|
||||
}
|
||||
|
||||
public int getLastTetherError(String iface) {
|
||||
TetherInterfaceSM sm = null;
|
||||
synchronized (mPublicSync) {
|
||||
|
||||
@@ -1898,6 +1898,18 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTetheringChanged(String iface, boolean tethering) {
|
||||
// No need to enforce permission because setRestrictBackground() will do it.
|
||||
if (LOGD) Log.d(TAG, "onTetherStateChanged(" + iface + ", " + tethering + ")");
|
||||
synchronized (mRulesLock) {
|
||||
if (mRestrictBackground && tethering) {
|
||||
Log.d(TAG, "Tethering on (" + iface +"); disable Data Saver");
|
||||
setRestrictBackground(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRestrictBackground(boolean restrictBackground) {
|
||||
mContext.enforceCallingOrSelfPermission(MANAGE_NETWORK_POLICY, TAG);
|
||||
|
||||
Reference in New Issue
Block a user