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

Commit 386362eb authored by Kweku Adams's avatar Kweku Adams Committed by Android (Google) Code Review
Browse files

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

parents a98298ec 9d999938
Loading
Loading
Loading
Loading
+5 −0
Original line number Original line Diff line number Diff line
@@ -143,6 +143,11 @@ public interface AppStandbyInternal {
    void setAppStandbyBuckets(@NonNull List<AppStandbyInfo> appBuckets, int userId, int callingUid,
    void setAppStandbyBuckets(@NonNull List<AppStandbyInfo> appBuckets, int userId, int callingUid,
            int callingPid);
            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
     * Put the specified app in the
     * {@link android.app.usage.UsageStatsManager#STANDBY_BUCKET_RESTRICTED}
     * {@link android.app.usage.UsageStatsManager#STANDBY_BUCKET_RESTRICTED}
+12 −0
Original line number Original line 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
    @Override
    public void restrictApp(@NonNull String packageName, int userId,
    public void restrictApp(@NonNull String packageName, int userId,
            @ForcedReasons int restrictReason) {
            @ForcedReasons int restrictReason) {
+1 −0
Original line number Original line Diff line number Diff line
@@ -53,6 +53,7 @@ interface IUsageStatsManager {
    void setAppStandbyBucket(String packageName, int bucket, int userId);
    void setAppStandbyBucket(String packageName, int bucket, int userId);
    ParceledListSlice getAppStandbyBuckets(String callingPackage, int userId);
    ParceledListSlice getAppStandbyBuckets(String callingPackage, int userId);
    void setAppStandbyBuckets(in ParceledListSlice appBuckets, 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 setEstimatedLaunchTime(String packageName, long estimatedLaunchTime, int userId);
    void setEstimatedLaunchTimes(in ParceledListSlice appLaunchTimes, int userId);
    void setEstimatedLaunchTimes(in ParceledListSlice appLaunchTimes, int userId);
    void registerAppUsageObserver(int observerId, in String[] packages, long timeLimitMs,
    void registerAppUsageObserver(int observerId, in String[] packages, long timeLimitMs,
+17 −0
Original line number Original line 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
     * 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
     * one of its {@link android.app.Activity Activities}. The provided time is persisted across
+34 −0
Original line number Original line 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
        @Override
        public void setEstimatedLaunchTime(String packageName, long estimatedLaunchTime,
        public void setEstimatedLaunchTime(String packageName, long estimatedLaunchTime,
                int userId) {
                int userId) {