Loading apex/jobscheduler/service/java/com/android/server/tare/Agent.java +23 −17 Original line number Diff line number Diff line Loading @@ -554,6 +554,25 @@ class Agent { } } @GuardedBy("mLock") void reclaimAllAssetsLocked(final int userId, @NonNull final String pkgName, int regulationId) { final Ledger ledger = mScribe.getLedgerLocked(userId, pkgName); final long curBalance = ledger.getCurrentBalance(); if (curBalance <= 0) { return; } if (DEBUG) { Slog.i(TAG, "Reclaiming " + cakeToString(curBalance) + " from " + appToString(userId, pkgName) + " because of " + eventToString(regulationId)); } final long now = getCurrentTimeMillis(); recordTransactionLocked(userId, pkgName, ledger, new Ledger.Transaction(now, now, regulationId, null, -curBalance, 0), true); } /** * Reclaim a percentage of unused ARCs from every app that hasn't been used recently. The * reclamation will not reduce an app's balance below its minimum balance as dictated by Loading @@ -564,7 +583,7 @@ class Agent { * @param minUnusedTimeMs The minimum amount of time (in milliseconds) that must have * transpired since the last user usage event before we will consider * reclaiming ARCs from the app. * @param scaleMinBalance Whether or not to used the scaled minimum app balance. If false, * @param scaleMinBalance Whether or not to use the scaled minimum app balance. If false, * this will use the constant min balance floor given by * {@link EconomicPolicy#getMinSatiatedBalance(int, String)}. If true, * this will use the scaled balance given by Loading Loading @@ -603,7 +622,8 @@ class Agent { } if (toReclaim > 0) { if (DEBUG) { Slog.i(TAG, "Reclaiming unused wealth! Taking " + toReclaim Slog.i(TAG, "Reclaiming unused wealth! Taking " + cakeToString(toReclaim) + " from " + appToString(userId, pkgName)); } Loading Loading @@ -667,21 +687,7 @@ class Agent { */ @GuardedBy("mLock") void onAppRestrictedLocked(final int userId, @NonNull final String pkgName) { final long curBalance = getBalanceLocked(userId, pkgName); final long minBalance = mIrs.getMinBalanceLocked(userId, pkgName); if (curBalance <= minBalance) { return; } if (DEBUG) { Slog.i(TAG, "App restricted! Taking " + curBalance + " from " + appToString(userId, pkgName)); } final long now = getCurrentTimeMillis(); final Ledger ledger = mScribe.getLedgerLocked(userId, pkgName); recordTransactionLocked(userId, pkgName, ledger, new Ledger.Transaction(now, now, REGULATION_BG_RESTRICTED, null, -curBalance, 0), true); reclaimAllAssetsLocked(userId, pkgName, REGULATION_BG_RESTRICTED); } /** Loading apex/jobscheduler/service/java/com/android/server/tare/EconomicPolicy.java +3 −0 Original line number Diff line number Diff line Loading @@ -70,6 +70,7 @@ public abstract class EconomicPolicy { /** App is fully restricted from running in the background. */ static final int REGULATION_BG_RESTRICTED = TYPE_REGULATION | 5; static final int REGULATION_BG_UNRESTRICTED = TYPE_REGULATION | 6; static final int REGULATION_FORCE_STOP = TYPE_REGULATION | 8; static final int REWARD_NOTIFICATION_SEEN = TYPE_REWARD | 0; static final int REWARD_NOTIFICATION_INTERACTION = TYPE_REWARD | 1; Loading Loading @@ -409,6 +410,8 @@ public abstract class EconomicPolicy { return "BG_RESTRICTED"; case REGULATION_BG_UNRESTRICTED: return "BG_UNRESTRICTED"; case REGULATION_FORCE_STOP: return "FORCE_STOP"; } return "UNKNOWN_REGULATION:" + Integer.toHexString(eventId); } Loading apex/jobscheduler/service/java/com/android/server/tare/InternalResourceService.java +3 −1 Original line number Diff line number Diff line Loading @@ -533,7 +533,9 @@ public class InternalResourceService extends SystemService { void onPackageForceStopped(final int userId, @NonNull final String pkgName) { synchronized (mLock) { // TODO: reduce ARC count by some amount // Remove all credits if the user force stops the app. It will slowly regain them // in response to different events. mAgent.reclaimAllAssetsLocked(userId, pkgName, EconomicPolicy.REGULATION_FORCE_STOP); } } Loading Loading
apex/jobscheduler/service/java/com/android/server/tare/Agent.java +23 −17 Original line number Diff line number Diff line Loading @@ -554,6 +554,25 @@ class Agent { } } @GuardedBy("mLock") void reclaimAllAssetsLocked(final int userId, @NonNull final String pkgName, int regulationId) { final Ledger ledger = mScribe.getLedgerLocked(userId, pkgName); final long curBalance = ledger.getCurrentBalance(); if (curBalance <= 0) { return; } if (DEBUG) { Slog.i(TAG, "Reclaiming " + cakeToString(curBalance) + " from " + appToString(userId, pkgName) + " because of " + eventToString(regulationId)); } final long now = getCurrentTimeMillis(); recordTransactionLocked(userId, pkgName, ledger, new Ledger.Transaction(now, now, regulationId, null, -curBalance, 0), true); } /** * Reclaim a percentage of unused ARCs from every app that hasn't been used recently. The * reclamation will not reduce an app's balance below its minimum balance as dictated by Loading @@ -564,7 +583,7 @@ class Agent { * @param minUnusedTimeMs The minimum amount of time (in milliseconds) that must have * transpired since the last user usage event before we will consider * reclaiming ARCs from the app. * @param scaleMinBalance Whether or not to used the scaled minimum app balance. If false, * @param scaleMinBalance Whether or not to use the scaled minimum app balance. If false, * this will use the constant min balance floor given by * {@link EconomicPolicy#getMinSatiatedBalance(int, String)}. If true, * this will use the scaled balance given by Loading Loading @@ -603,7 +622,8 @@ class Agent { } if (toReclaim > 0) { if (DEBUG) { Slog.i(TAG, "Reclaiming unused wealth! Taking " + toReclaim Slog.i(TAG, "Reclaiming unused wealth! Taking " + cakeToString(toReclaim) + " from " + appToString(userId, pkgName)); } Loading Loading @@ -667,21 +687,7 @@ class Agent { */ @GuardedBy("mLock") void onAppRestrictedLocked(final int userId, @NonNull final String pkgName) { final long curBalance = getBalanceLocked(userId, pkgName); final long minBalance = mIrs.getMinBalanceLocked(userId, pkgName); if (curBalance <= minBalance) { return; } if (DEBUG) { Slog.i(TAG, "App restricted! Taking " + curBalance + " from " + appToString(userId, pkgName)); } final long now = getCurrentTimeMillis(); final Ledger ledger = mScribe.getLedgerLocked(userId, pkgName); recordTransactionLocked(userId, pkgName, ledger, new Ledger.Transaction(now, now, REGULATION_BG_RESTRICTED, null, -curBalance, 0), true); reclaimAllAssetsLocked(userId, pkgName, REGULATION_BG_RESTRICTED); } /** Loading
apex/jobscheduler/service/java/com/android/server/tare/EconomicPolicy.java +3 −0 Original line number Diff line number Diff line Loading @@ -70,6 +70,7 @@ public abstract class EconomicPolicy { /** App is fully restricted from running in the background. */ static final int REGULATION_BG_RESTRICTED = TYPE_REGULATION | 5; static final int REGULATION_BG_UNRESTRICTED = TYPE_REGULATION | 6; static final int REGULATION_FORCE_STOP = TYPE_REGULATION | 8; static final int REWARD_NOTIFICATION_SEEN = TYPE_REWARD | 0; static final int REWARD_NOTIFICATION_INTERACTION = TYPE_REWARD | 1; Loading Loading @@ -409,6 +410,8 @@ public abstract class EconomicPolicy { return "BG_RESTRICTED"; case REGULATION_BG_UNRESTRICTED: return "BG_UNRESTRICTED"; case REGULATION_FORCE_STOP: return "FORCE_STOP"; } return "UNKNOWN_REGULATION:" + Integer.toHexString(eventId); } Loading
apex/jobscheduler/service/java/com/android/server/tare/InternalResourceService.java +3 −1 Original line number Diff line number Diff line Loading @@ -533,7 +533,9 @@ public class InternalResourceService extends SystemService { void onPackageForceStopped(final int userId, @NonNull final String pkgName) { synchronized (mLock) { // TODO: reduce ARC count by some amount // Remove all credits if the user force stops the app. It will slowly regain them // in response to different events. mAgent.reclaimAllAssetsLocked(userId, pkgName, EconomicPolicy.REGULATION_FORCE_STOP); } } Loading