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

Commit 9265c3bb authored by Kweku Adams's avatar Kweku Adams Committed by Automerger Merge Worker
Browse files

Merge "Let settings query an app's minimum bucket." into tm-dev am: 386362eb

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/17036723

Change-Id: I0028b22598ea4e57108c99e25a3062f16c7e394a
parents 320b304d 386362eb
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -143,6 +143,11 @@ public interface AppStandbyInternal {
    void setAppStandbyBuckets(@NonNull List<AppStandbyInfo> appBuckets, int userId, int callingUid,
            int callingPid);

    /** Return the lowest bucket this app can enter. */
    @StandbyBuckets
    int getAppMinStandbyBucket(String packageName, int appId, int userId,
            boolean shouldObfuscateInstantApps);

    /**
     * Put the specified app in the
     * {@link android.app.usage.UsageStatsManager#STANDBY_BUCKET_RESTRICTED}
+12 −0
Original line number Diff line number Diff line
@@ -1436,6 +1436,18 @@ public class AppStandbyController
        }
    }

    @Override
    @StandbyBuckets
    public int getAppMinStandbyBucket(String packageName, int appId, int userId,
            boolean shouldObfuscateInstantApps) {
        if (shouldObfuscateInstantApps && mInjector.isPackageEphemeral(userId, packageName)) {
            return STANDBY_BUCKET_NEVER;
        }
        synchronized (mAppIdleLock) {
            return getAppMinBucket(packageName, appId, userId);
        }
    }

    @Override
    public void restrictApp(@NonNull String packageName, int userId,
            @ForcedReasons int restrictReason) {
+1 −0
Original line number Diff line number Diff line
@@ -53,6 +53,7 @@ interface IUsageStatsManager {
    void setAppStandbyBucket(String packageName, int bucket, int userId);
    ParceledListSlice getAppStandbyBuckets(String callingPackage, int userId);
    void setAppStandbyBuckets(in ParceledListSlice appBuckets, int userId);
    int getAppMinStandbyBucket(String packageName, String callingPackage, int userId);
    void setEstimatedLaunchTime(String packageName, long estimatedLaunchTime, int userId);
    void setEstimatedLaunchTimes(in ParceledListSlice appLaunchTimes, int userId);
    void registerAppUsageObserver(int observerId, in String[] packages, long timeLimitMs,
+17 −0
Original line number Diff line number Diff line
@@ -786,6 +786,23 @@ public final class UsageStatsManager {
        }
    }

    /**
     * Return the lowest bucket this app can ever enter.
     *
     * @param packageName the package for which to fetch the minimum allowed standby bucket.
     * {@hide}
     */
    @StandbyBuckets
    @RequiresPermission(android.Manifest.permission.PACKAGE_USAGE_STATS)
    public int getAppMinStandbyBucket(String packageName) {
        try {
            return mService.getAppMinStandbyBucket(packageName, mContext.getOpPackageName(),
                    mContext.getUserId());
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Changes an app's estimated launch time. An app is considered "launched" when a user opens
     * one of its {@link android.app.Activity Activities}. The provided time is persisted across
+34 −0
Original line number Diff line number Diff line
@@ -2378,6 +2378,40 @@ public class UsageStatsService extends SystemService implements
            }
        }

        @Override
        public int getAppMinStandbyBucket(String packageName, String callingPackage, int userId) {
            final int callingUid = Binder.getCallingUid();
            try {
                userId = ActivityManager.getService().handleIncomingUser(
                        Binder.getCallingPid(), callingUid, userId, false, false,
                        "getAppStandbyBucket", null);
            } catch (RemoteException re) {
                throw re.rethrowFromSystemServer();
            }
            final int packageUid = mPackageManagerInternal.getPackageUid(packageName, 0, userId);
            // If the calling app is asking about itself, continue, else check for permission.
            if (packageUid != callingUid) {
                if (!hasPermission(callingPackage)) {
                    throw new SecurityException(
                            "Don't have permission to query min app standby bucket");
                }
            }
            if (packageUid < 0) {
                throw new IllegalArgumentException(
                        "Cannot get min standby bucket for non existent package ("
                                + packageName + ")");
            }
            final boolean obfuscateInstantApps = shouldObfuscateInstantAppsForCaller(callingUid,
                    userId);
            final long token = Binder.clearCallingIdentity();
            try {
                return mAppStandby.getAppMinStandbyBucket(
                        packageName, UserHandle.getAppId(packageUid), userId, obfuscateInstantApps);
            } finally {
                Binder.restoreCallingIdentity(token);
            }
        }

        @Override
        public void setEstimatedLaunchTime(String packageName, long estimatedLaunchTime,
                int userId) {