Search in sources :

Example 11 with IUsageStatsManager

use of android.app.usage.IUsageStatsManager in project android_frameworks_base by AOSPA.

the class Am method runSetInactive.

private void runSetInactive() throws Exception {
    int userId = UserHandle.USER_CURRENT;
    String opt;
    while ((opt = nextOption()) != null) {
        if (opt.equals("--user")) {
            userId = parseUserArg(nextArgRequired());
        } else {
            System.err.println("Error: Unknown option: " + opt);
            return;
        }
    }
    String packageName = nextArgRequired();
    String value = nextArgRequired();
    IUsageStatsManager usm = IUsageStatsManager.Stub.asInterface(ServiceManager.getService(Context.USAGE_STATS_SERVICE));
    usm.setAppInactive(packageName, Boolean.parseBoolean(value), userId);
}
Also used : IUsageStatsManager(android.app.usage.IUsageStatsManager)

Example 12 with IUsageStatsManager

use of android.app.usage.IUsageStatsManager in project android_frameworks_base by ResurrectionRemix.

the class Am method getRecentConfigurations.

private List<Configuration> getRecentConfigurations(int days) {
    IUsageStatsManager usm = IUsageStatsManager.Stub.asInterface(ServiceManager.getService(Context.USAGE_STATS_SERVICE));
    final long now = System.currentTimeMillis();
    final long nDaysAgo = now - (days * 24 * 60 * 60 * 1000);
    try {
        @SuppressWarnings("unchecked") ParceledListSlice<ConfigurationStats> configStatsSlice = usm.queryConfigurationStats(UsageStatsManager.INTERVAL_BEST, nDaysAgo, now, "com.android.shell");
        if (configStatsSlice == null) {
            return Collections.emptyList();
        }
        final ArrayMap<Configuration, Integer> recentConfigs = new ArrayMap<>();
        final List<ConfigurationStats> configStatsList = configStatsSlice.getList();
        final int configStatsListSize = configStatsList.size();
        for (int i = 0; i < configStatsListSize; i++) {
            final ConfigurationStats stats = configStatsList.get(i);
            final int indexOfKey = recentConfigs.indexOfKey(stats.getConfiguration());
            if (indexOfKey < 0) {
                recentConfigs.put(stats.getConfiguration(), stats.getActivationCount());
            } else {
                recentConfigs.setValueAt(indexOfKey, recentConfigs.valueAt(indexOfKey) + stats.getActivationCount());
            }
        }
        final Comparator<Configuration> comparator = new Comparator<Configuration>() {

            @Override
            public int compare(Configuration a, Configuration b) {
                return recentConfigs.get(b).compareTo(recentConfigs.get(a));
            }
        };
        ArrayList<Configuration> configs = new ArrayList<>(recentConfigs.size());
        configs.addAll(recentConfigs.keySet());
        Collections.sort(configs, comparator);
        return configs;
    } catch (RemoteException e) {
        return Collections.emptyList();
    }
}
Also used : ConfigurationStats(android.app.usage.ConfigurationStats) Configuration(android.content.res.Configuration) ArrayList(java.util.ArrayList) ArrayMap(android.util.ArrayMap) Comparator(java.util.Comparator) IUsageStatsManager(android.app.usage.IUsageStatsManager) RemoteException(android.os.RemoteException)

Example 13 with IUsageStatsManager

use of android.app.usage.IUsageStatsManager in project android_frameworks_base by crdroidandroid.

the class Am method getRecentConfigurations.

private List<Configuration> getRecentConfigurations(int days) {
    IUsageStatsManager usm = IUsageStatsManager.Stub.asInterface(ServiceManager.getService(Context.USAGE_STATS_SERVICE));
    final long now = System.currentTimeMillis();
    final long nDaysAgo = now - (days * 24 * 60 * 60 * 1000);
    try {
        @SuppressWarnings("unchecked") ParceledListSlice<ConfigurationStats> configStatsSlice = usm.queryConfigurationStats(UsageStatsManager.INTERVAL_BEST, nDaysAgo, now, "com.android.shell");
        if (configStatsSlice == null) {
            return Collections.emptyList();
        }
        final ArrayMap<Configuration, Integer> recentConfigs = new ArrayMap<>();
        final List<ConfigurationStats> configStatsList = configStatsSlice.getList();
        final int configStatsListSize = configStatsList.size();
        for (int i = 0; i < configStatsListSize; i++) {
            final ConfigurationStats stats = configStatsList.get(i);
            final int indexOfKey = recentConfigs.indexOfKey(stats.getConfiguration());
            if (indexOfKey < 0) {
                recentConfigs.put(stats.getConfiguration(), stats.getActivationCount());
            } else {
                recentConfigs.setValueAt(indexOfKey, recentConfigs.valueAt(indexOfKey) + stats.getActivationCount());
            }
        }
        final Comparator<Configuration> comparator = new Comparator<Configuration>() {

            @Override
            public int compare(Configuration a, Configuration b) {
                return recentConfigs.get(b).compareTo(recentConfigs.get(a));
            }
        };
        ArrayList<Configuration> configs = new ArrayList<>(recentConfigs.size());
        configs.addAll(recentConfigs.keySet());
        Collections.sort(configs, comparator);
        return configs;
    } catch (RemoteException e) {
        return Collections.emptyList();
    }
}
Also used : ConfigurationStats(android.app.usage.ConfigurationStats) Configuration(android.content.res.Configuration) ArrayList(java.util.ArrayList) ArrayMap(android.util.ArrayMap) Comparator(java.util.Comparator) IUsageStatsManager(android.app.usage.IUsageStatsManager) RemoteException(android.os.RemoteException)

Example 14 with IUsageStatsManager

use of android.app.usage.IUsageStatsManager in project android_frameworks_base by crdroidandroid.

the class Am method runSetInactive.

private void runSetInactive() throws Exception {
    int userId = UserHandle.USER_CURRENT;
    String opt;
    while ((opt = nextOption()) != null) {
        if (opt.equals("--user")) {
            userId = parseUserArg(nextArgRequired());
        } else {
            System.err.println("Error: Unknown option: " + opt);
            return;
        }
    }
    String packageName = nextArgRequired();
    String value = nextArgRequired();
    IUsageStatsManager usm = IUsageStatsManager.Stub.asInterface(ServiceManager.getService(Context.USAGE_STATS_SERVICE));
    usm.setAppInactive(packageName, Boolean.parseBoolean(value), userId);
}
Also used : IUsageStatsManager(android.app.usage.IUsageStatsManager)

Example 15 with IUsageStatsManager

use of android.app.usage.IUsageStatsManager in project android_frameworks_base by crdroidandroid.

the class Am method runGetInactive.

private void runGetInactive() throws Exception {
    int userId = UserHandle.USER_CURRENT;
    String opt;
    while ((opt = nextOption()) != null) {
        if (opt.equals("--user")) {
            userId = parseUserArg(nextArgRequired());
        } else {
            System.err.println("Error: Unknown option: " + opt);
            return;
        }
    }
    String packageName = nextArgRequired();
    IUsageStatsManager usm = IUsageStatsManager.Stub.asInterface(ServiceManager.getService(Context.USAGE_STATS_SERVICE));
    boolean isIdle = usm.isAppInactive(packageName, userId);
    System.out.println("Idle=" + isIdle);
}
Also used : IUsageStatsManager(android.app.usage.IUsageStatsManager)

Aggregations

IUsageStatsManager (android.app.usage.IUsageStatsManager)15 ConfigurationStats (android.app.usage.ConfigurationStats)5 Configuration (android.content.res.Configuration)5 RemoteException (android.os.RemoteException)5 ArrayMap (android.util.ArrayMap)5 ArrayList (java.util.ArrayList)5 Comparator (java.util.Comparator)5