Search in sources :

Example 61 with CancellationSignal

use of android.os.CancellationSignal in project android_packages_apps_Launcher3 by crdroidandroid.

the class LauncherInitListener method handleInit.

@Override
public boolean handleInit(Launcher launcher, boolean alreadyOnHome) {
    if (mRemoteAnimationProvider != null) {
        QuickstepTransitionManager appTransitionManager = ((BaseQuickstepLauncher) launcher).getAppTransitionManager();
        // Set a one-time animation provider. After the first call, this will get cleared.
        // TODO: Probably also check the intended target id.
        CancellationSignal cancellationSignal = new CancellationSignal();
        appTransitionManager.setRemoteAnimationProvider(new RemoteAnimationProvider() {

            @Override
            public AnimatorSet createWindowAnimation(RemoteAnimationTargetCompat[] appTargets, RemoteAnimationTargetCompat[] wallpaperTargets) {
                // On the first call clear the reference.
                cancellationSignal.cancel();
                RemoteAnimationProvider provider = mRemoteAnimationProvider;
                mRemoteAnimationProvider = null;
                if (provider != null && launcher.getStateManager().getState().overviewUi) {
                    return provider.createWindowAnimation(appTargets, wallpaperTargets);
                }
                return null;
            }
        }, cancellationSignal);
    }
    launcher.deferOverlayCallbacksUntilNextResumeOrStop();
    return super.handleInit(launcher, alreadyOnHome);
}
Also used : RemoteAnimationTargetCompat(com.android.systemui.shared.system.RemoteAnimationTargetCompat) AnimatorSet(android.animation.AnimatorSet) CancellationSignal(android.os.CancellationSignal) RemoteAnimationProvider(com.android.quickstep.util.RemoteAnimationProvider)

Example 62 with CancellationSignal

use of android.os.CancellationSignal in project android_packages_apps_Launcher3 by crdroidandroid.

the class LineageUtils method showLockScreen.

/**
 * Shows authentication screen to confirm credentials (pin, pattern or password) for the current
 * user of the device.
 *
 * @param context The {@code Context} used to get {@code KeyguardManager} service
 * @param title the {@code String} which will be shown as the pompt title
 * @param successRunnable The {@code Runnable} which will be executed if the user does not setup
 *                        device security or if lock screen is unlocked
 */
public static void showLockScreen(Context context, String title, Runnable successRunnable) {
    if (hasSecureKeyguard(context)) {
        final BiometricPrompt.AuthenticationCallback authenticationCallback = new BiometricPrompt.AuthenticationCallback() {

            @Override
            public void onAuthenticationSucceeded(BiometricPrompt.AuthenticationResult result) {
                successRunnable.run();
            }

            @Override
            public void onAuthenticationError(int errorCode, CharSequence errString) {
            // Do nothing
            }
        };
        final BiometricPrompt bp = new BiometricPrompt.Builder(context).setTitle(title).setAllowedAuthenticators(Authenticators.BIOMETRIC_STRONG | Authenticators.DEVICE_CREDENTIAL).build();
        final Handler handler = new Handler(Looper.getMainLooper());
        bp.authenticate(new CancellationSignal(), runnable -> handler.post(runnable), authenticationCallback);
    } else {
        // Notify the user a secure keyguard is required for protected apps,
        // but allow to set hidden apps
        Toast.makeText(context, R.string.trust_apps_no_lock_error, Toast.LENGTH_LONG).show();
        successRunnable.run();
    }
}
Also used : BiometricPrompt(android.hardware.biometrics.BiometricPrompt) Handler(android.os.Handler) CancellationSignal(android.os.CancellationSignal)

Example 63 with CancellationSignal

use of android.os.CancellationSignal in project android_packages_apps_Launcher3 by crdroidandroid.

the class DatabaseWidgetPreviewLoader method loadPreview.

/**
 * 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.
 */
@Override
@NonNull
public CancellationSignal loadPreview(@NonNull BaseActivity activity, @NonNull WidgetItem item, @NonNull Size previewSize, @NonNull WidgetPreviewLoadedCallback callback) {
    int previewWidth = previewSize.getWidth();
    int previewHeight = previewSize.getHeight();
    String size = previewWidth + "x" + previewHeight;
    WidgetCacheKey key = new WidgetCacheKey(item.componentName, item.user, size);
    PreviewLoadTask task = new PreviewLoadTask(activity, key, item, previewWidth, previewHeight, callback);
    task.executeOnExecutor(Executors.THREAD_POOL_EXECUTOR);
    CancellationSignal signal = new CancellationSignal();
    signal.setOnCancelListener(task);
    return signal;
}
Also used : CancellationSignal(android.os.CancellationSignal) Paint(android.graphics.Paint) NonNull(androidx.annotation.NonNull)

Example 64 with CancellationSignal

use of android.os.CancellationSignal in project android_packages_apps_Launcher3 by crdroidandroid.

the class CachingWidgetPreviewLoaderTest method loadPreview_thenLoaded_thenCancelled_shouldNotRemovePreviewFromCache.

@Test
public void loadPreview_thenLoaded_thenCancelled_shouldNotRemovePreviewFromCache() {
    CancellationSignal cancellationSignal = mLoader.loadPreview(mTestActivity, mWidgetItem, SIZE_10_10, mPreviewLoadedCallback);
    verify(mDelegate).loadPreview(any(), any(), any(), mCallbackCaptor.capture());
    WidgetPreviewLoadedCallback loaderCallback = mCallbackCaptor.getValue();
    loaderCallback.onPreviewLoaded(BITMAP);
    cancellationSignal.cancel();
    assertThat(mLoader.getPreview(mWidgetItem, SIZE_10_10)).isEqualTo(BITMAP);
}
Also used : WidgetPreviewLoadedCallback(com.android.launcher3.widget.WidgetPreviewLoader.WidgetPreviewLoadedCallback) CancellationSignal(android.os.CancellationSignal) Test(org.junit.Test)

Example 65 with CancellationSignal

use of android.os.CancellationSignal in project android_packages_apps_Launcher3 by crdroidandroid.

the class CachingWidgetPreviewLoaderTest method loadPreview_thenCancelled_shouldCancelDelegateRequest.

@Test
public void loadPreview_thenCancelled_shouldCancelDelegateRequest() {
    CancellationSignal cancellationSignal = mLoader.loadPreview(mTestActivity, mWidgetItem, SIZE_10_10, mPreviewLoadedCallback);
    cancellationSignal.cancel();
    verify(mCancellationSignal).cancel();
    verifyZeroInteractions(mPreviewLoadedCallback);
    assertThat(mLoader.getPreview(mWidgetItem, SIZE_10_10)).isNull();
}
Also used : CancellationSignal(android.os.CancellationSignal) Test(org.junit.Test)

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