@SuppressWarnings("SameParameterValue") @Nullable static PowerManager.WakeLock acquireWakeLock(@NonNull Context context, @NonNull String tag, long timeoutMillis) { PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE); PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, tag); wakeLock.setReferenceCounted(false); return acquireWakeLock(context, wakeLock, timeoutMillis) ? wakeLock : null; }
private static void acquireWakeLockAndSendMessage(Context context, Message msg, long delay) { if (mWakeLock == null) { Context appContext = context.getApplicationContext(); PowerManager pm = (PowerManager) appContext.getSystemService(Context.POWER_SERVICE); mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Timber headset button"); mWakeLock.setReferenceCounted(false); } if (DEBUG) Log.v(TAG, "Acquiring wake lock and sending " + msg.what); // Make sure we don't indefinitely hold the wake lock under any circumstances mWakeLock.acquire(10000); mHandler.sendMessageDelayed(msg, delay); }
private static void acquireWakeLockAndSendMessage(Context context, Message msg, long delay) { if (mWakeLock == null) { Context appContext = context.getApplicationContext(); PowerManager pm = (PowerManager) appContext.getSystemService(Context.POWER_SERVICE); mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Timber headset button"); mWakeLock.setReferenceCounted(false); } if (DEBUG) Log.v(TAG, "Acquiring wake lock and sending " + msg.what); // Make sure we don't indefinitely hold the wake lock under any circumstances mWakeLock.acquire(10000); mHandler.sendMessageDelayed(msg, delay); }
private static void acquireWakeLockAndSendMessage(Context context, Message msg, long delay) { if (mWakeLock == null) { Context appContext = context.getApplicationContext(); PowerManager pm = (PowerManager) appContext.getSystemService(Context.POWER_SERVICE); mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Timber headset button"); mWakeLock.setReferenceCounted(false); } if (DEBUG) Log.v(TAG, "Acquiring wake lock and sending " + msg.what); // Make sure we don't indefinitely hold the wake lock under any circumstances mWakeLock.acquire(10000); mHandler.sendMessageDelayed(msg, delay); }
public void initManager() { mPowerManager = (PowerManager) CommonApp.getContext().getSystemService(Context.POWER_SERVICE); mWakeLockRead = mPowerManager.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, "SCREEN_ON"); mWakeLockRead.setReferenceCounted(false); }
@Override protected void onDestroy() { if (wakeLock != null && wakeLock.isHeld()) { wakeLock.setReferenceCounted(false); wakeLock.release(); } super.onDestroy(); }
private static final String NAME = "com.commonsware.cwac.wakeful.WakefulIntentService"; private static volatile PowerManager.WakeLock lockStatic = null; private static PowerManager.WakeLock lock; // Needed since network will to work when device is sleeping. synchronized private static PowerManager.WakeLock getLock(Context context) { if (lockStatic == null) { PowerManager mgr = (PowerManager) context.getSystemService(Context.POWER_SERVICE); lockStatic = mgr.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, NAME); lockStatic.setReferenceCounted(true); } return (lockStatic); } }
private void setupLocks() { mWifiLock = ((WifiManager) service.getApplicationContext().getSystemService(Context.WIFI_SERVICE)) .createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF, Config.wifiLockTag); mWifiLock.setReferenceCounted(false); PowerManager pm = (PowerManager) service.getApplicationContext().getSystemService(Context.POWER_SERVICE); mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, Config.wakeLockTag); mWakeLock.setReferenceCounted(false); mNotificationManager = (NotificationManager) service.getApplicationContext().getSystemService(NOTIFICATION_SERVICE); }
private synchronized void createWakeLock() { // Create a new wake lock if we haven't made one yet. if (mWakeLock == null) { PowerManager pm = (PowerManager)getSystemService(Context.POWER_SERVICE); mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MMS Connectivity"); mWakeLock.setReferenceCounted(false); } }
@Override protected void onDestroy() { stopRing(); if (wakeLock != null && wakeLock.isHeld()) { wakeLock.setReferenceCounted(false); wakeLock.release(); } super.onDestroy(); }
if(powerManager.isWakeLockLevelSupported(PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK)) { PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK, TAG); wakeLock.setReferenceCounted(false); return wakeLock; } else { return null; } }
mWakeLock.setReferenceCounted(false); if (washeld) { mWakeLock.acquire();
if (pm != null) { wakeLock = pm.newWakeLock(mode | PowerManager.ON_AFTER_RELEASE, ExoMediaPlayer.class.getName()); wakeLock.setReferenceCounted(false); } else { Log.e(TAG, "Unable to acquire WAKE_LOCK due to a null power manager");
mWakeLock.setReferenceCounted(false);
mWakeLock.setReferenceCounted(false);
@Override public void onCreate() { super.onCreate(); PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE); wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG); wakeLock.setReferenceCounted(false); if (!wakeLock.isHeld()) wakeLock.acquire(); if (UPLOAD_POOL_SIZE <= 0) { UPLOAD_POOL_SIZE = Runtime.getRuntime().availableProcessors(); } // Creates a thread pool manager uploadThreadPool = new ThreadPoolExecutor( UPLOAD_POOL_SIZE, // Initial pool size UPLOAD_POOL_SIZE, // Max pool size KEEP_ALIVE_TIME_IN_SECONDS, TimeUnit.SECONDS, uploadTasksQueue); }
@Override public void setReferenceCounted(boolean counted) { synchronized (wakeLock) { wakeLock.setReferenceCounted(counted); } }
CompatWorkEnqueuer(Context context, ComponentName cn) { super(context, cn); mContext = context.getApplicationContext(); if (mContext.checkPermission(Manifest.permission.WAKE_LOCK, Process.myPid(), Process.myUid()) == PackageManager.PERMISSION_GRANTED) { // Make wake locks. We need two, because the launch wake lock wants to have // a timeout, and the system does not do the right thing if you mix timeout and // non timeout (or even changing the timeout duration) in one wake lock. PowerManager pm = ((PowerManager) context.getSystemService(Context.POWER_SERVICE)); mLaunchWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, cn.getClassName() + ":launch"); mLaunchWakeLock.setReferenceCounted(false); mRunWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, cn.getClassName() + ":run"); mRunWakeLock.setReferenceCounted(false); } else { TinkerLog.w(TAG, "it would be better to grant WAKE_LOCK permission to your app so that tinker can use WakeLock to keep system awake."); mLaunchWakeLock = mRunWakeLock = null; } }
@Test public void newWakeLock_shouldAcquireAndReleaseNonReferenceCountedLock() throws Exception { PowerManager.WakeLock lock = powerManager.newWakeLock(0, "TAG"); lock.setReferenceCounted(false); assertThat(lock.isHeld()).isFalse(); lock.acquire(); assertThat(lock.isHeld()).isTrue(); lock.acquire(); assertThat(lock.isHeld()).isTrue(); lock.release(); assertThat(lock.isHeld()).isFalse(); }
@Test public void isReferenceCounted_shouldGetAndSet() throws Exception { PowerManager.WakeLock lock = powerManager.newWakeLock(0, "TAG"); assertThat(shadowOf(lock).isReferenceCounted()).isTrue(); lock.setReferenceCounted(false); assertThat(shadowOf(lock).isReferenceCounted()).isFalse(); lock.setReferenceCounted(true); assertThat(shadowOf(lock).isReferenceCounted()).isTrue(); }