Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8d224caf authored by Peter Visontay's avatar Peter Visontay
Browse files

ActivityManager exposes launch count API.

Bug: 3431684
Change-Id: I49d4fb0b1620aafaf251d77700bc017859328968
parent 2fad6162
Loading
Loading
Loading
Loading
+31 −0
Original line number Diff line number Diff line
@@ -30,11 +30,17 @@ import android.os.RemoteException;
import android.os.Handler;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.ServiceManager;
import android.os.SystemProperties;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.util.Log;
import com.android.internal.app.IUsageStats;
import com.android.internal.os.PkgUsageStats;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Interact with the overall activities running in the system.
@@ -1233,4 +1239,29 @@ public class ActivityManager {
    public static boolean isRunningInTestHarness() {
        return SystemProperties.getBoolean("ro.test_harness", false);
    }

    /**
     * Returns the launch count of each installed package.
     *
     * @hide
     */
    public Map<String, Integer> getAllPackageLaunchCounts() {
        try {
            IUsageStats usageStatsService = IUsageStats.Stub.asInterface(
                    ServiceManager.getService("usagestats"));
            if (usageStatsService == null) {
                return new HashMap<String, Integer>();
            }

            Map<String, Integer> launchCounts = new HashMap<String, Integer>();
            for (PkgUsageStats pkgUsageStats : usageStatsService.getAllPkgUsageStats()) {
                launchCounts.put(pkgUsageStats.packageName, pkgUsageStats.launchCount);
            }

            return launchCounts;
        } catch (RemoteException e) {
            Log.w(TAG, "Could not query launch counts", e);
            return new HashMap<String, Integer>();
        }
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -1196,7 +1196,7 @@
    <permission android:name="android.permission.PACKAGE_USAGE_STATS"
        android:label="@string/permlab_pkgUsageStats"
        android:description="@string/permdesc_pkgUsageStats"
        android:protectionLevel="signature" />
        android:protectionLevel="signatureOrSystem" />

    <!-- Allows an application to collect battery statistics -->
    <permission android:name="android.permission.BATTERY_STATS"