Use call notification as service's foreground notification instead of having two
This commit is contained in:
parent
7fe461411d
commit
0cda463087
3 changed files with 39 additions and 9 deletions
|
@ -68,6 +68,8 @@ public class LinphoneLauncherActivity extends Activity {
|
||||||
classToStart = LinphoneActivity.class;
|
classToStart = LinphoneActivity.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LinphoneService.instance().removeForegroundServiceNotificationIfPossible();
|
||||||
|
|
||||||
mHandler.postDelayed(
|
mHandler.postDelayed(
|
||||||
new Runnable() {
|
new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -128,6 +128,10 @@ public final class LinphoneService extends Service {
|
||||||
return mNotificationManager;
|
return mNotificationManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void removeForegroundServiceNotificationIfPossible() {
|
||||||
|
mNotificationManager.removeForegroundServiceNotificationIfPossible();
|
||||||
|
}
|
||||||
|
|
||||||
public Class<? extends Activity> getIncomingReceivedActivity() {
|
public Class<? extends Activity> getIncomingReceivedActivity() {
|
||||||
return mIncomingReceivedActivity;
|
return mIncomingReceivedActivity;
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,11 +56,13 @@ public class NotificationsManager {
|
||||||
private final HashMap<String, Notifiable> mCallNotifMap;
|
private final HashMap<String, Notifiable> mCallNotifMap;
|
||||||
private int mLastNotificationId;
|
private int mLastNotificationId;
|
||||||
private final Notification mServiceNotification;
|
private final Notification mServiceNotification;
|
||||||
|
private int mCurrentForegroundServiceNotification;
|
||||||
|
|
||||||
public NotificationsManager(Context context) {
|
public NotificationsManager(Context context) {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
mChatNotifMap = new HashMap<>();
|
mChatNotifMap = new HashMap<>();
|
||||||
mCallNotifMap = new HashMap<>();
|
mCallNotifMap = new HashMap<>();
|
||||||
|
mCurrentForegroundServiceNotification = 0;
|
||||||
|
|
||||||
mNM = (NotificationManager) mContext.getSystemService(NOTIFICATION_SERVICE);
|
mNM = (NotificationManager) mContext.getSystemService(NOTIFICATION_SERVICE);
|
||||||
mNM.cancelAll();
|
mNM.cancelAll();
|
||||||
|
@ -110,10 +112,24 @@ public class NotificationsManager {
|
||||||
|
|
||||||
public void startForeground() {
|
public void startForeground() {
|
||||||
LinphoneService.instance().startForeground(SERVICE_NOTIF_ID, mServiceNotification);
|
LinphoneService.instance().startForeground(SERVICE_NOTIF_ID, mServiceNotification);
|
||||||
|
mCurrentForegroundServiceNotification = SERVICE_NOTIF_ID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void startForeground(Notification notification, int id) {
|
||||||
|
LinphoneService.instance().startForeground(id, notification);
|
||||||
|
mCurrentForegroundServiceNotification = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stopForeground() {
|
public void stopForeground() {
|
||||||
LinphoneService.instance().stopForeground(true);
|
LinphoneService.instance().stopForeground(true);
|
||||||
|
mCurrentForegroundServiceNotification = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeForegroundServiceNotificationIfPossible() {
|
||||||
|
if (!LinphonePreferences.instance().getServiceNotificationVisibility()
|
||||||
|
&& mCurrentForegroundServiceNotification == SERVICE_NOTIF_ID) {
|
||||||
|
stopForeground();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendNotification(int id, Notification notif) {
|
public void sendNotification(int id, Notification notif) {
|
||||||
|
@ -295,19 +311,16 @@ public class NotificationsManager {
|
||||||
mCallNotifMap.put(addressAsString, notif);
|
mCallNotifMap.put(addressAsString, notif);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isServiceNotificationDisplayed()) {
|
|
||||||
if (call.getCore().getCallsNb() == 0) {
|
|
||||||
stopForeground();
|
|
||||||
} else {
|
|
||||||
startForeground();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int notificationTextId;
|
int notificationTextId;
|
||||||
int iconId;
|
int iconId;
|
||||||
switch (call.getState()) {
|
switch (call.getState()) {
|
||||||
case Released:
|
case Released:
|
||||||
case End:
|
case End:
|
||||||
|
if (mCurrentForegroundServiceNotification == notif.getNotificationId()) {
|
||||||
|
// Call is released, remove service notification to allow for an other call to
|
||||||
|
// be service notification
|
||||||
|
stopForeground();
|
||||||
|
}
|
||||||
mNM.cancel(notif.getNotificationId());
|
mNM.cancel(notif.getNotificationId());
|
||||||
mCallNotifMap.remove(addressAsString);
|
mCallNotifMap.remove(addressAsString);
|
||||||
return;
|
return;
|
||||||
|
@ -346,8 +359,19 @@ public class NotificationsManager {
|
||||||
bm,
|
bm,
|
||||||
name,
|
name,
|
||||||
pendingIntent);
|
pendingIntent);
|
||||||
|
|
||||||
|
if (!isServiceNotificationDisplayed()) {
|
||||||
|
if (call.getCore().getCallsNb() == 0) {
|
||||||
|
stopForeground();
|
||||||
|
} else {
|
||||||
|
if (mCurrentForegroundServiceNotification == 0) {
|
||||||
|
startForeground(notification, notif.getNotificationId());
|
||||||
|
} else {
|
||||||
sendNotification(notif.getNotificationId(), notification);
|
sendNotification(notif.getNotificationId(), notification);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public String getSipUriForCallNotificationId(int notificationId) {
|
public String getSipUriForCallNotificationId(int notificationId) {
|
||||||
for (String addr : mCallNotifMap.keySet()) {
|
for (String addr : mCallNotifMap.keySet()) {
|
||||||
|
|
Loading…
Reference in a new issue