Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/notifications/WebApkNotificationClient.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/notifications/WebApkNotificationClient.java b/chrome/android/java/src/org/chromium/chrome/browser/notifications/WebApkNotificationClient.java |
| index 7d34867a787b8048f9b15b0f7950fb8367c612a8..a272721443549b4e4b9d23b2b5f1b65db1aac0f0 100644 |
| --- a/chrome/android/java/src/org/chromium/chrome/browser/notifications/WebApkNotificationClient.java |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/notifications/WebApkNotificationClient.java |
| @@ -12,8 +12,8 @@ import android.os.Build; |
| import android.os.RemoteException; |
| import org.chromium.base.ContextUtils; |
| -import org.chromium.base.Log; |
| -import org.chromium.webapk.lib.client.WebApkServiceConnectionManager; |
| +import org.chromium.webapk.lib.client.WebApkIdentityServiceClient; |
| +import org.chromium.webapk.lib.client.WebApkServiceClient; |
| import org.chromium.webapk.lib.runtime_library.IWebApkApi; |
| /** |
| @@ -21,70 +21,48 @@ import org.chromium.webapk.lib.runtime_library.IWebApkApi; |
| * context of a WebAPK, enriching the notification with the WebAPK's small icon when available. |
| */ |
| public class WebApkNotificationClient { |
| - private static final String TAG = "cr_WebApk"; |
| - |
| - // Callback which catches RemoteExceptions thrown due to IWebApkApi failure. |
| - private abstract static class ApiUseCallback |
| - implements WebApkServiceConnectionManager.ConnectionCallback { |
| - public abstract void useApi(IWebApkApi api) throws RemoteException; |
| - |
| - @Override |
| - public void onConnected(IWebApkApi api) { |
| - try { |
| - useApi(api); |
| - } catch (RemoteException e) { |
| - Log.w(TAG, "WebApkAPI use failed.", e); |
| - } |
| - } |
| - } |
| - |
| /** |
| - * Connect to a WebAPK's bound service, build a notification and hand it over to the WebAPK to |
| + * Connects to a WebAPK's bound service, builds a notification and hand it over to the WebAPK to |
| * display. Handing over the notification makes the notification look like it originated from |
| * the WebAPK - not Chrome - in the Android UI. |
| */ |
| public static void notifyNotification(final String webApkPackage, |
| final NotificationBuilderBase notificationBuilder, final String platformTag, |
| final int platformID) { |
| - final ApiUseCallback connectionCallback = new ApiUseCallback() { |
| - @Override |
| - public void useApi(IWebApkApi api) throws RemoteException { |
| - int smallIconId = api.getSmallIconId(); |
| - // Prior to Android M, the small icon had to be from the resources of the app whose |
| - // NotificationManager is used in {@link NotificationManager#notify()}. On Android |
| - // M+, the small icon has to be from the resources of the app whose context is |
| - // passed to the {@link Notification.Builder()} constructor. |
| - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { |
| - // Android M+ introduced |
| - // {@link Notification.Builder#setSmallIcon(Bitmap icon)}. |
| - if (!notificationBuilder.hasSmallIconBitmap()) { |
| - notificationBuilder.setSmallIcon( |
| - decodeImageResource(webApkPackage, smallIconId)); |
| + final WebApkServiceClient.ApiUseCallback connectionCallback = |
| + new WebApkServiceClient.ApiUseCallback() { |
| + @Override |
| + public void useApi(IWebApkApi api) throws RemoteException { |
| + int smallIconId = api.getSmallIconId(); |
| + // Prior to Android M, the small icon had to be from the resources of the |
| + // app whose NotificationManager is used in |
| + // {@link NotificationManager#notify()}. On Android M+, the small icon has |
| + // to be from the resources of the app whose context is passed to the |
| + // {@link Notification.Builder()} constructor. |
| + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { |
| + // Android M+ introduced |
| + // {@link Notification.Builder#setSmallIcon(Bitmap icon)}. |
| + if (!notificationBuilder.hasSmallIconBitmap()) { |
| + notificationBuilder.setSmallIcon( |
| + decodeImageResource(webApkPackage, smallIconId)); |
| + } |
| + } else { |
| + notificationBuilder.setSmallIcon(smallIconId); |
| + } |
| + api.notifyNotification( |
| + platformTag, platformID, notificationBuilder.build()); |
| } |
| - } else { |
| - notificationBuilder.setSmallIcon(smallIconId); |
| - } |
| - api.notifyNotification(platformTag, platformID, notificationBuilder.build()); |
| - } |
| - }; |
| + }; |
| - WebApkServiceConnectionManager.getInstance().connect( |
| + WebApkServiceClient.notifyNotification( |
| ContextUtils.getApplicationContext(), webApkPackage, connectionCallback); |
| } |
| - /** |
| - * Cancel notification previously shown by WebAPK. |
| - */ |
| + /** Cancel notification previously shown by WebAPK. */ |
| public static void cancelNotification( |
| - String webApkPackage, final String platformTag, final int platformID) { |
| - final ApiUseCallback connectionCallback = new ApiUseCallback() { |
| - @Override |
| - public void useApi(IWebApkApi api) throws RemoteException { |
| - api.cancelNotification(platformTag, platformID); |
| - } |
| - }; |
| - WebApkServiceConnectionManager.getInstance().connect( |
| - ContextUtils.getApplicationContext(), webApkPackage, connectionCallback); |
| + String webApkPackage, WebApkIdentityServiceClient.CheckRuntimeHostCallback callback) { |
| + WebApkIdentityServiceClient.checkWebApkRuntimeHostAsync( |
|
Yaron
2017/07/14 19:52:04
Shouldn't this be cancelNotification?
Xi Han
2017/07/14 22:00:56
Thanks for catching it!
|
| + ContextUtils.getApplicationContext(), webApkPackage, callback); |
| } |
| /** Decodes bitmap from WebAPK's resources. */ |