Android 6.0 粘性服务在华为 P9 上被 PgedBinderListener 杀死
Android 6.0 sticky service killed by PgedBinderListener on Huawei P9
我在一种设备上遇到了一个非常具体的问题。我正在开发的应用程序在除华为 P9 以外的任何设备上都没有任何问题。
该应用程序启动了一项服务,该服务应该在后台运行,但是,在该设备上,该服务在设备锁定时被终止。我追踪到这个问题:
09-20 14:31:14.799 1854-1878/? I/PgedBinderListener: kstate callback type:8 value1=2656 value2=KILLED
我不知道可能是什么原因。我在日志中看到的唯一可疑的事情是据称由 Keyguard 生成的错误。事实上,这是与华为相关的错误,而且问题只出现在华为设备上,这似乎暗示了一种联系。这是错误:
09-20 14:31:10.804 1364-1584/? I/KeyguardService: KGSvcCall onStartedGoingToSleep. 2
09-20 14:31:10.837 1902-1902/? I/HwLauncher: Launcher onStop()
09-20 14:31:10.841 1902-1912/? I/HwLauncher: Launcher.LauncherProvider begin check permission at checkPermission
09-20 14:31:10.843 1902-1912/? W/System.err: java.lang.SecurityException: Permission Denial: reading com.huawei.android.launcher.LauncherProvider from pid=1364, uid=10029 requires com.huawei.android.launcher.permission.WRITE_SETTINGS: uid 10029 does not have com.huawei.android.launcher.permission.WRITE_SETTINGS.
09-20 14:31:10.843 1902-1912/? W/System.err: at android.app.ContextImpl.enforce(ContextImpl.java:1599)
09-20 14:31:10.843 1902-1912/? W/System.err: at android.app.ContextImpl.enforcePermission(ContextImpl.java:1612)
09-20 14:31:10.843 1902-1912/? W/System.err: at android.content.ContextWrapper.enforcePermission(ContextWrapper.java:664)
09-20 14:31:10.843 1902-1912/? W/System.err: at com.huawei.android.launcher.LauncherProvider.checkPermission(LauncherProvider.java:1615)
09-20 14:31:10.843 1902-1912/? W/System.err: at com.huawei.android.launcher.LauncherProvider.call(LauncherProvider.java:1854)
09-20 14:31:10.843 1902-1912/? W/System.err: at android.content.ContentProvider$Transport.call(ContentProvider.java:398)
09-20 14:31:10.843 1902-1912/? W/System.err: at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:283)
09-20 14:31:10.843 1902-1912/? W/System.err: at android.os.Binder.execTransact(Binder.java:453)
09-20 14:31:10.844 1902-1912/? E/DatabaseUtils: Writing exception to parcel
java.lang.SecurityException: Permission Denial: reading com.huawei.android.launcher.LauncherProvider from pid=1364, uid=10029 requires com.huawei.android.launcher.permission.WRITE_SETTINGS: uid 10029 does not have com.huawei.android.launcher.permission.WRITE_SETTINGS.
at android.app.ContextImpl.enforce(ContextImpl.java:1599)
at android.app.ContextImpl.enforcePermission(ContextImpl.java:1612)
at android.content.ContextWrapper.enforcePermission(ContextWrapper.java:664)
at com.huawei.android.launcher.LauncherProvider.checkPermission(LauncherProvider.java:1615)
at com.huawei.android.launcher.LauncherProvider.call(LauncherProvider.java:1854)
at android.content.ContentProvider$Transport.call(ContentProvider.java:398)
at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:283)
at android.os.Binder.execTransact(Binder.java:453)
09-20 14:31:10.845 1364-1650/? E/LauncherInteractiveUtil: Call launcher evnt fail. lock=true
java.lang.SecurityException: Permission Denial: reading com.huawei.android.launcher.LauncherProvider from pid=1364, uid=10029 requires com.huawei.android.launcher.permission.WRITE_SETTINGS: uid 10029 does not have com.huawei.android.launcher.permission.WRITE_SETTINGS.
at android.os.Parcel.readException(Parcel.java:1602)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:183)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:135)
at android.content.ContentProviderProxy.call(ContentProviderNative.java:646)
at android.content.ContentProviderClient.call(ContentProviderClient.java:437)
at com.huawei.keyguard.support.LauncherInteractiveUtil$Caller.run(LauncherInteractiveUtil.java:59)
at android.os.AsyncTask$SerialExecutor.run(AsyncTask.java:246)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:833)
我确实尝试向清单添加 com.huawei.android.launcher.permission.WRITE_SETTINGS 权限,但是它没有任何区别,因为记录的错误似乎是由 Keyguard 引起的。
我在写问题时偶然发现了答案。
在华为上,您必须将应用程序添加到电池管理中的受保护应用程序中,以防止服务被杀死。用户可以在执行检查时被告知:
"huawei".equalsIgnoreCase(android.os.Build.MANUFACTURER)
显然没有办法检查该应用程序是否已在那里启用。
我在一种设备上遇到了一个非常具体的问题。我正在开发的应用程序在除华为 P9 以外的任何设备上都没有任何问题。
该应用程序启动了一项服务,该服务应该在后台运行,但是,在该设备上,该服务在设备锁定时被终止。我追踪到这个问题:
09-20 14:31:14.799 1854-1878/? I/PgedBinderListener: kstate callback type:8 value1=2656 value2=KILLED
我不知道可能是什么原因。我在日志中看到的唯一可疑的事情是据称由 Keyguard 生成的错误。事实上,这是与华为相关的错误,而且问题只出现在华为设备上,这似乎暗示了一种联系。这是错误:
09-20 14:31:10.804 1364-1584/? I/KeyguardService: KGSvcCall onStartedGoingToSleep. 2
09-20 14:31:10.837 1902-1902/? I/HwLauncher: Launcher onStop()
09-20 14:31:10.841 1902-1912/? I/HwLauncher: Launcher.LauncherProvider begin check permission at checkPermission
09-20 14:31:10.843 1902-1912/? W/System.err: java.lang.SecurityException: Permission Denial: reading com.huawei.android.launcher.LauncherProvider from pid=1364, uid=10029 requires com.huawei.android.launcher.permission.WRITE_SETTINGS: uid 10029 does not have com.huawei.android.launcher.permission.WRITE_SETTINGS.
09-20 14:31:10.843 1902-1912/? W/System.err: at android.app.ContextImpl.enforce(ContextImpl.java:1599)
09-20 14:31:10.843 1902-1912/? W/System.err: at android.app.ContextImpl.enforcePermission(ContextImpl.java:1612)
09-20 14:31:10.843 1902-1912/? W/System.err: at android.content.ContextWrapper.enforcePermission(ContextWrapper.java:664)
09-20 14:31:10.843 1902-1912/? W/System.err: at com.huawei.android.launcher.LauncherProvider.checkPermission(LauncherProvider.java:1615)
09-20 14:31:10.843 1902-1912/? W/System.err: at com.huawei.android.launcher.LauncherProvider.call(LauncherProvider.java:1854)
09-20 14:31:10.843 1902-1912/? W/System.err: at android.content.ContentProvider$Transport.call(ContentProvider.java:398)
09-20 14:31:10.843 1902-1912/? W/System.err: at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:283)
09-20 14:31:10.843 1902-1912/? W/System.err: at android.os.Binder.execTransact(Binder.java:453)
09-20 14:31:10.844 1902-1912/? E/DatabaseUtils: Writing exception to parcel
java.lang.SecurityException: Permission Denial: reading com.huawei.android.launcher.LauncherProvider from pid=1364, uid=10029 requires com.huawei.android.launcher.permission.WRITE_SETTINGS: uid 10029 does not have com.huawei.android.launcher.permission.WRITE_SETTINGS.
at android.app.ContextImpl.enforce(ContextImpl.java:1599)
at android.app.ContextImpl.enforcePermission(ContextImpl.java:1612)
at android.content.ContextWrapper.enforcePermission(ContextWrapper.java:664)
at com.huawei.android.launcher.LauncherProvider.checkPermission(LauncherProvider.java:1615)
at com.huawei.android.launcher.LauncherProvider.call(LauncherProvider.java:1854)
at android.content.ContentProvider$Transport.call(ContentProvider.java:398)
at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:283)
at android.os.Binder.execTransact(Binder.java:453)
09-20 14:31:10.845 1364-1650/? E/LauncherInteractiveUtil: Call launcher evnt fail. lock=true
java.lang.SecurityException: Permission Denial: reading com.huawei.android.launcher.LauncherProvider from pid=1364, uid=10029 requires com.huawei.android.launcher.permission.WRITE_SETTINGS: uid 10029 does not have com.huawei.android.launcher.permission.WRITE_SETTINGS.
at android.os.Parcel.readException(Parcel.java:1602)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:183)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:135)
at android.content.ContentProviderProxy.call(ContentProviderNative.java:646)
at android.content.ContentProviderClient.call(ContentProviderClient.java:437)
at com.huawei.keyguard.support.LauncherInteractiveUtil$Caller.run(LauncherInteractiveUtil.java:59)
at android.os.AsyncTask$SerialExecutor.run(AsyncTask.java:246)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:833)
我确实尝试向清单添加 com.huawei.android.launcher.permission.WRITE_SETTINGS 权限,但是它没有任何区别,因为记录的错误似乎是由 Keyguard 引起的。
我在写问题时偶然发现了答案。
在华为上,您必须将应用程序添加到电池管理中的受保护应用程序中,以防止服务被杀死。用户可以在执行检查时被告知: "huawei".equalsIgnoreCase(android.os.Build.MANUFACTURER) 显然没有办法检查该应用程序是否已在那里启用。