Loading mobile/android/base/sync/CommandProcessor.java +45 −0 Original line number Diff line number Diff line Loading @@ -7,11 +7,21 @@ package org.mozilla.gecko.sync; import java.util.ArrayList; import java.util.List; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicInteger; import org.json.simple.JSONArray; import org.mozilla.gecko.R; import android.app.Notification; import android.app.NotificationManager; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.net.Uri; public class CommandProcessor { private static final String LOG_TAG = "Command"; private static AtomicInteger currentId = new AtomicInteger(); protected ConcurrentHashMap<String, CommandRunner> commands = new ConcurrentHashMap<String, CommandRunner>(); private final static CommandProcessor processor = new CommandProcessor(); Loading Loading @@ -80,4 +90,39 @@ public class CommandProcessor { return null; } } public void displayURI(List<String> args, Context context) { // These two args are guaranteed to exist by trusting the client sender. String uri = args.get(0); String clientId = args.get(1); Logger.info(LOG_TAG, "Received a URI for display: " + uri + " from " + clientId); String title = null; if (args.size() == 3) { title = args.get(2); } // Get NotificationManager. String ns = Context.NOTIFICATION_SERVICE; NotificationManager mNotificationManager = (NotificationManager)context.getSystemService(ns); // Create a Notficiation. int icon = R.drawable.sync_ic_launcher; String notificationTitle = context.getString(R.string.sync_new_tab); if (title != null) { notificationTitle = notificationTitle.concat(": " + title); } long when = System.currentTimeMillis(); Notification notification = new Notification(icon, notificationTitle, when); notification.flags = Notification.FLAG_AUTO_CANCEL; // Set pending intent associated with the notification. Intent notificationIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri)); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0); notification.setLatestEventInfo(context, notificationTitle, uri, contentIntent); // Send notification. mNotificationManager.notify(currentId.getAndIncrement(), notification); } } mobile/android/base/sync/GlobalSession.java +7 −0 Original line number Diff line number Diff line Loading @@ -176,6 +176,13 @@ public class GlobalSession implements CredentialsSource, PrefsSource, HttpRespon resetClient(null); } }); processor.registerCommand("displayURI", new CommandRunner() { @Override public void executeCommand(List<String> args) { CommandProcessor.getProcessor().displayURI(args, getContext()); } }); } protected void prepareStages() { Loading mobile/android/base/sync/syncadapter/SyncAdapter.java +0 −19 Original line number Diff line number Diff line Loading @@ -7,16 +7,11 @@ package org.mozilla.gecko.sync.syncadapter; import java.io.IOException; import java.net.URI; import java.security.NoSuchAlgorithmException; import java.util.List; import java.util.concurrent.TimeUnit; import org.json.simple.parser.ParseException; import org.mozilla.gecko.sync.AlreadySyncingException; import org.mozilla.gecko.sync.CommandRunner; import org.mozilla.gecko.sync.CommandProcessor; import org.mozilla.gecko.sync.GlobalConstants; import org.mozilla.gecko.sync.GlobalSession; import org.mozilla.gecko.sync.Logger; import org.mozilla.gecko.sync.NonObjectJSONException; import org.mozilla.gecko.sync.SyncConfiguration; import org.mozilla.gecko.sync.SyncConfigurationException; Loading Loading @@ -66,15 +61,6 @@ public class SyncAdapter extends AbstractThreadedSyncAdapter implements GlobalSe mContext = context; Log.d(LOG_TAG, "AccountManager.get(" + mContext + ")"); mAccountManager = AccountManager.get(context); // Register the displayURI command here so our SyncService // can receive notifications to open a URI. CommandProcessor.getProcessor().registerCommand("displayURI", new CommandRunner() { @Override public void executeCommand(List<String> args) { displayURI(args.get(0), args.get(1)); } }); } private SharedPreferences getGlobalPrefs() { Loading Loading @@ -493,9 +479,4 @@ public class SyncAdapter extends AbstractThreadedSyncAdapter implements GlobalSe public void informUnauthorizedResponse(GlobalSession session, URI oldClusterURL) { setClusterURLIsStale(true); } public void displayURI(String uri, String clientId) { Logger.info(LOG_TAG, "Received a URI for display: " + uri + " from " + clientId); // TODO: Bug 732147 - Send tab to device: receiving pushed tabs } } mobile/android/sync/strings.xml.in +2 −0 Original line number Diff line number Diff line Loading @@ -61,3 +61,5 @@ <!-- Notification strings --> <string name="sync_notification_oneaccount">&sync.notification.oneaccount.label;</string> <!-- Push tab to device strings --> <string name="sync_new_tab">&new_tab;</string> Loading
mobile/android/base/sync/CommandProcessor.java +45 −0 Original line number Diff line number Diff line Loading @@ -7,11 +7,21 @@ package org.mozilla.gecko.sync; import java.util.ArrayList; import java.util.List; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicInteger; import org.json.simple.JSONArray; import org.mozilla.gecko.R; import android.app.Notification; import android.app.NotificationManager; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.net.Uri; public class CommandProcessor { private static final String LOG_TAG = "Command"; private static AtomicInteger currentId = new AtomicInteger(); protected ConcurrentHashMap<String, CommandRunner> commands = new ConcurrentHashMap<String, CommandRunner>(); private final static CommandProcessor processor = new CommandProcessor(); Loading Loading @@ -80,4 +90,39 @@ public class CommandProcessor { return null; } } public void displayURI(List<String> args, Context context) { // These two args are guaranteed to exist by trusting the client sender. String uri = args.get(0); String clientId = args.get(1); Logger.info(LOG_TAG, "Received a URI for display: " + uri + " from " + clientId); String title = null; if (args.size() == 3) { title = args.get(2); } // Get NotificationManager. String ns = Context.NOTIFICATION_SERVICE; NotificationManager mNotificationManager = (NotificationManager)context.getSystemService(ns); // Create a Notficiation. int icon = R.drawable.sync_ic_launcher; String notificationTitle = context.getString(R.string.sync_new_tab); if (title != null) { notificationTitle = notificationTitle.concat(": " + title); } long when = System.currentTimeMillis(); Notification notification = new Notification(icon, notificationTitle, when); notification.flags = Notification.FLAG_AUTO_CANCEL; // Set pending intent associated with the notification. Intent notificationIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri)); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0); notification.setLatestEventInfo(context, notificationTitle, uri, contentIntent); // Send notification. mNotificationManager.notify(currentId.getAndIncrement(), notification); } }
mobile/android/base/sync/GlobalSession.java +7 −0 Original line number Diff line number Diff line Loading @@ -176,6 +176,13 @@ public class GlobalSession implements CredentialsSource, PrefsSource, HttpRespon resetClient(null); } }); processor.registerCommand("displayURI", new CommandRunner() { @Override public void executeCommand(List<String> args) { CommandProcessor.getProcessor().displayURI(args, getContext()); } }); } protected void prepareStages() { Loading
mobile/android/base/sync/syncadapter/SyncAdapter.java +0 −19 Original line number Diff line number Diff line Loading @@ -7,16 +7,11 @@ package org.mozilla.gecko.sync.syncadapter; import java.io.IOException; import java.net.URI; import java.security.NoSuchAlgorithmException; import java.util.List; import java.util.concurrent.TimeUnit; import org.json.simple.parser.ParseException; import org.mozilla.gecko.sync.AlreadySyncingException; import org.mozilla.gecko.sync.CommandRunner; import org.mozilla.gecko.sync.CommandProcessor; import org.mozilla.gecko.sync.GlobalConstants; import org.mozilla.gecko.sync.GlobalSession; import org.mozilla.gecko.sync.Logger; import org.mozilla.gecko.sync.NonObjectJSONException; import org.mozilla.gecko.sync.SyncConfiguration; import org.mozilla.gecko.sync.SyncConfigurationException; Loading Loading @@ -66,15 +61,6 @@ public class SyncAdapter extends AbstractThreadedSyncAdapter implements GlobalSe mContext = context; Log.d(LOG_TAG, "AccountManager.get(" + mContext + ")"); mAccountManager = AccountManager.get(context); // Register the displayURI command here so our SyncService // can receive notifications to open a URI. CommandProcessor.getProcessor().registerCommand("displayURI", new CommandRunner() { @Override public void executeCommand(List<String> args) { displayURI(args.get(0), args.get(1)); } }); } private SharedPreferences getGlobalPrefs() { Loading Loading @@ -493,9 +479,4 @@ public class SyncAdapter extends AbstractThreadedSyncAdapter implements GlobalSe public void informUnauthorizedResponse(GlobalSession session, URI oldClusterURL) { setClusterURLIsStale(true); } public void displayURI(String uri, String clientId) { Logger.info(LOG_TAG, "Received a URI for display: " + uri + " from " + clientId); // TODO: Bug 732147 - Send tab to device: receiving pushed tabs } }
mobile/android/sync/strings.xml.in +2 −0 Original line number Diff line number Diff line Loading @@ -61,3 +61,5 @@ <!-- Notification strings --> <string name="sync_notification_oneaccount">&sync.notification.oneaccount.label;</string> <!-- Push tab to device strings --> <string name="sync_new_tab">&new_tab;</string>