Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 435a65b4 authored by Philip P. Moltmann's avatar Philip P. Moltmann
Browse files

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
parent 7d7bfe74
Loading
Loading
Loading
Loading
+38 −12
Original line number Diff line number Diff line
@@ -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