feat(android,interface): Handle battery optimisation
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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 {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user