Search in sources :

Example 71 with CancellationSignal

use of android.os.CancellationSignal in project packages_apps_Settings by Evolution-X.

the class PrintJobSettingsActivityTest method viewPrintJobSettings.

@Test
@LargeTest
public void viewPrintJobSettings() throws Exception {
    UUID uuid = UUID.randomUUID();
    Object isWriteCalled = new Object();
    // Create adapter that is good enough to start a print preview
    PrintDocumentAdapter adapter = new PrintDocumentAdapter() {

        @Override
        public void onLayout(PrintAttributes oldAttributes, PrintAttributes newAttributes, CancellationSignal cancellationSignal, LayoutResultCallback callback, Bundle extras) {
            callback.onLayoutFinished(new PrintDocumentInfo.Builder(uuid.toString()).build(), true);
        }

        @Override
        public void onWrite(PageRange[] pages, ParcelFileDescriptor destination, CancellationSignal cancellationSignal, WriteResultCallback callback) {
            synchronized (isWriteCalled) {
                isWriteCalled.notify();
            }
            callback.onWriteFailed(null);
        }
    };
    Activity activity = mActivityRule.getActivity();
    PrintManager pm = mActivityRule.getActivity().getSystemService(PrintManager.class);
    // Start printing
    PrintJob printJob = pm.print(uuid.toString(), adapter, null);
    // Wait until print preview is up
    synchronized (isWriteCalled) {
        isWriteCalled.wait();
    }
    // Start print job settings
    Intent intent = new Intent(android.provider.Settings.ACTION_PRINT_SETTINGS);
    intent.putExtra(EXTRA_PRINT_JOB_ID, printJob.getId().flattenToString());
    intent.setData(Uri.fromParts("printjob", printJob.getId().flattenToString(), null));
    activity.startActivity(intent);
    UiDevice uiDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
    UiObject2 printPrefTitle = uiDevice.wait(Until.findObject(By.text("Configuring " + uuid.toString())), 5000);
    assertNotNull(printPrefTitle);
    Log.i(LOG_TAG, "Found " + printPrefTitle.getText());
}
Also used : PrintJob(android.print.PrintJob) Bundle(android.os.Bundle) UiDevice(android.support.test.uiautomator.UiDevice) Activity(android.app.Activity) Intent(android.content.Intent) PrintAttributes(android.print.PrintAttributes) PrintManager(android.print.PrintManager) ParcelFileDescriptor(android.os.ParcelFileDescriptor) UUID(java.util.UUID) PrintDocumentAdapter(android.print.PrintDocumentAdapter) CancellationSignal(android.os.CancellationSignal) UiObject2(android.support.test.uiautomator.UiObject2) LargeTest(androidx.test.filters.LargeTest) Test(org.junit.Test) LargeTest(androidx.test.filters.LargeTest)

Example 72 with CancellationSignal

use of android.os.CancellationSignal in project cyborg-core by nu-art.

the class FingerprintModule method startListening.

@RequiresPermission(USE_FINGERPRINT)
public void startListening(Cipher cipher) {
    if (!isEnabled() || !hasEnrolledFingerprints()) {
        return;
    }
    if (cancellationSignal != null && !cancellationSignal.isCanceled()) {
        logWarning("Already listening");
        return;
    }
    CryptoObject cryptoObject = new CryptoObject(cipher);
    cancellationSignal = new CancellationSignal();
    // The line below prevents the false positive inspection from Android Studio
    // noinspection ResourceType
    getFingerprintManager().authenticate(cryptoObject, cancellationSignal, 0, /* flags */
    new AuthenticationCallback() {

        @Override
        public void onAuthenticationError(final int errorCode, final CharSequence errString) {
            cancellationSignal = null;
            dispatchGlobalEvent("Authentication help(" + errorCode + "): " + errString, FingerprintAuthenticationListener.class, new Processor<FingerprintAuthenticationListener>() {

                @Override
                public void process(FingerprintAuthenticationListener listener) {
                    listener.onAuthenticationError(errorCode, errString);
                }
            });
        }

        @Override
        public void onAuthenticationHelp(final int helpCode, final CharSequence helpString) {
            dispatchGlobalEvent("Authentication help(" + helpCode + "): " + helpString, FingerprintAuthenticationListener.class, new Processor<FingerprintAuthenticationListener>() {

                @Override
                public void process(FingerprintAuthenticationListener listener) {
                    listener.onAuthenticationHelp(helpCode, helpString);
                }
            });
        }

        @Override
        public void onAuthenticationSucceeded(final AuthenticationResult result) {
            cancellationSignal = null;
            dispatchGlobalEvent("Authentication successful", FingerprintAuthenticationListener.class, new Processor<FingerprintAuthenticationListener>() {

                @Override
                public void process(FingerprintAuthenticationListener listener) {
                    listener.onAuthenticationSucceeded(result);
                }
            });
        }

        @Override
        public void onAuthenticationFailed() {
            dispatchGlobalEvent("Authentication failed", FingerprintAuthenticationListener.class, new Processor<FingerprintAuthenticationListener>() {

                @Override
                public void process(FingerprintAuthenticationListener listener) {
                    listener.onAuthenticationFailed();
                }
            });
        }
    }, handler);
}
Also used : Processor(com.nu.art.core.generics.Processor) AuthenticationCallback(android.hardware.fingerprint.FingerprintManager.AuthenticationCallback) CancellationSignal(android.os.CancellationSignal) CryptoObject(android.hardware.fingerprint.FingerprintManager.CryptoObject) SuppressLint(android.annotation.SuppressLint) AuthenticationResult(android.hardware.fingerprint.FingerprintManager.AuthenticationResult) RequiresPermission(android.support.annotation.RequiresPermission)

Example 73 with CancellationSignal

use of android.os.CancellationSignal in project SightRemote by TebbeUbben.

the class ConfirmationDialog method show.

@SuppressLint("NewApi")
public void show() {
    prepareViews();
    dialog = builder.show();
    dialog.setOnDismissListener((dialogInterface -> onClose()));
    dialog.setOnCancelListener((dialog -> onClose()));
    if (useFingerprint())
        getFingerprintManager().authenticate(null, cancellationSignal = new CancellationSignal(), 0, new FingerprintManager.AuthenticationCallback() {

            @Override
            public void onAuthenticationSucceeded(FingerprintManager.AuthenticationResult result) {
                onConfirm();
            }

            @Override
            public void onAuthenticationFailed() {
                fingerprintIcon.getBackground().setColorFilter(ContextCompat.getColor(SightRemote.getInstance(), R.color.colorWrong), PorterDuff.Mode.MULTIPLY);
                fingerprintText.setText(R.string.couldnt_recognize_fingerprint);
                fingerprintText.setTextColor(ContextCompat.getColor(SightRemote.getInstance(), R.color.colorWrong));
            }
        }, null);
    if (getBooleanPref(PREF_BOOLEAN_ENABLE_CONFIRMATION_CHALLENGES))
        pin.requestFocus();
}
Also used : Context(android.content.Context) LinearLayout(android.widget.LinearLayout) PREF_BOOLEAN_CONFIRMATION_USE_FINGERPRINT(sugar.free.sightremote.utils.Preferences.PREF_BOOLEAN_CONFIRMATION_USE_FINGERPRINT) Spanned(android.text.Spanned) PackageManager(android.content.pm.PackageManager) RequiresApi(android.support.annotation.RequiresApi) Preferences.getStringPref(sugar.free.sightremote.utils.Preferences.getStringPref) Editable(android.text.Editable) ArrayList(java.util.ArrayList) Manifest(android.Manifest) SuppressLint(android.annotation.SuppressLint) Handler(android.os.Handler) Looper(android.os.Looper) View(android.view.View) Button(android.widget.Button) PREF_STRING_CONFIRMATION_PIN(sugar.free.sightremote.utils.Preferences.PREF_STRING_CONFIRMATION_PIN) Preferences.getBooleanPref(sugar.free.sightremote.utils.Preferences.getBooleanPref) Build(android.os.Build) DialogInterface(android.content.DialogInterface) LayoutInflater(android.view.LayoutInflater) CancellationSignal(android.os.CancellationSignal) ContextCompat(android.support.v4.content.ContextCompat) HTMLUtil(sugar.free.sightremote.utils.HTMLUtil) PREF_BOOLEAN_ENABLE_CONFIRMATION_CHALLENGES(sugar.free.sightremote.utils.Preferences.PREF_BOOLEAN_ENABLE_CONFIRMATION_CHALLENGES) FingerprintManager(android.hardware.fingerprint.FingerprintManager) PREF_BOOLEAN_CONFIRMATION_USE_PIN(sugar.free.sightremote.utils.Preferences.PREF_BOOLEAN_CONFIRMATION_USE_PIN) PorterDuff(android.graphics.PorterDuff) List(java.util.List) R(sugar.free.sightremote.R) AlertDialog(android.support.v7.app.AlertDialog) TextView(android.widget.TextView) Vibrator(android.os.Vibrator) SightRemote(sugar.free.sightremote.SightRemote) Collections(java.util.Collections) TextWatcher(android.text.TextWatcher) CancellationSignal(android.os.CancellationSignal) SuppressLint(android.annotation.SuppressLint)

Example 74 with CancellationSignal

use of android.os.CancellationSignal in project platform_packages_apps_Settings by BlissRoms.

the class FingerprintEnrollSidecar method startEnrollment.

private void startEnrollment() {
    mHandler.removeCallbacks(mTimeoutRunnable);
    mEnrollmentSteps = -1;
    mEnrollmentCancel = new CancellationSignal();
    getActivity().getSystemService(FingerprintManager.class).enroll(mToken, mEnrollmentCancel, 0, /* flags */
    mEnrollmentCallback);
    mEnrolling = true;
}
Also used : FingerprintManager(android.hardware.fingerprint.FingerprintManager) CancellationSignal(android.os.CancellationSignal)

Example 75 with CancellationSignal

use of android.os.CancellationSignal in project platform_packages_apps_Settings by AospExtended.

the class BiometricFragment method onResume.

@Override
public void onResume() {
    super.onResume();
    if (mCancellationSignal == null) {
        mCancellationSignal = new CancellationSignal();
        mBiometricPrompt.authenticateUser(mCancellationSignal, mClientExecutor, mAuthenticationCallback, mUserId);
    }
}
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