Search in sources :

Example 96 with WorkerThread

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);
            }
        }
    });
}
Also used : BluetoothLeScanner(android.bluetooth.le.BluetoothLeScanner) WorkerThread(androidx.annotation.WorkerThread) ScanCallback(android.bluetooth.le.ScanCallback)

Example 97 with WorkerThread

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);
            }
        }
    });
}
Also used : BluetoothLeScanner(android.bluetooth.le.BluetoothLeScanner) WorkerThread(androidx.annotation.WorkerThread) ScanCallback(android.bluetooth.le.ScanCallback)

Example 98 with WorkerThread

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) {
    }
}
Also used : Bitmap(android.graphics.Bitmap) InputStream(java.io.InputStream) UserManager(android.os.UserManager) IOException(java.io.IOException) Uri(android.net.Uri) WorkerThread(androidx.annotation.WorkerThread)

Example 99 with WorkerThread

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;
}
Also used : BatteryTipLoader(com.android.settings.fuelgauge.batterytip.BatteryTipLoader) BatteryStatsHelperLoader(com.android.settings.fuelgauge.BatteryStatsHelperLoader) BatteryStatsHelper(com.android.internal.os.BatteryStatsHelper) BatteryTip(com.android.settings.fuelgauge.batterytip.tips.BatteryTip) WorkerThread(androidx.annotation.WorkerThread)

Example 100 with WorkerThread

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;
}
Also used : IntentFilter(android.content.IntentFilter) Estimate(com.android.settingslib.fuelgauge.Estimate) Intent(android.content.Intent) BatteryStats(android.os.BatteryStats) WorkerThread(androidx.annotation.WorkerThread)

Aggregations

WorkerThread (androidx.annotation.WorkerThread)365 NonNull (androidx.annotation.NonNull)151 IOException (java.io.IOException)83 Recipient (org.thoughtcrime.securesms.recipients.Recipient)82 Nullable (androidx.annotation.Nullable)51 RecipientId (org.thoughtcrime.securesms.recipients.RecipientId)46 Cursor (android.database.Cursor)41 ArrayList (java.util.ArrayList)41 Context (android.content.Context)39 Uri (android.net.Uri)32 LinkedList (java.util.LinkedList)30 List (java.util.List)30 RecipientDatabase (org.thoughtcrime.securesms.database.RecipientDatabase)28 Stream (com.annimon.stream.Stream)26 HashMap (java.util.HashMap)26 Log (org.signal.core.util.logging.Log)26 HashSet (java.util.HashSet)24 Map (java.util.Map)21 Collections (java.util.Collections)20 ApplicationDependencies (org.thoughtcrime.securesms.dependencies.ApplicationDependencies)20