summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Klyubin <klyubin@google.com>2013-09-10 14:13:15 -0700
committerAlex Klyubin <klyubin@google.com>2013-09-10 14:24:41 -0700
commit3e9a765ff5e6ab74bed605c86fcf53b6581b9060 (patch)
tree2a25bc65563c85c08c27019b2bfe7353b726176c
parent71510286b8ed1d116b0cf234254dcbd8316ff751 (diff)
downloadandroid_packages_apps_PackageInstaller-3e9a765ff5e6ab74bed605c86fcf53b6581b9060.zip
android_packages_apps_PackageInstaller-3e9a765ff5e6ab74bed605c86fcf53b6581b9060.tar.gz
android_packages_apps_PackageInstaller-3e9a765ff5e6ab74bed605c86fcf53b6581b9060.tar.bz2
Robustify logging of analytics about PackageInstaller.
This CL switches from the type-unsafe EventLog.writeEvent method to the strictly-typed EventLogTags.writeInstallPackageAttempt. This method is generated from the definition of this event in EventLogTags.logtags and thus offers compile-time type checking. Bug: 10605940 Change-Id: I62895b60fe4c01d4314eba564476e0f1ed7ad78b
-rw-r--r--src/com/android/packageinstaller/EventLogTags.logtags2
-rw-r--r--src/com/android/packageinstaller/InstallFlowAnalytics.java105
2 files changed, 42 insertions, 65 deletions
diff --git a/src/com/android/packageinstaller/EventLogTags.logtags b/src/com/android/packageinstaller/EventLogTags.logtags
index 5cb5d91..0183148 100644
--- a/src/com/android/packageinstaller/EventLogTags.logtags
+++ b/src/com/android/packageinstaller/EventLogTags.logtags
@@ -3,4 +3,4 @@
option java_package com.android.packageinstaller
# APK install attempt via PackageInstaller (see InstallFlowAnalytics for format)
-90300 install_package_attempt (type|4)
+90300 install_package_attempt (result_and_flags|1),(total_time|1|3),(time_till_pkg_info_obtained|1|3),(time_till_install_clicked|1|3)
diff --git a/src/com/android/packageinstaller/InstallFlowAnalytics.java b/src/com/android/packageinstaller/InstallFlowAnalytics.java
index 8fc805a..ac8e53a 100644
--- a/src/com/android/packageinstaller/InstallFlowAnalytics.java
+++ b/src/com/android/packageinstaller/InstallFlowAnalytics.java
@@ -115,7 +115,7 @@ public class InstallFlowAnalytics implements Parcelable {
/**
* Time instant when the user clicked the Install button, measured in elapsed realtime
* milliseconds. See {@link SystemClock#elapsedRealtime()}. This field is only valid if the
- * Install button has been clicked as recorded in {@link #mInstallButtonClicked}.
+ * Install button has been clicked, as signaled by {@link #FLAG_INSTALL_BUTTON_CLICKED}.
*/
private long mInstallButtonClickTimestampMillis;
@@ -385,12 +385,45 @@ public class InstallFlowAnalytics implements Parcelable {
}
private void writeToEventLog() {
- Object[] value = getEventLogEventValue();
- EventLog.writeEvent(EventLogTags.INSTALL_PACKAGE_ATTEMPT, value);
+ byte packageManagerInstallResultByte = 0;
+ if (mResult == RESULT_PACKAGE_MANAGER_INSTALL_FAILED) {
+ // PackageManager install error codes are negative, starting from -1 and going to
+ // -111 (at the moment). We thus store them in negated form.
+ packageManagerInstallResultByte = clipUnsignedValueToUnsignedByte(
+ -mPackageManagerInstallResult);
+ }
+
+ int resultAndFlags = (mResult & 0xff)
+ | ((packageManagerInstallResultByte & 0xff) << 8)
+ | ((mFlags & 0xffff) << 16);
+
+ // Total elapsed time from start to end, in milliseconds.
+ int totalElapsedTime =
+ clipUnsignedLongToUnsignedInt(mEndTimestampMillis - mStartTimestampMillis);
+
+ // Total elapsed time from start till information about the package being installed was
+ // obtained, in milliseconds.
+ int elapsedTimeTillPackageInfoObtained = (isPackageInfoObtained())
+ ? clipUnsignedLongToUnsignedInt(
+ mPackageInfoObtainedTimestampMillis - mStartTimestampMillis)
+ : 0;
+
+ // Total elapsed time from start till Install button clicked, in milliseconds
+ // milliseconds.
+ int elapsedTimeTillInstallButtonClick = (isInstallButtonClicked())
+ ? clipUnsignedLongToUnsignedInt(
+ mInstallButtonClickTimestampMillis - mStartTimestampMillis)
+ : 0;
+
+ EventLogTags.writeInstallPackageAttempt(
+ resultAndFlags,
+ totalElapsedTime,
+ elapsedTimeTillPackageInfoObtained,
+ elapsedTimeTillInstallButtonClick);
mLogged = true;
if (Log.isLoggable(TAG, Log.VERBOSE)) {
- Log.v(TAG, "Aalytics:"
+ Log.v(TAG, "Analytics:"
+ "\n\tinstallsFromUnknownSourcesPermitted: "
+ isInstallsFromUnknownSourcesPermitted()
+ "\n\tinstallRequestFromUnknownSource: " + isInstallRequestFromUnknownSource()
@@ -417,67 +450,11 @@ public class InstallFlowAnalytics implements Parcelable {
+ ((isInstallButtonClicked())
? ((mInstallButtonClickTimestampMillis - mStartTimestampMillis) + " ms")
: "n/a"));
- StringBuilder dump = new StringBuilder();
- for (Object element : value) {
- if (dump.length() > 0) {
- dump.append(", ");
- }
- if (element instanceof Integer) {
- dump.append("0x")
- .append(Long.toString(((Integer) element) & 0xffffffffL, 16));
- } else {
- dump.append(element);
- }
- }
- Log.v(TAG, "Wrote to Event Log: " + dump);
- }
- }
-
- private Object[] getEventLogEventValue() {
- // IMPLEMENTATION NOTE: Analytics are packed into the following list:
- // * 32-bit int (ordered from least significant to most significant bits):
- // * 1 byte: outcome of the flow (see RESULT_... constants)
- // * 1 byte: PackageManager install error code (negated) or 0 if it didn't run
- // * 2 bytes: flags (see FLAG_... constants)
- // * 32-bit unsigned int: total elapsed time (milliseconds)
- // * 32-bit unsigned int: time elapsed from start till information about the package being
- // installed was obtained (milliseconds)
- // * 32-bit unsigned int: time elapsed from start till Install button click (milliseconds)
-
- byte packageManagerInstallResultByte = 0;
- if (mResult == RESULT_PACKAGE_MANAGER_INSTALL_FAILED) {
- // PackageManager install error codes are negative, starting from -1 and going to
- // -111 (at the moment). We thus store them in negated form.
- packageManagerInstallResultByte = clipUnsignedValueToUnsignedByte(
- -mPackageManagerInstallResult);
+ Log.v(TAG, "Wrote to Event Log: 0x" + Long.toString(resultAndFlags & 0xffffffffL, 16)
+ + ", " + totalElapsedTime
+ + ", " + elapsedTimeTillPackageInfoObtained
+ + ", " + elapsedTimeTillInstallButtonClick);
}
-
- // Total elapsed time from start to end, in milliseconds.
- int totalElapsedTime =
- clipUnsignedLongToUnsignedInt(mEndTimestampMillis - mStartTimestampMillis);
-
- // Total elapsed time from start till information about the package being installed was
- // obtained, in milliseconds.
- int elapsedTimeTillPackageInfoObtained = (isPackageInfoObtained())
- ? clipUnsignedLongToUnsignedInt(
- mPackageInfoObtainedTimestampMillis - mStartTimestampMillis)
- : 0;
-
- // Total elapsed time from start till Install button clicked, in milliseconds
- // milliseconds.
- int elapsedTimeTillInstallButtonClick = (isInstallButtonClicked())
- ? clipUnsignedLongToUnsignedInt(
- mInstallButtonClickTimestampMillis - mStartTimestampMillis)
- : 0;
-
- return new Object[] {
- (int) ((mResult & 0xff)
- | ((packageManagerInstallResultByte & 0xff) << 8)
- | ((mFlags & 0xffffL) << 16)),
- totalElapsedTime,
- elapsedTimeTillPackageInfoObtained,
- elapsedTimeTillInstallButtonClick,
- };
}
private static final byte clipUnsignedValueToUnsignedByte(long value) {