androidwear-oswakeuppowermanagerambient

Waking Wear Device from Ambient Mode from Companion Mobile App


I'm writing a Custom Watch Face for Android Wear, and I am able to send settings data to the watch from mobile just fine. However when the watch is in ambient mode and the user changes the settings from their mobile, I'd like to wake the watch from Ambient Mode to show the updated changes to the watch.

I've tried using Power Manager, but I get this exception:

java.lang.IllegalArgumentException: Must specify a valid wake lock level.
            at android.os.PowerManager.validateWakeLockParameters(PowerManager.java:442)
            at android.os.PowerManager.newWakeLock(PowerManager.java:427)

I don't understand this message because I set the wake lock level in newWakeLock.

Here's my Code:

private PowerManager.WakeLock mWakeLock;
private void wakeUpScreen(){
    PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
    if(mWakeLock == null) {
        mWakeLock = powerManager.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP, 
            "CubeWatch");
        Log.d(TAG, "WAKE UP!!!!");
        mWakeLock.acquire();
    }
    if(!mWakeLock.isHeld()) mWakeLock.acquire();  //if called a second time and isn't locked
    mHandler.removeCallbacks(mRunReleaseLock);    //if already waiting, then we'll start the time over 
    mHandler.postDelayed(mRunReleaseLock, 3000);
}
Handler mHandler = new Handler();
Runnable mRunReleaseLock= new Runnable() {
    @Override
    public void run() {
        mWakeLock.release();
    }
};

Solution

  • ACQUIRE_CAUSES_WAKEUP must always be combined with FULL_WAKE_LOCK, SCREEN_BRIGHT_WAKE_LOCK, SCREEN_DIM_WAKE_LOCK and/or PARTIAL_WAKE_LOCK.

    I am currently using

    mWakeLock = powerManager.newWakeLock((PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE), "wakeLock");
    

    which works but warns me about depreciation of SCREEN_BRIGHT_WAKE_LOCK and FULL_WAKE_LOCK. SCREEN_DIM_WAKE_LOCK is also depreciated. Maybe new Wake Lock States are prepared for a future Android Wear version? Something like AMBIENT_WAKE_LOCK and INTERACTIVE_WAKE_LOCK would be nice. For the moment, SCREEN_BRIGHT_WAKE_LOCK and FULL_WAKE_LOCK works just fine.