Ejemplo n.º 1
0
        public AlarmPage(Alarm alarm)
        {
            InitializeComponent(); //şimdiki

            if (alarm != null)
            {
                CurrentAlarm = alarm;
            }
            else
            {
                CurrentAlarm = new Alarm();
            }

            keyguardManager = (KeyguardManager)Forms.Context.GetSystemService(Android.Content.Context.KeyguardService);
            keyguardLock    = keyguardManager.NewKeyguardLock("TAG");
            _blocked        = keyguardManager.InKeyguardRestrictedInputMode(); //Klavyeyi kilitlemek ve açmak için kullanılabilecek sınıf

            if (_blocked)
            {
                keyguardLock.DisableKeyguard();
            }

            AlarmPageViewModel apVM = new AlarmPageViewModel(CurrentAlarm);

            apVM.OnAlarmTurnedOff += ToShakePage;
            BindingContext         = apVM;
        }
Ejemplo n.º 2
0
            public override void OnVisibilityChanged(bool visible)
            {
                is_visible = visible;

                bIsLockScreen = false;
                if (is_visible)
                {
                    if (myKM == null)
                    {
                        myKM = (KeyguardManager)mContext.GetSystemService(Context.KeyguardService);
                    }
                    if (myKM.IsDeviceLocked || myKM.IsKeyguardLocked)
                    {
                        bIsLockScreen = true;
                        //Tools.ShowToast(mContext, "Start LockScreenMode");
                    }
                }
                //Tools.ShowToast(mContext, "IsVisible: " + visible + "\nIsDeviceLocked: " + myKM.IsDeviceLocked + "\nIsDeviceLocked: " + myKM.IsKeyguardLocked);

                if (visible)
                {
                    DrawFrame();
                }
                else
                {
                    mHandler.RemoveCallbacks(mDrawCube);
                }
            }
        /// <summary>
        ///     Checks to see if the hardware is available to scan for fingerprints
        ///     and that the user has fingerprints enrolled.
        /// </summary>
        /// <returns></returns>
        string CheckFingerprintEligibility()
        {
            _canScan = true;

            if (!_fingerprintManager.IsHardwareDetected)
            {
                _canScan = false;
                string msg = Resources.GetString(Resource.String.missing_fingerprint_scanner);
                Log.Warn(TAG, msg);
                return(msg);
            }

            KeyguardManager keyguardManager = (KeyguardManager)GetSystemService(KeyguardService);

            if (!keyguardManager.IsKeyguardSecure)
            {
                string msg = Resources.GetString(Resource.String.keyguard_disabled);
                _canScan = false;
                Log.Warn(TAG, msg);
                return(msg);
            }


            if (!_fingerprintManager.HasEnrolledFingerprints)
            {
                _canScan = false;
                string msg = Resources.GetString(Resource.String.register_fingerprint);
                Log.Warn(TAG, msg);
                return(msg);
            }

            return(string.Empty);
        }
        /// <summary>
        /// Check if app is in foreground
        /// </summary>
        /// <returns></returns>
        private bool AppInForeground()
        {
            var context = Application.Context;

            KeyguardManager km = (KeyguardManager)context.GetSystemService(Context.KeyguardService);

            if (!km.InKeyguardRestrictedInputMode())
            {
                var activityManager = (ActivityManager)context.GetSystemService(Context.ActivityService);
                var appProcesses    = activityManager.RunningAppProcesses;
                if (appProcesses == null)
                {
                    return(false);
                }

                var packageName = context.PackageName;
                foreach (ActivityManager.RunningAppProcessInfo appProcess in appProcesses)
                {
                    if (appProcess.Importance == Importance.Foreground && appProcess.ProcessName == packageName)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Ejemplo n.º 5
0
        private void sendNotification(string AlertTone)
        {
            try
            {
                KeyguardManager myKM   = (KeyguardManager)Android.App.Application.Context.GetSystemService(Context.KeyguardService);
                bool            islock = myKM.InKeyguardRestrictedInputMode();
                if (islock)
                {
                    //it is locked
                    if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.Lollipop)
                    {
                        MyAlarmManager();
                    }
                    else
                    {
                        AlartManager();
                    }
                }
                else
                {
                    AlartManager();
                    //it is not locked
                }

                notificationSound(AlertTone);
            }
            catch (System.Exception e)
            {
                ExceptioHandler(e.Message, "sendNotification");
            }
        }
Ejemplo n.º 6
0
        public override async Task <FingerprintAvailability> GetAvailabilityAsync(bool allowAlternativeAuthentication = false)
        {
            if (Build.VERSION.SdkInt < BuildVersionCodes.M)
            {
                return(FingerprintAvailability.NoApi);
            }


            var biometricAvailability = GetBiometricAvailability();

            if (biometricAvailability == FingerprintAvailability.Available || !allowAlternativeAuthentication)
            {
                return(biometricAvailability);
            }

            var context = Application.Context;

            try
            {
                KeyguardManager manager =
                    (KeyguardManager)context.GetSystemService(Android.Content.Context.KeyguardService);
                if (manager.IsDeviceSecure)
                {
                    return(FingerprintAvailability.Available);
                }

                return(FingerprintAvailability.NoFallback);
            }
            catch
            {
                return(FingerprintAvailability.NoFallback);
            }
        }
Ejemplo n.º 7
0
 public override void OnReceive(Context context, Intent intent)
 {
     Android.Util.Log.Info("MonoGame", intent.Action.ToString());
     if (intent.Action == Intent.ActionScreenOff)
     {
         ScreenReceiver.ScreenLocked = true;
         MediaPlayer.IsMuted         = true;
     }
     else if (intent.Action == Intent.ActionScreenOn)
     {
         // If the user turns the screen on just after it has automatically turned off,
         // the keyguard will not have had time to activate and the ActionUserPreset intent
         // will not be broadcast. We need to check if the lock is currently active
         // and if not re-enable the game related functions.
         // http://stackoverflow.com/questions/4260794/how-to-tell-if-device-is-sleeping
         KeyguardManager keyguard = (KeyguardManager)context.GetSystemService(Context.KeyguardService);
         if (!keyguard.InKeyguardRestrictedInputMode())
         {
             ScreenReceiver.ScreenLocked = false;
             MediaPlayer.IsMuted         = false;
         }
     }
     else if (intent.Action == Intent.ActionUserPresent)
     {
         // This intent is broadcast when the user unlocks the phone
         ScreenReceiver.ScreenLocked = false;
         MediaPlayer.IsMuted         = false;
     }
 }
Ejemplo n.º 8
0
        public void GetFingerprint(EventHandler evt, bool encrypt, byte[] data)
        {
            //make sure the device is secured
            KeyguardManager keyguardManager = (KeyguardManager)Application.Context.GetSystemService(Context.KeyguardService);

            if (!keyguardManager.IsKeyguardSecure)
            {
                return;
            }
            //make sure fingerprints are enrolled
            if (!m_fingerprintManager.HasEnrolledFingerprints)
            {
                return;
            }
            //check permissions
            Android.Content.PM.Permission permissionResult = ContextCompat.CheckSelfPermission(Application.Context, Manifest.Permission.UseFingerprint);
            if (permissionResult != Android.Content.PM.Permission.Granted)
            {
                return;
            }

            m_evt  = evt;
            m_data = data;
            m_mode = encrypt ? CipherMode.EncryptMode : CipherMode.DecryptMode;

            CryptoObjectHelper cryptoHelper = new CryptoObjectHelper();

            cancellationSignal = new Android.Support.V4.OS.CancellationSignal();

            //prompt user to scan their fingerprint
            m_fingerprintManager.Authenticate(cryptoHelper.BuildCryptoObject(m_mode), 0, cancellationSignal, this, null);
        }
Ejemplo n.º 9
0
        private void AuthenticateApp()
        {
            //Get the instance of KeyGuardManager
            KeyguardManager keyguardManager = (KeyguardManager)GetSystemService(KeyguardService);

            //Check if the device version is greater than or equal to Lollipop(21)
            if (Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.Lollipop)
            {
                //Create an intent to open device screen lock screen to authenticate
                //Pass the Screen Lock screen Title and Description
                Intent i = keyguardManager.CreateConfirmDeviceCredentialIntent("Unlock to Login.", "");
                try
                {
                    //Start activity for result
                    StartActivityForResult(i, LOCK_REQUEST_CODE);
                }
                catch (Exception e)
                {
                    //If some exception occurs means Screen lock is not set up please set screen lock
                    //Open Security screen directly to enable patter lock
                    Intent intent = new Intent(Android.Provider.Settings.ActionSecuritySettings);
                    try
                    {
                        //Start activity for result
                        StartActivityForResult(intent, SECURITY_SETTING_REQUEST_CODE);
                    }
                    catch (Exception ex)
                    {
                        //no security available
                    }
                }
            }
        }
        public bool IsFingerprintSupported()
        {
            if (Android.OS.Build.VERSION.SdkInt < Android.OS.BuildVersionCodes.M)
            {
                return(false);
            }

            if (fingerprintManager == null)
            {
                fingerprintManager = FingerprintManagerCompat.From(activity);
            }
            if (fingerprintManager == null || !fingerprintManager.IsHardwareDetected)
            {
                return(false);
            }
            if (!fingerprintManager.HasEnrolledFingerprints)
            {
                return(false);
            }

            if (keyguardManager == null)
            {
                keyguardManager = (KeyguardManager)activity.GetSystemService(Context.KeyguardService);
            }
            if (keyguardManager == null || !keyguardManager.IsKeyguardSecure)
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 11
0
        private static bool HasLockScreen()
        {
            KeyguardManager keyguardManager = (KeyguardManager)Application.Context.GetSystemService(Context.KeyguardService);

            var isSecure = keyguardManager.IsKeyguardSecure;

            return(isSecure);
        }
Ejemplo n.º 12
0
        private bool IsDeviceSecure()
        {
            KeyguardManager keyguardManager = (KeyguardManager)GetSystemService(KeyguardService);

            //this method only work whose api level is greater than or equal to Jelly_Bean (16)
            return(Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.JellyBean && keyguardManager.IsKeyguardSecure);

            //You can also use keyguardManager.isDeviceSecure(); but it requires API Level 23
        }
Ejemplo n.º 13
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            fingerprintModule = new FingerprintModule(this);
            mKeyguardManager  = fingerprintModule.ProvidesKeyguardManager(this);
            mKeyStore         = fingerprintModule.ProvidesKeystore();
            mKeyGenerator     = fingerprintModule.ProvidesKeyGenerator();
            mCipher           = fingerprintModule.ProvidesCipher(mKeyStore);

            RequestPermissions(new [] { Manifest.Permission.UseFingerprint }, FINGERPRINT_PERMISSION_REQUEST_CODE);
        }
        /// <summary>
        /// Inizializza lo scanner per l'impronta digitale
        /// </summary>
        public void Init()
        {
            try
            {
                FingerprintManagerCompat fingerprintManagerCmp = FingerprintManagerCompat.From(CurrentContext);
                if (!fingerprintManagerCmp.IsHardwareDetected)
                {
                    throw new Exception(Resources.GetString(Resource.String.errFpHWNotDetected));
                }

                // Il dispositivo deve essere protetto da blocca schermo, altrimenti non si può usare
                // l'impronta digitale
                KeyguardManager keyguardManager = (KeyguardManager)CurrentContext.GetSystemService(Context.KeyguardService);
                if (!keyguardManager.IsKeyguardSecure)
                {
                    throw new Exception(Resources.GetString(Resource.String.errFpLockScreen));
                }

                // Verifica la presenza della registrazione di almeno una impronta digitale
                if (!HasEnrolledFingerprints(fingerprintManagerCmp))
                {
                    throw new Exception(Resources.GetString(Resource.String.errFpNotFound));
                }

                // Verifica delle autorizzazioni da Android 6 in poi
                if (Build.VERSION.SdkInt >= BuildVersionCodes.M)
                {
                    Android.Content.PM.Permission permissionResult = ContextCompat.CheckSelfPermission(CurrentContext, USE_FINFERPRINT_PERMISSION);
                    if (permissionResult == Android.Content.PM.Permission.Granted)
                    {
                        FingerprintManager = fingerprintManagerCmp;
                    }
                    else
                    {
                        // No permission. Go and ask for permissions and don't start the scanner. See
                        // https://developer.android.com/training/permissions/requesting.html
                        MainActivity.Instance.RequestPermissions(new[] { USE_FINFERPRINT_PERMISSION }, 0);
                        // Verifico di nuovo i permessi
                        permissionResult = ContextCompat.CheckSelfPermission(CurrentContext, USE_FINFERPRINT_PERMISSION);
                        if (permissionResult != Android.Content.PM.Permission.Granted)
                        {
                            throw new Exception(Resources.GetString(Resource.String.errFpPermissionDenied));
                        }
                    }
                }
            }
            catch (Exception)
            {
                FingerprintManager = null;
                throw;
            }
        }
        public bool IsDeviceSecured()
        {
            KeyguardManager keyguardManager = (KeyguardManager)Android.App.Application.Context.GetSystemService(Android.App.Application.KeyguardService);

            if (!keyguardManager.IsKeyguardSecure)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
Ejemplo n.º 16
0
 internal static void PromptKeyguardManagerAuth(string title, string desc)
 {
     //BuildVersionCodes.Q Android 10
     if ((int)Build.VERSION.SdkInt < 29)
     {
         KeyguardManager km = (KeyguardManager)Configuration.CurrentActivity.GetSystemService(Activity.KeyguardService);
         if (km.IsKeyguardSecure)
         {
             Intent authIntent = km.CreateConfirmDeviceCredentialIntent(title, desc);
             Configuration.CurrentActivity.StartActivityForResult(authIntent, Configuration.KeyguardManagerRequestCode);
         }
     }
 }
Ejemplo n.º 17
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            Window.SetFlags(WindowManagerFlags.Secure, WindowManagerFlags.Secure);
            SetContentView(Resource.Layout.activityMain);

            var toolbar = FindViewById <Toolbar>(Resource.Id.toolbar);

            SetSupportActionBar(toolbar);
            SupportActionBar.SetTitle(Resource.String.categoryAll);

            _bottomAppBar = FindViewById <BottomAppBar>(Resource.Id.bottomAppBar);
            _bottomAppBar.NavigationClick += OnBottomAppBarNavigationClick;
            _bottomAppBar.MenuItemClick   += (sender, args) =>
            {
                toolbar.Menu.FindItem(Resource.Id.actionSearch).ExpandActionView();
                _authList.SmoothScrollToPosition(0);
            };

            _coordinatorLayout = FindViewById <CoordinatorLayout>(Resource.Id.coordinatorLayout);
            _progressBar       = FindViewById <ProgressBar>(Resource.Id.appBarProgressBar);

            _addButton        = FindViewById <FloatingActionButton>(Resource.Id.buttonAdd);
            _addButton.Click += OnAddButtonClick;

            _authList               = FindViewById <RecyclerView>(Resource.Id.list);
            _emptyStateLayout       = FindViewById <LinearLayout>(Resource.Id.layoutEmptyState);
            _emptyMessageText       = FindViewById <TextView>(Resource.Id.textEmptyMessage);
            _viewGuideButton        = FindViewById <MaterialButton>(Resource.Id.buttonViewGuide);
            _viewGuideButton.Click += (sender, args) =>
            {
                StartChildActivity(typeof(GuideActivity));
            };

            _isChildActivityOpen = false;
            _keyguardManager     = (KeyguardManager)GetSystemService(KeyguardService);

            MobileBarcodeScanner.Initialize(Application);
            _barcodeScanner = new MobileBarcodeScanner();

            DetectGoogleAPIsAvailability();

            var prefs       = PreferenceManager.GetDefaultSharedPreferences(this);
            var firstLaunch = prefs.GetBoolean("firstLaunch", true);

            if (firstLaunch)
            {
                StartChildActivity(typeof(IntroActivity));
            }
        }
Ejemplo n.º 18
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);
            Button logInButton = FindViewById <Button>(Resource.Id.logInButton);

            logInButton.Click += (s, e) =>
            {
                Intent intent = new Intent(this, typeof(HomeActivity));
                this.StartActivity(intent);
            };
            KeyguardManager    keyguardManager    = (KeyguardManager)GetSystemService(KeyguardService);
            FingerprintManager fingerprintManager = (FingerprintManager)GetSystemService(FingerprintService);

            if (ActivityCompat.CheckSelfPermission(this, Manifest.Permission.UseFingerprint)
                != (int)Android.Content.PM.Permission.Granted)
            {
                return;
            }
            if (!fingerprintManager.IsHardwareDetected)
            {
                Toast.MakeText(this, "FingerPrint authentication permission not enable", ToastLength.Short).Show();
            }
            else
            {
                if (!fingerprintManager.HasEnrolledFingerprints)
                {
                    Toast.MakeText(this, "Register at least one fingerprint in Settings", ToastLength.Short).Show();
                }
                else
                {
                    if (!keyguardManager.IsKeyguardSecure)
                    {
                        Toast.MakeText(this, "Lock screen security not enable in Settings", ToastLength.Short).Show();
                    }
                    else
                    {
                        GenKey();
                    }
                    if (CipherInit())
                    {
                        FingerprintManager.CryptoObject cryptoObject = new FingerprintManager.CryptoObject(cipher);
                        FingerprintHandler handler = new FingerprintHandler(this);
                        handler.StartAuthentication(fingerprintManager, cryptoObject);
                    }
                }
            }
        }
Ejemplo n.º 19
0
        public static ScreenStatus GetScreenStatus(Context ctx)
        {
            PowerManager    powerManager  = (PowerManager)ctx.GetSystemService(Context.PowerService);
            var             isScreenAwake = Build.VERSION.SdkInt < BuildVersionCodes.KitkatWatch ? powerManager.IsScreenOn : powerManager.IsInteractive;
            KeyguardManager kM            = (KeyguardManager)ctx.GetSystemService(Context.KeyguardService);

            if (kM.IsDeviceLocked)
            {
                if (isScreenAwake)
                {
                    return(kM.IsDeviceSecure ? ScreenStatus.OnLockedSecure : ScreenStatus.OnLockedInsecure);
                }
                return(kM.IsDeviceSecure ? ScreenStatus.OffLockedSecure : ScreenStatus.OffLockedInsecure);
            }
            return(isScreenAwake ? ScreenStatus.OnUnlocked : ScreenStatus.OffUnlocked);
        }
Ejemplo n.º 20
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.biometric_activity);
            if (this.Intent.Extras != null)
            {
                transactionObject = JsonConvert.DeserializeObject <TransactionObject>(Intent.GetStringExtra("transactionObject"));
                user = JsonConvert.DeserializeObject <User>(Intent.GetStringExtra("users"));
            }
            KeyguardManager    keyguardManager    = (KeyguardManager)GetSystemService(KeyguardService);
            FingerprintManager fingerprintManager = (FingerprintManager)GetSystemService(FingerprintService);

            if (ActivityCompat.CheckSelfPermission(this, Manifest.Permission.UseFingerprint)
                != (int)Android.Content.PM.Permission.Granted)
            {
                return;
            }
            if (!fingerprintManager.IsHardwareDetected)
            {
                Toast.MakeText(this, "FingerPrint authentication permission not enable", ToastLength.Short).Show();
            }
            else
            {
                if (!fingerprintManager.HasEnrolledFingerprints)
                {
                    Toast.MakeText(this, "Register at least one fingerprint in Settings", ToastLength.Short).Show();
                }
                else
                {
                    if (!keyguardManager.IsKeyguardSecure)
                    {
                        Toast.MakeText(this, "Lock screen security not enable in Settings", ToastLength.Short).Show();
                    }
                    else
                    {
                        GenKey();
                    }
                    if (CipherInit())
                    {
                        FingerprintManager.CryptoObject cryptoObject = new FingerprintManager.CryptoObject(cipher);
                        FingerprintHandler handler = new FingerprintHandler(this, transactionObject, user);
                        handler.StartAuthentication(fingerprintManager, cryptoObject);
                    }
                }
            }
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Initialize fingerprint authentication mechanism
        /// </summary>
        /// <param name="activity">Root activity</param>
        public static void FingerprintAuthenticate(Activity activity)
        {
            FingerprintManagerCompat fingerprint = FingerprintManagerCompat.From(activity);
            KeyguardManager          keyGuard    = activity.GetSystemService(Context.KeyguardService) as KeyguardManager;

            Android.Content.PM.Permission permission = activity.CheckSelfPermission(Android.Manifest.Permission.UseFingerprint);
            if (fingerprint.IsHardwareDetected &&
                keyGuard.IsKeyguardSecure &&
                fingerprint.HasEnrolledFingerprints &&
                permission == Android.Content.PM.Permission.Granted)
            {
                const int           flags        = 0;
                CryptoObjectFactory cryptoHelper = new CryptoObjectFactory();
                FingerprintManagerCompat.AuthenticationCallback authCallback = new AuthCallback(activity as Activities.LoginActivity);
                fingerprint.Authenticate(cryptoHelper.BuildCryptoObject(), flags, new Android.Support.V4.OS.CancellationSignal(), authCallback, null);
            }
        }
Ejemplo n.º 22
0
        private void _autentificareAmprenta(object ob, EventArgs ev)
        {
            KeyguardManager    _manager  = (KeyguardManager)GetSystemService(KeyguardService);
            FingerprintManager _amprente = (FingerprintManager)GetSystemService(FingerprintService);

            if (Android.Support.V4.Content.ContextCompat.CheckSelfPermission(this, _permisiune) != (int)Android.Content.PM.Permission.Granted)
            {
                return;
            }
            if (!_amprente.IsHardwareDetected)
            {
                Toast.MakeText(this, "The use of fingertip authentication is disabled", ToastLength.Short).Show();
            }
            else
            {
                if (!_amprente.HasEnrolledFingerprints)
                {
                    Toast.MakeText(this, "No fingertips registered in our app", ToastLength.Short).Show();
                }
                else
                {
                    if (!_manager.IsKeyguardSecure)
                    {
                        Toast.MakeText(this, "Please enable lock screen security!", ToastLength.Short).Show();
                    }
                    else
                    {
                        _algoritmCriptare();
                    }
                    if (_genereazaCifru())
                    {
                        FingerprintManager.CryptoObject _criptat = new FingerprintManager.CryptoObject(_cifru);
                        CreatorAmprenta _creator = new CreatorAmprenta(this);
                        _creator._startAutentificare(_amprente, _criptat);
                        gotoCriptare.Visibility = ViewStates.Visible;
                        gotoGPS.Visibility      = ViewStates.Visible;
                        gotoContinut.Visibility = ViewStates.Visible;
                        ftipTV.Text             = "Now you can use any of the options below";
                        gotoCriptare.Click     += _accesCriptarePosibil;
                        gotoGPS.Click          += _accesGPSPosibil;
                        gotoContinut.Click     += _accesContinutPosibil;
                    }
                }
            }
        }
        private void Authenticate()
        {
            FingerprintManager fingerprint = this.GetSystemService(FingerprintService) as FingerprintManager;
            KeyguardManager    keyGuard    = GetSystemService(KeyguardService) as KeyguardManager;

            Android.Content.PM.Permission permission = CheckSelfPermission(Android.Manifest.Permission.UseFingerprint);
            if (fingerprint.IsHardwareDetected &&
                keyGuard.IsKeyguardSecure &&
                fingerprint.HasEnrolledFingerprints &&
                permission == Android.Content.PM.Permission.Granted)
            {
                const int           flags              = 0;
                CryptoObjectFactory cryptoObject       = new CryptoObjectFactory();
                CancellationSignal  cancellationSignal = new CancellationSignal();
                FingerprintManager.AuthenticationCallback authCallback = new AuthCallback(this);
                fingerprint.Authenticate(cryptoObject.BuildCryptoObject(), cancellationSignal, flags, authCallback, null);
            }
        }
Ejemplo n.º 24
0
 public override void OnReceive(Context context, Intent intent)
 {
     if (intent.Action == Intent.ActionScreenOn)
     {
         KeyguardManager keyguard = (KeyguardManager)context.GetSystemService(Context.KeyguardService);
         if (!keyguard.InKeyguardRestrictedInputMode())
         {
             OnUnlocked();
         }
     }
     else if (intent.Action == Intent.ActionScreenOff)
     {
         OnLocked();
     }
     else if (intent.Action == Intent.ActionUserPresent)
     {
         OnUnlocked();
     }
 }
Ejemplo n.º 25
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            Window.SetFlags(WindowManagerFlags.Secure, WindowManagerFlags.Secure);
            SetContentView(Resource.Layout.activityMain);

            // Actionbar
            var toolbar = FindViewById <Toolbar>(Resource.Id.activityMain_toolbar);

            _progressBar = FindViewById <ProgressBar>(Resource.Id.activityMain_progressBar);

            SetSupportActionBar(toolbar);
            SupportActionBar.SetTitle(Resource.String.categoryAll);
            SupportActionBar.SetHomeButtonEnabled(true);
            SupportActionBar.SetDisplayHomeAsUpEnabled(true);

            // Navigation Drawer
            _drawerLayout   = FindViewById <DrawerLayout>(Resource.Id.activityMain_drawerLayout);
            _navigationView = FindViewById <NavigationView>(Resource.Id.activityMain_navView);
            _navigationView.NavigationItemSelected += DrawerItemSelected;

            _actionBarDrawerToggle = new IdleActionBarDrawerToggle(this, _drawerLayout, toolbar,
                                                                   Resource.String.appName, Resource.String.appName);
            _drawerLayout.AddDrawerListener(_actionBarDrawerToggle);

            // Buttons
            _addButton        = FindViewById <FloatingActionButton>(Resource.Id.activityMain_buttonAdd);
            _addButton.Click += AddButtonClick;

            // Barcode scanner
            MobileBarcodeScanner.Initialize(Application);
            _barcodeScanner = new MobileBarcodeScanner();

            // Misc
            _keyguardManager = (KeyguardManager)GetSystemService(KeyguardService);

            // Recyclerview
            _authList   = FindViewById <RecyclerView>(Resource.Id.activityMain_authList);
            _emptyState = FindViewById <LinearLayout>(Resource.Id.activityMain_emptyState);

            _isChildActivityOpen = false;
        }
Ejemplo n.º 26
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            SetContentView(Resource.Layout.Main);

            KeyguardManager    keyguardManager    = (KeyguardManager)GetSystemService(KeyguardService);
            FingerprintManager fingerprintManager = (FingerprintManager)GetSystemService(FingerprintService);

            if (ActivityCompat.CheckSelfPermission(this, Manifest.Permission.UseFingerprint) != (int)Android.Content.PM.Permission.Granted)
            {
                return;
            }
            if (!fingerprintManager.IsHardwareDetected)
            {
                Toast.MakeText(this, "Fingerprint authentication permission not enalbe", ToastLength.Long).Show();
            }
            else
            {
                if (!fingerprintManager.HasEnrolledFingerprints)
                {
                    Toast.MakeText(this, "Register at least one fingerprint in Settings", ToastLength.Long).Show();
                }
                else
                {
                    if (!keyguardManager.IsKeyguardSecure)
                    {
                        Toast.MakeText(this, "Lock screen security not enable in Settings", ToastLength.Long).Show();
                    }
                    else
                    {
                        GenKey();
                    }
                    if (CipherInit())
                    {
                        FingerprintManager.CryptoObject cryptoObject = new FingerprintManager.CryptoObject(cipher);
                        FingerprintHandler helper = new FingerprintHandler(this);
                        helper.StartAuthentication(fingerprintManager, cryptoObject);
                    }
                }
            }
        }
Ejemplo n.º 27
0
 public void Authenticate(int requestCode = 0)
 {
     try
     {
         KeyguardManager manager = (KeyguardManager)Android.App.Application.Context.GetSystemService(Context.KeyguardService);
         if (manager.IsKeyguardSecure)
         {
             var intent = manager.CreateConfirmDeviceCredentialIntent("Enter Password", "Enter your password to authenticate yourself");
             intent.SetType(null);
             if (intent != null)
             {
                 //Android.App.Application.Context.StartActivity(intent);
                 CrossCurrentActivity.Current.Activity.StartActivityForResult(intent, requestCode);
             }
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
 }
Ejemplo n.º 28
0
        public void Authenticate()
        {
            KeyguardManager    keyguardManager    = (KeyguardManager)Forms.Context.GetSystemService("keyguard");
            FingerprintManager fingerprintManager = (FingerprintManager)Forms.Context.GetSystemService("fingerprint");

            if (ActivityCompat.CheckSelfPermission(Forms.Context, Manifest.Permission.UseFingerprint) != (int)Android.Content.PM.Permission.Granted)
            {
                return;
            }
            if (!fingerprintManager.IsHardwareDetected)
            {
                Toast.MakeText(Forms.Context, "FingerPrint authentication permission not enable", ToastLength.Short).Show();
            }
            else
            {
                if (!fingerprintManager.HasEnrolledFingerprints)
                {
                    Toast.MakeText(Forms.Context, "Register at least one fingerprint in Settings", ToastLength.Short).Show();
                }
                else
                {
                    if (!keyguardManager.IsKeyguardSecure)
                    {
                        Toast.MakeText(Forms.Context, "Lock screen security not enable in Settings", ToastLength.Short).Show();
                    }
                    else
                    {
                        GenKey();
                    }
                    if (CipherInit())
                    {
                        FingerprintManager.CryptoObject cryptoObject = new FingerprintManager.CryptoObject(cipher);

                        StartAuthentication(fingerprintManager, cryptoObject);
                    }
                }
            }
        }
Ejemplo n.º 29
0
        public void CheckFingerPrint()
        {
            try
            {
                FingerprintManagerCompat fingerprintManager = FingerprintManagerCompat.From(this);
                KeyguardManager          keyguardManager    = GetSystemService(KeyguardService) as KeyguardManager;
                App.AndroidFingerPrintSupported = fingerprintManager.IsHardwareDetected && keyguardManager.IsKeyguardSecure && fingerprintManager.HasEnrolledFingerprints;
                CrossFingerprint.SetCurrentActivityResolver(() => CrossCurrentActivity.Current.Activity);//Register FingerScan Nuget
            }
            catch (Exception e)
            {
            }


            //if (!keyguardManager.IsKeyguardSecure)
            //{
            //}
            //if (!fingerprintManager.HasEnrolledFingerprints)
            //{
            //    // Can't use fingerprint authentication - notify the user that they need to
            //    // enroll at least one fingerprint with the device.
            //}
        }
Ejemplo n.º 30
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            SetContentView(Resource.Layout.Main);

            keyguardManager = (KeyguardManager)GetSystemService(Context.KeyguardService);
            var purchaseButton = FindViewById <Button> (Resource.Id.purchase_button);

            if (!keyguardManager.IsKeyguardSecure)
            {
                // Show a message that the user hasn't set up a lock screen.
                Toast.MakeText(this, "Secure lock screen isn't set up.\n"
                               + "Go to 'Settings -> Security -> Screenlock' to set up a lock screen",
                               ToastLength.Short).Show();
                purchaseButton.Enabled = false;
                return;
            }

            CreateKey();

            // Test to encrypt something. It might fail if the timeout expired (30s).
            purchaseButton.Click += (object sender, EventArgs e) => TryEncrypt();
        }