diff options
author | Todd Kennedy <toddke@google.com> | 2015-10-22 15:22:15 -0700 |
---|---|---|
committer | Todd Kennedy <toddke@google.com> | 2015-10-23 10:03:52 -0700 |
commit | 22d31ce57f956ef2f914179b8a73f64edc885276 (patch) | |
tree | adaca52f7686e605ed564465bf15c63e64360cc3 | |
parent | 714b00201443c541fc9a87fa45fe515b33a34b9e (diff) | |
download | android_packages_apps_PackageInstaller-22d31ce57f956ef2f914179b8a73f64edc885276.tar.gz android_packages_apps_PackageInstaller-22d31ce57f956ef2f914179b8a73f64edc885276.tar.bz2 android_packages_apps_PackageInstaller-22d31ce57f956ef2f914179b8a73f64edc885276.zip |
Remove InstallFlowAnalytics
These were no longer being used and they were broken with a recent change
adjusting the flow of the PackageInstaller.
Bug: 24542039
Change-Id: I14b98dd0f8cdb69d31eab54a3f1b96048263c222
-rw-r--r-- | Android.mk | 3 | ||||
-rw-r--r-- | src/com/android/packageinstaller/EventLogTags.logtags | 6 | ||||
-rwxr-xr-x | src/com/android/packageinstaller/InstallAppProgress.java | 8 | ||||
-rw-r--r-- | src/com/android/packageinstaller/InstallFlowAnalytics.java | 608 | ||||
-rw-r--r-- | src/com/android/packageinstaller/PackageInstallerActivity.java | 83 | ||||
-rw-r--r-- | src/com/android/packageinstaller/TabsAdapter.java | 8 |
6 files changed, 2 insertions, 714 deletions
@@ -4,8 +4,7 @@ include $(CLEAR_VARS) LOCAL_MODULE_TAGS := optional LOCAL_SRC_FILES := \ - $(call all-java-files-under, src) \ - src/com/android/packageinstaller/EventLogTags.logtags + $(call all-java-files-under, src) LOCAL_STATIC_JAVA_LIBRARIES += \ android-support-v4 \ diff --git a/src/com/android/packageinstaller/EventLogTags.logtags b/src/com/android/packageinstaller/EventLogTags.logtags deleted file mode 100644 index 8cbb1ccd..00000000 --- a/src/com/android/packageinstaller/EventLogTags.logtags +++ /dev/null @@ -1,6 +0,0 @@ -# See system/core/logcat/event.logtags for a description of the format of this file. - -option java_package com.android.packageinstaller - -# APK install attempt via PackageInstaller (see InstallFlowAnalytics for format) -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),(package_digest|3) diff --git a/src/com/android/packageinstaller/InstallAppProgress.java b/src/com/android/packageinstaller/InstallAppProgress.java index f0362eb2..9cb1c2c9 100755 --- a/src/com/android/packageinstaller/InstallAppProgress.java +++ b/src/com/android/packageinstaller/InstallAppProgress.java @@ -68,15 +68,12 @@ public class InstallAppProgress extends Activity implements View.OnClickListener private final String TAG="InstallAppProgress"; static final String EXTRA_MANIFEST_DIGEST = "com.android.packageinstaller.extras.manifest_digest"; - static final String EXTRA_INSTALL_FLOW_ANALYTICS = - "com.android.packageinstaller.extras.install_flow_analytics"; private static final String BROADCAST_ACTION = "com.android.packageinstaller.ACTION_INSTALL_COMMIT"; private static final String BROADCAST_SENDER_PERMISSION = "android.permission.INSTALL_PACKAGES"; private ApplicationInfo mAppInfo; private Uri mPackageURI; - private InstallFlowAnalytics mInstallFlowAnalytics; private ProgressBar mProgressBar; private View mOkPanel; private TextView mStatusTextView; @@ -94,7 +91,6 @@ public class InstallAppProgress extends Activity implements View.OnClickListener public void handleMessage(Message msg) { switch (msg.what) { case INSTALL_COMPLETE: - mInstallFlowAnalytics.setFlowFinishedWithPackageManagerResult(msg.arg1); if (getIntent().getBooleanExtra(Intent.EXTRA_RETURN_RESULT, false)) { Intent result = new Intent(); result.putExtra(Intent.EXTRA_INSTALL_RESULT, msg.arg1); @@ -198,14 +194,10 @@ public class InstallAppProgress extends Activity implements View.OnClickListener super.onCreate(icicle); Intent intent = getIntent(); mAppInfo = intent.getParcelableExtra(PackageUtil.INTENT_ATTR_APPLICATION_INFO); - mInstallFlowAnalytics = intent.getParcelableExtra(EXTRA_INSTALL_FLOW_ANALYTICS); - mInstallFlowAnalytics.setContext(this); mPackageURI = intent.getData(); final String scheme = mPackageURI.getScheme(); if (scheme != null && !"file".equals(scheme) && !"package".equals(scheme)) { - mInstallFlowAnalytics.setFlowFinished( - InstallFlowAnalytics.RESULT_FAILED_UNSUPPORTED_SCHEME); throw new IllegalArgumentException("unexpected scheme " + scheme); } diff --git a/src/com/android/packageinstaller/InstallFlowAnalytics.java b/src/com/android/packageinstaller/InstallFlowAnalytics.java deleted file mode 100644 index 4591f31c..00000000 --- a/src/com/android/packageinstaller/InstallFlowAnalytics.java +++ /dev/null @@ -1,608 +0,0 @@ -/* -** -** Copyright 2013, The Android Open Source Project -** -** Licensed under the Apache License, Version 2.0 (the "License"); -** you may not use this file except in compliance with the License. -** You may obtain a copy of the License at -** -** http://www.apache.org/licenses/LICENSE-2.0 -** -** Unless required by applicable law or agreed to in writing, software -** distributed under the License is distributed on an "AS IS" BASIS, -** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -** See the License for the specific language governing permissions and -** limitations under the License. -*/ -package com.android.packageinstaller; - -import android.content.Context; -import android.content.pm.PackageManager; -import android.net.Uri; -import android.os.AsyncTask; -import android.os.Parcel; -import android.os.Parcelable; -import android.os.SystemClock; -import android.provider.Settings; -import android.util.EventLog; -import android.util.Log; - -import java.io.BufferedInputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; - -import libcore.io.IoUtils; - -/** - * Analytics about an attempt to install a package via {@link PackageInstallerActivity}. - * - * <p>An instance of this class is created at the beginning of the install flow and gradually filled - * as the user progresses through the flow. When the flow terminates (regardless of the reason), - * {@link #setFlowFinished(byte)} is invoked which reports the installation attempt as an event - * to the Event Log. - */ -public class InstallFlowAnalytics implements Parcelable { - - private static final String TAG = "InstallFlowAnalytics"; - - /** Installation has not yet terminated. */ - static final byte RESULT_NOT_YET_AVAILABLE = -1; - - /** Package successfully installed. */ - static final byte RESULT_SUCCESS = 0; - - /** Installation failed because scheme unsupported. */ - static final byte RESULT_FAILED_UNSUPPORTED_SCHEME = 1; - - /** - * Installation of an APK failed because of a failure to obtain information from the provided - * APK. - */ - static final byte RESULT_FAILED_TO_GET_PACKAGE_INFO = 2; - - /** - * Installation of an already installed package into the current user profile failed because the - * specified package is not installed. - */ - static final byte RESULT_FAILED_PACKAGE_MISSING = 3; - - /** - * Installation failed because installation from unknown sources is prohibited by the Unknown - * Sources setting. - */ - static final byte RESULT_BLOCKED_BY_UNKNOWN_SOURCES_SETTING = 4; - - /** Installation cancelled by the user. */ - static final byte RESULT_CANCELLED_BY_USER = 5; - - /** - * Installation failed due to {@code PackageManager} failure. PackageManager error code is - * provided in {@link #mPackageManagerInstallResult}). - */ - static final byte RESULT_PACKAGE_MANAGER_INSTALL_FAILED = 6; - - /** - * Installation blocked since this feature is not allowed on Android Wear devices yet. - */ - static final byte RESULT_NOT_ALLOWED_ON_WEAR = 7; - - private static final int FLAG_INSTALLS_FROM_UNKNOWN_SOURCES_PERMITTED = 1 << 0; - private static final int FLAG_INSTALL_REQUEST_FROM_UNKNOWN_SOURCE = 1 << 1; - private static final int FLAG_VERIFY_APPS_ENABLED = 1 << 2; - private static final int FLAG_APP_VERIFIER_INSTALLED = 1 << 3; - private static final int FLAG_FILE_URI = 1 << 4; - private static final int FLAG_REPLACE = 1 << 5; - private static final int FLAG_SYSTEM_APP = 1 << 6; - private static final int FLAG_PACKAGE_INFO_OBTAINED = 1 << 7; - private static final int FLAG_INSTALL_BUTTON_CLICKED = 1 << 8; - private static final int FLAG_NEW_PERMISSIONS_FOUND = 1 << 9; - private static final int FLAG_PERMISSIONS_DISPLAYED = 1 << 10; - private static final int FLAG_NEW_PERMISSIONS_DISPLAYED = 1 << 11; - private static final int FLAG_ALL_PERMISSIONS_DISPLAYED = 1 << 12; - - /** - * Information about this flow expressed as a collection of flags. See {@code FLAG_...} - * constants. - */ - private int mFlags; - - /** Outcome of the flow. See {@code RESULT_...} constants. */ - private byte mResult = RESULT_NOT_YET_AVAILABLE; - - /** - * Result code returned by {@code PackageManager} to install the package or {@code 0} if - * {@code PackageManager} has not yet been invoked to install the package. - */ - private int mPackageManagerInstallResult; - - /** - * Time instant when the installation request arrived, measured in elapsed realtime - * milliseconds. See {@link SystemClock#elapsedRealtime()}. - */ - private long mStartTimestampMillis; - - /** - * Time instant when the information about the package being installed was obtained, measured in - * elapsed realtime milliseconds. See {@link SystemClock#elapsedRealtime()}. - */ - private long mPackageInfoObtainedTimestampMillis; - - /** - * 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 signaled by {@link #FLAG_INSTALL_BUTTON_CLICKED}. - */ - private long mInstallButtonClickTimestampMillis; - - /** - * Time instant when this flow terminated, measured in elapsed realtime milliseconds. See - * {@link SystemClock#elapsedRealtime()}. - */ - private long mEndTimestampMillis; - - /** URI of the package being installed. */ - private String mPackageUri; - - /** Whether this attempt has been logged to the Event Log. */ - private boolean mLogged; - - private Context mContext; - - public static final Parcelable.Creator<InstallFlowAnalytics> CREATOR = - new Parcelable.Creator<InstallFlowAnalytics>() { - @Override - public InstallFlowAnalytics createFromParcel(Parcel in) { - return new InstallFlowAnalytics(in); - } - - @Override - public InstallFlowAnalytics[] newArray(int size) { - return new InstallFlowAnalytics[size]; - } - }; - - public InstallFlowAnalytics() {} - - public InstallFlowAnalytics(Parcel in) { - mFlags = in.readInt(); - mResult = in.readByte(); - mPackageManagerInstallResult = in.readInt(); - mStartTimestampMillis = in.readLong(); - mPackageInfoObtainedTimestampMillis = in.readLong(); - mInstallButtonClickTimestampMillis = in.readLong(); - mEndTimestampMillis = in.readLong(); - mPackageUri = in.readString(); - mLogged = readBoolean(in); - } - - @Override - public void writeToParcel(Parcel dest, int flags) { - dest.writeInt(mFlags); - dest.writeByte(mResult); - dest.writeInt(mPackageManagerInstallResult); - dest.writeLong(mStartTimestampMillis); - dest.writeLong(mPackageInfoObtainedTimestampMillis); - dest.writeLong(mInstallButtonClickTimestampMillis); - dest.writeLong(mEndTimestampMillis); - dest.writeString(mPackageUri); - writeBoolean(dest, mLogged); - } - - private static void writeBoolean(Parcel dest, boolean value) { - dest.writeByte((byte) (value ? 1 : 0)); - } - - private static boolean readBoolean(Parcel dest) { - return dest.readByte() != 0; - } - - @Override - public int describeContents() { - return 0; - } - - void setContext(Context context) { - mContext = context; - } - - /** Sets whether the Unknown Sources setting is checked. */ - void setInstallsFromUnknownSourcesPermitted(boolean permitted) { - setFlagState(FLAG_INSTALLS_FROM_UNKNOWN_SOURCES_PERMITTED, permitted); - } - - /** Gets whether the Unknown Sources setting is checked. */ - private boolean isInstallsFromUnknownSourcesPermitted() { - return isFlagSet(FLAG_INSTALLS_FROM_UNKNOWN_SOURCES_PERMITTED); - } - - /** Sets whether this install attempt is from an unknown source. */ - void setInstallRequestFromUnknownSource(boolean unknownSource) { - setFlagState(FLAG_INSTALL_REQUEST_FROM_UNKNOWN_SOURCE, unknownSource); - } - - /** Gets whether this install attempt is from an unknown source. */ - private boolean isInstallRequestFromUnknownSource() { - return isFlagSet(FLAG_INSTALL_REQUEST_FROM_UNKNOWN_SOURCE); - } - - /** Sets whether app verification is enabled. */ - void setVerifyAppsEnabled(boolean enabled) { - setFlagState(FLAG_VERIFY_APPS_ENABLED, enabled); - } - - /** Gets whether app verification is enabled. */ - private boolean isVerifyAppsEnabled() { - return isFlagSet(FLAG_VERIFY_APPS_ENABLED); - } - - /** Sets whether at least one app verifier is installed. */ - void setAppVerifierInstalled(boolean installed) { - setFlagState(FLAG_APP_VERIFIER_INSTALLED, installed); - } - - /** Gets whether at least one app verifier is installed. */ - private boolean isAppVerifierInstalled() { - return isFlagSet(FLAG_APP_VERIFIER_INSTALLED); - } - - /** - * Sets whether an APK file is being installed. - * - * @param fileUri {@code true} if an APK file is being installed, {@code false} if an already - * installed package is being installed to this user profile. - */ - void setFileUri(boolean fileUri) { - setFlagState(FLAG_FILE_URI, fileUri); - } - - /** - * Sets the URI of the package being installed. - */ - void setPackageUri(String packageUri) { - mPackageUri = packageUri; - } - - /** - * Gets whether an APK file is being installed. - * - * @return {@code true} if an APK file is being installed, {@code false} if an already - * installed package is being installed to this user profile. - */ - private boolean isFileUri() { - return isFlagSet(FLAG_FILE_URI); - } - - /** Sets whether this is an attempt to replace an existing package. */ - void setReplace(boolean replace) { - setFlagState(FLAG_REPLACE, replace); - } - - /** Gets whether this is an attempt to replace an existing package. */ - private boolean isReplace() { - return isFlagSet(FLAG_REPLACE); - } - - /** Sets whether the package being updated is a system package. */ - void setSystemApp(boolean systemApp) { - setFlagState(FLAG_SYSTEM_APP, systemApp); - } - - /** Gets whether the package being updated is a system package. */ - private boolean isSystemApp() { - return isFlagSet(FLAG_SYSTEM_APP); - } - - /** - * Sets whether the package being installed is requesting more permissions than the already - * installed version of the package. - */ - void setNewPermissionsFound(boolean found) { - setFlagState(FLAG_NEW_PERMISSIONS_FOUND, found); - } - - /** - * Gets whether the package being installed is requesting more permissions than the already - * installed version of the package. - */ - private boolean isNewPermissionsFound() { - return isFlagSet(FLAG_NEW_PERMISSIONS_FOUND); - } - - /** Sets whether permissions were displayed to the user. */ - void setPermissionsDisplayed(boolean displayed) { - setFlagState(FLAG_PERMISSIONS_DISPLAYED, displayed); - } - - /** Gets whether permissions were displayed to the user. */ - private boolean isPermissionsDisplayed() { - return isFlagSet(FLAG_PERMISSIONS_DISPLAYED); - } - - /** - * Sets whether new permissions were displayed to the user (if permissions were displayed at - * all). - */ - void setNewPermissionsDisplayed(boolean displayed) { - setFlagState(FLAG_NEW_PERMISSIONS_DISPLAYED, displayed); - } - - /** - * Gets whether new permissions were displayed to the user (if permissions were displayed at - * all). - */ - private boolean isNewPermissionsDisplayed() { - return isFlagSet(FLAG_NEW_PERMISSIONS_DISPLAYED); - } - - /** - * Sets whether all permissions were displayed to the user (if permissions were displayed at - * all). - */ - void setAllPermissionsDisplayed(boolean displayed) { - setFlagState(FLAG_ALL_PERMISSIONS_DISPLAYED, displayed); - } - - /** - * Gets whether all permissions were displayed to the user (if permissions were displayed at - * all). - */ - private boolean isAllPermissionsDisplayed() { - return isFlagSet(FLAG_ALL_PERMISSIONS_DISPLAYED); - } - - /** - * Sets the time instant when the installation request arrived, measured in elapsed realtime - * milliseconds. See {@link SystemClock#elapsedRealtime()}. - */ - void setStartTimestampMillis(long timestampMillis) { - mStartTimestampMillis = timestampMillis; - } - - /** - * Records that the information about the package info has been obtained or that there has been - * a failure to obtain the information. - */ - void setPackageInfoObtained() { - setFlagState(FLAG_PACKAGE_INFO_OBTAINED, true); - mPackageInfoObtainedTimestampMillis = SystemClock.elapsedRealtime(); - } - - /** - * Checks whether the information about the package info has been obtained or that there has - * been a failure to obtain the information. - */ - private boolean isPackageInfoObtained() { - return isFlagSet(FLAG_PACKAGE_INFO_OBTAINED); - } - - /** - * Records that the Install button has been clicked. - */ - void setInstallButtonClicked() { - setFlagState(FLAG_INSTALL_BUTTON_CLICKED, true); - mInstallButtonClickTimestampMillis = SystemClock.elapsedRealtime(); - } - - /** - * Checks whether the Install button has been clicked. - */ - private boolean isInstallButtonClicked() { - return isFlagSet(FLAG_INSTALL_BUTTON_CLICKED); - } - - /** - * Marks this flow as finished due to {@code PackageManager} succeeding or failing to install - * the package and reports this to the Event Log. - */ - void setFlowFinishedWithPackageManagerResult(int packageManagerResult) { - mPackageManagerInstallResult = packageManagerResult; - if (packageManagerResult == PackageManager.INSTALL_SUCCEEDED) { - setFlowFinished( - InstallFlowAnalytics.RESULT_SUCCESS); - } else { - setFlowFinished( - InstallFlowAnalytics.RESULT_PACKAGE_MANAGER_INSTALL_FAILED); - } - } - - /** - * Marks this flow as finished and reports this to the Event Log. - */ - void setFlowFinished(byte result) { - if (mLogged) { - return; - } - mResult = result; - mEndTimestampMillis = SystemClock.elapsedRealtime(); - writeToEventLog(); - } - - 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); - } - } - - private static final byte clipUnsignedValueToUnsignedByte(long value) { - if (value < 0) { - return 0; - } else if (value > 0xff) { - return (byte) 0xff; - } else { - return (byte) value; - } - } - - private static final int clipUnsignedLongToUnsignedInt(long value) { - if (value < 0) { - return 0; - } else if (value > 0xffffffffL) { - return 0xffffffff; - } else { - return (int) value; - } - } - - /** - * Sets or clears the specified flag in the {@link #mFlags} field. - */ - private void setFlagState(int flag, boolean set) { - if (set) { - mFlags |= flag; - } else { - mFlags &= ~flag; - } - } - - /** - * Checks whether the specified flag is set in the {@link #mFlags} field. - */ - private boolean isFlagSet(int flag) { - return (mFlags & flag) == flag; - } - - /** - * Checks whether the user has consented to app verification. - */ - private boolean isUserConsentToVerifyAppsGranted() { - return Settings.Secure.getInt( - mContext.getContentResolver(), - Settings.Secure.PACKAGE_VERIFIER_USER_CONSENT, 0) != 0; - } - - /** - * Gets the digest of the contents of the package being installed. - */ - private byte[] getPackageContentsDigest() throws IOException { - File file = new File(Uri.parse(mPackageUri).getPath()); - return getSha256ContentsDigest(file); - } - - /** - * Gets the SHA-256 digest of the contents of the specified file. - */ - private static byte[] getSha256ContentsDigest(File file) throws IOException { - MessageDigest digest; - try { - digest = MessageDigest.getInstance("SHA-256"); - } catch (NoSuchAlgorithmException e) { - throw new RuntimeException("SHA-256 not available", e); - } - - byte[] buf = new byte[8192]; - InputStream in = null; - try { - in = new BufferedInputStream(new FileInputStream(file), buf.length); - int chunkSize; - while ((chunkSize = in.read(buf)) != -1) { - digest.update(buf, 0, chunkSize); - } - } finally { - IoUtils.closeQuietly(in); - } - return digest.digest(); - } -} diff --git a/src/com/android/packageinstaller/PackageInstallerActivity.java b/src/com/android/packageinstaller/PackageInstallerActivity.java index 3ea3959d..0759ecec 100644 --- a/src/com/android/packageinstaller/PackageInstallerActivity.java +++ b/src/com/android/packageinstaller/PackageInstallerActivity.java @@ -33,12 +33,10 @@ import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; import android.content.pm.PackageParser; import android.content.pm.PackageUserState; -import android.content.pm.ResolveInfo; import android.content.pm.VerificationParams; import android.net.Uri; import android.os.Build; import android.os.Bundle; -import android.os.SystemClock; import android.os.UserManager; import android.provider.Settings; import android.support.v4.view.ViewPager; @@ -53,7 +51,6 @@ import android.widget.TabHost; import android.widget.TextView; import java.io.File; -import java.util.List; /* * This activity is launched when a new application is installed via side loading @@ -85,8 +82,6 @@ public class PackageInstallerActivity extends Activity implements OnCancelListen // ApplicationInfo object primarily used for already existing applications private ApplicationInfo mAppInfo = null; - private InstallFlowAnalytics mInstallFlowAnalytics; - // View for install progress View mInstallConfirm; // Buttons to indicate user acceptance @@ -97,8 +92,6 @@ public class PackageInstallerActivity extends Activity implements OnCancelListen static final String PREFS_ALLOWED_SOURCES = "allowed_sources"; - private static final String PACKAGE_MIME_TYPE = "application/vnd.android.package-archive"; - private static final String TAB_ID_ALL = "all"; private static final String TAB_ID_NEW = "new"; @@ -117,16 +110,6 @@ public class PackageInstallerActivity extends Activity implements OnCancelListen tabHost.setup(); ViewPager viewPager = (ViewPager)findViewById(R.id.pager); TabsAdapter adapter = new TabsAdapter(this, tabHost, viewPager); - adapter.setOnTabChangedListener(new TabHost.OnTabChangeListener() { - @Override - public void onTabChanged(String tabId) { - if (TAB_ID_ALL.equals(tabId)) { - mInstallFlowAnalytics.setAllPermissionsDisplayed(true); - } else if (TAB_ID_NEW.equals(tabId)) { - mInstallFlowAnalytics.setNewPermissionsDisplayed(true); - } - } - }); // If the app supports runtime permissions the new permissions will // be requested at runtime, hence we do not show them at install. boolean supportsRuntimePermissions = mPkgInfo.applicationInfo.targetSdkVersion @@ -148,7 +131,6 @@ public class PackageInstallerActivity extends Activity implements OnCancelListen if (!supportsRuntimePermissions) { newPermissionsFound = (perms.getPermissionCount(AppSecurityPermissions.WHICH_NEW) > 0); - mInstallFlowAnalytics.setNewPermissionsFound(newPermissionsFound); if (newPermissionsFound) { permVisible = true; mScrollView.addView(perms.getPermissionsView( @@ -181,7 +163,6 @@ public class PackageInstallerActivity extends Activity implements OnCancelListen adapter.addTab(tabHost.newTabSpec(TAB_ID_ALL).setIndicator( getText(R.string.allPerms)), root); } - mInstallFlowAnalytics.setPermissionsDisplayed(permVisible); if (!permVisible) { if (mAppInfo != null) { // This is an update to an application, but there are no @@ -194,8 +175,6 @@ public class PackageInstallerActivity extends Activity implements OnCancelListen msg = R.string.install_confirm_question_no_perms; } tabHost.setVisibility(View.GONE); - mInstallFlowAnalytics.setAllPermissionsDisplayed(false); - mInstallFlowAnalytics.setNewPermissionsDisplayed(false); findViewById(R.id.filler).setVisibility(View.VISIBLE); findViewById(R.id.divider).setVisibility(View.GONE); mScrollView = null; @@ -378,23 +357,6 @@ public class PackageInstallerActivity extends Activity implements OnCancelListen return true; } - private boolean isVerifyAppsEnabled() { - if (mUserManager.hasUserRestriction(UserManager.ENSURE_VERIFY_APPS)) { - return true; - } - return Settings.Global.getInt(getContentResolver(), - Settings.Global.PACKAGE_VERIFIER_ENABLE, 1) > 0; - } - - private boolean isAppVerifierInstalled() { - final PackageManager pm = getPackageManager(); - final Intent verification = new Intent(Intent.ACTION_PACKAGE_NEEDS_VERIFICATION); - verification.setType(PACKAGE_MIME_TYPE); - verification.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); - final List<ResolveInfo> receivers = pm.queryBroadcastReceivers(verification, 0); - return (receivers.size() > 0) ? true : false; - } - /** * @return whether unknown sources is enabled by user in Settings */ @@ -434,10 +396,6 @@ public class PackageInstallerActivity extends Activity implements OnCancelListen mAppInfo = null; } - mInstallFlowAnalytics.setReplace(mAppInfo != null); - mInstallFlowAnalytics.setSystemApp( - (mAppInfo != null) && ((mAppInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0)); - // If we have a session id, we're invoked to verify the permissions for the given // package. Otherwise, we start the install process. if (mSessionId != -1) { @@ -486,21 +444,8 @@ public class PackageInstallerActivity extends Activity implements OnCancelListen final boolean unknownSourcesAllowedByAdmin = isUnknownSourcesAllowedByAdmin(); final boolean unknownSourcesAllowedByUser = isUnknownSourcesEnabled(); - boolean requestFromUnknownSource = isInstallRequestFromUnknownSource(intent); - mInstallFlowAnalytics = new InstallFlowAnalytics(); - mInstallFlowAnalytics.setContext(this); - mInstallFlowAnalytics.setStartTimestampMillis(SystemClock.elapsedRealtime()); - mInstallFlowAnalytics.setInstallsFromUnknownSourcesPermitted(unknownSourcesAllowedByAdmin - && unknownSourcesAllowedByUser); - mInstallFlowAnalytics.setInstallRequestFromUnknownSource(requestFromUnknownSource); - mInstallFlowAnalytics.setVerifyAppsEnabled(isVerifyAppsEnabled()); - mInstallFlowAnalytics.setAppVerifierInstalled(isAppVerifierInstalled()); - mInstallFlowAnalytics.setPackageUri(mPackageURI.toString()); - if (DeviceUtils.isWear(this)) { showDialogInner(DLG_NOT_SUPPORTED_ON_WEAR); - mInstallFlowAnalytics.setFlowFinished( - InstallFlowAnalytics.RESULT_NOT_ALLOWED_ON_WEAR); return; } @@ -508,15 +453,12 @@ public class PackageInstallerActivity extends Activity implements OnCancelListen if (scheme != null && !"file".equals(scheme) && !"package".equals(scheme)) { Log.w(TAG, "Unsupported scheme " + scheme); setPmResult(PackageManager.INSTALL_FAILED_INVALID_URI); - mInstallFlowAnalytics.setFlowFinished( - InstallFlowAnalytics.RESULT_FAILED_UNSUPPORTED_SCHEME); finish(); return; } final PackageUtil.AppSnippet as; if ("package".equals(mPackageURI.getScheme())) { - mInstallFlowAnalytics.setFileUri(false); try { mPkgInfo = mPm.getPackageInfo(mPackageURI.getSchemeSpecificPart(), PackageManager.GET_PERMISSIONS | PackageManager.GET_UNINSTALLED_PACKAGES); @@ -527,15 +469,11 @@ public class PackageInstallerActivity extends Activity implements OnCancelListen + " not available. Discontinuing installation"); showDialogInner(DLG_PACKAGE_ERROR); setPmResult(PackageManager.INSTALL_FAILED_INVALID_APK); - mInstallFlowAnalytics.setPackageInfoObtained(); - mInstallFlowAnalytics.setFlowFinished( - InstallFlowAnalytics.RESULT_FAILED_PACKAGE_MISSING); return; } as = new PackageUtil.AppSnippet(mPm.getApplicationLabel(mPkgInfo.applicationInfo), mPm.getApplicationIcon(mPkgInfo.applicationInfo)); } else { - mInstallFlowAnalytics.setFileUri(true); final File sourceFile = new File(mPackageURI.getPath()); PackageParser.Package parsed = PackageUtil.getPackageInfo(sourceFile); @@ -544,9 +482,6 @@ public class PackageInstallerActivity extends Activity implements OnCancelListen Log.w(TAG, "Parse error when parsing manifest. Discontinuing installation"); showDialogInner(DLG_PACKAGE_ERROR); setPmResult(PackageManager.INSTALL_FAILED_INVALID_APK); - mInstallFlowAnalytics.setPackageInfoObtained(); - mInstallFlowAnalytics.setFlowFinished( - InstallFlowAnalytics.RESULT_FAILED_TO_GET_PACKAGE_INFO); return; } mPkgInfo = PackageParser.generatePackageInfo(parsed, null, @@ -555,7 +490,6 @@ public class PackageInstallerActivity extends Activity implements OnCancelListen mPkgDigest = parsed.manifestDigest; as = PackageUtil.getAppSnippet(this, mPkgInfo.applicationInfo, sourceFile); } - mInstallFlowAnalytics.setPackageInfoObtained(); //set view setContentView(R.layout.install_start); @@ -566,6 +500,7 @@ public class PackageInstallerActivity extends Activity implements OnCancelListen mOriginatingUid = getOriginatingUid(intent); // Block the install attempt on the Unknown Sources setting if necessary. + final boolean requestFromUnknownSource = isInstallRequestFromUnknownSource(intent); if (!requestFromUnknownSource) { initiateInstall(); return; @@ -577,13 +512,9 @@ public class PackageInstallerActivity extends Activity implements OnCancelListen if (!unknownSourcesAllowedByAdmin || (!unknownSourcesAllowedByUser && isManagedProfile)) { showDialogInner(DLG_ADMIN_RESTRICTS_UNKNOWN_SOURCES); - mInstallFlowAnalytics.setFlowFinished( - InstallFlowAnalytics.RESULT_BLOCKED_BY_UNKNOWN_SOURCES_SETTING); } else if (!unknownSourcesAllowedByUser) { // Ask user to enable setting first showDialogInner(DLG_UNKNOWN_SOURCES); - mInstallFlowAnalytics.setFlowFinished( - InstallFlowAnalytics.RESULT_BLOCKED_BY_UNKNOWN_SOURCES_SETTING); } else { initiateInstall(); } @@ -666,8 +597,6 @@ public class PackageInstallerActivity extends Activity implements OnCancelListen if (mSessionId != -1) { mInstaller.setPermissionsResult(mSessionId, false); } - mInstallFlowAnalytics.setFlowFinished( - InstallFlowAnalytics.RESULT_CANCELLED_BY_USER); super.onBackPressed(); } @@ -679,14 +608,8 @@ public class PackageInstallerActivity extends Activity implements OnCancelListen public void onClick(View v) { if (v == mOk) { if (mOkCanInstall || mScrollView == null) { - mInstallFlowAnalytics.setInstallButtonClicked(); if (mSessionId != -1) { mInstaller.setPermissionsResult(mSessionId, true); - - // We're only confirming permissions, so we don't really know how the - // story ends; assume success. - mInstallFlowAnalytics.setFlowFinishedWithPackageManagerResult( - PackageManager.INSTALL_SUCCEEDED); finish(); } else { startInstall(); @@ -700,8 +623,6 @@ public class PackageInstallerActivity extends Activity implements OnCancelListen if (mSessionId != -1) { mInstaller.setPermissionsResult(mSessionId, false); } - mInstallFlowAnalytics.setFlowFinished( - InstallFlowAnalytics.RESULT_CANCELLED_BY_USER); finish(); } } @@ -714,8 +635,6 @@ public class PackageInstallerActivity extends Activity implements OnCancelListen newIntent.setData(mPackageURI); newIntent.setClass(this, InstallAppProgress.class); newIntent.putExtra(InstallAppProgress.EXTRA_MANIFEST_DIGEST, mPkgDigest); - newIntent.putExtra( - InstallAppProgress.EXTRA_INSTALL_FLOW_ANALYTICS, mInstallFlowAnalytics); String installerPackageName = getIntent().getStringExtra( Intent.EXTRA_INSTALLER_PACKAGE_NAME); if (mOriginatingURI != null) { diff --git a/src/com/android/packageinstaller/TabsAdapter.java b/src/com/android/packageinstaller/TabsAdapter.java index 699cbed3..3509e092 100644 --- a/src/com/android/packageinstaller/TabsAdapter.java +++ b/src/com/android/packageinstaller/TabsAdapter.java @@ -46,7 +46,6 @@ public class TabsAdapter extends PagerAdapter private final ViewPager mViewPager; private final ArrayList<TabInfo> mTabs = new ArrayList<TabInfo>(); private final Rect mTempRect = new Rect(); - private TabHost.OnTabChangeListener mOnTabChangeListener; static final class TabInfo { private final String tag; @@ -115,17 +114,10 @@ public class TabsAdapter extends PagerAdapter return view == object; } - public void setOnTabChangedListener(TabHost.OnTabChangeListener listener) { - mOnTabChangeListener = listener; - } - @Override public void onTabChanged(String tabId) { int position = mTabHost.getCurrentTab(); mViewPager.setCurrentItem(position); - if (mOnTabChangeListener != null) { - mOnTabChangeListener.onTabChanged(tabId); - } } @Override |