Java Code Examples for android.os.PowerManager#PARTIAL_WAKE_LOCK

The following examples show how to use android.os.PowerManager#PARTIAL_WAKE_LOCK . 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: PowerManagerService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
private boolean isWakeLockLevelSupportedInternal(int level) {
    synchronized (mLock) {
        switch (level) {
            case PowerManager.PARTIAL_WAKE_LOCK:
            case PowerManager.SCREEN_DIM_WAKE_LOCK:
            case PowerManager.SCREEN_BRIGHT_WAKE_LOCK:
            case PowerManager.FULL_WAKE_LOCK:
            case PowerManager.DOZE_WAKE_LOCK:
            case PowerManager.DRAW_WAKE_LOCK:
                return true;

            case PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK:
                return mSystemReady && mDisplayManagerInternal.isProximitySensorAvailable();

            default:
                return false;
        }
    }
}
 
Example 2
Source File: PowerManagerService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/** Get wake lock summary flags that correspond to the given wake lock. */
private int getWakeLockSummaryFlags(WakeLock wakeLock) {
    switch (wakeLock.mFlags & PowerManager.WAKE_LOCK_LEVEL_MASK) {
        case PowerManager.PARTIAL_WAKE_LOCK:
            if (!wakeLock.mDisabled) {
                // We only respect this if the wake lock is not disabled.
                return WAKE_LOCK_CPU;
            }
            break;
        case PowerManager.FULL_WAKE_LOCK:
            return WAKE_LOCK_SCREEN_BRIGHT | WAKE_LOCK_BUTTON_BRIGHT;
        case PowerManager.SCREEN_BRIGHT_WAKE_LOCK:
            return WAKE_LOCK_SCREEN_BRIGHT;
        case PowerManager.SCREEN_DIM_WAKE_LOCK:
            return WAKE_LOCK_SCREEN_DIM;
        case PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK:
            return WAKE_LOCK_PROXIMITY_SCREEN_OFF;
        case PowerManager.DOZE_WAKE_LOCK:
            return WAKE_LOCK_DOZE;
        case PowerManager.DRAW_WAKE_LOCK:
            return WAKE_LOCK_DRAW;
    }
    return 0;
}
 
Example 3
Source File: PowerManagerService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
private void updateWakeLockDisabledStatesLocked() {
    boolean changed = false;
    final int numWakeLocks = mWakeLocks.size();
    for (int i = 0; i < numWakeLocks; i++) {
        final WakeLock wakeLock = mWakeLocks.get(i);
        if ((wakeLock.mFlags & PowerManager.WAKE_LOCK_LEVEL_MASK)
                == PowerManager.PARTIAL_WAKE_LOCK) {
            if (setWakeLockDisabledStateLocked(wakeLock)) {
                changed = true;
                if (wakeLock.mDisabled) {
                    // This wake lock is no longer being respected.
                    notifyWakeLockReleasedLocked(wakeLock);
                } else {
                    notifyWakeLockAcquiredLocked(wakeLock);
                }
            }
        }
    }
    if (changed) {
        mDirty |= DIRTY_WAKE_LOCKS;
        updatePowerStateLocked();
    }
}
 
Example 4
Source File: PowerManagerService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
private String getLockLevelString() {
    switch (mFlags & PowerManager.WAKE_LOCK_LEVEL_MASK) {
        case PowerManager.FULL_WAKE_LOCK:
            return "FULL_WAKE_LOCK                ";
        case PowerManager.SCREEN_BRIGHT_WAKE_LOCK:
            return "SCREEN_BRIGHT_WAKE_LOCK       ";
        case PowerManager.SCREEN_DIM_WAKE_LOCK:
            return "SCREEN_DIM_WAKE_LOCK          ";
        case PowerManager.PARTIAL_WAKE_LOCK:
            return "PARTIAL_WAKE_LOCK             ";
        case PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK:
            return "PROXIMITY_SCREEN_OFF_WAKE_LOCK";
        case PowerManager.DOZE_WAKE_LOCK:
            return "DOZE_WAKE_LOCK                ";
        case PowerManager.DRAW_WAKE_LOCK:
            return "DRAW_WAKE_LOCK                ";
        default:
            return "???                           ";
    }
}
 
Example 5
Source File: AudioApi.java    From flutter_plugin_playlist with MIT License 5 votes vote down vote up
public AudioApi(Context context) {
    this.audioPlayer = new AudioPlayer(context.getApplicationContext());

    audioPlayer.setOnErrorListener(this);
    audioPlayer.setOnPreparedListener(this);
    audioPlayer.setOnCompletionListener(this);
    audioPlayer.setOnSeekCompletionListener(this);
    audioPlayer.setOnBufferUpdateListener(this);

    // If you have not included the WAKE_LOCK permission in your project,
    // the following lines have no effect.
    int wakeMode = PowerManager.PARTIAL_WAKE_LOCK; // | PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK;
    audioPlayer.setWakeMode(context, wakeMode);
    audioPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
}
 
Example 6
Source File: PowerManagerService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private void restartNofifyLongTimerLocked(WakeLock wakeLock) {
    wakeLock.mAcquireTime = SystemClock.uptimeMillis();
    if ((wakeLock.mFlags & PowerManager.WAKE_LOCK_LEVEL_MASK)
            == PowerManager.PARTIAL_WAKE_LOCK && mNotifyLongScheduled == 0) {
        enqueueNotifyLongMsgLocked(wakeLock.mAcquireTime + MIN_LONG_WAKE_CHECK_INTERVAL);
    }
}
 
Example 7
Source File: PowerManagerService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
void checkForLongWakeLocks() {
    synchronized (mLock) {
        final long now = SystemClock.uptimeMillis();
        mNotifyLongDispatched = now;
        final long when = now - MIN_LONG_WAKE_CHECK_INTERVAL;
        long nextCheckTime = Long.MAX_VALUE;
        final int numWakeLocks = mWakeLocks.size();
        for (int i = 0; i < numWakeLocks; i++) {
            final WakeLock wakeLock = mWakeLocks.get(i);
            if ((wakeLock.mFlags & PowerManager.WAKE_LOCK_LEVEL_MASK)
                    == PowerManager.PARTIAL_WAKE_LOCK) {
                if (wakeLock.mNotifiedAcquired && !wakeLock.mNotifiedLong) {
                    if (wakeLock.mAcquireTime < when) {
                        // This wake lock has exceeded the long acquire time, report!
                        notifyWakeLockLongStartedLocked(wakeLock);
                    } else {
                        // This wake lock could still become a long one, at this time.
                        long checkTime = wakeLock.mAcquireTime + MIN_LONG_WAKE_CHECK_INTERVAL;
                        if (checkTime < nextCheckTime) {
                            nextCheckTime = checkTime;
                        }
                    }
                }
            }
        }
        mNotifyLongScheduled = 0;
        mHandler.removeMessages(MSG_CHECK_FOR_LONG_WAKELOCKS);
        if (nextCheckTime != Long.MAX_VALUE) {
            mNotifyLongNextCheck = nextCheckTime;
            enqueueNotifyLongMsgLocked(nextCheckTime);
        } else {
            mNotifyLongNextCheck = 0;
        }
    }
}
 
Example 8
Source File: PowerManagerService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private boolean setWakeLockDisabledStateLocked(WakeLock wakeLock) {
    if ((wakeLock.mFlags & PowerManager.WAKE_LOCK_LEVEL_MASK)
            == PowerManager.PARTIAL_WAKE_LOCK) {
        boolean disabled = false;
        final int appid = UserHandle.getAppId(wakeLock.mOwnerUid);
        if (appid >= Process.FIRST_APPLICATION_UID) {
            // Cached inactive processes are never allowed to hold wake locks.
            if (mConstants.NO_CACHED_WAKE_LOCKS) {
                disabled = !wakeLock.mUidState.mActive &&
                        wakeLock.mUidState.mProcState
                                != ActivityManager.PROCESS_STATE_NONEXISTENT &&
                        wakeLock.mUidState.mProcState > ActivityManager.PROCESS_STATE_RECEIVER;
            }
            if (mDeviceIdleMode) {
                // If we are in idle mode, we will also ignore all partial wake locks that are
                // for application uids that are not whitelisted.
                final UidState state = wakeLock.mUidState;
                if (Arrays.binarySearch(mDeviceIdleWhitelist, appid) < 0 &&
                        Arrays.binarySearch(mDeviceIdleTempWhitelist, appid) < 0 &&
                        state.mProcState != ActivityManager.PROCESS_STATE_NONEXISTENT &&
                        state.mProcState >
                                ActivityManager.PROCESS_STATE_BOUND_FOREGROUND_SERVICE) {
                    disabled = true;
                }
            }
        }
        if (wakeLock.mDisabled != disabled) {
            wakeLock.mDisabled = disabled;
            return true;
        }
    }
    return false;
}
 
Example 9
Source File: Notifier.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private int getBatteryStatsWakeLockMonitorType(int flags) {
    switch (flags & PowerManager.WAKE_LOCK_LEVEL_MASK) {
        case PowerManager.PARTIAL_WAKE_LOCK:
            return BatteryStats.WAKE_TYPE_PARTIAL;

        case PowerManager.SCREEN_DIM_WAKE_LOCK:
        case PowerManager.SCREEN_BRIGHT_WAKE_LOCK:
            return BatteryStats.WAKE_TYPE_FULL;

        case PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK:
            if (mSuspendWhenScreenOffDueToProximityConfig) {
                return -1;
            }
            return BatteryStats.WAKE_TYPE_PARTIAL;

        case PowerManager.DRAW_WAKE_LOCK:
            return BatteryStats.WAKE_TYPE_DRAW;

        case PowerManager.DOZE_WAKE_LOCK:
            // Doze wake locks are an internal implementation detail of the
            // communication between dream manager service and power manager
            // service.  They have no additive battery impact.
            return -1;

        default:
            return -1;
    }
}
 
Example 10
Source File: BasicMediaPlayerTestCase_SetWakeModeMethod.java    From android-openslmediaplayer with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
private static final String wakeModeToString(int mode) {
    StringBuilder sb = new StringBuilder();

    if ((mode & PowerManager.PARTIAL_WAKE_LOCK) != 0) {
        appendWithOR(sb, "PARTIAL_WAKE_LOCK");
    }

    if ((mode & PowerManager.ACQUIRE_CAUSES_WAKEUP) != 0) {
        appendWithOR(sb, "ACQUIRE_CAUSES_WAKEUP");
    }

    if ((mode & PowerManager.ON_AFTER_RELEASE) != 0) {
        appendWithOR(sb, "ON_AFTER_RELEASE");
    }

    // deprecated values
    if ((mode & PowerManager.FULL_WAKE_LOCK) != 0) {
        appendWithOR(sb, "FULL_WAKE_LOCK");
    }

    if ((mode & PowerManager.SCREEN_DIM_WAKE_LOCK) != 0) {
        appendWithOR(sb, "SCREEN_DIM_WAKE_LOCK");
    }

    if ((mode & PowerManager.SCREEN_BRIGHT_WAKE_LOCK) != 0) {
        appendWithOR(sb, "SCREEN_BRIGHT_WAKE_LOCK");
    }

    return sb.toString();
}
 
Example 11
Source File: PreferenceValues.java    From WhereYouGo with GNU General Public License v3.0 4 votes vote down vote up
public static void enableWakeLock() {
    try {
        boolean disable = false;
        int new_level = 0;
        if (!Preferences.GLOBAL_RUN_SCREEN_OFF) {
            if (!existCurrentActivity()) {
                disable = true;
            } else {
                if (Preferences.APPEARANCE_HIGHLIGHT == VALUE_HIGHLIGHT_OFF) {
                    disable = true;
                } else if (Preferences.APPEARANCE_HIGHLIGHT == VALUE_HIGHLIGHT_ONLY_GPS) {
                    if (!LocationState.isActuallyHardwareGpsOn()) {
                        disable = true;
                    }
                }
            }
        }

        if ((Preferences.APPEARANCE_HIGHLIGHT == VALUE_HIGHLIGHT_ONLY_GPS || Preferences.APPEARANCE_HIGHLIGHT == VALUE_HIGHLIGHT_ALWAYS) && existCurrentActivity()) {
            new_level = PowerManager.SCREEN_BRIGHT_WAKE_LOCK;
        } else {
            if (Preferences.GLOBAL_RUN_SCREEN_OFF) {
                new_level = PowerManager.PARTIAL_WAKE_LOCK;
            }
        }
        Logger.w(TAG, "enableWakeLock(), dis:" + disable + " level:" + new_level + ", wl:" + wl + " current level:" + wl_level);
        if ((disable || new_level == 0) && wl != null) {
            disableWakeLock();
        } else if (!disable && new_level != wl_level) {
            if (wl != null) {
                wl.release();
            }
            PowerManager pm = (PowerManager) A.getApp().getSystemService(Context.POWER_SERVICE);
            if (pm != null) {
                wl = pm.newWakeLock(new_level, TAG);
                wl.acquire();
                wl_level = new_level;
            }
        }
        // Logger.w(TAG, "enableWakeLock(), res:" + wl);
    } catch (Exception e) {
        Logger.e(TAG, "enableWakeLock(), e:" + e.toString());
    }
}
 
Example 12
Source File: AppWakeUpManager.java    From your-local-weather with GNU General Public License v3.0 4 votes vote down vote up
public void wakeUp() {
    appendLog(getBaseContext(), TAG, "powerManager:", powerManager);

    boolean isInUse;

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
        isInUse = powerManager.isInteractive();
    } else {
        isInUse = powerManager.isScreenOn();
    }

    if (isInUse || ((wakeLock != null) && wakeLock.isHeld())) {
        appendLog(getBaseContext(), TAG, "lock is held");
        return;
    }

    timerWakeUpHandler.postDelayed(timerWakeUpRunnable, WAKEUP_TIMEOUT_IN_MS);

    String wakeUpStrategy = PreferenceManager.getDefaultSharedPreferences(getBaseContext())
            .getString(Constants.KEY_WAKE_UP_STRATEGY, "nowakeup");
    appendLog(getBaseContext(), TAG, "wakeLock:wakeUpStrategy:", wakeUpStrategy);
    if (wakeLock != null) {
        try {
            wakeLock.release();
        } catch (Throwable th) {
            // ignoring this exception, probably wakeLock was already released
        }
    }
    if ("nowakeup".equals(wakeUpStrategy)) {
        return;
    }
    int powerLockID;
    if ("wakeupfull".equals(wakeUpStrategy)) {
        powerLockID = PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP;
    } else {
        powerLockID = PowerManager.PARTIAL_WAKE_LOCK;
    }
    appendLog(getBaseContext(), TAG, "wakeLock:powerLockID:", powerLockID);
    wakeLock = powerManager.newWakeLock(powerLockID, "YourLocalWeather:PowerLock");
    appendLog(getBaseContext(), TAG, "wakeLock:", wakeLock, ":", wakeLock.isHeld());
    if (!wakeLock.isHeld()) {
        wakeLock.acquire();
    }
    appendLog(getBaseContext(), TAG, "wakeLock acquired");
}
 
Example 13
Source File: FormRecordListActivity.java    From commcare-android with Apache License 2.0 4 votes vote down vote up
@Override
public int getWakeLockLevel() {
    return PowerManager.PARTIAL_WAKE_LOCK;
}