blob: dbaace2f0ac9a85c977d18ea4fb212e0dea44af7 [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
19import android.content.ComponentName;
Adam Lesinski7f61e962014-09-02 16:43:52 -070020import android.content.res.Configuration;
Adam Lesinski0debc9a2014-07-16 19:09:13 -070021
Daniel Nishicf9d19e2017-01-23 14:33:42 -080022import java.util.List;
Ritesh Reddy8a6ce2c2015-12-17 17:03:54 +000023
Adam Lesinski0debc9a2014-07-16 19:09:13 -070024/**
25 * UsageStatsManager local system service interface.
26 *
27 * {@hide} Only for use within the system server.
28 */
29public abstract class UsageStatsManagerInternal {
30
31 /**
32 * Reports an event to the UsageStatsManager.
33 *
Adam Lesinski7f61e962014-09-02 16:43:52 -070034 * @param component The component for which this event occurred.
Adam Lesinski3c153512014-07-23 17:34:34 -070035 * @param userId The user id to which the component belongs to.
Adam Lesinski7f61e962014-09-02 16:43:52 -070036 * @param eventType The event that occurred. Valid values can be found at
Adam Lesinski35168002014-07-21 15:25:30 -070037 * {@link UsageEvents}
Adam Lesinski0debc9a2014-07-16 19:09:13 -070038 */
Adam Lesinski7f61e962014-09-02 16:43:52 -070039 public abstract void reportEvent(ComponentName component, int userId, int eventType);
40
41 /**
Adam Lesinski978a1ed2015-03-02 11:37:24 -080042 * Reports an event to the UsageStatsManager.
43 *
44 * @param packageName The package for which this event occurred.
45 * @param userId The user id to which the component belongs to.
46 * @param eventType The event that occurred. Valid values can be found at
47 * {@link UsageEvents}
48 */
49 public abstract void reportEvent(String packageName, int userId, int eventType);
50
51 /**
Adam Lesinski7f61e962014-09-02 16:43:52 -070052 * Reports a configuration change to the UsageStatsManager.
53 *
54 * @param config The new device configuration.
55 */
56 public abstract void reportConfigurationChange(Configuration config, int userId);
Adam Lesinski0debc9a2014-07-16 19:09:13 -070057
58 /**
Makoto Onukiac042502016-05-20 16:39:42 -070059 * Reports that an action equivalent to a ShortcutInfo is taken by the user.
60 *
61 * @param packageName The package name of the shortcut publisher
62 * @param shortcutId The ID of the shortcut in question
63 * @param userId The user in which the content provider was accessed.
64 *
65 * @see android.content.pm.ShortcutManager#reportShortcutUsed(String)
66 */
67 public abstract void reportShortcutUsage(String packageName, String shortcutId, int userId);
68
69 /**
Amith Yamasani37a40c22015-06-17 13:25:42 -070070 * Reports that a content provider has been accessed by a foreground app.
71 * @param name The authority of the content provider
72 * @param pkgName The package name of the content provider
73 * @param userId The user in which the content provider was accessed.
74 */
75 public abstract void reportContentProviderUsage(String name, String pkgName, int userId);
76
77 /**
Adam Lesinski0debc9a2014-07-16 19:09:13 -070078 * Prepares the UsageStatsService for shutdown.
79 */
80 public abstract void prepareShutdown();
Amith Yamasanib0ff3222015-03-04 09:56:14 -080081
82 /**
83 * Returns true if the app has not been used for a certain amount of time. How much time?
84 * Could be hours, could be days, who knows?
85 *
86 * @param packageName
Dianne Hackbornfcc95a62015-11-02 13:43:29 -080087 * @param uidForAppId The uid of the app, which will be used for its app id
Amith Yamasanib0ff3222015-03-04 09:56:14 -080088 * @param userId
89 * @return
90 */
Dianne Hackbornfcc95a62015-11-02 13:43:29 -080091 public abstract boolean isAppIdle(String packageName, int uidForAppId, int userId);
Amith Yamasanib0ff3222015-03-04 09:56:14 -080092
93 /**
Dianne Hackborn4a503b12015-08-06 22:19:06 -070094 * Returns all of the uids for a given user where all packages associating with that uid
95 * are in the app idle state -- there are no associated apps that are not idle. This means
96 * all of the returned uids can be safely considered app idle.
97 */
98 public abstract int[] getIdleUidsForUser(int userId);
99
100 /**
Xiaohui Chen8dca36d2015-06-19 12:44:59 -0700101 * @return True if currently app idle parole mode is on. This means all idle apps are allow to
102 * run for a short period of time.
103 */
104 public abstract boolean isAppIdleParoleOn();
105
106 /**
Amith Yamasanib0ff3222015-03-04 09:56:14 -0800107 * Sets up a listener for changes to packages being accessed.
108 * @param listener A listener within the system process.
109 */
110 public abstract void addAppIdleStateChangeListener(
111 AppIdleStateChangeListener listener);
112
113 /**
114 * Removes a listener that was previously added for package usage state changes.
115 * @param listener The listener within the system process to remove.
116 */
117 public abstract void removeAppIdleStateChangeListener(
118 AppIdleStateChangeListener listener);
119
Xiaohui Chen8dca36d2015-06-19 12:44:59 -0700120 public static abstract class AppIdleStateChangeListener {
121 public abstract void onAppIdleStateChanged(String packageName, int userId, boolean idle);
122 public abstract void onParoleStateChanged(boolean isParoleOn);
Amith Yamasanib0ff3222015-03-04 09:56:14 -0800123 }
124
Ritesh Reddy8a6ce2c2015-12-17 17:03:54 +0000125 /* Backup/Restore API */
126 public abstract byte[] getBackupPayload(int user, String key);
127
128 public abstract void applyRestoredPayload(int user, String key, byte[] payload);
129
Makoto Onukiad623012017-05-15 09:29:34 -0700130 /**
131 * Return usage stats.
132 *
133 * @param obfuscateInstantApps whether instant app package names need to be obfuscated in the
134 * result.
135 */
Daniel Nishicf9d19e2017-01-23 14:33:42 -0800136 public abstract List<UsageStats> queryUsageStatsForUser(
Makoto Onukiad623012017-05-15 09:29:34 -0700137 int userId, int interval, long beginTime, long endTime, boolean obfuscateInstantApps);
Adam Lesinski0debc9a2014-07-16 19:09:13 -0700138}