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

Commit 0f403a58 authored by Android Build Coastguard Worker's avatar Android Build Coastguard Worker
Browse files

Snap for 10080193 from 454ab306 to udc-qpr1-release

Change-Id: Ia856f24d7233c5de25a31592380ccbafaa4edd42
parents ea94c447 454ab306
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -22,7 +22,6 @@ import android.app.ActivityManagerInternal.AppBackgroundRestrictionListener;
import android.app.AppOpsManager;
import android.app.AppOpsManager.PackageOps;
import android.app.IActivityManager;
import android.app.UidObserver;
import android.app.usage.UsageStatsManager;
import android.content.BroadcastReceiver;
import android.content.Context;
@@ -54,6 +53,7 @@ import com.android.internal.app.IAppOpsCallback;
import com.android.internal.app.IAppOpsService;
import com.android.internal.util.ArrayUtils;
import com.android.internal.util.StatLogger;
import com.android.modules.expresslog.Counter;
import com.android.server.AppStateTrackerProto.ExemptedPackage;
import com.android.server.AppStateTrackerProto.RunAnyInBackgroundRestrictedPackages;
import com.android.server.usage.AppStandbyInternal;
@@ -79,6 +79,9 @@ import java.util.Set;
public class AppStateTrackerImpl implements AppStateTracker {
    private static final boolean DEBUG = false;

    private static final String APP_RESTRICTION_COUNTER_METRIC_ID =
            "battery.value_app_background_restricted";

    private final Object mLock = new Object();
    private final Context mContext;

@@ -748,6 +751,9 @@ public class AppStateTrackerImpl implements AppStateTracker {
            } catch (RemoteException e) {
                // Shouldn't happen
            }
            if (restricted) {
                Counter.logIncrementWithUid(APP_RESTRICTION_COUNTER_METRIC_ID, uid);
            }
            synchronized (mLock) {
                if (updateForcedAppStandbyUidPackageLocked(uid, packageName, restricted)) {
                    mHandler.notifyRunAnyAppOpsChanged(uid, packageName);
+57 −3
Original line number Diff line number Diff line
@@ -49,8 +49,10 @@ import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.util.ArrayUtils;
import com.android.internal.util.BitUtils;
import com.android.modules.expresslog.Histogram;
import com.android.modules.utils.TypedXmlPullParser;
import com.android.modules.utils.TypedXmlSerializer;
import com.android.server.AppSchedulingModuleThread;
import com.android.server.IoThread;
import com.android.server.job.JobSchedulerInternal.JobStorePersistStats;
import com.android.server.job.controllers.JobStatus;
@@ -94,6 +96,7 @@ public final class JobStore {

    /** Threshold to adjust how often we want to write to the db. */
    private static final long JOB_PERSIST_DELAY = 2000L;
    private static final long SCHEDULED_JOB_HIGH_WATER_MARK_PERIOD_MS = 30 * 60_000L;
    @VisibleForTesting
    static final String JOB_FILE_SPLIT_PREFIX = "jobs_";
    private static final int ALL_UIDS = -1;
@@ -131,6 +134,30 @@ public final class JobStore {

    private JobStorePersistStats mPersistInfo = new JobStorePersistStats();

    /**
     * Separately updated value of the JobSet size to avoid recalculating it frequently for logging
     * purposes. Continue to use {@link JobSet#size()} for the up-to-date and accurate value.
     */
    private int mCurrentJobSetSize = 0;
    private int mScheduledJob30MinHighWaterMark = 0;
    private static final Histogram sScheduledJob30MinHighWaterMarkLogger = new Histogram(
            "job_scheduler.value_hist_scheduled_job_30_min_high_water_mark",
            new Histogram.ScaledRangeOptions(15, 1, 99, 1.5f));
    private final Runnable mScheduledJobHighWaterMarkLoggingRunnable = new Runnable() {
        @Override
        public void run() {
            AppSchedulingModuleThread.getHandler().removeCallbacks(this);
            synchronized (mLock) {
                sScheduledJob30MinHighWaterMarkLogger.logSample(mScheduledJob30MinHighWaterMark);
                mScheduledJob30MinHighWaterMark = mJobSet.size();
            }
            // The count doesn't need to be logged at exact times. Logging based on system uptime
            // should be fine.
            AppSchedulingModuleThread.getHandler()
                    .postDelayed(this, SCHEDULED_JOB_HIGH_WATER_MARK_PERIOD_MS);
        }
    };

    /** Used by the {@link JobSchedulerService} to instantiate the JobStore. */
    static JobStore get(JobSchedulerService jobManagerService) {
        synchronized (sSingletonLock) {
@@ -183,6 +210,9 @@ public final class JobStore {
        mXmlTimestamp = mJobsFile.exists()
                ? mJobsFile.getLastModifiedTime() : mJobFileDirectory.lastModified();
        mRtcGood = (sSystemClock.millis() > mXmlTimestamp);

        AppSchedulingModuleThread.getHandler().postDelayed(
                mScheduledJobHighWaterMarkLoggingRunnable, SCHEDULED_JOB_HIGH_WATER_MARK_PERIOD_MS);
    }

    private void init() {
@@ -252,7 +282,10 @@ public final class JobStore {
     * @param jobStatus Job to add.
     */
    public void add(JobStatus jobStatus) {
        mJobSet.add(jobStatus);
        if (mJobSet.add(jobStatus)) {
            mCurrentJobSetSize++;
            maybeUpdateHighWaterMark();
        }
        if (jobStatus.isPersisted()) {
            mPendingJobWriteUids.put(jobStatus.getUid(), true);
            maybeWriteStatusToDiskAsync();
@@ -267,7 +300,10 @@ public final class JobStore {
     */
    @VisibleForTesting
    public void addForTesting(JobStatus jobStatus) {
        mJobSet.add(jobStatus);
        if (mJobSet.add(jobStatus)) {
            mCurrentJobSetSize++;
            maybeUpdateHighWaterMark();
        }
        if (jobStatus.isPersisted()) {
            mPendingJobWriteUids.put(jobStatus.getUid(), true);
        }
@@ -303,6 +339,7 @@ public final class JobStore {
            }
            return false;
        }
        mCurrentJobSetSize--;
        if (removeFromPersisted && jobStatus.isPersisted()) {
            mPendingJobWriteUids.put(jobStatus.getUid(), true);
            maybeWriteStatusToDiskAsync();
@@ -315,7 +352,9 @@ public final class JobStore {
     */
    @VisibleForTesting
    public void removeForTesting(JobStatus jobStatus) {
        mJobSet.remove(jobStatus);
        if (mJobSet.remove(jobStatus)) {
            mCurrentJobSetSize--;
        }
        if (jobStatus.isPersisted()) {
            mPendingJobWriteUids.put(jobStatus.getUid(), true);
        }
@@ -327,6 +366,7 @@ public final class JobStore {
     */
    public void removeJobsOfUnlistedUsers(int[] keepUserIds) {
        mJobSet.removeJobsOfUnlistedUsers(keepUserIds);
        mCurrentJobSetSize = mJobSet.size();
    }

    /** Note a change in the specified JobStatus that necessitates writing job state to disk. */
@@ -342,6 +382,7 @@ public final class JobStore {
    public void clear() {
        mJobSet.clear();
        mPendingJobWriteUids.put(ALL_UIDS, true);
        mCurrentJobSetSize = 0;
        maybeWriteStatusToDiskAsync();
    }

@@ -352,6 +393,7 @@ public final class JobStore {
    public void clearForTesting() {
        mJobSet.clear();
        mPendingJobWriteUids.put(ALL_UIDS, true);
        mCurrentJobSetSize = 0;
    }

    void setUseSplitFiles(boolean useSplitFiles) {
@@ -442,6 +484,12 @@ public final class JobStore {
        mJobSet.forEachJobForSourceUid(sourceUid, functor);
    }

    private void maybeUpdateHighWaterMark() {
        if (mScheduledJob30MinHighWaterMark < mCurrentJobSetSize) {
            mScheduledJob30MinHighWaterMark = mCurrentJobSetSize;
        }
    }

    /** Version of the db schema. */
    private static final int JOBS_FILE_VERSION = 1;
    /**
@@ -1125,6 +1173,12 @@ public final class JobStore {
            if (needFileMigration) {
                migrateJobFilesAsync();
            }

            // Log the count immediately after loading from boot.
            mCurrentJobSetSize = numJobs;
            mScheduledJob30MinHighWaterMark = mCurrentJobSetSize;
            mScheduledJobHighWaterMarkLoggingRunnable.run();

            if (mCompletionLatch != null) {
                mCompletionLatch.countDown();
            }
+29 −0
Original line number Diff line number Diff line
@@ -60,13 +60,16 @@ import android.os.RemoteCallback;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.SystemClock;
import android.os.UserHandle;
import android.os.UserManager;
import android.provider.DeviceConfig;
import android.util.ArrayMap;
import android.util.ArraySet;
import android.util.Log;
import android.util.LongSparseArray;
import android.util.LongSparseLongArray;
import android.util.Pools;
import android.util.Slog;
import android.util.SparseArray;

import com.android.internal.annotations.GuardedBy;
@@ -179,6 +182,8 @@ import java.util.function.Supplier;
 */
@SystemService(Context.APP_OPS_SERVICE)
public class AppOpsManager {
    private static final String LOG_TAG = "AppOpsManager";

    /**
     * This is a subtle behavior change to {@link #startWatchingMode}.
     *
@@ -7517,6 +7522,7 @@ public class AppOpsManager {
     */
    @RequiresPermission(android.Manifest.permission.MANAGE_APP_OPS_MODES)
    public void setUidMode(int code, int uid, @Mode int mode) {
        logAnySeriousModeChanges(code, uid, null, mode);
        try {
            mService.setUidMode(code, uid, mode);
        } catch (RemoteException e) {
@@ -7537,6 +7543,7 @@ public class AppOpsManager {
    @SystemApi
    @RequiresPermission(android.Manifest.permission.MANAGE_APP_OPS_MODES)
    public void setUidMode(@NonNull String appOp, int uid, @Mode int mode) {
        logAnySeriousModeChanges(strOpToOp(appOp), uid, null, mode);
        try {
            mService.setUidMode(AppOpsManager.strOpToOp(appOp), uid, mode);
        } catch (RemoteException e) {
@@ -7572,11 +7579,32 @@ public class AppOpsManager {
        }
    }

    private void logAnySeriousModeChanges(int code, int uid, String packageName, @Mode int mode) {
        // TODO (b/280869337): Remove this once we have the required data.
        if (code != OP_RUN_ANY_IN_BACKGROUND || mode == MODE_ALLOWED) {
            return;
        }
        final StringBuilder log = new StringBuilder("Attempt to change RUN_ANY_IN_BACKGROUND to ")
                .append(modeToName(mode))
                .append(" for uid: ")
                .append(UserHandle.formatUid(uid))
                .append(" package: ")
                .append(packageName)
                .append(" by: ")
                .append(mContext.getOpPackageName());
        if (Process.myUid() == Process.SYSTEM_UID) {
            Slog.wtfStack(LOG_TAG, log.toString());
        } else {
            Log.w(LOG_TAG, log.toString());
        }
    }

    /** @hide */
    @UnsupportedAppUsage
    @TestApi
    @RequiresPermission(android.Manifest.permission.MANAGE_APP_OPS_MODES)
    public void setMode(int code, int uid, String packageName, @Mode int mode) {
        logAnySeriousModeChanges(code, uid, packageName, mode);
        try {
            mService.setMode(code, uid, packageName, mode);
        } catch (RemoteException e) {
@@ -7599,6 +7627,7 @@ public class AppOpsManager {
    @RequiresPermission(android.Manifest.permission.MANAGE_APP_OPS_MODES)
    public void setMode(@NonNull String op, int uid, @Nullable String packageName,
            @Mode int mode) {
        logAnySeriousModeChanges(strOpToOp(op), uid, packageName, mode);
        try {
            mService.setMode(strOpToOp(op), uid, packageName, mode);
        } catch (RemoteException e) {
+1 −1
Original line number Diff line number Diff line
@@ -91,7 +91,7 @@ public class PackageInfo implements Parcelable {
    /**
     * The version name of this package, as specified by the &lt;manifest&gt;
     * tag's {@link android.R.styleable#AndroidManifest_versionName versionName}
     * attribute.
     * attribute, or null if there was none.
     */
    public String versionName;

+4 −1
Original line number Diff line number Diff line
@@ -1136,7 +1136,10 @@ public final class SQLiteConnectionPool implements Closeable {
        Printer indentedPrinter = PrefixPrinter.create(printer, "    ");
        synchronized (mLock) {
            if (directories != null) {
                directories.add(new File(mConfiguration.path).getParent());
                String parent = new File(mConfiguration.path).getParent();
                if (parent != null) {
                    directories.add(parent);
                }
            }
            boolean isCompatibilityWalEnabled = mConfiguration.isLegacyCompatibilityWalEnabled();
            printer.println("Connection pool for " + mConfiguration.path + ":");
Loading