diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index af5fb514f..f48923c4b 100755
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -35,6 +35,7 @@
+
diff --git a/app/src/main/java/org/linphone/LinphoneActivity.java b/app/src/main/java/org/linphone/LinphoneActivity.java
index ee84319ec..e59d79928 100644
--- a/app/src/main/java/org/linphone/LinphoneActivity.java
+++ b/app/src/main/java/org/linphone/LinphoneActivity.java
@@ -27,6 +27,7 @@ import android.app.Dialog;
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
+import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
@@ -266,6 +267,13 @@ public class LinphoneActivity extends LinphoneGenericActivity
getString(R.string.error_io_error), Toast.LENGTH_LONG);
}
}
+
+ if (state == RegistrationState.Ok) {
+ // For push notifications to work on Huawei device,
+ // app must be in "protected mode" in battery settings...
+ // https://stackoverflow.com/questions/31638986/protected-apps-setting-on-huawei-phones-and-how-to-handle-it
+ displayDialogIfDeviceIsHuawei();
+ }
}
@Override
@@ -1064,9 +1072,7 @@ public class LinphoneActivity extends LinphoneGenericActivity
}
public void displayChatRoomError() {
- final Dialog dialog =
- LinphoneActivity.instance()
- .displayDialog(getString(R.string.chat_room_creation_failed));
+ final Dialog dialog = displayDialog(getString(R.string.chat_room_creation_failed));
dialog.findViewById(R.id.dialog_delete_button).setVisibility(View.GONE);
Button cancel = dialog.findViewById(R.id.dialog_cancel_button);
cancel.setText(getString(R.string.ok));
@@ -2002,6 +2008,70 @@ public class LinphoneActivity extends LinphoneGenericActivity
return -1;
}
+ private void displayDialogIfDeviceIsHuawei() {
+ if ("huawei".equalsIgnoreCase(android.os.Build.MANUFACTURER)) {
+ Log.w("[Hacks] Huawei device detected !");
+ if (!LinphonePreferences.instance().hasHuaweiDialogBeenPrompted()) {
+ Log.w("[Hacks] Huawei device detected, asking for protected mode !");
+
+ final Dialog dialog = new Dialog(this);
+ dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
+ Drawable d = new ColorDrawable(ContextCompat.getColor(this, R.color.colorC));
+ d.setAlpha(200);
+ dialog.setContentView(R.layout.dialog);
+ dialog.getWindow()
+ .setLayout(
+ WindowManager.LayoutParams.MATCH_PARENT,
+ WindowManager.LayoutParams.MATCH_PARENT);
+ dialog.getWindow().setBackgroundDrawable(d);
+
+ TextView customText = dialog.findViewById(R.id.dialog_message);
+ customText.setText(R.string.huawei_protected_app_dialog_message);
+
+ TextView customTitle = dialog.findViewById(R.id.dialog_title);
+ customTitle.setText(R.string.huawei_protected_app_dialog_title);
+
+ Button accept = dialog.findViewById(R.id.dialog_ok_button);
+ accept.setVisibility(View.VISIBLE);
+ accept.setText(R.string.huawei_protected_app_dialog_button_go_to_settings);
+ accept.setOnClickListener(
+ new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ Log.w(
+ "[Hacks] Huawei device detected, user is going to battery settings :)");
+ LinphonePreferences.instance().huaweiDialogPrompted(true);
+ Intent intent = new Intent();
+ intent.setComponent(
+ new ComponentName(
+ "com.huawei.systemmanager",
+ "com.huawei.systemmanager.optimize.process.ProtectActivity"));
+ startActivity(intent);
+ dialog.dismiss();
+ }
+ });
+
+ Button cancel = dialog.findViewById(R.id.dialog_cancel_button);
+ cancel.setText(R.string.huawei_protected_app_dialog_button_later);
+ cancel.setOnClickListener(
+ new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ Log.w(
+ "[Hacks] Huawei device detected, user didn't go to battery settings :(");
+ LinphonePreferences.instance().huaweiDialogPrompted(true);
+ dialog.dismiss();
+ }
+ });
+
+ Button delete = dialog.findViewById(R.id.dialog_delete_button);
+ delete.setVisibility(View.GONE);
+
+ dialog.show();
+ }
+ }
+ }
+
private class LocalOrientationEventListener extends OrientationEventListener {
LocalOrientationEventListener(Context context) {
super(context);
diff --git a/app/src/main/java/org/linphone/LinphoneManager.java b/app/src/main/java/org/linphone/LinphoneManager.java
index fe2139224..20dfeb4fb 100644
--- a/app/src/main/java/org/linphone/LinphoneManager.java
+++ b/app/src/main/java/org/linphone/LinphoneManager.java
@@ -1231,9 +1231,7 @@ public class LinphoneManager implements CoreListener, SensorEventListener, Accou
Log.i("New global state [", state, "]");
if (state == GlobalState.On) {
try {
- Log.e("LinphoneManager", " onGlobalStateChanged ON");
initLiblinphone(lc);
-
} catch (IllegalArgumentException iae) {
Log.e(iae);
}
diff --git a/app/src/main/java/org/linphone/LinphoneService.java b/app/src/main/java/org/linphone/LinphoneService.java
index 82f7ee915..da79ce4d4 100644
--- a/app/src/main/java/org/linphone/LinphoneService.java
+++ b/app/src/main/java/org/linphone/LinphoneService.java
@@ -24,9 +24,7 @@ import android.app.AlarmManager;
import android.app.Application;
import android.app.PendingIntent;
import android.app.Service;
-import android.content.ComponentName;
import android.content.Context;
-import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException;
@@ -37,7 +35,6 @@ import android.os.IBinder;
import android.os.SystemClock;
import android.provider.ContactsContract;
import android.view.WindowManager;
-import androidx.appcompat.app.AlertDialog;
import java.util.ArrayList;
import org.linphone.contacts.ContactsManager;
import org.linphone.core.Call;
@@ -257,11 +254,6 @@ public final class LinphoneService extends Service {
BluetoothManager.getInstance().initBluetooth();
- // For push notifications to work on Huawei device,
- // app must be in "protected mode" in battery settings...
- // https://stackoverflow.com/questions/31638986/protected-apps-setting-on-huawei-phones-and-how-to-handle-it
- displayDialogIfDeviceIsHuawei();
-
return START_REDELIVER_INTENT;
}
@@ -419,45 +411,6 @@ public final class LinphoneService extends Service {
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
}
- private void displayDialogIfDeviceIsHuawei() {
- if ("huawei".equalsIgnoreCase(android.os.Build.MANUFACTURER)) {
- Log.w("[Service] Huawei device detected, asking for protected mode !");
- if (!LinphonePreferences.instance().hasHuaweiDialogBeenPrompted()) {
- AlertDialog.Builder builder = new AlertDialog.Builder(this);
- builder.setTitle(R.string.huawei_protected_app_dialog_title)
- .setMessage(R.string.huawei_protected_app_dialog_message)
- .setPositiveButton(
- R.string.huawei_protected_app_dialog_button_go_to_settings,
- new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialogInterface, int i) {
- Log.w(
- "[Service] Huawei device detected, user is going to battery settings :)");
- LinphonePreferences.instance().huaweiDialogPrompted(true);
- Intent intent = new Intent();
- intent.setComponent(
- new ComponentName(
- "com.huawei.systemmanager",
- "com.huawei.systemmanager.optimize.process.ProtectActivity"));
- startActivity(intent);
- }
- })
- .setNegativeButton(
- R.string.huawei_protected_app_dialog_button_later,
- new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- Log.w(
- "[Service] Huawei device detected, user didn't go to battery settings :(");
- LinphonePreferences.instance().huaweiDialogPrompted(true);
- }
- })
- .create()
- .show();
- }
- }
- }
-
/*Believe me or not, but knowing the application visibility state on Android is a nightmare.
After two days of hard work I ended with the following class, that does the job more or less reliabily.
*/
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index df6ddacaf..a4f2d6d6c 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -492,7 +492,7 @@
Huawei device detected!
It seems your device is a Huawei. In order for the app to be able to receive calls and messages while in background using push notifications, the protected toogle must be enabled in the settings.
- Go to settings
+ Settings
Later