Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(90)

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/physicalweb/PhysicalWebBroadcastService.java

Issue 2765003002: [Android O] Upstreaming notification channels code (Closed)
Patch Set: Rebase + update tag Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.chrome.browser.physicalweb; 5 package org.chromium.chrome.browser.physicalweb;
6 6
7 import android.annotation.TargetApi; 7 import android.annotation.TargetApi;
8 import android.app.NotificationManager; 8 import android.app.NotificationManager;
9 import android.app.PendingIntent; 9 import android.app.PendingIntent;
10 import android.app.Service; 10 import android.app.Service;
11 import android.bluetooth.BluetoothAdapter; 11 import android.bluetooth.BluetoothAdapter;
12 import android.content.BroadcastReceiver; 12 import android.content.BroadcastReceiver;
13 import android.content.Context; 13 import android.content.Context;
14 import android.content.Intent; 14 import android.content.Intent;
15 import android.content.IntentFilter; 15 import android.content.IntentFilter;
16 import android.content.SharedPreferences; 16 import android.content.SharedPreferences;
17 import android.os.Build; 17 import android.os.Build;
18 import android.os.IBinder; 18 import android.os.IBinder;
19 19
20 import org.chromium.base.ContextUtils; 20 import org.chromium.base.ContextUtils;
21 import org.chromium.base.Log; 21 import org.chromium.base.Log;
22 import org.chromium.chrome.R; 22 import org.chromium.chrome.R;
23 import org.chromium.chrome.browser.AppHooks;
24 import org.chromium.chrome.browser.notifications.ChromeNotificationBuilder; 23 import org.chromium.chrome.browser.notifications.ChromeNotificationBuilder;
24 import org.chromium.chrome.browser.notifications.NotificationBuilderFactory;
25 import org.chromium.chrome.browser.notifications.NotificationConstants; 25 import org.chromium.chrome.browser.notifications.NotificationConstants;
26 import org.chromium.chrome.browser.notifications.NotificationManagerProxy; 26 import org.chromium.chrome.browser.notifications.NotificationManagerProxy;
27 import org.chromium.chrome.browser.notifications.NotificationManagerProxyImpl; 27 import org.chromium.chrome.browser.notifications.NotificationManagerProxyImpl;
28 import org.chromium.chrome.browser.util.IntentUtils; 28 import org.chromium.chrome.browser.util.IntentUtils;
29 29
30 /** 30 /**
31 * Broadcasts Physical Web URLs via Bluetooth Low Energy (BLE). 31 * Broadcasts Physical Web URLs via Bluetooth Low Energy (BLE).
32 * 32 *
33 * This background service will start when the user activates the Physical Web S haring item in the 33 * This background service will start when the user activates the Physical Web S haring item in the
34 * sharing chooser intent. If the URL received from the triggering Tab is valida ted 34 * sharing chooser intent. If the URL received from the triggering Tab is valida ted
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 * The notification specifies the URL that is being broadcast. It cannot be swiped away, 142 * The notification specifies the URL that is being broadcast. It cannot be swiped away,
143 * but broadcasting can be terminated with the stop button on the notificati on. 143 * but broadcasting can be terminated with the stop button on the notificati on.
144 */ 144 */
145 private void createBroadcastNotification(String displayUrl) { 145 private void createBroadcastNotification(String displayUrl) {
146 Context context = getApplicationContext(); 146 Context context = getApplicationContext();
147 PendingIntent stopPendingIntent = PendingIntent.getBroadcast( 147 PendingIntent stopPendingIntent = PendingIntent.getBroadcast(
148 context, 0, new Intent(STOP_SERVICE), PendingIntent.FLAG_UPDATE_ CURRENT); 148 context, 0, new Intent(STOP_SERVICE), PendingIntent.FLAG_UPDATE_ CURRENT);
149 NotificationManagerProxy notificationManager = new NotificationManagerPr oxyImpl( 149 NotificationManagerProxy notificationManager = new NotificationManagerPr oxyImpl(
150 (NotificationManager) getSystemService(NOTIFICATION_SERVICE)); 150 (NotificationManager) getSystemService(NOTIFICATION_SERVICE));
151 ChromeNotificationBuilder notificationBuilder = 151 ChromeNotificationBuilder notificationBuilder =
152 AppHooks.get() 152 NotificationBuilderFactory
153 .createChromeNotificationBuilder(true /* preferCompat */ , 153 .createChromeNotificationBuilder(true /* preferCompat */ ,
154 NotificationConstants.CATEGORY_ID_BROWSER, 154 NotificationConstants.CATEGORY_ID_BROWSER,
155 context.getString(R.string.notification_category _browser), 155 context.getString(R.string.notification_category _browser),
156 NotificationConstants.CATEGORY_GROUP_ID_GENERAL, 156 NotificationConstants.CATEGORY_GROUP_ID_GENERAL,
157 context.getString(R.string.notification_category _group_general)) 157 context.getString(R.string.notification_category _group_general))
158 .setSmallIcon(R.drawable.ic_image_white_24dp) 158 .setSmallIcon(R.drawable.ic_image_white_24dp)
159 .setContentTitle(getString(R.string.physical_web_broadca st_notification)) 159 .setContentTitle(getString(R.string.physical_web_broadca st_notification))
160 .setContentText(displayUrl) 160 .setContentText(displayUrl)
161 .setOngoing(true) 161 .setOngoing(true)
162 .addAction(android.R.drawable.ic_menu_close_clear_cancel , 162 .addAction(android.R.drawable.ic_menu_close_clear_cancel ,
163 getString(R.string.physical_web_stop_broadcast), stopPendingIntent); 163 getString(R.string.physical_web_stop_broadcast), stopPendingIntent);
164 notificationManager.notify( 164 notificationManager.notify(
165 NotificationConstants.NOTIFICATION_ID_PHYSICAL_WEB, notification Builder.build()); 165 NotificationConstants.NOTIFICATION_ID_PHYSICAL_WEB, notification Builder.build());
166 } 166 }
167 167
168 /** Turns off URL broadcasting. */ 168 /** Turns off URL broadcasting. */
169 private void disableUrlBroadcasting() { 169 private void disableUrlBroadcasting() {
170 NotificationManagerProxy notificationManager = new NotificationManagerPr oxyImpl( 170 NotificationManagerProxy notificationManager = new NotificationManagerPr oxyImpl(
171 (NotificationManager) getSystemService(NOTIFICATION_SERVICE)); 171 (NotificationManager) getSystemService(NOTIFICATION_SERVICE));
172 notificationManager.cancel(NotificationConstants.NOTIFICATION_ID_PHYSICA L_WEB); 172 notificationManager.cancel(NotificationConstants.NOTIFICATION_ID_PHYSICA L_WEB);
173 } 173 }
174 174
175 private native byte[] nativeEncodeUrl(String url); 175 private native byte[] nativeEncodeUrl(String url);
176 } 176 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698