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

Commit e5bcba0a authored by android-build-team Robot's avatar android-build-team Robot
Browse files

Snap for 7310088 from e723159e to sc-release

Change-Id: Ieef3cc314c37b4e478a34cfe654b8c3c71034703
parents 186f01d0 e723159e
Loading
Loading
Loading
Loading
+4 −14
Original line number Diff line number Diff line
@@ -402,16 +402,6 @@ java_library_static {
    },
}

java_defaults {
    name: "android_defaults_stubs_current",
    sdk_version: "none",
    system_modules: "none",
    java_version: "1.8",
    compile_dex: true,
    defaults_visibility: ["//visibility:private"],
    visibility: ["//visibility:public"],
}

java_defaults {
    name: "android_stubs_dists_default",
    dist: {
@@ -431,7 +421,7 @@ java_library_static {
        "android-non-updatable.stubs",
        "private-stub-annotations-jar",
    ],
    defaults: ["android_defaults_stubs_current"],
    defaults: ["android.jar_defaults"],
}

java_library_static {
@@ -441,7 +431,7 @@ java_library_static {
        "private-stub-annotations-jar",
    ],
    defaults: [
        "android_defaults_stubs_current",
        "android.jar_defaults",
        "android_stubs_dists_default",
    ],
    dist: {
@@ -469,7 +459,7 @@ java_library_static {
        "private-stub-annotations-jar",
    ],
    defaults: [
        "android_defaults_stubs_current",
        "android.jar_defaults",
        "android_stubs_dists_default",
    ],
    dist: {
@@ -480,7 +470,7 @@ java_library_static {
java_library_static {
    name: "android_module_lib_stubs_current",
    defaults: [
        "android_defaults_stubs_current",
        "android.jar_defaults",
        "android_stubs_dists_default",
    ],
    static_libs: [
+1 −0
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ java_library {
        "framework",
        "framework-appsearch",
        "services.core",
        "services.usage",
    ],
    static_libs: [
        "icing-java-proto-lite",
+72 −16
Original line number Diff line number Diff line
@@ -40,7 +40,9 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.content.pm.PackageManagerInternal;
import android.content.pm.PackageStats;
import android.os.Binder;
import android.os.Bundle;
import android.os.ParcelFileDescriptor;
@@ -60,6 +62,8 @@ import com.android.server.appsearch.external.localstorage.AppSearchImpl;
import com.android.server.appsearch.external.localstorage.stats.CallStats;
import com.android.server.appsearch.stats.LoggerInstanceManager;
import com.android.server.appsearch.stats.PlatformLogger;
import com.android.server.usage.StorageStatsManagerInternal;
import com.android.server.usage.StorageStatsManagerInternal.StorageStatsAugmenter;

import com.google.android.icing.proto.PersistType;

@@ -82,6 +86,7 @@ import java.util.concurrent.TimeUnit;
public class AppSearchManagerService extends SystemService {
    private static final String TAG = "AppSearchManagerService";
    private final Context mContext;
    private PackageManager mPackageManager;
    private PackageManagerInternal mPackageManagerInternal;
    private ImplInstanceManager mImplInstanceManager;
    private UserManager mUserManager;
@@ -109,11 +114,14 @@ public class AppSearchManagerService extends SystemService {
    @Override
    public void onStart() {
        publishBinderService(Context.APP_SEARCH_SERVICE, new Stub());
        mPackageManager = getContext().getPackageManager();
        mPackageManagerInternal = LocalServices.getService(PackageManagerInternal.class);
        mImplInstanceManager = ImplInstanceManager.getInstance(mContext);
        mUserManager = mContext.getSystemService(UserManager.class);
        mLoggerInstanceManager = LoggerInstanceManager.getInstance();
        registerReceivers();
        LocalServices.getService(StorageStatsManagerInternal.class)
                .registerStorageStatsAugmenter(new AppSearchStorageStatsAugmenter(), TAG);
    }

    private void registerReceivers() {
@@ -168,6 +176,21 @@ public class AppSearchManagerService extends SystemService {
        }
    }

    private void verifyUserUnlocked(int callingUserId) {
        synchronized (mUnlockedUserIdsLocked) {
            // First, check the local copy.
            if (mUnlockedUserIdsLocked.contains(callingUserId)) {
                return;
            }
            // If the local copy says the user is locked, check with UM for the actual state,
            // since the user might just have been unlocked.
            if (!mUserManager.isUserUnlockingOrUnlocked(UserHandle.of(callingUserId))) {
                throw new IllegalStateException(
                        "User " + callingUserId + " is locked or not running.");
            }
        }
    }

    private class Stub extends IAppSearchManager.Stub {
        @Override
        public void setSchema(
@@ -769,21 +792,6 @@ public class AppSearchManagerService extends SystemService {
            });
        }

        private void verifyUserUnlocked(int callingUserId) {
            synchronized (mUnlockedUserIdsLocked) {
                // First, check the local copy.
                if (mUnlockedUserIdsLocked.contains(callingUserId)) {
                    return;
                }
                // If the local copy says the user is locked, check with UM for the actual state,
                // since the user might just have been unlocked.
                if (!mUserManager.isUserUnlockingOrUnlocked(UserHandle.of(callingUserId))) {
                    throw new IllegalStateException(
                            "User " + callingUserId + " is locked or not running.");
                }
            }
        }

        private void verifyCallingPackage(int callingUid, @NonNull String callingPackage) {
            Objects.requireNonNull(callingPackage);
            if (mPackageManagerInternal.getPackageUid(
@@ -859,4 +867,52 @@ public class AppSearchManagerService extends SystemService {
                /*name=*/ null,
                /*callerPackage=*/ null);
    }

    // TODO(b/179160886): Cache the previous storage stats.
    private class AppSearchStorageStatsAugmenter implements StorageStatsAugmenter {
        @Override
        public void augmentStatsForPackage(
                @NonNull PackageStats stats,
                @NonNull String packageName,
                @UserIdInt int userId,
                boolean callerHasStatsPermission) {
            Objects.requireNonNull(stats);
            Objects.requireNonNull(packageName);
            try {
                verifyUserUnlocked(userId);
                AppSearchImpl impl = mImplInstanceManager.getOrCreateAppSearchImpl(mContext,
                        userId);
                stats.dataSize += impl.getStorageInfoForPackage(packageName).getSizeBytes();
            } catch (Throwable t) {
                Log.e(
                        TAG,
                        "Unable to augment storage stats for userId "
                                + userId
                                + " packageName "
                                + packageName,
                        t);
            }
        }

        @Override
        public void augmentStatsForUid(
                @NonNull PackageStats stats, int uid, boolean callerHasStatsPermission) {
            Objects.requireNonNull(stats);
            int userId = UserHandle.getUserId(uid);
            try {
                verifyUserUnlocked(userId);
                String[] packagesForUid = mPackageManager.getPackagesForUid(uid);
                if (packagesForUid == null) {
                    return;
                }
                AppSearchImpl impl = mImplInstanceManager.getOrCreateAppSearchImpl(mContext,
                        userId);
                for (String packageName : packagesForUid) {
                    stats.dataSize += impl.getStorageInfoForPackage(packageName).getSizeBytes();
                }
            } catch (Throwable t) {
                Log.e(TAG, "Unable to augment storage stats for uid " + uid, t);
            }
        }
    }
}
+2 −1
Original line number Diff line number Diff line
@@ -49,7 +49,8 @@ public class BlobStoreIdleJobService extends JobService {
    public boolean onStopJob(final JobParameters params) {
        Slog.d(TAG, "Idle maintenance job is stopped; id=" + params.getJobId()
                + ", reason="
                + JobParameters.getLegacyReasonCodeDescription(params.getLegacyStopReason()));
                + JobParameters.getInternalReasonCodeDescription(
                        params.getInternalStopReasonCode()));
        return false;
    }

+54 −34
Original line number Diff line number Diff line
@@ -44,36 +44,53 @@ import java.lang.annotation.RetentionPolicy;
public class JobParameters implements Parcelable {

    /** @hide */
    public static final int REASON_CANCELED = JobProtoEnums.STOP_REASON_CANCELLED; // 0.
    public static final int INTERNAL_STOP_REASON_CANCELED =
            JobProtoEnums.STOP_REASON_CANCELLED; // 0.
    /** @hide */
    public static final int REASON_CONSTRAINTS_NOT_SATISFIED =
    public static final int INTERNAL_STOP_REASON_CONSTRAINTS_NOT_SATISFIED =
            JobProtoEnums.STOP_REASON_CONSTRAINTS_NOT_SATISFIED; // 1.
    /** @hide */
    public static final int REASON_PREEMPT = JobProtoEnums.STOP_REASON_PREEMPT; // 2.
    /** @hide */
    public static final int REASON_TIMEOUT = JobProtoEnums.STOP_REASON_TIMEOUT; // 3.
    public static final int INTERNAL_STOP_REASON_PREEMPT =
            JobProtoEnums.STOP_REASON_PREEMPT; // 2.
    /**
     * The job ran for at least its minimum execution limit.
     * @hide
     */
    public static final int INTERNAL_STOP_REASON_TIMEOUT =
            JobProtoEnums.STOP_REASON_TIMEOUT; // 3.
    /** @hide */
    public static final int REASON_DEVICE_IDLE = JobProtoEnums.STOP_REASON_DEVICE_IDLE; // 4.
    public static final int INTERNAL_STOP_REASON_DEVICE_IDLE =
            JobProtoEnums.STOP_REASON_DEVICE_IDLE; // 4.
    /** @hide */
    public static final int REASON_DEVICE_THERMAL = JobProtoEnums.STOP_REASON_DEVICE_THERMAL; // 5.
    public static final int INTERNAL_STOP_REASON_DEVICE_THERMAL =
            JobProtoEnums.STOP_REASON_DEVICE_THERMAL; // 5.
    /**
     * The job is in the {@link android.app.usage.UsageStatsManager#STANDBY_BUCKET_RESTRICTED}
     * bucket.
     *
     * @hide
     */
    public static final int REASON_RESTRICTED_BUCKET =
    public static final int INTERNAL_STOP_REASON_RESTRICTED_BUCKET =
            JobProtoEnums.STOP_REASON_RESTRICTED_BUCKET; // 6.
    /**
     * The app was uninstalled.
     * @hide
     */
    public static  final int DEBUG_REASON_UNINSTALL = 7;
    public static final int INTERNAL_STOP_REASON_UNINSTALL = 7;
    /**
     * The app's data was cleared.
     * @hide
     */
    public static  final int DEBUG_REASON_DATA_CLEARED = 8;
    public static final int INTERNAL_STOP_REASON_DATA_CLEARED = 8;
    /**
     * @hide
     */
    public static final int INTERNAL_STOP_REASON_RTC_UPDATED = 9;
    /**
     * The app called jobFinished() on its own.
     * @hide
     */
    public static final int INTERNAL_STOP_REASON_SUCCESSFUL_FINISH = 10;

    /**
     * All the stop reason codes. This should be regarded as an immutable array at runtime.
@@ -85,13 +102,13 @@ public class JobParameters implements Parcelable {
     * @hide
     */
    public static final int[] JOB_STOP_REASON_CODES = {
            REASON_CANCELED,
            REASON_CONSTRAINTS_NOT_SATISFIED,
            REASON_PREEMPT,
            REASON_TIMEOUT,
            REASON_DEVICE_IDLE,
            REASON_DEVICE_THERMAL,
            REASON_RESTRICTED_BUCKET,
            INTERNAL_STOP_REASON_CANCELED,
            INTERNAL_STOP_REASON_CONSTRAINTS_NOT_SATISFIED,
            INTERNAL_STOP_REASON_PREEMPT,
            INTERNAL_STOP_REASON_TIMEOUT,
            INTERNAL_STOP_REASON_DEVICE_IDLE,
            INTERNAL_STOP_REASON_DEVICE_THERMAL,
            INTERNAL_STOP_REASON_RESTRICTED_BUCKET,
    };

    /**
@@ -99,21 +116,24 @@ public class JobParameters implements Parcelable {
     */
    // TODO(142420609): make it @SystemApi for mainline
    @NonNull
    public static String getLegacyReasonCodeDescription(int reasonCode) {
    public static String getInternalReasonCodeDescription(int reasonCode) {
        switch (reasonCode) {
            case REASON_CANCELED: return "canceled";
            case REASON_CONSTRAINTS_NOT_SATISFIED: return "constraints";
            case REASON_PREEMPT: return "preempt";
            case REASON_TIMEOUT: return "timeout";
            case REASON_DEVICE_IDLE: return "device_idle";
            case REASON_DEVICE_THERMAL: return "thermal";
            case REASON_RESTRICTED_BUCKET: return "restricted_bucket";
            case INTERNAL_STOP_REASON_CANCELED: return "canceled";
            case INTERNAL_STOP_REASON_CONSTRAINTS_NOT_SATISFIED: return "constraints";
            case INTERNAL_STOP_REASON_PREEMPT: return "preempt";
            case INTERNAL_STOP_REASON_TIMEOUT: return "timeout";
            case INTERNAL_STOP_REASON_DEVICE_IDLE: return "device_idle";
            case INTERNAL_STOP_REASON_DEVICE_THERMAL: return "thermal";
            case INTERNAL_STOP_REASON_RESTRICTED_BUCKET: return "restricted_bucket";
            case INTERNAL_STOP_REASON_UNINSTALL: return "uninstall";
            case INTERNAL_STOP_REASON_DATA_CLEARED: return "data_cleared";
            case INTERNAL_STOP_REASON_RTC_UPDATED: return "rtc_updated";
            case INTERNAL_STOP_REASON_SUCCESSFUL_FINISH: return "successful_finish";
            default: return "unknown:" + reasonCode;
        }
    }

    /** @hide */
    // TODO: move current users of legacy reasons to new public reasons
    @NonNull
    public static int[] getJobStopReasonCodes() {
        return JOB_STOP_REASON_CODES;
@@ -241,7 +261,7 @@ public class JobParameters implements Parcelable {
    private final Network network;

    private int mStopReason = STOP_REASON_UNDEFINED;
    private int mLegacyStopReason; // Default value of stopReason is REASON_CANCELED
    private int mInternalStopReason; // Default value is REASON_CANCELED
    private String debugStopReason; // Human readable stop reason for debugging.

    /** @hide */
@@ -280,8 +300,8 @@ public class JobParameters implements Parcelable {
    }

    /** @hide */
    public int getLegacyStopReason() {
        return mLegacyStopReason;
    public int getInternalStopReasonCode() {
        return mInternalStopReason;
    }

    /**
@@ -502,15 +522,15 @@ public class JobParameters implements Parcelable {
            network = null;
        }
        mStopReason = in.readInt();
        mLegacyStopReason = in.readInt();
        mInternalStopReason = in.readInt();
        debugStopReason = in.readString();
    }

    /** @hide */
    public void setStopReason(@StopReason int reason, int legacyStopReason,
    public void setStopReason(@StopReason int reason, int internalStopReason,
            String debugStopReason) {
        mStopReason = reason;
        mLegacyStopReason = legacyStopReason;
        mInternalStopReason = internalStopReason;
        this.debugStopReason = debugStopReason;
    }

@@ -543,7 +563,7 @@ public class JobParameters implements Parcelable {
            dest.writeInt(0);
        }
        dest.writeInt(mStopReason);
        dest.writeInt(mLegacyStopReason);
        dest.writeInt(mInternalStopReason);
        dest.writeString(debugStopReason);
    }

Loading