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

Commit ea9f0d0f authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Rename narc to cake." into tm-dev am: a300bfc5 am: 12fa729d

parents a1c5c0cb 12fa729d
Loading
Loading
Loading
Loading
+8 −8
Original line number Original line Diff line number Diff line
@@ -28,8 +28,8 @@ import static com.android.server.tare.EconomicPolicy.TYPE_REWARD;
import static com.android.server.tare.EconomicPolicy.eventToString;
import static com.android.server.tare.EconomicPolicy.eventToString;
import static com.android.server.tare.EconomicPolicy.getEventType;
import static com.android.server.tare.EconomicPolicy.getEventType;
import static com.android.server.tare.TareUtils.appToString;
import static com.android.server.tare.TareUtils.appToString;
import static com.android.server.tare.TareUtils.cakeToString;
import static com.android.server.tare.TareUtils.getCurrentTimeMillis;
import static com.android.server.tare.TareUtils.getCurrentTimeMillis;
import static com.android.server.tare.TareUtils.narcToString;


import android.annotation.NonNull;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.Nullable;
@@ -161,7 +161,7 @@ class Agent {


    @GuardedBy("mLock")
    @GuardedBy("mLock")
    private boolean isAffordableLocked(long balance, long price, long ctp) {
    private boolean isAffordableLocked(long balance, long price, long ctp) {
        return balance >= price && mScribe.getRemainingConsumableNarcsLocked() >= ctp;
        return balance >= price && mScribe.getRemainingConsumableCakesLocked() >= ctp;
    }
    }


    @GuardedBy("mLock")
    @GuardedBy("mLock")
@@ -464,13 +464,13 @@ class Agent {
                    + eventToString(transaction.eventId)
                    + eventToString(transaction.eventId)
                    + (transaction.tag == null ? "" : ":" + transaction.tag)
                    + (transaction.tag == null ? "" : ":" + transaction.tag)
                    + " for " + appToString(userId, pkgName)
                    + " for " + appToString(userId, pkgName)
                    + " by " + narcToString(transaction.delta - newDelta));
                    + " by " + cakeToString(transaction.delta - newDelta));
            transaction = new Ledger.Transaction(
            transaction = new Ledger.Transaction(
                    transaction.startTimeMs, transaction.endTimeMs,
                    transaction.startTimeMs, transaction.endTimeMs,
                    transaction.eventId, transaction.tag, newDelta, transaction.ctp);
                    transaction.eventId, transaction.tag, newDelta, transaction.ctp);
        }
        }
        ledger.recordTransaction(transaction);
        ledger.recordTransaction(transaction);
        mScribe.adjustRemainingConsumableNarcsLocked(-transaction.ctp);
        mScribe.adjustRemainingConsumableCakesLocked(-transaction.ctp);
        if (transaction.delta != 0 && notifyOnAffordabilityChange) {
        if (transaction.delta != 0 && notifyOnAffordabilityChange) {
            final ArraySet<ActionAffordabilityNote> actionAffordabilityNotes =
            final ArraySet<ActionAffordabilityNote> actionAffordabilityNotes =
                    mActionAffordabilityNotes.get(userId, pkgName);
                    mActionAffordabilityNotes.get(userId, pkgName);
@@ -724,7 +724,7 @@ class Agent {
    private void reclaimAssetsLocked(final int userId, @NonNull final String pkgName) {
    private void reclaimAssetsLocked(final int userId, @NonNull final String pkgName) {
        final Ledger ledger = mScribe.getLedgerLocked(userId, pkgName);
        final Ledger ledger = mScribe.getLedgerLocked(userId, pkgName);
        if (ledger.getCurrentBalance() != 0) {
        if (ledger.getCurrentBalance() != 0) {
            mScribe.adjustRemainingConsumableNarcsLocked(-ledger.getCurrentBalance());
            mScribe.adjustRemainingConsumableCakesLocked(-ledger.getCurrentBalance());
        }
        }
        mScribe.discardLedgerLocked(userId, pkgName);
        mScribe.discardLedgerLocked(userId, pkgName);
        mCurrentOngoingEvents.delete(userId, pkgName);
        mCurrentOngoingEvents.delete(userId, pkgName);
@@ -872,7 +872,7 @@ class Agent {
            return;
            return;
        }
        }
        mTrendCalculator.reset(getBalanceLocked(userId, pkgName),
        mTrendCalculator.reset(getBalanceLocked(userId, pkgName),
                mScribe.getRemainingConsumableNarcsLocked(),
                mScribe.getRemainingConsumableCakesLocked(),
                mActionAffordabilityNotes.get(userId, pkgName));
                mActionAffordabilityNotes.get(userId, pkgName));
        ongoingEvents.forEach(mTrendCalculator);
        ongoingEvents.forEach(mTrendCalculator);
        final long lowerTimeMs = mTrendCalculator.getTimeToCrossLowerThresholdMs();
        final long lowerTimeMs = mTrendCalculator.getTimeToCrossLowerThresholdMs();
@@ -1260,11 +1260,11 @@ class Agent {
                        pw.print(" runtime=");
                        pw.print(" runtime=");
                        TimeUtils.formatDuration(nowElapsed - ongoingEvent.startTimeElapsed, pw);
                        TimeUtils.formatDuration(nowElapsed - ongoingEvent.startTimeElapsed, pw);
                        pw.print(" delta/sec=");
                        pw.print(" delta/sec=");
                        pw.print(narcToString(ongoingEvent.getDeltaPerSec()));
                        pw.print(cakeToString(ongoingEvent.getDeltaPerSec()));
                        final long ctp = ongoingEvent.getCtpPerSec();
                        final long ctp = ongoingEvent.getCtpPerSec();
                        if (ctp != 0) {
                        if (ctp != 0) {
                            pw.print(" ctp/sec=");
                            pw.print(" ctp/sec=");
                            pw.print(narcToString(ongoingEvent.getCtpPerSec()));
                            pw.print(cakeToString(ongoingEvent.getCtpPerSec()));
                        }
                        }
                        pw.print(" refCount=");
                        pw.print(" refCount=");
                        pw.print(ongoingEvent.refCount);
                        pw.print(ongoingEvent.refCount);
+45 −45
Original line number Original line Diff line number Diff line
@@ -97,8 +97,8 @@ import static com.android.server.tare.Modifier.COST_MODIFIER_CHARGING;
import static com.android.server.tare.Modifier.COST_MODIFIER_DEVICE_IDLE;
import static com.android.server.tare.Modifier.COST_MODIFIER_DEVICE_IDLE;
import static com.android.server.tare.Modifier.COST_MODIFIER_POWER_SAVE_MODE;
import static com.android.server.tare.Modifier.COST_MODIFIER_POWER_SAVE_MODE;
import static com.android.server.tare.Modifier.COST_MODIFIER_PROCESS_STATE;
import static com.android.server.tare.Modifier.COST_MODIFIER_PROCESS_STATE;
import static com.android.server.tare.TareUtils.arcToNarc;
import static com.android.server.tare.TareUtils.arcToCake;
import static com.android.server.tare.TareUtils.narcToString;
import static com.android.server.tare.TareUtils.cakeToString;


import android.annotation.NonNull;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.Nullable;
@@ -219,143 +219,143 @@ public class AlarmManagerEconomicPolicy extends EconomicPolicy {
            Slog.e(TAG, "Global setting key incorrect: ", e);
            Slog.e(TAG, "Global setting key incorrect: ", e);
        }
        }


        mMinSatiatedBalanceExempted = arcToNarc(mParser.getInt(KEY_AM_MIN_SATIATED_BALANCE_EXEMPTED,
        mMinSatiatedBalanceExempted = arcToCake(mParser.getInt(KEY_AM_MIN_SATIATED_BALANCE_EXEMPTED,
                DEFAULT_AM_MIN_SATIATED_BALANCE_EXEMPTED));
                DEFAULT_AM_MIN_SATIATED_BALANCE_EXEMPTED));
        mMinSatiatedBalanceOther = arcToNarc(mParser.getInt(KEY_AM_MIN_SATIATED_BALANCE_OTHER_APP,
        mMinSatiatedBalanceOther = arcToCake(mParser.getInt(KEY_AM_MIN_SATIATED_BALANCE_OTHER_APP,
                DEFAULT_AM_MIN_SATIATED_BALANCE_OTHER_APP));
                DEFAULT_AM_MIN_SATIATED_BALANCE_OTHER_APP));
        mMaxSatiatedBalance = arcToNarc(mParser.getInt(KEY_AM_MAX_SATIATED_BALANCE,
        mMaxSatiatedBalance = arcToCake(mParser.getInt(KEY_AM_MAX_SATIATED_BALANCE,
                DEFAULT_AM_MAX_SATIATED_BALANCE));
                DEFAULT_AM_MAX_SATIATED_BALANCE));
        mInitialSatiatedConsumptionLimit = arcToNarc(mParser.getInt(
        mInitialSatiatedConsumptionLimit = arcToCake(mParser.getInt(
                KEY_AM_INITIAL_CONSUMPTION_LIMIT, DEFAULT_AM_INITIAL_CONSUMPTION_LIMIT));
                KEY_AM_INITIAL_CONSUMPTION_LIMIT, DEFAULT_AM_INITIAL_CONSUMPTION_LIMIT));
        mHardSatiatedConsumptionLimit = Math.max(mInitialSatiatedConsumptionLimit,
        mHardSatiatedConsumptionLimit = Math.max(mInitialSatiatedConsumptionLimit,
                arcToNarc(mParser.getInt(
                arcToCake(mParser.getInt(
                        KEY_AM_HARD_CONSUMPTION_LIMIT, DEFAULT_AM_HARD_CONSUMPTION_LIMIT)));
                        KEY_AM_HARD_CONSUMPTION_LIMIT, DEFAULT_AM_HARD_CONSUMPTION_LIMIT)));


        final long exactAllowWhileIdleWakeupBasePrice = arcToNarc(
        final long exactAllowWhileIdleWakeupBasePrice = arcToCake(
                mParser.getInt(KEY_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_EXACT_WAKEUP_BASE_PRICE,
                mParser.getInt(KEY_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_EXACT_WAKEUP_BASE_PRICE,
                        DEFAULT_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_EXACT_WAKEUP_BASE_PRICE));
                        DEFAULT_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_EXACT_WAKEUP_BASE_PRICE));


        mActions.put(ACTION_ALARM_WAKEUP_EXACT_ALLOW_WHILE_IDLE,
        mActions.put(ACTION_ALARM_WAKEUP_EXACT_ALLOW_WHILE_IDLE,
                new Action(ACTION_ALARM_WAKEUP_EXACT_ALLOW_WHILE_IDLE,
                new Action(ACTION_ALARM_WAKEUP_EXACT_ALLOW_WHILE_IDLE,
                        arcToNarc(mParser.getInt(
                        arcToCake(mParser.getInt(
                                KEY_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_EXACT_WAKEUP_CTP,
                                KEY_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_EXACT_WAKEUP_CTP,
                                DEFAULT_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_EXACT_WAKEUP_CTP)),
                                DEFAULT_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_EXACT_WAKEUP_CTP)),
                        exactAllowWhileIdleWakeupBasePrice));
                        exactAllowWhileIdleWakeupBasePrice));
        mActions.put(ACTION_ALARM_WAKEUP_EXACT,
        mActions.put(ACTION_ALARM_WAKEUP_EXACT,
                new Action(ACTION_ALARM_WAKEUP_EXACT,
                new Action(ACTION_ALARM_WAKEUP_EXACT,
                        arcToNarc(mParser.getInt(KEY_AM_ACTION_ALARM_EXACT_WAKEUP_CTP,
                        arcToCake(mParser.getInt(KEY_AM_ACTION_ALARM_EXACT_WAKEUP_CTP,
                                DEFAULT_AM_ACTION_ALARM_EXACT_WAKEUP_CTP)),
                                DEFAULT_AM_ACTION_ALARM_EXACT_WAKEUP_CTP)),
                        arcToNarc(mParser.getInt(KEY_AM_ACTION_ALARM_EXACT_WAKEUP_BASE_PRICE,
                        arcToCake(mParser.getInt(KEY_AM_ACTION_ALARM_EXACT_WAKEUP_BASE_PRICE,
                                DEFAULT_AM_ACTION_ALARM_EXACT_WAKEUP_BASE_PRICE))));
                                DEFAULT_AM_ACTION_ALARM_EXACT_WAKEUP_BASE_PRICE))));


        final long inexactAllowWhileIdleWakeupBasePrice =
        final long inexactAllowWhileIdleWakeupBasePrice =
                arcToNarc(mParser.getInt(
                arcToCake(mParser.getInt(
                        KEY_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_INEXACT_WAKEUP_BASE_PRICE,
                        KEY_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_INEXACT_WAKEUP_BASE_PRICE,
                        DEFAULT_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_INEXACT_WAKEUP_BASE_PRICE));
                        DEFAULT_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_INEXACT_WAKEUP_BASE_PRICE));


        mActions.put(ACTION_ALARM_WAKEUP_INEXACT_ALLOW_WHILE_IDLE,
        mActions.put(ACTION_ALARM_WAKEUP_INEXACT_ALLOW_WHILE_IDLE,
                new Action(ACTION_ALARM_WAKEUP_INEXACT_ALLOW_WHILE_IDLE,
                new Action(ACTION_ALARM_WAKEUP_INEXACT_ALLOW_WHILE_IDLE,
                        arcToNarc(mParser.getInt(
                        arcToCake(mParser.getInt(
                                KEY_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_INEXACT_WAKEUP_CTP,
                                KEY_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_INEXACT_WAKEUP_CTP,
                                DEFAULT_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_INEXACT_WAKEUP_CTP)),
                                DEFAULT_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_INEXACT_WAKEUP_CTP)),
                        inexactAllowWhileIdleWakeupBasePrice));
                        inexactAllowWhileIdleWakeupBasePrice));
        mActions.put(ACTION_ALARM_WAKEUP_INEXACT,
        mActions.put(ACTION_ALARM_WAKEUP_INEXACT,
                new Action(ACTION_ALARM_WAKEUP_INEXACT,
                new Action(ACTION_ALARM_WAKEUP_INEXACT,
                        arcToNarc(mParser.getInt(
                        arcToCake(mParser.getInt(
                                KEY_AM_ACTION_ALARM_INEXACT_WAKEUP_CTP,
                                KEY_AM_ACTION_ALARM_INEXACT_WAKEUP_CTP,
                                DEFAULT_AM_ACTION_ALARM_INEXACT_WAKEUP_CTP)),
                                DEFAULT_AM_ACTION_ALARM_INEXACT_WAKEUP_CTP)),
                        arcToNarc(mParser.getInt(
                        arcToCake(mParser.getInt(
                                KEY_AM_ACTION_ALARM_INEXACT_WAKEUP_BASE_PRICE,
                                KEY_AM_ACTION_ALARM_INEXACT_WAKEUP_BASE_PRICE,
                                DEFAULT_AM_ACTION_ALARM_INEXACT_WAKEUP_BASE_PRICE))));
                                DEFAULT_AM_ACTION_ALARM_INEXACT_WAKEUP_BASE_PRICE))));


        final long exactAllowWhileIdleNonWakeupBasePrice =
        final long exactAllowWhileIdleNonWakeupBasePrice =
                arcToNarc(mParser.getInt(
                arcToCake(mParser.getInt(
                        KEY_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_EXACT_NONWAKEUP_BASE_PRICE,
                        KEY_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_EXACT_NONWAKEUP_BASE_PRICE,
                        DEFAULT_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_INEXACT_NONWAKEUP_BASE_PRICE));
                        DEFAULT_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_INEXACT_NONWAKEUP_BASE_PRICE));


        mActions.put(ACTION_ALARM_NONWAKEUP_EXACT_ALLOW_WHILE_IDLE,
        mActions.put(ACTION_ALARM_NONWAKEUP_EXACT_ALLOW_WHILE_IDLE,
                new Action(ACTION_ALARM_NONWAKEUP_EXACT_ALLOW_WHILE_IDLE,
                new Action(ACTION_ALARM_NONWAKEUP_EXACT_ALLOW_WHILE_IDLE,
                        arcToNarc(mParser.getInt(
                        arcToCake(mParser.getInt(
                                KEY_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_EXACT_NONWAKEUP_CTP,
                                KEY_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_EXACT_NONWAKEUP_CTP,
                                DEFAULT_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_EXACT_NONWAKEUP_CTP)),
                                DEFAULT_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_EXACT_NONWAKEUP_CTP)),
                        exactAllowWhileIdleNonWakeupBasePrice));
                        exactAllowWhileIdleNonWakeupBasePrice));
        mActions.put(ACTION_ALARM_NONWAKEUP_EXACT,
        mActions.put(ACTION_ALARM_NONWAKEUP_EXACT,
                new Action(ACTION_ALARM_NONWAKEUP_EXACT,
                new Action(ACTION_ALARM_NONWAKEUP_EXACT,
                        arcToNarc(mParser.getInt(
                        arcToCake(mParser.getInt(
                                KEY_AM_ACTION_ALARM_EXACT_NONWAKEUP_CTP,
                                KEY_AM_ACTION_ALARM_EXACT_NONWAKEUP_CTP,
                                DEFAULT_AM_ACTION_ALARM_EXACT_NONWAKEUP_CTP)),
                                DEFAULT_AM_ACTION_ALARM_EXACT_NONWAKEUP_CTP)),
                        arcToNarc(mParser.getInt(
                        arcToCake(mParser.getInt(
                                KEY_AM_ACTION_ALARM_EXACT_NONWAKEUP_BASE_PRICE,
                                KEY_AM_ACTION_ALARM_EXACT_NONWAKEUP_BASE_PRICE,
                                DEFAULT_AM_ACTION_ALARM_EXACT_NONWAKEUP_BASE_PRICE))));
                                DEFAULT_AM_ACTION_ALARM_EXACT_NONWAKEUP_BASE_PRICE))));


        final long inexactAllowWhileIdleNonWakeupBasePrice =
        final long inexactAllowWhileIdleNonWakeupBasePrice =
                arcToNarc(mParser.getInt(
                arcToCake(mParser.getInt(
                        KEY_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_INEXACT_NONWAKEUP_BASE_PRICE,
                        KEY_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_INEXACT_NONWAKEUP_BASE_PRICE,
                        DEFAULT_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_INEXACT_NONWAKEUP_BASE_PRICE));
                        DEFAULT_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_INEXACT_NONWAKEUP_BASE_PRICE));


        mActions.put(ACTION_ALARM_NONWAKEUP_INEXACT_ALLOW_WHILE_IDLE,
        mActions.put(ACTION_ALARM_NONWAKEUP_INEXACT_ALLOW_WHILE_IDLE,
                new Action(ACTION_ALARM_NONWAKEUP_INEXACT_ALLOW_WHILE_IDLE,
                new Action(ACTION_ALARM_NONWAKEUP_INEXACT_ALLOW_WHILE_IDLE,
                        arcToNarc(mParser.getInt(
                        arcToCake(mParser.getInt(
                                KEY_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_INEXACT_NONWAKEUP_CTP,
                                KEY_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_INEXACT_NONWAKEUP_CTP,
                                DEFAULT_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_INEXACT_NONWAKEUP_CTP)),
                                DEFAULT_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_INEXACT_NONWAKEUP_CTP)),
                        inexactAllowWhileIdleNonWakeupBasePrice));
                        inexactAllowWhileIdleNonWakeupBasePrice));
        mActions.put(ACTION_ALARM_NONWAKEUP_INEXACT,
        mActions.put(ACTION_ALARM_NONWAKEUP_INEXACT,
                new Action(ACTION_ALARM_NONWAKEUP_INEXACT,
                new Action(ACTION_ALARM_NONWAKEUP_INEXACT,
                        arcToNarc(mParser.getInt(
                        arcToCake(mParser.getInt(
                                KEY_AM_ACTION_ALARM_INEXACT_NONWAKEUP_CTP,
                                KEY_AM_ACTION_ALARM_INEXACT_NONWAKEUP_CTP,
                                DEFAULT_AM_ACTION_ALARM_INEXACT_NONWAKEUP_CTP)),
                                DEFAULT_AM_ACTION_ALARM_INEXACT_NONWAKEUP_CTP)),
                        arcToNarc(mParser.getInt(
                        arcToCake(mParser.getInt(
                                KEY_AM_ACTION_ALARM_INEXACT_NONWAKEUP_BASE_PRICE,
                                KEY_AM_ACTION_ALARM_INEXACT_NONWAKEUP_BASE_PRICE,
                                DEFAULT_AM_ACTION_ALARM_INEXACT_NONWAKEUP_BASE_PRICE))));
                                DEFAULT_AM_ACTION_ALARM_INEXACT_NONWAKEUP_BASE_PRICE))));
        mActions.put(ACTION_ALARM_CLOCK,
        mActions.put(ACTION_ALARM_CLOCK,
                new Action(ACTION_ALARM_CLOCK,
                new Action(ACTION_ALARM_CLOCK,
                        arcToNarc(mParser.getInt(
                        arcToCake(mParser.getInt(
                                KEY_AM_ACTION_ALARM_ALARMCLOCK_CTP,
                                KEY_AM_ACTION_ALARM_ALARMCLOCK_CTP,
                                DEFAULT_AM_ACTION_ALARM_ALARMCLOCK_CTP)),
                                DEFAULT_AM_ACTION_ALARM_ALARMCLOCK_CTP)),
                        arcToNarc(mParser.getInt(
                        arcToCake(mParser.getInt(
                                KEY_AM_ACTION_ALARM_ALARMCLOCK_BASE_PRICE,
                                KEY_AM_ACTION_ALARM_ALARMCLOCK_BASE_PRICE,
                                DEFAULT_AM_ACTION_ALARM_ALARMCLOCK_BASE_PRICE))));
                                DEFAULT_AM_ACTION_ALARM_ALARMCLOCK_BASE_PRICE))));


        mRewards.put(REWARD_TOP_ACTIVITY, new Reward(REWARD_TOP_ACTIVITY,
        mRewards.put(REWARD_TOP_ACTIVITY, new Reward(REWARD_TOP_ACTIVITY,
                arcToNarc(mParser.getInt(KEY_AM_REWARD_TOP_ACTIVITY_INSTANT,
                arcToCake(mParser.getInt(KEY_AM_REWARD_TOP_ACTIVITY_INSTANT,
                        DEFAULT_AM_REWARD_TOP_ACTIVITY_INSTANT)),
                        DEFAULT_AM_REWARD_TOP_ACTIVITY_INSTANT)),
                (long) (arcToNarc(1) * mParser.getFloat(KEY_AM_REWARD_TOP_ACTIVITY_ONGOING,
                (long) (arcToCake(1) * mParser.getFloat(KEY_AM_REWARD_TOP_ACTIVITY_ONGOING,
                        DEFAULT_AM_REWARD_TOP_ACTIVITY_ONGOING)),
                        DEFAULT_AM_REWARD_TOP_ACTIVITY_ONGOING)),
                arcToNarc(mParser.getInt(KEY_AM_REWARD_TOP_ACTIVITY_MAX,
                arcToCake(mParser.getInt(KEY_AM_REWARD_TOP_ACTIVITY_MAX,
                        DEFAULT_AM_REWARD_TOP_ACTIVITY_MAX))));
                        DEFAULT_AM_REWARD_TOP_ACTIVITY_MAX))));
        mRewards.put(REWARD_NOTIFICATION_SEEN, new Reward(REWARD_NOTIFICATION_SEEN,
        mRewards.put(REWARD_NOTIFICATION_SEEN, new Reward(REWARD_NOTIFICATION_SEEN,
                arcToNarc(mParser.getInt(KEY_AM_REWARD_NOTIFICATION_SEEN_INSTANT,
                arcToCake(mParser.getInt(KEY_AM_REWARD_NOTIFICATION_SEEN_INSTANT,
                        DEFAULT_AM_REWARD_NOTIFICATION_SEEN_INSTANT)),
                        DEFAULT_AM_REWARD_NOTIFICATION_SEEN_INSTANT)),
                arcToNarc(mParser.getInt(KEY_AM_REWARD_NOTIFICATION_SEEN_ONGOING,
                arcToCake(mParser.getInt(KEY_AM_REWARD_NOTIFICATION_SEEN_ONGOING,
                        DEFAULT_AM_REWARD_NOTIFICATION_SEEN_ONGOING)),
                        DEFAULT_AM_REWARD_NOTIFICATION_SEEN_ONGOING)),
                arcToNarc(mParser.getInt(KEY_AM_REWARD_NOTIFICATION_SEEN_MAX,
                arcToCake(mParser.getInt(KEY_AM_REWARD_NOTIFICATION_SEEN_MAX,
                        DEFAULT_AM_REWARD_NOTIFICATION_SEEN_MAX))));
                        DEFAULT_AM_REWARD_NOTIFICATION_SEEN_MAX))));
        mRewards.put(REWARD_NOTIFICATION_INTERACTION,
        mRewards.put(REWARD_NOTIFICATION_INTERACTION,
                new Reward(REWARD_NOTIFICATION_INTERACTION,
                new Reward(REWARD_NOTIFICATION_INTERACTION,
                        arcToNarc(mParser.getInt(
                        arcToCake(mParser.getInt(
                                KEY_AM_REWARD_NOTIFICATION_INTERACTION_INSTANT,
                                KEY_AM_REWARD_NOTIFICATION_INTERACTION_INSTANT,
                                DEFAULT_AM_REWARD_NOTIFICATION_INTERACTION_INSTANT)),
                                DEFAULT_AM_REWARD_NOTIFICATION_INTERACTION_INSTANT)),
                        arcToNarc(mParser.getInt(
                        arcToCake(mParser.getInt(
                                KEY_AM_REWARD_NOTIFICATION_INTERACTION_ONGOING,
                                KEY_AM_REWARD_NOTIFICATION_INTERACTION_ONGOING,
                                DEFAULT_AM_REWARD_NOTIFICATION_INTERACTION_ONGOING)),
                                DEFAULT_AM_REWARD_NOTIFICATION_INTERACTION_ONGOING)),
                        arcToNarc(mParser.getInt(
                        arcToCake(mParser.getInt(
                                KEY_AM_REWARD_NOTIFICATION_INTERACTION_MAX,
                                KEY_AM_REWARD_NOTIFICATION_INTERACTION_MAX,
                                DEFAULT_AM_REWARD_NOTIFICATION_INTERACTION_MAX))));
                                DEFAULT_AM_REWARD_NOTIFICATION_INTERACTION_MAX))));
        mRewards.put(REWARD_WIDGET_INTERACTION, new Reward(REWARD_WIDGET_INTERACTION,
        mRewards.put(REWARD_WIDGET_INTERACTION, new Reward(REWARD_WIDGET_INTERACTION,
                arcToNarc(mParser.getInt(KEY_AM_REWARD_WIDGET_INTERACTION_INSTANT,
                arcToCake(mParser.getInt(KEY_AM_REWARD_WIDGET_INTERACTION_INSTANT,
                        DEFAULT_AM_REWARD_WIDGET_INTERACTION_INSTANT)),
                        DEFAULT_AM_REWARD_WIDGET_INTERACTION_INSTANT)),
                arcToNarc(mParser.getInt(KEY_AM_REWARD_WIDGET_INTERACTION_ONGOING,
                arcToCake(mParser.getInt(KEY_AM_REWARD_WIDGET_INTERACTION_ONGOING,
                        DEFAULT_AM_REWARD_WIDGET_INTERACTION_ONGOING)),
                        DEFAULT_AM_REWARD_WIDGET_INTERACTION_ONGOING)),
                arcToNarc(mParser.getInt(KEY_AM_REWARD_WIDGET_INTERACTION_MAX,
                arcToCake(mParser.getInt(KEY_AM_REWARD_WIDGET_INTERACTION_MAX,
                        DEFAULT_AM_REWARD_WIDGET_INTERACTION_MAX))));
                        DEFAULT_AM_REWARD_WIDGET_INTERACTION_MAX))));
        mRewards.put(REWARD_OTHER_USER_INTERACTION,
        mRewards.put(REWARD_OTHER_USER_INTERACTION,
                new Reward(REWARD_OTHER_USER_INTERACTION,
                new Reward(REWARD_OTHER_USER_INTERACTION,
                        arcToNarc(mParser.getInt(KEY_AM_REWARD_OTHER_USER_INTERACTION_INSTANT,
                        arcToCake(mParser.getInt(KEY_AM_REWARD_OTHER_USER_INTERACTION_INSTANT,
                                DEFAULT_AM_REWARD_OTHER_USER_INTERACTION_INSTANT)),
                                DEFAULT_AM_REWARD_OTHER_USER_INTERACTION_INSTANT)),
                        arcToNarc(mParser.getInt(
                        arcToCake(mParser.getInt(
                                KEY_AM_REWARD_OTHER_USER_INTERACTION_ONGOING,
                                KEY_AM_REWARD_OTHER_USER_INTERACTION_ONGOING,
                                DEFAULT_AM_REWARD_OTHER_USER_INTERACTION_ONGOING)),
                                DEFAULT_AM_REWARD_OTHER_USER_INTERACTION_ONGOING)),
                        arcToNarc(mParser.getInt(
                        arcToCake(mParser.getInt(
                                KEY_AM_REWARD_OTHER_USER_INTERACTION_MAX,
                                KEY_AM_REWARD_OTHER_USER_INTERACTION_MAX,
                                DEFAULT_AM_REWARD_OTHER_USER_INTERACTION_MAX))));
                                DEFAULT_AM_REWARD_OTHER_USER_INTERACTION_MAX))));
    }
    }
@@ -364,14 +364,14 @@ public class AlarmManagerEconomicPolicy extends EconomicPolicy {
    void dump(IndentingPrintWriter pw) {
    void dump(IndentingPrintWriter pw) {
        pw.println("Min satiated balances:");
        pw.println("Min satiated balances:");
        pw.increaseIndent();
        pw.increaseIndent();
        pw.print("Exempted", narcToString(mMinSatiatedBalanceExempted)).println();
        pw.print("Exempted", cakeToString(mMinSatiatedBalanceExempted)).println();
        pw.print("Other", narcToString(mMinSatiatedBalanceOther)).println();
        pw.print("Other", cakeToString(mMinSatiatedBalanceOther)).println();
        pw.decreaseIndent();
        pw.decreaseIndent();
        pw.print("Max satiated balance", narcToString(mMaxSatiatedBalance)).println();
        pw.print("Max satiated balance", cakeToString(mMaxSatiatedBalance)).println();
        pw.print("Consumption limits: [");
        pw.print("Consumption limits: [");
        pw.print(narcToString(mInitialSatiatedConsumptionLimit));
        pw.print(cakeToString(mInitialSatiatedConsumptionLimit));
        pw.print(", ");
        pw.print(", ");
        pw.print(narcToString(mHardSatiatedConsumptionLimit));
        pw.print(cakeToString(mHardSatiatedConsumptionLimit));
        pw.println("]");
        pw.println("]");


        pw.println();
        pw.println();
+8 −8
Original line number Original line Diff line number Diff line
@@ -21,7 +21,7 @@ import static com.android.server.tare.Modifier.COST_MODIFIER_DEVICE_IDLE;
import static com.android.server.tare.Modifier.COST_MODIFIER_POWER_SAVE_MODE;
import static com.android.server.tare.Modifier.COST_MODIFIER_POWER_SAVE_MODE;
import static com.android.server.tare.Modifier.COST_MODIFIER_PROCESS_STATE;
import static com.android.server.tare.Modifier.COST_MODIFIER_PROCESS_STATE;
import static com.android.server.tare.Modifier.NUM_COST_MODIFIERS;
import static com.android.server.tare.Modifier.NUM_COST_MODIFIERS;
import static com.android.server.tare.TareUtils.narcToString;
import static com.android.server.tare.TareUtils.cakeToString;


import android.annotation.CallSuper;
import android.annotation.CallSuper;
import android.annotation.IntDef;
import android.annotation.IntDef;
@@ -203,7 +203,7 @@ public abstract class EconomicPolicy {
    abstract long getMaxSatiatedBalance();
    abstract long getMaxSatiatedBalance();


    /**
    /**
     * Returns the maximum number of narcs that should be consumed during a full 100% discharge
     * Returns the maximum number of cakes that should be consumed during a full 100% discharge
     * cycle. This is the initial limit. The system may choose to increase the limit over time,
     * cycle. This is the initial limit. The system may choose to increase the limit over time,
     * but the increased limit should never exceed the value returned from
     * but the increased limit should never exceed the value returned from
     * {@link #getHardSatiatedConsumptionLimit()}.
     * {@link #getHardSatiatedConsumptionLimit()}.
@@ -211,7 +211,7 @@ public abstract class EconomicPolicy {
    abstract long getInitialSatiatedConsumptionLimit();
    abstract long getInitialSatiatedConsumptionLimit();


    /**
    /**
     * Returns the maximum number of narcs that should be consumed during a full 100% discharge
     * Returns the maximum number of cakes that should be consumed during a full 100% discharge
     * cycle. This is the hard limit that should never be exceeded.
     * cycle. This is the hard limit that should never be exceeded.
     */
     */
    abstract long getHardSatiatedConsumptionLimit();
    abstract long getHardSatiatedConsumptionLimit();
@@ -430,9 +430,9 @@ public abstract class EconomicPolicy {
        pw.print(actionToString(action.id));
        pw.print(actionToString(action.id));
        pw.print(": ");
        pw.print(": ");
        pw.print("ctp=");
        pw.print("ctp=");
        pw.print(narcToString(action.costToProduce));
        pw.print(cakeToString(action.costToProduce));
        pw.print(", basePrice=");
        pw.print(", basePrice=");
        pw.print(narcToString(action.basePrice));
        pw.print(cakeToString(action.basePrice));
        pw.println();
        pw.println();
    }
    }


@@ -440,11 +440,11 @@ public abstract class EconomicPolicy {
        pw.print(rewardToString(reward.id));
        pw.print(rewardToString(reward.id));
        pw.print(": ");
        pw.print(": ");
        pw.print("instant=");
        pw.print("instant=");
        pw.print(narcToString(reward.instantReward));
        pw.print(cakeToString(reward.instantReward));
        pw.print(", ongoing/sec=");
        pw.print(", ongoing/sec=");
        pw.print(narcToString(reward.ongoingRewardPerSecond));
        pw.print(cakeToString(reward.ongoingRewardPerSecond));
        pw.print(", maxDaily=");
        pw.print(", maxDaily=");
        pw.print(narcToString(reward.maxDailyReward));
        pw.print(cakeToString(reward.maxDailyReward));
        pw.println();
        pw.println();
    }
    }
}
}
+19 −19
Original line number Original line Diff line number Diff line
@@ -23,8 +23,8 @@ import static android.text.format.DateUtils.HOUR_IN_MILLIS;
import static android.text.format.DateUtils.MINUTE_IN_MILLIS;
import static android.text.format.DateUtils.MINUTE_IN_MILLIS;


import static com.android.server.tare.TareUtils.appToString;
import static com.android.server.tare.TareUtils.appToString;
import static com.android.server.tare.TareUtils.cakeToString;
import static com.android.server.tare.TareUtils.getCurrentTimeMillis;
import static com.android.server.tare.TareUtils.getCurrentTimeMillis;
import static com.android.server.tare.TareUtils.narcToString;


import android.annotation.NonNull;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.Nullable;
@@ -528,9 +528,9 @@ public class InternalResourceService extends SystemService {
    void maybePerformQuantitativeEasingLocked() {
    void maybePerformQuantitativeEasingLocked() {
        // We don't need to increase the limit if the device runs out of consumable credits
        // We don't need to increase the limit if the device runs out of consumable credits
        // when the battery is low.
        // when the battery is low.
        final long remainingConsumableNarcs = mScribe.getRemainingConsumableNarcsLocked();
        final long remainingConsumableCakes = mScribe.getRemainingConsumableCakesLocked();
        if (mCurrentBatteryLevel <= QUANTITATIVE_EASING_BATTERY_THRESHOLD
        if (mCurrentBatteryLevel <= QUANTITATIVE_EASING_BATTERY_THRESHOLD
                || remainingConsumableNarcs > 0) {
                || remainingConsumableCakes > 0) {
            return;
            return;
        }
        }
        final long currentConsumptionLimit = mScribe.getSatiatedConsumptionLimitLocked();
        final long currentConsumptionLimit = mScribe.getSatiatedConsumptionLimitLocked();
@@ -539,8 +539,8 @@ public class InternalResourceService extends SystemService {
        final long newConsumptionLimit = Math.min(currentConsumptionLimit + shortfall,
        final long newConsumptionLimit = Math.min(currentConsumptionLimit + shortfall,
                mCompleteEconomicPolicy.getHardSatiatedConsumptionLimit());
                mCompleteEconomicPolicy.getHardSatiatedConsumptionLimit());
        if (newConsumptionLimit != currentConsumptionLimit) {
        if (newConsumptionLimit != currentConsumptionLimit) {
            Slog.i(TAG, "Increasing consumption limit from " + narcToString(currentConsumptionLimit)
            Slog.i(TAG, "Increasing consumption limit from " + cakeToString(currentConsumptionLimit)
                    + " to " + narcToString(newConsumptionLimit));
                    + " to " + cakeToString(newConsumptionLimit));
            mScribe.setConsumptionLimitLocked(newConsumptionLimit);
            mScribe.setConsumptionLimitLocked(newConsumptionLimit);
            adjustCreditSupplyLocked(/* allowIncrease */ true);
            adjustCreditSupplyLocked(/* allowIncrease */ true);
        }
        }
@@ -562,16 +562,16 @@ public class InternalResourceService extends SystemService {
    @GuardedBy("mLock")
    @GuardedBy("mLock")
    private void adjustCreditSupplyLocked(boolean allowIncrease) {
    private void adjustCreditSupplyLocked(boolean allowIncrease) {
        final long newLimit = getConsumptionLimitLocked();
        final long newLimit = getConsumptionLimitLocked();
        final long remainingConsumableNarcs = mScribe.getRemainingConsumableNarcsLocked();
        final long remainingConsumableCakes = mScribe.getRemainingConsumableCakesLocked();
        if (remainingConsumableNarcs == newLimit) {
        if (remainingConsumableCakes == newLimit) {
            return;
            return;
        }
        }
        if (remainingConsumableNarcs > newLimit) {
        if (remainingConsumableCakes > newLimit) {
            mScribe.adjustRemainingConsumableNarcsLocked(newLimit - remainingConsumableNarcs);
            mScribe.adjustRemainingConsumableCakesLocked(newLimit - remainingConsumableCakes);
        } else if (allowIncrease) {
        } else if (allowIncrease) {
            final double perc = mCurrentBatteryLevel / 100d;
            final double perc = mCurrentBatteryLevel / 100d;
            final long shortfall = newLimit - remainingConsumableNarcs;
            final long shortfall = newLimit - remainingConsumableCakes;
            mScribe.adjustRemainingConsumableNarcsLocked((long) (perc * shortfall));
            mScribe.adjustRemainingConsumableCakesLocked((long) (perc * shortfall));
        }
        }
        mAgent.onCreditSupplyChanged();
        mAgent.onCreditSupplyChanged();
    }
    }
@@ -919,7 +919,7 @@ public class InternalResourceService extends SystemService {
                            + cost.price * (action.ongoingDurationMs / 1000);
                            + cost.price * (action.ongoingDurationMs / 1000);
                }
                }
                return mAgent.getBalanceLocked(userId, pkgName) >= requiredBalance
                return mAgent.getBalanceLocked(userId, pkgName) >= requiredBalance
                        && mScribe.getRemainingConsumableNarcsLocked() >= requiredBalance;
                        && mScribe.getRemainingConsumableCakesLocked() >= requiredBalance;
            }
            }
        }
        }


@@ -947,7 +947,7 @@ public class InternalResourceService extends SystemService {
                }
                }
                final long minBalance = Math.min(
                final long minBalance = Math.min(
                        mAgent.getBalanceLocked(userId, pkgName),
                        mAgent.getBalanceLocked(userId, pkgName),
                        mScribe.getRemainingConsumableNarcsLocked());
                        mScribe.getRemainingConsumableCakesLocked());
                return minBalance * 1000 / totalCostPerSecond;
                return minBalance * 1000 / totalCostPerSecond;
            }
            }
        }
        }
@@ -1103,21 +1103,21 @@ public class InternalResourceService extends SystemService {


            final long consumptionLimit = getConsumptionLimitLocked();
            final long consumptionLimit = getConsumptionLimitLocked();
            pw.print("Consumption limit (current/initial-satiated/current-satiated): ");
            pw.print("Consumption limit (current/initial-satiated/current-satiated): ");
            pw.print(narcToString(consumptionLimit));
            pw.print(cakeToString(consumptionLimit));
            pw.print("/");
            pw.print("/");
            pw.print(narcToString(mCompleteEconomicPolicy.getInitialSatiatedConsumptionLimit()));
            pw.print(cakeToString(mCompleteEconomicPolicy.getInitialSatiatedConsumptionLimit()));
            pw.print("/");
            pw.print("/");
            pw.println(narcToString(mScribe.getSatiatedConsumptionLimitLocked()));
            pw.println(cakeToString(mScribe.getSatiatedConsumptionLimitLocked()));


            final long remainingConsumable = mScribe.getRemainingConsumableNarcsLocked();
            final long remainingConsumable = mScribe.getRemainingConsumableCakesLocked();
            pw.print("Goods remaining: ");
            pw.print("Goods remaining: ");
            pw.print(narcToString(remainingConsumable));
            pw.print(cakeToString(remainingConsumable));
            pw.print(" (");
            pw.print(" (");
            pw.print(String.format("%.2f", 100f * remainingConsumable / consumptionLimit));
            pw.print(String.format("%.2f", 100f * remainingConsumable / consumptionLimit));
            pw.println("% of current limit)");
            pw.println("% of current limit)");


            pw.print("Device wealth: ");
            pw.print("Device wealth: ");
            pw.println(narcToString(mScribe.getNarcsInCirculationForLoggingLocked()));
            pw.println(cakeToString(mScribe.getCakesInCirculationForLoggingLocked()));


            pw.println();
            pw.println();
            pw.print("Exempted apps", mExemptedApps);
            pw.print("Exempted apps", mExemptedApps);
+49 −49

File changed.

Preview size limit exceeded, changes collapsed.

Loading