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

时间:2014-01-02 22:52:56

标签: 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)

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

我们正在使用WAKE_LOCK权限

<uses-permission android:name="android.permission.WAKE_LOCK" />

for 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);
    }
}

2 个答案:

答案 0 :(得分:0)

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

我发现这来自我刚刚从示例代码中复制的代码。如果我从 public IBinder onBind(Intent intent)中抛出UnsupportedOperationException,就像在示例中我每隔五秒左右就会得到上面提到的异常唤醒锁定未激活

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

希望这会对你有所帮助。

答案 1 :(得分:0)

我有同样的错误,但是经常调用MediaPlayer.setVolume。