|
@ -22,7 +22,6 @@ public class DeviceSelectDataManager { |
|
|
private static final String KEY_SELECTED_HARDWARE_ID = "selected_hardware_id"; |
|
|
private static final String KEY_SELECTED_HARDWARE_ID = "selected_hardware_id"; |
|
|
private static final String KEY_SELECTED_HARDWARE_NAME = "selected_hardware_name"; |
|
|
private static final String KEY_SELECTED_HARDWARE_NAME = "selected_hardware_name"; |
|
|
private static final String KEY_SESSION_TOKEN = "session_token"; |
|
|
private static final String KEY_SESSION_TOKEN = "session_token"; |
|
|
private static final String KEY_VALID_UNTIL = "valid_until"; |
|
|
|
|
|
private static final String KEY_SELECT_TIME = "select_time"; |
|
|
private static final String KEY_SELECT_TIME = "select_time"; |
|
|
private static final String KEY_IS_DEVICE_SELECTED = "is_device_selected"; |
|
|
private static final String KEY_IS_DEVICE_SELECTED = "is_device_selected"; |
|
|
|
|
|
|
|
@ -84,6 +83,13 @@ public class DeviceSelectDataManager { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
|
|
|
* 重新加载设备选择数据(用于调试和修复数据问题) |
|
|
|
|
|
*/ |
|
|
|
|
|
public void reloadSelectData() { |
|
|
|
|
|
loadSelectDataFromPrefs(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
* 保存完整的API响应数据(包括code和data) |
|
|
* 保存完整的API响应数据(包括code和data) |
|
|
* @param apiResponse 完整的API响应 |
|
|
* @param apiResponse 完整的API响应 |
|
|
* @param selectedPadInfo 选中的设备信息 |
|
|
* @param selectedPadInfo 选中的设备信息 |
|
@ -125,9 +131,12 @@ public class DeviceSelectDataManager { |
|
|
|
|
|
|
|
|
if (currentSelectResponse != null && currentSelectResponse.getSessionToken() != null) { |
|
|
if (currentSelectResponse != null && currentSelectResponse.getSessionToken() != null) { |
|
|
editor.putString(KEY_SESSION_TOKEN, currentSelectResponse.getSessionToken()); |
|
|
editor.putString(KEY_SESSION_TOKEN, currentSelectResponse.getSessionToken()); |
|
|
|
|
|
Log.d(TAG, "保存sessionToken到SharedPreferences: " + currentSelectResponse.getSessionToken()); |
|
|
|
|
|
} else { |
|
|
|
|
|
Log.w(TAG, "currentSelectResponse或sessionToken为空,无法保存"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
editor.putLong(KEY_VALID_UNTIL, currentSelectResponse != null ? currentSelectResponse.getValidUntil() : 0); |
|
|
|
|
|
|
|
|
// 移除了对KEY_VALID_UNTIL的使用,因为服务器不再返回valid_until字段 |
|
|
editor.putLong(KEY_SELECT_TIME, System.currentTimeMillis()); |
|
|
editor.putLong(KEY_SELECT_TIME, System.currentTimeMillis()); |
|
|
editor.putBoolean(KEY_IS_DEVICE_SELECTED, isDeviceSelected); |
|
|
editor.putBoolean(KEY_IS_DEVICE_SELECTED, isDeviceSelected); |
|
|
|
|
|
|
|
@ -147,7 +156,9 @@ public class DeviceSelectDataManager { |
|
|
editor.putString(KEY_MINI_QRCODE_URL, miniQrcodeUrl); |
|
|
editor.putString(KEY_MINI_QRCODE_URL, miniQrcodeUrl); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
editor.apply(); |
|
|
|
|
|
|
|
|
// 确保数据被提交 |
|
|
|
|
|
boolean commitResult = editor.commit(); |
|
|
|
|
|
Log.d(TAG, "SharedPreferences提交结果: " + commitResult); |
|
|
|
|
|
|
|
|
Log.d(TAG, "完整API响应数据保存成功"); |
|
|
Log.d(TAG, "完整API响应数据保存成功"); |
|
|
logCompleteApiResponseInfo(); |
|
|
logCompleteApiResponseInfo(); |
|
@ -178,10 +189,39 @@ public class DeviceSelectDataManager { |
|
|
* @return 会话Token |
|
|
* @return 会话Token |
|
|
*/ |
|
|
*/ |
|
|
public String getSessionToken() { |
|
|
public String getSessionToken() { |
|
|
|
|
|
// 首先尝试从内存缓存获取 |
|
|
if (currentSelectResponse != null) { |
|
|
if (currentSelectResponse != null) { |
|
|
return currentSelectResponse.getSessionToken(); |
|
|
|
|
|
|
|
|
String token = currentSelectResponse.getSessionToken(); |
|
|
|
|
|
if (token != null && !token.isEmpty()) { |
|
|
|
|
|
return token; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 如果内存缓存中没有,则尝试从SharedPreferences获取 |
|
|
|
|
|
String token = preferences.getString(KEY_SESSION_TOKEN, ""); |
|
|
|
|
|
if (token != null && !token.isEmpty()) { |
|
|
|
|
|
// 同时更新内存缓存 |
|
|
|
|
|
if (currentSelectResponse == null) { |
|
|
|
|
|
// 尝试重建currentSelectResponse |
|
|
|
|
|
String selectResponseJson = preferences.getString(KEY_SELECT_RESPONSE, ""); |
|
|
|
|
|
if (!selectResponseJson.isEmpty()) { |
|
|
|
|
|
try { |
|
|
|
|
|
currentSelectResponse = gson.fromJson(selectResponseJson, PadApiService.PadSelectResponse.class); |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
Log.e(TAG, "重建currentSelectResponse时发生异常: " + e.getMessage()); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 确保currentSelectResponse中的sessionToken也被更新 |
|
|
|
|
|
if (currentSelectResponse != null) { |
|
|
|
|
|
currentSelectResponse.setSessionToken(token); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return token; |
|
|
} |
|
|
} |
|
|
return preferences.getString(KEY_SESSION_TOKEN, ""); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ""; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
@ -211,10 +251,8 @@ public class DeviceSelectDataManager { |
|
|
* @return 有效期时间戳 |
|
|
* @return 有效期时间戳 |
|
|
*/ |
|
|
*/ |
|
|
public long getValidUntil() { |
|
|
public long getValidUntil() { |
|
|
if (currentSelectResponse != null) { |
|
|
|
|
|
return currentSelectResponse.getValidUntil(); |
|
|
|
|
|
} |
|
|
|
|
|
return preferences.getLong(KEY_VALID_UNTIL, 0); |
|
|
|
|
|
|
|
|
// 服务器不再返回valid_until字段,始终返回0 |
|
|
|
|
|
return 0; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
@ -230,16 +268,9 @@ public class DeviceSelectDataManager { |
|
|
* @return true如果会话有效 |
|
|
* @return true如果会话有效 |
|
|
*/ |
|
|
*/ |
|
|
public boolean isSessionValid() { |
|
|
public boolean isSessionValid() { |
|
|
long validUntil = getValidUntil(); |
|
|
|
|
|
if (validUntil <= 0) { |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
long currentTime = System.currentTimeMillis(); |
|
|
|
|
|
boolean isValid = currentTime < validUntil; |
|
|
|
|
|
|
|
|
|
|
|
Log.d(TAG, "会话有效性检查 - 当前时间: " + currentTime + ", 有效期至: " + validUntil + ", 有效: " + isValid); |
|
|
|
|
|
return isValid; |
|
|
|
|
|
|
|
|
// 服务器不再返回valid_until字段,无法检查会话有效性 |
|
|
|
|
|
// 默认返回true,假设会话始终有效 |
|
|
|
|
|
return true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
@ -273,7 +304,6 @@ public class DeviceSelectDataManager { |
|
|
editor.remove(KEY_SELECTED_HARDWARE_ID); |
|
|
editor.remove(KEY_SELECTED_HARDWARE_ID); |
|
|
editor.remove(KEY_SELECTED_HARDWARE_NAME); |
|
|
editor.remove(KEY_SELECTED_HARDWARE_NAME); |
|
|
editor.remove(KEY_SESSION_TOKEN); |
|
|
editor.remove(KEY_SESSION_TOKEN); |
|
|
editor.remove(KEY_VALID_UNTIL); |
|
|
|
|
|
editor.remove(KEY_SELECT_TIME); |
|
|
editor.remove(KEY_SELECT_TIME); |
|
|
editor.putBoolean(KEY_IS_DEVICE_SELECTED, false); |
|
|
editor.putBoolean(KEY_IS_DEVICE_SELECTED, false); |
|
|
|
|
|
|
|
@ -302,12 +332,18 @@ public class DeviceSelectDataManager { |
|
|
String selectResponseJson = preferences.getString(KEY_SELECT_RESPONSE, ""); |
|
|
String selectResponseJson = preferences.getString(KEY_SELECT_RESPONSE, ""); |
|
|
boolean savedIsDeviceSelected = preferences.getBoolean(KEY_IS_DEVICE_SELECTED, false); |
|
|
boolean savedIsDeviceSelected = preferences.getBoolean(KEY_IS_DEVICE_SELECTED, false); |
|
|
|
|
|
|
|
|
|
|
|
Log.d(TAG, "从SharedPreferences加载数据: selectResponseJson=" + (selectResponseJson != null ? selectResponseJson.length() : 0) + |
|
|
|
|
|
"字符, savedIsDeviceSelected=" + savedIsDeviceSelected); |
|
|
|
|
|
|
|
|
if (!selectResponseJson.isEmpty() && savedIsDeviceSelected) { |
|
|
if (!selectResponseJson.isEmpty() && savedIsDeviceSelected) { |
|
|
currentSelectResponse = gson.fromJson(selectResponseJson, PadApiService.PadSelectResponse.class); |
|
|
currentSelectResponse = gson.fromJson(selectResponseJson, PadApiService.PadSelectResponse.class); |
|
|
|
|
|
Log.d(TAG, "成功解析selectResponseJson"); |
|
|
|
|
|
|
|
|
// 重建PadInfo对象 |
|
|
// 重建PadInfo对象 |
|
|
int hardwareId = preferences.getInt(KEY_SELECTED_HARDWARE_ID, 0); |
|
|
int hardwareId = preferences.getInt(KEY_SELECTED_HARDWARE_ID, 0); |
|
|
String hardwareName = preferences.getString(KEY_SELECTED_HARDWARE_NAME, ""); |
|
|
String hardwareName = preferences.getString(KEY_SELECTED_HARDWARE_NAME, ""); |
|
|
|
|
|
Log.d(TAG, "从SharedPreferences获取hardwareId=" + hardwareId + ", hardwareName=" + hardwareName); |
|
|
|
|
|
|
|
|
if (hardwareId > 0) { |
|
|
if (hardwareId > 0) { |
|
|
currentSelectedPadInfo = new PadApiService.PadInfo(); |
|
|
currentSelectedPadInfo = new PadApiService.PadInfo(); |
|
|
currentSelectedPadInfo.setHardwareId(hardwareId); |
|
|
currentSelectedPadInfo.setHardwareId(hardwareId); |
|
@ -326,11 +362,31 @@ public class DeviceSelectDataManager { |
|
|
apiResponseMessage = preferences.getString(KEY_API_RESPONSE_MESSAGE, null); |
|
|
apiResponseMessage = preferences.getString(KEY_API_RESPONSE_MESSAGE, null); |
|
|
apiFullResponse = preferences.getString(KEY_API_FULL_RESPONSE, null); |
|
|
apiFullResponse = preferences.getString(KEY_API_FULL_RESPONSE, null); |
|
|
|
|
|
|
|
|
|
|
|
Log.d(TAG, "加载API响应数据: code=" + apiResponseCode + |
|
|
|
|
|
", dataJson=" + (apiResponseDataJson != null ? apiResponseDataJson.length() : 0) + "字符" + |
|
|
|
|
|
", message=" + (apiResponseMessage != null ? apiResponseMessage : "null") + |
|
|
|
|
|
", fullResponse=" + (apiFullResponse != null ? apiFullResponse.length() : 0) + "字符"); |
|
|
|
|
|
|
|
|
// 新增:加载人脸识别许可证 |
|
|
// 新增:加载人脸识别许可证 |
|
|
faceLicense = preferences.getString(KEY_FACE_LICENSE, null); |
|
|
faceLicense = preferences.getString(KEY_FACE_LICENSE, null); |
|
|
|
|
|
|
|
|
// 新增:加载小程序码链接 |
|
|
// 新增:加载小程序码链接 |
|
|
miniQrcodeUrl = preferences.getString(KEY_MINI_QRCODE_URL, null); |
|
|
miniQrcodeUrl = preferences.getString(KEY_MINI_QRCODE_URL, null); |
|
|
|
|
|
uploadFaceMiniQrcodeUrl = preferences.getString(KEY_UPLOAD_FACE_MINI_QRCODE_URL, null); |
|
|
|
|
|
|
|
|
|
|
|
// 确保sessionToken也被正确加载到内存中 |
|
|
|
|
|
String sessionToken = preferences.getString(KEY_SESSION_TOKEN, ""); |
|
|
|
|
|
Log.d(TAG, "从SharedPreferences加载sessionToken: " + (sessionToken != null ? sessionToken.length() : 0) + "字符"); |
|
|
|
|
|
|
|
|
|
|
|
if (currentSelectResponse != null && (currentSelectResponse.getSessionToken() == null || currentSelectResponse.getSessionToken().isEmpty())) { |
|
|
|
|
|
// 如果currentSelectResponse中的sessionToken为空,但SharedPreferences中有,尝试更新 |
|
|
|
|
|
if (sessionToken != null && !sessionToken.isEmpty()) { |
|
|
|
|
|
currentSelectResponse.setSessionToken(sessionToken); |
|
|
|
|
|
Log.d(TAG, "通过setSessionToken更新currentSelectResponse中的sessionToken成功"); |
|
|
|
|
|
} |
|
|
|
|
|
} else if (currentSelectResponse != null) { |
|
|
|
|
|
Log.d(TAG, "currentSelectResponse中已有sessionToken: " + (currentSelectResponse.getSessionToken() != null ? currentSelectResponse.getSessionToken().length() : 0) + "字符"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if (apiResponseCode > 0 || (apiResponseDataJson != null && !apiResponseDataJson.isEmpty())) { |
|
|
if (apiResponseCode > 0 || (apiResponseDataJson != null && !apiResponseDataJson.isEmpty())) { |
|
|
Log.d(TAG, "从本地存储恢复API响应数据成功"); |
|
|
Log.d(TAG, "从本地存储恢复API响应数据成功"); |
|
@ -364,7 +420,6 @@ public class DeviceSelectDataManager { |
|
|
Log.i(TAG, "选中设备ID: " + getSelectedHardwareId()); |
|
|
Log.i(TAG, "选中设备ID: " + getSelectedHardwareId()); |
|
|
Log.i(TAG, "选中设备名称: " + getSelectedHardwareName()); |
|
|
Log.i(TAG, "选中设备名称: " + getSelectedHardwareName()); |
|
|
Log.i(TAG, "会话Token: " + (getSessionToken() != null && !getSessionToken().isEmpty() ? "已设置" : "未设置")); |
|
|
Log.i(TAG, "会话Token: " + (getSessionToken() != null && !getSessionToken().isEmpty() ? "已设置" : "未设置")); |
|
|
Log.i(TAG, "有效期至: " + getValidUntil()); |
|
|
|
|
|
Log.i(TAG, "会话是否有效: " + isSessionValid()); |
|
|
Log.i(TAG, "会话是否有效: " + isSessionValid()); |
|
|
Log.i(TAG, "========================"); |
|
|
Log.i(TAG, "========================"); |
|
|
} |
|
|
} |
|
@ -412,7 +467,6 @@ public class DeviceSelectDataManager { |
|
|
editor.putString(KEY_SESSION_TOKEN, selectResponse.getSessionToken()); |
|
|
editor.putString(KEY_SESSION_TOKEN, selectResponse.getSessionToken()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
editor.putLong(KEY_VALID_UNTIL, selectResponse.getValidUntil()); |
|
|
|
|
|
editor.putLong(KEY_SELECT_TIME, System.currentTimeMillis()); |
|
|
editor.putLong(KEY_SELECT_TIME, System.currentTimeMillis()); |
|
|
editor.putBoolean(KEY_IS_DEVICE_SELECTED, true); |
|
|
editor.putBoolean(KEY_IS_DEVICE_SELECTED, true); |
|
|
|
|
|
|
|
|