Java Code Examples for android.os.PowerManager.WakeLock#release()
The following examples show how to use
android.os.PowerManager.WakeLock#release() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WakeLockUtil.java From mollyim-android with GNU General Public License v3.0 | 6 votes |
/** * @param tag will be prefixed with "signal:" if it does not already start with it. */ public static void release(@Nullable WakeLock wakeLock, @NonNull String tag) { tag = prefixTag(tag); try { if (wakeLock == null) { Log.d(TAG, "Wakelock was null. Skipping. Tag: " + tag); } else if (wakeLock.isHeld()) { wakeLock.release(); Log.d(TAG, "Released wakelock with tag: " + tag); } else { Log.d(TAG, "Wakelock wasn't held at time of release: " + tag); } } catch (Exception e) { Log.w(TAG, "Failed to release wakelock with tag: " + tag, e); } }
Example 2
Source File: WakeLockManager.java From OmniList with GNU Affero General Public License v3.0 | 6 votes |
/** * Releases a partial {@link WakeLock} with a tag contained in the given{@link Intent} * * @param intent intent*/ private void releasePartialWakeLock(Intent intent) { if (intent.hasExtra(WakeLockManager.EXTRA_WAKELOCK_TAG)) { final int hash = intent.getIntExtra(WakeLockManager.EXTRA_WAKELOCK_HASH, -1); final String tag = intent.getStringExtra(WakeLockManager.EXTRA_WAKELOCK_TAG); // We use copy on write list. Iterator won't cause ConcurrentModificationException for (WakeLock wakeLock : wakeLocks) { if (hash == wakeLock.hashCode()) { if (wakeLock.isHeld()) { wakeLock.release(); LogUtils.d("releasePartialWakeLock: " + wakeLock.toString() + " " + tag + " was released"); } else { LogUtils.d("releasePartialWakeLock: " + wakeLock.toString() + " " + tag + " was already released!"); } wakeLocks.remove(wakeLock); return; } } LogUtils.e("releasePartialWakeLock: " + "Hash " + hash + " was not found"); } }
Example 3
Source File: WakefulBroadcastReceiver.java From letv with Apache License 2.0 | 6 votes |
public static boolean completeWakefulIntent(Intent intent) { int id = intent.getIntExtra(EXTRA_WAKE_LOCK_ID, 0); if (id == 0) { return false; } synchronized (mActiveWakeLocks) { WakeLock wl = (WakeLock) mActiveWakeLocks.get(id); if (wl != null) { wl.release(); mActiveWakeLocks.remove(id); return true; } Log.w("WakefulBroadcastReceiver", "No active wake lock id #" + id); return true; } }
Example 4
Source File: MqttService.java From Sparkplug with Eclipse Public License 1.0 | 6 votes |
@Override @SuppressLint("Wakelock") public void onReceive(Context context, Intent intent) { traceDebug(TAG, "Internal network status receive."); // we protect against the phone switching off // by requesting a wake lock - we request the minimum possible wake // lock - just enough to keep the CPU running until we've finished PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE); WakeLock wl = pm .newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MQTT"); wl.acquire(); traceDebug(TAG,"Reconnect for Network recovery."); if (isOnline()) { traceDebug(TAG,"Online,reconnect."); // we have an internet connection - have another try at // connecting reconnect(); } else { notifyClientsOffline(); } wl.release(); }
Example 5
Source File: ApplicationMigrationService.java From Silence with GNU General Public License v3.0 | 6 votes |
@Override public void run() { notification = initializeBackgroundNotification(); PowerManager powerManager = (PowerManager)getSystemService(Context.POWER_SERVICE); WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Migration"); try { wakeLock.acquire(); setState(new ImportState(ImportState.STATE_MIGRATING_BEGIN, null)); SmsMigrator.migrateDatabase(ApplicationMigrationService.this, masterSecret, ApplicationMigrationService.this); setState(new ImportState(ImportState.STATE_MIGRATING_COMPLETE, null)); setDatabaseImported(ApplicationMigrationService.this); stopForeground(true); notifyImportComplete(); stopSelf(); } finally { wakeLock.release(); } }
Example 6
Source File: InCallWakeLockUtils.java From flutter-incall-manager with ISC License | 5 votes |
private boolean _releaseWakeLock(WakeLock lock) { synchronized (lock) { if (lock.isHeld()) { lock.release(); return true; } } return false; }
Example 7
Source File: ScreenLockUtil.java From AndroidModulePattern with Apache License 2.0 | 5 votes |
/** * 取消屏幕常亮 * * @param activity you know */ public static void cancelKeepScreen(Activity activity) { WakeLock wakeLock = mWakeLockArray.get(activity); if (wakeLock != null) { if (wakeLock.isHeld()) { wakeLock.release(); } } Log.i(TAG, "取消屏幕常亮"); }
Example 8
Source File: InCallWakeLockUtils.java From react-native-incall-manager with ISC License | 5 votes |
private boolean _releaseWakeLock(WakeLock lock) { synchronized (lock) { if (lock.isHeld()) { lock.release(); return true; } } return false; }
Example 9
Source File: MQTTService.java From appcan-android with GNU Lesser General Public License v3.0 | 5 votes |
private void releaseWakelock(WakeLock wl, String tag) { try { wl.release(); } catch (Exception e) { PushReportUtility.oe(tag, e); } }
Example 10
Source File: DbBindingService.java From Onosendai with Apache License 2.0 | 5 votes |
@Override protected final void onHandleIntent (final Intent i) { final PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); final WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, C.TAG); wl.acquire(); try { doWork(i); } finally { wl.release(); } }
Example 11
Source File: SettingsDownloader.java From SettingsDeployer with MIT License | 4 votes |
@Override protected Boolean doInBackground(String... strParams) { Boolean result = Boolean.FALSE; // get a wakelock to hold for the duration of the background work. downloading // may be slow. extraction usually isn't too slow but also takes a bit of time. limit the wakelock's time! PowerManager powerManager = (PowerManager)m_ctx.getSystemService(Context.POWER_SERVICE); WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "SettingsDownloaderWakeLock"); wakeLock.acquire(FOUR_MINUTES); // download the file String filename = downloadFile(strParams[0]); if (filename != null) { File fSettingsZip = new File(filename); if (fSettingsZip.exists() && !isCancelled()) { try { m_logWriter.write("Successfully downloaded to: "+filename+"\n"); // extract to wanted directory String destDir = strParams[1]; boolean bSuccess = extractSettingsZip(fSettingsZip, destDir); result = (bSuccess ? Boolean.TRUE : Boolean.FALSE); // delete settings zip if (fSettingsZip.exists()) { fSettingsZip.delete(); } } catch(Exception e) { Log.e("SettingsDownloader", "Error: "+e.toString()); } } } // if our max time hasn't passed but work is done or an error occurred we bail out and release if (wakeLock.isHeld()) { wakeLock.release(); } return result; }
Example 12
Source File: MyScreenLocker.java From SimplePomodoro-android with MIT License | 4 votes |
public void unlock(){ PowerManager pm = (PowerManager)mActivity.getSystemService(Context.POWER_SERVICE); WakeLock mWakelock = pm.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP |PowerManager.SCREEN_DIM_WAKE_LOCK, "SimpleTimer"); mWakelock.acquire(); mWakelock.release(); }