1

Do you have better way to make the device awakes by 100%? I repeatedly call the acquire() but I'm not sure if that is correct. Or should I just call the acquire() once? Or should I make use of Intent.ACTION_SCREEN_OFF?

public class MyServiceThatKeepsTheDeviceAwake extends IntentService {   
TAG = "com.android.browser.test.launcher.BrowsePageService";
...
@Override
public void onCreate() {
    super.onCreate();
    mPowerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
    mWakeLock = mPowerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK |PowerManager.ACQUIRE_CAUSES_WAKEUP |PowerManager.ON_AFTER_RELEASE, TAG);
}

@Override
public void onStart(Intent intent, int startId) {
    super.onStart(intent, startId);
    mWakeLock.acquire();
}

// No release

*This service is run using AlarmManager every 20 seconds

---Added:

*This gives me the ff. output when repeatedly running it. Should there be any problem with this? Should there be any problem call it repeatedly?

C:\Windows\System32>adb shell dumpsys power
Power Manager State:
mIsPowered=false mPowerState=3 mScreenOffTime=463571 ms
mPartialCount=9
mWakeLockState=SCREEN_BRIGHT_BIT SCREEN_ON_BIT
mUserState=
mPowerState=SCREEN_BRIGHT_BIT SCREEN_ON_BIT
mLocks.gather=SCREEN_BRIGHT_BIT SCREEN_ON_BIT
mNextTimeout=355968 now=463589 -107s from now
mDimScreen=true mStayOnConditions=0
mScreenOffReason=0 mUserState=0
mBroadcastQueue={-1,-1,-1}
mBroadcastWhy={0,0,0}
mPokey=0 mPokeAwakeonSet=false
mKeyboardVisible=false mUserActivityAllowed=true
mKeylightDelay=6000 mDimDelay=2000 mScreenOffDelay=7000
mPreventScreenOn=false  mScreenBrightnessOverride=-1  mButtonBrightnessOverride=-1
mScreenOffTimeoutSetting=15000 mMaximumScreenOffTimeout=2147483647
mLastScreenOnTime=19531
mBroadcastWakeLock=UnsynchronizedWakeLock(mFlags=0x1 mCount=0 mHeld=false)
mStayOnWhilePluggedInScreenDimLock=UnsynchronizedWakeLock(mFlags=0x6 mCount=0 mHeld=false)
mStayOnWhilePluggedInPartialLock=UnsynchronizedWakeLock(mFlags=0x1 mCount=0 mHeld=false)
mPreventScreenOnPartialLock=UnsynchronizedWakeLock(mFlags=0x1 mCount=0 mHeld=false)
mProximityPartialLock=UnsynchronizedWakeLock(mFlags=0x1 mCount=0 mHeld=false)
mProximityWakeLockCount=0
mProximitySensorEnabled=false
mProximitySensorActive=false
mProximityPendingValue=-1
mLastProximityEventTime=0
mLightSensorEnabled=true
mLightSensorValue=1219.0 mLightSensorPendingValue=1173.0
mLightSensorPendingDecrease=true mLightSensorPendingIncrease=false
mLightSensorScreenBrightness=122 mLightSensorButtonBrightness=0 mLightSensorKeyboardBrightness=0
mUseSoftwareAutoBrightness=true
mAutoBrightessEnabled=true
mScreenBrightness: animating=false targetValue=122 curValue=122.0 delta=0.45

mLocks.size=16:
FULL_WAKE_LOCK                 'com.android.browser.test.launcher.BrowsePageService'ACQUIRE_CAUSES_WAKEUP  activated (minState=3, uid=10040, pid=722)
FULL_WAKE_LOCK                 'com.android.browser.test.launcher.BrowsePageService'ACQUIRE_CAUSES_WAKEUP  activated (minState=3, uid=10040, pid=722)
FULL_WAKE_LOCK                 'com.android.browser.test.launcher.BrowsePageService'ACQUIRE_CAUSES_WAKEUP  activated (minState=3, uid=10040, pid=722)
FULL_WAKE_LOCK                 'com.android.browser.test.launcher.BrowsePageService'ACQUIRE_CAUSES_WAKEUP  activated (minState=3, uid=10040, pid=722)
FULL_WAKE_LOCK                 'com.android.browser.test.launcher.BrowsePageService'ACQUIRE_CAUSES_WAKEUP  activated (minState=3, uid=10040, pid=722)
FULL_WAKE_LOCK                 'com.android.browser.test.launcher.BrowsePageService'ACQUIRE_CAUSES_WAKEUP  activated (minState=3, uid=10040, pid=722)
FULL_WAKE_LOCK                 'com.android.browser.test.launcher.BrowsePageService'ACQUIRE_CAUSES_WAKEUP  activated (minState=3, uid=10040, pid=722)
PARTIAL_WAKE_LOCK              'WSBase.lastChance' activated (minState=0, uid=10007, pid=243)
PARTIAL_WAKE_LOCK              'WSBase.lastChance' activated (minState=0, uid=10007, pid=243)
PARTIAL_WAKE_LOCK              'WSBase.lastChance' activated (minState=0, uid=10007, pid=243)
PARTIAL_WAKE_LOCK              'WSBase.lastChance' activated (minState=0, uid=10007, pid=243)
PARTIAL_WAKE_LOCK              'WSBase.lastChance' activated (minState=0, uid=10007, pid=243)
PARTIAL_WAKE_LOCK              'WSBase.lastChance' activated (minState=0, uid=10007, pid=243)
PARTIAL_WAKE_LOCK              'WSBase.lastChance' activated (minState=0, uid=10007, pid=243)
PARTIAL_WAKE_LOCK              'WSBase.lastChance' activated (minState=0, uid=10007, pid=243)
PARTIAL_WAKE_LOCK              'WSBase' activated (minState=0, uid=10007, pid=243)

mPokeLocks.size=0:
quiel
  • 427
  • 1
  • 3
  • 19
  • The Best option is you set it Sleep Timeout with Value "Never" from settings. but you need to do it manually for all the devices – Krish Mar 26 '12 at 05:40
  • Motorola xoom doesn't have "Never" option or not all the devices have that option. How should I suppose to do that? – quiel Mar 26 '12 at 05:45
  • Then you should set that value to max time like 1 hour or more – Krish Mar 26 '12 at 05:46
  • Thanks Krish! But it is more likely that I should modify the Settings.apk in order to achieve 100% awake with this option. – quiel Mar 26 '12 at 05:55

1 Answers1

1

No need to call acquire() repeatedly.Just in onCreate() acquire lock.It will work until you do not call release().Just in onDestroy() of activity call release(), As it battery consuming task.

For more detail look at this Detail Discussion on Wake up of Screen

Community
  • 1
  • 1
Tofeeq Ahmad
  • 11,935
  • 4
  • 61
  • 87
  • You mean I should call acquire() in the onCreate of an Activity that starts the AlarmManager? If thats the case what if the Activity was destroyed by the system. Will the wakelock will also be released? – quiel Mar 26 '12 at 06:27
  • 1
    If activity in foreground than it will never destroyed by system.In background also its rare case that activity will destroyed.But if yes then its method ondestroyed() will call you it will release() lock – Tofeeq Ahmad Mar 26 '12 at 06:29
  • Yes I got your point Sameer. Just call acquire() once from Activity, but has possibility to be released() when my the activity was destroyed by the system. I should try it. – quiel Mar 26 '12 at 07:03
  • But, should there be any problem when I repeatedly acquire() it? I added additional info from the original post. – quiel Mar 26 '12 at 07:05
  • what the need of calling it repeatedly ? If you call then i think it will not give any error(have not tried ever) but its not a good way to code.I expect it can give error IllegalStateException – Tofeeq Ahmad Mar 26 '12 at 07:10
  • You got a point. I tried repeating calls to guarantee it will not sleep but as you said, just one call is enough. It works! – quiel Mar 26 '12 at 07:37