Home | History | Annotate | Download | only in usage
      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 
     19 import android.content.ComponentName;
     20 import android.content.res.Configuration;
     21 
     22 import java.io.IOException;
     23 
     24 /**
     25  * UsageStatsManager local system service interface.
     26  *
     27  * {@hide} Only for use within the system server.
     28  */
     29 public abstract class UsageStatsManagerInternal {
     30 
     31     /**
     32      * Reports an event to the UsageStatsManager.
     33      *
     34      * @param component The component for which this event occurred.
     35      * @param userId The user id to which the component belongs to.
     36      * @param eventType The event that occurred. Valid values can be found at
     37      * {@link UsageEvents}
     38      */
     39     public abstract void reportEvent(ComponentName component, int userId, int eventType);
     40 
     41     /**
     42      * 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     /**
     52      * 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);
     57 
     58     /**
     59      * 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     /**
     70      * 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     /**
     78      * Prepares the UsageStatsService for shutdown.
     79      */
     80     public abstract void prepareShutdown();
     81 
     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
     87      * @param uidForAppId The uid of the app, which will be used for its app id
     88      * @param userId
     89      * @return
     90      */
     91     public abstract boolean isAppIdle(String packageName, int uidForAppId, int userId);
     92 
     93     /**
     94      * 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     /**
    101      * @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     /**
    107      * 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 
    120     public static abstract class AppIdleStateChangeListener {
    121         public abstract void onAppIdleStateChanged(String packageName, int userId, boolean idle);
    122         public abstract void onParoleStateChanged(boolean isParoleOn);
    123     }
    124 
    125     /*  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 
    130 }
    131