Java Code Examples for android.os.PowerManager#isDeviceIdleMode()
The following examples show how to use
android.os.PowerManager#isDeviceIdleMode() .
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: BatterySaverController.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
private void updateBatterySavingStats() { final PowerManager pm = getPowerManager(); if (pm == null) { Slog.wtf(TAG, "PowerManager not initialized"); return; } final boolean isInteractive = pm.isInteractive(); final int dozeMode = pm.isDeviceIdleMode() ? DozeState.DEEP : pm.isLightDeviceIdleMode() ? DozeState.LIGHT : DozeState.NOT_DOZING; synchronized (mLock) { if (mIsPluggedIn) { mBatterySavingStats.startCharging(); return; } mBatterySavingStats.transitionState( mEnabled ? BatterySaverState.ON : BatterySaverState.OFF, isInteractive ? InteractiveState.INTERACTIVE : InteractiveState.NON_INTERACTIVE, dozeMode); } }
Example 2
Source File: PowerSaveModeChangedReceiver.java From BackPackTrackII with GNU General Public License v3.0 | 6 votes |
@Override public void onReceive(final Context context, Intent intent) { Log.i(TAG, "Received " + intent); PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); if (!pm.isDeviceIdleMode()) { long time = new Date().getTime(); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); long ref_time = prefs.getLong(SettingsFragment.PREF_PRESSURE_REF_TIME, 0); int interval = Integer.parseInt(prefs.getString(SettingsFragment.PREF_WEATHER_INTERVAL, SettingsFragment.DEFAULT_WEATHER_INTERVAL)); if (ref_time + interval * 60 * 1000 < time) { Intent intentWeather = new Intent(context, BackgroundService.class); intentWeather.setAction(BackgroundService.ACTION_UPDATE_WEATHER); context.startService(intentWeather); } } }
Example 3
Source File: Device.java From android-job with Apache License 2.0 | 6 votes |
@SuppressWarnings("deprecation") public static boolean isIdle(Context context) { PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { /* * isDeviceIdleMode() is a very strong requirement and could cause a job * to be never run. isDeviceIdleMode() returns true in doze mode, but jobs * are delayed until the device leaves doze mode */ return powerManager.isDeviceIdleMode() || !powerManager.isInteractive(); } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) { return !powerManager.isInteractive(); } else { return !powerManager.isScreenOn(); } }
Example 4
Source File: Requirements.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
private boolean checkIdleRequirement(Context context) { if (!isIdleRequired()) { return true; } PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE); return Util.SDK_INT >= 23 ? !powerManager.isDeviceIdleMode() : Util.SDK_INT >= 20 ? !powerManager.isInteractive() : !powerManager.isScreenOn(); }
Example 5
Source File: ModulesBroadcastReceiver.java From InviZible with GNU General Public License v3.0 | 5 votes |
@TargetApi(Build.VERSION_CODES.M) private void idleStateChanged(Context context) { PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); if (pm != null) { Log.i(LOG_TAG, "ModulesBroadcastReceiver device idle=" + pm.isDeviceIdleMode()); } // Reload rules when coming from idle mode if (pm != null && !pm.isDeviceIdleMode()) { updateIptablesRules(false); } }
Example 6
Source File: ServiceVPN.java From InviZible with GNU General Public License v3.0 | 5 votes |
@Override @TargetApi(Build.VERSION_CODES.M) public void onReceive(Context context, Intent intent) { Log.i(LOG_TAG, "VPN Received " + intent); PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); if (pm != null) { Log.i(LOG_TAG, "VPN device idle=" + pm.isDeviceIdleMode()); } // Reload rules when coming from idle mode if (pm != null && !pm.isDeviceIdleMode()) reload("VPN idle state changed", ServiceVPN.this); }
Example 7
Source File: Requirements.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
private boolean checkIdleRequirement(Context context) { if (!isIdleRequired()) { return true; } PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE); return Util.SDK_INT >= 23 ? !powerManager.isDeviceIdleMode() : Util.SDK_INT >= 20 ? !powerManager.isInteractive() : !powerManager.isScreenOn(); }
Example 8
Source File: DeviceUtils.java From JobSchedulerCompat with MIT License | 5 votes |
@SuppressWarnings({"deprecation", "ConstantConditions"}) public static boolean isIdle(Context context) { PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { return powerManager.isDeviceIdleMode() || !powerManager.isInteractive(); } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) { return !powerManager.isInteractive(); } else { return !powerManager.isScreenOn(); } }
Example 9
Source File: Utils.java From Applozic-Android-SDK with BSD 3-Clause "New" or "Revised" License | 5 votes |
public static boolean isDeviceInIdleState(Context context) { if (hasMarshmallow()) { PowerManager pm = context.getSystemService(PowerManager.class); if (pm != null && pm.isDeviceIdleMode()) { return true; } } return false; }
Example 10
Source File: PowerManagerCompat.java From mollyim-android with GNU General Public License v3.0 | 4 votes |
public static boolean isDeviceIdleMode(@NonNull PowerManager powerManager) { if (Build.VERSION.SDK_INT >= 23) { return powerManager.isDeviceIdleMode(); } return false; }
Example 11
Source File: Requirements.java From MediaSDK with Apache License 2.0 | 4 votes |
private boolean isDeviceIdle(Context context) { PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE); return Util.SDK_INT >= 23 ? powerManager.isDeviceIdleMode() : Util.SDK_INT >= 20 ? !powerManager.isInteractive() : !powerManager.isScreenOn(); }
Example 12
Source File: Requirements.java From Telegram-FOSS with GNU General Public License v2.0 | 4 votes |
private boolean isDeviceIdle(Context context) { PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE); return Util.SDK_INT >= 23 ? powerManager.isDeviceIdleMode() : Util.SDK_INT >= 20 ? !powerManager.isInteractive() : !powerManager.isScreenOn(); }
Example 13
Source File: Requirements.java From Telegram with GNU General Public License v2.0 | 4 votes |
private boolean isDeviceIdle(Context context) { PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE); return Util.SDK_INT >= 23 ? powerManager.isDeviceIdleMode() : Util.SDK_INT >= 20 ? !powerManager.isInteractive() : !powerManager.isScreenOn(); }