Merge "Inform NPMS about the app coming to the TOP state early." into tm-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
ec157586d7
@@ -842,4 +842,15 @@ public abstract class ActivityManagerInternal {
|
||||
* Returns some summary statistics of the current PendingIntent queue - sizes and counts.
|
||||
*/
|
||||
public abstract List<PendingIntentStats> getPendingIntentStats();
|
||||
|
||||
/**
|
||||
* Register the UidObserver for NetworkPolicyManager service.
|
||||
*
|
||||
* This is equivalent to calling
|
||||
* {@link IActivityManager#registerUidObserver(IUidObserver, int, int, String)} but having a
|
||||
* separate method for NetworkPolicyManager service so that it's UidObserver can be called
|
||||
* separately outside the usual UidObserver flow.
|
||||
*/
|
||||
public abstract void registerNetworkPolicyUidObserver(@NonNull IUidObserver observer,
|
||||
int which, int cutpoint, @NonNull String callingPackage);
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ import static android.app.ActivityManager.INSTR_FLAG_DISABLE_ISOLATED_STORAGE;
|
||||
import static android.app.ActivityManager.INSTR_FLAG_DISABLE_TEST_API_CHECKS;
|
||||
import static android.app.ActivityManager.INSTR_FLAG_NO_RESTART;
|
||||
import static android.app.ActivityManager.INTENT_SENDER_ACTIVITY;
|
||||
import static android.app.ActivityManager.PROCESS_CAPABILITY_ALL;
|
||||
import static android.app.ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND;
|
||||
import static android.app.ActivityManager.PROCESS_STATE_NONEXISTENT;
|
||||
import static android.app.ActivityManager.PROCESS_STATE_TOP;
|
||||
@@ -1483,6 +1484,7 @@ public class ActivityManagerService extends IActivityManager.Stub
|
||||
final ActivityThread mSystemThread;
|
||||
|
||||
final UidObserverController mUidObserverController;
|
||||
private volatile IUidObserver mNetworkPolicyUidObserver;
|
||||
|
||||
final AppRestrictionController mAppRestrictionController;
|
||||
|
||||
@@ -17300,6 +17302,19 @@ public class ActivityManagerService extends IActivityManager.Stub
|
||||
if (isNewPending && mOomAdjuster != null) { // It can be null in unit test.
|
||||
mOomAdjuster.mCachedAppOptimizer.unfreezeProcess(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) {
|
||||
try {
|
||||
mNetworkPolicyUidObserver.onUidStateChanged(uid, PROCESS_STATE_TOP,
|
||||
mProcessList.getProcStateSeqCounter(), PROCESS_CAPABILITY_ALL);
|
||||
} catch (RemoteException e) {
|
||||
// Should not happen; call is within the same process
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -17497,6 +17512,14 @@ public class ActivityManagerService extends IActivityManager.Stub
|
||||
public void restart() {
|
||||
ActivityManagerService.this.restart();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerNetworkPolicyUidObserver(@NonNull IUidObserver observer,
|
||||
int which, int cutpoint, @NonNull String callingPackage) {
|
||||
mNetworkPolicyUidObserver = observer;
|
||||
mUidObserverController.register(observer, which, cutpoint, callingPackage,
|
||||
Binder.getCallingUid());
|
||||
}
|
||||
}
|
||||
|
||||
long inputDispatchingTimedOut(int pid, final boolean aboveSystem, String reason) {
|
||||
|
||||
@@ -423,9 +423,8 @@ public final class ProcessList {
|
||||
* Having a global counter ensures that seq numbers are monotonically increasing for a
|
||||
* particular uid even when the uidRecord is re-created.
|
||||
*/
|
||||
@GuardedBy("mService")
|
||||
@VisibleForTesting
|
||||
long mProcStateSeqCounter = 0;
|
||||
volatile long mProcStateSeqCounter = 0;
|
||||
|
||||
/**
|
||||
* A global counter for generating sequence numbers to uniquely identify pending process starts.
|
||||
@@ -4860,6 +4859,10 @@ public final class ProcessList {
|
||||
}
|
||||
}
|
||||
|
||||
long getProcStateSeqCounter() {
|
||||
return mProcStateSeqCounter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a server socket in system_server, zygote will connect to it
|
||||
* in order to send unsolicited messages to system_server.
|
||||
|
||||
@@ -1007,7 +1007,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
||||
final int changes = ActivityManager.UID_OBSERVER_PROCSTATE
|
||||
| ActivityManager.UID_OBSERVER_GONE
|
||||
| ActivityManager.UID_OBSERVER_CAPABILITY;
|
||||
mActivityManager.registerUidObserver(mUidObserver, changes,
|
||||
mActivityManagerInternal.registerNetworkPolicyUidObserver(mUidObserver, changes,
|
||||
NetworkPolicyManager.FOREGROUND_THRESHOLD_STATE, "android");
|
||||
mNetworkManager.registerObserver(mAlertObserver);
|
||||
} catch (RemoteException e) {
|
||||
|
||||
@@ -441,14 +441,14 @@ public class NetworkPolicyManagerServiceTest {
|
||||
setNetpolicyXml(context);
|
||||
|
||||
doAnswer(new Answer<Void>() {
|
||||
|
||||
@Override
|
||||
public Void answer(InvocationOnMock invocation) throws Throwable {
|
||||
mUidObserver = (IUidObserver) invocation.getArguments()[0];
|
||||
Log.d(TAG, "set mUidObserver to " + mUidObserver);
|
||||
return null;
|
||||
}
|
||||
}).when(mActivityManager).registerUidObserver(any(), anyInt(), anyInt(), any(String.class));
|
||||
}).when(mActivityManagerInternal).registerNetworkPolicyUidObserver(any(),
|
||||
anyInt(), anyInt(), any(String.class));
|
||||
|
||||
mFutureIntent = newRestrictBackgroundChangedFuture();
|
||||
mDeps = new TestDependencies(mServiceContext);
|
||||
|
||||
Reference in New Issue
Block a user