Inform Application thread to block for network rules to be updated.
Bug: 226299593 Test: atest tests/cts/hostside/src/com/android/cts/net/HostsideRestrictBackgroundNetworkTests.java Change-Id: Ie37173d0d3f4034a74b834550920530166cd4201 Merged-In: Ie37173d0d3f4034a74b834550920530166cd4201
This commit is contained in:
@@ -587,7 +587,7 @@ public abstract class ActivityManagerInternal {
|
||||
* @param uid uid
|
||||
* @param pid pid of the ProcessRecord that is pending top.
|
||||
*/
|
||||
public abstract void addPendingTopUid(int uid, int pid);
|
||||
public abstract void addPendingTopUid(int uid, int pid, @Nullable IApplicationThread thread);
|
||||
|
||||
/**
|
||||
* Delete uid from the ActivityManagerService PendingStartActivityUids list.
|
||||
|
||||
@@ -16315,23 +16315,39 @@ public class ActivityManagerService extends IActivityManager.Stub
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addPendingTopUid(int uid, int pid) {
|
||||
mPendingStartActivityUids.add(uid, pid);
|
||||
public void addPendingTopUid(int uid, int pid, @Nullable IApplicationThread thread) {
|
||||
final boolean isNewPending = mPendingStartActivityUids.add(uid, pid);
|
||||
// We need to update the network rules for the app coming to the top state so that
|
||||
// it can access network when the device or the app is in a restricted state
|
||||
// (e.g. battery/data saver) but since waiting for updateOomAdj to complete and then
|
||||
// informing NetworkPolicyManager might get delayed, informing the state change as soon
|
||||
// as we know app is going to come to the top state.
|
||||
if (mNetworkPolicyUidObserver != null) {
|
||||
if (isNewPending && mNetworkPolicyUidObserver != null) {
|
||||
try {
|
||||
final long procStateSeq = mProcessList.getNextProcStateSeq();
|
||||
mNetworkPolicyUidObserver.onUidStateChanged(uid, PROCESS_STATE_TOP,
|
||||
mProcessList.getNextProcStateSeq(), PROCESS_CAPABILITY_ALL);
|
||||
procStateSeq, PROCESS_CAPABILITY_ALL);
|
||||
if (thread != null && isNetworkingBlockedForUid(uid)) {
|
||||
thread.setNetworkBlockSeq(procStateSeq);
|
||||
}
|
||||
} catch (RemoteException e) {
|
||||
// Should not happen; call is within the same process
|
||||
Slog.d(TAG, "Error calling setNetworkBlockSeq", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isNetworkingBlockedForUid(int uid) {
|
||||
synchronized (mUidNetworkBlockedReasons) {
|
||||
// TODO: We can consider only those blocked reasons that will be overridden
|
||||
// by the TOP state. For other ones, there is no point in waiting.
|
||||
// TODO: We can reuse this data in
|
||||
// ProcessList#incrementProcStateSeqAndNotifyAppsLOSP instead of calling into
|
||||
// NetworkManagementService.
|
||||
return mUidNetworkBlockedReasons.get(uid, BLOCKED_REASON_NONE)
|
||||
!= BLOCKED_REASON_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deletePendingTopUid(int uid, long nowElapsed) {
|
||||
mPendingStartActivityUids.delete(uid, nowElapsed);
|
||||
|
||||
@@ -44,10 +44,12 @@ final class PendingStartActivityUids {
|
||||
mContext = context;
|
||||
}
|
||||
|
||||
synchronized void add(int uid, int pid) {
|
||||
synchronized boolean add(int uid, int pid) {
|
||||
if (mPendingUids.get(uid) == null) {
|
||||
mPendingUids.put(uid, new Pair<>(pid, SystemClock.elapsedRealtime()));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
synchronized void delete(int uid, long nowElapsed) {
|
||||
|
||||
@@ -1123,7 +1123,7 @@ public class WindowProcessController extends ConfigurationContainer<Configuratio
|
||||
|
||||
/** Makes the process have top state before oom-adj is computed from a posted message. */
|
||||
void addToPendingTop() {
|
||||
mAtm.mAmInternal.addPendingTopUid(mUid, mPid);
|
||||
mAtm.mAmInternal.addPendingTopUid(mUid, mPid, mThread);
|
||||
}
|
||||
|
||||
void updateServiceConnectionActivities() {
|
||||
@@ -1176,7 +1176,7 @@ public class WindowProcessController extends ConfigurationContainer<Configuratio
|
||||
}
|
||||
// update ActivityManagerService.PendingStartActivityUids list.
|
||||
if (topProcessState == ActivityManager.PROCESS_STATE_TOP) {
|
||||
mAtm.mAmInternal.addPendingTopUid(mUid, mPid);
|
||||
mAtm.mAmInternal.addPendingTopUid(mUid, mPid, mThread);
|
||||
}
|
||||
prepareOomAdjustment();
|
||||
// Posting the message at the front of queue so WM lock isn't held when we call into AM,
|
||||
|
||||
Reference in New Issue
Block a user