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

Commit 03722fd0 authored by Sumedh Sen's avatar Sumedh Sen Committed by Android (Google) Code Review
Browse files

Merge changes I49329e62,I64197ebe into main

* changes:
  Modify logic to compute trustedSource
  Dont check for "no_install_unknown_sources" for installs from privileged sources.
parents 86d98183 822c0f33
Loading
Loading
Loading
Loading
+20 −14
Original line number Original line Diff line number Diff line
@@ -125,13 +125,14 @@ public class InstallStart extends Activity {
                -1, callingUid) == PackageManager.PERMISSION_GRANTED;
                -1, callingUid) == PackageManager.PERMISSION_GRANTED;
        boolean isSystemDownloadsProvider = PackageUtil.getSystemDownloadsProviderInfo(
        boolean isSystemDownloadsProvider = PackageUtil.getSystemDownloadsProviderInfo(
                                                mPackageManager, callingUid) != null;
                                                mPackageManager, callingUid) != null;
        boolean isTrustedSource = false;

        if (sourceInfo != null && sourceInfo.isPrivilegedApp()) {
        boolean isPrivilegedAndKnown = (sourceInfo != null && sourceInfo.isPrivilegedApp()) &&
            isTrustedSource = intent.getBooleanExtra(Intent.EXTRA_NOT_UNKNOWN_SOURCE, false) || (
            intent.getBooleanExtra(Intent.EXTRA_NOT_UNKNOWN_SOURCE, false);
                callingUid != Process.INVALID_UID && checkPermission(
        boolean isInstallPkgPermissionGranted =
                    Manifest.permission.INSTALL_PACKAGES, -1 /* pid */, callingUid)
            checkPermission(Manifest.permission.INSTALL_PACKAGES, /* pid= */ -1, callingUid)
                    == PackageManager.PERMISSION_GRANTED);
                    == PackageManager.PERMISSION_GRANTED;
        }

        boolean isTrustedSource = isPrivilegedAndKnown || isInstallPkgPermissionGranted;


        if (!isTrustedSource && !isSystemDownloadsProvider && !isDocumentsManager
        if (!isTrustedSource && !isSystemDownloadsProvider && !isDocumentsManager
                && callingUid != Process.INVALID_UID) {
                && callingUid != Process.INVALID_UID) {
@@ -154,7 +155,7 @@ public class InstallStart extends Activity {
            mAbortInstall = true;
            mAbortInstall = true;
        }
        }


        checkDevicePolicyRestrictions();
        checkDevicePolicyRestrictions(isTrustedSource);


        final String installerPackageNameFromIntent = getIntent().getStringExtra(
        final String installerPackageNameFromIntent = getIntent().getStringExtra(
                Intent.EXTRA_INSTALLER_PACKAGE_NAME);
                Intent.EXTRA_INSTALLER_PACKAGE_NAME);
@@ -304,12 +305,17 @@ public class InstallStart extends Activity {
        return callingUid == installerUid;
        return callingUid == installerUid;
    }
    }


    private void checkDevicePolicyRestrictions() {
    private void checkDevicePolicyRestrictions(boolean isTrustedSource) {
        final String[] restrictions = new String[] {
        String[] restrictions;
        if(isTrustedSource) {
            restrictions = new String[] { UserManager.DISALLOW_INSTALL_APPS };
        } else {
            restrictions =  new String[] {
                UserManager.DISALLOW_INSTALL_APPS,
                UserManager.DISALLOW_INSTALL_APPS,
                UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES,
                UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES,
                UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES_GLOBALLY
                UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES_GLOBALLY
            };
            };
        }


        final DevicePolicyManager dpm = getSystemService(DevicePolicyManager.class);
        final DevicePolicyManager dpm = getSystemService(DevicePolicyManager.class);
        for (String restriction : restrictions) {
        for (String restriction : restrictions) {