Commit 4df7199f authored by hanxi's avatar hanxi Committed by Commit bot

Hide Chrome actions in notifications shown for WebAPKs

This CL hides the "Site setting" action when notifications are shown by WebAPKs.
The "additional settings in the app" link will be removed from the notification
settings for WebAPKs in the System UI in Android O. Before Android O, the
settings gear to open app-specific settings shown on the rear of a notification
following a long-press will be gone as well.

BUG=654539

Review-Url: https://codereview.chromium.org/2826223002
Cr-Commit-Position: refs/heads/master@{#467843}
parent 5dad32e3
......@@ -232,6 +232,12 @@ public class CustomNotificationBuilder extends NotificationBuilderBase {
private void configureSettingsButton(RemoteViews bigView) {
if (mSettingsAction == null) {
bigView.setViewVisibility(R.id.origin_settings_icon, View.GONE);
int rightPadding =
dpToPx(BUTTON_ICON_PADDING_DP, mContext.getResources().getDisplayMetrics());
int leftPadding =
Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP ? rightPadding : 0;
bigView.setViewPadding(R.id.origin, leftPadding, 0, rightPadding, 0);
return;
}
bigView.setOnClickPendingIntent(R.id.origin, mSettingsAction.intent);
......
......@@ -504,16 +504,6 @@ public class NotificationPlatformBridge {
NotificationSystemStatusUtil.determineAppNotificationStatus(context),
NotificationSystemStatusUtil.APP_NOTIFICATIONS_STATUS_BOUNDARY);
// Set up a pending intent for going to the settings screen for |origin|.
Intent settingsIntent = PreferencesLauncher.createIntentForSettingsPage(
context, SingleWebsitePreferences.class.getName());
settingsIntent.setData(makeIntentData(notificationId, origin, -1 /* actionIndex */));
settingsIntent.putExtra(Preferences.EXTRA_SHOW_FRAGMENT_ARGUMENTS,
SingleWebsitePreferences.createFragmentArgsForSite(origin));
PendingIntent pendingSettingsIntent = PendingIntent.getActivity(context,
PENDING_INTENT_REQUEST_CODE, settingsIntent, PendingIntent.FLAG_UPDATE_CURRENT);
PendingIntent clickIntent = makePendingIntent(context,
NotificationConstants.ACTION_CLICK_NOTIFICATION, notificationId, origin, profileId,
incognito, tag, webApkPackage, -1 /* actionIndex */);
......@@ -555,19 +545,6 @@ public class NotificationPlatformBridge {
}
}
// If action buttons are displayed, there isn't room for the full Site Settings button
// label and icon, so abbreviate it. This has the unfortunate side-effect of unnecessarily
// abbreviating it on Android Wear also (crbug.com/576656). If custom layouts are enabled,
// the label and icon provided here only affect Android Wear, so don't abbreviate them.
boolean abbreviateSiteSettings = actions.length > 0 && !useCustomLayouts(hasImage);
int settingsIconId = abbreviateSiteSettings ? 0 : R.drawable.settings_cog;
CharSequence settingsTitle = abbreviateSiteSettings
? res.getString(R.string.notification_site_settings_button)
: res.getString(R.string.page_info_site_settings_button);
// If the settings button is displayed together with the other buttons it has to be the last
// one, so add it after the other actions.
notificationBuilder.addSettingsAction(settingsIconId, settingsTitle, pendingSettingsIntent);
// The Android framework applies a fallback vibration pattern for the sound when the device
// is in vibrate mode, there is no custom pattern, and the vibration default has been
// disabled. To truly prevent vibration, provide a custom empty pattern.
......@@ -581,6 +558,31 @@ public class NotificationPlatformBridge {
String platformTag = makePlatformTag(notificationId, origin, tag);
if (webApkPackage.isEmpty()) {
// Set up a pending intent for going to the settings screen for |origin|.
Intent settingsIntent = PreferencesLauncher.createIntentForSettingsPage(
context, SingleWebsitePreferences.class.getName());
settingsIntent.setData(makeIntentData(notificationId, origin, -1 /* actionIndex */));
settingsIntent.putExtra(Preferences.EXTRA_SHOW_FRAGMENT_ARGUMENTS,
SingleWebsitePreferences.createFragmentArgsForSite(origin));
PendingIntent pendingSettingsIntent = PendingIntent.getActivity(context,
PENDING_INTENT_REQUEST_CODE, settingsIntent, PendingIntent.FLAG_UPDATE_CURRENT);
// If action buttons are displayed, there isn't room for the full Site Settings button
// label and icon, so abbreviate it. This has the unfortunate side-effect of
// unnecessarily abbreviating it on Android Wear also (crbug.com/576656). If custom
// layouts are enabled, the label and icon provided here only affect Android Wear, so
// don't abbreviate them.
boolean abbreviateSiteSettings = actions.length > 0 && !useCustomLayouts(hasImage);
int settingsIconId = abbreviateSiteSettings ? 0 : R.drawable.settings_cog;
CharSequence settingsTitle = abbreviateSiteSettings
? res.getString(R.string.notification_site_settings_button)
: res.getString(R.string.page_info_site_settings_button);
// If the settings button is displayed together with the other buttons it has to be the
// last one, so add it after the other actions.
notificationBuilder.addSettingsAction(
settingsIconId, settingsTitle, pendingSettingsIntent);
mNotificationManager.notify(platformTag, PLATFORM_ID, notificationBuilder.build());
NotificationUmaTracker.getInstance().onNotificationShown(
NotificationUmaTracker.SITES, ChannelDefinitions.CHANNEL_ID_SITES);
......
......@@ -31,12 +31,6 @@
<data android:scheme="{{{scope_url_scheme}}}" android:host="{{{scope_url_host}}}" android:pathPrefix="{{{scope_url_path}}}"></data>
</intent-filter>
</activity>
<activity android:name="org.chromium.webapk.shell_apk.NotificationSettingsLauncherActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.NOTIFICATION_PREFERENCES"/>
</intent-filter>
</activity>
<meta-data android:name="org.chromium.webapk.shell_apk.shellApkVersion" android:value="{{{shell_apk_version}}}" />
<meta-data android:name="org.chromium.webapk.shell_apk.runtimeHost" android:value="{{{runtime_host}}}" />
<meta-data android:name="org.chromium.webapk.shell_apk.startUrl" android:value="{{{start_url}}}" />
......
......@@ -112,7 +112,6 @@ android_library("webapk_java") {
"src/org/chromium/webapk/shell_apk/DexLoader.java",
"src/org/chromium/webapk/shell_apk/HostBrowserClassLoader.java",
"src/org/chromium/webapk/shell_apk/MainActivity.java",
"src/org/chromium/webapk/shell_apk/NotificationSettingsLauncherActivity.java",
"src/org/chromium/webapk/shell_apk/WebApkSandboxedProcessService.java",
"src/org/chromium/webapk/shell_apk/WebApkSandboxedProcessService0.java",
"src/org/chromium/webapk/shell_apk/WebApkSandboxedProcessService1.java",
......
......@@ -6,7 +6,7 @@
# (including AndroidManifest.xml) is updated. This version should be incremented
# prior to uploading a new ShellAPK to the WebAPK Minting Server.
# Does not affect Chrome.apk
template_shell_apk_version = 3
template_shell_apk_version = 4
# The ShellAPK version expected by Chrome. Chrome will try to update the WebAPK
# if the WebAPK's ShellAPK version is less than |expected_shell_apk_version|.
......
// 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.shell_apk;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
/**
* Forwards NOTIFICATION_PREFERENCES intent to host browser.
*/
public class NotificationSettingsLauncherActivity extends Activity {
@Override
public void onCreate(Bundle savedInstance) {
super.onCreate(savedInstance);
String hostPackage = WebApkUtils.getHostBrowserPackageName(this);
Intent intent = getIntent();
intent.setPackage(hostPackage);
intent.setComponent(null);
startActivity(intent);
finish();
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment