private void writeToEventLog() { 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); } final int resultAndFlags = (mResult & 0xff) | ((packageManagerInstallResultByte & 0xff) << 8) | ((mFlags & 0xffff) << 16); // Total elapsed time from start to end, in milliseconds. final int totalElapsedTime = clipUnsignedLongToUnsignedInt(mEndTimestampMillis - mStartTimestampMillis); // Total elapsed time from start till information about the package being installed was // obtained, in milliseconds. final int elapsedTimeTillPackageInfoObtained = (isPackageInfoObtained()) ? clipUnsignedLongToUnsignedInt( mPackageInfoObtainedTimestampMillis - mStartTimestampMillis) : 0; // Total elapsed time from start till Install button clicked, in milliseconds // milliseconds. final int elapsedTimeTillInstallButtonClick = (isInstallButtonClicked()) ? clipUnsignedLongToUnsignedInt( mInstallButtonClickTimestampMillis - mStartTimestampMillis) : 0; // If this user has consented to app verification, augment the logged event with the hash of // the contents of the APK. if (((mFlags & FLAG_FILE_URI) != 0) && ((mFlags & FLAG_VERIFY_APPS_ENABLED) != 0) && (isUserConsentToVerifyAppsGranted())) { // Log the hash of the APK's contents. // Reading the APK may take a while -- perform in background. AsyncTask.THREAD_POOL_EXECUTOR.execute( new Runnable() { @Override public void run() { byte[] digest = null; try { digest = getPackageContentsDigest(); } catch (IOException e) { Log.w(TAG, "Failed to hash APK contents", e); } finally { String digestHex = (digest != null) ? IntegralToString.bytesToHexString(digest, false) : ""; EventLogTags.writeInstallPackageAttempt( resultAndFlags, totalElapsedTime, elapsedTimeTillPackageInfoObtained, elapsedTimeTillInstallButtonClick, digestHex); } } }); } else { // Do not log the hash of the APK's contents EventLogTags.writeInstallPackageAttempt( resultAndFlags, totalElapsedTime, elapsedTimeTillPackageInfoObtained, elapsedTimeTillInstallButtonClick, ""); } mLogged = true; if (Log.isLoggable(TAG, Log.VERBOSE)) { Log.v( TAG, "Analytics:" + "\n\tinstallsFromUnknownSourcesPermitted: " + isInstallsFromUnknownSourcesPermitted() + "\n\tinstallRequestFromUnknownSource: " + isInstallRequestFromUnknownSource() + "\n\tverifyAppsEnabled: " + isVerifyAppsEnabled() + "\n\tappVerifierInstalled: " + isAppVerifierInstalled() + "\n\tfileUri: " + isFileUri() + "\n\treplace: " + isReplace() + "\n\tsystemApp: " + isSystemApp() + "\n\tpackageInfoObtained: " + isPackageInfoObtained() + "\n\tinstallButtonClicked: " + isInstallButtonClicked() + "\n\tpermissionsDisplayed: " + isPermissionsDisplayed() + "\n\tnewPermissionsDisplayed: " + isNewPermissionsDisplayed() + "\n\tallPermissionsDisplayed: " + isAllPermissionsDisplayed() + "\n\tnewPermissionsFound: " + isNewPermissionsFound() + "\n\tresult: " + mResult + "\n\tpackageManagerInstallResult: " + mPackageManagerInstallResult + "\n\ttotalDuration: " + (mEndTimestampMillis - mStartTimestampMillis) + " ms" + "\n\ttimeTillPackageInfoObtained: " + ((isPackageInfoObtained()) ? ((mPackageInfoObtainedTimestampMillis - mStartTimestampMillis) + " ms") : "n/a") + "\n\ttimeTillInstallButtonClick: " + ((isInstallButtonClicked()) ? ((mInstallButtonClickTimestampMillis - mStartTimestampMillis) + " ms") : "n/a")); Log.v( TAG, "Wrote to Event Log: 0x" + Long.toString(resultAndFlags & 0xffffffffL, 16) + ", " + totalElapsedTime + ", " + elapsedTimeTillPackageInfoObtained + ", " + elapsedTimeTillInstallButtonClick); } }