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;
}
}