Added make quick target to makefile and setting to disable/enable service notification

This commit is contained in:
Sylvain Berfini 2016-07-11 14:09:08 +02:00
parent 954cf1e447
commit f804c29008
6 changed files with 65 additions and 9 deletions

View file

@ -71,6 +71,7 @@
<string name="pref_preferred_video_fps_key">pref_preferred_video_fps_key</string>
<string name="pref_bandwidth_limit_key">pref_bandwidth_limit_key</string>
<string name="pref_animation_enable_key">pref_animation_enable_key</string>
<string name="pref_service_notification_key">pref_service_notification_key</string>
<string name="pref_escape_plus_key">pref_escape_plus_key</string>
<string name="pref_friendlist_subscribe_key">pref_friendlist_subscribe_key</string>
<string name="pref_echo_cancellation_key">pref_echo_cancellation_key</string>

View file

@ -291,6 +291,7 @@
<string name="pref_debug">Debug</string>
<string name="pref_background_mode">Background mode</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>
<string name="pref_incoming_call_timeout_title">Incoming call hangup (in seconds)</string>
<string name="pref_image_sharing_server_title">Sharing server</string>

View file

@ -202,6 +202,10 @@
android:title="@string/pref_background_mode"
android:key="@string/pref_background_mode_key"/>
<CheckBoxPreference
android:title="@string/pref_service_notification"
android:key="@string/pref_service_notification_key"/>
<CheckBoxPreference
android:title="@string/pref_animation_enable_title"
android:key="@string/pref_animation_enable_key"/>

View file

@ -1334,4 +1334,12 @@ public class LinphonePreferences {
public void setActivityToLaunchOnIncomingReceived(String name) {
getConfig().setString("app", "incoming_call_activity", name);
}
public boolean getServiceNotificationVisibility() {
return getConfig().getBool("app", "show_service_notification", true);
}
public void setServiceNotificationVisibility(boolean enable) {
getConfig().setBool("app", "show_service_notification", enable);
}
}

View file

@ -32,6 +32,7 @@ import org.linphone.core.LinphoneCoreException;
import org.linphone.core.LinphoneCoreFactory;
import org.linphone.core.LinphoneCoreListenerBase;
import org.linphone.core.LinphoneProxyConfig;
import org.linphone.core.LpConfig;
import org.linphone.mediastream.Log;
import org.linphone.mediastream.Version;
@ -46,7 +47,6 @@ import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.database.ContentObserver;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
@ -126,6 +126,31 @@ public final class LinphoneService extends Service {
public void resetMessageNotifCount() {
mMsgNotifCount = 0;
}
private boolean displayServiceNotification() {
return LinphonePreferences.instance().getServiceNotificationVisibility();
}
public void showServiceNotification() {
startForegroundCompat(NOTIF_ID, mNotif);
LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
if (lc == null) return;
LinphoneProxyConfig lpc = lc.getDefaultProxyConfig();
if (lpc != null) {
if (lpc.isRegistered()) {
sendNotification(IC_LEVEL_ORANGE, R.string.notification_registered);
} else {
sendNotification(IC_LEVEL_ORANGE, R.string.notification_register_failure);
}
} else {
sendNotification(IC_LEVEL_ORANGE, R.string.notification_started);
}
}
public void hideServiceNotification() {
stopForegroundCompat(NOTIF_ID);
}
@SuppressWarnings("unchecked")
@Override
@ -195,7 +220,7 @@ public final class LinphoneService extends Service {
@Override
public void globalState(LinphoneCore lc,LinphoneCore.GlobalState state, String message) {
if (state == GlobalState.GlobalOn) {
if (state == GlobalState.GlobalOn && displayServiceNotification()) {
sendNotification(IC_LEVEL_ORANGE, R.string.notification_started);
}
}
@ -207,15 +232,15 @@ public final class LinphoneService extends Service {
// return;
// }
if (!mDisableRegistrationStatus) {
if (state == RegistrationState.RegistrationOk && LinphoneManager.getLc().getDefaultProxyConfig() != null && LinphoneManager.getLc().getDefaultProxyConfig().isRegistered()) {
if (displayServiceNotification() && state == RegistrationState.RegistrationOk && LinphoneManager.getLc().getDefaultProxyConfig() != null && LinphoneManager.getLc().getDefaultProxyConfig().isRegistered()) {
sendNotification(IC_LEVEL_ORANGE, R.string.notification_registered);
}
if ((state == RegistrationState.RegistrationFailed || state == RegistrationState.RegistrationCleared) && (LinphoneManager.getLc().getDefaultProxyConfig() == null || !LinphoneManager.getLc().getDefaultProxyConfig().isRegistered())) {
if (displayServiceNotification() && (state == RegistrationState.RegistrationFailed || state == RegistrationState.RegistrationCleared) && (LinphoneManager.getLc().getDefaultProxyConfig() == null || !LinphoneManager.getLc().getDefaultProxyConfig().isRegistered())) {
sendNotification(IC_LEVEL_ORANGE, R.string.notification_register_failure);
}
if (state == RegistrationState.RegistrationNone) {
if (displayServiceNotification() && state == RegistrationState.RegistrationNone) {
sendNotification(IC_LEVEL_ORANGE, R.string.notification_started);
}
}
@ -241,7 +266,9 @@ public final class LinphoneService extends Service {
getContentResolver().registerContentObserver(ContactsContract.Contacts.CONTENT_URI, true, ContactsManager.getInstance());
startForegroundCompat(NOTIF_ID, mNotif);
if (displayServiceNotification()) {
startForegroundCompat(NOTIF_ID, mNotif);
}
if (!mTestDelayElapsed) {
// Only used when testing. Simulates a 5 seconds delay for launching service
@ -505,7 +532,7 @@ public final class LinphoneService extends Service {
mDisableRegistrationStatus = true;
}
public synchronized void sendNotification(int level, int textId) {
private synchronized void sendNotification(int level, int textId) {
String text = getString(textId);
if (text.contains("%s") && LinphoneManager.getLc() != null) {
// Test for null lc is to avoid a NPE when Android mess up badly with the String resources.
@ -593,10 +620,10 @@ public final class LinphoneService extends Service {
Intent notifIntent = new Intent(this, incomingReceivedActivity);
mNotifContentIntent = PendingIntent.getActivity(this, 0, notifIntent, PendingIntent.FLAG_UPDATE_CURRENT);
if (mNotif != null) {
/*if (mNotif != null) {
mNotif.contentIntent = mNotifContentIntent;
}
notifyWrapper(NOTIF_ID, mNotif);
notifyWrapper(NOTIF_ID, mNotif);*/
}
protected void onIncomingReceived() {

View file

@ -899,6 +899,7 @@ public class SettingsFragment extends PreferencesListFragment {
((CheckBoxPreference)findPreference(getString(R.string.pref_debug_key))).setChecked(mPrefs.isDebugEnabled());
((CheckBoxPreference)findPreference(getString(R.string.pref_background_mode_key))).setChecked(mPrefs.isBackgroundModeEnabled());
((CheckBoxPreference)findPreference(getString(R.string.pref_animation_enable_key))).setChecked(mPrefs.areAnimationsEnabled());
((CheckBoxPreference)findPreference(getString(R.string.pref_service_notification_key))).setChecked(mPrefs.getServiceNotificationVisibility());
((CheckBoxPreference)findPreference(getString(R.string.pref_autostart_key))).setChecked(mPrefs.isAutoStartEnabled());
setPreferenceDefaultValueAndSummary(R.string.pref_image_sharing_server_key, mPrefs.getSharingPictureServerUrl());
setPreferenceDefaultValueAndSummary(R.string.pref_remote_provisioning_key, mPrefs.getRemoteProvisioningUrl());
@ -934,6 +935,20 @@ public class SettingsFragment extends PreferencesListFragment {
}
});
findPreference(getString(R.string.pref_service_notification_key)).setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
boolean value = (Boolean) newValue;
mPrefs.setServiceNotificationVisibility(value);
if (value) {
LinphoneService.instance().showServiceNotification();
} else {
LinphoneService.instance().hideServiceNotification();
}
return true;
}
});
findPreference(getString(R.string.pref_autostart_key)).setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {