From a310dd355f880b06c9ec913ca4b4df838b57fd5e Mon Sep 17 00:00:00 2001 From: Sumedh Sen Date: Tue, 7 Feb 2023 14:00:56 -0800 Subject: [PATCH] Resume installation after permitting installing unknown apps. When a user allows an app to install unknown apps, resume the installation. PIA checked for an incorrect result code from the settings activity, which is now fixed. Instead, we check if the client is allowed to install unknown apps before resuming. PIA will finish itself if the user returns from the install unknown apps settings page without toggling the permission. Bug: 267992205 Test: Manual. Followed the repro steps in the mentioned bug. Change-Id: I17eca83c7fbfb3a610fe9cd009f3e61e4723a651 --- .../PackageInstallerActivity.java | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/packages/PackageInstaller/src/com/android/packageinstaller/PackageInstallerActivity.java b/packages/PackageInstaller/src/com/android/packageinstaller/PackageInstallerActivity.java index 3ec81aa380659..bb896af85bc14 100644 --- a/packages/PackageInstaller/src/com/android/packageinstaller/PackageInstallerActivity.java +++ b/packages/PackageInstaller/src/com/android/packageinstaller/PackageInstallerActivity.java @@ -246,26 +246,28 @@ public class PackageInstallerActivity extends AlertActivity { @Override public void onActivityResult(int request, int result, Intent data) { - if (request == REQUEST_TRUST_EXTERNAL_SOURCE && result == RESULT_OK) { - // The user has just allowed this package to install other packages (via Settings). - mAllowUnknownSources = true; - + if (request == REQUEST_TRUST_EXTERNAL_SOURCE) { // Log the fact that the app is requesting an install, and is now allowed to do it // (before this point we could only log that it's requesting an install, but isn't // allowed to do it yet). String appOpStr = AppOpsManager.permissionToOp(Manifest.permission.REQUEST_INSTALL_PACKAGES); - mAppOpsManager.noteOpNoThrow(appOpStr, mOriginatingUid, mOriginatingPackage, - mCallingAttributionTag, + int appOpMode = mAppOpsManager.noteOpNoThrow(appOpStr, mOriginatingUid, + mOriginatingPackage, mCallingAttributionTag, "Successfully started package installation activity"); - - DialogFragment currentDialog = - (DialogFragment) getFragmentManager().findFragmentByTag("dialog"); - if (currentDialog != null) { - currentDialog.dismissAllowingStateLoss(); + if (appOpMode == AppOpsManager.MODE_ALLOWED) { + // The user has just allowed this package to install other packages + // (via Settings). + mAllowUnknownSources = true; + DialogFragment currentDialog = + (DialogFragment) getFragmentManager().findFragmentByTag("dialog"); + if (currentDialog != null) { + currentDialog.dismissAllowingStateLoss(); + } + initiateInstall(); + } else { + finish(); } - - initiateInstall(); } else { finish(); }