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

Commit a75426fc authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Don't allocate ARCs to nonfunctional apps."

parents ecf59820 70db8c3b
Loading
Loading
Loading
Loading
+18 −8
Original line number Diff line number Diff line
@@ -633,6 +633,18 @@ class Agent {
        }
    }

    /** Returns true if an app should be given credits in the general distributions. */
    private boolean shouldGiveCredits(@NonNull PackageInfo packageInfo) {
        final ApplicationInfo applicationInfo = packageInfo.applicationInfo;
        // Skip apps that wouldn't be doing any work. Giving them ARCs would be wasteful.
        if (applicationInfo == null || !applicationInfo.hasCode()) {
            return false;
        }
        final int userId = UserHandle.getUserId(packageInfo.applicationInfo.uid);
        // No point allocating ARCs to the system. It can do whatever it wants.
        return !mIrs.isSystem(userId, packageInfo.packageName);
    }

    @GuardedBy("mLock")
    void distributeBasicIncomeLocked(int batteryLevel) {
        List<PackageInfo> pkgs = mIrs.getInstalledPackages();
@@ -641,12 +653,11 @@ class Agent {
        final long now = getCurrentTimeMillis();
        for (int i = 0; i < pkgs.size(); ++i) {
            final PackageInfo pkgInfo = pkgs.get(i);
            final int userId = UserHandle.getUserId(pkgInfo.applicationInfo.uid);
            final String pkgName = pkgInfo.packageName;
            if (mIrs.isSystem(userId, pkgName)) {
                // No point allocating ARCs to the system. It can do whatever it wants.
            if (!shouldGiveCredits(pkgInfo)) {
                continue;
            }
            final int userId = UserHandle.getUserId(pkgInfo.applicationInfo.uid);
            final String pkgName = pkgInfo.packageName;
            Ledger ledger = getLedgerLocked(userId, pkgName);
            final long minBalance = mIrs.getMinBalanceLocked(userId, pkgName);
            final double perc = batteryLevel / 100d;
@@ -682,12 +693,11 @@ class Agent {

        for (int i = 0; i < pkgs.size(); ++i) {
            final PackageInfo packageInfo = pkgs.get(i);
            final String pkgName = packageInfo.packageName;
            final Ledger ledger = getLedgerLocked(userId, pkgName);
            if (mIrs.isSystem(userId, pkgName)) {
                // No point allocating ARCs to the system. It can do whatever it wants.
            if (!shouldGiveCredits(packageInfo)) {
                continue;
            }
            final String pkgName = packageInfo.packageName;
            final Ledger ledger = getLedgerLocked(userId, pkgName);
            if (ledger.getCurrentBalance() > 0) {
                // App already got credits somehow. Move along.
                Slog.wtf(TAG, "App " + pkgName + " had credits before economy was set up");