Commit b8cc1e37 authored by Peter Kotwicz's avatar Peter Kotwicz Committed by Commit Bot

[Android WebAPK] Launch WebAPK with splash screen in single activity stack

This CL:
- Changes NewSplashWebApk.apk to launch the host browser in the same task as
the ShellAPK.
- Introduces TransparentSplashWebApkActivity. TransparentSplashWebApkActivity
  is identical to WebApkActivity except that it does not set
  android:documentLaunchMode.

BUG=1253206

Change-Id: I827769b7fd8ccab762863a400873c20d34068300
Reviewed-on: https://chromium-review.googlesource.com/c/1263878
Commit-Queue: Peter Kotwicz <pkotwicz@chromium.org>
Reviewed-by: default avatarPeter Conn <peconn@chromium.org>
Reviewed-by: default avatarXi Han <hanxi@chromium.org>
Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#602180}
parent c43580bf
......@@ -688,6 +688,18 @@ by a child template that "extends" this file.
</activity-alias>
{% endfor %}
<!-- Activities for WebAPKs. -->
<activity android:name="org.chromium.chrome.browser.webapps.TransparentSplashWebApkActivity"
android:theme="@style/WebappTheme"
android:label="@string/webapp_activity_title"
android:launchMode="singleTop"
android:exported="false"
android:persistableMode="persistNever"
{{ self.supports_video_persistence() }}
{{ self.chrome_activity_common() }}
>
{{ self.supports_vr() }}
{{ self.extra_web_rendering_activity_definitions() }}
</activity>
<activity android:name="org.chromium.chrome.browser.webapps.WebApkActivity"
android:theme="@style/WebappTheme"
android:label="@string/webapp_activity_title"
......
......@@ -732,8 +732,9 @@ public class ShortcutHelper {
if (WebApkValidator.isValidWebApk(context, packageInfo.packageName)) {
// Pass non-null URL parameter so that {@link WebApkInfo#create()}
// return value is non-null
WebApkInfo webApkInfo = WebApkInfo.create(packageInfo.packageName, "",
ShortcutSource.UNKNOWN, false /* forceNavigation */);
WebApkInfo webApkInfo =
WebApkInfo.create(packageInfo.packageName, "", ShortcutSource.UNKNOWN,
false /* forceNavigation */, false /* useTransparentSplash */);
if (webApkInfo != null) {
names.add(webApkInfo.name());
shortNames.add(webApkInfo.shortName());
......
......@@ -16,13 +16,13 @@ import android.support.annotation.Nullable;
import android.support.customtabs.trusted.TrustedWebActivityServiceConnectionManager;
import android.support.customtabs.trusted.TrustedWebActivityServiceWrapper;
import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.ContextUtils;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.ChromeFeatureList;
import org.chromium.chrome.browser.UrlConstants;
import org.chromium.chrome.browser.notifications.NotificationBuilderBase;
import org.chromium.chrome.browser.notifications.NotificationUmaTracker;
import org.chromium.chrome.browser.webapps.WebappLauncherActivity;
import java.util.List;
import java.util.Set;
......@@ -161,7 +161,9 @@ public class TrustedWebActivityClient {
Intent intent = new Intent();
intent.setData(Uri.parse(url));
intent.setAction(Intent.ACTION_VIEW);
intent.setFlags(WebappLauncherActivity.getWebappActivityIntentFlags());
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| ApiCompatibilityUtils.getActivityNewDocumentFlag()
| Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.setComponent(new ComponentName(twaPackageName, twaActivityName));
return intent;
}
......
......@@ -17,6 +17,7 @@ import android.os.TransactionTooLargeException;
import android.support.annotation.Nullable;
import android.support.v4.app.BundleCompat;
import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.Log;
import org.chromium.base.VisibleForTesting;
......@@ -380,6 +381,13 @@ public class IntentUtils {
}
}
/** Returns whether the intent starts an activity in a new task or a new document. */
public static boolean isIntentForNewTaskOrNewDocument(Intent intent) {
int testFlags =
Intent.FLAG_ACTIVITY_NEW_TASK | ApiCompatibilityUtils.getActivityNewDocumentFlag();
return (intent.getFlags() & testFlags) != 0;
}
/**
* Returns how large the Intent will be in Parcel form, which is helpful for gauging whether
* Android will deliver the Intent instead of throwing a TransactionTooLargeException.
......
// Copyright 2018 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;
/**
* WebApkActivity variant to use when ShellAPK displays a splash screen.
* TransparentSplashWebApkActivity is fully transparent while the page is
* loading, enabling the ShellAPK's splash screen to show from underneath the
* WebApkActivity. Once the page is loaded, the activity becomes opaque hiding
* the splash screen underneath.
*/
public class TransparentSplashWebApkActivity extends WebApkActivity {}
......@@ -65,6 +65,7 @@ public class WebApkInfo extends WebappInfo {
// A serialized string of the Share Target details (if any) for the WebAPK.
private String mSerializedShareTarget;
private Map<String, String> mIconUrlToMurmur2HashMap;
private boolean mUseTransparentSplash;
public static WebApkInfo createEmpty() {
return new WebApkInfo();
......@@ -98,7 +99,11 @@ public class WebApkInfo extends WebappInfo {
boolean forceNavigation = IntentUtils.safeGetBooleanExtra(
intent, ShortcutHelper.EXTRA_FORCE_NAVIGATION, true);
return create(webApkPackageName, url, source, forceNavigation);
boolean useTransparentSplash = !IntentUtils.isIntentForNewTaskOrNewDocument(intent)
&& IntentUtils.safeGetBooleanExtra(
intent, WebApkConstants.EXTRA_USE_TRANSPARENT_SPLASH, false);
return create(webApkPackageName, url, source, forceNavigation, useTransparentSplash);
}
private static @WebApkDistributor int getDistributor(Bundle bundle, String packageName) {
......@@ -125,10 +130,12 @@ public class WebApkInfo extends WebappInfo {
* @param url Url that the WebAPK should navigate to when launched.
* @param source Source that the WebAPK was launched from.
* @param forceNavigation Whether the WebAPK should navigate to {@link url} if it is already
* running.
* running.
* @param useTransparentSplash Whether the WebApkActivity should be fully transparent while the
* page is loading.
*/
public static WebApkInfo create(
String webApkPackageName, String url, int source, boolean forceNavigation) {
public static WebApkInfo create(String webApkPackageName, String url, int source,
boolean forceNavigation, boolean useTransparentSplash) {
// Unlike non-WebAPK web apps, WebAPK ids are predictable. A malicious actor may send an
// intent with a valid start URL and arbitrary other data. Only use the start URL, the
// package name and the ShortcutSource from the launch intent and extract the remaining data
......@@ -194,7 +201,8 @@ public class WebApkInfo extends WebappInfo {
new Icon(primaryIcon), new Icon(badgeIcon), new Icon(splashIcon), name, shortName,
displayMode, orientation, source, themeColor, backgroundColor, webApkPackageName,
shellApkVersion, manifestUrl, manifestStartUrl, distributor,
iconUrlToMurmur2HashMap, serializedShareTarget, forceNavigation);
iconUrlToMurmur2HashMap, serializedShareTarget, forceNavigation,
useTransparentSplash);
}
/**
......@@ -226,6 +234,8 @@ public class WebApkInfo extends WebappInfo {
* the WebAPK.
* @param forceNavigation Whether the WebAPK should navigate to {@link url} if the
* WebAPK is already open.
* @param useTransparentSplash Whether the WebApkActivity should be fully transparent while
* the page is loading.
*/
public static WebApkInfo create(String id, String url, String scope, Icon primaryIcon,
Icon badgeIcon, Icon splashIcon, String name, String shortName,
......@@ -233,7 +243,7 @@ public class WebApkInfo extends WebappInfo {
long backgroundColor, String webApkPackageName, int shellApkVersion, String manifestUrl,
String manifestStartUrl, @WebApkDistributor int distributor,
Map<String, String> iconUrlToMurmur2HashMap, String serializedShareTarget,
boolean forceNavigation) {
boolean forceNavigation, boolean useTransparentSplash) {
if (id == null || url == null || manifestStartUrl == null || webApkPackageName == null) {
Log.e(TAG,
"Incomplete data provided: " + id + ", " + url + ", " + manifestStartUrl + ", "
......@@ -251,7 +261,8 @@ public class WebApkInfo extends WebappInfo {
return new WebApkInfo(id, url, scope, primaryIcon, badgeIcon, splashIcon, name, shortName,
displayMode, orientation, source, themeColor, backgroundColor, webApkPackageName,
shellApkVersion, manifestUrl, manifestStartUrl, distributor,
iconUrlToMurmur2HashMap, serializedShareTarget, forceNavigation);
iconUrlToMurmur2HashMap, serializedShareTarget, forceNavigation,
useTransparentSplash);
}
protected WebApkInfo(String id, String url, String scope, Icon primaryIcon, Icon badgeIcon,
......@@ -260,7 +271,7 @@ public class WebApkInfo extends WebappInfo {
String webApkPackageName, int shellApkVersion, String manifestUrl,
String manifestStartUrl, @WebApkDistributor int distributor,
Map<String, String> iconUrlToMurmur2HashMap, String serializedShareTarget,
boolean forceNavigation) {
boolean forceNavigation, boolean useTransparentSplash) {
super(id, url, scope, primaryIcon, name, shortName, displayMode, orientation, source,
themeColor, backgroundColor, null /* splash_screen_url */,
false /* isIconGenerated */, forceNavigation);
......@@ -273,6 +284,7 @@ public class WebApkInfo extends WebappInfo {
mDistributor = distributor;
mIconUrlToMurmur2HashMap = iconUrlToMurmur2HashMap;
mSerializedShareTarget = serializedShareTarget;
mUseTransparentSplash = useTransparentSplash;
}
protected WebApkInfo() {}
......@@ -303,6 +315,11 @@ public class WebApkInfo extends WebappInfo {
return mApkPackageName;
}
@Override
public boolean useTransparentSplash() {
return mUseTransparentSplash;
}
public int shellApkVersion() {
return mShellApkVersion;
}
......
......@@ -120,7 +120,8 @@ public class WebApkUpdateDataFetcher extends EmptyTabObserver {
name, shortName, displayMode, orientation, mOldInfo.source(), themeColor,
backgroundColor, mOldInfo.apkPackageName(), mOldInfo.shellApkVersion(),
mOldInfo.manifestUrl(), manifestStartUrl, WebApkInfo.WebApkDistributor.BROWSER,
iconUrlToMurmur2HashMap, serializedShareTarget, mOldInfo.shouldForceNavigation());
iconUrlToMurmur2HashMap, serializedShareTarget, mOldInfo.shouldForceNavigation(),
mOldInfo.useTransparentSplash());
mObserver.onGotManifestData(info, primaryIconUrl, badgeIconUrl);
}
......
......@@ -13,6 +13,7 @@ import android.content.Context;
import android.content.Intent;
import android.support.v4.app.NotificationCompat;
import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.metrics.RecordUserAction;
import org.chromium.blink_public.platform.WebDisplayMode;
import org.chromium.chrome.R;
......@@ -67,7 +68,9 @@ class WebappActionsNotificationManager {
}
private Notification createNotification() {
int intentFlags = WebappLauncherActivity.getWebappActivityIntentFlags();
int intentFlags = Intent.FLAG_ACTIVITY_NEW_TASK
| ApiCompatibilityUtils.getActivityNewDocumentFlag()
| Intent.FLAG_ACTIVITY_CLEAR_TOP;
int pendingIntentFlags = PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT;
PendingIntent focusIntent = PendingIntent.getActivity(mWebappActivity, 0,
......
......@@ -363,6 +363,11 @@ public class WebappInfo {
return mIsIconGenerated;
}
/** Returns whether the WebappActivity should be transparent while the page is loading. */
public boolean useTransparentSplash() {
return false;
}
/**
* Sets extras on an Intent that will launch a WebappActivity.
* @param intent Intent that will be used to launch a WebappActivity.
......
......@@ -51,11 +51,23 @@ public class WebappLauncherActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mCreateTime = SystemClock.elapsedRealtime();
launchActivity();
ApiCompatibilityUtils.finishAndRemoveTask(this);
Intent launchIntent = createLaunchIntent();
if (launchIntent == null) {
ApiCompatibilityUtils.finishAndRemoveTask(this);
return;
}
IntentUtils.safeStartActivity(this, launchIntent);
if (IntentUtils.isIntentForNewTaskOrNewDocument(launchIntent)) {
ApiCompatibilityUtils.finishAndRemoveTask(this);
} else {
finish();
}
}
public void launchActivity() {
public Intent createLaunchIntent() {
Intent intent = getIntent();
ChromeWebApkHost.init();
......@@ -72,8 +84,7 @@ public class WebappLauncherActivity extends Activity {
// does not specify required values such as the uri.
if (webappInfo == null) {
String url = IntentUtils.safeGetStringExtra(intent, ShortcutHelper.EXTRA_URL);
launchInTab(url, ShortcutSource.UNKNOWN);
return;
return createLaunchInTabIntent(url, ShortcutSource.UNKNOWN);
}
String webappUrl = webappInfo.uri().toString();
......@@ -108,15 +119,14 @@ public class WebappLauncherActivity extends Activity {
long shellLaunchTimestamp =
IntentHandler.getWebApkShellLaunchTimestampFromIntent(intent);
IntentHandler.addShellLaunchTimestampToIntent(launchIntent, shellLaunchTimestamp);
startActivity(launchIntent);
return;
return launchIntent;
}
Log.e(TAG, "Shortcut (%s) opened in Chrome.", webappUrl);
// The shortcut data doesn't match the current encoding. Change the intent action to
// launch the URL with a VIEW Intent in the regular browser.
launchInTab(webappUrl, webappSource);
return createLaunchInTabIntent(webappUrl, webappSource);
}
// Gets the source of a WebAPK from the WebappDataStorage if the source has been stored before.
......@@ -140,8 +150,8 @@ public class WebappLauncherActivity extends Activity {
return ShortcutSource.WEBAPK_UNKNOWN;
}
private void launchInTab(String webappUrl, int webappSource) {
if (TextUtils.isEmpty(webappUrl)) return;
private Intent createLaunchInTabIntent(String webappUrl, int webappSource) {
if (TextUtils.isEmpty(webappUrl)) return null;
Intent launchIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(webappUrl));
launchIntent.setClassName(getPackageName(), ChromeLauncherActivity.class.getName());
......@@ -149,7 +159,7 @@ public class WebappLauncherActivity extends Activity {
launchIntent.putExtra(ShortcutHelper.EXTRA_SOURCE, webappSource);
launchIntent.setFlags(
Intent.FLAG_ACTIVITY_NEW_TASK | ApiCompatibilityUtils.getActivityNewDocumentFlag());
startActivity(launchIntent);
return launchIntent;
}
/**
......@@ -180,6 +190,7 @@ public class WebappLauncherActivity extends Activity {
public static Intent createWebappLaunchIntent(WebappInfo info, boolean isWebApk) {
String activityName = isWebApk ? WebApkActivity.class.getName()
: WebappActivity.class.getName();
boolean newTask = true;
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
// Specifically assign the app to a particular WebappActivity instance.
int namespace = isWebApk ? ActivityAssigner.ActivityAssignerNamespace.WEBAPK_NAMESPACE
......@@ -201,6 +212,11 @@ public class WebappLauncherActivity extends Activity {
}
break;
}
} else {
if (isWebApk && info.useTransparentSplash()) {
activityName = TransparentSplashWebApkActivity.class.getName();
newTask = false;
}
}
// Create an intent to launch the Webapp in an unmapped WebappActivity.
......@@ -212,14 +228,7 @@ public class WebappLauncherActivity extends Activity {
// Activity.
launchIntent.setAction(Intent.ACTION_VIEW);
launchIntent.setData(Uri.parse(WebappActivity.WEBAPP_SCHEME + "://" + info.id()));
launchIntent.setFlags(getWebappActivityIntentFlags());
return launchIntent;
}
/**
* Returns the set of Intent flags required to correctly launch a WebappActivity.
*/
public static int getWebappActivityIntentFlags() {
// Setting FLAG_ACTIVITY_CLEAR_TOP handles 2 edge cases:
// - If a legacy PWA is launching from a notification, we want to ensure that the URL being
// launched is the URL in the intent. If a paused WebappActivity exists for this id,
......@@ -235,9 +244,16 @@ public class WebappLauncherActivity extends Activity {
// an Intent to an existing top Activity (such as sent from the Webapp Actions Notification)
// will trigger a new WebappActivity to be launched and onCreate called instead of
// onNewIntent of the existing WebappActivity being called.
return Intent.FLAG_ACTIVITY_NEW_TASK
| ApiCompatibilityUtils.getActivityNewDocumentFlag()
| Intent.FLAG_ACTIVITY_CLEAR_TOP;
// TODO(pkotwicz): Route Webapp Actions Notification actions through new intent filter
// instead of WebappLauncherActivity. http://crbug.com/894610
if (newTask) {
launchIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| ApiCompatibilityUtils.getActivityNewDocumentFlag()
| Intent.FLAG_ACTIVITY_CLEAR_TOP);
} else {
launchIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
}
return launchIntent;
}
/**
......
......@@ -1589,6 +1589,7 @@ chrome_java_sources = [
"java/src/org/chromium/chrome/browser/webapps/ChromeWebApkHostSignature.java",
"java/src/org/chromium/chrome/browser/webapps/GooglePlayWebApkInstallDelegate.java",
"java/src/org/chromium/chrome/browser/webapps/SplashscreenObserver.java",
"java/src/org/chromium/chrome/browser/webapps/TransparentSplashWebApkActivity.java",
"java/src/org/chromium/chrome/browser/webapps/WebApkActivity.java",
"java/src/org/chromium/chrome/browser/webapps/WebApkActivity0.java",
"java/src/org/chromium/chrome/browser/webapps/WebApkActivity1.java",
......
......@@ -106,7 +106,7 @@ public class WebApkUpdateDataFetcherTest {
WebApkInfo oldInfo = WebApkInfo.create("", "", scopeUrl, null, null, null, null,
null, -1, -1, -1, -1, -1, "random.package", -1, manifestUrl, "",
WebApkInfo.WebApkDistributor.BROWSER, new HashMap<String, String>(), null,
false /* forceNavigation */);
false /* forceNavigation */, false /* useTransparentSplash */);
fetcher.start(mTab, oldInfo, observer);
}
});
......
......@@ -160,7 +160,7 @@ public class WebApkUpdateManagerTest {
WebApkVersion.REQUEST_UPDATE_FOR_SHELL_APK_VERSION,
creationData.manifestUrl, creationData.startUrl,
WebApkInfo.WebApkDistributor.BROWSER, creationData.iconUrlToMurmur2HashMap,
null, false /* forceNavigation */);
null, false /* forceNavigation */, false /* useTransparentSplash */);
updateManager.updateIfNeeded(mTab, info);
}
});
......
......@@ -135,6 +135,6 @@ public class WebappVisibilityTest {
: WebApkInfo.create("", "", webappStartUrlOrScopeUrl, null, null, null, null, null,
displayMode, 0, 0, 0, 0, "", 0, null, "",
WebApkInfo.WebApkDistributor.BROWSER, null, null,
false /* forceNavigation */);
false /* forceNavigation */, false /* useTransparentSplash */);
}
}
......@@ -121,6 +121,7 @@ public class WebApkInfoTest {
intent.putExtra(ShortcutHelper.EXTRA_FORCE_NAVIGATION, true);
intent.putExtra(ShortcutHelper.EXTRA_URL, START_URL);
intent.putExtra(ShortcutHelper.EXTRA_SOURCE, ShortcutSource.NOTIFICATION);
intent.putExtra(WebApkConstants.EXTRA_USE_TRANSPARENT_SPLASH, true);
WebApkInfo info = WebApkInfo.create(intent);
......@@ -147,6 +148,7 @@ public class WebApkInfoTest {
Assert.assertEquals(ICON_MURMUR2_HASH, info.iconUrlToMurmur2HashMap().get(ICON_URL));
Assert.assertEquals(SOURCE, info.source());
Assert.assertTrue(info.useTransparentSplash());
Assert.assertEquals(null, info.icon());
Assert.assertEquals(null, info.badgeIcon());
......
......@@ -257,7 +257,8 @@ public class WebApkUpdateManagerUnitTest {
manifestData.shortName, manifestData.displayMode, manifestData.orientation, -1,
manifestData.themeColor, manifestData.backgroundColor, kPackageName, -1,
WEB_MANIFEST_URL, manifestData.startUrl, WebApkInfo.WebApkDistributor.BROWSER,
manifestData.iconUrlToMurmur2HashMap, null, false /* forceNavigation */);
manifestData.iconUrlToMurmur2HashMap, null, false /* forceNavigation */,
false /* useTransparentSplash */);
}
/**
......
......@@ -27,6 +27,11 @@ public final class WebApkConstants {
// Activity launch time for uma tracking of Chrome web apk startup
public static final String EXTRA_WEBAPK_LAUNCH_TIME =
"org.chromium.chrome.browser.webapk_launch_time";
// Whether the host browser's activity should be completely transparent till the page
// has loaded. This enables the ShellAPK's splash screen to show through the host browser's
// activity.
public static final String EXTRA_USE_TRANSPARENT_SPLASH =
"org.chromium.chrome.browser.webapk.transparent_splash";
// Must be kept in sync with chrome/browser/android/shortcut_info.h.
public static final int SHORTCUT_SOURCE_UNKNOWN = 0;
......
......@@ -12,4 +12,4 @@
# //chrome/android/webapk/shell_apk:webapk is changed. This includes
# Java files, Android resource files and AndroidManifest.xml. Does not affect
# Chrome.apk
current_shell_apk_version = 66
current_shell_apk_version = 67
......@@ -41,15 +41,27 @@ public class HostBrowserLauncher {
return;
}
Intent launchIntent = createLaunchInWebApkModeIntent(context, params);
try {
context.startActivity(launchIntent);
} catch (ActivityNotFoundException e) {
Log.w(TAG, "Unable to launch browser in WebAPK mode.");
e.printStackTrace();
}
}
/** Creates intent to launch host browser in WebAPK mode. */
public static Intent createLaunchInWebApkModeIntent(
Context context, HostBrowserLauncherParams params) {
Intent intent = new Intent();
intent.setAction(ACTION_START_WEBAPK);
intent.setPackage(params.getHostBrowserPackageName());
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Bundle copiedExtras = params.getOriginalIntent().getExtras();
if (copiedExtras != null) {
intent.putExtras(copiedExtras);
}
intent.putExtra(WebApkConstants.EXTRA_URL, params.getStartUrl())
.putExtra(WebApkConstants.EXTRA_SOURCE, params.getSource())
.putExtra(WebApkConstants.EXTRA_WEBAPK_PACKAGE_NAME, context.getPackageName())
......@@ -62,13 +74,7 @@ public class HostBrowserLauncher {
if (!params.wasDialogShown()) {
intent.putExtra(WebApkConstants.EXTRA_WEBAPK_LAUNCH_TIME, params.getLaunchTimeMs());
}
try {
context.startActivity(intent);
} catch (ActivityNotFoundException e) {
Log.w(TAG, "Unable to launch browser in WebAPK mode.");
e.printStackTrace();
}
return intent;
}
/** Launches a WebAPK in its runtime host browser as a tab. */
......
......@@ -4,11 +4,17 @@
package org.chromium.webapk.shell_apk.h2o;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Build;
import android.util.Log;
import org.chromium.webapk.lib.common.WebApkConstants;
import org.chromium.webapk.shell_apk.HostBrowserLauncher;
import org.chromium.webapk.shell_apk.HostBrowserLauncherParams;
/** Contains methods for launching host browser where ShellAPK shows the splash screen. */
......@@ -16,6 +22,8 @@ public class H2OLauncher {
// Lowest version of Chromium which supports ShellAPK showing the splash screen.
private static final int MINIMUM_REQUIRED_CHROMIUM_VERSION_NEW_SPLASH = Integer.MAX_VALUE;
private static final String TAG = "cr_H2OLauncher";
/**
* Returns whether the main intent should launch SplashActivity.class for the given host browser
* params.
......@@ -42,4 +50,24 @@ public class H2OLauncher {
pm.setComponentEnabledSetting(
disableComponent, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, 0);
}
/** Launches the host browser in WebAPK-transparent-splashscreen mode. */
public static void launch(Activity splashActivity, HostBrowserLauncherParams params) {
Log.v(TAG, "WebAPK Launch URL: " + params.getStartUrl());
Intent intent = HostBrowserLauncher.createLaunchInWebApkModeIntent(
splashActivity.getApplicationContext(), params);
intent.putExtra(WebApkConstants.EXTRA_USE_TRANSPARENT_SPLASH, true);
// Clear Intent.FLAG_ACTIVITY_NEW_TASK flag set by
// {@link HostBrowserLauncher#createLaunchInWebApkModeIntent()}.
intent.setFlags(0);
try {
splashActivity.startActivity(intent);
} catch (ActivityNotFoundException e) {
Log.w(TAG, "Unable to launch browser in WebAPK mode.");
e.printStackTrace();
}
}
}
......@@ -55,14 +55,14 @@ public class SplashActivity extends HostBrowserLauncherActivity {
Context appContext = getApplicationContext();
// TODO(pkotwicz): Pass parameter to tell Chrome not to show splash screen.
HostBrowserLauncher.launch(appContext, params);
if (!H2OLauncher.shouldMainIntentLaunchSplashActivity(params)) {
HostBrowserLauncher.launch(appContext, params);
H2OLauncher.changeEnabledComponentsAndKillShellApk(appContext,
new ComponentName(appContext, H2OMainActivity.class), getComponentName());
finish();
return;
}
H2OLauncher.launch(this, params);
}
}
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