private void DetectUser() { string appid = AGConnectServicesConfig.FromContext(Activity).GetString("client/app_id"); SafetyDetect.GetClient(Activity).UserDetection(appid) .AddOnSuccessListener(new OnSuccessListener((Result) => { UserDetectResponse userDetectResponse = (UserDetectResponse)Result; Log.Info("DetectUser", $"User detection succeed, response {userDetectResponse.ResponseToken}"); Toast.MakeText(Activity.ApplicationContext, $"User detection succeed.", ToastLength.Short).Show(); })) .AddOnFailureListener(new OnFailureListener((Result) => { string errorMessage = null; if (Result is ApiException exception) { errorMessage = $"{SafetyDetectStatusCodes.GetStatusCodeString(exception.StatusCode)}: {exception.Message}"; } else { errorMessage = ((Java.Lang.Exception)Result).Message; } Log.Error("DetectUser", errorMessage); Toast.MakeText(Activity.ApplicationContext, $"User detection failed! Message: {errorMessage}", ToastLength.Short).Show(); // If value is 19800, this means Fake user detection failed. It also be throwed when user clicks cancel button. })); }
private void GetWifiDetectStatus() { SafetyDetect.GetClient(Activity).WifiDetectStatus .AddOnSuccessListener(new OnSuccessListener((Result) => { WifiDetectResponse wifiDetectResponse = (WifiDetectResponse)Result; Toast.MakeText(Activity.ApplicationContext, $"WifiDetect status: {wifiDetectResponse.WifiDetectStatus}", ToastLength.Short).Show(); Log.Info("WifiDetectStatus", $"{wifiDetectResponse.WifiDetectStatus}"); })) .AddOnFailureListener(new OnFailureListener((Result) => { string errorMessage = null; if (Result is ApiException exception) { errorMessage = $"{SafetyDetectStatusCodes.GetStatusCodeString(exception.StatusCode)}: {exception.Message}"; } else { errorMessage = ((Java.Lang.Exception)Result).Message; } Log.Error("WifiDetectStatus", errorMessage); Toast.MakeText(Activity.ApplicationContext, $"GetWifiDetect status failed! Message: {errorMessage}", ToastLength.Short).Show(); //If Value is 19003 that means the user device area does not support the Safety Detect service. })); }
private void EnableAppsCheck() { SafetyDetect.GetClient(Activity).EnableAppsCheck() .AddOnSuccessListener(new OnSuccessListener((Result) => { VerifyAppsCheckEnabledResp appsCheckResp = (VerifyAppsCheckEnabledResp)Result; bool isEnableAppsCheck = appsCheckResp.Result; if (isEnableAppsCheck) { Toast.MakeText(Activity.ApplicationContext, "The AppsCheck feature is enabled.", ToastLength.Short).Show(); Log.Info("EnableAppsCheck", "The AppsCheck feature is enabled."); } })) .AddOnFailureListener(new OnFailureListener((Result) => { string errorMessage = null; if (Result is ApiException exception) { errorMessage = $"{SafetyDetectStatusCodes.GetStatusCodeString(exception.StatusCode)}: {exception.Message}"; } else { errorMessage = ((Java.Lang.Exception)Result).Message; } Log.Error("EnableAppsCheck", errorMessage); Toast.MakeText(Activity.ApplicationContext, $"Enable AppsCheck failed! Message: {errorMessage}", ToastLength.Short).Show(); })); }
private void SysIntegrity() { byte[] nonce = new byte[24]; string appid = AGConnectServicesConfig.FromContext(Activity).GetString("client/app_id"); SafetyDetect.GetClient(Activity).SysIntegrity(nonce, appid).AddOnSuccessListener(new OnSuccessListener((Result) => { SysIntegrityResp response = (SysIntegrityResp)Result; string jwStr = response.Result; string[] jwsSplit = jwStr.Split("."); string jwsPayloadStr = jwsSplit[1]; byte[] data = Convert.FromBase64String(jwsPayloadStr); string jsonString = Encoding.UTF8.GetString(data); JSONObject jObject = new JSONObject(jsonString); Log.Info("SysIntegrity", jsonString.Replace(",", ",\n")); string basicIntegrityText = null; try { bool basicIntegrity = jObject.GetBoolean("basicIntegrity"); if (basicIntegrity) { theButton.SetBackgroundResource(Resource.Drawable.btn_round_green); basicIntegrityText = "Basic Integrity is Success."; } else { theButton.SetBackgroundResource(Resource.Drawable.btn_round_red); basicIntegrityText = "Basic Integrity is Failure."; adviceTextView.Text = $"Advice: {jObject.GetString("advice")}"; } } catch (JSONException e) { Android.Util.Log.Error("SysIntegrity", e.Message); } basicIntegrityTextView.Text = basicIntegrityText; theButton.SetText(Resource.String.rerun); })).AddOnFailureListener(new OnFailureListener((Result) => { string errorMessage = null; if (Result is ApiException exception) { errorMessage = $"{SafetyDetectStatusCodes.GetStatusCodeString(exception.StatusCode)}: {exception.Message}"; } else { errorMessage = ((Java.Lang.Exception)Result).Message; } Log.Error("SysIntegrity", errorMessage); theButton.SetBackgroundResource(Resource.Drawable.btn_round_yellow); })); }
private void CallUrlCheckApi() { string appid = AGConnectServicesConfig.FromContext(Activity).GetString("client/app_id"); EditText editText = Activity.FindViewById <EditText>(Resource.Id.fg_call_urlCheck_text); string realUrl = editText.Text.Trim(); TextView textResult = Activity.FindViewById <TextView>(Resource.Id.fg_call_urlResult); client.UrlCheck(realUrl, appid, UrlCheckThreat.Malware, UrlCheckThreat.Phishing) .AddOnSuccessListener(new OnSuccessListener((Result) => { /** * Called after successfully communicating with the SafetyDetect API. * The #onSuccess callback receives an * {@link Com.Huawei.Hms.Support.Api.Entity.Safetydetect.UrlCheckResponse} that contains a * list of UrlCheckThreat that contains the threat type of the Url. * Indicates communication with the service was successful. * Identify any detected threats. * Get UrlCheckResponse property of UrlCheckResponse then you can get List<UrlCheckThreat> . * If List<UrlCheckThreat> is empty , that means no threats found , else that means threats found */ List <UrlCheckThreat> list = ((UrlCheckResponse)Result).GetUrlCheckResponse().ToList(); if (list.Count == 0) { textResult.Text = "No threats found."; Log.Info("UrlCheck", $"{textResult.Text}"); } else { textResult.Text = "Threats found!"; Log.Info("UrlCheck", $"{textResult.Text}"); foreach (UrlCheckThreat line in list) { Log.Info("UrlCheck", $"Threat type: {line.UrlCheckResult}"); } } })).AddOnFailureListener(new OnFailureListener((Result) => { string errorMessage = null; if (Result is ApiException exception) { errorMessage = $"{SafetyDetectStatusCodes.GetStatusCodeString(exception.StatusCode)}: {exception.Message}"; } Log.Error("UrlCheck", errorMessage); })); }
private void GetMaliciousApps() { SafetyDetect.GetClient(Activity).MaliciousAppsList .AddOnSuccessListener(new OnSuccessListener((Result) => { MaliciousAppsListResp maliciousAppsListResp = (MaliciousAppsListResp)Result; List <MaliciousAppsData> appsDataList = maliciousAppsListResp.MaliciousAppsList.ToList(); if (maliciousAppsListResp.RtnCode == CommonCode.Ok) { if (appsDataList.Count == 0) { Toast.MakeText(Activity.ApplicationContext, "No known potentially malicious apps are installed.", ToastLength.Short).Show(); } else { foreach (MaliciousAppsData maliciousApp in appsDataList) { Log.Info("GetMaliciousApps", "Information about a malicious app:"); Log.Info("GetMaliciousApps", $"APK: {maliciousApp.ApkPackageName}"); Log.Info("GetMaliciousApps", $"SHA-256: {maliciousApp.ApkSha256}"); Log.Info("GetMaliciousApps", $"Category: {maliciousApp.ApkCategory}"); } MaliciousAppsDataListAdapter maliciousAppAdapter = new MaliciousAppsDataListAdapter(appsDataList, Activity.ApplicationContext); maliciousAppListView.Adapter = maliciousAppAdapter; } } })) .AddOnFailureListener(new OnFailureListener((Result) => { string errorMessage = null; if (Result is ApiException exception) { errorMessage = $"{SafetyDetectStatusCodes.GetStatusCodeString(exception.StatusCode)}: {exception.Message}"; } else { errorMessage = ((Java.Lang.Exception)Result).Message; } Log.Error("GetMaliciousApps", errorMessage); Toast.MakeText(Activity.ApplicationContext, $"Verfy AppsCheck Enabled failed! Message: {errorMessage}", ToastLength.Short).Show(); })); }
private void GetRiskToken() { SafetyDetect.GetClient(Activity).RiskToken .AddOnSuccessListener(new OnSuccessListener((Result) => { RiskTokenResponse riskTokenResponse = (RiskTokenResponse)Result; Log.Info("GetRiskToken", $"GetRiskToken succeed, response {riskTokenResponse.RiskToken}"); Toast.MakeText(Activity.ApplicationContext, $"GetRiskToken succeed response {riskTokenResponse.RiskToken}", ToastLength.Short).Show(); })) .AddOnFailureListener(new OnFailureListener((Result) => { string errorMessage = null; if (Result is ApiException exception) { errorMessage = $"{SafetyDetectStatusCodes.GetStatusCodeString(exception.StatusCode)}: {exception.Message}"; } else { errorMessage = ((Java.Lang.Exception)Result).Message; } Log.Error("GetRiskToken", errorMessage); Toast.MakeText(Activity.ApplicationContext, $"GetRiskToken failed! Message: {errorMessage}", ToastLength.Short).Show(); })); }