Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: auto start and battery optimization permission denied #279

Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
8 changes: 8 additions & 0 deletions lib/l10n/app_zh.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
8 changes: 8 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
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
Loading