如何检查“验证应用程序"是否有效以编程方式启用或禁用

如何检查“验证应用程序

问题描述:

如果谷歌的验证应用"在应用启动时被禁用,我有一个安全要求来提醒用户.问题是我不知道有什么方法可以检查验证应用程序"是否被禁用.

I've a security requirement to alert users if google's "verify app" is disabled on app launch. The problem is that I dont know any way to check whether "verify app" is disabled or not.

我尝试使用下面的代码,但它总是返回 1.

I tried to use the code below, but it's always returning 1.

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

此外,作为一项要求,如果此功能被禁用,希望用户被导航到验证应用"设置.

Also, as a requirement, want user to be navigated to the "verifiy app" settings if this feature is disabled.

阅读首选项,不再有用,因为 android 现在不更新首选项.所以基本上阅读谷歌验证的首选项值是行不通的.

Reading preferences, won't help anymore as android don't update preferences now. So basically reading preferences value for google Verify won't work.

请使用以下 SaftyNet 回调来验证谷歌保护.

Please use below SaftyNet callbacks to verify google protect.

SafetyNet.getClient(context)
                .isVerifyAppsEnabled()
                .addOnCompleteListener(new OnCompleteListener<SafetyNetApi.VerifyAppsUserResponse>() {
                    @Override
                    public void onComplete(@NonNull Task<SafetyNetApi.VerifyAppsUserResponse> task) {
---
}
});