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();
}
}
}
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;
}
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);
}
}
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;
}
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;
}
}
}
Aggregations