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 CONTACTS_LIST:
|
||||||
case HISTORY_LIST:
|
case HISTORY_LIST:
|
||||||
case CHAT_LIST:
|
case CHAT_LIST:
|
||||||
boolean isBackgroundModeActive =
|
if (LinphoneUtils.onKeyBackGoHome(this, keyCode, event)) {
|
||||||
LinphonePreferences.instance().isBackgroundModeEnabled();
|
|
||||||
if (!isBackgroundModeActive) {
|
|
||||||
stopService(
|
|
||||||
new Intent(Intent.ACTION_MAIN)
|
|
||||||
.setClass(this, LinphoneService.class));
|
|
||||||
finish();
|
|
||||||
} else if (LinphoneUtils.onKeyBackGoHome(this, keyCode, event)) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -863,8 +863,7 @@ public class LinphoneManager implements CoreListener, SensorEventListener, Accou
|
||||||
if (LinphonePreferences.instance() != null) {
|
if (LinphonePreferences.instance() != null) {
|
||||||
// We set network reachable at false before destroy LC to not send register with expires
|
// We set network reachable at false before destroy LC to not send register with expires
|
||||||
// at 0
|
// at 0
|
||||||
if (LinphonePreferences.instance().isPushNotificationEnabled()
|
if (LinphonePreferences.instance().isPushNotificationEnabled()) {
|
||||||
|| LinphonePreferences.instance().isBackgroundModeEnabled()) {
|
|
||||||
Log.w(
|
Log.w(
|
||||||
"[Manager] Setting network reachability to False to prevent unregister and allow incoming push notifications");
|
"[Manager] Setting network reachability to False to prevent unregister and allow incoming push notifications");
|
||||||
mCore.setNetworkReachable(false);
|
mCore.setNetworkReachable(false);
|
||||||
|
|
|
@ -367,14 +367,16 @@ public final class LinphoneService extends Service {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTaskRemoved(Intent rootIntent) {
|
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();
|
Core lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
|
||||||
if (lc != null) {
|
if (lc != null) {
|
||||||
lc.terminateAllCalls();
|
lc.terminateAllCalls();
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.i("[Service] Task removed, stop service");
|
|
||||||
|
|
||||||
// If push is enabled, don't unregister account, otherwise do unregister
|
// If push is enabled, don't unregister account, otherwise do unregister
|
||||||
if (LinphonePreferences.instance().isPushNotificationEnabled()) {
|
if (LinphonePreferences.instance().isPushNotificationEnabled()) {
|
||||||
if (lc != null) lc.setNetworkReachable(false);
|
if (lc != null) lc.setNetworkReachable(false);
|
||||||
|
|
|
@ -73,10 +73,6 @@ public class NotificationsManager {
|
||||||
|
|
||||||
Compatibility.createNotificationChannels(mContext);
|
Compatibility.createNotificationChannels(mContext);
|
||||||
|
|
||||||
Intent notifIntent =
|
|
||||||
new Intent(mContext, LinphoneService.instance().getIncomingReceivedActivity());
|
|
||||||
notifIntent.putExtra("Notification", true);
|
|
||||||
|
|
||||||
Bitmap bm = null;
|
Bitmap bm = null;
|
||||||
try {
|
try {
|
||||||
bm = BitmapFactory.decodeResource(mContext.getResources(), R.mipmap.ic_launcher);
|
bm = BitmapFactory.decodeResource(mContext.getResources(), R.mipmap.ic_launcher);
|
||||||
|
@ -84,6 +80,9 @@ public class NotificationsManager {
|
||||||
Log.e(e);
|
Log.e(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Intent notifIntent = new Intent(mContext, LinphoneActivity.class);
|
||||||
|
notifIntent.putExtra("Notification", true);
|
||||||
|
|
||||||
PendingIntent pendingIntent =
|
PendingIntent pendingIntent =
|
||||||
PendingIntent.getActivity(
|
PendingIntent.getActivity(
|
||||||
mContext, SERVICE_NOTIF_ID, notifIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
mContext, SERVICE_NOTIF_ID, notifIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||||
|
@ -123,7 +122,7 @@ public class NotificationsManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeForegroundServiceNotificationIfPossible() {
|
public void removeForegroundServiceNotificationIfPossible() {
|
||||||
if (!LinphonePreferences.instance().getServiceNotificationVisibility()
|
if (!isServiceNotificationDisplayed()
|
||||||
&& mCurrentForegroundServiceNotification == SERVICE_NOTIF_ID) {
|
&& mCurrentForegroundServiceNotification == SERVICE_NOTIF_ID) {
|
||||||
stopForeground();
|
stopForeground();
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,6 @@ public class AdvancedSettingsFragment extends Fragment {
|
||||||
mJavaLogger,
|
mJavaLogger,
|
||||||
mFriendListSubscribe,
|
mFriendListSubscribe,
|
||||||
mBackgroundMode,
|
mBackgroundMode,
|
||||||
mForegroundService,
|
|
||||||
mStartAtBoot,
|
mStartAtBoot,
|
||||||
mDarkMode;
|
mDarkMode;
|
||||||
private TextSetting mRemoteProvisioningUrl, mDisplayName, mUsername;
|
private TextSetting mRemoteProvisioningUrl, mDisplayName, mUsername;
|
||||||
|
@ -92,8 +91,6 @@ public class AdvancedSettingsFragment extends Fragment {
|
||||||
|
|
||||||
mBackgroundMode = mRootView.findViewById(R.id.pref_background_mode);
|
mBackgroundMode = mRootView.findViewById(R.id.pref_background_mode);
|
||||||
|
|
||||||
mForegroundService = mRootView.findViewById(R.id.pref_service_notification);
|
|
||||||
|
|
||||||
mStartAtBoot = mRootView.findViewById(R.id.pref_autostart);
|
mStartAtBoot = mRootView.findViewById(R.id.pref_autostart);
|
||||||
|
|
||||||
mDarkMode = mRootView.findViewById(R.id.pref_dark_mode);
|
mDarkMode = mRootView.findViewById(R.id.pref_dark_mode);
|
||||||
|
@ -135,14 +132,6 @@ public class AdvancedSettingsFragment extends Fragment {
|
||||||
});
|
});
|
||||||
|
|
||||||
mBackgroundMode.setListener(
|
mBackgroundMode.setListener(
|
||||||
new SettingListenerBase() {
|
|
||||||
@Override
|
|
||||||
public void onBoolValueChanged(boolean newValue) {
|
|
||||||
mPrefs.setBackgroundModeEnabled(newValue);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
mForegroundService.setListener(
|
|
||||||
new SettingListenerBase() {
|
new SettingListenerBase() {
|
||||||
@Override
|
@Override
|
||||||
public void onBoolValueChanged(boolean newValue) {
|
public void onBoolValueChanged(boolean newValue) {
|
||||||
|
@ -219,9 +208,7 @@ public class AdvancedSettingsFragment extends Fragment {
|
||||||
|
|
||||||
mFriendListSubscribe.setChecked(mPrefs.isFriendlistsubscriptionEnabled());
|
mFriendListSubscribe.setChecked(mPrefs.isFriendlistsubscriptionEnabled());
|
||||||
|
|
||||||
mBackgroundMode.setChecked(mPrefs.isBackgroundModeEnabled());
|
mBackgroundMode.setChecked(mPrefs.getServiceNotificationVisibility());
|
||||||
|
|
||||||
mForegroundService.setChecked(mPrefs.getServiceNotificationVisibility());
|
|
||||||
|
|
||||||
mStartAtBoot.setChecked(mPrefs.isAutoStartEnabled());
|
mStartAtBoot.setChecked(mPrefs.isAutoStartEnabled());
|
||||||
|
|
||||||
|
|
|
@ -705,10 +705,6 @@ public class LinphonePreferences {
|
||||||
return getConfig().getBool("app", "background_mode", true);
|
return getConfig().getBool("app", "background_mode", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBackgroundModeEnabled(boolean enabled) {
|
|
||||||
getConfig().setBool("app", "background_mode", enabled);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isAutoStartEnabled() {
|
public boolean isAutoStartEnabled() {
|
||||||
return getConfig().getBool("app", "auto_start", false);
|
return getConfig().getBool("app", "auto_start", false);
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,14 +34,9 @@
|
||||||
android:id="@+id/pref_background_mode"
|
android:id="@+id/pref_background_mode"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
linphone:subtitle="@string/pref_background_mode_desc"
|
||||||
linphone:title="@string/pref_background_mode" />
|
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
|
<org.linphone.settings.widget.SwitchSetting
|
||||||
android:id="@+id/pref_autostart"
|
android:id="@+id/pref_autostart"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
|
|
@ -481,6 +481,7 @@
|
||||||
<string name="pref_java_debug">Use Java logger</string>
|
<string name="pref_java_debug">Use Java logger</string>
|
||||||
<string name="pref_friendlist_subscribe">Friendlist subscribe</string>
|
<string name="pref_friendlist_subscribe">Friendlist subscribe</string>
|
||||||
<string name="pref_background_mode">Background mode</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_animation_enable_title">Enable Animations</string>
|
||||||
<string name="pref_service_notification">Enable service notification</string>
|
<string name="pref_service_notification">Enable service notification</string>
|
||||||
<string name="pref_autostart">Start at boot time</string>
|
<string name="pref_autostart">Start at boot time</string>
|
||||||
|
|
Loading…
Reference in a new issue