Question

If you go into your android device to Settings-> Security, under the Device Administration section there are some settings for Verify Apps.

While working on AOSP, I am trying to get some testing software to work. So part of that requires I enable and disable this feature. I already have code to disable some other features, they look like this:

    //Allow mock locations
    Settings.Secure.putInt(getContentResolver(),
            Settings.Secure.ALLOW_MOCK_LOCATION, 
            1);

    //Stay on while plugged in
    Settings.Global.putInt(getContentResolver(),
            Settings.Global.STAY_ON_WHILE_PLUGGED_IN, 
            BatteryManager.BATTERY_PLUGGED_USB);

Note* I am running as root so I can change these settings. So to clarify, my question is how to change the settings Verify Apps, where is that located?

Was it helpful?

Solution

You're looking for Settings.Global.PACKAGE_VERIFIER_ENABLE. It doesn't seem to be up on the documentation site, but you can see it in the source.

Definition:

android.provider.Settings.java

Example usage by the default settings app:

com.android.settings.SecuritySettings.java

OTHER TIPS

Thanks(with upvotes) @Paradopolis and @Geobits with this question and the answer combination. @Geobits gave the correct answer. I'm posting mine, if somebody needs a detailed summarize and a method to get/set that option's status.

PACKAGE_VERIFIER_ENABLE is first defined at api level 14 with "verifier_enable" value under android.provider.Settings.Secure.

API level 14(4.0.1_r1):

public static final String PACKAGE_VERIFIER_ENABLE = "verifier_enable";

Its value and defined class changed after API level 17. Its value became "package_verifier_enable" under android.provider.Settings.Global

API level 17(4.2_r1):

public static final String PACKAGE_VERIFIER_ENABLE = "package_verifier_enable";

PACKAGE_VERIFIER_ENABLE property is defined public but it is hidden by annotation at its definition. So we can't use it as Settings.Secure.PACKAGE_VERIFIER_ENABLE or Settings.Global.PACKAGE_VERIFIER_ENABLE, but we can use its value.

If anybody needs to determine if package verify is checked/unchecked, or check/uncheck it programmatically can use class below:

public abstract class DeviceSettings {

    public enum SettingsCheckStatus {
        CHECKED, UNCHECKED, UNDEFINED
    }

    public static SettingsCheckStatus isVerifyAppsChecked(Context context) {
        // PACKAGE_VERIFIER_ENABLE is added after API level 14.
        // Its value changed at API level 17

        int packageVerifierEnabledAsInt = -1;
        if (Build.VERSION.SDK_INT >= 17) {
            packageVerifierEnabledAsInt = Settings.Global.getInt(context.getContentResolver(), "package_verifier_enable", -1);
        } else if (Build.VERSION.SDK_INT >= 14) {
            packageVerifierEnabledAsInt = Settings.Secure.getInt(context.getContentResolver(), "verifier_enable", -1);
        } else {
            // No package verification option before API Level 14
        }

        SettingsCheckStatus settingsCheckStatus = SettingsCheckStatus.UNDEFINED;
        switch (packageVerifierEnabledAsInt) {
        case 0:
            settingsCheckStatus = SettingsCheckStatus.UNCHECKED;
            break;
        case 1:
            settingsCheckStatus = SettingsCheckStatus.CHECKED;
            break;
        default:
            break;
        }

        return settingsCheckStatus;
    }

    /**
     * 
     * @param context
     * @param checked
     * @return
     * 
     * You must add <b>android.permission.WRITE_SECURE_SETTINGS</b> to your application's manifest file to use this method. 
     * Keep in mind, lint error checking may show an error on your manifest. <a href="http://stackoverflow.com/questions/13801984/permission-is-only-granted-to-system-app">See link to solve it.</a> <br>
     * Note that, this method <b>can only work on rooted devices or if your application is going to be a system app.<b>
     * 
     */
    public static boolean setVerifyAppsChecked(Context context, boolean checked) {
        boolean operationCompletedSuccessfully = false;
        int packageVerifierEnabledAsInt = checked ? 1 : 0;
        try {
            if (Build.VERSION.SDK_INT >= 17) {
                operationCompletedSuccessfully = Settings.Global.putInt(context.getContentResolver(), "package_verifier_enable", packageVerifierEnabledAsInt);
            } else if (Build.VERSION.SDK_INT >= 14) {
                operationCompletedSuccessfully = Settings.Secure.putInt(context.getContentResolver(), "verifier_enable", packageVerifierEnabledAsInt);
            } else {
                // No package verification option before API Level 14
            }
        } catch (Throwable t) {
            // Your device is not rooted or your app is not a system app.
        }

        return operationCompletedSuccessfully;
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top