android - 如何检测有根/越狱的安卓设备

标签 android jailbreak rooted-device

在我的 Android 应用程序中,我只想为获得 root 权限的设备提供特定功能。唯一的检查方法是知道我是否可以运行 super 用户命令吗?这个检查够了吗?还有更多方法可以检测越狱的 Android 设备吗?

最佳答案

对于那些仍然想知道如何检测 root 设备的人,现在有一种方法可以做到这一点。

您现在可以使用 SafetyNet Attestation API

Here是文档的链接。

以下是从文档中获取的如何使用 API 的 fragment 。

// The nonce should be at least 16 bytes in length.
// You must generate the value of API_KEY in the Google APIs dashboard.
SafetyNet.getClient(this).attest(nonce, API_KEY)
    .addOnSuccessListener(this,
        new OnSuccessListener<SafetyNetApi.AttestationResponse>() {
            @Override
            public void onSuccess(SafetyNetApi.AttestationResponse response) {
                // Indicates communication with the service was successful.
                // Use response.getJwsResult() to get the result data.
            }
        })
    .addOnFailureListener(this, new OnFailureListener() {
        @Override
        public void onFailure(@NonNull Exception e) {
            // An error occurred while communicating with the service.
            if (e instanceof ApiException) {
                // An error with the Google Play services API contains some
                // additional details.
                ApiException apiException = (ApiException) e;
                // You can retrieve the status code using the
                // apiException.getStatusCode() method.
            } else {
                // A different, unknown type of error occurred.
                Log.d(TAG, "Error: " + e.getMessage());
            }
        }
    });

要使用以下 API,您必须从 Google API 控制台生成一个 API key 。此 key 是您传递给 .attest() 方法的内容。

同时添加 SafetyNet 依赖项。

实现 'com.google.android.gms:play-services-safetynet:15.0.1'

参见 https://developers.google.com/android/guides/setup获取最新的依赖版本。

API 返回以下内容:

{
  "nonce": "R2Rra24fVm5xa2Mg",
  "timestampMs": 9860437986543,
  "apkPackageName": "com.package.name.of.requesting.app",
  "apkCertificateDigestSha256": ["base64 encoded, SHA-256 hash of the
                              certificate used to sign requesting app"],
  "apkDigestSha256": ["base64 encoded, SHA-256 hash of
                  the APK installed on a user's device"],
  "ctsProfileMatch": true,
  "basicIntegrity": true,
}

其中 ctsProfileMatchbasicIntegrity 设备的完整性。

enter image description here

关于android - 如何检测有根/越狱的安卓设备,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17950990/

相关文章:

java - 将 JSON 从 Elasticsearch 转换为 Java 对象

java - 如何从主 Activity 刷新 Fragment 中的 ListView?

android - Gradle 将重复文件放入 apk 文件中

xcode - 如何开始越狱开发

ios - 使用 vb.net 将包含文件的文件夹导入到越狱的 iPhone 中

android - 如何让 Android 设备在 root 设备上进入休眠模式(比如,点击按钮)

android - 为我的 Android 设备删除 Settings.APK 会有什么影响?

java - Android 中如何防止 root 设备绕过证书固定?

java - Android 中刷新按钮

ios - 越狱设备上的 NSFileProtection