зеркало из https://github.com/mozilla/pjs.git
Bug 732147 - Send tab to device: receiving pushed tabs on Android. r=rnewman
This commit is contained in:
Родитель
545ec0ab6d
Коммит
d875f46c61
|
@ -7,11 +7,21 @@ package org.mozilla.gecko.sync;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
import org.json.simple.JSONArray;
|
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 {
|
public class CommandProcessor {
|
||||||
private static final String LOG_TAG = "Command";
|
private static final String LOG_TAG = "Command";
|
||||||
|
private static AtomicInteger currentId = new AtomicInteger();
|
||||||
protected ConcurrentHashMap<String, CommandRunner> commands = new ConcurrentHashMap<String, CommandRunner>();
|
protected ConcurrentHashMap<String, CommandRunner> commands = new ConcurrentHashMap<String, CommandRunner>();
|
||||||
|
|
||||||
private final static CommandProcessor processor = new CommandProcessor();
|
private final static CommandProcessor processor = new CommandProcessor();
|
||||||
|
@ -80,4 +90,39 @@ public class CommandProcessor {
|
||||||
return null;
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -176,6 +176,13 @@ public class GlobalSession implements CredentialsSource, PrefsSource, HttpRespon
|
||||||
resetClient(null);
|
resetClient(null);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
processor.registerCommand("displayURI", new CommandRunner() {
|
||||||
|
@Override
|
||||||
|
public void executeCommand(List<String> args) {
|
||||||
|
CommandProcessor.getProcessor().displayURI(args, getContext());
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void prepareStages() {
|
protected void prepareStages() {
|
||||||
|
|
|
@ -7,16 +7,11 @@ package org.mozilla.gecko.sync.syncadapter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
import java.util.List;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.json.simple.parser.ParseException;
|
import org.json.simple.parser.ParseException;
|
||||||
import org.mozilla.gecko.sync.AlreadySyncingException;
|
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.GlobalConstants;
|
||||||
import org.mozilla.gecko.sync.GlobalSession;
|
import org.mozilla.gecko.sync.GlobalSession;
|
||||||
import org.mozilla.gecko.sync.Logger;
|
|
||||||
import org.mozilla.gecko.sync.NonObjectJSONException;
|
import org.mozilla.gecko.sync.NonObjectJSONException;
|
||||||
import org.mozilla.gecko.sync.SyncConfiguration;
|
import org.mozilla.gecko.sync.SyncConfiguration;
|
||||||
import org.mozilla.gecko.sync.SyncConfigurationException;
|
import org.mozilla.gecko.sync.SyncConfigurationException;
|
||||||
|
@ -66,15 +61,6 @@ public class SyncAdapter extends AbstractThreadedSyncAdapter implements GlobalSe
|
||||||
mContext = context;
|
mContext = context;
|
||||||
Log.d(LOG_TAG, "AccountManager.get(" + mContext + ")");
|
Log.d(LOG_TAG, "AccountManager.get(" + mContext + ")");
|
||||||
mAccountManager = AccountManager.get(context);
|
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() {
|
private SharedPreferences getGlobalPrefs() {
|
||||||
|
@ -493,9 +479,4 @@ public class SyncAdapter extends AbstractThreadedSyncAdapter implements GlobalSe
|
||||||
public void informUnauthorizedResponse(GlobalSession session, URI oldClusterURL) {
|
public void informUnauthorizedResponse(GlobalSession session, URI oldClusterURL) {
|
||||||
setClusterURLIsStale(true);
|
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
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,3 +61,5 @@
|
||||||
<!-- Notification strings -->
|
<!-- Notification strings -->
|
||||||
<string name="sync_notification_oneaccount">&sync.notification.oneaccount.label;</string>
|
<string name="sync_notification_oneaccount">&sync.notification.oneaccount.label;</string>
|
||||||
|
|
||||||
|
<!-- Push tab to device strings -->
|
||||||
|
<string name="sync_new_tab">&new_tab;</string>
|
||||||
|
|
Загрузка…
Ссылка в новой задаче