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.
     }));
 }
Beispiel #2
0
 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 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.
            }));
        }
Beispiel #4
0
        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);
            }));
        }
Beispiel #5
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            SetContentView(Resource.Layout.activity_main);

            AGConnectServicesConfig config = AGConnectServicesConfig.FromContext(ApplicationContext);

            Android.Support.V7.Widget.Toolbar toolbar = FindViewById <Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar);
            SetSupportActionBar(toolbar);
            SafetyDetect.GetClient(this).InitUserDetect();

            FloatingActionButton fab = FindViewById <FloatingActionButton>(Resource.Id.fab);

            fab.Click += FabOnClick;
        }
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            View view = inflater.Inflate(Resource.Layout.fg_urlcheck, container, false);

            Spinner spinner = view.FindViewById <Spinner>(Resource.Id.fg_url_spinner);

            spinner.ItemSelected += Spinner_ItemSelected;
            ArrayAdapter adapter = ArrayAdapter.CreateFromResource(Activity, Resource.Array.url_array, Android.Resource.Layout.SimpleSpinnerItem);

            adapter.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerDropDownItem);
            spinner.Adapter = adapter;

            client = SafetyDetect.GetClient(Activity);
            view.FindViewById <Button>(Resource.Id.fg_call_url_btn).SetOnClickListener(this);

            return(view);
        }
Beispiel #7
0
 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();
     }));
 }
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            View   view  = inflater.Inflate(Resource.Layout.fg_others, container, false);
            string appid = AGConnectServicesConfig.FromContext(Activity).GetString("client/app_id");

            view.FindViewById <Button>(Resource.Id.fg_wifidetect).SetOnClickListener(this);
            view.FindViewById <Button>(Resource.Id.fg_userdetect).SetOnClickListener(this);
            view.FindViewById <Button>(Resource.Id.fg_risktoken).SetOnClickListener(this);

            client = SafetyDetect.GetClient(Activity);

            client.InitUserDetect()
            .AddOnSuccessListener(new OnSuccessListener((Result) => { Log.Info("InitUserDetect", "InitUserDetect is succeeded."); }))
            .AddOnFailureListener(new OnFailureListener((Result) => { Log.Error("InitUserDetect", "InitUserDetect is failed."); }));
            client.InitAntiFraud(appid)
            .AddOnSuccessListener(new OnSuccessListener((Result) => { Log.Info("InitAntiFraud", "InitAntiFraud is succeeded."); }))
            .AddOnFailureListener(new OnFailureListener((Result) => { Log.Error("InitAntiFraud", "InitAntiFraud is failed."); }));

            return(view);
        }
 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();
     }));
 }
Beispiel #10
0
 private void detect()
 {
     client = SafetyDetect.GetClient(this);
     client.UserDetection(APP_ID).AddOnSuccessListener(this, this).AddOnFailureListener(this, this);
 }