Skip to content
Snippets Groups Projects
Commit a310667a authored by Kateryna Kostiuk's avatar Kateryna Kostiuk Committed by Aline Bonnet
Browse files

Trust requests:perform actions with notification


Add actions accept, refuse and block for incoming trust request
notification.

Tuleap: #1495
Change-Id: I64af2c877e69c659137b1640cf28083e169b28e6
Reviewed-by: default avatarAlexandre Lision <alexandre.lision@savoirfairelinux.com>
parent 0933f9a7
No related branches found
No related tags found
No related merge requests found
...@@ -27,7 +27,7 @@ package cx.ring.service; ...@@ -27,7 +27,7 @@ package cx.ring.service;
import android.app.Service; import android.app.Service;
import android.content.Intent; import android.content.Intent;
import android.hardware.Camera; import android.os.Bundle;
import android.os.IBinder; import android.os.IBinder;
import android.os.RemoteException; import android.os.RemoteException;
import android.util.Log; import android.util.Log;
...@@ -36,7 +36,6 @@ import android.view.SurfaceHolder; ...@@ -36,7 +36,6 @@ import android.view.SurfaceHolder;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
...@@ -44,42 +43,56 @@ import java.util.concurrent.ExecutorService; ...@@ -44,42 +43,56 @@ import java.util.concurrent.ExecutorService;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
import cx.ring.BuildConfig;
import cx.ring.application.RingApplication; import cx.ring.application.RingApplication;
import cx.ring.daemon.StringMap; import cx.ring.daemon.StringMap;
import cx.ring.model.Codec; import cx.ring.model.Codec;
import cx.ring.services.AccountService; import cx.ring.services.AccountService;
import cx.ring.services.CallService; import cx.ring.services.CallService;
import cx.ring.services.ConferenceService; import cx.ring.services.ConferenceService;
import cx.ring.services.ContactService;
import cx.ring.services.DaemonService; import cx.ring.services.DaemonService;
import cx.ring.services.DeviceRuntimeService; import cx.ring.services.DeviceRuntimeService;
import cx.ring.services.HardwareService; import cx.ring.services.HardwareService;
import cx.ring.services.NotificationService;
import cx.ring.services.NotificationServiceImpl;
public class DRingService extends Service { public class DRingService extends Service {
public static final String ACTION_TRUST_REQUEST_ACCEPT = BuildConfig.APPLICATION_ID + ".action.TRUST_REQUEST_ACCEPT";
public static final String ACTION_TRUST_REQUEST_REFUSE = BuildConfig.APPLICATION_ID + ".action.TRUST_REQUEST_REFUSE";
public static final String ACTION_TRUST_REQUEST_BLOCK = BuildConfig.APPLICATION_ID + ".action.TRUST_REQUEST_BLOCK";
private static final String TAG = DRingService.class.getName();
@Inject @Inject
DaemonService mDaemonService; protected DaemonService mDaemonService;
@Inject @Inject
CallService mCallService; protected CallService mCallService;
@Inject @Inject
ConferenceService mConferenceService; protected ConferenceService mConferenceService;
@Inject @Inject
AccountService mAccountService; protected AccountService mAccountService;
@Inject @Inject
HardwareService mHardwareService; protected HardwareService mHardwareService;
@Inject @Inject
DeviceRuntimeService mDeviceRuntimeService; protected DeviceRuntimeService mDeviceRuntimeService;
@Inject @Inject
@Named("DaemonExecutor") protected NotificationService mNotificationService;
ExecutorService mExecutor;
static final String TAG = DRingService.class.getName(); @Inject
protected ContactService mContactService;
@Inject
@Named("DaemonExecutor")
protected ExecutorService mExecutor;
@Override @Override
public void onCreate() { public void onCreate() {
...@@ -93,6 +106,11 @@ public class DRingService extends Service { ...@@ -93,6 +106,11 @@ public class DRingService extends Service {
@Override @Override
public int onStartCommand(Intent intent, int flags, int startId) { public int onStartCommand(Intent intent, int flags, int startId) {
Log.i(TAG, "onStartCommand " + (intent == null ? "null" : intent.getAction()) + " " + flags + " " + startId); Log.i(TAG, "onStartCommand " + (intent == null ? "null" : intent.getAction()) + " " + flags + " " + startId);
if (intent != null && intent.getAction() != null) {
parseIntent(intent);
}
return START_STICKY; /* started and stopped explicitly */ return START_STICKY; /* started and stopped explicitly */
} }
...@@ -500,4 +518,43 @@ public class DRingService extends Service { ...@@ -500,4 +518,43 @@ public class DRingService extends Service {
mAccountService.registerName(account, password, name); mAccountService.registerName(account, password, name);
} }
}; };
private void parseIntent(Intent intent) {
switch (intent.getAction()) {
case ACTION_TRUST_REQUEST_ACCEPT:
case ACTION_TRUST_REQUEST_REFUSE:
case ACTION_TRUST_REQUEST_BLOCK: {
Bundle extras = intent.getExtras();
if (extras != null) {
handleTrustRequestAction(intent.getAction(), extras);
}
break;
}
default:
break;
}
}
private void handleTrustRequestAction(String action, Bundle extras) {
String account = extras.getString(NotificationServiceImpl.TRUST_REQUEST_NOTIFICATION_ACCOUNT_ID);
String from = extras.getString(NotificationServiceImpl.TRUST_REQUEST_NOTIFICATION_FROM);
if (account != null && from != null) {
mNotificationService.cancelTrustRequestNotification(account);
switch (action) {
case ACTION_TRUST_REQUEST_ACCEPT: {
mAccountService.acceptTrustRequest(account, from);
break;
}
case ACTION_TRUST_REQUEST_REFUSE: {
mAccountService.discardTrustRequest(account, from);
break;
}
case ACTION_TRUST_REQUEST_BLOCK: {
mAccountService.discardTrustRequest(account, from);
mContactService.removeContact(account, from);
break;
}
}
}
}
} }
...@@ -43,6 +43,7 @@ import cx.ring.BuildConfig; ...@@ -43,6 +43,7 @@ import cx.ring.BuildConfig;
import cx.ring.R; import cx.ring.R;
import cx.ring.client.ConversationActivity; import cx.ring.client.ConversationActivity;
import cx.ring.client.HomeActivity; import cx.ring.client.HomeActivity;
import cx.ring.contactrequests.PendingContactRequestsFragment;
import cx.ring.fragments.ConversationFragment; import cx.ring.fragments.ConversationFragment;
import cx.ring.model.CallContact; import cx.ring.model.CallContact;
import cx.ring.model.Conference; import cx.ring.model.Conference;
...@@ -51,8 +52,8 @@ import cx.ring.model.ServiceEvent; ...@@ -51,8 +52,8 @@ import cx.ring.model.ServiceEvent;
import cx.ring.model.SipCall; import cx.ring.model.SipCall;
import cx.ring.model.TextMessage; import cx.ring.model.TextMessage;
import cx.ring.service.CallManagerCallBack; import cx.ring.service.CallManagerCallBack;
import cx.ring.service.DRingService;
import cx.ring.service.LocalService; import cx.ring.service.LocalService;
import cx.ring.contactrequests.PendingContactRequestsFragment;
import cx.ring.utils.ActionHelper; import cx.ring.utils.ActionHelper;
import cx.ring.utils.BitmapUtils; import cx.ring.utils.BitmapUtils;
import cx.ring.utils.ContentUriHandler; import cx.ring.utils.ContentUriHandler;
...@@ -64,17 +65,22 @@ public class NotificationServiceImpl extends NotificationService implements Obse ...@@ -64,17 +65,22 @@ public class NotificationServiceImpl extends NotificationService implements Obse
private static final String TAG = NotificationServiceImpl.class.getName(); private static final String TAG = NotificationServiceImpl.class.getName();
public static final String TRUST_REQUEST_NOTIFICATION_ACCOUNT_ID = "trustRequestNotificationAccountId";
public static final String TRUST_REQUEST_NOTIFICATION_FROM = "trustRequestNotificationFrom";
private static final String NOTIF_CALL = "CALL"; private static final String NOTIF_CALL = "CALL";
private static final String NOTIF_MSG = "MESSAGE"; private static final String NOTIF_MSG = "MESSAGE";
private static final String NOTIF_TRUST_REQUEST = "TRUST REQUEST"; private static final String NOTIF_TRUST_REQUEST = "TRUST REQUEST";
private final String EXTRAS_NUMBER_TRUST_REQUEST_KEY = BuildConfig.APPLICATION_ID + "numberOfTrustRequestssKey";
private final String EXTRAS_TRUST_REQUEST_FROM_KEY = BuildConfig.APPLICATION_ID + "trustREquestFrom"; private static final String EXTRAS_NUMBER_TRUST_REQUEST_KEY = BuildConfig.APPLICATION_ID + "numberOfTrustRequestKey";
private static final String EXTRAS_TRUST_REQUEST_FROM_KEY = BuildConfig.APPLICATION_ID + "trustRequestFrom";
@Inject @Inject
Context mContext; protected Context mContext;
@Inject @Inject
AccountService mAccountService; protected AccountService mAccountService;
private NotificationManagerCompat notificationManager; private NotificationManagerCompat notificationManager;
...@@ -240,7 +246,6 @@ public class NotificationServiceImpl extends NotificationService implements Obse ...@@ -240,7 +246,6 @@ public class NotificationServiceImpl extends NotificationService implements Obse
@Override @Override
public void showIncomingTrustRequestNotification(String accountID, String from) { public void showIncomingTrustRequestNotification(String accountID, String from) {
int notificationId = getIncomingTrustNotificationId(accountID); int notificationId = getIncomingTrustNotificationId(accountID);
NotificationCompat.Builder messageNotificationBuilder = mNotificationBuilders.get(notificationId); NotificationCompat.Builder messageNotificationBuilder = mNotificationBuilders.get(notificationId);
//count number of notifications to update notification's text //count number of notifications to update notification's text
...@@ -255,14 +260,39 @@ public class NotificationServiceImpl extends NotificationService implements Obse ...@@ -255,14 +260,39 @@ public class NotificationServiceImpl extends NotificationService implements Obse
} }
numberOfNotifications = notificationInfo.getInt(EXTRAS_NUMBER_TRUST_REQUEST_KEY); numberOfNotifications = notificationInfo.getInt(EXTRAS_NUMBER_TRUST_REQUEST_KEY);
numberOfNotifications++; numberOfNotifications++;
if (numberOfNotifications > 1) { if (numberOfNotifications > 1) {
cancelTrustRequestNotification(accountID);
messageNotificationBuilder.setContentText(String.format(mContext.getString(R.string.contact_request_msg), Integer.toString(numberOfNotifications))); messageNotificationBuilder.setContentText(String.format(mContext.getString(R.string.contact_request_msg), Integer.toString(numberOfNotifications)));
messageNotificationBuilder.setLargeIcon(null); messageNotificationBuilder.setLargeIcon(null);
messageNotificationBuilder.mActions.clear();
numberOfNotifications--;
} }
} }
} else { } else {
messageNotificationBuilder = new NotificationCompat.Builder(mContext); messageNotificationBuilder = new NotificationCompat.Builder(mContext);
messageNotificationBuilder.setContentText(from); Bundle info = new Bundle();
info.putString(TRUST_REQUEST_NOTIFICATION_ACCOUNT_ID, accountID);
info.putString(TRUST_REQUEST_NOTIFICATION_FROM, from);
messageNotificationBuilder.setContentText(from)
.addAction(R.drawable.ic_action_accept, mContext.getText(R.string.accept),
PendingIntent.getService(mContext, new Random().nextInt(),
new Intent(DRingService.ACTION_TRUST_REQUEST_ACCEPT)
.setClass(mContext, DRingService.class)
.putExtras(info),
PendingIntent.FLAG_ONE_SHOT))
.addAction(R.drawable.ic_delete_white, mContext.getText(R.string.refuse),
PendingIntent.getService(mContext, new Random().nextInt(),
new Intent(DRingService.ACTION_TRUST_REQUEST_REFUSE)
.setClass(mContext, DRingService.class)
.putExtras(info),
PendingIntent.FLAG_ONE_SHOT))
.addAction(R.drawable.ic_close_white, mContext.getText(R.string.block),
PendingIntent.getService(mContext, new Random().nextInt(),
new Intent(DRingService.ACTION_TRUST_REQUEST_BLOCK)
.setClass(mContext, DRingService.class)
.putExtras(info),
PendingIntent.FLAG_ONE_SHOT));
Resources res = mContext.getResources(); Resources res = mContext.getResources();
int height = (int) res.getDimension(android.R.dimen.notification_large_icon_height); int height = (int) res.getDimension(android.R.dimen.notification_large_icon_height);
int width = (int) res.getDimension(android.R.dimen.notification_large_icon_width); int width = (int) res.getDimension(android.R.dimen.notification_large_icon_width);
...@@ -276,6 +306,7 @@ public class NotificationServiceImpl extends NotificationService implements Obse ...@@ -276,6 +306,7 @@ public class NotificationServiceImpl extends NotificationService implements Obse
Bundle extras = new Bundle(); Bundle extras = new Bundle();
extras.putInt(EXTRAS_NUMBER_TRUST_REQUEST_KEY, numberOfNotifications); extras.putInt(EXTRAS_NUMBER_TRUST_REQUEST_KEY, numberOfNotifications);
extras.putString(EXTRAS_TRUST_REQUEST_FROM_KEY, from); extras.putString(EXTRAS_TRUST_REQUEST_FROM_KEY, from);
messageNotificationBuilder.setPriority(NotificationCompat.PRIORITY_HIGH) messageNotificationBuilder.setPriority(NotificationCompat.PRIORITY_HIGH)
.setDefaults(NotificationCompat.DEFAULT_ALL) .setDefaults(NotificationCompat.DEFAULT_ALL)
.setAutoCancel(true) .setAutoCancel(true)
...@@ -287,6 +318,7 @@ public class NotificationServiceImpl extends NotificationService implements Obse ...@@ -287,6 +318,7 @@ public class NotificationServiceImpl extends NotificationService implements Obse
messageNotificationBuilder.setContentIntent(PendingIntent.getActivity(mContext, messageNotificationBuilder.setContentIntent(PendingIntent.getActivity(mContext,
new Random().nextInt(), intentOpenTrustRequestFragment, PendingIntent.FLAG_ONE_SHOT)) new Random().nextInt(), intentOpenTrustRequestFragment, PendingIntent.FLAG_ONE_SHOT))
.addExtras(extras); .addExtras(extras);
notificationManager.notify(notificationId, messageNotificationBuilder.build()); notificationManager.notify(notificationId, messageNotificationBuilder.build());
if (numberOfNotifications == 1) { if (numberOfNotifications == 1) {
mNotificationBuilders.put(notificationId, messageNotificationBuilder); mNotificationBuilders.put(notificationId, messageNotificationBuilder);
...@@ -385,6 +417,7 @@ public class NotificationServiceImpl extends NotificationService implements Obse ...@@ -385,6 +417,7 @@ public class NotificationServiceImpl extends NotificationService implements Obse
} }
break; break;
} }
case INCOMING_TRUST_REQUEST: { case INCOMING_TRUST_REQUEST: {
final String accountID = arg.getEventInput(ServiceEvent.EventInput.ACCOUNT_ID, String.class); final String accountID = arg.getEventInput(ServiceEvent.EventInput.ACCOUNT_ID, String.class);
final String from = arg.getEventInput(ServiceEvent.EventInput.FROM, String.class); final String from = arg.getEventInput(ServiceEvent.EventInput.FROM, String.class);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment