/**
  * Returns the usage statistics of each installed package.
  *
  * @hide
  */
 public PkgUsageStats[] getAllPackageUsageStats() {
   try {
     IUsageStats usageStatsService =
         IUsageStats.Stub.asInterface(ServiceManager.getService("usagestats"));
     if (usageStatsService != null) {
       return usageStatsService.getAllPkgUsageStats();
     }
   } catch (RemoteException e) {
     Log.w(TAG, "Could not query usage stats", e);
   }
   return new PkgUsageStats[0];
 }
  /**
   * 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>();
      }

      PkgUsageStats[] allPkgUsageStats = usageStatsService.getAllPkgUsageStats();
      if (allPkgUsageStats == null) {
        return new HashMap<String, Integer>();
      }

      Map<String, Integer> launchCounts = new HashMap<String, Integer>();
      for (PkgUsageStats pkgUsageStats : allPkgUsageStats) {
        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>();
    }
  }