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

Unified Diff: webapk/libs/client/src/org/chromium/webapk/lib/client/NotificationClient.java

Issue 1965583002: Move //webapk to //chrome/android/webapk (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: webapk/libs/client/src/org/chromium/webapk/lib/client/NotificationClient.java
diff --git a/webapk/libs/client/src/org/chromium/webapk/lib/client/NotificationClient.java b/webapk/libs/client/src/org/chromium/webapk/lib/client/NotificationClient.java
deleted file mode 100644
index 3a180a46546909dbfbeb09f746ae7916e96d8810..0000000000000000000000000000000000000000
--- a/webapk/libs/client/src/org/chromium/webapk/lib/client/NotificationClient.java
+++ /dev/null
@@ -1,135 +0,0 @@
-// Copyright 2016 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-package org.chromium.webapk.lib.client;
-
-import android.app.PendingIntent;
-import android.content.ComponentName;
-import android.content.Context;
-import android.content.Intent;
-import android.content.ServiceConnection;
-import android.graphics.Bitmap;
-import android.os.IBinder;
-import android.os.RemoteException;
-import android.util.Log;
-
-import org.chromium.webapk.lib.runtime_library.IWebApkApi;
-
-/**
- * NotificationClient provides APIs that a WebAPK host can delegate display or close notification
- * tasks.
- */
-public class NotificationClient {
- private static final String CATEGORY_MINTED_API = "android.intent.category.MINTED_API";
- private static final String TAG = "cr_NotificationClient";
-
- private IWebApkApi mMintedApi;
-
- public NotificationClient() {}
-
- /**
- * Connect to a bind service of the WebAPK with the given package name, build a notification
- * and hand it over to the WebAPK to display.
- */
- public void displayNotification(Context context, final int pendingIntentRequestCode,
- final NotificationBuilderDelegate notificationBuilder,
- final Intent clickIntent, final Intent closeIntent, final Intent[] actionIntents,
- final String[] actionTitles, final Bitmap[] actionIcons, final int flags,
- final String platformTag, final int platformID, String packageNameOfMintedAPK) {
- Intent intent = createIntentToBindMintedAPI(packageNameOfMintedAPK);
- try {
- context.bindService(intent, new ServiceConnection() {
- @Override
- public void onServiceDisconnected(ComponentName name) {
- }
- @Override
- public void onServiceConnected(ComponentName name, IBinder service) {
- mMintedApi = IWebApkApi.Stub.asInterface(service);
- Log.d(TAG, "Got minted api: " + mMintedApi);
- try {
- // Create all the PendingIntents needed to build the notification.
- PendingIntent clickPendingIntent = mMintedApi.getBroadcastPendingIntent(
- pendingIntentRequestCode, clickIntent, flags);
- PendingIntent closePendingIntent = mMintedApi.getBroadcastPendingIntent(
- pendingIntentRequestCode, closeIntent, flags);
- PendingIntent[] actionPendingIntents = null;
- if (actionIntents != null) {
- actionPendingIntents = new PendingIntent[actionIntents.length];
- for (int actionIndex = 0; actionIndex < actionIntents.length;
- actionIndex++) {
- actionPendingIntents[actionIndex] =
- mMintedApi.getBroadcastPendingIntent(
- pendingIntentRequestCode,
- actionIntents[actionIndex], flags);
- }
- }
- notificationBuilder.setSmallIcon(mMintedApi.getSmallIconId());
- // Build a notification.
- buildNotification(notificationBuilder, clickPendingIntent,
- closePendingIntent, actionPendingIntents, actionTitles,
- actionIcons);
- // Dispaly the notification.
- mMintedApi.displayNotification(platformTag, platformID,
- notificationBuilder.build());
- } catch (RemoteException e) {
- Log.w(TAG, "MintedAPI use failed, exception: " + e);
- }
- }
- }, Context.BIND_AUTO_CREATE);
- } catch (SecurityException e) {
- Log.w(TAG, "Security failed binding.");
- }
- }
-
- /**
- * Connect to a bind service of a WebAPK with the given package name, and ask the it to close a
- * notification.
- */
- public void closeNotification(Context context, String packageNameOfMintedAPK,
- final String platformTag, final int platformID) {
- Intent intent = NotificationClient.createIntentToBindMintedAPI(packageNameOfMintedAPK);
- try {
- context.bindService(intent, new ServiceConnection() {
- @Override
- public void onServiceDisconnected(ComponentName name) {
- }
- @Override
- public void onServiceConnected(ComponentName name, IBinder service) {
- mMintedApi = IWebApkApi.Stub.asInterface(service);
- Log.d(TAG, "Got minted api: " + mMintedApi);
- try {
- mMintedApi.closeNotification(platformTag, platformID);
- } catch (RemoteException e) {
- Log.w(TAG, "MintedAPI use failed, exception: " + e);
- }
- }
- }, Context.BIND_AUTO_CREATE);
- } catch (SecurityException e) {
- Log.w(TAG, "Security failed binding.");
- }
- }
-
- private static Intent createIntentToBindMintedAPI(String packageNameOfMintedAPK) {
- Intent intent = new Intent();
- intent.addCategory(CATEGORY_MINTED_API);
- intent.setPackage(packageNameOfMintedAPK);
- return intent;
- }
-
- private static void buildNotification(final NotificationBuilderDelegate notificationBuilder,
- final PendingIntent clickPendingIntent, final PendingIntent closePendingIntent,
- final PendingIntent[] actionPendingIntents,
- final String[] actionTitles, final Bitmap[] actionIcons) {
- notificationBuilder.setContentIntent(clickPendingIntent)
- .setDeleteIntent(closePendingIntent);
- if (actionPendingIntents != null) {
- for (int actionIndex = 0; actionIndex < actionPendingIntents.length;
- actionIndex++) {
- notificationBuilder.addAction(actionIcons[actionIndex],
- actionTitles[actionIndex],
- actionPendingIntents[actionIndex]);
- }
- }
- }
-}

Powered by Google App Engine
This is Rietveld 408576698