Search in sources :

Example 86 with CancellationSignal

use of android.os.CancellationSignal in project wanandroid by KnightAndroid.

the class BiometricPromptApiM method authenticate.

@RequiresApi(api = Build.VERSION_CODES.M)
@Override
public void authenticate(boolean loginFlg, @Nullable CancellationSignal cancel, @NonNull BiometricPromptManager.OnBiometricIdentifyCallback callback) {
    // 指纹识别的回调
    mManagerIdentifyCallback = callback;
    mDialog = BiometricPromptDialog.newInstance();
    mDialog.setOnBiometricPromptDialogActionCallback(new BiometricPromptDialog.OnBiometricPromptDialogActionCallback() {

        @Override
        public void onDialogDismiss() {
            // 当dialog消失的时候,包括点击userPassword、点击cancel、和识别成功之后
            if (mCancellationSignal != null && !mCancellationSignal.isCanceled()) {
                mCancellationSignal.cancel();
            }
        }

        @Override
        public void onCancel() {
            // 点击cancel键
            if (mManagerIdentifyCallback != null) {
                mManagerIdentifyCallback.onCancel();
            }
        }
    });
    mDialog.showAllowingStateLoss(mActivity.getSupportFragmentManager(), "BiometricPromptApiM");
    mCancellationSignal = cancel;
    if (mCancellationSignal == null) {
        mCancellationSignal = new CancellationSignal();
    }
    mCancellationSignal.setOnCancelListener(new CancellationSignal.OnCancelListener() {

        @Override
        public void onCancel() {
            mDialog.dismiss();
        }
    });
    KeyGenTool mKeyGenTool = new KeyGenTool(mActivity);
    FingerprintManager.CryptoObject object;
    if (loginFlg) {
        // 解密
        try {
            /**
             * 可通过服务器保存iv,然后在使用之前从服务器获取
             */
            String ivStr = CacheUtils.getCliperIv();
            byte[] iv = Base64.decode(ivStr, Base64.URL_SAFE);
            object = new FingerprintManager.CryptoObject(mKeyGenTool.getDecryptCipher(iv));
            getFingerprintManager(mActivity).authenticate(object, mCancellationSignal, 0, mFmAuthCallback, null);
        } catch (Exception e) {
            e.printStackTrace();
        }
    } else {
        // 加密
        try {
            object = new FingerprintManager.CryptoObject(mKeyGenTool.getEncryptCipher());
            getFingerprintManager(mActivity).authenticate(object, mCancellationSignal, 0, mFmAuthCallback, null);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
Also used : FingerprintManager(android.hardware.fingerprint.FingerprintManager) BiometricPromptDialog(com.knight.wanandroid.library_biometric.dialog.BiometricPromptDialog) CancellationSignal(android.os.CancellationSignal) RequiresApi(androidx.annotation.RequiresApi)

Example 87 with CancellationSignal

use of android.os.CancellationSignal in project apollo by muun.

the class MuunLockOverlay method enableFingerprintOnApi23.

@RequiresApi(api = Build.VERSION_CODES.M)
private void enableFingerprintOnApi23() {
    final FingerprintManager fingerprintManager = (FingerprintManager) getContext().getSystemService(Context.FINGERPRINT_SERVICE);
    final boolean canEnableFingerprint = (fingerprintManager != null) && fingerprintManager.isHardwareDetected() && fingerprintManager.hasEnrolledFingerprints();
    if (!canEnableFingerprint) {
        return;
    }
    final FingerprintCallback listener = new FingerprintCallback();
    cancelFingerprint = new CancellationSignal();
    fingerprintManager.authenticate(// No CryptoObject, we won't sign or encrypt with fingerprints
    null, // A CancellationSignal to stop listening
    cancelFingerprint, // No flags (fun fact: none actually existed when I wrote this)
    0, // Our custom bag of friendly callbacks
    listener, // No special Handler, use the default
    null);
    isFingerprintEnabled = true;
}
Also used : FingerprintManager(android.hardware.fingerprint.FingerprintManager) CancellationSignal(android.os.CancellationSignal) RequiresApi(androidx.annotation.RequiresApi)

Example 88 with CancellationSignal

use of android.os.CancellationSignal in project Ehviewer_CN_SXJ by xiaojieonly.

the class SecurityScene method onResume.

@Override
public void onResume() {
    super.onResume();
    if (null != mShakeDetector) {
        mSensorManager.registerListener(mShakeDetector, mAccelerometer, SensorManager.SENSOR_DELAY_UI);
    }
    if (isFingerprintAuthAvailable()) {
        mFingerprintCancellationSignal = new CancellationSignal();
        // The line below prevents the false positive inspection from Android Studio
        // noinspection ResourceType
        mFingerprintManager.authenticate(null, mFingerprintCancellationSignal, 0, new FingerprintManager.AuthenticationCallback() {

            @Override
            public void onAuthenticationError(int errMsgId, CharSequence errString) {
                fingerprintError(true);
            }

            @Override
            public void onAuthenticationFailed() {
                fingerprintError(false);
            }

            @Override
            public void onAuthenticationSucceeded(FingerprintManager.AuthenticationResult result) {
                mFingerprintIcon.setImageResource(R.drawable.fingerprint_success);
                mFingerprintIcon.postDelayed(new Runnable() {

                    @Override
                    public void run() {
                        startSceneForCheckStep(CHECK_STEP_SECURITY, getArguments());
                        finish();
                    }
                }, SUCCESS_DELAY_MILLIS);
            }
        }, null);
    }
}
Also used : FingerprintManager(android.hardware.fingerprint.FingerprintManager) CancellationSignal(android.os.CancellationSignal)

Example 89 with CancellationSignal

use of android.os.CancellationSignal in project Neo-Launcher by NeoApplications.

the class WidgetPreviewLoader method getPreview.

/**
 * Generates the widget preview on {@link AsyncTask#THREAD_POOL_EXECUTOR}. Must be
 * called on UI thread
 *
 * @return a request id which can be used to cancel the request.
 */
public CancellationSignal getPreview(WidgetItem item, int previewWidth, int previewHeight, WidgetCell caller) {
    String size = previewWidth + "x" + previewHeight;
    WidgetCacheKey key = new WidgetCacheKey(item.componentName, item.user, size);
    PreviewLoadTask task = new PreviewLoadTask(key, item, previewWidth, previewHeight, caller);
    task.executeOnExecutor(Executors.THREAD_POOL_EXECUTOR);
    CancellationSignal signal = new CancellationSignal();
    signal.setOnCancelListener(task);
    return signal;
}
Also used : CancellationSignal(android.os.CancellationSignal)

Example 90 with CancellationSignal

use of android.os.CancellationSignal in project Neo-Launcher by NeoApplications.

the class FloatingIconView method checkIconResult.

/**
 * Checks if the icon result is loaded. If true, we set the icon immediately. Else, we add a
 * callback to set the icon once the icon result is loaded.
 */
private void checkIconResult(View originalView) {
    CancellationSignal cancellationSignal = new CancellationSignal();
    if (mIconLoadResult == null) {
        Log.w(TAG, "No icon load result found in checkIconResult");
        return;
    }
    synchronized (mIconLoadResult) {
        if (mIconLoadResult.isIconLoaded) {
            setIcon(originalView, mIconLoadResult.drawable, mIconLoadResult.badge, mIconLoadResult.iconOffset);
            hideOriginalView(originalView);
        } else {
            mIconLoadResult.onIconLoaded = () -> {
                if (cancellationSignal.isCanceled()) {
                    return;
                }
                setIcon(originalView, mIconLoadResult.drawable, mIconLoadResult.badge, mIconLoadResult.iconOffset);
                setVisibility(VISIBLE);
                hideOriginalView(originalView);
            };
            mLoadIconSignal = cancellationSignal;
        }
    }
}
Also used : CancellationSignal(android.os.CancellationSignal)

Aggregations

CancellationSignal (android.os.CancellationSignal)170 Cursor (android.database.Cursor)22 Test (org.junit.Test)21 BiometricPrompt (android.hardware.biometrics.BiometricPrompt)20 OperationCanceledException (android.os.OperationCanceledException)18 ParcelFileDescriptor (android.os.ParcelFileDescriptor)17 Handler (android.os.Handler)15 KeyguardManager (android.app.KeyguardManager)14 Intent (android.content.Intent)14 FingerprintManager (android.hardware.fingerprint.FingerprintManager)14 Bundle (android.os.Bundle)14 Activity (android.app.Activity)12 PrintAttributes (android.print.PrintAttributes)12 PrintDocumentAdapter (android.print.PrintDocumentAdapter)12 PrintJob (android.print.PrintJob)12 PrintManager (android.print.PrintManager)12 UiDevice (android.support.test.uiautomator.UiDevice)12 UiObject2 (android.support.test.uiautomator.UiObject2)12 LargeTest (androidx.test.filters.LargeTest)12 UUID (java.util.UUID)12