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

Commit 73eabee3 authored by Kun Liang's avatar Kun Liang Committed by Shashank Mittal
Browse files

Block application install from unknown sources through adb

adb install command  doesn't check source of an application.

This change enforces that adb install command only works if user has
download/install from unknown sources selected in settings app.

Change-Id: Id0d328d1dad36089802d6bec2f5d2f940e045c25
parent 21b6775d
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -574,6 +574,14 @@ public abstract class PackageManager {
     */
    public static final int INSTALL_FAILED_VERSION_DOWNGRADE = -25;

    /**
     * Installation return code: this is passed to the {@link IPackageInstallObserver} by
     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if
     * the package is from unknown sources but not trusted sources.
     * @hide
     */
    public static final int INSTALL_FAILED_UNKNOWN_SOURCES = -26;

    /**
     * Installation parse return code: this is passed to the {@link IPackageInstallObserver} by
     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)}
+12 −0
Original line number Diff line number Diff line
@@ -116,6 +116,7 @@ import android.os.SystemProperties;
import android.os.UserHandle;
import android.os.Environment.UserEnvironment;
import android.os.UserManager;
import android.provider.Settings.Global;
import android.security.KeyStore;
import android.security.SystemKeyStore;
import android.text.TextUtils;
@@ -6517,6 +6518,17 @@ public class PackageManagerService extends IPackageManager.Stub {
            filteredFlags = flags & ~PackageManager.INSTALL_FROM_ADB;
        }

        // Check if unknown sources allowed
        if (android.app.AppOpsManager.isStrictEnable() &&
            ((filteredFlags & PackageManager.INSTALL_FROM_ADB) != 0) &&
            Global.getInt(mContext.getContentResolver(), Global.INSTALL_NON_MARKET_APPS, 0) <= 0) {
            try {
                observer.packageInstalled("", PackageManager.INSTALL_FAILED_UNKNOWN_SOURCES);
            } catch (RemoteException re) {
            }
            return;
        }

        verificationParams.setInstallerUid(uid);

        final Message msg = mHandler.obtainMessage(INIT_COPY);