diff --git a/app/src/main/java/org/linphone/LinphoneActivity.java b/app/src/main/java/org/linphone/LinphoneActivity.java index c58b3df65..354c62bc5 100644 --- a/app/src/main/java/org/linphone/LinphoneActivity.java +++ b/app/src/main/java/org/linphone/LinphoneActivity.java @@ -1589,14 +1589,7 @@ public class LinphoneActivity extends LinphoneGenericActivity case CONTACTS_LIST: case HISTORY_LIST: case CHAT_LIST: - boolean isBackgroundModeActive = - LinphonePreferences.instance().isBackgroundModeEnabled(); - if (!isBackgroundModeActive) { - stopService( - new Intent(Intent.ACTION_MAIN) - .setClass(this, LinphoneService.class)); - finish(); - } else if (LinphoneUtils.onKeyBackGoHome(this, keyCode, event)) { + if (LinphoneUtils.onKeyBackGoHome(this, keyCode, event)) { return true; } break; diff --git a/app/src/main/java/org/linphone/LinphoneManager.java b/app/src/main/java/org/linphone/LinphoneManager.java index 2f69ab4c1..07e191ccb 100644 --- a/app/src/main/java/org/linphone/LinphoneManager.java +++ b/app/src/main/java/org/linphone/LinphoneManager.java @@ -863,8 +863,7 @@ public class LinphoneManager implements CoreListener, SensorEventListener, Accou if (LinphonePreferences.instance() != null) { // We set network reachable at false before destroy LC to not send register with expires // at 0 - if (LinphonePreferences.instance().isPushNotificationEnabled() - || LinphonePreferences.instance().isBackgroundModeEnabled()) { + if (LinphonePreferences.instance().isPushNotificationEnabled()) { Log.w( "[Manager] Setting network reachability to False to prevent unregister and allow incoming push notifications"); mCore.setNetworkReachable(false); diff --git a/app/src/main/java/org/linphone/LinphoneService.java b/app/src/main/java/org/linphone/LinphoneService.java index a4150374f..f9171df31 100644 --- a/app/src/main/java/org/linphone/LinphoneService.java +++ b/app/src/main/java/org/linphone/LinphoneService.java @@ -367,14 +367,16 @@ public final class LinphoneService extends Service { @Override public void onTaskRemoved(Intent rootIntent) { - if (getResources().getBoolean(R.bool.kill_service_with_task_manager)) { + boolean serviceNotif = LinphonePreferences.instance().getServiceNotificationVisibility(); + if (serviceNotif) { + Log.i("[Service] Service is running in foreground, don't stop it"); + } else if (getResources().getBoolean(R.bool.kill_service_with_task_manager)) { + Log.i("[Service] Task removed, stop service"); Core lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull(); if (lc != null) { lc.terminateAllCalls(); } - Log.i("[Service] Task removed, stop service"); - // If push is enabled, don't unregister account, otherwise do unregister if (LinphonePreferences.instance().isPushNotificationEnabled()) { if (lc != null) lc.setNetworkReachable(false); diff --git a/app/src/main/java/org/linphone/notifications/NotificationsManager.java b/app/src/main/java/org/linphone/notifications/NotificationsManager.java index 98c84a41e..2af730f7c 100644 --- a/app/src/main/java/org/linphone/notifications/NotificationsManager.java +++ b/app/src/main/java/org/linphone/notifications/NotificationsManager.java @@ -73,10 +73,6 @@ public class NotificationsManager { Compatibility.createNotificationChannels(mContext); - Intent notifIntent = - new Intent(mContext, LinphoneService.instance().getIncomingReceivedActivity()); - notifIntent.putExtra("Notification", true); - Bitmap bm = null; try { bm = BitmapFactory.decodeResource(mContext.getResources(), R.mipmap.ic_launcher); @@ -84,6 +80,9 @@ public class NotificationsManager { Log.e(e); } + Intent notifIntent = new Intent(mContext, LinphoneActivity.class); + notifIntent.putExtra("Notification", true); + PendingIntent pendingIntent = PendingIntent.getActivity( mContext, SERVICE_NOTIF_ID, notifIntent, PendingIntent.FLAG_UPDATE_CURRENT); @@ -123,7 +122,7 @@ public class NotificationsManager { } public void removeForegroundServiceNotificationIfPossible() { - if (!LinphonePreferences.instance().getServiceNotificationVisibility() + if (!isServiceNotificationDisplayed() && mCurrentForegroundServiceNotification == SERVICE_NOTIF_ID) { stopForeground(); } diff --git a/app/src/main/java/org/linphone/settings/AdvancedSettingsFragment.java b/app/src/main/java/org/linphone/settings/AdvancedSettingsFragment.java index 015a4bc70..b2825a230 100644 --- a/app/src/main/java/org/linphone/settings/AdvancedSettingsFragment.java +++ b/app/src/main/java/org/linphone/settings/AdvancedSettingsFragment.java @@ -48,7 +48,6 @@ public class AdvancedSettingsFragment extends Fragment { mJavaLogger, mFriendListSubscribe, mBackgroundMode, - mForegroundService, mStartAtBoot, mDarkMode; private TextSetting mRemoteProvisioningUrl, mDisplayName, mUsername; @@ -92,8 +91,6 @@ public class AdvancedSettingsFragment extends Fragment { mBackgroundMode = mRootView.findViewById(R.id.pref_background_mode); - mForegroundService = mRootView.findViewById(R.id.pref_service_notification); - mStartAtBoot = mRootView.findViewById(R.id.pref_autostart); mDarkMode = mRootView.findViewById(R.id.pref_dark_mode); @@ -135,14 +132,6 @@ public class AdvancedSettingsFragment extends Fragment { }); mBackgroundMode.setListener( - new SettingListenerBase() { - @Override - public void onBoolValueChanged(boolean newValue) { - mPrefs.setBackgroundModeEnabled(newValue); - } - }); - - mForegroundService.setListener( new SettingListenerBase() { @Override public void onBoolValueChanged(boolean newValue) { @@ -219,9 +208,7 @@ public class AdvancedSettingsFragment extends Fragment { mFriendListSubscribe.setChecked(mPrefs.isFriendlistsubscriptionEnabled()); - mBackgroundMode.setChecked(mPrefs.isBackgroundModeEnabled()); - - mForegroundService.setChecked(mPrefs.getServiceNotificationVisibility()); + mBackgroundMode.setChecked(mPrefs.getServiceNotificationVisibility()); mStartAtBoot.setChecked(mPrefs.isAutoStartEnabled()); diff --git a/app/src/main/java/org/linphone/settings/LinphonePreferences.java b/app/src/main/java/org/linphone/settings/LinphonePreferences.java index ff0075e2e..94561f5eb 100644 --- a/app/src/main/java/org/linphone/settings/LinphonePreferences.java +++ b/app/src/main/java/org/linphone/settings/LinphonePreferences.java @@ -705,10 +705,6 @@ public class LinphonePreferences { return getConfig().getBool("app", "background_mode", true); } - public void setBackgroundModeEnabled(boolean enabled) { - getConfig().setBool("app", "background_mode", enabled); - } - public boolean isAutoStartEnabled() { return getConfig().getBool("app", "auto_start", false); } diff --git a/app/src/main/res/layout/settings_advanced.xml b/app/src/main/res/layout/settings_advanced.xml index 16622a9f4..a0177db37 100644 --- a/app/src/main/res/layout/settings_advanced.xml +++ b/app/src/main/res/layout/settings_advanced.xml @@ -34,14 +34,9 @@ android:id="@+id/pref_background_mode" android:layout_width="match_parent" android:layout_height="wrap_content" + linphone:subtitle="@string/pref_background_mode_desc" linphone:title="@string/pref_background_mode" /> - - Use Java logger Friendlist subscribe Background mode + Show a notification to keep the app alive Enable Animations Enable service notification Start at boot time