blob: 5d6a989ffef84135a0f63d40b9e9f37b57283e6f [file] [log] [blame]
Adam Lesinski0debc9a2014-07-16 19:09:13 -07001/**
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License. You may obtain a copy
6 * of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 * License for the specific language governing permissions and limitations
14 * under the License.
15 */
16
17package android.app.usage;
18
Amith Yamasani53f06ea2018-01-05 17:53:46 -080019import android.annotation.UserIdInt;
Amith Yamasaniafbccb72017-11-27 10:44:24 -080020import android.app.usage.UsageStatsManager.StandbyBuckets;
Adam Lesinski0debc9a2014-07-16 19:09:13 -070021import android.content.ComponentName;
Adam Lesinski7f61e962014-09-02 16:43:52 -070022import android.content.res.Configuration;
Adam Lesinski0debc9a2014-07-16 19:09:13 -070023
Daniel Nishicf9d19e2017-01-23 14:33:42 -080024import java.util.List;
Sudheer Shanka101c3532018-01-08 16:28:42 -080025import java.util.Set;
Ritesh Reddy8a6ce2c2015-12-17 17:03:54 +000026
Adam Lesinski0debc9a2014-07-16 19:09:13 -070027/**
28 * UsageStatsManager local system service interface.
29 *
30 * {@hide} Only for use within the system server.
31 */
32public abstract class UsageStatsManagerInternal {
33
34 /**
35 * Reports an event to the UsageStatsManager.
36 *
Adam Lesinski7f61e962014-09-02 16:43:52 -070037 * @param component The component for which this event occurred.
Adam Lesinski3c153512014-07-23 17:34:34 -070038 * @param userId The user id to which the component belongs to.
Adam Lesinski7f61e962014-09-02 16:43:52 -070039 * @param eventType The event that occurred. Valid values can be found at
Adam Lesinski35168002014-07-21 15:25:30 -070040 * {@link UsageEvents}
Adam Lesinski0debc9a2014-07-16 19:09:13 -070041 */
Amith Yamasani53f06ea2018-01-05 17:53:46 -080042 public abstract void reportEvent(ComponentName component, @UserIdInt int userId, int eventType);
Adam Lesinski7f61e962014-09-02 16:43:52 -070043
44 /**
Adam Lesinski978a1ed2015-03-02 11:37:24 -080045 * Reports an event to the UsageStatsManager.
46 *
47 * @param packageName The package for which this event occurred.
48 * @param userId The user id to which the component belongs to.
49 * @param eventType The event that occurred. Valid values can be found at
50 * {@link UsageEvents}
51 */
Amith Yamasani53f06ea2018-01-05 17:53:46 -080052 public abstract void reportEvent(String packageName, @UserIdInt int userId, int eventType);
Adam Lesinski978a1ed2015-03-02 11:37:24 -080053
54 /**
Adam Lesinski7f61e962014-09-02 16:43:52 -070055 * Reports a configuration change to the UsageStatsManager.
56 *
57 * @param config The new device configuration.
58 */
Amith Yamasani53f06ea2018-01-05 17:53:46 -080059 public abstract void reportConfigurationChange(Configuration config, @UserIdInt int userId);
Adam Lesinski0debc9a2014-07-16 19:09:13 -070060
61 /**
Makoto Onukiac042502016-05-20 16:39:42 -070062 * Reports that an action equivalent to a ShortcutInfo is taken by the user.
63 *
64 * @param packageName The package name of the shortcut publisher
65 * @param shortcutId The ID of the shortcut in question
66 * @param userId The user in which the content provider was accessed.
67 *
68 * @see android.content.pm.ShortcutManager#reportShortcutUsed(String)
69 */
Amith Yamasani53f06ea2018-01-05 17:53:46 -080070 public abstract void reportShortcutUsage(String packageName, String shortcutId,
71 @UserIdInt int userId);
Makoto Onukiac042502016-05-20 16:39:42 -070072
73 /**
Amith Yamasani37a40c22015-06-17 13:25:42 -070074 * Reports that a content provider has been accessed by a foreground app.
75 * @param name The authority of the content provider
76 * @param pkgName The package name of the content provider
77 * @param userId The user in which the content provider was accessed.
78 */
Amith Yamasani53f06ea2018-01-05 17:53:46 -080079 public abstract void reportContentProviderUsage(String name, String pkgName,
80 @UserIdInt int userId);
Amith Yamasani37a40c22015-06-17 13:25:42 -070081
82 /**
Adam Lesinski0debc9a2014-07-16 19:09:13 -070083 * Prepares the UsageStatsService for shutdown.
84 */
85 public abstract void prepareShutdown();
Amith Yamasanib0ff3222015-03-04 09:56:14 -080086
87 /**
88 * Returns true if the app has not been used for a certain amount of time. How much time?
89 * Could be hours, could be days, who knows?
90 *
91 * @param packageName
Dianne Hackbornfcc95a62015-11-02 13:43:29 -080092 * @param uidForAppId The uid of the app, which will be used for its app id
Amith Yamasanib0ff3222015-03-04 09:56:14 -080093 * @param userId
94 * @return
95 */
Amith Yamasani53f06ea2018-01-05 17:53:46 -080096 public abstract boolean isAppIdle(String packageName, int uidForAppId, @UserIdInt int userId);
Amith Yamasanib0ff3222015-03-04 09:56:14 -080097
98 /**
Christopher Tatea732f012017-10-26 17:26:53 -070099 * Returns the app standby bucket that the app is currently in. This accessor does
100 * <em>not</em> obfuscate instant apps.
101 *
102 * @param packageName
103 * @param userId
104 * @param nowElapsed The current time, in the elapsedRealtime time base
105 * @return the AppStandby bucket code the app currently resides in. If the app is
106 * unknown in the given user, STANDBY_BUCKET_NEVER is returned.
107 */
Amith Yamasani53f06ea2018-01-05 17:53:46 -0800108 @StandbyBuckets public abstract int getAppStandbyBucket(String packageName,
109 @UserIdInt int userId, long nowElapsed);
Christopher Tatea732f012017-10-26 17:26:53 -0700110
111 /**
Dianne Hackborn4a503b12015-08-06 22:19:06 -0700112 * Returns all of the uids for a given user where all packages associating with that uid
113 * are in the app idle state -- there are no associated apps that are not idle. This means
114 * all of the returned uids can be safely considered app idle.
115 */
Amith Yamasani53f06ea2018-01-05 17:53:46 -0800116 public abstract int[] getIdleUidsForUser(@UserIdInt int userId);
Dianne Hackborn4a503b12015-08-06 22:19:06 -0700117
118 /**
Xiaohui Chen8dca36d2015-06-19 12:44:59 -0700119 * @return True if currently app idle parole mode is on. This means all idle apps are allow to
120 * run for a short period of time.
121 */
122 public abstract boolean isAppIdleParoleOn();
123
124 /**
Amith Yamasanib0ff3222015-03-04 09:56:14 -0800125 * Sets up a listener for changes to packages being accessed.
126 * @param listener A listener within the system process.
127 */
128 public abstract void addAppIdleStateChangeListener(
129 AppIdleStateChangeListener listener);
130
131 /**
132 * Removes a listener that was previously added for package usage state changes.
133 * @param listener The listener within the system process to remove.
134 */
135 public abstract void removeAppIdleStateChangeListener(
136 AppIdleStateChangeListener listener);
137
Xiaohui Chen8dca36d2015-06-19 12:44:59 -0700138 public static abstract class AppIdleStateChangeListener {
Amith Yamasani84cd7b72017-11-07 13:59:37 -0800139
140 /** Callback to inform listeners that the idle state has changed to a new bucket. */
Amith Yamasani53f06ea2018-01-05 17:53:46 -0800141 public abstract void onAppIdleStateChanged(String packageName, @UserIdInt int userId,
142 boolean idle, int bucket);
Amith Yamasani84cd7b72017-11-07 13:59:37 -0800143
144 /**
145 * Callback to inform listeners that the parole state has changed. This means apps are
146 * allowed to do work even if they're idle or in a low bucket.
147 */
Xiaohui Chen8dca36d2015-06-19 12:44:59 -0700148 public abstract void onParoleStateChanged(boolean isParoleOn);
Christopher Tated117b292018-01-05 17:32:36 -0800149
150 /**
151 * Optional callback to inform the listener that the app has transitioned into
152 * an active state due to user interaction.
153 */
154 public void onUserInteractionStarted(String packageName, @UserIdInt int userId) {
155 // No-op by default
156 }
Amith Yamasanib0ff3222015-03-04 09:56:14 -0800157 }
158
Amith Yamasani53f06ea2018-01-05 17:53:46 -0800159 /** Backup/Restore API */
160 public abstract byte[] getBackupPayload(@UserIdInt int userId, String key);
Ritesh Reddy8a6ce2c2015-12-17 17:03:54 +0000161
Amith Yamasani53f06ea2018-01-05 17:53:46 -0800162 /**
163 * ?
164 * @param userId
165 * @param key
166 * @param payload
167 */
168 public abstract void applyRestoredPayload(@UserIdInt int userId, String key, byte[] payload);
Ritesh Reddy8a6ce2c2015-12-17 17:03:54 +0000169
Makoto Onukiad623012017-05-15 09:29:34 -0700170 /**
Sudheer Shanka101c3532018-01-08 16:28:42 -0800171 * Called by DevicePolicyManagerService to inform that a new admin has been added.
172 *
173 * @param packageName the package in which the admin component is part of.
174 * @param userId the userId in which the admin has been added.
175 */
176 public abstract void onActiveAdminAdded(String packageName, int userId);
177
178 /**
179 * Called by DevicePolicyManagerService to inform about the active admins in an user.
180 *
181 * @param adminApps the set of active admins in {@param userId} or null if there are none.
182 * @param userId the userId to which the admin apps belong.
183 */
184 public abstract void setActiveAdminApps(Set<String> adminApps, int userId);
185
186 /**
Sudheer Shankac53c47f2018-01-16 12:01:00 -0800187 * Called by DevicePolicyManagerService during boot to inform that admin data is loaded and
188 * pushed to UsageStatsService.
189 */
190 public abstract void onAdminDataAvailable();
191
192 /**
Makoto Onukiad623012017-05-15 09:29:34 -0700193 * Return usage stats.
194 *
195 * @param obfuscateInstantApps whether instant app package names need to be obfuscated in the
196 * result.
197 */
Amith Yamasani53f06ea2018-01-05 17:53:46 -0800198 public abstract List<UsageStats> queryUsageStatsForUser(@UserIdInt int userId, int interval,
199 long beginTime, long endTime, boolean obfuscateInstantApps);
200
201 /**
202 * Used to persist the last time a job was run for this app, in order to make decisions later
203 * whether a job should be deferred until later. The time passed in should be in elapsed
204 * realtime since boot.
205 * @param packageName the app that executed a job.
206 * @param userId the user associated with the job.
207 * @param elapsedRealtime the time when the job was executed, in elapsed realtime millis since
208 * boot.
209 */
210 public abstract void setLastJobRunTime(String packageName, @UserIdInt int userId,
211 long elapsedRealtime);
212
213 /**
214 * Returns the time in millis since a job was executed for this app, in elapsed realtime
215 * timebase. This value can be larger than the current elapsed realtime if the job was executed
216 * before the device was rebooted. The default value is {@link Long#MAX_VALUE}.
217 * @param packageName the app you're asking about.
218 * @param userId the user associated with the job.
219 * @return the time in millis since a job was last executed for the app, provided it was
220 * indicated here before by a call to {@link #setLastJobRunTime(String, int, long)}.
221 */
222 public abstract long getTimeSinceLastJobRun(String packageName, @UserIdInt int userId);
Christopher Tated117b292018-01-05 17:32:36 -0800223
224 /**
225 * Report a few data points about an app's job state at the current time.
226 *
227 * @param packageName the app whose job state is being described
228 * @param userId which user the app is associated with
229 * @param numDeferredJobs the number of pending jobs that were deferred
230 * due to bucketing policy
231 * @param timeSinceLastJobRun number of milliseconds since the last time one of
232 * this app's jobs was executed
233 */
234 public abstract void reportAppJobState(String packageName, @UserIdInt int userId,
235 int numDeferredJobs, long timeSinceLastJobRun);
Adam Lesinski0debc9a2014-07-16 19:09:13 -0700236}