Commit 0d173351 authored by Michael van Ouwerkerk's avatar Michael van Ouwerkerk Committed by Chromium LUCI CQ

Check Android manifest metadata flag for site settings shortcut.

Bug: 1169122
Change-Id: If401cb17cf9b5443f9892eca45eb45d39ea46f24
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2642147Reviewed-by: default avatarGlenn Hartmann <hartmanng@chromium.org>
Commit-Queue: Michael van Ouwerkerk <mvanouwerkerk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#846170}
parent 2bbb13a2
...@@ -168,6 +168,7 @@ ...@@ -168,6 +168,7 @@
<meta-data android:name="org.chromium.webapk.shell_apk.webManifestUrl" android:value="{{{web_manifest_url}}}" /> <meta-data android:name="org.chromium.webapk.shell_apk.webManifestUrl" android:value="{{{web_manifest_url}}}" />
<meta-data android:name="org.chromium.webapk.shell_apk.isNewStyleWebApk" android:value="[[{use_new_splash}]]" /> <meta-data android:name="org.chromium.webapk.shell_apk.isNewStyleWebApk" android:value="[[{use_new_splash}]]" />
<meta-data android:name="org.chromium.webapk.shell_apk.enableSiteSettingsShortcut" android:value="{{{enable_site_settings_shortcut}}}" />
<service <service
android:name="org.chromium.webapk.shell_apk.WebApkServiceFactory" android:name="org.chromium.webapk.shell_apk.WebApkServiceFactory"
android:exported="true" android:exported="true"
......
...@@ -12,4 +12,4 @@ ...@@ -12,4 +12,4 @@
# //chrome/android/webapk/shell_apk:webapk is changed. This includes # //chrome/android/webapk/shell_apk:webapk is changed. This includes
# Java files, Android resource files and AndroidManifest.xml. Does not affect # Java files, Android resource files and AndroidManifest.xml. Does not affect
# Chrome.apk # Chrome.apk
current_shell_apk_version = 134 current_shell_apk_version = 135
...@@ -218,10 +218,8 @@ public final class LaunchTest { ...@@ -218,10 +218,8 @@ public final class LaunchTest {
*/ */
@Test @Test
public void testTargetShareActivityPreserved() { public void testTargetShareActivityPreserved() {
registerWebApk(true /* isNewStyleWebApk */);
Bundle metadata = new Bundle(); Bundle metadata = new Bundle();
metadata.putString(WebApkMetaDataKeys.START_URL, "https://pwa.rocks/"); metadata.putString(WebApkMetaDataKeys.START_URL, DEFAULT_START_URL);
Bundle[] shareMetadata = new Bundle[2]; Bundle[] shareMetadata = new Bundle[2];
for (int i = 0; i < shareMetadata.length; ++i) { for (int i = 0; i < shareMetadata.length; ++i) {
shareMetadata[i] = new Bundle(); shareMetadata[i] = new Bundle();
...@@ -494,8 +492,7 @@ public final class LaunchTest { ...@@ -494,8 +492,7 @@ public final class LaunchTest {
@Test @Test
@Config(sdk = Build.VERSION_CODES.N_MR1) @Config(sdk = Build.VERSION_CODES.N_MR1)
public void testAddsSiteSettings() { public void testAddsSiteSettings() {
registerWebApk(true /* isNewStyleWebApk */); registerApkForSiteSettings(true /*enableInMetadata*/, true /*addCategory*/);
registerSiteSettingsCategory();
Intent launchIntent = new Intent(Intent.ACTION_MAIN); Intent launchIntent = new Intent(Intent.ACTION_MAIN);
launchIntent.setPackage(sWebApkPackageName); launchIntent.setPackage(sWebApkPackageName);
...@@ -514,13 +511,30 @@ public final class LaunchTest { ...@@ -514,13 +511,30 @@ public final class LaunchTest {
} }
/** /**
* Tests that we remove the shortcut in the case that it was previously * Tests that no shortcut is added if the current version of Chrome does not support it.
* added but the current version of Chrome no longer supports it.
*/ */
@Test @Test
@Config(sdk = Build.VERSION_CODES.N_MR1) @Config(sdk = Build.VERSION_CODES.N_MR1)
public void testDoesNotAddSiteSettingsIfCategoryMissing() { public void testDoesNotAddSiteSettingsIfCategoryMissing() {
registerWebApk(true /* isNewStyleWebApk */); registerApkForSiteSettings(true /*enableInMetadata*/, false /*addCategory*/);
Intent launchIntent = new Intent(Intent.ACTION_MAIN);
launchIntent.setPackage(sWebApkPackageName);
launchAndCheckBrowserLaunched(false /* opaqueMainActivityInitiallyEnabled */, launchIntent,
H2OMainActivity.class, SITE_SETTINGS_COMPATIBLE_BROWSER_VERSION);
ShortcutManager shortcutManager = mAppContext.getSystemService(ShortcutManager.class);
assertFalse(containsSiteSettingsDynamicShortcut(shortcutManager));
}
/**
* Tests that no shortcut is added if the feature is disabled in the metadata of the WebAPK.
*/
@Test
@Config(sdk = Build.VERSION_CODES.N_MR1)
public void testDoesNotAddSiteSettingsIfDisabledInMetadata() {
registerApkForSiteSettings(false /*enableInMetadata*/, true /*addCategory*/);
Intent launchIntent = new Intent(Intent.ACTION_MAIN); Intent launchIntent = new Intent(Intent.ACTION_MAIN);
launchIntent.setPackage(sWebApkPackageName); launchIntent.setPackage(sWebApkPackageName);
...@@ -536,8 +550,7 @@ public final class LaunchTest { ...@@ -536,8 +550,7 @@ public final class LaunchTest {
@Test @Test
@Config(sdk = Build.VERSION_CODES.LOLLIPOP) @Config(sdk = Build.VERSION_CODES.LOLLIPOP)
public void testDoesNotAddSiteSettingsWhenSdkLow() { public void testDoesNotAddSiteSettingsWhenSdkLow() {
registerWebApk(true /* isNewStyleWebApk */); registerApkForSiteSettings(true /*enableInMetadata*/, true /*addCategory*/);
registerSiteSettingsCategory();
Intent launchIntent = new Intent(Intent.ACTION_MAIN); Intent launchIntent = new Intent(Intent.ACTION_MAIN);
launchIntent.setPackage(sWebApkPackageName); launchIntent.setPackage(sWebApkPackageName);
...@@ -545,7 +558,7 @@ public final class LaunchTest { ...@@ -545,7 +558,7 @@ public final class LaunchTest {
launchAndCheckBrowserLaunched(false /* opaqueMainActivityInitiallyEnabled */, launchIntent, launchAndCheckBrowserLaunched(false /* opaqueMainActivityInitiallyEnabled */, launchIntent,
H2OMainActivity.class, SITE_SETTINGS_COMPATIBLE_BROWSER_VERSION); H2OMainActivity.class, SITE_SETTINGS_COMPATIBLE_BROWSER_VERSION);
// There is no shortcut manager in Android M. Therefore if // There is no shortcut manager in Android L. Therefore if
// this test passes, then we did not attempt to add the shortcut. // this test passes, then we did not attempt to add the shortcut.
} }
...@@ -578,11 +591,18 @@ public final class LaunchTest { ...@@ -578,11 +591,18 @@ public final class LaunchTest {
private static void registerWebApk(boolean isNewStyleWebApk) { private static void registerWebApk(boolean isNewStyleWebApk) {
Bundle metadata = new Bundle(); Bundle metadata = new Bundle();
metadata.putBoolean(WebApkMetaDataKeys.IS_NEW_STYLE_WEBAPK, isNewStyleWebApk); metadata.putBoolean(WebApkMetaDataKeys.IS_NEW_STYLE_WEBAPK, isNewStyleWebApk);
metadata.putString(WebApkMetaDataKeys.START_URL, "https://pwa.rocks/"); metadata.putString(WebApkMetaDataKeys.START_URL, DEFAULT_START_URL);
WebApkTestHelper.registerWebApkWithMetaData(sWebApkPackageName, metadata, null); WebApkTestHelper.registerWebApkWithMetaData(sWebApkPackageName, metadata, null);
} }
private void registerSiteSettingsCategory() { private void registerApkForSiteSettings(boolean enableInMetadata, boolean addCategory) {
Bundle metadata = new Bundle();
metadata.putString(WebApkMetaDataKeys.START_URL, DEFAULT_START_URL);
metadata.putBoolean(WebApkMetaDataKeys.ENABLE_SITE_SETTINGS_SHORTCUT, enableInMetadata);
WebApkTestHelper.registerWebApkWithMetaData(sWebApkPackageName, metadata, null);
if (!addCategory) return;
Intent intent = Intent intent =
new Intent().setAction("android.support.customtabs.action.CustomTabsService"); new Intent().setAction("android.support.customtabs.action.CustomTabsService");
intent.setPackage(BROWSER_PACKAGE_NAME); intent.setPackage(BROWSER_PACKAGE_NAME);
......
...@@ -38,5 +38,6 @@ ...@@ -38,5 +38,6 @@
"mime_type": "image/*" "mime_type": "image/*"
}] }]
}], }],
"has_maskable_icon": true "has_maskable_icon": true,
"enable_site_settings_shortcut": true
} }
...@@ -26,6 +26,7 @@ import android.widget.FrameLayout; ...@@ -26,6 +26,7 @@ import android.widget.FrameLayout;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import android.widget.Toast; import android.widget.Toast;
import org.chromium.components.webapk.lib.common.WebApkMetaDataKeys;
import org.chromium.webapk.lib.common.WebApkConstants; import org.chromium.webapk.lib.common.WebApkConstants;
import java.util.Collections; import java.util.Collections;
...@@ -65,7 +66,7 @@ public class ManageDataLauncherActivity extends Activity { ...@@ -65,7 +66,7 @@ public class ManageDataLauncherActivity extends Activity {
mProviderPackage = getIntent().getStringExtra(EXTRA_PROVIDER_PACKAGE); mProviderPackage = getIntent().getStringExtra(EXTRA_PROVIDER_PACKAGE);
mUrl = Uri.parse(getIntent().getStringExtra(EXTRA_SITE_SETTINGS_URL)); mUrl = Uri.parse(getIntent().getStringExtra(EXTRA_SITE_SETTINGS_URL));
if (!supportsLaunchSettings(this, mProviderPackage)) { if (!siteSettingsShortcutEnabled(this, mProviderPackage)) {
handleNoSupportForLaunchSettings(); handleNoSupportForLaunchSettings();
return; return;
} }
...@@ -126,7 +127,13 @@ public class ManageDataLauncherActivity extends Activity { ...@@ -126,7 +127,13 @@ public class ManageDataLauncherActivity extends Activity {
} }
} }
private static boolean supportsLaunchSettings(Context context, String providerPackage) { private static boolean siteSettingsShortcutEnabled(Context context, String providerPackage) {
Bundle metadata = WebApkUtils.readMetaData(context);
if (metadata == null
|| !metadata.getBoolean(WebApkMetaDataKeys.ENABLE_SITE_SETTINGS_SHORTCUT)) {
return false;
}
Intent intent = new Intent(ACTION_CUSTOM_TABS_CONNECTION); Intent intent = new Intent(ACTION_CUSTOM_TABS_CONNECTION);
intent.addCategory(CATEGORY_LAUNCH_WEBAPK_SITE_SETTINGS); intent.addCategory(CATEGORY_LAUNCH_WEBAPK_SITE_SETTINGS);
intent.setPackage(providerPackage); intent.setPackage(providerPackage);
...@@ -177,7 +184,7 @@ public class ManageDataLauncherActivity extends Activity { ...@@ -177,7 +184,7 @@ public class ManageDataLauncherActivity extends Activity {
ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class); ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class);
// Remove potentially existing shortcut if package does not support shortcuts. // Remove potentially existing shortcut if package does not support shortcuts.
if (!supportsLaunchSettings(context, params.getHostBrowserPackageName())) { if (!siteSettingsShortcutEnabled(context, params.getHostBrowserPackageName())) {
shortcutManager.removeDynamicShortcuts(Collections.singletonList( shortcutManager.removeDynamicShortcuts(Collections.singletonList(
ManageDataLauncherActivity.SITE_SETTINGS_SHORTCUT_ID)); ManageDataLauncherActivity.SITE_SETTINGS_SHORTCUT_ID));
return; return;
......
...@@ -44,4 +44,6 @@ public final class WebApkMetaDataKeys { ...@@ -44,4 +44,6 @@ public final class WebApkMetaDataKeys {
public static final String SHARE_PARAM_NAMES = "org.chromium.webapk.shell_apk.shareParamNames"; public static final String SHARE_PARAM_NAMES = "org.chromium.webapk.shell_apk.shareParamNames";
public static final String SHARE_PARAM_ACCEPTS = public static final String SHARE_PARAM_ACCEPTS =
"org.chromium.webapk.shell_apk.shareParamAccepts"; "org.chromium.webapk.shell_apk.shareParamAccepts";
public static final String ENABLE_SITE_SETTINGS_SHORTCUT =
"org.chromium.webapk.shell_apk.enableSiteSettingsShortcut";
} }
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