Search in sources :

Example 76 with CancellationSignal

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

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 77 with CancellationSignal

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

the class BiometricEnrollSidecar method startEnrollment.

protected void startEnrollment() {
    mHandler.removeCallbacks(mTimeoutRunnable);
    mEnrollmentSteps = -1;
    mEnrollmentCancel = new CancellationSignal();
    mEnrolling = true;
}
Also used : CancellationSignal(android.os.CancellationSignal)

Example 78 with CancellationSignal

use of android.os.CancellationSignal in project LearningApps by evitwilly.

the class NoteDao_Impl method notesByCreatedDate.

@Override
public Object notesByCreatedDate(final Continuation<? super List<NoteWithTags>> continuation) {
    final String _sql = "select * from notes order by created_date";
    final RoomSQLiteQuery _statement = RoomSQLiteQuery.acquire(_sql, 0);
    final CancellationSignal _cancellationSignal = DBUtil.createCancellationSignal();
    return CoroutinesRoom.execute(__db, true, _cancellationSignal, new Callable<List<NoteWithTags>>() {

        @Override
        public List<NoteWithTags> call() throws Exception {
            __db.beginTransaction();
            try {
                final Cursor _cursor = DBUtil.query(__db, _statement, true, null);
                try {
                    final int _cursorIndexOfTitle = CursorUtil.getColumnIndexOrThrow(_cursor, "title");
                    final int _cursorIndexOfCreatedDate = CursorUtil.getColumnIndexOrThrow(_cursor, "created_date");
                    final int _cursorIndexOfEditedDate = CursorUtil.getColumnIndexOrThrow(_cursor, "edited_date");
                    final int _cursorIndexOfId = CursorUtil.getColumnIndexOrThrow(_cursor, "id");
                    final LongSparseArray<ArrayList<Tag>> _collectionTags = new LongSparseArray<ArrayList<Tag>>();
                    while (_cursor.moveToNext()) {
                        final long _tmpKey = _cursor.getLong(_cursorIndexOfId);
                        ArrayList<Tag> _tmpTagsCollection = _collectionTags.get(_tmpKey);
                        if (_tmpTagsCollection == null) {
                            _tmpTagsCollection = new ArrayList<Tag>();
                            _collectionTags.put(_tmpKey, _tmpTagsCollection);
                        }
                    }
                    _cursor.moveToPosition(-1);
                    __fetchRelationshiptagsAsruFreeitNotesDataDbEntityTag(_collectionTags);
                    final List<NoteWithTags> _result = new ArrayList<NoteWithTags>(_cursor.getCount());
                    while (_cursor.moveToNext()) {
                        final NoteWithTags _item;
                        final Note _tmpNote;
                        if (!(_cursor.isNull(_cursorIndexOfTitle) && _cursor.isNull(_cursorIndexOfCreatedDate) && _cursor.isNull(_cursorIndexOfEditedDate) && _cursor.isNull(_cursorIndexOfId))) {
                            final String _tmpTitle;
                            if (_cursor.isNull(_cursorIndexOfTitle)) {
                                _tmpTitle = null;
                            } else {
                                _tmpTitle = _cursor.getString(_cursorIndexOfTitle);
                            }
                            final long _tmpCreatedDate;
                            _tmpCreatedDate = _cursor.getLong(_cursorIndexOfCreatedDate);
                            final long _tmpEditedDate;
                            _tmpEditedDate = _cursor.getLong(_cursorIndexOfEditedDate);
                            final long _tmpId;
                            _tmpId = _cursor.getLong(_cursorIndexOfId);
                            _tmpNote = new Note(_tmpTitle, _tmpCreatedDate, _tmpEditedDate, _tmpId);
                        } else {
                            _tmpNote = null;
                        }
                        ArrayList<Tag> _tmpTagsCollection_1 = null;
                        final long _tmpKey_1 = _cursor.getLong(_cursorIndexOfId);
                        _tmpTagsCollection_1 = _collectionTags.get(_tmpKey_1);
                        if (_tmpTagsCollection_1 == null) {
                            _tmpTagsCollection_1 = new ArrayList<Tag>();
                        }
                        _item = new NoteWithTags(_tmpNote, _tmpTagsCollection_1);
                        _result.add(_item);
                    }
                    __db.setTransactionSuccessful();
                    return _result;
                } finally {
                    _cursor.close();
                    _statement.release();
                }
            } finally {
                __db.endTransaction();
            }
        }
    }, continuation);
}
Also used : LongSparseArray(androidx.collection.LongSparseArray) ArrayList(java.util.ArrayList) NoteWithTags(ru.freeit.notes.data.db.entity.NoteWithTags) String(java.lang.String) RoomSQLiteQuery(androidx.room.RoomSQLiteQuery) Cursor(android.database.Cursor) Exception(java.lang.Exception) Note(ru.freeit.notes.data.db.entity.Note) ArrayList(java.util.ArrayList) List(java.util.List) Tag(ru.freeit.notes.data.db.entity.Tag) CancellationSignal(android.os.CancellationSignal) Override(java.lang.Override) Override(java.lang.Override)

Example 79 with CancellationSignal

use of android.os.CancellationSignal in project LearningApps by evitwilly.

the class NoteDao_Impl method notes.

@Override
public Object notes(final Continuation<? super List<NoteWithTags>> continuation) {
    final String _sql = "select * from notes";
    final RoomSQLiteQuery _statement = RoomSQLiteQuery.acquire(_sql, 0);
    final CancellationSignal _cancellationSignal = DBUtil.createCancellationSignal();
    return CoroutinesRoom.execute(__db, true, _cancellationSignal, new Callable<List<NoteWithTags>>() {

        @Override
        public List<NoteWithTags> call() throws Exception {
            __db.beginTransaction();
            try {
                final Cursor _cursor = DBUtil.query(__db, _statement, true, null);
                try {
                    final int _cursorIndexOfTitle = CursorUtil.getColumnIndexOrThrow(_cursor, "title");
                    final int _cursorIndexOfCreatedDate = CursorUtil.getColumnIndexOrThrow(_cursor, "created_date");
                    final int _cursorIndexOfEditedDate = CursorUtil.getColumnIndexOrThrow(_cursor, "edited_date");
                    final int _cursorIndexOfId = CursorUtil.getColumnIndexOrThrow(_cursor, "id");
                    final LongSparseArray<ArrayList<Tag>> _collectionTags = new LongSparseArray<ArrayList<Tag>>();
                    while (_cursor.moveToNext()) {
                        final long _tmpKey = _cursor.getLong(_cursorIndexOfId);
                        ArrayList<Tag> _tmpTagsCollection = _collectionTags.get(_tmpKey);
                        if (_tmpTagsCollection == null) {
                            _tmpTagsCollection = new ArrayList<Tag>();
                            _collectionTags.put(_tmpKey, _tmpTagsCollection);
                        }
                    }
                    _cursor.moveToPosition(-1);
                    __fetchRelationshiptagsAsruFreeitNotesDataDbEntityTag(_collectionTags);
                    final List<NoteWithTags> _result = new ArrayList<NoteWithTags>(_cursor.getCount());
                    while (_cursor.moveToNext()) {
                        final NoteWithTags _item;
                        final Note _tmpNote;
                        if (!(_cursor.isNull(_cursorIndexOfTitle) && _cursor.isNull(_cursorIndexOfCreatedDate) && _cursor.isNull(_cursorIndexOfEditedDate) && _cursor.isNull(_cursorIndexOfId))) {
                            final String _tmpTitle;
                            if (_cursor.isNull(_cursorIndexOfTitle)) {
                                _tmpTitle = null;
                            } else {
                                _tmpTitle = _cursor.getString(_cursorIndexOfTitle);
                            }
                            final long _tmpCreatedDate;
                            _tmpCreatedDate = _cursor.getLong(_cursorIndexOfCreatedDate);
                            final long _tmpEditedDate;
                            _tmpEditedDate = _cursor.getLong(_cursorIndexOfEditedDate);
                            final long _tmpId;
                            _tmpId = _cursor.getLong(_cursorIndexOfId);
                            _tmpNote = new Note(_tmpTitle, _tmpCreatedDate, _tmpEditedDate, _tmpId);
                        } else {
                            _tmpNote = null;
                        }
                        ArrayList<Tag> _tmpTagsCollection_1 = null;
                        final long _tmpKey_1 = _cursor.getLong(_cursorIndexOfId);
                        _tmpTagsCollection_1 = _collectionTags.get(_tmpKey_1);
                        if (_tmpTagsCollection_1 == null) {
                            _tmpTagsCollection_1 = new ArrayList<Tag>();
                        }
                        _item = new NoteWithTags(_tmpNote, _tmpTagsCollection_1);
                        _result.add(_item);
                    }
                    __db.setTransactionSuccessful();
                    return _result;
                } finally {
                    _cursor.close();
                    _statement.release();
                }
            } finally {
                __db.endTransaction();
            }
        }
    }, continuation);
}
Also used : LongSparseArray(androidx.collection.LongSparseArray) ArrayList(java.util.ArrayList) NoteWithTags(ru.freeit.notes.data.db.entity.NoteWithTags) String(java.lang.String) RoomSQLiteQuery(androidx.room.RoomSQLiteQuery) Cursor(android.database.Cursor) Exception(java.lang.Exception) Note(ru.freeit.notes.data.db.entity.Note) ArrayList(java.util.ArrayList) List(java.util.List) Tag(ru.freeit.notes.data.db.entity.Tag) CancellationSignal(android.os.CancellationSignal) Override(java.lang.Override) Override(java.lang.Override)

Example 80 with CancellationSignal

use of android.os.CancellationSignal in project android_packages_apps_Settings by Project-Kaleidoscope.

the class WifiDppUtils 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 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, Runnable successRunnable) {
    final KeyguardManager keyguardManager = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
    if (keyguardManager.isKeyguardSecure()) {
        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.Builder builder = new BiometricPrompt.Builder(context).setTitle(context.getText(R.string.wifi_dpp_lockscreen_title));
        if (keyguardManager.isDeviceSecure()) {
            builder.setDeviceCredentialAllowed(true);
        }
        final BiometricPrompt bp = builder.build();
        final Handler handler = new Handler(Looper.getMainLooper());
        bp.authenticate(new CancellationSignal(), runnable -> handler.post(runnable), authenticationCallback);
    } else {
        successRunnable.run();
    }
}
Also used : BiometricPrompt(android.hardware.biometrics.BiometricPrompt) Handler(android.os.Handler) KeyguardManager(android.app.KeyguardManager) 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