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