use of androidx.annotation.WorkerThread in project android-beacon-library by AltBeacon.
the class CycledLeScannerForLollipop method postStopLeScan.
private void postStopLeScan() {
if (!isBluetoothOn()) {
LogManager.d(TAG, "Not stopping scan because bluetooth is off");
return;
}
final BluetoothLeScanner scanner = getScanner();
if (scanner == null) {
return;
}
final ScanCallback scanCallback = getNewLeScanCallback();
mScanHandler.removeCallbacksAndMessages(null);
mScanHandler.post(new Runnable() {
@WorkerThread
@Override
public void run() {
try {
LogManager.d(TAG, "Stopping LE scan on scan handler");
scanner.stopScan(scanCallback);
} catch (IllegalStateException e) {
LogManager.w(TAG, "Cannot stop scan. Bluetooth may be turned off.");
} catch (NullPointerException npe) {
// Necessary because of https://code.google.com/p/android/issues/detail?id=160503
LogManager.e(npe, TAG, "Cannot stop scan. Unexpected NPE.");
} catch (SecurityException e) {
// Thrown by Samsung Knox devices if bluetooth access denied for an app
LogManager.e(TAG, "Cannot stop scan. Security Exception", e);
}
}
});
}
use of androidx.annotation.WorkerThread in project android-beacon-library by AltBeacon.
the class CycledLeScannerForLollipop method postStartLeScan.
private void postStartLeScan(final List<ScanFilter> filters, final ScanSettings settings) {
final BluetoothLeScanner scanner = getScanner();
if (scanner == null) {
return;
}
final ScanCallback scanCallback = getNewLeScanCallback();
mScanHandler.removeCallbacksAndMessages(null);
mScanHandler.post(new Runnable() {
@WorkerThread
@Override
public void run() {
try {
scanner.startScan(filters, settings, scanCallback);
} catch (IllegalStateException e) {
LogManager.w(TAG, "Cannot start scan. Bluetooth may be turned off.");
} catch (NullPointerException npe) {
// Necessary because of https://code.google.com/p/android/issues/detail?id=160503
LogManager.e(npe, TAG, "Cannot start scan. Unexpected NPE.");
} catch (SecurityException e) {
// Thrown by Samsung Knox devices if bluetooth access denied for an app
LogManager.e(TAG, "Cannot start scan. Security Exception: " + e.getMessage(), e);
}
}
});
}
use of androidx.annotation.WorkerThread in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class UserSettings method copyMeProfilePhoto.
@WorkerThread
static void copyMeProfilePhoto(Context context, UserInfo user) {
Uri contactUri = ContactsContract.Profile.CONTENT_URI;
int userId = user != null ? user.id : UserHandle.myUserId();
InputStream avatarDataStream = ContactsContract.Contacts.openContactPhotoInputStream(context.getContentResolver(), contactUri, true);
// If there's no profile photo, assign a default avatar
if (avatarDataStream == null) {
assignDefaultPhoto(context, userId);
return;
}
UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);
Bitmap icon = BitmapFactory.decodeStream(avatarDataStream);
um.setUserIcon(userId, icon);
try {
avatarDataStream.close();
} catch (IOException ioe) {
}
}
use of androidx.annotation.WorkerThread in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class BatteryFixSlice method refreshBatteryTips.
@WorkerThread
private static List<BatteryTip> refreshBatteryTips(Context context) {
final BatteryStatsHelperLoader statsLoader = new BatteryStatsHelperLoader(context);
final BatteryStatsHelper statsHelper = statsLoader.loadInBackground();
final BatteryTipLoader loader = new BatteryTipLoader(context, statsHelper);
final List<BatteryTip> batteryTips = loader.loadInBackground();
for (BatteryTip batteryTip : batteryTips) {
if (batteryTip.getState() != BatteryTip.StateType.INVISIBLE) {
context.getSharedPreferences(PREFS, MODE_PRIVATE).edit().putInt(KEY_CURRENT_TIPS_TYPE, batteryTip.getType()).putInt(KEY_CURRENT_TIPS_STATE, batteryTip.getState()).apply();
break;
}
}
return batteryTips;
}
use of androidx.annotation.WorkerThread in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class BatteryUtils method getBatteryInfo.
@WorkerThread
public BatteryInfo getBatteryInfo(final BatteryStatsHelper statsHelper, final String tag) {
final long startTime = System.currentTimeMillis();
// Stuff we always need to get BatteryInfo
final Intent batteryBroadcast = mContext.registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
final long elapsedRealtimeUs = PowerUtil.convertMsToUs(SystemClock.elapsedRealtime());
final BatteryStats stats = statsHelper.getStats();
BatteryInfo batteryInfo;
Estimate estimate = getEnhancedEstimate();
// couldn't get estimate from cache or provider, use fallback
if (estimate == null) {
estimate = new Estimate(PowerUtil.convertUsToMs(stats.computeBatteryTimeRemaining(elapsedRealtimeUs)), false, /* isBasedOnUsage */
EstimateKt.AVERAGE_TIME_TO_DISCHARGE_UNKNOWN);
}
BatteryUtils.logRuntime(tag, "BatteryInfoLoader post query", startTime);
batteryInfo = BatteryInfo.getBatteryInfo(mContext, batteryBroadcast, stats, estimate, elapsedRealtimeUs, false);
BatteryUtils.logRuntime(tag, "BatteryInfoLoader.loadInBackground", startTime);
return batteryInfo;
}
Aggregations