Tethering and Data Saver: There Can Be Only One!

If tethering is on when Data Saver mode is turned on, tethering should
be disabled, and vice-versa.

BUG: 28313291
Change-Id: I7f3dadbd97ea1492ab76b41043dea7487c1db02d
This commit is contained in:
Felipe Leme
2016-04-25 14:41:31 -07:00
parent 40d1fb87a4
commit 9842878b75

View File

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