blob: 09ced2648de1acff210fa0dc5251baf219102945 [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 /**
Julia Reynolds1fac86e2018-03-07 08:30:37 -050062 * Reports that an application has posted an interruptive notification.
63 *
64 * @param packageName The package name of the app that posted the notification
65 * @param channelId The ID of the NotificationChannel to which the notification was posted
66 * @param userId The user in which the notification was posted
67 */
68 public abstract void reportInterruptiveNotification(String packageName, String channelId,
69 @UserIdInt int userId);
70
71 /**
Makoto Onukiac042502016-05-20 16:39:42 -070072 * Reports that an action equivalent to a ShortcutInfo is taken by the user.
73 *
74 * @param packageName The package name of the shortcut publisher
75 * @param shortcutId The ID of the shortcut in question
76 * @param userId The user in which the content provider was accessed.
77 *
78 * @see android.content.pm.ShortcutManager#reportShortcutUsed(String)
79 */
Amith Yamasani53f06ea2018-01-05 17:53:46 -080080 public abstract void reportShortcutUsage(String packageName, String shortcutId,
81 @UserIdInt int userId);
Makoto Onukiac042502016-05-20 16:39:42 -070082
83 /**
Amith Yamasani37a40c22015-06-17 13:25:42 -070084 * Reports that a content provider has been accessed by a foreground app.
85 * @param name The authority of the content provider
86 * @param pkgName The package name of the content provider
87 * @param userId The user in which the content provider was accessed.
88 */
Amith Yamasani53f06ea2018-01-05 17:53:46 -080089 public abstract void reportContentProviderUsage(String name, String pkgName,
90 @UserIdInt int userId);
Amith Yamasani37a40c22015-06-17 13:25:42 -070091
92 /**
Adam Lesinski0debc9a2014-07-16 19:09:13 -070093 * Prepares the UsageStatsService for shutdown.
94 */
95 public abstract void prepareShutdown();
Amith Yamasanib0ff3222015-03-04 09:56:14 -080096
97 /**
98 * Returns true if the app has not been used for a certain amount of time. How much time?
99 * Could be hours, could be days, who knows?
100 *
101 * @param packageName
Dianne Hackbornfcc95a62015-11-02 13:43:29 -0800102 * @param uidForAppId The uid of the app, which will be used for its app id
Amith Yamasanib0ff3222015-03-04 09:56:14 -0800103 * @param userId
104 * @return
105 */
Amith Yamasani53f06ea2018-01-05 17:53:46 -0800106 public abstract boolean isAppIdle(String packageName, int uidForAppId, @UserIdInt int userId);
Amith Yamasanib0ff3222015-03-04 09:56:14 -0800107
108 /**
Christopher Tatea732f012017-10-26 17:26:53 -0700109 * Returns the app standby bucket that the app is currently in. This accessor does
110 * <em>not</em> obfuscate instant apps.
111 *
112 * @param packageName
113 * @param userId
114 * @param nowElapsed The current time, in the elapsedRealtime time base
115 * @return the AppStandby bucket code the app currently resides in. If the app is
116 * unknown in the given user, STANDBY_BUCKET_NEVER is returned.
117 */
Amith Yamasani53f06ea2018-01-05 17:53:46 -0800118 @StandbyBuckets public abstract int getAppStandbyBucket(String packageName,
119 @UserIdInt int userId, long nowElapsed);
Christopher Tatea732f012017-10-26 17:26:53 -0700120
121 /**
Dianne Hackborn4a503b12015-08-06 22:19:06 -0700122 * Returns all of the uids for a given user where all packages associating with that uid
123 * are in the app idle state -- there are no associated apps that are not idle. This means
124 * all of the returned uids can be safely considered app idle.
125 */
Amith Yamasani53f06ea2018-01-05 17:53:46 -0800126 public abstract int[] getIdleUidsForUser(@UserIdInt int userId);
Dianne Hackborn4a503b12015-08-06 22:19:06 -0700127
128 /**
Xiaohui Chen8dca36d2015-06-19 12:44:59 -0700129 * @return True if currently app idle parole mode is on. This means all idle apps are allow to
130 * run for a short period of time.
131 */
132 public abstract boolean isAppIdleParoleOn();
133
134 /**
Amith Yamasanib0ff3222015-03-04 09:56:14 -0800135 * Sets up a listener for changes to packages being accessed.
136 * @param listener A listener within the system process.
137 */
138 public abstract void addAppIdleStateChangeListener(
139 AppIdleStateChangeListener listener);
140
141 /**
142 * Removes a listener that was previously added for package usage state changes.
143 * @param listener The listener within the system process to remove.
144 */
145 public abstract void removeAppIdleStateChangeListener(
146 AppIdleStateChangeListener listener);
147
Xiaohui Chen8dca36d2015-06-19 12:44:59 -0700148 public static abstract class AppIdleStateChangeListener {
Amith Yamasani84cd7b72017-11-07 13:59:37 -0800149
150 /** Callback to inform listeners that the idle state has changed to a new bucket. */
Amith Yamasani53f06ea2018-01-05 17:53:46 -0800151 public abstract void onAppIdleStateChanged(String packageName, @UserIdInt int userId,
Amith Yamasani119be9a2018-02-18 22:23:00 -0800152 boolean idle, int bucket, int reason);
Amith Yamasani84cd7b72017-11-07 13:59:37 -0800153
154 /**
155 * Callback to inform listeners that the parole state has changed. This means apps are
156 * allowed to do work even if they're idle or in a low bucket.
157 */
Xiaohui Chen8dca36d2015-06-19 12:44:59 -0700158 public abstract void onParoleStateChanged(boolean isParoleOn);
Christopher Tated117b292018-01-05 17:32:36 -0800159
160 /**
161 * Optional callback to inform the listener that the app has transitioned into
162 * an active state due to user interaction.
163 */
164 public void onUserInteractionStarted(String packageName, @UserIdInt int userId) {
165 // No-op by default
166 }
Amith Yamasanib0ff3222015-03-04 09:56:14 -0800167 }
168
Amith Yamasani53f06ea2018-01-05 17:53:46 -0800169 /** Backup/Restore API */
170 public abstract byte[] getBackupPayload(@UserIdInt int userId, String key);
Ritesh Reddy8a6ce2c2015-12-17 17:03:54 +0000171
Amith Yamasani53f06ea2018-01-05 17:53:46 -0800172 /**
173 * ?
174 * @param userId
175 * @param key
176 * @param payload
177 */
178 public abstract void applyRestoredPayload(@UserIdInt int userId, String key, byte[] payload);
Ritesh Reddy8a6ce2c2015-12-17 17:03:54 +0000179
Makoto Onukiad623012017-05-15 09:29:34 -0700180 /**
Sudheer Shanka101c3532018-01-08 16:28:42 -0800181 * Called by DevicePolicyManagerService to inform that a new admin has been added.
182 *
183 * @param packageName the package in which the admin component is part of.
184 * @param userId the userId in which the admin has been added.
185 */
186 public abstract void onActiveAdminAdded(String packageName, int userId);
187
188 /**
189 * Called by DevicePolicyManagerService to inform about the active admins in an user.
190 *
191 * @param adminApps the set of active admins in {@param userId} or null if there are none.
192 * @param userId the userId to which the admin apps belong.
193 */
194 public abstract void setActiveAdminApps(Set<String> adminApps, int userId);
195
196 /**
Sudheer Shankac53c47f2018-01-16 12:01:00 -0800197 * Called by DevicePolicyManagerService during boot to inform that admin data is loaded and
198 * pushed to UsageStatsService.
199 */
200 public abstract void onAdminDataAvailable();
201
202 /**
Makoto Onukiad623012017-05-15 09:29:34 -0700203 * Return usage stats.
204 *
205 * @param obfuscateInstantApps whether instant app package names need to be obfuscated in the
206 * result.
207 */
Amith Yamasani53f06ea2018-01-05 17:53:46 -0800208 public abstract List<UsageStats> queryUsageStatsForUser(@UserIdInt int userId, int interval,
209 long beginTime, long endTime, boolean obfuscateInstantApps);
210
211 /**
212 * Used to persist the last time a job was run for this app, in order to make decisions later
213 * whether a job should be deferred until later. The time passed in should be in elapsed
214 * realtime since boot.
215 * @param packageName the app that executed a job.
216 * @param userId the user associated with the job.
217 * @param elapsedRealtime the time when the job was executed, in elapsed realtime millis since
218 * boot.
219 */
220 public abstract void setLastJobRunTime(String packageName, @UserIdInt int userId,
221 long elapsedRealtime);
222
223 /**
224 * Returns the time in millis since a job was executed for this app, in elapsed realtime
225 * timebase. This value can be larger than the current elapsed realtime if the job was executed
226 * before the device was rebooted. The default value is {@link Long#MAX_VALUE}.
227 * @param packageName the app you're asking about.
228 * @param userId the user associated with the job.
229 * @return the time in millis since a job was last executed for the app, provided it was
230 * indicated here before by a call to {@link #setLastJobRunTime(String, int, long)}.
231 */
232 public abstract long getTimeSinceLastJobRun(String packageName, @UserIdInt int userId);
Christopher Tated117b292018-01-05 17:32:36 -0800233
234 /**
235 * Report a few data points about an app's job state at the current time.
236 *
237 * @param packageName the app whose job state is being described
238 * @param userId which user the app is associated with
239 * @param numDeferredJobs the number of pending jobs that were deferred
240 * due to bucketing policy
241 * @param timeSinceLastJobRun number of milliseconds since the last time one of
242 * this app's jobs was executed
243 */
244 public abstract void reportAppJobState(String packageName, @UserIdInt int userId,
245 int numDeferredJobs, long timeSinceLastJobRun);
Adam Lesinski0debc9a2014-07-16 19:09:13 -0700246}