Merge change 7854 into donut
* changes: Issue #1884058 (Need to only record frequency and duration for selected Google apps)
This commit is contained in:
@@ -2508,10 +2508,16 @@ public final class Settings {
|
|||||||
public static final String CHECKIN_EVENTS = "checkin_events";
|
public static final String CHECKIN_EVENTS = "checkin_events";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Event tags for list of services to upload during checkin.
|
* Comma-separated list of service names to dump and upload during checkin.
|
||||||
*/
|
*/
|
||||||
public static final String CHECKIN_DUMPSYS_LIST = "checkin_dumpsys_list";
|
public static final String CHECKIN_DUMPSYS_LIST = "checkin_dumpsys_list";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Comma-separated list of packages to specify for each service that is
|
||||||
|
* dumped (currently only meaningful for user activity).
|
||||||
|
*/
|
||||||
|
public static final String CHECKIN_PACKAGE_LIST = "checkin_package_list";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The interval (in seconds) between periodic checkin attempts.
|
* The interval (in seconds) between periodic checkin attempts.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@@ -617,7 +618,7 @@ public final class UsageStatsService extends IUsageStats.Stub {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void collectDumpInfoFLOCK(PrintWriter pw, boolean isCompactOutput,
|
private void collectDumpInfoFLOCK(PrintWriter pw, boolean isCompactOutput,
|
||||||
boolean deleteAfterPrint) {
|
boolean deleteAfterPrint, HashSet<String> packages) {
|
||||||
List<String> fileList = getUsageStatsFileListFLOCK();
|
List<String> fileList = getUsageStatsFileListFLOCK();
|
||||||
if (fileList == null) {
|
if (fileList == null) {
|
||||||
return;
|
return;
|
||||||
@@ -633,7 +634,8 @@ public final class UsageStatsService extends IUsageStats.Stub {
|
|||||||
String dateStr = file.substring(FILE_PREFIX.length());
|
String dateStr = file.substring(FILE_PREFIX.length());
|
||||||
try {
|
try {
|
||||||
Parcel in = getParcelForFile(dFile);
|
Parcel in = getParcelForFile(dFile);
|
||||||
collectDumpInfoFromParcelFLOCK(in, pw, dateStr, isCompactOutput);
|
collectDumpInfoFromParcelFLOCK(in, pw, dateStr, isCompactOutput,
|
||||||
|
packages);
|
||||||
if (deleteAfterPrint) {
|
if (deleteAfterPrint) {
|
||||||
// Delete old file after collecting info only for checkin requests
|
// Delete old file after collecting info only for checkin requests
|
||||||
dFile.delete();
|
dFile.delete();
|
||||||
@@ -648,7 +650,7 @@ public final class UsageStatsService extends IUsageStats.Stub {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void collectDumpInfoFromParcelFLOCK(Parcel in, PrintWriter pw,
|
private void collectDumpInfoFromParcelFLOCK(Parcel in, PrintWriter pw,
|
||||||
String date, boolean isCompactOutput) {
|
String date, boolean isCompactOutput, HashSet<String> packages) {
|
||||||
StringBuilder sb = new StringBuilder(512);
|
StringBuilder sb = new StringBuilder(512);
|
||||||
if (isCompactOutput) {
|
if (isCompactOutput) {
|
||||||
sb.append("D:");
|
sb.append("D:");
|
||||||
@@ -678,7 +680,10 @@ public final class UsageStatsService extends IUsageStats.Stub {
|
|||||||
}
|
}
|
||||||
sb.setLength(0);
|
sb.setLength(0);
|
||||||
PkgUsageStatsExtended pus = new PkgUsageStatsExtended(in);
|
PkgUsageStatsExtended pus = new PkgUsageStatsExtended(in);
|
||||||
if (isCompactOutput) {
|
if (packages != null && !packages.contains(pkgName)) {
|
||||||
|
// This package has not been requested -- don't print
|
||||||
|
// anything for it.
|
||||||
|
} else if (isCompactOutput) {
|
||||||
sb.append("P:");
|
sb.append("P:");
|
||||||
sb.append(pkgName);
|
sb.append(pkgName);
|
||||||
sb.append(',');
|
sb.append(',');
|
||||||
@@ -765,6 +770,25 @@ public final class UsageStatsService extends IUsageStats.Stub {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Searches array of arguments for the specified string's data
|
||||||
|
* @param args array of argument strings
|
||||||
|
* @param value value to search for
|
||||||
|
* @return the string of data after the arg, or null if there is none
|
||||||
|
*/
|
||||||
|
private static String scanArgsData(String[] args, String value) {
|
||||||
|
if (args != null) {
|
||||||
|
final int N = args.length;
|
||||||
|
for (int i=0; i<N; i++) {
|
||||||
|
if (value.equals(args[i])) {
|
||||||
|
i++;
|
||||||
|
return i < N ? args[i] : null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
/*
|
/*
|
||||||
* The data persisted to file is parsed and the stats are computed.
|
* The data persisted to file is parsed and the stats are computed.
|
||||||
@@ -773,6 +797,7 @@ public final class UsageStatsService extends IUsageStats.Stub {
|
|||||||
final boolean isCheckinRequest = scanArgs(args, "--checkin");
|
final boolean isCheckinRequest = scanArgs(args, "--checkin");
|
||||||
final boolean isCompactOutput = isCheckinRequest || scanArgs(args, "-c");
|
final boolean isCompactOutput = isCheckinRequest || scanArgs(args, "-c");
|
||||||
final boolean deleteAfterPrint = isCheckinRequest || scanArgs(args, "-d");
|
final boolean deleteAfterPrint = isCheckinRequest || scanArgs(args, "-d");
|
||||||
|
final String rawPackages = scanArgsData(args, "--packages");
|
||||||
|
|
||||||
// Make sure the current stats are written to the file. This
|
// Make sure the current stats are written to the file. This
|
||||||
// doesn't need to be done if we are deleting files after printing,
|
// doesn't need to be done if we are deleting files after printing,
|
||||||
@@ -781,8 +806,27 @@ public final class UsageStatsService extends IUsageStats.Stub {
|
|||||||
writeStatsToFile(true);
|
writeStatsToFile(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
HashSet<String> packages = null;
|
||||||
|
if (rawPackages != null) {
|
||||||
|
if (!"*".equals(rawPackages)) {
|
||||||
|
// A * is a wildcard to show all packages.
|
||||||
|
String[] names = rawPackages.split(",");
|
||||||
|
for (String n : names) {
|
||||||
|
if (packages == null) {
|
||||||
|
packages = new HashSet<String>();
|
||||||
|
}
|
||||||
|
packages.add(n);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (isCheckinRequest) {
|
||||||
|
// If checkin doesn't specify any packages, then we simply won't
|
||||||
|
// show anything.
|
||||||
|
Log.w(TAG, "Checkin without packages");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
synchronized (mFileLock) {
|
synchronized (mFileLock) {
|
||||||
collectDumpInfoFLOCK(pw, isCompactOutput, deleteAfterPrint);
|
collectDumpInfoFLOCK(pw, isCompactOutput, deleteAfterPrint, packages);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user