gpt4 book ai didi

android - Paho MQTT AlarmPingSender 唤醒锁卡住

转载 作者:行者123 更新时间:2023-11-29 20:32:04 27 4
gpt4 key购买 nike

我正在为我的项目使用 Paho Android 服务(应用程序名称是 Sealer)。 ( link )

我测试了大约 22 小时,结果给我带来了一个奇怪的结果。

我的应用似乎让 CPU 保持唤醒状态很长时间(~10.5 小时)。

我通过wakelock标签在源码中查找,发现wakelock标签属于AlarmPingSender类。有人遇到过这个问题吗?

没有修改Android服务源代码,它是原始的。

我附上了一些屏幕截图(环聊和 Viber 只是为了比较)。

Screenshots

编辑 1.

我的源代码中有一个代码 fragment :

    mqttOptions = new MqttConnectOptions();
mqttOptions.setCleanSession(false);
// defaultKeepAlive is 240
mqttOptions.setKeepAliveInterval(Constants.defaultKeepAlive);

编辑 2

我认为这是 Android 服务源代码中的相关代码:

/*
* This class sends PingReq packet to MQTT broker
*/
class AlarmReceiver extends BroadcastReceiver {
private WakeLock wakelock;
private String wakeLockTag = MqttServiceConstants.PING_WAKELOCK
+ that.comms.getClient().getClientId();

@Override
public void onReceive(Context context, Intent intent) {
// According to the docs, "Alarm Manager holds a CPU wake lock as
// long as the alarm receiver's onReceive() method is executing.
// This guarantees that the phone will not sleep until you have
// finished handling the broadcast.", but this class still get
// a wake lock to wait for ping finished.
int count = intent.getIntExtra(Intent.EXTRA_ALARM_COUNT, -1);
Log.d(TAG, "Ping " + count + " times.");

Log.d(TAG, "Check time :" + System.currentTimeMillis());
IMqttToken token = comms.checkForActivity();

// No ping has been sent.
if (token == null) {
return;
}

// Assign new callback to token to execute code after PingResq
// arrives. Get another wakelock even receiver already has one,
// release it until ping response returns.
if (wakelock == null) {
PowerManager pm = (PowerManager) service
.getSystemService(Service.POWER_SERVICE);
wakelock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
wakeLockTag);
}
wakelock.acquire();
token.setActionCallback(new IMqttActionListener() {

@Override
public void onSuccess(IMqttToken asyncActionToken) {
Log.d(TAG, "Success. Release lock(" + wakeLockTag + "):"
+ System.currentTimeMillis());
//Release wakelock when it is done.
if(wakelock != null && wakelock.isHeld()){
wakelock.release();
}
}

@Override
public void onFailure(IMqttToken asyncActionToken,
Throwable exception) {
Log.d(TAG, "Failure. Release lock(" + wakeLockTag + "):"
+ System.currentTimeMillis());
//Release wakelock when it is done.
if(wakelock != null && wakelock.isHeld()){
wakelock.release();
}
}
});
}
}

似乎(至少根据屏幕截图)唤醒锁不知何故“卡住了”,没有释放。

最佳答案

我有同样的问题并创建了一个错误报告。请查看更多帮助:https://bugs.eclipse.org/bugs/show_bug.cgi?id=480134

关于android - Paho MQTT AlarmPingSender 唤醒锁卡住,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31780657/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com