|
@ -32,6 +32,9 @@ public class DeviceSelectDataManager { |
|
|
private static final String KEY_API_RESPONSE_MESSAGE = "api_response_message"; |
|
|
private static final String KEY_API_RESPONSE_MESSAGE = "api_response_message"; |
|
|
private static final String KEY_API_FULL_RESPONSE = "api_full_response"; |
|
|
private static final String KEY_API_FULL_RESPONSE = "api_full_response"; |
|
|
|
|
|
|
|
|
|
|
|
// 新增:人脸识别许可证存储常量 |
|
|
|
|
|
private static final String KEY_FACE_LICENSE = "face_license"; |
|
|
|
|
|
|
|
|
private SharedPreferences preferences; |
|
|
private SharedPreferences preferences; |
|
|
private Gson gson; |
|
|
private Gson gson; |
|
|
|
|
|
|
|
@ -42,6 +45,8 @@ public class DeviceSelectDataManager { |
|
|
private PadApiService.PadSelectResponse currentSelectResponse; |
|
|
private PadApiService.PadSelectResponse currentSelectResponse; |
|
|
private PadApiService.PadInfo currentSelectedPadInfo; |
|
|
private PadApiService.PadInfo currentSelectedPadInfo; |
|
|
private boolean isDeviceSelected = false; |
|
|
private boolean isDeviceSelected = false; |
|
|
|
|
|
// 新增:人脸识别许可证内存缓存 |
|
|
|
|
|
private String faceLicense; |
|
|
|
|
|
|
|
|
// API响应存储 |
|
|
// API响应存储 |
|
|
private int apiResponseCode; |
|
|
private int apiResponseCode; |
|
@ -93,6 +98,8 @@ public class DeviceSelectDataManager { |
|
|
// 将data对象转换为JSON字符串 |
|
|
// 将data对象转换为JSON字符串 |
|
|
if (apiResponse.getData() != null) { |
|
|
if (apiResponse.getData() != null) { |
|
|
this.apiResponseDataJson = gson.toJson(apiResponse.getData()); |
|
|
this.apiResponseDataJson = gson.toJson(apiResponse.getData()); |
|
|
|
|
|
// 新增:提取并保存faceLicense |
|
|
|
|
|
extractAndSaveFaceLicense(apiResponse.getData()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 将完整响应转换为JSON字符串 |
|
|
// 将完整响应转换为JSON字符串 |
|
@ -123,6 +130,11 @@ public class DeviceSelectDataManager { |
|
|
editor.putString(KEY_API_RESPONSE_MESSAGE, apiResponseMessage); |
|
|
editor.putString(KEY_API_RESPONSE_MESSAGE, apiResponseMessage); |
|
|
editor.putString(KEY_API_FULL_RESPONSE, apiFullResponse); |
|
|
editor.putString(KEY_API_FULL_RESPONSE, apiFullResponse); |
|
|
|
|
|
|
|
|
|
|
|
// 新增:保存人脸识别许可证 |
|
|
|
|
|
if (faceLicense != null && !faceLicense.isEmpty()) { |
|
|
|
|
|
editor.putString(KEY_FACE_LICENSE, faceLicense); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
editor.apply(); |
|
|
editor.apply(); |
|
|
|
|
|
|
|
|
Log.d(TAG, "完整API响应数据保存成功"); |
|
|
Log.d(TAG, "完整API响应数据保存成功"); |
|
@ -238,6 +250,8 @@ public class DeviceSelectDataManager { |
|
|
this.apiResponseDataJson = null; |
|
|
this.apiResponseDataJson = null; |
|
|
this.apiResponseMessage = null; |
|
|
this.apiResponseMessage = null; |
|
|
this.apiFullResponse = null; |
|
|
this.apiFullResponse = null; |
|
|
|
|
|
// 新增:清除人脸识别许可证内存缓存 |
|
|
|
|
|
this.faceLicense = null; |
|
|
|
|
|
|
|
|
// 清除持久化存储 |
|
|
// 清除持久化存储 |
|
|
SharedPreferences.Editor editor = preferences.edit(); |
|
|
SharedPreferences.Editor editor = preferences.edit(); |
|
@ -255,6 +269,9 @@ public class DeviceSelectDataManager { |
|
|
editor.remove(KEY_API_RESPONSE_MESSAGE); |
|
|
editor.remove(KEY_API_RESPONSE_MESSAGE); |
|
|
editor.remove(KEY_API_FULL_RESPONSE); |
|
|
editor.remove(KEY_API_FULL_RESPONSE); |
|
|
|
|
|
|
|
|
|
|
|
// 新增:清除人脸识别许可证持久化存储 |
|
|
|
|
|
editor.remove(KEY_FACE_LICENSE); |
|
|
|
|
|
|
|
|
editor.apply(); |
|
|
editor.apply(); |
|
|
|
|
|
|
|
|
Log.d(TAG, "设备选择数据已清除"); |
|
|
Log.d(TAG, "设备选择数据已清除"); |
|
@ -292,9 +309,23 @@ 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); |
|
|
|
|
|
|
|
|
|
|
|
// 新增:加载人脸识别许可证 |
|
|
|
|
|
faceLicense = preferences.getString(KEY_FACE_LICENSE, null); |
|
|
|
|
|
|
|
|
if (apiResponseCode > 0 || (apiResponseDataJson != null && !apiResponseDataJson.isEmpty())) { |
|
|
if (apiResponseCode > 0 || (apiResponseDataJson != null && !apiResponseDataJson.isEmpty())) { |
|
|
Log.d(TAG, "从本地存储恢复API响应数据成功"); |
|
|
Log.d(TAG, "从本地存储恢复API响应数据成功"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 如果有API响应数据但没有faceLicense,尝试从响应数据中提取 |
|
|
|
|
|
if ((apiResponseCode > 0 || (apiResponseDataJson != null && !apiResponseDataJson.isEmpty())) |
|
|
|
|
|
&& (faceLicense == null || faceLicense.isEmpty())) { |
|
|
|
|
|
try { |
|
|
|
|
|
PadApiService.PadSelectResponse response = gson.fromJson(apiResponseDataJson, PadApiService.PadSelectResponse.class); |
|
|
|
|
|
extractAndSaveFaceLicense(response); |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
Log.e(TAG, "从API响应数据中提取人脸识别许可证失败: " + e.getMessage()); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} catch (Exception e) { |
|
|
} catch (Exception e) { |
|
|
Log.e(TAG, "加载设备选择数据失败: " + e.getMessage()); |
|
|
Log.e(TAG, "加载设备选择数据失败: " + e.getMessage()); |
|
|
// 清除可能损坏的数据 |
|
|
// 清除可能损坏的数据 |
|
@ -345,6 +376,9 @@ public class DeviceSelectDataManager { |
|
|
this.currentSelectedPadInfo = selectedPadInfo; |
|
|
this.currentSelectedPadInfo = selectedPadInfo; |
|
|
this.isDeviceSelected = true; |
|
|
this.isDeviceSelected = true; |
|
|
|
|
|
|
|
|
|
|
|
// 新增:提取并保存faceLicense |
|
|
|
|
|
extractAndSaveFaceLicense(selectResponse); |
|
|
|
|
|
|
|
|
// 保存到持久化存储 |
|
|
// 保存到持久化存储 |
|
|
SharedPreferences.Editor editor = preferences.edit(); |
|
|
SharedPreferences.Editor editor = preferences.edit(); |
|
|
editor.putString(KEY_SELECT_RESPONSE, gson.toJson(selectResponse)); |
|
|
editor.putString(KEY_SELECT_RESPONSE, gson.toJson(selectResponse)); |
|
@ -361,6 +395,12 @@ public class DeviceSelectDataManager { |
|
|
editor.putLong(KEY_VALID_UNTIL, selectResponse.getValidUntil()); |
|
|
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); |
|
|
|
|
|
|
|
|
|
|
|
// 新增:保存人脸识别许可证 |
|
|
|
|
|
if (faceLicense != null && !faceLicense.isEmpty()) { |
|
|
|
|
|
editor.putString(KEY_FACE_LICENSE, faceLicense); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
editor.apply(); |
|
|
editor.apply(); |
|
|
|
|
|
|
|
|
Log.d(TAG, "设备选择数据保存成功"); |
|
|
Log.d(TAG, "设备选择数据保存成功"); |
|
@ -488,4 +528,46 @@ public class DeviceSelectDataManager { |
|
|
|
|
|
|
|
|
Log.i(TAG, "=============================="); |
|
|
Log.i(TAG, "=============================="); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 从PadSelectResponse中提取人脸识别许可证并保存到内存缓存 |
|
|
|
|
|
* @param response PadSelectResponse对象 |
|
|
|
|
|
*/ |
|
|
|
|
|
private void extractAndSaveFaceLicense(PadApiService.PadSelectResponse response) { |
|
|
|
|
|
try { |
|
|
|
|
|
if (response != null && response.getPadConfig() != null) { |
|
|
|
|
|
String license = response.getPadConfig().getFaceLicense(); |
|
|
|
|
|
if (license != null && !license.isEmpty()) { |
|
|
|
|
|
this.faceLicense = license; |
|
|
|
|
|
Log.d(TAG, "人脸识别许可证提取成功,长度: " + license.length()); |
|
|
|
|
|
} else { |
|
|
|
|
|
Log.w(TAG, "人脸识别许可证为空或不存在"); |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
Log.w(TAG, "无法提取人脸识别许可证:PadSelectResponse或PadConfig为空"); |
|
|
|
|
|
} |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
Log.e(TAG, "提取人脸识别许可证失败: " + e.getMessage(), e); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 获取人脸识别许可证 |
|
|
|
|
|
* @return 人脸识别许可证字符串 |
|
|
|
|
|
*/ |
|
|
|
|
|
public String getFaceLicense() { |
|
|
|
|
|
if (faceLicense != null) { |
|
|
|
|
|
return faceLicense; |
|
|
|
|
|
} |
|
|
|
|
|
return preferences.getString(KEY_FACE_LICENSE, ""); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 检查是否存在有效的人脸识别许可证 |
|
|
|
|
|
* @return true如果存在有效的人脸识别许可证 |
|
|
|
|
|
*/ |
|
|
|
|
|
public boolean hasFaceLicense() { |
|
|
|
|
|
String license = getFaceLicense(); |
|
|
|
|
|
return license != null && !license.isEmpty(); |
|
|
|
|
|
} |
|
|
} |
|
|
} |