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

Commit 124d0507 authored by Kun Liang's avatar Kun Liang Committed by Steve Kondik
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 15cb44e1
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
/*
 * Copyright (c) 2013-2014, The Linux Foundation. All rights reserved.
 * Not a Contribution.
 *
 * Copyright (C) 2006 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
@@ -623,6 +626,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
/*
 * Copyright (c) 2013-2014, The Linux Foundation. All rights reserved.
 * Not a Contribution.
 *
 * Copyright (C) 2006 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
@@ -155,6 +158,7 @@ import android.os.SystemClock;
import android.os.SystemProperties;
import android.os.UserHandle;
import android.os.UserManager;
import android.provider.Settings.Secure;
import android.security.KeyStore;
import android.security.SystemKeyStore;
import android.system.ErrnoException;
@@ -10397,6 +10401,14 @@ public class PackageManagerService extends IPackageManager.Stub {
            }
        }
        if (android.app.AppOpsManager.isStrictEnable()
                && ((installFlags & PackageManager.INSTALL_FROM_ADB) != 0)
                && Secure.getInt(mContext.getContentResolver(),
                        Secure.INSTALL_NON_MARKET_APPS, 0) <= 0) {
            res.returnCode = PackageManager.INSTALL_FAILED_UNKNOWN_SOURCES;
            return;
        }
        try {
            pp.collectCertificates(pkg, parseFlags);
            pp.collectManifestDigest(pkg);