| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package com.android.server.tare; |
| 18 |
|
| 19 |
import android.annotation.NonNull; |
| 20 |
import android.annotation.Nullable; |
| 21 |
|
| 22 |
import java.util.ArrayList; |
| 23 |
import java.util.Collections; |
| 24 |
import java.util.Comparator; |
| 25 |
import java.util.List; |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
public interface EconomyManagerInternal { |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
final class AnticipatedAction { |
| 37 |
public final int actionId; |
| 38 |
public final int numInstantaneousCalls; |
| 39 |
public final long ongoingDurationMs; |
| 40 |
private final int mHashCode; |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
public AnticipatedAction(@EconomicPolicy.AppAction int actionId, |
| 48 |
int numInstantaneousCalls, long ongoingDurationMs) { |
| 49 |
this.actionId = actionId; |
| 50 |
this.numInstantaneousCalls = numInstantaneousCalls; |
| 51 |
this.ongoingDurationMs = ongoingDurationMs; |
| 52 |
|
| 53 |
int hash = 0; |
| 54 |
hash = 31 * hash + actionId; |
| 55 |
hash = 31 * hash + numInstantaneousCalls; |
| 56 |
hash = 31 * hash + (int) (ongoingDurationMs ^ (ongoingDurationMs >>> 32)); |
| 57 |
mHashCode = hash; |
| 58 |
} |
| 59 |
|
| 60 |
@Override |
| 61 |
public boolean equals(Object o) { |
| 62 |
if (this == o) return true; |
| 63 |
if (o == null || getClass() != o.getClass()) return false; |
| 64 |
AnticipatedAction that = (AnticipatedAction) o; |
| 65 |
return actionId == that.actionId |
| 66 |
&& numInstantaneousCalls == that.numInstantaneousCalls |
| 67 |
&& ongoingDurationMs == that.ongoingDurationMs; |
| 68 |
} |
| 69 |
|
| 70 |
@Override |
| 71 |
public int hashCode() { |
| 72 |
return mHashCode; |
| 73 |
} |
| 74 |
} |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
final class ActionBill { |
| 80 |
private static final Comparator<AnticipatedAction> |
| 81 |
sAnticipatedActionComparator = Comparator.comparingInt(aa -> aa.actionId); |
| 82 |
|
| 83 |
private final List<AnticipatedAction> mAnticipatedActions; |
| 84 |
private final int mHashCode; |
| 85 |
|
| 86 |
public ActionBill(@NonNull List<AnticipatedAction> anticipatedActions) { |
| 87 |
List<AnticipatedAction> actions = new ArrayList<>(anticipatedActions); |
| 88 |
actions.sort(sAnticipatedActionComparator); |
| 89 |
mAnticipatedActions = Collections.unmodifiableList(actions); |
| 90 |
|
| 91 |
int hash = 0; |
| 92 |
for (int i = 0; i < mAnticipatedActions.size(); ++i) { |
| 93 |
hash = 31 * hash + mAnticipatedActions.get(i).hashCode(); |
| 94 |
} |
| 95 |
mHashCode = hash; |
| 96 |
} |
| 97 |
|
| 98 |
List<AnticipatedAction> getAnticipatedActions() { |
| 99 |
return mAnticipatedActions; |
| 100 |
} |
| 101 |
|
| 102 |
@Override |
| 103 |
public boolean equals(Object o) { |
| 104 |
if (this == o) return true; |
| 105 |
if (o == null || getClass() != o.getClass()) return false; |
| 106 |
ActionBill that = (ActionBill) o; |
| 107 |
return mAnticipatedActions.equals(that.mAnticipatedActions); |
| 108 |
} |
| 109 |
|
| 110 |
@Override |
| 111 |
public int hashCode() { |
| 112 |
return mHashCode; |
| 113 |
} |
| 114 |
} |
| 115 |
|
| 116 |
|
| 117 |
interface AffordabilityChangeListener { |
| 118 |
void onAffordabilityChanged(int userId, @NonNull String pkgName, @NonNull ActionBill bill, |
| 119 |
boolean canAfford); |
| 120 |
} |
| 121 |
|
| 122 |
|
| 123 |
interface TareStateChangeListener { |
| 124 |
void onTareEnabledStateChanged(boolean isTareEnabled); |
| 125 |
} |
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
boolean canPayFor(int userId, @NonNull String pkgName, @NonNull ActionBill bill); |
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
long getMaxDurationMs(int userId, @NonNull String pkgName, @NonNull ActionBill bill); |
| 137 |
|
| 138 |
|
| 139 |
boolean isEnabled(); |
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
void registerAffordabilityChangeListener(int userId, @NonNull String pkgName, |
| 146 |
@NonNull AffordabilityChangeListener listener, @NonNull ActionBill bill); |
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
void unregisterAffordabilityChangeListener(int userId, @NonNull String pkgName, |
| 153 |
@NonNull AffordabilityChangeListener listener, @NonNull ActionBill bill); |
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
void registerTareStateChangeListener(@NonNull TareStateChangeListener listener); |
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
void unregisterTareStateChangeListener(@NonNull TareStateChangeListener listener); |
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
void noteInstantaneousEvent(int userId, @NonNull String pkgName, int eventId, |
| 172 |
@Nullable String tag); |
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
void noteOngoingEventStarted(int userId, @NonNull String pkgName, int eventId, |
| 185 |
@Nullable String tag); |
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
void noteOngoingEventStopped(int userId, @NonNull String pkgName, int eventId, |
| 196 |
@Nullable String tag); |
| 197 |
} |