Merge changes I8aca6ac9,I995f7c6e into tm-dev am: 8a4c3cc16a
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/17799744 Change-Id: Ifab3a612a9046fdebe86b6a550a76ae29f85bf3e Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -15390,16 +15390,6 @@ public final class Settings {
|
||||
@Readable
|
||||
public static final String DEVICE_DEMO_MODE = "device_demo_mode";
|
||||
|
||||
/**
|
||||
* Indicates the maximum time that an app is blocked for the network rules to get updated.
|
||||
*
|
||||
* Type: long
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
@Readable
|
||||
public static final String NETWORK_ACCESS_TIMEOUT_MS = "network_access_timeout_ms";
|
||||
|
||||
/**
|
||||
* The reason for the settings database being downgraded. This is only for
|
||||
* troubleshooting purposes and its value should not be interpreted in any way.
|
||||
|
||||
@@ -1057,9 +1057,6 @@ class SettingsProtoDumpUtil {
|
||||
dumpSetting(s, p,
|
||||
Settings.Global.NETWORK_SCORING_PROVISIONED,
|
||||
GlobalSettingsProto.Network.SCORING_PROVISIONED);
|
||||
dumpSetting(s, p,
|
||||
Settings.Global.NETWORK_ACCESS_TIMEOUT_MS,
|
||||
GlobalSettingsProto.Network.ACCESS_TIMEOUT_MS);
|
||||
dumpSetting(s, p,
|
||||
Settings.Global.RECOMMENDED_NETWORK_EVALUATOR_CACHE_EXPIRY_MS,
|
||||
GlobalSettingsProto.Network.RECOMMENDED_NETWORK_EVALUATOR_CACHE_EXPIRY_MS);
|
||||
|
||||
@@ -527,7 +527,6 @@ public class SettingsBackupTest {
|
||||
Settings.Global.INSTALL_CARRIER_APP_NOTIFICATION_PERSISTENT,
|
||||
Settings.Global.INSTALL_CARRIER_APP_NOTIFICATION_SLEEP_MILLIS,
|
||||
Settings.Global.USER_SWITCHER_ENABLED,
|
||||
Settings.Global.NETWORK_ACCESS_TIMEOUT_MS,
|
||||
Settings.Global.WARNING_TEMPERATURE,
|
||||
Settings.Global.WEBVIEW_DATA_REDUCTION_PROXY_KEY,
|
||||
Settings.Global.WEBVIEW_MULTIPROCESS,
|
||||
|
||||
@@ -140,6 +140,11 @@ final class ActivityManagerConstants extends ContentObserver {
|
||||
*/
|
||||
static final String KEY_COMPONENT_ALIAS_OVERRIDES = "component_alias_overrides";
|
||||
|
||||
/**
|
||||
* Indicates the maximum time that an app is blocked for the network rules to get updated.
|
||||
*/
|
||||
static final String KEY_NETWORK_ACCESS_TIMEOUT_MS = "network_access_timeout_ms";
|
||||
|
||||
private static final int DEFAULT_MAX_CACHED_PROCESSES = 32;
|
||||
private static final long DEFAULT_FGSERVICE_MIN_SHOWN_TIME = 2*1000;
|
||||
private static final long DEFAULT_FGSERVICE_MIN_REPORT_TIME = 3*1000;
|
||||
@@ -185,6 +190,7 @@ final class ActivityManagerConstants extends ContentObserver {
|
||||
private static final float DEFAULT_FGS_START_ALLOWED_LOG_SAMPLE_RATE = 0.25f; // 25%
|
||||
private static final float DEFAULT_FGS_START_DENIED_LOG_SAMPLE_RATE = 1; // 100%
|
||||
private static final long DEFAULT_PROCESS_KILL_TIMEOUT_MS = 10 * 1000;
|
||||
private static final long DEFAULT_NETWORK_ACCESS_TIMEOUT_MS = 200; // 0.2 sec
|
||||
|
||||
static final long DEFAULT_BACKGROUND_SETTLE_TIME = 60 * 1000;
|
||||
static final long DEFAULT_KILL_BG_RESTRICTED_CACHED_IDLE_SETTLE_TIME_MS = 60 * 1000;
|
||||
@@ -781,6 +787,11 @@ final class ActivityManagerConstants extends ContentObserver {
|
||||
private List<String> mDefaultImperceptibleKillExemptPackages;
|
||||
private List<Integer> mDefaultImperceptibleKillExemptProcStates;
|
||||
|
||||
/**
|
||||
* Indicates the maximum time spent waiting for the network rules to get updated.
|
||||
*/
|
||||
volatile long mNetworkAccessTimeoutMs = DEFAULT_NETWORK_ACCESS_TIMEOUT_MS;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private static final int OOMADJ_UPDATE_POLICY_SLOW = 0;
|
||||
private static final int OOMADJ_UPDATE_POLICY_QUICK = 1;
|
||||
@@ -976,6 +987,9 @@ final class ActivityManagerConstants extends ContentObserver {
|
||||
case KEY_MAX_EMPTY_TIME_MILLIS:
|
||||
updateMaxEmptyTimeMillis();
|
||||
break;
|
||||
case KEY_NETWORK_ACCESS_TIMEOUT_MS:
|
||||
updateNetworkAccessTimeoutMs();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -1446,6 +1460,13 @@ final class ActivityManagerConstants extends ContentObserver {
|
||||
DEFAULT_MAX_EMPTY_TIME_MILLIS);
|
||||
}
|
||||
|
||||
private void updateNetworkAccessTimeoutMs() {
|
||||
mNetworkAccessTimeoutMs = DeviceConfig.getLong(
|
||||
DeviceConfig.NAMESPACE_ACTIVITY_MANAGER,
|
||||
KEY_NETWORK_ACCESS_TIMEOUT_MS,
|
||||
DEFAULT_NETWORK_ACCESS_TIMEOUT_MS);
|
||||
}
|
||||
|
||||
private void updateServiceStartForegroundTimeoutMs() {
|
||||
mServiceStartForegroundTimeoutMs = DeviceConfig.getInt(
|
||||
DeviceConfig.NAMESPACE_ACTIVITY_MANAGER,
|
||||
@@ -1756,6 +1777,8 @@ final class ActivityManagerConstants extends ContentObserver {
|
||||
pw.print("="); pw.println(mServiceStartForegroundAnrDelayMs);
|
||||
pw.print(" "); pw.print(KEY_SERVICE_BIND_ALMOST_PERCEPTIBLE_TIMEOUT_MS);
|
||||
pw.print("="); pw.println(mServiceBindAlmostPerceptibleTimeoutMs);
|
||||
pw.print(" "); pw.print(KEY_NETWORK_ACCESS_TIMEOUT_MS);
|
||||
pw.print("="); pw.println(mNetworkAccessTimeoutMs);
|
||||
|
||||
pw.println();
|
||||
if (mOverrideMaxCachedProcesses >= 0) {
|
||||
|
||||
@@ -49,12 +49,6 @@ import static android.content.pm.PackageManager.MATCH_DIRECT_BOOT_UNAWARE;
|
||||
import static android.content.pm.PackageManager.MATCH_SYSTEM_ONLY;
|
||||
import static android.content.pm.PackageManager.MATCH_UNINSTALLED_PACKAGES;
|
||||
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
|
||||
import static android.net.ConnectivityManager.BLOCKED_METERED_REASON_DATA_SAVER;
|
||||
import static android.net.ConnectivityManager.BLOCKED_METERED_REASON_USER_RESTRICTED;
|
||||
import static android.net.ConnectivityManager.BLOCKED_REASON_APP_STANDBY;
|
||||
import static android.net.ConnectivityManager.BLOCKED_REASON_BATTERY_SAVER;
|
||||
import static android.net.ConnectivityManager.BLOCKED_REASON_DOZE;
|
||||
import static android.net.ConnectivityManager.BLOCKED_REASON_LOW_POWER_STANDBY;
|
||||
import static android.net.ConnectivityManager.BLOCKED_REASON_NONE;
|
||||
import static android.os.FactoryTest.FACTORY_TEST_OFF;
|
||||
import static android.os.IServiceManager.DUMP_FLAG_PRIORITY_CRITICAL;
|
||||
@@ -101,7 +95,6 @@ import static android.os.Process.setThreadPriority;
|
||||
import static android.os.Process.setThreadScheduler;
|
||||
import static android.provider.Settings.Global.ALWAYS_FINISH_ACTIVITIES;
|
||||
import static android.provider.Settings.Global.DEBUG_APP;
|
||||
import static android.provider.Settings.Global.NETWORK_ACCESS_TIMEOUT_MS;
|
||||
import static android.provider.Settings.Global.WAIT_FOR_DEBUGGER;
|
||||
import static android.text.format.DateUtils.DAY_IN_MILLIS;
|
||||
import static android.util.FeatureFlagUtils.SETTINGS_ENABLE_MONITOR_PHANTOM_PROCS;
|
||||
@@ -136,6 +129,7 @@ import static com.android.server.am.ActivityManagerDebugConfig.TAG_AM;
|
||||
import static com.android.server.am.ActivityManagerDebugConfig.TAG_WITH_CLASS_NAME;
|
||||
import static com.android.server.am.MemoryStatUtil.hasMemcg;
|
||||
import static com.android.server.am.ProcessList.ProcStartHandler;
|
||||
import static com.android.server.net.NetworkPolicyManagerInternal.updateBlockedReasonsWithProcState;
|
||||
import static com.android.server.pm.PackageManagerService.PLATFORM_PACKAGE_NAME;
|
||||
import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_CLEANUP;
|
||||
import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_SWITCH;
|
||||
@@ -540,11 +534,6 @@ public class ActivityManagerService extends IActivityManager.Stub
|
||||
// If set, we will push process association information in to procstats.
|
||||
static final boolean TRACK_PROCSTATS_ASSOCIATIONS = true;
|
||||
|
||||
/**
|
||||
* Default value for {@link Settings.Global#NETWORK_ACCESS_TIMEOUT_MS}.
|
||||
*/
|
||||
private static final long NETWORK_ACCESS_TIMEOUT_DEFAULT_MS = 200; // 0.2 sec
|
||||
|
||||
// The minimum memory growth threshold (in KB) for low RAM devices.
|
||||
private static final int MINIMUM_MEMORY_GROWTH_THRESHOLD = 10 * 1000; // 10 MB
|
||||
|
||||
@@ -716,12 +705,6 @@ public class ActivityManagerService extends IActivityManager.Stub
|
||||
final AppErrors mAppErrors;
|
||||
final PackageWatchdog mPackageWatchdog;
|
||||
|
||||
/**
|
||||
* Indicates the maximum time spent waiting for the network rules to get updated.
|
||||
*/
|
||||
@VisibleForTesting
|
||||
long mWaitForNetworkTimeoutMs;
|
||||
|
||||
/**
|
||||
* Uids of apps with current active camera sessions. Access synchronized on
|
||||
* the IntArray instance itself, and no other locks must be acquired while that
|
||||
@@ -7934,8 +7917,6 @@ public class ActivityManagerService extends IActivityManager.Stub
|
||||
final boolean waitForDebugger = Settings.Global.getInt(resolver, WAIT_FOR_DEBUGGER, 0) != 0;
|
||||
final boolean alwaysFinishActivities =
|
||||
Settings.Global.getInt(resolver, ALWAYS_FINISH_ACTIVITIES, 0) != 0;
|
||||
final long waitForNetworkTimeoutMs = Settings.Global.getLong(resolver,
|
||||
NETWORK_ACCESS_TIMEOUT_MS, NETWORK_ACCESS_TIMEOUT_DEFAULT_MS);
|
||||
mHiddenApiBlacklist.registerObserver();
|
||||
mPlatformCompat.registerContentObserver();
|
||||
|
||||
@@ -7956,7 +7937,6 @@ public class ActivityManagerService extends IActivityManager.Stub
|
||||
com.android.internal.R.bool.config_multiuserDelayUserDataLocking);
|
||||
mUserController.setInitialConfig(userSwitchUiEnabled, maxRunningUsers,
|
||||
delayUserDataLocking);
|
||||
mWaitForNetworkTimeoutMs = waitForNetworkTimeoutMs;
|
||||
}
|
||||
mAppErrors.loadAppsNotReportingCrashesFromConfig(res.getString(
|
||||
com.android.internal.R.string.config_appsNotReportingCrashes));
|
||||
@@ -17296,7 +17276,7 @@ public class ActivityManagerService extends IActivityManager.Stub
|
||||
final long procStateSeq = mProcessList.getNextProcStateSeq();
|
||||
mNetworkPolicyUidObserver.onUidStateChanged(uid, PROCESS_STATE_TOP,
|
||||
procStateSeq, PROCESS_CAPABILITY_ALL);
|
||||
if (thread != null && isNetworkingBlockedForUid(uid)) {
|
||||
if (thread != null && shouldWaitForNetworkRulesUpdate(uid)) {
|
||||
thread.setNetworkBlockSeq(procStateSeq);
|
||||
}
|
||||
} catch (RemoteException e) {
|
||||
@@ -17305,29 +17285,18 @@ public class ActivityManagerService extends IActivityManager.Stub
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isNetworkingBlockedForUid(int uid) {
|
||||
private boolean shouldWaitForNetworkRulesUpdate(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.
|
||||
final int uidBlockedReasons = mUidNetworkBlockedReasons.get(
|
||||
uid, BLOCKED_REASON_NONE);
|
||||
if (uidBlockedReasons == BLOCKED_REASON_NONE) {
|
||||
return false;
|
||||
}
|
||||
final int topExemptedBlockedReasons = BLOCKED_REASON_BATTERY_SAVER
|
||||
| BLOCKED_REASON_DOZE
|
||||
| BLOCKED_REASON_APP_STANDBY
|
||||
| BLOCKED_REASON_LOW_POWER_STANDBY
|
||||
| BLOCKED_METERED_REASON_DATA_SAVER
|
||||
| BLOCKED_METERED_REASON_USER_RESTRICTED;
|
||||
final int effectiveBlockedReasons =
|
||||
uidBlockedReasons & ~topExemptedBlockedReasons;
|
||||
// Only consider it as blocked if it is not blocked by a reason
|
||||
// that is not exempted by app being in the top state.
|
||||
return effectiveBlockedReasons == BLOCKED_REASON_NONE;
|
||||
// We should only inform the uid to block if it is currently blocked but will be
|
||||
// unblocked once it comes to the TOP state.
|
||||
return uidBlockedReasons != BLOCKED_REASON_NONE
|
||||
&& updateBlockedReasonsWithProcState(uidBlockedReasons, PROCESS_STATE_TOP)
|
||||
== BLOCKED_REASON_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17629,10 +17598,10 @@ public class ActivityManagerService extends IActivityManager.Stub
|
||||
}
|
||||
final long startTime = SystemClock.uptimeMillis();
|
||||
record.procStateSeqWaitingForNetwork = procStateSeq;
|
||||
record.networkStateLock.wait(mWaitForNetworkTimeoutMs);
|
||||
record.networkStateLock.wait(mConstants.mNetworkAccessTimeoutMs);
|
||||
record.procStateSeqWaitingForNetwork = 0;
|
||||
final long totalTime = SystemClock.uptimeMillis() - startTime;
|
||||
if (totalTime >= mWaitForNetworkTimeoutMs || DEBUG_NETWORK) {
|
||||
if (totalTime >= mConstants.mNetworkAccessTimeoutMs || DEBUG_NETWORK) {
|
||||
Slog.w(TAG_NETWORK, "Total time waited for network rules to get updated: "
|
||||
+ totalTime + ". Uid: " + callingUid + " procStateSeq: "
|
||||
+ procStateSeq + " UidRec: " + record
|
||||
|
||||
@@ -4792,7 +4792,7 @@ public final class ProcessList {
|
||||
final UidRecord uidRec = activeUids.valueAt(i);
|
||||
uidRec.curProcStateSeq = getNextProcStateSeq();
|
||||
}
|
||||
if (mService.mWaitForNetworkTimeoutMs <= 0) {
|
||||
if (mService.mConstants.mNetworkAccessTimeoutMs <= 0) {
|
||||
return;
|
||||
}
|
||||
// Used for identifying which uids need to block for network.
|
||||
|
||||
@@ -16,6 +16,9 @@
|
||||
|
||||
package com.android.server.net;
|
||||
|
||||
import static com.android.server.net.NetworkPolicyManagerService.UidBlockedState.getAllowedReasonsForProcState;
|
||||
import static com.android.server.net.NetworkPolicyManagerService.UidBlockedState.getEffectiveBlockedReasons;
|
||||
|
||||
import android.annotation.Nullable;
|
||||
import android.net.Network;
|
||||
import android.os.PowerExemptionManager.ReasonCode;
|
||||
@@ -84,7 +87,6 @@ public abstract class NetworkPolicyManagerInternal {
|
||||
public abstract void setMeteredRestrictedPackages(
|
||||
Set<String> packageNames, int userId);
|
||||
|
||||
|
||||
/**
|
||||
* Similar to {@link #setMeteredRestrictedPackages(Set, int)} but updates the restricted
|
||||
* packages list asynchronously.
|
||||
@@ -97,4 +99,10 @@ public abstract class NetworkPolicyManagerInternal {
|
||||
|
||||
/** Informs that the Low Power Standby allowlist has changed */
|
||||
public abstract void setLowPowerStandbyAllowlist(int[] uids);
|
||||
|
||||
/** Update the {@code blockedReasons} taking into account the {@code procState} of the uid */
|
||||
public static int updateBlockedReasonsWithProcState(int blockedReasons, int procState) {
|
||||
final int allowedReasons = getAllowedReasonsForProcState(procState);
|
||||
return getEffectiveBlockedReasons(blockedReasons, allowedReasons);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6315,6 +6315,17 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
||||
return effectiveBlockedReasons;
|
||||
}
|
||||
|
||||
static int getAllowedReasonsForProcState(int procState) {
|
||||
if (procState > NetworkPolicyManager.FOREGROUND_THRESHOLD_STATE) {
|
||||
return ALLOWED_REASON_NONE;
|
||||
} else if (procState <= NetworkPolicyManager.TOP_THRESHOLD_STATE) {
|
||||
return ALLOWED_REASON_TOP | ALLOWED_REASON_FOREGROUND
|
||||
| ALLOWED_METERED_REASON_FOREGROUND;
|
||||
} else {
|
||||
return ALLOWED_REASON_FOREGROUND | ALLOWED_METERED_REASON_FOREGROUND;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return toString(blockedReasons, allowedReasons, effectiveBlockedReasons);
|
||||
|
||||
@@ -164,7 +164,7 @@ public class ActivityManagerServiceTest {
|
||||
mHandler = new TestHandler(mHandlerThread.getLooper());
|
||||
mInjector = new TestInjector(mContext);
|
||||
mAms = new ActivityManagerService(mInjector, mServiceThreadRule.getThread());
|
||||
mAms.mWaitForNetworkTimeoutMs = 2000;
|
||||
mAms.mConstants.mNetworkAccessTimeoutMs = 2000;
|
||||
mAms.mActivityTaskManager = new ActivityTaskManagerService(mContext);
|
||||
mAms.mActivityTaskManager.initialize(null, null, mHandler.getLooper());
|
||||
mHandler.setRunnablesToIgnore(
|
||||
|
||||
Reference in New Issue
Block a user