Send broadcast when changing restrict background.
When changing global restrict background status, send connectivity change broadcast, since it radically changes DISCONNECTED/BLOCKED status system-wide. Also reduce verbose stats logging. Bug: 5854466 Change-Id: I3b612c520f50cc3000a3a569b7e0ab5f691cc2bd
This commit is contained in:
@@ -21,5 +21,6 @@ oneway interface INetworkPolicyListener {
|
||||
|
||||
void onUidRulesChanged(int uid, int uidRules);
|
||||
void onMeteredIfacesChanged(in String[] meteredIfaces);
|
||||
void onRestrictBackgroundChanged(boolean restrictBackground);
|
||||
|
||||
}
|
||||
|
||||
@@ -1394,9 +1394,7 @@ private NetworkStateTracker makeWimaxStateTracker() {
|
||||
private INetworkPolicyListener mPolicyListener = new INetworkPolicyListener.Stub() {
|
||||
@Override
|
||||
public void onUidRulesChanged(int uid, int uidRules) {
|
||||
// only someone like NPMS should only be calling us
|
||||
mContext.enforceCallingOrSelfPermission(MANAGE_NETWORK_POLICY, TAG);
|
||||
|
||||
// caller is NPMS, since we only register with them
|
||||
if (LOGD_RULES) {
|
||||
log("onUidRulesChanged(uid=" + uid + ", uidRules=" + uidRules + ")");
|
||||
}
|
||||
@@ -1415,9 +1413,7 @@ private NetworkStateTracker makeWimaxStateTracker() {
|
||||
|
||||
@Override
|
||||
public void onMeteredIfacesChanged(String[] meteredIfaces) {
|
||||
// only someone like NPMS should only be calling us
|
||||
mContext.enforceCallingOrSelfPermission(MANAGE_NETWORK_POLICY, TAG);
|
||||
|
||||
// caller is NPMS, since we only register with them
|
||||
if (LOGD_RULES) {
|
||||
log("onMeteredIfacesChanged(ifaces=" + Arrays.toString(meteredIfaces) + ")");
|
||||
}
|
||||
@@ -1429,6 +1425,27 @@ private NetworkStateTracker makeWimaxStateTracker() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRestrictBackgroundChanged(boolean restrictBackground) {
|
||||
// caller is NPMS, since we only register with them
|
||||
if (LOGD_RULES) {
|
||||
log("onRestrictBackgroundChanged(restrictBackground=" + restrictBackground + ")");
|
||||
}
|
||||
|
||||
// kick off connectivity change broadcast for active network, since
|
||||
// global background policy change is radical.
|
||||
final int networkType = mActiveDefaultNetwork;
|
||||
if (isNetworkTypeValid(networkType)) {
|
||||
final NetworkStateTracker tracker = mNetTrackers[networkType];
|
||||
if (tracker != null) {
|
||||
final NetworkInfo info = tracker.getNetworkInfo();
|
||||
if (info != null && info.isConnected()) {
|
||||
sendConnectedBroadcast(info);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -195,6 +195,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
||||
private static final int MSG_FOREGROUND_ACTIVITIES_CHANGED = 3;
|
||||
private static final int MSG_PROCESS_DIED = 4;
|
||||
private static final int MSG_LIMIT_REACHED = 5;
|
||||
private static final int MSG_RESTRICT_BACKGROUND_CHANGED = 6;
|
||||
|
||||
private final Context mContext;
|
||||
private final IActivityManager mActivityManager;
|
||||
@@ -1225,6 +1226,9 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
||||
updateNotificationsLocked();
|
||||
writePolicyLocked();
|
||||
}
|
||||
|
||||
mHandler.obtainMessage(MSG_RESTRICT_BACKGROUND_CHANGED, restrictBackground ? 1 : 0, 0)
|
||||
.sendToTarget();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1573,6 +1577,20 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
case MSG_RESTRICT_BACKGROUND_CHANGED: {
|
||||
final boolean restrictBackground = msg.arg1 != 0;
|
||||
final int length = mListeners.beginBroadcast();
|
||||
for (int i = 0; i < length; i++) {
|
||||
final INetworkPolicyListener listener = mListeners.getBroadcastItem(i);
|
||||
if (listener != null) {
|
||||
try {
|
||||
listener.onRestrictBackgroundChanged(restrictBackground);
|
||||
} catch (RemoteException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
mListeners.finishBroadcast();
|
||||
}
|
||||
default: {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -51,6 +51,7 @@ import java.util.Map;
|
||||
public class NetworkStatsRecorder {
|
||||
private static final String TAG = "NetworkStatsRecorder";
|
||||
private static final boolean LOGD = true;
|
||||
private static final boolean LOGV = false;
|
||||
|
||||
private final FileRotator mRotator;
|
||||
private final NonMonotonicObserver<String> mObserver;
|
||||
@@ -170,7 +171,7 @@ public class NetworkStatsRecorder {
|
||||
|
||||
mLastSnapshot = snapshot;
|
||||
|
||||
if (LOGD && unknownIfaces.size() > 0) {
|
||||
if (LOGV && unknownIfaces.size() > 0) {
|
||||
Slog.w(TAG, "unknown interfaces " + unknownIfaces + ", ignoring those stats");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user