唤醒锁定不断在Nexus 5上引发异常

Bjo*_*inn 6 android exception wakelock

我们最近使用Nexus 5作为测试设备.它正在运行Android 4.4.2.问题是它每隔2到4秒不断地将以下异常作为警告:

01-02 22:33:33.482      751-894/? W/Binder? Caught a RuntimeException from the binder stub implementation.
java.lang.IllegalArgumentException: Wake lock not active
        at com.android.server.power.PowerManagerService.updateWakeLockWorkSourceInternal(PowerManagerService.java:794)
        at com.android.server.power.PowerManagerService.updateWakeLockWorkSource(PowerManagerService.java:780)
        at com.android.server.power.PowerManagerService.updateWakeLockUids(PowerManagerService.java:761)
        at android.os.IPowerManager$Stub.onTransact(IPowerManager.java:103)
        at android.os.Binder.execTransact(Binder.java:404)
        at dalvik.system.NativeStart.run(Native Method)
Run Code Online (Sandbox Code Playgroud)

我们测试的其他手机没有显示相同的警告(包括运行4.4.2的Nexus 4)

我们正在使用WAKE_LOCK权限

<uses-permission android:name="android.permission.WAKE_LOCK" />
Run Code Online (Sandbox Code Playgroud)

适用于Google Cloud Messenger

我也确保在我们的应用程序中发生这种情况.按包名过滤logcat后的警告停留.退出应用程序后,它也会停止.

这导致的主要问题是Android Studio在一段时间后滞后所以我需要清除logcat.运行时异常也不是我想要撒谎的东西.任何想法为什么会这样?

[编辑]
这是我们的代码中使用它的地方.这只是谷歌的GcmBroadcastReceiver

public class GcmBroadcastReceiver extends WakefulBroadcastReceiver
{
    public void onReceive(Context context, Intent intent)
    {
        // Explicitly specify that GcmIntentService will handle the intent.
        ComponentName comp = new ComponentName(context.getPackageName(), GcmIntentService.class.getName());

        // Start the service, keeping the device awake while it is launching.
        startWakefulService(context, (intent.setComponent(comp)));
        setResultCode(Activity.RESULT_OK);
    }
}
Run Code Online (Sandbox Code Playgroud)

小智 0

这可能与我使用 MediaPlayer 时遇到的问题相同。当我要求 MediaPlayer 在单独的线程服务中为我处理唤醒锁时,我每五秒左右就会收到唤醒锁未激活状态。

我发现这来自我刚刚从示例代码中复制的代码。如果我从public IBinder onBind(Intentintent)抛出 UnsupportedOperationException ,如示例中所示,我会每五秒左右收到上述异常Wake lock not active 。

简单的解决方案是返回 null而不是抛出异常。

希望这对您有帮助。