Merge "Bandwidth-related commands porting"

This commit is contained in:
Luke Huang
2018-09-13 03:01:22 +00:00
committed by Gerrit Code Review

View File

@@ -1560,10 +1560,11 @@ public class NetworkManagementService extends INetworkManagementService.Stub
try {
// TODO: support quota shared across interfaces
mConnector.execute("bandwidth", "setiquota", iface, quotaBytes);
mNetdService.bandwidthSetInterfaceQuota(iface, quotaBytes);
mActiveQuotas.put(iface, quotaBytes);
} catch (NativeDaemonConnectorException e) {
throw e.rethrowAsParcelableException();
} catch (RemoteException | ServiceSpecificException e) {
throw new IllegalStateException(e);
}
synchronized (mTetheringStatsProviders) {
@@ -1594,9 +1595,9 @@ public class NetworkManagementService extends INetworkManagementService.Stub
try {
// TODO: support quota shared across interfaces
mConnector.execute("bandwidth", "removeiquota", iface);
} catch (NativeDaemonConnectorException e) {
throw e.rethrowAsParcelableException();
mNetdService.bandwidthRemoveInterfaceQuota(iface);
} catch (RemoteException | ServiceSpecificException e) {
throw new IllegalStateException(e);
}
synchronized (mTetheringStatsProviders) {
@@ -1628,10 +1629,10 @@ public class NetworkManagementService extends INetworkManagementService.Stub
try {
// TODO: support alert shared across interfaces
mConnector.execute("bandwidth", "setinterfacealert", iface, alertBytes);
mNetdService.bandwidthSetInterfaceAlert(iface, alertBytes);
mActiveAlerts.put(iface, alertBytes);
} catch (NativeDaemonConnectorException e) {
throw e.rethrowAsParcelableException();
} catch (RemoteException | ServiceSpecificException e) {
throw new IllegalStateException(e);
}
}
}
@@ -1648,10 +1649,10 @@ public class NetworkManagementService extends INetworkManagementService.Stub
try {
// TODO: support alert shared across interfaces
mConnector.execute("bandwidth", "removeinterfacealert", iface);
mNetdService.bandwidthRemoveInterfaceAlert(iface);
mActiveAlerts.remove(iface);
} catch (NativeDaemonConnectorException e) {
throw e.rethrowAsParcelableException();
} catch (RemoteException | ServiceSpecificException e) {
throw new IllegalStateException(e);
}
}
}
@@ -1661,18 +1662,15 @@ public class NetworkManagementService extends INetworkManagementService.Stub
mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
try {
mConnector.execute("bandwidth", "setglobalalert", alertBytes);
} catch (NativeDaemonConnectorException e) {
throw e.rethrowAsParcelableException();
mNetdService.bandwidthSetGlobalAlert(alertBytes);
} catch (RemoteException | ServiceSpecificException e) {
throw new IllegalStateException(e);
}
}
private void setUidOnMeteredNetworkList(int uid, boolean blacklist, boolean enable) {
mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
final String chain = blacklist ? "naughtyapps" : "niceapps";
final String suffix = enable ? "add" : "remove";
synchronized (mQuotaLock) {
boolean oldEnable;
SparseBooleanArray quotaList;
@@ -1687,7 +1685,19 @@ public class NetworkManagementService extends INetworkManagementService.Stub
Trace.traceBegin(Trace.TRACE_TAG_NETWORK, "inetd bandwidth");
try {
mConnector.execute("bandwidth", suffix + chain, uid);
if (blacklist) {
if (enable) {
mNetdService.bandwidthAddNaughtyApp(uid);
} else {
mNetdService.bandwidthRemoveNaughtyApp(uid);
}
} else {
if (enable) {
mNetdService.bandwidthAddNiceApp(uid);
} else {
mNetdService.bandwidthRemoveNiceApp(uid);
}
}
synchronized (mRulesLock) {
if (enable) {
quotaList.put(uid, true);
@@ -1695,8 +1705,8 @@ public class NetworkManagementService extends INetworkManagementService.Stub
quotaList.delete(uid);
}
}
} catch (NativeDaemonConnectorException e) {
throw e.rethrowAsParcelableException();
} catch (RemoteException | ServiceSpecificException e) {
throw new IllegalStateException(e);
} finally {
Trace.traceEnd(Trace.TRACE_TAG_NETWORK);
}