Fixed crash on Huawei (added permission) + improved huawei popup using our dialog template
This commit is contained in:
parent
adb3506cce
commit
9b0fa01310
5 changed files with 75 additions and 53 deletions
|
@ -35,6 +35,7 @@
|
|||
<!-- Needed to pre fill the wizard email field (only if enabled in custom settings) -->
|
||||
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
|
||||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
||||
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
|
||||
<uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" />
|
||||
<uses-permission android:name="android.permission.READ_SYNC_SETTINGS" />
|
||||
<uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS" />
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
*/
|
||||
|
|
|
@ -492,7 +492,7 @@
|
|||
<!-- Device specifics -->
|
||||
<string name="huawei_protected_app_dialog_title">Huawei device detected!</string>
|
||||
<string name="huawei_protected_app_dialog_message">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.</string>
|
||||
<string name="huawei_protected_app_dialog_button_go_to_settings">Go to settings</string>
|
||||
<string name="huawei_protected_app_dialog_button_go_to_settings">Settings</string>
|
||||
<string name="huawei_protected_app_dialog_button_later">Later</string>
|
||||
|
||||
<!-- Content description -->
|
||||
|
|
Loading…
Reference in a new issue