Skip to content

Commit 34c12b4

Browse files
committed
设置超时时间为心跳间隔的1.5倍
1 parent 94e6d09 commit 34c12b4

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

hub/hub-device-android/src/main/java/com/tencent/iot/hub/device/android/core/mqtt/TXAlarmPingSender.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,11 @@ public void onReceive(Context context, Intent intent) {
158158
PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
159159
wakelock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, wakeLockTag);
160160
try { // 唤醒锁获取失败,抛出权限异常,同时避免后续的释放过程
161-
wakelock.acquire(60000);
161+
// 设置超时时间为心跳间隔的1.5倍,确保有足够时间等待ping响应
162+
long keepAliveTime = mComms.getKeepAlive();
163+
long timeout = Math.max(keepAliveTime * 3 / 2, 60000); // 至少60秒
164+
wakelock.acquire(timeout);
165+
TXLog.d(TAG, "WakeLock acquired with timeout: " + timeout + "ms, keepAlive: " + keepAliveTime + "ms");
162166
} catch (Exception e) {
163167
TXLog.e(TAG, "wakelock without permission.WAKE_LOCK return");
164168
e.printStackTrace();

0 commit comments

Comments
 (0)