Reworked background/service settings
This commit is contained in:
parent
ea14b00bfb
commit
7241fc80b3
8 changed files with 14 additions and 42 deletions
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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" />
|
||||
|
||||
<org.linphone.settings.widget.SwitchSetting
|
||||
android:id="@+id/pref_service_notification"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
linphone:title="@string/pref_service_notification" />
|
||||
|
||||
<org.linphone.settings.widget.SwitchSetting
|
||||
android:id="@+id/pref_autostart"
|
||||
android:layout_width="match_parent"
|
||||
|
|
|
@ -481,6 +481,7 @@
|
|||
<string name="pref_java_debug">Use Java logger</string>
|
||||
<string name="pref_friendlist_subscribe">Friendlist subscribe</string>
|
||||
<string name="pref_background_mode">Background mode</string>
|
||||
<string name="pref_background_mode_desc">Show a notification to keep the app alive</string>
|
||||
<string name="pref_animation_enable_title">Enable Animations</string>
|
||||
<string name="pref_service_notification">Enable service notification</string>
|
||||
<string name="pref_autostart">Start at boot time</string>
|
||||
|
|
Loading…
Reference in a new issue