在我的 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,
}
其中 ctsProfileMatch
和 basicIntegrity
设备的完整性。
关于android - 如何检测有根/越狱的安卓设备,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17950990/