//安全检测服务
public void securityFunction() {
//安全检测对象
SafetyDetectClient mClient = SafetyDetect.getClient(this);
// TODO(developer): Change the nonce generation to include your own, used once value,
// ideally from your remote server.
byte[] nonce = ("Sample" + System.currentTimeMillis()).getBytes();
Log.i(TAG, "securityFunction:=========== " + nonce.length);
SysIntegrityRequest sysintegrityrequest = new SysIntegrityRequest();
sysintegrityrequest.setAppId("106321561");//APPID
sysintegrityrequest.setNonce(nonce);//
sysintegrityrequest.setAlg("PS256");//RS256
Task task = mClient.sysIntegrity(sysintegrityrequest);
task.addOnSuccessListener(new OnSuccessListener<SysIntegrityResp>() {
@Override
public void onSuccess(SysIntegrityResp response) {
Log.i(TAG, "onSuccess: 系统检测成功!!!");
// Indicates communication with the service was successful.
// Use response.getResult() to get the result data.
String jwsStr = response.getResult();
Log.i(TAG, "onSuccess: " + jwsStr);
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(Exception e) {
Log.i(TAG, "onFailure: 系统检测失败!!!" + e.getMessage());
// An error occurred while communicating with the service.
if (e instanceof ApiException) {
// An error with the HMS API contains some
// additional details.
ApiException apiException = (ApiException) e;
// You can retrieve the status code using
// the apiException.getStatusCode() method.
Log.e(TAG, "Error: " + SafetyDetectStatusCodes.getStatusCodeString(apiException.getStatusCode()) + ": " + apiException.getMessage());
} else {
// A different, unknown type of error occurred.
Log.e(TAG, "ERROR:" + e.getMessage());
}
}
});
}
private static final String TAG = "MainActivity";