我在一种设备上有一个非常具体的问题。我正在开发的应用程序在除华为 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$1.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 引起的。