Debian Codegraph @

apex/jobscheduler/service/java/com/android/server/tare/README.md

raw symbols SCIP
1 # Overview
2
3 Welcome to The Android Resource Economy (TARE for short). If you're reading this, you may be
4 wondering what all of this code is for and what it means. TARE is an attempt to apply economic
5 principles to resource (principally battery) management. It acknowledges that battery is a limited
6 resource on mobile devices and that the system must allocate and apportion those resources
7 accordingly. Every action (running a job, firing an alarm, using the network, using the CPU, etc.)
8 has a cost. Once that action has been performed and that bit of battery has been drained, it's no
9 longer available for someone else (another app) to use until the user charges the device again.
10
11 The key tenets of TARE are:
12
13 1. Charge for actions --- when an app performs an action, reduce its access to resources in the
14 future. This should help remind everyone that everything they do has a cost.
15 1. Reward for good actions --- reward and encourage behavior that provides value to the user
16 1. Fine bad actions --- fine and discourage behavior that is bad for the user
17
18 In an ideal world, the system could be said to most efficiently allocate resources by maximizing its
19 profits — by maximizing the aggregate sum of the difference between an action's price (that
20 the app ends up paying) and the cost to produce by the system. This assumes that more important
21 actions have a higher price than less important actions and all actors have perfect information and
22 convey that information accurately. With these assumptions, maximizing profits implies that the
23 system runs the most important work first and proceeds in decreasing order of importance. Of course,
24 that also means the system will not run anything where an app would pay less for the action than the
25 system's cost to produce that action. Some of this breaks down when we throw TOP apps into the mix
26 — TOP apps pay 0 for all actions, even though the CTP may be greater than 0. This is to ensure
27 ideal user experience for the app the user is actively interacting with. Similar caveats exist for
28 system-critical processes (such as the OS itself) and apps running foreground services (since those
29 could be critical to user experience, as is the case for media and navigation apps). Excluding those
30 caveats/special situations, maximizing profits of actions performed by apps in the background should
31 be the target.
32
33 To achieve the goal laid out by TARE, we use Android Resource Credits (ARCs for short) as the
34 internal/representative currency of the system.
35
36 ## How do ARCs work?
37
38 ARCs are required to perform any action while in the background. Some actions may have a fixed cost.
39 Others may be more dynamic (some may even allow apps to bid higher ARCs for some actions to have
40 them prioritized). If the app doesn't have enough ARCs, the action can't be performed. Apps are
41 granted ARCs (below a certain threshold) as the device charges. Apps are also granted ARCs for
42 providing user value (eg. for doing things that engage the user).
43
44 ARCs will be used across the entire system as one unified concept. When an app performs an action,
45 it pulls from the same account, regardless of the action. This means that apps can choose to do more
46 of one action in lieu of being able to do as much of another. For example, an app can choose to use
47 all of its ARCs for jobs if it doesn't want to schedule any alarms.
48
49 ### Scaling
50
51 With the ARC system, we can limit the total number of ARCs in circulation, thus limiting how much
52 total work can be done, regardless of how many apps the user has installed.
53
54 ## EconomicPolicy
55
56 An EconomicPolicy defines the actions and rewards a specific subsystem makes use of. Each subsystem
57 will likely have a unique set of actions that apps can perform, and may choose to reward apps for
58 certain behaviors. Generally, the app should be rewarded with ARCs for behaviors that indicate that
59 the app provided value to the user. The current set of behaviors that apps may be rewarded for
60 include 1) a user seeing a notification, 2) a user interacting with a notification, 3) the user
61 opening the app and/or staying in the app for some period of time, 4) the user interacting with a
62 widget, and 5) the user explicitly interacting with the app in some other way. These behaviors may
63 change as we determine better ways of identifying providing value to the user and/or user desire for
64 the app to perform the actions it's requesting.
65
66 ### Consumption Limit
67
68 The consumption limit represents the maximum amount of resources available to be consumed. When the
69 battery is satiated (at 100%), then the amount of resources available to be consumed is equal to the
70 consumption limit. Each action has a cost to produce that action. When the action is performed,
71 those resources are consumed. Thus, when an action is performed, the action's CTP is deducted from
72 the remaining amount of resources available. In keeping with the tenet that resources are limited
73 and ARCs are a proxy for battery consumption, the amount of resources available to be consumed are
74 adjusted as the battery level changes. That is, the consumption limit is scaled based on the current
75 battery level, and if the amount currently available to be consumed is greater than the scaled
76 consumption limit, then the available resources are decreased to match the scaled limit.
77
78 ### Regulation
79
80 Regulations are unique events invoked by the ~~government~~ system in order to get the whole economy
81 moving smoothly.
82
83 # Previous Implementations
84
85 ## V0
86
87 The initial implementation/proposal combined the supply of resources with the allocation in a single
88 mechanism. It defined the maximum number of resources (ARCs) available at a time, and then divided
89 (allocated) that number among the installed apps, intending to have some left over that could be
90 allocated as part of the rewards. There were several problems with that mechanism:
91
92 1. Not all apps used their credits, which meant that allocating credits to those packages
93 effectively permanently reduced the number of usable/re-allocatable ARCs.
94 1. Having a global maximum circulation spread across multiple apps meant that as more apps were
95 installed, the allocation to each app decreased. Eventually (with enough apps installed), no app
96 would be given enough credits to perform any actions.
97
98 These problems effectively meant that misallocation was a big problem, demand wasn't well reflected,
99 and some apps may not have been able to perform work even though they otherwise should have been.
100
101 Tare Improvement Proposal #1 (TIP1) separated allocation (to apps) from supply (by the system) and
102 allowed apps to accrue credits as appropriate while still limiting the total number of credits
103 consumed.
104
105 # Potential Future Changes
106
107 These are some ideas for further changes. There's no guarantee that they'll be implemented.
108
109 * Include additional components and policies for them. TARE may benefit from adding policies for
110 components such as broadcast dispatching, network traffic, location requests, and sensor usage.
111 * Have a separate "account" for critical/special actions. In other words, have two accounts for each
112 app, where one acts like a special savings account and is only allowed to be used for special
113 actions such as expedited job execution. The second account would have a lower maximum than the
114 main account, but would help to make sure that normal actions don't interfere too much with more
115 critical actions.
116 * Transferring credits from one app to another. For apps that rely on others for some pieces of
117 work, it may be beneficial to allow the requesting app to transfer, donate, or somehow make
118 available some of its own credits to the app doing the work in order to make sure the working app
119 has enough credits available to do the work.
120 * Formulate values based on device hardware. For example, adjust the consumption limit based on the
121 battery size, or the price and/or CTP of actions based on hardware efficiency.
122 * Price discovery via an auction system. Instead of just setting a fixed price that may be modified
123 by device and app states, let an app say how much it's willing to pay for a specific action and
124 then have a small auction when the system needs to decide which app to perform the action for
125 first or how much to charge the app.
126
127 # Definitions
128
129 * ARC: Android Resource Credits are the "currency" units used as an abstraction layer over the real
130 battery drain. They allow the system to standardize costs and prices across various devices.
131 * Cake: A lie; also the smallest unit of an ARC (1 cake = one-billionth of an ARC = 1 nano-ARC).
132 When the apps request to do something, we shall let them eat cake.
133 * Cost to produce (CTP): An economic term that refers to the total cost incurred by a business to
134 produce a specific quantity of a product or offer a service. In TARE's context, CTP is meant to be
135 the estimated cost t ohe system to accomplish a certain action. These "actions" are basically APIs
136 that apps use to get something done. So the idea is to define the base cost for an app to use a
137 specific API.
138 * Satiated: used to refer to when the device is fully charged (at 100% battery level)