Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8a4c3cc1 authored by Sudheer Shanka's avatar Sudheer Shanka Committed by Android (Google) Code Review
Browse files

Merge changes I8aca6ac9,I995f7c6e into tm-dev

* changes:
  Migrate NETWORK_ACCESS_TIMEOUT flag to DeviceConfig.
  Don't hardcode the blocked reasons in AMS.
parents 6a435bb6 664ded5d
Loading
Loading
Loading
Loading
+0 −10
Original line number Diff line number Diff line
@@ -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.
+0 −3
Original line number Diff line number Diff line
@@ -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);
+0 −1
Original line number Diff line number Diff line
@@ -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,
+23 −0
Original line number Diff line number Diff line
@@ -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) {
+10 −41
Original line number Diff line number Diff line
@@ -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
Loading