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>
|
<intent>
|
||||||
<action android:name="android.media.action.VIDEO_CAPTURE" />
|
<action android:name="android.media.action.VIDEO_CAPTURE" />
|
||||||
</intent>
|
</intent>
|
||||||
|
|
||||||
|
<intent>
|
||||||
|
<action android:name="android.settings.IGNORE_BATTERY_OPTIMIZATION_SETTINGS" />
|
||||||
|
</intent>
|
||||||
</queries>
|
</queries>
|
||||||
|
|
||||||
<!-- This is required for independent push notifications service to work
|
<!-- This is required for independent push notifications service to work
|
||||||
(when FCM service can not be used) -->
|
(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
|
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
|
||||||
calls FlutterMain.startInitialization(this); in its onCreate method.
|
calls FlutterMain.startInitialization(this); in its onCreate method.
|
||||||
|
@ -1,10 +1,8 @@
|
|||||||
package org.communiquons.comunic.independentnotifications;
|
package org.communiquons.comunic.independentnotifications;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.net.Uri;
|
|
||||||
import android.os.PowerManager;
|
import android.os.PowerManager;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
|
|
||||||
@ -23,9 +21,10 @@ public class NotificationsChannel implements MethodChannel.MethodCallHandler {
|
|||||||
@Override
|
@Override
|
||||||
public void onMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result result) {
|
public void onMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result result) {
|
||||||
try {
|
try {
|
||||||
|
if (call.method.equals("needPreConfiguration"))
|
||||||
|
result.success(needPreConfiguration());
|
||||||
|
|
||||||
|
else if (call.method.equals("preConfigure"))
|
||||||
if (call.method.equals("preConfigure"))
|
|
||||||
preConfigure(result);
|
preConfigure(result);
|
||||||
|
|
||||||
else
|
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
|
* Pre-configure independent notifications service
|
||||||
*/
|
*/
|
||||||
private void preConfigure(@NonNull MethodChannel.Result result) throws Exception {
|
private void preConfigure(@NonNull MethodChannel.Result result) {
|
||||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
|
if (needPreConfiguration() && android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
|
||||||
if (!context.getSystemService(PowerManager.class).isIgnoringBatteryOptimizations(context.getPackageName())) {
|
// See https://stackoverflow.com/a/41853011
|
||||||
@SuppressLint("BatteryLife")
|
Intent intent = new Intent(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS);
|
||||||
Intent intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS,
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
Uri.parse("package:" + context.getPackageName()));
|
|
||||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
||||||
|
|
||||||
context.startActivity(intent);
|
context.startActivity(intent);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
result.success(null);
|
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';
|
import 'package:flutter/services.dart';
|
||||||
|
|
||||||
/// Independent push notifications helper
|
/// Independent push notifications helper
|
||||||
@ -8,11 +11,19 @@ class IndependentPushNotificationsHelper {
|
|||||||
static const platform = const MethodChannel(
|
static const platform = const MethodChannel(
|
||||||
"org.communiquons.comunic/independent-push-notifications-service");
|
"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
|
/// Call this method to prepare the application for background refresh by
|
||||||
/// requesting appropriate permissions, configuring battery optimization...
|
/// requesting appropriate permissions, configuring battery optimization...
|
||||||
///
|
///
|
||||||
/// Throws an Exception in case of failure
|
/// 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");
|
await platform.invokeMethod("preConfigure");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -121,7 +121,8 @@ class _PushNotificationsConfigurationRouteState
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case PushNotificationsStatus.INDEPENDENT:
|
case PushNotificationsStatus.INDEPENDENT:
|
||||||
await IndependentPushNotificationsHelper.preConfigure();
|
if (await IndependentPushNotificationsHelper.needPreConfiguration())
|
||||||
|
await IndependentPushNotificationsHelper.preConfigure(context);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import 'package:comunic/helpers/account_helper.dart';
|
import 'package:comunic/helpers/account_helper.dart';
|
||||||
import 'package:comunic/helpers/events_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/server_config_helper.dart';
|
||||||
import 'package:comunic/helpers/version_helper.dart';
|
import 'package:comunic/helpers/version_helper.dart';
|
||||||
import 'package:comunic/helpers/websocket_helper.dart';
|
import 'package:comunic/helpers/websocket_helper.dart';
|
||||||
@ -78,8 +77,8 @@ class _InitializeWidgetState extends SafeState<InitializeWidget> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
print("Check push notifications configuration...");
|
print("Check push notifications configuration...");
|
||||||
if (await PushNotificationsHelper.getLocalStatus() ==
|
/*if (await PushNotificationsHelper.getLocalStatus() ==
|
||||||
PushNotificationsStatus.UNDEFINED)
|
PushNotificationsStatus.UNDEFINED)*/// TODO : remove comment
|
||||||
await showInitialPushNotificationsConfiguration(context);
|
await showInitialPushNotificationsConfiguration(context);
|
||||||
|
|
||||||
print("Attempting WebSocket connection...");
|
print("Attempting WebSocket connection...");
|
||||||
|
Loading…
Reference in New Issue
Block a user