天道酬勤,学无止境

android-doze

Purpose of WakeLock in modern Android?

I'm having a hard time understanding the purpose of WakeLock in modern versions of Android, after the introduction of Doze and Foreground Services. It appears as if WakeLocks are pretty much legacy as this point (although not marked as deprecated), replaced by Foreground Services (as WakeLocks are not actually respected by Doze). From the documentation: "One legitimate case for using a wake lock might be a background service that needs to grab a wake lock to keep the CPU running to do work while the screen is off" - But this isn't really true anymore after the introduction of doze and

2022-04-29 23:26:09    分类:问答    android   power-management   android-doze   batterymanager   powermanager

Unplugging the device via ADB: "can't find service"

问题 我必须测试我的应用在打盹模式下的行为。 根据文档,我首先必须通过在终端中输入以下命令使设备认为它已拔出: $ adb shell dumpsys battery unplug 但是,什么也没发生,它会记录: 找不到服务:电池 我该怎么办? 回答1 日志指出没有电池服务(这可能是特定于设备的)。 输入以下命令查找现有的电池相关服务: $ adb shell service list | grep battery 它会导致这样的事情 $ adb shell service list | grep battery 88 batterymanager: [android.app.IBatteryService] 107 batterystats: [com.android.internal.app.IBatteryStats] 114 batteryproperties: [android.os.IBatteryPropertiesRegistrar] 要管理电池,您应该使用batterymanager是有道理的。 $ adb shell dumpsys batterymanager 输出(万一充电的 USB 已插入) Current Battery Service state: (UPDATES STOPPED -- use 'reset' to restart) AC

2022-04-27 03:15:13    分类:技术分享    android   adb   android-6.0-marshmallow   android-doze   android-doze-and-standby

Android Alarm Manager setExactAndAllowWhileIdle() not working in Android 7.0 Nougat in Doze mode

I am trying to make an alarm fire in my app every 30 minutes using Alarm Manager's setExactAndAllowWhileIdle but it is not working! I test the functionality by issuing a push notification whenever I receive an alarm signal. The problem is: when the device enters doze mode after being idle for sometime, I no longer receive alarms. However, as soon as I turn On the screen, I receive a notification. My app needs accurate alarms that need to be delivered exactly on-time every 30 minutes! It can not afford to receive delayed alarms or dropped ones because the device is in Doze mode! I used the

2022-03-26 12:38:33    分类:问答    android   android-intent   android-alarms   android-7.0-nougat   android-doze

Unplugging the device via ADB: "can't find service"

I have to test how my app behaves in doze mode. According to the documentation, I first must make the device think it's unplugged by entering the following command in the terminal: $ adb shell dumpsys battery unplug However, nothing happens and it logs: Can't find service: battery What should I do?

2022-03-16 23:20:30    分类:问答    android   adb   android-6.0-marshmallow   android-doze   android-doze-and-standby

Intent Service not working in doze mode

One of my peer developer has written an intent service that makes an API call and then sleeps for 2 mins. After waking up, it sends again. Below is the code: public class GpsTrackingService extends IntentService { .... @Override protected void onHandleIntent(Intent intent) { do{ try{ //make API call here //then go to sleep for 2 mins TimeUnit.SECONDS.sleep(120); } catch(InterruptedException ex){ ex.printStackTrace(); } } while (preferences.shouldSendGps()); //till the user can send gps. } .... } Manifest <service android:name=".commons.GpsTrackingService" /> This is working fine when the phone

2022-03-09 06:44:24    分类:问答    android   android-6.0-marshmallow   android-intentservice   android-doze

Doze mode sleeps Google's Geofence sample application

I have an android application that uses Geofence and I'm having a hard time overcoming Doze mode. My manifest has the WAKE_LOCK permission and seven setNotificationResponsiveness to 0 for each region. I even changed PendingIntent to BroadcastReceiver but the app literally sleeps or is dead after a while with the deleted smartphone screen. I've already tried using LocationRequest LocationRequest.setFastestInterval(1000); LocationRequest.setInterval(2000); Even so, I did not succeed. Has anyone managed to keep the application running with the Doze?

2022-02-16 04:08:43    分类:问答    android   android-geofence   android-doze

Why is Network access in my geofence broadcast receiver unreliable?

Use case: When geofence triggers we need to contact server ASAP. We have solved this with an implicit BroadcastReceiver calling a Service for several years, but problematic in new versions due to Doze and Oreo background restrictions. Attempted fixes: We moved geofence registering from implicit -> explicit broadcast receiver to get around the "background mode" restriction. We tried to do it as in Googles examples, i.e. the broadcast receiver calling enqueueWork() on a JobIntentService. The problem with this is that we often noticed a long "lag" between when the job was scheduled and when it

2022-01-23 11:27:27    分类:问答    android   broadcastreceiver   android-geofence   android-jobscheduler   android-doze