blob: 4b4fe72f855f1fd8059f3d864bf01f9509b408fa [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 Yamasaniafbccb72017-11-27 10:44:24 -080019import android.app.usage.UsageStatsManager.StandbyBuckets;
Adam Lesinski0debc9a2014-07-16 19:09:13 -070020import android.content.ComponentName;
Adam Lesinski7f61e962014-09-02 16:43:52 -070021import android.content.res.Configuration;
Adam Lesinski0debc9a2014-07-16 19:09:13 -070022
Daniel Nishicf9d19e2017-01-23 14:33:42 -080023import java.util.List;
Ritesh Reddy8a6ce2c2015-12-17 17:03:54 +000024
Adam Lesinski0debc9a2014-07-16 19:09:13 -070025/**
26 * UsageStatsManager local system service interface.
27 *
28 * {@hide} Only for use within the system server.
29 */
30public abstract class UsageStatsManagerInternal {
31
32 /**
33 * Reports an event to the UsageStatsManager.
34 *
Adam Lesinski7f61e962014-09-02 16:43:52 -070035 * @param component The component for which this event occurred.
Adam Lesinski3c153512014-07-23 17:34:34 -070036 * @param userId The user id to which the component belongs to.
Adam Lesinski7f61e962014-09-02 16:43:52 -070037 * @param eventType The event that occurred. Valid values can be found at
Adam Lesinski35168002014-07-21 15:25:30 -070038 * {@link UsageEvents}
Adam Lesinski0debc9a2014-07-16 19:09:13 -070039 */
Adam Lesinski7f61e962014-09-02 16:43:52 -070040 public abstract void reportEvent(ComponentName component, int userId, int eventType);
41
42 /**
Adam Lesinski978a1ed2015-03-02 11:37:24 -080043 * Reports an event to the UsageStatsManager.
44 *
45 * @param packageName The package for which this event occurred.
46 * @param userId The user id to which the component belongs to.
47 * @param eventType The event that occurred. Valid values can be found at
48 * {@link UsageEvents}
49 */
50 public abstract void reportEvent(String packageName, int userId, int eventType);
51
52 /**
Adam Lesinski7f61e962014-09-02 16:43:52 -070053 * Reports a configuration change to the UsageStatsManager.
54 *
55 * @param config The new device configuration.
56 */
57 public abstract void reportConfigurationChange(Configuration config, int userId);
Adam Lesinski0debc9a2014-07-16 19:09:13 -070058
59 /**
Makoto Onukiac042502016-05-20 16:39:42 -070060 * Reports that an action equivalent to a ShortcutInfo is taken by the user.
61 *
62 * @param packageName The package name of the shortcut publisher
63 * @param shortcutId The ID of the shortcut in question
64 * @param userId The user in which the content provider was accessed.
65 *
66 * @see android.content.pm.ShortcutManager#reportShortcutUsed(String)
67 */
68 public abstract void reportShortcutUsage(String packageName, String shortcutId, int userId);
69
70 /**
Amith Yamasani37a40c22015-06-17 13:25:42 -070071 * Reports that a content provider has been accessed by a foreground app.
72 * @param name The authority of the content provider
73 * @param pkgName The package name of the content provider
74 * @param userId The user in which the content provider was accessed.
75 */
76 public abstract void reportContentProviderUsage(String name, String pkgName, int userId);
77
78 /**
Adam Lesinski0debc9a2014-07-16 19:09:13 -070079 * Prepares the UsageStatsService for shutdown.
80 */
81 public abstract void prepareShutdown();
Amith Yamasanib0ff3222015-03-04 09:56:14 -080082
83 /**
84 * Returns true if the app has not been used for a certain amount of time. How much time?
85 * Could be hours, could be days, who knows?
86 *
87 * @param packageName
Dianne Hackbornfcc95a62015-11-02 13:43:29 -080088 * @param uidForAppId The uid of the app, which will be used for its app id
Amith Yamasanib0ff3222015-03-04 09:56:14 -080089 * @param userId
90 * @return
91 */
Dianne Hackbornfcc95a62015-11-02 13:43:29 -080092 public abstract boolean isAppIdle(String packageName, int uidForAppId, int userId);
Amith Yamasanib0ff3222015-03-04 09:56:14 -080093
94 /**
Christopher Tatea732f012017-10-26 17:26:53 -070095 * Returns the app standby bucket that the app is currently in. This accessor does
96 * <em>not</em> obfuscate instant apps.
97 *
98 * @param packageName
99 * @param userId
100 * @param nowElapsed The current time, in the elapsedRealtime time base
101 * @return the AppStandby bucket code the app currently resides in. If the app is
102 * unknown in the given user, STANDBY_BUCKET_NEVER is returned.
103 */
104 @StandbyBuckets public abstract int getAppStandbyBucket(String packageName, int userId,
105 long nowElapsed);
106
107 /**
Dianne Hackborn4a503b12015-08-06 22:19:06 -0700108 * Returns all of the uids for a given user where all packages associating with that uid
109 * are in the app idle state -- there are no associated apps that are not idle. This means
110 * all of the returned uids can be safely considered app idle.
111 */
112 public abstract int[] getIdleUidsForUser(int userId);
113
114 /**
Xiaohui Chen8dca36d2015-06-19 12:44:59 -0700115 * @return True if currently app idle parole mode is on. This means all idle apps are allow to
116 * run for a short period of time.
117 */
118 public abstract boolean isAppIdleParoleOn();
119
120 /**
Amith Yamasanib0ff3222015-03-04 09:56:14 -0800121 * Sets up a listener for changes to packages being accessed.
122 * @param listener A listener within the system process.
123 */
124 public abstract void addAppIdleStateChangeListener(
125 AppIdleStateChangeListener listener);
126
127 /**
128 * Removes a listener that was previously added for package usage state changes.
129 * @param listener The listener within the system process to remove.
130 */
131 public abstract void removeAppIdleStateChangeListener(
132 AppIdleStateChangeListener listener);
133
Xiaohui Chen8dca36d2015-06-19 12:44:59 -0700134 public static abstract class AppIdleStateChangeListener {
Amith Yamasani84cd7b72017-11-07 13:59:37 -0800135
136 /** Callback to inform listeners that the idle state has changed to a new bucket. */
137 public abstract void onAppIdleStateChanged(String packageName, int userId, boolean idle,
138 int bucket);
139
140 /**
141 * Callback to inform listeners that the parole state has changed. This means apps are
142 * allowed to do work even if they're idle or in a low bucket.
143 */
Xiaohui Chen8dca36d2015-06-19 12:44:59 -0700144 public abstract void onParoleStateChanged(boolean isParoleOn);
Amith Yamasanib0ff3222015-03-04 09:56:14 -0800145 }
146
Ritesh Reddy8a6ce2c2015-12-17 17:03:54 +0000147 /* Backup/Restore API */
148 public abstract byte[] getBackupPayload(int user, String key);
149
150 public abstract void applyRestoredPayload(int user, String key, byte[] payload);
151
Makoto Onukiad623012017-05-15 09:29:34 -0700152 /**
153 * Return usage stats.
154 *
155 * @param obfuscateInstantApps whether instant app package names need to be obfuscated in the
156 * result.
157 */
Daniel Nishicf9d19e2017-01-23 14:33:42 -0800158 public abstract List<UsageStats> queryUsageStatsForUser(
Makoto Onukiad623012017-05-15 09:29:34 -0700159 int userId, int interval, long beginTime, long endTime, boolean obfuscateInstantApps);
Adam Lesinski0debc9a2014-07-16 19:09:13 -0700160}