Index: components/devtools_bridge/test/android/javatests/src/org/chromium/components/devtools_bridge/TestDevToolsBridgeService.java |
diff --git a/components/devtools_bridge/test/android/javatests/src/org/chromium/components/devtools_bridge/TestDevToolsBridgeService.java b/components/devtools_bridge/test/android/javatests/src/org/chromium/components/devtools_bridge/TestDevToolsBridgeService.java |
index b9b9c07d464e7c0dc41993c1e0eceef3010ab2ed..39c8a037959d3af6f8605c0f330ce2226e198aa0 100644 |
--- a/components/devtools_bridge/test/android/javatests/src/org/chromium/components/devtools_bridge/TestDevToolsBridgeService.java |
+++ b/components/devtools_bridge/test/android/javatests/src/org/chromium/components/devtools_bridge/TestDevToolsBridgeService.java |
@@ -4,13 +4,23 @@ |
package org.chromium.components.devtools_bridge; |
-import org.chromium.components.devtools_bridge.ui.ServiceUIFactory; |
+import android.app.Notification; |
+import android.app.PendingIntent; |
+import android.content.Intent; |
+import android.widget.Toast; |
+ |
+import com.google.ipc.invalidation.external.client.contrib.MultiplexingGcmListener; |
/** |
* Service for manual testing DevToolsBridgeServer with GCD signaling. |
*/ |
public final class TestDevToolsBridgeService extends DevToolsBridgeServiceBase { |
private static final String SOCKET_NAME = "chrome_shell_devtools_remote"; |
+ public final int NOTIFICATION_ID = 1; |
+ public final String DISCONNECT_ALL_CLIENTS_ACTION = |
+ "action.DISCONNECT_ALL_CLIENTS_ACTION"; |
+ public final String UPDATE_GCM_CHANNEL_ID_ACTION = |
+ "action.UPDATE_GCM_CHANNEL_ID"; |
/** |
* Redirects intents to the TestDevToolsBridgeService. |
@@ -22,22 +32,56 @@ public final class TestDevToolsBridgeService extends DevToolsBridgeServiceBase { |
} |
@Override |
- protected String socketName() { |
- return SOCKET_NAME; |
+ protected void querySocketName(DevToolsBridgeServer.QuerySocketCallback callback) { |
+ callback.onSuccess(SOCKET_NAME); |
} |
@Override |
- protected ServiceUIFactory newUIFactory() { |
- return new UIFactoryImpl(); |
+ protected void onFirstSessionStarted() { |
+ startForeground(NOTIFICATION_ID, newForegroundNotification()); |
} |
- private static class UIFactoryImpl extends ServiceUIFactory { |
- protected String productName() { |
- return "GCDHostService"; |
- } |
+ @Override |
+ protected void onLastSessionStopped() { |
+ stopForeground(true); |
+ } |
- protected int notificationSmallIcon() { |
- return android.R.drawable.alert_dark_frame; |
+ @Override |
+ protected void onHandleIntent(Intent intent) { |
+ if (DISCONNECT_ALL_CLIENTS_ACTION.equals(intent.getAction())) { |
+ server().closeAllSessions(); |
+ } else if (UPDATE_GCM_CHANNEL_ID_ACTION.equals(intent.getAction())) { |
+ String channelId = MultiplexingGcmListener.initializeGcm(this); |
+ if (channelId.isEmpty()) { |
+ Toast.makeText(this, "Not registered", Toast.LENGTH_SHORT).show(); |
+ } else { |
+ server().updateCloudMessagesId(channelId, startTask()); |
+ Toast.makeText(this, "Updating. See log for results.", Toast.LENGTH_SHORT).show(); |
+ } |
} |
} |
+ |
+ private PendingIntent newPendingIntent(String action) { |
+ Intent intent = new Intent(this, getClass()); |
+ intent.setAction(action); |
+ return PendingIntent.getService(this, 0, intent, 0); |
+ } |
+ |
+ private Notification newForegroundNotification() { |
+ return new Notification.Builder(this) |
+ // Mandatory fields |
+ .setSmallIcon(android.R.drawable.alert_dark_frame) |
+ .setContentTitle("TestDevToolsBridgeService") |
+ .setContentText("Remote debugger connected") |
+ |
+ // Optional |
+ .addAction(android.R.drawable.ic_delete, |
+ "Disconnect", newPendingIntent(DISCONNECT_ALL_CLIENTS_ACTION)) |
+ .addAction(android.R.drawable.ic_menu_manage, |
+ "Update GCM channel", newPendingIntent(UPDATE_GCM_CHANNEL_ID_ACTION)) |
+ .setOngoing(true) |
+ .setWhen(System.currentTimeMillis()) |
+ |
+ .build(); |
+ } |
} |