| Index: chrome/android/java/src/org/chromium/chrome/browser/webapps/WebApkDisclosureNotificationManager.java
|
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/webapps/WebApkDisclosureNotificationManager.java b/chrome/android/java/src/org/chromium/chrome/browser/webapps/WebApkDisclosureNotificationManager.java
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..13b8b7aef808e6473633ecbad1e4dfb099c19529
|
| --- /dev/null
|
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/webapps/WebApkDisclosureNotificationManager.java
|
| @@ -0,0 +1,64 @@
|
| +// Copyright 2017 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.chrome.browser.webapps;
|
| +
|
| +import android.app.Notification;
|
| +import android.content.Context;
|
| +import android.graphics.BitmapFactory;
|
| +
|
| +import org.chromium.base.ContextUtils;
|
| +import org.chromium.chrome.R;
|
| +import org.chromium.chrome.browser.notifications.NotificationUmaTracker;
|
| +import org.chromium.chrome.browser.notifications.StandardNotificationBuilder;
|
| +import org.chromium.chrome.browser.notifications.WebApkNotificationClient;
|
| +import org.chromium.chrome.browser.notifications.channels.ChannelDefinitions;
|
| +
|
| +import java.util.Random;
|
| +
|
| +/**
|
| + * Manages the notification indicating that a WebApk is backed by chrome code and may share data.
|
| + */
|
| +public class WebApkDisclosureNotificationManager {
|
| + private static final String WEBAPK_OPEN_TAG = "webapk_notification";
|
| +
|
| + /**
|
| + * Shows the privacy disclosure informing the user that Chrome is being used.
|
| + * @param webappInfo Web App this is currently displayed fullscreen.
|
| + * @return identifier used to display the notification
|
| + */
|
| + public static int showDisclosure(WebappInfo webappInfo) {
|
| + Context context = ContextUtils.getApplicationContext();
|
| + String title = webappInfo.shortName();
|
| +
|
| + StandardNotificationBuilder builder =
|
| + new StandardNotificationBuilder(context, ChannelDefinitions.CHANNEL_ID_BROWSER);
|
| + builder.setTitle(title)
|
| + .setPriority(Notification.PRIORITY_MIN)
|
| + .setLargeIcon(BitmapFactory.decodeResource(
|
| + context.getResources(), R.drawable.ic_launcher))
|
| + .setDeleteIntent(WebApkDisclosureNotificationService.getDeleteIntent(
|
| + context, webappInfo.id()))
|
| + .setBody(context.getResources().getString(
|
| + R.string.webapk_running_in_chrome_disclosure, title));
|
| +
|
| + int id = (new Random()).nextInt();
|
| + WebApkNotificationClient.notifyNotification(
|
| + webappInfo.webApkPackageName(), builder, WEBAPK_OPEN_TAG, id);
|
| + // Even though the Notification is shown via the WebApk, we still want to record UMA.
|
| + NotificationUmaTracker.getInstance().onNotificationShown(
|
| + NotificationUmaTracker.WEBAPK, ChannelDefinitions.CHANNEL_ID_BROWSER);
|
| + return id;
|
| + }
|
| +
|
| + /**
|
| + * Dismisses the notification.
|
| + * @param webappInfo Web App this is currently displayed fullscreen.
|
| + * @param id The identifier for the tag to dismiss.
|
| + */
|
| + public static void dismissNotification(WebappInfo webappInfo, int id) {
|
| + WebApkNotificationClient.cancelNotification(
|
| + webappInfo.webApkPackageName(), WEBAPK_OPEN_TAG, id);
|
| + }
|
| +}
|
|
|