diff options
author | Adam Lesinski <adamlesinski@google.com> | 2014-09-09 17:28:03 -0700 |
---|---|---|
committer | Adam Lesinski <adamlesinski@google.com> | 2014-09-10 15:02:59 -0700 |
commit | 65e76d1200395a9c67893378ddb64c47ede400b4 (patch) | |
tree | 198c2f2a9163870d75453753ccadbca2dc34c7c2 /cmds/am/src/com | |
parent | 05c4f7ad765e2178e6e28676fd3438d2aaa38894 (diff) | |
download | frameworks_base-65e76d1200395a9c67893378ddb64c47ede400b4.zip frameworks_base-65e76d1200395a9c67893378ddb64c47ede400b4.tar.gz frameworks_base-65e76d1200395a9c67893378ddb64c47ede400b4.tar.bz2 |
Output recent configs in am get-config command
Change-Id: Ic516e73d2e72ac0dc3136f7226cedd851fe22b85
Diffstat (limited to 'cmds/am/src/com')
-rw-r--r-- | cmds/am/src/com/android/commands/am/Am.java | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/cmds/am/src/com/android/commands/am/Am.java b/cmds/am/src/com/android/commands/am/Am.java index c06ef0d..989b500 100644 --- a/cmds/am/src/com/android/commands/am/Am.java +++ b/cmds/am/src/com/android/commands/am/Am.java @@ -28,10 +28,15 @@ import android.app.IInstrumentationWatcher; import android.app.Instrumentation; import android.app.ProfilerInfo; import android.app.UiAutomationConnection; +import android.app.usage.ConfigurationStats; +import android.app.usage.IUsageStatsManager; +import android.app.usage.UsageStatsManager; import android.content.ComponentName; +import android.content.Context; import android.content.IIntentReceiver; import android.content.Intent; import android.content.pm.IPackageManager; +import android.content.pm.ParceledListSlice; import android.content.pm.ResolveInfo; import android.content.res.Configuration; import android.graphics.Rect; @@ -47,6 +52,7 @@ import android.os.SystemProperties; import android.os.UserHandle; import android.text.TextUtils; import android.util.AndroidException; +import android.util.ArrayMap; import android.view.IWindowManager; import android.view.View; @@ -61,6 +67,9 @@ import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintStream; import java.net.URISyntaxException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; import java.util.HashSet; import java.util.List; @@ -1722,7 +1731,64 @@ public class Am extends BaseCommand { } } + 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(); + } + } + private void runGetConfig() throws Exception { + int days = 14; + String option = nextOption(); + if (option != null) { + if (!option.equals("--days")) { + throw new IllegalArgumentException("unrecognized option " + option); + } + + days = Integer.parseInt(nextArgRequired()); + if (days <= 0) { + throw new IllegalArgumentException("--days must be a positive integer"); + } + } + try { Configuration config = mAm.getConfiguration(); if (config == null) { @@ -1733,6 +1799,17 @@ public class Am extends BaseCommand { System.out.println("config: " + Configuration.resourceQualifierString(config)); System.out.println("abi: " + TextUtils.join(",", Build.SUPPORTED_ABIS)); + final List<Configuration> recentConfigs = getRecentConfigurations(days); + final int recentConfigSize = recentConfigs.size(); + if (recentConfigSize > 0) { + System.out.println("recentConfigs:"); + } + + for (int i = 0; i < recentConfigSize; i++) { + System.out.println(" config: " + Configuration.resourceQualifierString( + recentConfigs.get(i))); + } + } catch (RemoteException e) { } } |