Disable notification service on Android O

This commit is contained in:
Erwan Croze 2017-10-18 10:18:58 +02:00
parent 342ab8c41a
commit 926712a704
4 changed files with 26 additions and 7 deletions

View file

@ -93,6 +93,7 @@
<string name="about_bugreport_email">linphone-android@belledonne-communications.com</string>
<bool name="enable_call_notification">true</bool>
<bool name="kill_service_with_task_manager">true</bool>
<string name="notification_service_channel_id">linphone_notification_service_id</string>
<string name="notification_channel_id">linphone_notification_id</string>
<integer name="notification_ms_on">1000</integer>
<integer name="notification_ms_off">7000</integer>

View file

@ -485,5 +485,6 @@
<string name="content_description_call_options">Call options</string>
<string name="content_description_audio_route">Audio route</string>
<string name="content_description_exit_conference">Exit conference</string>
<string name="content_title_notification_service">Linphone Service</string>
<string name="content_title_notification">Linphone Notification</string>
</resources>

View file

@ -307,6 +307,12 @@ public final class LinphoneService extends Service {
dumpDeviceInformation();
dumpInstalledLinphoneInformation();
//Disable service notification for Android O
if ((Version.sdkAboveOrEqual(Version.API26_O_80))) {
LinphonePreferences.instance().setServiceNotificationVisibility(false);
mDisableRegistrationStatus = true;
}
mNM = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
mNM.cancel(INCALL_NOTIF_ID); // in case of crash the icon is not removed
Compatibility.CreateChannel(this);
@ -393,7 +399,7 @@ public final class LinphoneService extends Service {
@Override
public void globalState(LinphoneCore lc,LinphoneCore.GlobalState state, String message) {
if (state == GlobalState.GlobalOn && displayServiceNotification()) {
if (!mDisableRegistrationStatus && state == GlobalState.GlobalOn && displayServiceNotification()) {
sendNotification(IC_LEVEL_ORANGE, R.string.notification_started);
}
}

View file

@ -8,6 +8,7 @@ import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.graphics.Bitmap;
import android.media.AudioAttributes;
import android.view.ViewTreeObserver;
import org.linphone.R;
@ -37,12 +38,22 @@ public class ApiTwentySixPlus {
public static void CreateChannel(Context context) {
NotificationManager notificationManager =
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
String id = context.getString(R.string.notification_channel_id);
CharSequence name = context.getString(R.string.content_title_notification);
String description = context.getString(R.string.content_title_notification);
int importance = NotificationManager.IMPORTANCE_DEFAULT;
// Create service notification channel
String id = context.getString(R.string.notification_service_channel_id);
CharSequence name = context.getString(R.string.content_title_notification_service);
String description = context.getString(R.string.content_title_notification_service);
int importance = NotificationManager.IMPORTANCE_NONE;
NotificationChannel mChannel = new NotificationChannel(id, name, importance);
mChannel.setDescription(description);
mChannel.enableVibration(false);
notificationManager.createNotificationChannel(mChannel);
// Create message/call notification channel
id = context.getString(R.string.notification_channel_id);
name = context.getString(R.string.content_title_notification);
description = context.getString(R.string.content_title_notification);
importance = NotificationManager.IMPORTANCE_HIGH;
mChannel = new NotificationChannel(id, name, importance);
mChannel.setDescription(description);
mChannel.enableLights(true);
mChannel.setLightColor(context.getColor(R.color.notification_color_led));
mChannel.enableLights(true);
@ -103,7 +114,7 @@ public class ApiTwentySixPlus {
Notification notif;
if (largeIcon != null) {
notif = new Notification.Builder(context, context.getString(R.string.notification_channel_id))
notif = new Notification.Builder(context, context.getString(R.string.notification_service_channel_id))
.setContentTitle(title)
.setContentText(message)
.setSmallIcon(icon, level)
@ -114,7 +125,7 @@ public class ApiTwentySixPlus {
.setPriority(priority)
.build();
} else {
notif = new Notification.Builder(context, context.getString(R.string.notification_channel_id))
notif = new Notification.Builder(context, context.getString(R.string.notification_service_channel_id))
.setContentTitle(title)
.setContentText(message)
.setSmallIcon(icon, level)