diff --git a/frontend/device/kindle/device.lua b/frontend/device/kindle/device.lua index 2f68032bf..41ea0114f 100644 --- a/frontend/device/kindle/device.lua +++ b/frontend/device/kindle/device.lua @@ -54,12 +54,21 @@ local function kindleGetSavedNetworks() end if lipc_handle then local ha_input = lipc_handle:new_hasharray() -- an empty hash array since we only want to read - local ha_result = lipc_handle:access_hash_property("com.lab126.wifid", "profileData", ha_input) - local profiles = ha_result:to_table() - ha_result:destroy() - ha_input:destroy() - lipc_handle:close() - return profiles + local success, ha_result = pcall(function() + return lipc_handle:access_hash_property("com.lab126.wifid", "profileData", ha_input) + end) + if success then + local profiles = ha_result:to_table() + ha_result:destroy() + ha_input:destroy() + lipc_handle:close() + return profiles + else + logger.warn("kindleGetSavedNetworks: failed to access profileData") + ha_input:destroy() + lipc_handle:close() + return {} + end end end @@ -71,12 +80,22 @@ local function kindleGetCurrentProfile() end if lipc_handle then local ha_input = lipc_handle:new_hasharray() -- an empty hash array since we only want to read - local ha_result = lipc_handle:access_hash_property("com.lab126.wifid", "currentEssid", ha_input) - local profile = ha_result:to_table()[1] -- there is only a single element - ha_input:destroy() - ha_result:destroy() - lipc_handle:close() - return profile + local success, ha_result = pcall(function() + return lipc_handle:access_hash_property("com.lab126.wifid", "currentEssid", ha_input) + end) + + if success then + local profile = ha_result:to_table()[1] -- there is only a single element + ha_input:destroy() + ha_result:destroy() + lipc_handle:close() + return profile + else + logger.warn("kindleGetCurrentProfile: failed to access currentEssid") + ha_input:destroy() + lipc_handle:close() + return nil + end else return nil end @@ -111,7 +130,14 @@ local function kindleSaveNetwork(data) else profile:put_string(0, "secured", "no") end - lipc_handle:access_hash_property("com.lab126.wifid", "createProfile", profile):destroy() -- destroy the returned empty ha + local success, result = pcall(function() + return lipc_handle:access_hash_property("com.lab126.wifid", "createProfile", profile) + end) + if success then + result:destroy() -- destroy the returned empty ha + else + logger.warn("kindleSaveNetwork: failed to createProfile") + end profile:destroy() lipc_handle:close() end @@ -125,9 +151,26 @@ local function kindleGetScanList() lipc_handle = lipc.open_no_name() end if lipc_handle then - if lipc_handle:get_string_property("com.lab126.wifid", "cmState") ~= "CONNECTED" then + local success, cm_state = pcall(function() + return lipc_handle:get_string_property("com.lab126.wifid", "cmState") + end) + if not success then + -- cmState may fail when the LIPC backend is temporarily unavailable (e.g., suspend/lock). + logger.warn("kindleGetScanList: failed to access cmState") + end + -- Fall back to scanList if cmState is unavailable or not CONNECTED (cm_state may be nil). + local need_scan = (not success) or (cm_state ~= "CONNECTED") + if need_scan then local ha_input = lipc_handle:new_hasharray() - local ha_results = lipc_handle:access_hash_property("com.lab126.wifid", "scanList", ha_input) + local success_scan, ha_results = pcall(function() + return lipc_handle:access_hash_property("com.lab126.wifid", "scanList", ha_input) + end) + if not success_scan then + logger.warn("kindleGetScanList: failed to access scanList") + ha_input:destroy() + lipc_handle:close() + return {}, nil + end if ha_results == nil then -- Shouldn't really happen, access_hash_property will throw if LipcAccessHasharrayProperty failed ha_input:destroy() @@ -194,7 +237,14 @@ local function kindleScanThenGetResults() local done_scanning = false local wait_cnt = 80 -- 20s in chunks on 250ms while wait_cnt > 0 do - local scan_state = lipc_handle:get_string_property("com.lab126.wifid", "scanState") + local success, scan_state = pcall(function() + return lipc_handle:get_string_property("com.lab126.wifid", "scanState") + end) + + if not success then + logger.warn("kindleScanThenGetResults: failed to get scanState, aborting scan") + break + end if scan_state == "idle" then done_scanning = true