mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-11-25 06:19:22 +00:00
Avoid potential Google Play Store ban
This commit is contained in:
parent
6e274fa21a
commit
3520d5db58
@ -24,11 +24,15 @@
|
||||
<intent>
|
||||
<action android:name="android.media.action.VIDEO_CAPTURE" />
|
||||
</intent>
|
||||
|
||||
<intent>
|
||||
<action android:name="android.settings.IGNORE_BATTERY_OPTIMIZATION_SETTINGS" />
|
||||
</intent>
|
||||
</queries>
|
||||
|
||||
<!-- This is required for independent push notifications service to work
|
||||
(when FCM service can not be used) -->
|
||||
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
|
||||
|
||||
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
|
||||
calls FlutterMain.startInitialization(this); in its onCreate method.
|
||||
|
@ -1,10 +1,8 @@
|
||||
package org.communiquons.comunic.independentnotifications;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.PowerManager;
|
||||
import android.provider.Settings;
|
||||
|
||||
@ -23,9 +21,10 @@ public class NotificationsChannel implements MethodChannel.MethodCallHandler {
|
||||
@Override
|
||||
public void onMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result result) {
|
||||
try {
|
||||
if (call.method.equals("needPreConfiguration"))
|
||||
result.success(needPreConfiguration());
|
||||
|
||||
|
||||
if (call.method.equals("preConfigure"))
|
||||
else if (call.method.equals("preConfigure"))
|
||||
preConfigure(result);
|
||||
|
||||
else
|
||||
@ -37,19 +36,25 @@ public class NotificationsChannel implements MethodChannel.MethodCallHandler {
|
||||
|
||||
}
|
||||
|
||||
private boolean needPreConfiguration() {
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
|
||||
if (!context.getSystemService(PowerManager.class).isIgnoringBatteryOptimizations(context.getPackageName())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pre-configure independent notifications service
|
||||
*/
|
||||
private void preConfigure(@NonNull MethodChannel.Result result) throws Exception {
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
|
||||
if (!context.getSystemService(PowerManager.class).isIgnoringBatteryOptimizations(context.getPackageName())) {
|
||||
@SuppressLint("BatteryLife")
|
||||
Intent intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS,
|
||||
Uri.parse("package:" + context.getPackageName()));
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
private void preConfigure(@NonNull MethodChannel.Result result) {
|
||||
if (needPreConfiguration() && android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
|
||||
// See https://stackoverflow.com/a/41853011
|
||||
Intent intent = new Intent(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
|
||||
context.startActivity(intent);
|
||||
}
|
||||
context.startActivity(intent);
|
||||
}
|
||||
|
||||
result.success(null);
|
||||
|
@ -1,3 +1,6 @@
|
||||
import 'package:comunic/ui/dialogs/alert_dialog.dart';
|
||||
import 'package:comunic/utils/intl_utils.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
/// Independent push notifications helper
|
||||
@ -8,11 +11,19 @@ class IndependentPushNotificationsHelper {
|
||||
static const platform = const MethodChannel(
|
||||
"org.communiquons.comunic/independent-push-notifications-service");
|
||||
|
||||
/// Check if a pre-configuration is required for an application
|
||||
static Future<bool> needPreConfiguration() async {
|
||||
return await platform.invokeMethod("needPreConfiguration");
|
||||
}
|
||||
|
||||
/// Call this method to prepare the application for background refresh by
|
||||
/// requesting appropriate permissions, configuring battery optimization...
|
||||
///
|
||||
/// Throws an Exception in case of failure
|
||||
static Future<void> preConfigure() async {
|
||||
static Future<void> preConfigure(BuildContext context) async {
|
||||
await alert(context,
|
||||
tr("Battery optimization settings will appear. To make push notifications service work better, please disable battery optimization for Comunic..."));
|
||||
|
||||
await platform.invokeMethod("preConfigure");
|
||||
}
|
||||
}
|
||||
|
@ -121,7 +121,8 @@ class _PushNotificationsConfigurationRouteState
|
||||
break;
|
||||
|
||||
case PushNotificationsStatus.INDEPENDENT:
|
||||
await IndependentPushNotificationsHelper.preConfigure();
|
||||
if (await IndependentPushNotificationsHelper.needPreConfiguration())
|
||||
await IndependentPushNotificationsHelper.preConfigure(context);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -1,6 +1,5 @@
|
||||
import 'package:comunic/helpers/account_helper.dart';
|
||||
import 'package:comunic/helpers/events_helper.dart';
|
||||
import 'package:comunic/helpers/push_notifications_helper.dart';
|
||||
import 'package:comunic/helpers/server_config_helper.dart';
|
||||
import 'package:comunic/helpers/version_helper.dart';
|
||||
import 'package:comunic/helpers/websocket_helper.dart';
|
||||
@ -78,8 +77,8 @@ class _InitializeWidgetState extends SafeState<InitializeWidget> {
|
||||
}
|
||||
|
||||
print("Check push notifications configuration...");
|
||||
if (await PushNotificationsHelper.getLocalStatus() ==
|
||||
PushNotificationsStatus.UNDEFINED)
|
||||
/*if (await PushNotificationsHelper.getLocalStatus() ==
|
||||
PushNotificationsStatus.UNDEFINED)*/// TODO : remove comment
|
||||
await showInitialPushNotificationsConfiguration(context);
|
||||
|
||||
print("Attempting WebSocket connection...");
|
||||
|
Loading…
Reference in New Issue
Block a user