feat(android,interface): Handle battery optimisation

This commit is contained in:
2023-08-05 00:04:49 +02:00
parent 497ac279cc
commit 0d4f0c59cc
11 changed files with 165 additions and 5 deletions

View File

@@ -583,6 +583,55 @@ class MoxplatformApi {
}
}
Future<void> openBatteryOptimisationSettings() async {
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
'dev.flutter.pigeon.moxplatform_platform_interface.MoxplatformApi.openBatteryOptimisationSettings',
codec,
binaryMessenger: _binaryMessenger);
final List<Object?>? replyList = await channel.send(null) as List<Object?>?;
if (replyList == null) {
throw PlatformException(
code: 'channel-error',
message: 'Unable to establish connection on channel.',
);
} else if (replyList.length > 1) {
throw PlatformException(
code: replyList[0]! as String,
message: replyList[1] as String?,
details: replyList[2],
);
} else {
return;
}
}
Future<bool> isIgnoringBatteryOptimizations() async {
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
'dev.flutter.pigeon.moxplatform_platform_interface.MoxplatformApi.isIgnoringBatteryOptimizations',
codec,
binaryMessenger: _binaryMessenger);
final List<Object?>? replyList = await channel.send(null) as List<Object?>?;
if (replyList == null) {
throw PlatformException(
code: 'channel-error',
message: 'Unable to establish connection on channel.',
);
} else if (replyList.length > 1) {
throw PlatformException(
code: replyList[0]! as String,
message: replyList[1] as String?,
details: replyList[2],
);
} else if (replyList[0] == null) {
throw PlatformException(
code: 'null-error',
message: 'Host platform returned null value for non-null return value.',
);
} else {
return (replyList[0] as bool?)!;
}
}
/// Contacts APIs
Future<void> recordSentMessage(String arg_name, String arg_jid,
String? arg_avatarPath, FallbackIconType arg_fallbackIcon) async {

View File

@@ -4,4 +4,12 @@ abstract class PlatformImplementation {
/// Returns the path where cache data should be stored.
Future<String> getCacheDataPath();
/// Returns whether the app is battery-optimised (false) or
/// excluded from battery savings (true).
Future<bool> isIgnoringBatteryOptimizations();
/// Opens the page for battery optimisations. If not supported on the
/// platform, does nothing.
Future<void> openBatteryOptimisationSettings();
}

View File

@@ -8,4 +8,10 @@ class StubPlatformImplementation extends PlatformImplementation {
/// Returns the path where cache data should be stored.
@override
Future<String> getCacheDataPath() async => '';
@override
Future<bool> isIgnoringBatteryOptimizations() async => false;
@override
Future<void> openBatteryOptimisationSettings() async {}
}