Adam Lesinski | 0debc9a | 2014-07-16 19:09:13 -0700 | [diff] [blame] | 1 | /** |
| 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 | |
| 17 | package android.app.usage; |
| 18 | |
Amith Yamasani | afbccb7 | 2017-11-27 10:44:24 -0800 | [diff] [blame] | 19 | import android.app.usage.UsageStatsManager.StandbyBuckets; |
Adam Lesinski | 0debc9a | 2014-07-16 19:09:13 -0700 | [diff] [blame] | 20 | import android.content.ComponentName; |
Adam Lesinski | 7f61e96 | 2014-09-02 16:43:52 -0700 | [diff] [blame] | 21 | import android.content.res.Configuration; |
Adam Lesinski | 0debc9a | 2014-07-16 19:09:13 -0700 | [diff] [blame] | 22 | |
Daniel Nishi | cf9d19e | 2017-01-23 14:33:42 -0800 | [diff] [blame] | 23 | import java.util.List; |
Ritesh Reddy | 8a6ce2c | 2015-12-17 17:03:54 +0000 | [diff] [blame] | 24 | |
Adam Lesinski | 0debc9a | 2014-07-16 19:09:13 -0700 | [diff] [blame] | 25 | /** |
| 26 | * UsageStatsManager local system service interface. |
| 27 | * |
| 28 | * {@hide} Only for use within the system server. |
| 29 | */ |
| 30 | public abstract class UsageStatsManagerInternal { |
| 31 | |
| 32 | /** |
| 33 | * Reports an event to the UsageStatsManager. |
| 34 | * |
Adam Lesinski | 7f61e96 | 2014-09-02 16:43:52 -0700 | [diff] [blame] | 35 | * @param component The component for which this event occurred. |
Adam Lesinski | 3c15351 | 2014-07-23 17:34:34 -0700 | [diff] [blame] | 36 | * @param userId The user id to which the component belongs to. |
Adam Lesinski | 7f61e96 | 2014-09-02 16:43:52 -0700 | [diff] [blame] | 37 | * @param eventType The event that occurred. Valid values can be found at |
Adam Lesinski | 3516800 | 2014-07-21 15:25:30 -0700 | [diff] [blame] | 38 | * {@link UsageEvents} |
Adam Lesinski | 0debc9a | 2014-07-16 19:09:13 -0700 | [diff] [blame] | 39 | */ |
Adam Lesinski | 7f61e96 | 2014-09-02 16:43:52 -0700 | [diff] [blame] | 40 | public abstract void reportEvent(ComponentName component, int userId, int eventType); |
| 41 | |
| 42 | /** |
Adam Lesinski | 978a1ed | 2015-03-02 11:37:24 -0800 | [diff] [blame] | 43 | * 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 Lesinski | 7f61e96 | 2014-09-02 16:43:52 -0700 | [diff] [blame] | 53 | * 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 Lesinski | 0debc9a | 2014-07-16 19:09:13 -0700 | [diff] [blame] | 58 | |
| 59 | /** |
Makoto Onuki | ac04250 | 2016-05-20 16:39:42 -0700 | [diff] [blame] | 60 | * 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 Yamasani | 37a40c2 | 2015-06-17 13:25:42 -0700 | [diff] [blame] | 71 | * 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 Lesinski | 0debc9a | 2014-07-16 19:09:13 -0700 | [diff] [blame] | 79 | * Prepares the UsageStatsService for shutdown. |
| 80 | */ |
| 81 | public abstract void prepareShutdown(); |
Amith Yamasani | b0ff322 | 2015-03-04 09:56:14 -0800 | [diff] [blame] | 82 | |
| 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 Hackborn | fcc95a6 | 2015-11-02 13:43:29 -0800 | [diff] [blame] | 88 | * @param uidForAppId The uid of the app, which will be used for its app id |
Amith Yamasani | b0ff322 | 2015-03-04 09:56:14 -0800 | [diff] [blame] | 89 | * @param userId |
| 90 | * @return |
| 91 | */ |
Dianne Hackborn | fcc95a6 | 2015-11-02 13:43:29 -0800 | [diff] [blame] | 92 | public abstract boolean isAppIdle(String packageName, int uidForAppId, int userId); |
Amith Yamasani | b0ff322 | 2015-03-04 09:56:14 -0800 | [diff] [blame] | 93 | |
| 94 | /** |
Christopher Tate | a732f01 | 2017-10-26 17:26:53 -0700 | [diff] [blame] | 95 | * 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 Hackborn | 4a503b1 | 2015-08-06 22:19:06 -0700 | [diff] [blame] | 108 | * 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 Chen | 8dca36d | 2015-06-19 12:44:59 -0700 | [diff] [blame] | 115 | * @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 Yamasani | b0ff322 | 2015-03-04 09:56:14 -0800 | [diff] [blame] | 121 | * 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 Chen | 8dca36d | 2015-06-19 12:44:59 -0700 | [diff] [blame] | 134 | public static abstract class AppIdleStateChangeListener { |
Amith Yamasani | 84cd7b7 | 2017-11-07 13:59:37 -0800 | [diff] [blame] | 135 | |
| 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 Chen | 8dca36d | 2015-06-19 12:44:59 -0700 | [diff] [blame] | 144 | public abstract void onParoleStateChanged(boolean isParoleOn); |
Amith Yamasani | b0ff322 | 2015-03-04 09:56:14 -0800 | [diff] [blame] | 145 | } |
| 146 | |
Ritesh Reddy | 8a6ce2c | 2015-12-17 17:03:54 +0000 | [diff] [blame] | 147 | /* 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 Onuki | ad62301 | 2017-05-15 09:29:34 -0700 | [diff] [blame] | 152 | /** |
| 153 | * Return usage stats. |
| 154 | * |
| 155 | * @param obfuscateInstantApps whether instant app package names need to be obfuscated in the |
| 156 | * result. |
| 157 | */ |
Daniel Nishi | cf9d19e | 2017-01-23 14:33:42 -0800 | [diff] [blame] | 158 | public abstract List<UsageStats> queryUsageStatsForUser( |
Makoto Onuki | ad62301 | 2017-05-15 09:29:34 -0700 | [diff] [blame] | 159 | int userId, int interval, long beginTime, long endTime, boolean obfuscateInstantApps); |
Adam Lesinski | 0debc9a | 2014-07-16 19:09:13 -0700 | [diff] [blame] | 160 | } |