-
Notifications
You must be signed in to change notification settings - Fork 387
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import 'dart:io'; | ||
|
||
import 'package:disable_battery_optimization/disable_battery_optimization.dart'; | ||
import 'package:pilipala/utils/storage.dart'; | ||
|
||
void DisableBatteryOpt() async { | ||
if (!Platform.isAndroid) { | ||
return; | ||
} | ||
// 本地缓存中读取 是否禁用了电池优化 默认未禁用 | ||
bool isDisableBatteryOptLocal = | ||
GStrorage.localCache.get('isDisableBatteryOptLocal', defaultValue: false); | ||
if (!isDisableBatteryOptLocal) { | ||
final isBatteryOptimizationDisabled = | ||
await DisableBatteryOptimization.isBatteryOptimizationDisabled; | ||
if (isBatteryOptimizationDisabled == false) { | ||
final hasDisabled = await DisableBatteryOptimization | ||
.showDisableBatteryOptimizationSettings(); | ||
// 设置为已禁用 | ||
GStrorage.localCache.put('isDisableBatteryOptLocal', hasDisabled == true); | ||
} | ||
} | ||
|
||
bool isManufacturerBatteryOptimizationDisabled = GStrorage.localCache | ||
.get('isManufacturerBatteryOptimizationDisabled', defaultValue: false); | ||
if (!isManufacturerBatteryOptimizationDisabled) { | ||
final isManBatteryOptimizationDisabled = await DisableBatteryOptimization | ||
.isManufacturerBatteryOptimizationDisabled; | ||
if (isManBatteryOptimizationDisabled == false) { | ||
final hasDisabled = await DisableBatteryOptimization | ||
.showDisableManufacturerBatteryOptimizationSettings( | ||
"当前设备可能有额外的电池优化", | ||
"按照步骤操作以禁用电池优化,以保证应用在后台正常运行", | ||
); | ||
// 设置为已禁用 | ||
GStrorage.localCache.put( | ||
'isManufacturerBatteryOptimizationDisabled', hasDisabled == true); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters