Skip to content

Commit

Permalink
feat: auto start and battery optimization permission denied (#279)
Browse files Browse the repository at this point in the history
* feat: autoStart and batteryOptimization permission denied

* fix: autoStart and batteryOptimization permission denied

* feat: autoStart and batteryOptimization permission page

* fix: autoStart and batteryOptimization permission page

* build: 2041003

* build: 2.5.0

* build: 2051001

* fix: ios

* fix: ios

* feat: locationAlways

* build: 2051002

* fix: _autoStartPermission

* build: 2051003

* fix: permission

* fix: permission

* build: 2051005

* Update app_zh.arb

* i18

---------

Co-authored-by: lowrt <[email protected]>
  • Loading branch information
yayacat and lowrt authored Oct 21, 2024
1 parent b8d45d0 commit 6bef296
Show file tree
Hide file tree
Showing 5 changed files with 350 additions and 19 deletions.
2 changes: 1 addition & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ android {
applicationId "com.exptech.dpip"
minSdkVersion flutter.minSdkVersion
targetSdkVersion flutter.targetSdkVersion
versionCode 2041001
versionCode 2051005
versionName flutterVersionName
multiDexEnabled true
}
Expand Down
24 changes: 24 additions & 0 deletions lib/l10n/app_zh_TW.arb
Original file line number Diff line number Diff line change
Expand Up @@ -870,6 +870,14 @@
"@notification_permission_denied": {
"description": "「存取權限彈窗」 → 通知功能已被拒絕,請移至設定允許權限。"
},
"autoStart_permission_denied": "自啟動權限已被拒絕,請移至設定允許權限。",
"@autoStart_permission_denied": {
"description": "「存取權限彈窗」 → 自啟動權限已被拒絕,請移至設定允許權限。"
},
"batteryOptimization_permission_denied": "省電策略已被拒絕,請移至設定允許權限。",
"@batteryOptimization_permission_denied": {
"description": "「存取權限彈窗」 → 省電策略已被拒絕,請移至設定允許權限。"
},
"permission_request": "權限請求",
"@permission_request": {
"description": "「存取權限彈窗」 → 權限請求"
Expand Down Expand Up @@ -1773,5 +1781,21 @@
"type": "String"
}
}
},
"power_saving_position": "省電策略",
"@power_saving_position": {
"description": "「歡迎」頁面 → 省電策略"
},
"power_saving_position_text": "允許 DPIP 在背景中持續運行,以便即時防災通知資訊。",
"@power_saving_position_text": {
"description": "「歡迎」頁面 → 允許DPIP在背景中持續運行,以便即時防災通知資訊。"
},
"automatic_start_position": "自動化啟動",
"@automatic_start_position": {
"description": "「歡迎」頁面 → 自動化啟動"
},
"automatic_start_position_text": "允許 DPIP 在設備重新啟動或關閉後自動啟動,以持續提供防災通知服務。",
"@automatic_start_position_text": {
"description": "「歡迎」頁面 → 允許 DPIP 在設備重新啟動或關閉後自動啟動,以持續提供防災通知服務。"
}
}
158 changes: 157 additions & 1 deletion lib/route/settings/content/location.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class _SettingsLocationViewState extends State<SettingsLocationView> with Widget
PermissionStatus? notificationPermission;
PermissionStatus? locationPermission;
PermissionStatus? locationAlwaysPermission;
bool? autoStartPermission;
bool? batteryOptimizationPermission;

String? city;
String? town;
Expand Down Expand Up @@ -338,10 +340,12 @@ class _SettingsLocationViewState extends State<SettingsLocationView> with Widget
await checkLocationAlwaysPermission();

bool autoStart = await androidCheckAutoStartPermission(0);
autoStartPermission = autoStart;

if (!autoStart) return;

bool batteryOptimization = await androidCheckBatteryOptimizationPermission(0);
batteryOptimizationPermission = batteryOptimization;

if (!batteryOptimization) return;

Expand Down Expand Up @@ -408,6 +412,12 @@ class _SettingsLocationViewState extends State<SettingsLocationView> with Widget
});
},
);
if (Platform.isAndroid) {
setState(() async {
autoStartPermission = await Autostarter.checkAutoStartState() ?? false;
batteryOptimizationPermission = await DisableBatteryOptimization.isBatteryOptimizationDisabled ?? false;
});
}
}

void sendpositionUpdate() {
Expand Down Expand Up @@ -518,6 +528,79 @@ class _SettingsLocationViewState extends State<SettingsLocationView> with Widget
),
),
),
if (autoStartPermission != null && Platform.isAndroid)
Visibility(
visible: isAutoLocatingEnabled && !autoStartPermission!,
maintainAnimation: true,
maintainState: true,
child: AnimatedOpacity(
opacity: isAutoLocatingEnabled && !autoStartPermission! ? 1 : 0,
curve: const Interval(0.2, 1, curve: Easing.standard),
duration: Durations.medium2,
child: Padding(
padding: const EdgeInsets.all(16),
child: Row(children: [
Padding(
padding: const EdgeInsets.all(8),
child: Icon(
Symbols.warning,
color: context.colors.error,
),
),
const SizedBox(width: 8),
Expanded(
child: Text(
context.i18n.autoStart_permission_denied,
style: TextStyle(color: context.colors.error),
),
),
TextButton(
child: Text(context.i18n.settings),
onPressed: () async {
await Autostarter.getAutoStartPermission(newTask: true);
},
),
]),
),
),
),
if (batteryOptimizationPermission != null && Platform.isAndroid)
Visibility(
visible: isAutoLocatingEnabled && !batteryOptimizationPermission!,
maintainAnimation: true,
maintainState: true,
child: AnimatedOpacity(
opacity: isAutoLocatingEnabled && !batteryOptimizationPermission! ? 1 : 0,
curve: const Interval(0.2, 1, curve: Easing.standard),
duration: Durations.medium2,
child: Padding(
padding: const EdgeInsets.all(16),
child: Row(children: [
Padding(
padding: const EdgeInsets.all(8),
child: Icon(
Symbols.warning,
color: context.colors.error,
),
),
const SizedBox(width: 8),
Expanded(
child: Text(
context.i18n.batteryOptimization_permission_denied,
style: TextStyle(color: context.colors.error),
),
),
TextButton(
child: Text(context.i18n.settings),
onPressed: () {
DisableBatteryOptimization.showDisableBatteryOptimizationSettings();
Navigator.pop(context);
},
),
]),
),
),
),
Padding(
padding: const EdgeInsets.all(16),
child: Row(children: [
Expand Down Expand Up @@ -595,7 +678,80 @@ class _SettingsLocationViewState extends State<SettingsLocationView> with Widget
sendpositionUpdate();
});
},
)
),
if (autoStartPermission != null && Platform.isAndroid)
Visibility(
visible: !isAutoLocatingEnabled && city != null && town != null && !autoStartPermission!,
maintainAnimation: true,
maintainState: true,
child: AnimatedOpacity(
opacity: !isAutoLocatingEnabled && city != null && town != null && !autoStartPermission! ? 1 : 0,
curve: const Interval(0.2, 1, curve: Easing.standard),
duration: Durations.medium2,
child: Padding(
padding: const EdgeInsets.all(16),
child: Row(children: [
Padding(
padding: const EdgeInsets.all(8),
child: Icon(
Symbols.warning,
color: context.colors.error,
),
),
const SizedBox(width: 8),
Expanded(
child: Text(
context.i18n.autoStart_permission_denied,
style: TextStyle(color: context.colors.error),
),
),
TextButton(
child: Text(context.i18n.settings),
onPressed: () async {
await Autostarter.getAutoStartPermission(newTask: true);
},
),
]),
),
),
),
if (batteryOptimizationPermission != null && Platform.isAndroid)
Visibility(
visible: !isAutoLocatingEnabled && city != null && town != null && !batteryOptimizationPermission!,
maintainAnimation: true,
maintainState: true,
child: AnimatedOpacity(
opacity: !isAutoLocatingEnabled && city != null && town != null && !batteryOptimizationPermission! ? 1 : 0,
curve: const Interval(0.2, 1, curve: Easing.standard),
duration: Durations.medium2,
child: Padding(
padding: const EdgeInsets.all(16),
child: Row(children: [
Padding(
padding: const EdgeInsets.all(8),
child: Icon(
Symbols.warning,
color: context.colors.error,
),
),
const SizedBox(width: 8),
Expanded(
child: Text(
context.i18n.batteryOptimization_permission_denied,
style: TextStyle(color: context.colors.error),
),
),
TextButton(
child: Text(context.i18n.settings),
onPressed: () {
DisableBatteryOptimization.showDisableBatteryOptimizationSettings();
Navigator.pop(context);
},
),
]),
),
),
),
],
),
);
Expand Down
Loading

0 comments on commit 6bef296

Please sign in to comment.