fix:修复ota 升级读写权限获取的问题
This commit is contained in:
parent
8dcc1c7be3
commit
abc2788e0c
@ -697,7 +697,7 @@ class BlueManage {
|
|||||||
connectDeviceMacAddress = "";
|
connectDeviceMacAddress = "";
|
||||||
if (bluetoothConnectionState == BluetoothConnectionState.connected) {
|
if (bluetoothConnectionState == BluetoothConnectionState.connected) {
|
||||||
//加快蓝牙断连
|
//加快蓝牙断连
|
||||||
await bluetoothConnectDevice!.disconnect(timeout: 1);
|
await bluetoothConnectDevice!.disconnect(timeout: 2);
|
||||||
AppLog.log("断开连接成功");
|
AppLog.log("断开连接成功");
|
||||||
}
|
}
|
||||||
// }
|
// }
|
||||||
|
|||||||
@ -48,8 +48,7 @@ class LockEscalationLogic extends BaseGetXController {
|
|||||||
|
|
||||||
//手动升级
|
//手动升级
|
||||||
Future<void> otaUpdate() async {
|
Future<void> otaUpdate() async {
|
||||||
var status = await PermissionDialog.request(
|
var status = await PermissionDialog.requestStorage();
|
||||||
Permission.storage, '需要访问读写权限才能使用手动升级固件'.tr);
|
|
||||||
if (status != true) {
|
if (status != true) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -69,8 +68,7 @@ class LockEscalationLogic extends BaseGetXController {
|
|||||||
}
|
}
|
||||||
String md5Str = md5.convert(otaBin!).toString();
|
String md5Str = md5.convert(otaBin!).toString();
|
||||||
headJson!['fwMd5'] = md5Str;
|
headJson!['fwMd5'] = md5Str;
|
||||||
ShowTipView().showIosTipWithContentDialog("未避免异常情况,请在门打开时升级".tr,
|
ShowTipView().showIosTipWithContentDialog("未避免异常情况,请在门打开时升级".tr, () async {
|
||||||
() async {
|
|
||||||
blueOTAUpgrade(headJson!, [0, 0, 0, 0]);
|
blueOTAUpgrade(headJson!, [0, 0, 0, 0]);
|
||||||
EasyLoading.show(
|
EasyLoading.show(
|
||||||
status: '设备连接中...'.tr, maskType: EasyLoadingMaskType.black);
|
status: '设备连接中...'.tr, maskType: EasyLoadingMaskType.black);
|
||||||
|
|||||||
@ -431,8 +431,7 @@ class NearbyLockLogic extends BaseGetXController {
|
|||||||
|
|
||||||
//手动升级
|
//手动升级
|
||||||
Future<void> otaUpdate() async {
|
Future<void> otaUpdate() async {
|
||||||
var status = await PermissionDialog.request(
|
var status = await PermissionDialog.requestStorage();
|
||||||
Permission.storage, '需要访问读写权限才能使用手动升级固件'.tr);
|
|
||||||
if (status != true) {
|
if (status != true) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -190,6 +190,98 @@ class PermissionDialog {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//读写
|
||||||
|
static Future<bool> requestStorage() async {
|
||||||
|
if (Get.context == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
bool isAndroid33 =
|
||||||
|
AppPlatform.isAndroid && AppPlatform.getSdkIntValue() >= 33;
|
||||||
|
|
||||||
|
//通用的局部函数
|
||||||
|
List<Permission> requestPermission() {
|
||||||
|
List<Permission> permissions;
|
||||||
|
if (isAndroid33) {
|
||||||
|
permissions = [
|
||||||
|
Permission.mediaLibrary,
|
||||||
|
Permission.photos,
|
||||||
|
// Permission.audio,
|
||||||
|
Permission.videos,
|
||||||
|
Permission.manageExternalStorage,
|
||||||
|
];
|
||||||
|
} else {
|
||||||
|
permissions = [
|
||||||
|
Permission.storage,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
return permissions;
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<bool> permissionStatus(List<Permission> permissions) async {
|
||||||
|
bool isGranted = true;
|
||||||
|
for (Permission permission in permissions) {
|
||||||
|
isGranted =
|
||||||
|
isGranted && (await permission.status) == PermissionStatus.granted;
|
||||||
|
}
|
||||||
|
if (isAndroid33) {
|
||||||
|
// android 33以上需要申请媒体库权限
|
||||||
|
isGranted = (await Permission.mediaLibrary.status) ==
|
||||||
|
PermissionStatus.granted ||
|
||||||
|
(await Permission.manageExternalStorage.status) ==
|
||||||
|
PermissionStatus.granted;
|
||||||
|
}
|
||||||
|
return isGranted;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool application = true;
|
||||||
|
Permission permission = Permission.photos;
|
||||||
|
List<Permission> permissions = requestPermission();
|
||||||
|
dynamic cache = await Storage.getString(titles[permission]);
|
||||||
|
bool isGranted = await permissionStatus(permissions);
|
||||||
|
if (AppPlatform.isAndroid && !isGranted && cache is! String) {
|
||||||
|
application = await showCupertinoDialog(
|
||||||
|
context: Get.context!,
|
||||||
|
builder: (context) {
|
||||||
|
return PopScope(
|
||||||
|
canPop: false,
|
||||||
|
child: CupertinoAlertDialog(
|
||||||
|
title: Text('${'申请'.tr}${titles[permission] ?? ''}${'权限'.tr}'),
|
||||||
|
content: Text('需要访问读写权限才能使用手动升级固件'.tr),
|
||||||
|
actions: [
|
||||||
|
CupertinoDialogAction(
|
||||||
|
child: Text('不允许'.tr),
|
||||||
|
onPressed: () {
|
||||||
|
Get.back(result: false);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
CupertinoDialogAction(
|
||||||
|
child: Text('允许'.tr),
|
||||||
|
onPressed: () {
|
||||||
|
Get.back(result: true);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
));
|
||||||
|
},
|
||||||
|
);
|
||||||
|
if (application) {
|
||||||
|
await Storage.setString(titles[permission], titles[permission]);
|
||||||
|
}
|
||||||
|
} else if (cache is String) {
|
||||||
|
bool isDenied = !(await permissionStatus(permissions));
|
||||||
|
if (isDenied) {
|
||||||
|
showSet(permission);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (application) {
|
||||||
|
Map<Permission, PermissionStatus> statuses = await permissions.request();
|
||||||
|
bool isGranted = await permissionStatus(statuses.keys.toList());
|
||||||
|
return isGranted;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
//显示权限判断申请框
|
//显示权限判断申请框
|
||||||
static Future<bool> request(Permission permission, [String? content]) async {
|
static Future<bool> request(Permission permission, [String? content]) async {
|
||||||
if (Get.context == null) {
|
if (Get.context == null) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user