Created a NETWORK trace tag.
Also applied it to a few critical paths on NetworkPolicyManagerService. BUG: 31281543 Change-Id: If27240d86c21e5b49b9595bfcbc90214126cf489
This commit is contained in:
@@ -81,6 +81,8 @@ public final class Trace {
|
|||||||
public static final long TRACE_TAG_SYSTEM_SERVER = 1L << 19;
|
public static final long TRACE_TAG_SYSTEM_SERVER = 1L << 19;
|
||||||
/** @hide */
|
/** @hide */
|
||||||
public static final long TRACE_TAG_DATABASE = 1L << 20;
|
public static final long TRACE_TAG_DATABASE = 1L << 20;
|
||||||
|
/** @hide */
|
||||||
|
public static final long TRACE_TAG_NETWORK = 1L << 21;
|
||||||
|
|
||||||
private static final long TRACE_TAG_NOT_READY = 1L << 63;
|
private static final long TRACE_TAG_NOT_READY = 1L << 63;
|
||||||
private static final int MAX_SECTION_NAME_LEN = 127;
|
private static final int MAX_SECTION_NAME_LEN = 127;
|
||||||
|
|||||||
@@ -141,6 +141,7 @@ import android.os.RemoteCallbackList;
|
|||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.os.ResultReceiver;
|
import android.os.ResultReceiver;
|
||||||
import android.os.ServiceManager;
|
import android.os.ServiceManager;
|
||||||
|
import android.os.Trace;
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
import android.os.UserManager;
|
import android.os.UserManager;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
@@ -570,6 +571,8 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void systemReady() {
|
public void systemReady() {
|
||||||
|
Trace.traceBegin(Trace.TRACE_TAG_NETWORK, "systemReady");
|
||||||
|
try {
|
||||||
if (!isBandwidthControlEnabled()) {
|
if (!isBandwidthControlEnabled()) {
|
||||||
Slog.w(TAG, "bandwidth controls disabled, unable to enforce policy");
|
Slog.w(TAG, "bandwidth controls disabled, unable to enforce policy");
|
||||||
return;
|
return;
|
||||||
@@ -665,7 +668,8 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
|||||||
MANAGE_NETWORK_POLICY, mHandler);
|
MANAGE_NETWORK_POLICY, mHandler);
|
||||||
|
|
||||||
// listen for configured wifi networks to be removed
|
// listen for configured wifi networks to be removed
|
||||||
final IntentFilter wifiConfigFilter = new IntentFilter(CONFIGURED_NETWORKS_CHANGED_ACTION);
|
final IntentFilter wifiConfigFilter =
|
||||||
|
new IntentFilter(CONFIGURED_NETWORKS_CHANGED_ACTION);
|
||||||
mContext.registerReceiver(mWifiConfigReceiver, wifiConfigFilter, null, mHandler);
|
mContext.registerReceiver(mWifiConfigReceiver, wifiConfigFilter, null, mHandler);
|
||||||
|
|
||||||
// listen for wifi state changes to catch metered hint
|
// listen for wifi state changes to catch metered hint
|
||||||
@@ -674,14 +678,21 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
|||||||
mContext.registerReceiver(mWifiStateReceiver, wifiStateFilter, null, mHandler);
|
mContext.registerReceiver(mWifiStateReceiver, wifiStateFilter, null, mHandler);
|
||||||
|
|
||||||
mUsageStats.addAppIdleStateChangeListener(new AppIdleStateChangeListener());
|
mUsageStats.addAppIdleStateChangeListener(new AppIdleStateChangeListener());
|
||||||
|
} finally {
|
||||||
|
Trace.traceEnd(Trace.TRACE_TAG_NETWORK);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final private IUidObserver mUidObserver = new IUidObserver.Stub() {
|
final private IUidObserver mUidObserver = new IUidObserver.Stub() {
|
||||||
@Override public void onUidStateChanged(int uid, int procState) throws RemoteException {
|
@Override public void onUidStateChanged(int uid, int procState) throws RemoteException {
|
||||||
|
Trace.traceBegin(Trace.TRACE_TAG_NETWORK, "onUidStateChanged");
|
||||||
|
try {
|
||||||
synchronized (mUidRulesFirstLock) {
|
synchronized (mUidRulesFirstLock) {
|
||||||
updateUidStateUL(uid, procState);
|
updateUidStateUL(uid, procState);
|
||||||
}
|
}
|
||||||
|
} finally {
|
||||||
|
Trace.traceEnd(Trace.TRACE_TAG_NETWORK);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void onUidGone(int uid) throws RemoteException {
|
@Override public void onUidGone(int uid) throws RemoteException {
|
||||||
@@ -2046,7 +2057,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
|||||||
// Must whitelist foreground apps before turning data saver mode on.
|
// Must whitelist foreground apps before turning data saver mode on.
|
||||||
// TODO: there is no need to iterate through all apps here, just those in the foreground,
|
// TODO: there is no need to iterate through all apps here, just those in the foreground,
|
||||||
// so it could call AM to get the UIDs of such apps, and iterate through them instead.
|
// so it could call AM to get the UIDs of such apps, and iterate through them instead.
|
||||||
updateRulesForAllAppsUL(TYPE_RESTRICT_BACKGROUND);
|
updateRulesForRestrictBackgroundUL();
|
||||||
try {
|
try {
|
||||||
if (!mNetworkManager.setDataSaverModeEnabled(mRestrictBackground)) {
|
if (!mNetworkManager.setDataSaverModeEnabled(mRestrictBackground)) {
|
||||||
Slog.e(TAG, "Could not change Data Saver Mode on NMS to " + mRestrictBackground);
|
Slog.e(TAG, "Could not change Data Saver Mode on NMS to " + mRestrictBackground);
|
||||||
@@ -2204,6 +2215,8 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
|||||||
public void setDeviceIdleMode(boolean enabled) {
|
public void setDeviceIdleMode(boolean enabled) {
|
||||||
mContext.enforceCallingOrSelfPermission(MANAGE_NETWORK_POLICY, TAG);
|
mContext.enforceCallingOrSelfPermission(MANAGE_NETWORK_POLICY, TAG);
|
||||||
|
|
||||||
|
Trace.traceBegin(Trace.TRACE_TAG_NETWORK, "setDeviceIdleMode");
|
||||||
|
try {
|
||||||
synchronized (mUidRulesFirstLock) {
|
synchronized (mUidRulesFirstLock) {
|
||||||
if (mDeviceIdleMode != enabled) {
|
if (mDeviceIdleMode != enabled) {
|
||||||
mDeviceIdleMode = enabled;
|
mDeviceIdleMode = enabled;
|
||||||
@@ -2219,6 +2232,9 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} finally {
|
||||||
|
Trace.traceEnd(Trace.TRACE_TAG_NETWORK);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private NetworkPolicy findPolicyForNetworkNL(NetworkIdentity ident) {
|
private NetworkPolicy findPolicyForNetworkNL(NetworkIdentity ident) {
|
||||||
@@ -2505,6 +2521,8 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
|||||||
* {@link #updateRulesForPowerRestrictionsUL(int)}
|
* {@link #updateRulesForPowerRestrictionsUL(int)}
|
||||||
*/
|
*/
|
||||||
private void updateUidStateUL(int uid, int uidState) {
|
private void updateUidStateUL(int uid, int uidState) {
|
||||||
|
Trace.traceBegin(Trace.TRACE_TAG_NETWORK, "updateUidStateUL");
|
||||||
|
try {
|
||||||
final int oldUidState = mUidState.get(uid, ActivityManager.PROCESS_STATE_CACHED_EMPTY);
|
final int oldUidState = mUidState.get(uid, ActivityManager.PROCESS_STATE_CACHED_EMPTY);
|
||||||
if (oldUidState != uidState) {
|
if (oldUidState != uidState) {
|
||||||
// state changed, push updated rules
|
// state changed, push updated rules
|
||||||
@@ -2525,6 +2543,9 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
|||||||
}
|
}
|
||||||
updateNetworkStats(uid, isUidStateForegroundUL(uidState));
|
updateNetworkStats(uid, isUidStateForegroundUL(uidState));
|
||||||
}
|
}
|
||||||
|
} finally {
|
||||||
|
Trace.traceEnd(Trace.TRACE_TAG_NETWORK);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void removeUidStateUL(int uid) {
|
private void removeUidStateUL(int uid) {
|
||||||
@@ -2576,8 +2597,13 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void updateRulesForPowerSaveUL() {
|
void updateRulesForPowerSaveUL() {
|
||||||
|
Trace.traceBegin(Trace.TRACE_TAG_NETWORK, "updateRulesForPowerSaveUL");
|
||||||
|
try {
|
||||||
updateRulesForWhitelistedPowerSaveUL(mRestrictPower, FIREWALL_CHAIN_POWERSAVE,
|
updateRulesForWhitelistedPowerSaveUL(mRestrictPower, FIREWALL_CHAIN_POWERSAVE,
|
||||||
mUidFirewallPowerSaveRules);
|
mUidFirewallPowerSaveRules);
|
||||||
|
} finally {
|
||||||
|
Trace.traceEnd(Trace.TRACE_TAG_NETWORK);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateRuleForRestrictPowerUL(int uid) {
|
void updateRuleForRestrictPowerUL(int uid) {
|
||||||
@@ -2585,8 +2611,13 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void updateRulesForDeviceIdleUL() {
|
void updateRulesForDeviceIdleUL() {
|
||||||
|
Trace.traceBegin(Trace.TRACE_TAG_NETWORK, "updateRulesForDeviceIdleUL");
|
||||||
|
try {
|
||||||
updateRulesForWhitelistedPowerSaveUL(mDeviceIdleMode, FIREWALL_CHAIN_DOZABLE,
|
updateRulesForWhitelistedPowerSaveUL(mDeviceIdleMode, FIREWALL_CHAIN_DOZABLE,
|
||||||
mUidFirewallDozableRules);
|
mUidFirewallDozableRules);
|
||||||
|
} finally {
|
||||||
|
Trace.traceEnd(Trace.TRACE_TAG_NETWORK);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateRuleForDeviceIdleUL(int uid) {
|
void updateRuleForDeviceIdleUL(int uid) {
|
||||||
@@ -2648,6 +2679,8 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void updateRulesForAppIdleUL() {
|
void updateRulesForAppIdleUL() {
|
||||||
|
Trace.traceBegin(Trace.TRACE_TAG_NETWORK, "updateRulesForAppIdleUL");
|
||||||
|
try {
|
||||||
final SparseIntArray uidRules = mUidFirewallStandbyRules;
|
final SparseIntArray uidRules = mUidFirewallStandbyRules;
|
||||||
uidRules.clear();
|
uidRules.clear();
|
||||||
|
|
||||||
@@ -2669,6 +2702,9 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setUidFirewallRules(FIREWALL_CHAIN_STANDBY, uidRules);
|
setUidFirewallRules(FIREWALL_CHAIN_STANDBY, uidRules);
|
||||||
|
} finally {
|
||||||
|
Trace.traceEnd(Trace.TRACE_TAG_NETWORK);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateRuleForAppIdleUL(int uid) {
|
void updateRuleForAppIdleUL(int uid) {
|
||||||
@@ -2693,9 +2729,8 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
|||||||
* {@link #mRestrictPower}, or {@link #mDeviceIdleMode} value.
|
* {@link #mRestrictPower}, or {@link #mDeviceIdleMode} value.
|
||||||
*/
|
*/
|
||||||
private void updateRulesForGlobalChangeAL(boolean restrictedNetworksChanged) {
|
private void updateRulesForGlobalChangeAL(boolean restrictedNetworksChanged) {
|
||||||
long start;
|
Trace.traceBegin(Trace.TRACE_TAG_NETWORK, "updateRulesForGlobalChangeAL");
|
||||||
if (LOGD) start = System.currentTimeMillis();
|
try {
|
||||||
|
|
||||||
updateRulesForRestrictPowerUL();
|
updateRulesForRestrictPowerUL();
|
||||||
updateRulesForRestrictBackgroundUL();
|
updateRulesForRestrictBackgroundUL();
|
||||||
|
|
||||||
@@ -2704,22 +2739,30 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
|||||||
normalizePoliciesNL();
|
normalizePoliciesNL();
|
||||||
updateNetworkRulesNL();
|
updateNetworkRulesNL();
|
||||||
}
|
}
|
||||||
if (LOGD) {
|
} finally {
|
||||||
final long delta = System.currentTimeMillis() - start;
|
Trace.traceEnd(Trace.TRACE_TAG_NETWORK);
|
||||||
Slog.d(TAG, "updateRulesForGlobalChangeAL(" + restrictedNetworksChanged + ") took "
|
|
||||||
+ delta + "ms");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateRulesForRestrictPowerUL() {
|
private void updateRulesForRestrictPowerUL() {
|
||||||
|
Trace.traceBegin(Trace.TRACE_TAG_NETWORK, "updateRulesForRestrictPowerUL");
|
||||||
|
try {
|
||||||
updateRulesForDeviceIdleUL();
|
updateRulesForDeviceIdleUL();
|
||||||
updateRulesForAppIdleUL();
|
updateRulesForAppIdleUL();
|
||||||
updateRulesForPowerSaveUL();
|
updateRulesForPowerSaveUL();
|
||||||
updateRulesForAllAppsUL(TYPE_RESTRICT_POWER);
|
updateRulesForAllAppsUL(TYPE_RESTRICT_POWER);
|
||||||
|
} finally {
|
||||||
|
Trace.traceEnd(Trace.TRACE_TAG_NETWORK);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateRulesForRestrictBackgroundUL() {
|
private void updateRulesForRestrictBackgroundUL() {
|
||||||
|
Trace.traceBegin(Trace.TRACE_TAG_NETWORK, "updateRulesForRestrictBackgroundUL");
|
||||||
|
try {
|
||||||
updateRulesForAllAppsUL(TYPE_RESTRICT_BACKGROUND);
|
updateRulesForAllAppsUL(TYPE_RESTRICT_BACKGROUND);
|
||||||
|
} finally {
|
||||||
|
Trace.traceEnd(Trace.TRACE_TAG_NETWORK);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final int TYPE_RESTRICT_BACKGROUND = 1;
|
private static final int TYPE_RESTRICT_BACKGROUND = 1;
|
||||||
@@ -2734,6 +2777,10 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
|||||||
|
|
||||||
// TODO: refactor / consolidate all those updateXyz methods, there are way too many of them...
|
// TODO: refactor / consolidate all those updateXyz methods, there are way too many of them...
|
||||||
private void updateRulesForAllAppsUL(@RestrictType int type) {
|
private void updateRulesForAllAppsUL(@RestrictType int type) {
|
||||||
|
if (Trace.isTagEnabled(Trace.TRACE_TAG_NETWORK)) {
|
||||||
|
Trace.traceBegin(Trace.TRACE_TAG_NETWORK, "updateRulesForRestrictPowerUL-" + type);
|
||||||
|
}
|
||||||
|
try {
|
||||||
final PackageManager pm = mContext.getPackageManager();
|
final PackageManager pm = mContext.getPackageManager();
|
||||||
|
|
||||||
// update rules for all installed applications
|
// update rules for all installed applications
|
||||||
@@ -2762,6 +2809,11 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} finally {
|
||||||
|
if (Trace.isTagEnabled(Trace.TRACE_TAG_NETWORK)) {
|
||||||
|
Trace.traceEnd(Trace.TRACE_TAG_NETWORK);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateRulesForTempWhitelistChangeUL() {
|
private void updateRulesForTempWhitelistChangeUL() {
|
||||||
|
|||||||
Reference in New Issue
Block a user