Loading core/java/android/app/usage/UsageEvents.java +1 −3 Original line number Diff line number Diff line Loading @@ -106,9 +106,7 @@ public final class UsageEvents implements Parcelable { } /** * The time at which this event occurred, measured in milliseconds since the epoch. * <p/> * See {@link System#currentTimeMillis()}. * The time at which this event occurred. */ public long getTimeStamp() { return mTimeStamp; Loading core/java/android/app/usage/UsageStats.java +4 −12 Original line number Diff line number Diff line Loading @@ -81,36 +81,28 @@ public final class UsageStats implements Parcelable { } /** * Get the beginning of the time range this {@link android.app.usage.UsageStats} represents, * measured in milliseconds since the epoch. * <p/> * See {@link System#currentTimeMillis()}. * Get the beginning of the time range this {@link android.app.usage.UsageStats} represents. */ public long getFirstTimeStamp() { return mBeginTimeStamp; } /** * Get the end of the time range this {@link android.app.usage.UsageStats} represents, * measured in milliseconds since the epoch. * <p/> * See {@link System#currentTimeMillis()}. * Get the end of the time range this {@link android.app.usage.UsageStats} represents. */ public long getLastTimeStamp() { return mEndTimeStamp; } /** * Get the last time this package was used, measured in milliseconds since the epoch. * <p/> * See {@link System#currentTimeMillis()}. * Get the last time this package was used. */ public long getLastTimeUsed() { return mLastTimeUsed; } /** * Get the total time this package spent in the foreground, measured in milliseconds. * Get the total time this package spent in the foreground. */ public long getTotalTimeInForeground() { return mTotalTimeInForeground; Loading core/java/android/app/usage/UsageStatsManager.java +6 −4 Original line number Diff line number Diff line Loading @@ -23,7 +23,6 @@ import android.util.ArrayMap; import java.util.Collections; import java.util.List; import java.util.Map; /** * Provides access to device usage history and statistics. Usage data is aggregated into Loading Loading @@ -150,6 +149,7 @@ public final class UsageStatsManager { * @param endTime The exclusive end of the range of events to include in the results. * @return A {@link UsageEvents}. */ @SuppressWarnings("unchecked") public UsageEvents queryEvents(long beginTime, long endTime) { try { UsageEvents iter = mService.queryEvents(beginTime, endTime, Loading @@ -170,13 +170,15 @@ public final class UsageStatsManager { * * @param beginTime The inclusive beginning of the range of stats to include in the results. * @param endTime The exclusive end of the range of stats to include in the results. * @return A {@link java.util.Map} keyed by package name, or null if no stats are * @return An {@link android.util.ArrayMap} keyed by package name or null if no stats are * available. */ public Map<String, UsageStats> queryAndAggregateUsageStats(long beginTime, long endTime) { public ArrayMap<String, UsageStats> queryAndAggregateUsageStats(long beginTime, long endTime) { List<UsageStats> stats = queryUsageStats(INTERVAL_BEST, beginTime, endTime); if (stats.isEmpty()) { return Collections.emptyMap(); @SuppressWarnings("unchecked") ArrayMap<String, UsageStats> emptyStats = ArrayMap.EMPTY; return emptyStats; } ArrayMap<String, UsageStats> aggregatedStats = new ArrayMap<>(); Loading core/java/com/android/internal/app/ResolverActivity.java +2 −2 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ import android.app.usage.UsageStatsManager; import android.os.AsyncTask; import android.provider.Settings; import android.text.TextUtils; import android.util.ArrayMap; import android.util.Slog; import android.widget.AbsListView; import android.widget.GridView; Loading Loading @@ -72,7 +73,6 @@ import java.util.Comparator; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; /** Loading Loading @@ -100,7 +100,7 @@ public class ResolverActivity extends Activity implements AdapterView.OnItemClic private boolean mResolvingHome = false; private UsageStatsManager mUsm; private Map<String, UsageStats> mStats; private ArrayMap<String, UsageStats> mStats; private static final long USAGE_STATS_PERIOD = 1000 * 60 * 60 * 24 * 14; private boolean mRegistered; Loading tests/UsageStatsTest/src/com/android/tests/usagestats/UsageStatsActivity.java +8 −4 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.text.format.DateUtils; import android.util.ArrayMap; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuInflater; Loading @@ -35,7 +36,6 @@ import android.widget.TextView; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.Map; public class UsageStatsActivity extends ListActivity { private static final long USAGE_STATS_PERIOD = 1000 * 60 * 60 * 24 * 14; Loading Loading @@ -84,7 +84,7 @@ public class UsageStatsActivity extends ListActivity { private void updateAdapter() { long now = System.currentTimeMillis(); long beginTime = now - USAGE_STATS_PERIOD; Map<String, UsageStats> stats = mUsageStatsManager.queryAndAggregateUsageStats( ArrayMap<String, UsageStats> stats = mUsageStatsManager.queryAndAggregateUsageStats( beginTime, now); mAdapter.update(stats); } Loading @@ -92,13 +92,17 @@ public class UsageStatsActivity extends ListActivity { private class Adapter extends BaseAdapter { private ArrayList<UsageStats> mStats = new ArrayList<>(); public void update(Map<String, UsageStats> stats) { public void update(ArrayMap<String, UsageStats> stats) { mStats.clear(); if (stats == null) { return; } mStats.addAll(stats.values()); final int packageCount = stats.size(); for (int i = 0; i < packageCount; i++) { mStats.add(stats.valueAt(i)); } Collections.sort(mStats, mComparator); notifyDataSetChanged(); } Loading Loading
core/java/android/app/usage/UsageEvents.java +1 −3 Original line number Diff line number Diff line Loading @@ -106,9 +106,7 @@ public final class UsageEvents implements Parcelable { } /** * The time at which this event occurred, measured in milliseconds since the epoch. * <p/> * See {@link System#currentTimeMillis()}. * The time at which this event occurred. */ public long getTimeStamp() { return mTimeStamp; Loading
core/java/android/app/usage/UsageStats.java +4 −12 Original line number Diff line number Diff line Loading @@ -81,36 +81,28 @@ public final class UsageStats implements Parcelable { } /** * Get the beginning of the time range this {@link android.app.usage.UsageStats} represents, * measured in milliseconds since the epoch. * <p/> * See {@link System#currentTimeMillis()}. * Get the beginning of the time range this {@link android.app.usage.UsageStats} represents. */ public long getFirstTimeStamp() { return mBeginTimeStamp; } /** * Get the end of the time range this {@link android.app.usage.UsageStats} represents, * measured in milliseconds since the epoch. * <p/> * See {@link System#currentTimeMillis()}. * Get the end of the time range this {@link android.app.usage.UsageStats} represents. */ public long getLastTimeStamp() { return mEndTimeStamp; } /** * Get the last time this package was used, measured in milliseconds since the epoch. * <p/> * See {@link System#currentTimeMillis()}. * Get the last time this package was used. */ public long getLastTimeUsed() { return mLastTimeUsed; } /** * Get the total time this package spent in the foreground, measured in milliseconds. * Get the total time this package spent in the foreground. */ public long getTotalTimeInForeground() { return mTotalTimeInForeground; Loading
core/java/android/app/usage/UsageStatsManager.java +6 −4 Original line number Diff line number Diff line Loading @@ -23,7 +23,6 @@ import android.util.ArrayMap; import java.util.Collections; import java.util.List; import java.util.Map; /** * Provides access to device usage history and statistics. Usage data is aggregated into Loading Loading @@ -150,6 +149,7 @@ public final class UsageStatsManager { * @param endTime The exclusive end of the range of events to include in the results. * @return A {@link UsageEvents}. */ @SuppressWarnings("unchecked") public UsageEvents queryEvents(long beginTime, long endTime) { try { UsageEvents iter = mService.queryEvents(beginTime, endTime, Loading @@ -170,13 +170,15 @@ public final class UsageStatsManager { * * @param beginTime The inclusive beginning of the range of stats to include in the results. * @param endTime The exclusive end of the range of stats to include in the results. * @return A {@link java.util.Map} keyed by package name, or null if no stats are * @return An {@link android.util.ArrayMap} keyed by package name or null if no stats are * available. */ public Map<String, UsageStats> queryAndAggregateUsageStats(long beginTime, long endTime) { public ArrayMap<String, UsageStats> queryAndAggregateUsageStats(long beginTime, long endTime) { List<UsageStats> stats = queryUsageStats(INTERVAL_BEST, beginTime, endTime); if (stats.isEmpty()) { return Collections.emptyMap(); @SuppressWarnings("unchecked") ArrayMap<String, UsageStats> emptyStats = ArrayMap.EMPTY; return emptyStats; } ArrayMap<String, UsageStats> aggregatedStats = new ArrayMap<>(); Loading
core/java/com/android/internal/app/ResolverActivity.java +2 −2 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ import android.app.usage.UsageStatsManager; import android.os.AsyncTask; import android.provider.Settings; import android.text.TextUtils; import android.util.ArrayMap; import android.util.Slog; import android.widget.AbsListView; import android.widget.GridView; Loading Loading @@ -72,7 +73,6 @@ import java.util.Comparator; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; /** Loading Loading @@ -100,7 +100,7 @@ public class ResolverActivity extends Activity implements AdapterView.OnItemClic private boolean mResolvingHome = false; private UsageStatsManager mUsm; private Map<String, UsageStats> mStats; private ArrayMap<String, UsageStats> mStats; private static final long USAGE_STATS_PERIOD = 1000 * 60 * 60 * 24 * 14; private boolean mRegistered; Loading
tests/UsageStatsTest/src/com/android/tests/usagestats/UsageStatsActivity.java +8 −4 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.text.format.DateUtils; import android.util.ArrayMap; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuInflater; Loading @@ -35,7 +36,6 @@ import android.widget.TextView; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.Map; public class UsageStatsActivity extends ListActivity { private static final long USAGE_STATS_PERIOD = 1000 * 60 * 60 * 24 * 14; Loading Loading @@ -84,7 +84,7 @@ public class UsageStatsActivity extends ListActivity { private void updateAdapter() { long now = System.currentTimeMillis(); long beginTime = now - USAGE_STATS_PERIOD; Map<String, UsageStats> stats = mUsageStatsManager.queryAndAggregateUsageStats( ArrayMap<String, UsageStats> stats = mUsageStatsManager.queryAndAggregateUsageStats( beginTime, now); mAdapter.update(stats); } Loading @@ -92,13 +92,17 @@ public class UsageStatsActivity extends ListActivity { private class Adapter extends BaseAdapter { private ArrayList<UsageStats> mStats = new ArrayList<>(); public void update(Map<String, UsageStats> stats) { public void update(ArrayMap<String, UsageStats> stats) { mStats.clear(); if (stats == null) { return; } mStats.addAll(stats.values()); final int packageCount = stats.size(); for (int i = 0; i < packageCount; i++) { mStats.add(stats.valueAt(i)); } Collections.sort(mStats, mComparator); notifyDataSetChanged(); } Loading