diff options
author | Philip P. Moltmann <moltmann@google.com> | 2016-09-27 10:49:02 -0700 |
---|---|---|
committer | Philip P. Moltmann <moltmann@google.com> | 2016-09-27 19:51:21 +0000 |
commit | 435a65b477f5bc079700d84ea216faf2adc7c823 (patch) | |
tree | fc723bc6e028d63e83d9d40960f599f4f5256fd4 /src/com/android/packageinstaller/PackageInstallerActivity.java | |
parent | 7d7bfe74edd29b47562b04dea80afe2c6c6e5b19 (diff) | |
download | android_packages_apps_PackageInstaller-435a65b477f5bc079700d84ea216faf2adc7c823.tar.gz android_packages_apps_PackageInstaller-435a65b477f5bc079700d84ea216faf2adc7c823.tar.bz2 android_packages_apps_PackageInstaller-435a65b477f5bc079700d84ea216faf2adc7c823.zip |
Parse package before enabling unknown sources
So that when we return from the settings app we do not have distinguish
between file and content-uri based install anymore
Test: Manually went through the following workflows:
- Install from file
- Unknown sources is already enabled
- Unknown sources is not enabled yet
- Return 0 from settings
- unknown sources was enabled
- unknown sources was not enabled
- Return -1 from settings
- unknown sources was enabled
- unknown sources was not enabled
- Install from content URI
- Unknown sources is already enabled
- Unknown sources is not enabled yet
- Return 0 from settings
- unknown sources was enabled
- unknown sources was not enabled
- Return -1 from settings
- unknown sources was enabled
- unknown sources was not enabled
Fixes: 31328285
Change-Id: I1d23f2ba9a835f7bffc59108565b286aeb675411
Diffstat (limited to 'src/com/android/packageinstaller/PackageInstallerActivity.java')
-rw-r--r-- | src/com/android/packageinstaller/PackageInstallerActivity.java | 50 |
1 files changed, 38 insertions, 12 deletions
diff --git a/src/com/android/packageinstaller/PackageInstallerActivity.java b/src/com/android/packageinstaller/PackageInstallerActivity.java index 50ef0bf0..cf264d12 100644 --- a/src/com/android/packageinstaller/PackageInstallerActivity.java +++ b/src/com/android/packageinstaller/PackageInstallerActivity.java @@ -120,6 +120,9 @@ public class PackageInstallerActivity extends Activity implements OnCancelListen private static final int DLG_NOT_SUPPORTED_ON_WEAR = DLG_BASE + 7; private void startInstallConfirm() { + ((TextView) findViewById(R.id.install_confirm_question)) + .setText(R.string.install_confirm_question); + findViewById(R.id.spacer).setVisibility(View.GONE); TabHost tabHost = (TabHost)findViewById(android.R.id.tabhost); tabHost.setup(); tabHost.setVisibility(View.VISIBLE); @@ -324,7 +327,7 @@ public class PackageInstallerActivity extends Activity implements OnCancelListen // whether the untrusted sources setting is on. This allows partners to // implement a "allow untrusted source once" feature. if (request == REQUEST_ENABLE_UNKNOWN_SOURCES && result == RESULT_OK) { - initiateInstall(); + checkIfAllowedAndInitiateInstall(); } else { clearCachedApkIfNeededAndFinish(); } @@ -454,11 +457,23 @@ public class PackageInstallerActivity extends Activity implements OnCancelListen mOk.setOnClickListener(this); mCancel.setOnClickListener(this); + boolean wasSetUp = processPackageUri(packageUri); + if (!wasSetUp) { + return; + } + + checkIfAllowedAndInitiateInstall(); + } + + /** + * Check if it is allowed to install the package and initiate install if allowed. If not allowed + * show the appropriate dialog. + */ + private void checkIfAllowedAndInitiateInstall() { // Block the install attempt on the Unknown Sources setting if necessary. - final boolean requestFromUnknownSource = isInstallRequestFromUnknownSource(intent); + final boolean requestFromUnknownSource = isInstallRequestFromUnknownSource(getIntent()); if (!requestFromUnknownSource) { - processPackageUri(packageUri); - return; + initiateInstall(); } // If the admin prohibits it, or we're running in a managed profile, just show error @@ -479,7 +494,7 @@ public class PackageInstallerActivity extends Activity implements OnCancelListen showDialogInner(DLG_UNKNOWN_SOURCES); } else { - processPackageUri(packageUri); + initiateInstall(); } } @@ -492,7 +507,14 @@ public class PackageInstallerActivity extends Activity implements OnCancelListen super.onDestroy(); } - private void processPackageUri(final Uri packageUri) { + /** + * Parse the Uri and set up the installer for this package. + * + * @param packageUri The URI to parse + * + * @return {@code true} iff the installer could be set up + */ + private boolean processPackageUri(final Uri packageUri) { mPackageURI = packageUri; final String scheme = packageUri.getScheme(); @@ -511,7 +533,7 @@ public class PackageInstallerActivity extends Activity implements OnCancelListen + " not available. Discontinuing installation"); showDialogInner(DLG_PACKAGE_ERROR); setPmResult(PackageManager.INSTALL_FAILED_INVALID_APK); - return; + return false; } as = new PackageUtil.AppSnippet(mPm.getApplicationLabel(mPkgInfo.applicationInfo), mPm.getApplicationIcon(mPkgInfo.applicationInfo)); @@ -526,7 +548,7 @@ 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); - return; + return false; } mPkgInfo = PackageParser.generatePackageInfo(parsed, null, PackageManager.GET_PERMISSIONS, 0, 0, null, @@ -537,20 +559,20 @@ public class PackageInstallerActivity extends Activity implements OnCancelListen case SCHEME_CONTENT: { mStagingAsynTask = new StagingAsyncTask(); mStagingAsynTask.execute(packageUri); - return; + return false; } default: { Log.w(TAG, "Unsupported scheme " + scheme); setPmResult(PackageManager.INSTALL_FAILED_INVALID_URI); clearCachedApkIfNeededAndFinish(); - return; + return false; } } PackageUtil.initSnippetForNewApp(this, as, R.id.app_snippet); - initiateInstall(); + return true; } /** Get the ApplicationInfo for the calling package, if available */ @@ -776,7 +798,11 @@ public class PackageInstallerActivity extends Activity implements OnCancelListen } mContentUriApkStagingFile = file; Uri fileUri = Uri.fromFile(file); - processPackageUri(fileUri); + + boolean wasSetUp = processPackageUri(fileUri); + if (wasSetUp) { + checkIfAllowedAndInitiateInstall(); + } } @Override |