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

[Android WebAPK] Finish hooking up new-style splash screen

This CL merges ProvidedByWebApkSplashDelegate and
SameActivityWebappSplashDelegate. As a benefit of the merging,
new-style WebAPKs get:
- offline error dialog
- splash screen hiding functionality

BUG=817263
R=dominickn
TBR=yfriedman (for renaming SameActivityWebappSplashDelegate->WebappSplashDelegate)

Change-Id: I930817d457c51b45156cecf06ce23a94432fa613
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1608728
Commit-Queue: Peter Kotwicz <pkotwicz@chromium.org>
Reviewed-by: default avatarDominick Ng <dominickn@chromium.org>
Cr-Commit-Position: refs/heads/master@{#663078}
parent 20a9e582
......@@ -865,6 +865,7 @@ chrome_java_sources = [
"java/src/org/chromium/chrome/browser/metrics/UmaSessionStats.java",
"java/src/org/chromium/chrome/browser/metrics/UmaUtils.java",
"java/src/org/chromium/chrome/browser/metrics/VariationsSession.java",
"java/src/org/chromium/chrome/browser/metrics/WebappSplashUmaCache.java",
"java/src/org/chromium/chrome/browser/metrics/WebApkSplashscreenMetrics.java",
"java/src/org/chromium/chrome/browser/metrics/WebApkUma.java",
"java/src/org/chromium/chrome/browser/modaldialog/AppModalPresenter.java",
......@@ -1662,9 +1663,7 @@ chrome_java_sources = [
"java/src/org/chromium/chrome/browser/webapps/ChromeWebApkHost.java",
"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/ProvidedByWebApkSplashDelegate.java",
"java/src/org/chromium/chrome/browser/webapps/SameActivityWebappSplashDelegate.java",
"java/src/org/chromium/chrome/browser/metrics/SameActivityWebappUmaCache.java",
"java/src/org/chromium/chrome/browser/webapps/WebappSplashDelegate.java",
"java/src/org/chromium/chrome/browser/webapps/SameTaskWebApkActivity.java",
"java/src/org/chromium/chrome/browser/webapps/SplashController.java",
"java/src/org/chromium/chrome/browser/webapps/SplashDelegate.java",
......
......@@ -13,10 +13,10 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
/**
* Used by SameActivityWebappSplashDelegate to cache webapp splash screen UMA values. Records UMA
* Used by {@link WebappSplashDelegate} to cache webapp splash screen UMA values. Records UMA
* when {@link #commitMetrics()} is called.
*/
public class SameActivityWebappUmaCache {
public class WebappSplashUmaCache {
// SplashColorStatus defined in tools/metrics/histograms/enums.xml.
// NUM_ENTRIES is intentionally included into @IntDef.
@IntDef({SplashColorStatus.DEFAULT, SplashColorStatus.CUSTOM, SplashColorStatus.NUM_ENTRIES})
......
// Copyright 2019 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.content.Context;
import android.graphics.Bitmap;
import android.net.Uri;
import android.view.View;
import android.widget.ImageView;
import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.ContextUtils;
import org.chromium.base.FileUtils;
import org.chromium.base.StrictModeContext;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.util.ColorUtils;
import org.chromium.webapk.lib.common.WebApkCommonUtils;
/** Delegate which uses splash screen screenshot from the WebAPK's content provider. */
public class ProvidedByWebApkSplashDelegate implements SplashDelegate {
private WebappInfo mWebappInfo;
public ProvidedByWebApkSplashDelegate(WebappInfo webappInfo) {
mWebappInfo = webappInfo;
}
@Override
public View buildSplashView() {
Context appContext = ContextUtils.getApplicationContext();
ImageView splashView = new ImageView(appContext);
int backgroundColor = ColorUtils.getOpaqueColor(
mWebappInfo.backgroundColor(ApiCompatibilityUtils.getColor(
appContext.getResources(), R.color.webapp_default_bg)));
splashView.setBackgroundColor(backgroundColor);
Bitmap splashBitmap = null;
try (StrictModeContext smc = StrictModeContext.allowDiskReads()) {
splashBitmap = FileUtils.queryBitmapFromContentProvider(appContext,
Uri.parse(WebApkCommonUtils.generateSplashContentProviderUri(
mWebappInfo.webApkPackageName())));
}
if (splashBitmap != null) {
splashView.setScaleType(ImageView.ScaleType.FIT_CENTER);
splashView.setImageBitmap(splashBitmap);
}
return splashView;
}
@Override
public void onSplashHidden(Tab tab, @SplashController.SplashHidesReason int reason,
long startTimestamp, long endTimestamp) {
// TODO(pkotwicz) implement.
}
@Override
public boolean shouldWaitForSubsequentPageLoadToHideSplash() {
return false;
}
}
......@@ -883,16 +883,10 @@ public class WebappActivity extends SingleTabActivity {
/** Inits the splash screen */
protected void initSplash() {
// Splash screen is shown after preInflationStartup() is run and the delegate is set.
if (mWebappInfo.isSplashProvidedByWebApk()) {
mSplashController.setConfig(new ProvidedByWebApkSplashDelegate(mWebappInfo),
true /* isWindowInitiallyTranslucent */, 0 /* splashHideAnimationDurationMs */);
} else {
mSplashController.setConfig(
new SameActivityWebappSplashDelegate(
this, getLifecycleDispatcher(), mTabObserverRegistrar, mWebappInfo),
false /* isWindowInitiallyTranslucent */,
SameActivityWebappSplashDelegate.HIDE_ANIMATION_DURATION_MS);
}
boolean isWindowInitiallyTranslucent = mWebappInfo.isSplashProvidedByWebApk();
mSplashController.setConfig(new WebappSplashDelegate(this, getLifecycleDispatcher(),
mTabObserverRegistrar, mWebappInfo),
isWindowInitiallyTranslucent, WebappSplashDelegate.HIDE_ANIMATION_DURATION_MS);
}
/** Sets the screen orientation. */
......
......@@ -19,7 +19,7 @@ import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.Feature;
import org.chromium.chrome.browser.ChromeSwitches;
import org.chromium.chrome.browser.ShortcutHelper;
import org.chromium.chrome.browser.metrics.SameActivityWebappUmaCache;
import org.chromium.chrome.browser.metrics.WebappSplashUmaCache;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
/**
......@@ -47,7 +47,7 @@ public class WebappSplashScreenBackgroundColorTest {
Assert.assertEquals(1,
RecordHistogram.getHistogramValueCountForTesting(
SameActivityWebappUmaCache.HISTOGRAM_SPLASHSCREEN_BACKGROUNDCOLOR,
SameActivityWebappUmaCache.SplashColorStatus.CUSTOM));
WebappSplashUmaCache.HISTOGRAM_SPLASHSCREEN_BACKGROUNDCOLOR,
WebappSplashUmaCache.SplashColorStatus.CUSTOM));
}
}
......@@ -22,7 +22,7 @@ import org.chromium.base.test.util.Feature;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.ChromeSwitches;
import org.chromium.chrome.browser.ShortcutHelper;
import org.chromium.chrome.browser.metrics.SameActivityWebappUmaCache;
import org.chromium.chrome.browser.metrics.WebappSplashUmaCache;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
/**
......@@ -61,14 +61,14 @@ public class WebappSplashScreenHomescreenIconTest {
public void testUmaFallbackIcon() {
Assert.assertEquals(1,
RecordHistogram.getHistogramValueCountForTesting(
SameActivityWebappUmaCache.HISTOGRAM_SPLASHSCREEN_ICON_TYPE,
SameActivityWebappUmaCache.SplashIconType.FALLBACK));
WebappSplashUmaCache.HISTOGRAM_SPLASHSCREEN_ICON_TYPE,
WebappSplashUmaCache.SplashIconType.FALLBACK));
Bitmap icon = ShortcutHelper.decodeBitmapFromString(WebappActivityTestRule.TEST_ICON);
int sizeInDp = Math.round((float) icon.getWidth()
/ mActivityTestRule.getActivity().getResources().getDisplayMetrics().density);
Assert.assertEquals(1,
RecordHistogram.getHistogramValueCountForTesting(
SameActivityWebappUmaCache.HISTOGRAM_SPLASHSCREEN_ICON_SIZE, sizeInDp));
WebappSplashUmaCache.HISTOGRAM_SPLASHSCREEN_ICON_SIZE, sizeInDp));
}
}
......@@ -22,7 +22,7 @@ import org.chromium.base.test.util.Feature;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.ChromeSwitches;
import org.chromium.chrome.browser.ShortcutHelper;
import org.chromium.chrome.browser.metrics.SameActivityWebappUmaCache;
import org.chromium.chrome.browser.metrics.WebappSplashUmaCache;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
/**
......@@ -64,8 +64,8 @@ public class WebappSplashScreenIconTest {
public void testUmaCustomIcon() {
Assert.assertEquals(1,
RecordHistogram.getHistogramValueCountForTesting(
SameActivityWebappUmaCache.HISTOGRAM_SPLASHSCREEN_ICON_TYPE,
SameActivityWebappUmaCache.SplashIconType.CUSTOM));
WebappSplashUmaCache.HISTOGRAM_SPLASHSCREEN_ICON_TYPE,
WebappSplashUmaCache.SplashIconType.CUSTOM));
Bitmap icon =
ShortcutHelper.decodeBitmapFromString(WebappActivityTestRule.TEST_SPLASH_ICON);
......@@ -73,6 +73,6 @@ public class WebappSplashScreenIconTest {
/ mActivityTestRule.getActivity().getResources().getDisplayMetrics().density);
Assert.assertEquals(1,
RecordHistogram.getHistogramValueCountForTesting(
SameActivityWebappUmaCache.HISTOGRAM_SPLASHSCREEN_ICON_SIZE, sizeInDp));
WebappSplashUmaCache.HISTOGRAM_SPLASHSCREEN_ICON_SIZE, sizeInDp));
}
}
......@@ -32,7 +32,7 @@ import org.chromium.base.test.util.Feature;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.ChromeSwitches;
import org.chromium.chrome.browser.ShortcutHelper;
import org.chromium.chrome.browser.metrics.SameActivityWebappUmaCache;
import org.chromium.chrome.browser.metrics.WebappSplashUmaCache;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.tab.TabTestUtils;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
......@@ -175,42 +175,39 @@ public class WebappSplashScreenTest {
// Tests UMA values.
Assert.assertEquals(1,
RecordHistogram.getHistogramValueCountForTesting(
SameActivityWebappUmaCache.HISTOGRAM_SPLASHSCREEN_BACKGROUNDCOLOR,
SameActivityWebappUmaCache.SplashColorStatus.DEFAULT));
WebappSplashUmaCache.HISTOGRAM_SPLASHSCREEN_BACKGROUNDCOLOR,
WebappSplashUmaCache.SplashColorStatus.DEFAULT));
Assert.assertEquals(1,
RecordHistogram.getHistogramValueCountForTesting(
SameActivityWebappUmaCache.HISTOGRAM_SPLASHSCREEN_THEMECOLOR,
SameActivityWebappUmaCache.SplashColorStatus.DEFAULT));
WebappSplashUmaCache.HISTOGRAM_SPLASHSCREEN_THEMECOLOR,
WebappSplashUmaCache.SplashColorStatus.DEFAULT));
Assert.assertEquals(1,
RecordHistogram.getHistogramValueCountForTesting(
SameActivityWebappUmaCache.HISTOGRAM_SPLASHSCREEN_ICON_TYPE,
SameActivityWebappUmaCache.SplashIconType.NONE));
WebappSplashUmaCache.HISTOGRAM_SPLASHSCREEN_ICON_TYPE,
WebappSplashUmaCache.SplashIconType.NONE));
// Tests UMA counts.
Assert.assertEquals(1,
getHistogramTotalCountFor(
SameActivityWebappUmaCache.HISTOGRAM_SPLASHSCREEN_BACKGROUNDCOLOR,
SameActivityWebappUmaCache.SplashColorStatus.NUM_ENTRIES));
WebappSplashUmaCache.HISTOGRAM_SPLASHSCREEN_BACKGROUNDCOLOR,
WebappSplashUmaCache.SplashColorStatus.NUM_ENTRIES));
Assert.assertEquals(1,
getHistogramTotalCountFor(
SameActivityWebappUmaCache.HISTOGRAM_SPLASHSCREEN_THEMECOLOR,
SameActivityWebappUmaCache.SplashColorStatus.NUM_ENTRIES));
getHistogramTotalCountFor(WebappSplashUmaCache.HISTOGRAM_SPLASHSCREEN_THEMECOLOR,
WebappSplashUmaCache.SplashColorStatus.NUM_ENTRIES));
Assert.assertEquals(1,
getHistogramTotalCountFor(
SameActivityWebappUmaCache.HISTOGRAM_SPLASHSCREEN_ICON_TYPE,
SameActivityWebappUmaCache.SplashIconType.NUM_ENTRIES));
getHistogramTotalCountFor(WebappSplashUmaCache.HISTOGRAM_SPLASHSCREEN_ICON_TYPE,
WebappSplashUmaCache.SplashIconType.NUM_ENTRIES));
// Given that there is no icon, the ICON_SIZE UMA should not be recorded.
Assert.assertEquals(0,
getHistogramTotalCountFor(
SameActivityWebappUmaCache.HISTOGRAM_SPLASHSCREEN_ICON_SIZE, 50));
WebappSplashUmaCache.HISTOGRAM_SPLASHSCREEN_ICON_SIZE, 50));
// DURATION and HIDES UMA should not have been recorded yet.
Assert.assertFalse(hasHistogramEntry(
SameActivityWebappSplashDelegate.HISTOGRAM_SPLASHSCREEN_DURATION, 3000));
Assert.assertFalse(
hasHistogramEntry(WebappSplashDelegate.HISTOGRAM_SPLASHSCREEN_DURATION, 3000));
Assert.assertEquals(0,
getHistogramTotalCountFor(
SameActivityWebappSplashDelegate.HISTOGRAM_SPLASHSCREEN_HIDES,
getHistogramTotalCountFor(WebappSplashDelegate.HISTOGRAM_SPLASHSCREEN_HIDES,
SplashController.SplashHidesReason.NUM_ENTRIES));
}
......@@ -226,29 +223,26 @@ public class WebappSplashScreenTest {
mActivityTestRule.waitUntilSplashscreenHides();
// DURATION and HIDES should now have a value.
Assert.assertTrue(hasHistogramEntry(
SameActivityWebappSplashDelegate.HISTOGRAM_SPLASHSCREEN_DURATION, 10000));
Assert.assertTrue(
hasHistogramEntry(WebappSplashDelegate.HISTOGRAM_SPLASHSCREEN_DURATION, 10000));
Assert.assertEquals(1,
getHistogramTotalCountFor(
SameActivityWebappSplashDelegate.HISTOGRAM_SPLASHSCREEN_HIDES,
getHistogramTotalCountFor(WebappSplashDelegate.HISTOGRAM_SPLASHSCREEN_HIDES,
SplashController.SplashHidesReason.NUM_ENTRIES));
// The other UMA records should not have changed.
Assert.assertEquals(1,
getHistogramTotalCountFor(
SameActivityWebappUmaCache.HISTOGRAM_SPLASHSCREEN_BACKGROUNDCOLOR,
SameActivityWebappUmaCache.SplashColorStatus.NUM_ENTRIES));
WebappSplashUmaCache.HISTOGRAM_SPLASHSCREEN_BACKGROUNDCOLOR,
WebappSplashUmaCache.SplashColorStatus.NUM_ENTRIES));
Assert.assertEquals(1,
getHistogramTotalCountFor(
SameActivityWebappUmaCache.HISTOGRAM_SPLASHSCREEN_THEMECOLOR,
SameActivityWebappUmaCache.SplashColorStatus.NUM_ENTRIES));
getHistogramTotalCountFor(WebappSplashUmaCache.HISTOGRAM_SPLASHSCREEN_THEMECOLOR,
WebappSplashUmaCache.SplashColorStatus.NUM_ENTRIES));
Assert.assertEquals(1,
getHistogramTotalCountFor(
SameActivityWebappUmaCache.HISTOGRAM_SPLASHSCREEN_ICON_TYPE,
SameActivityWebappUmaCache.SplashIconType.NUM_ENTRIES));
getHistogramTotalCountFor(WebappSplashUmaCache.HISTOGRAM_SPLASHSCREEN_ICON_TYPE,
WebappSplashUmaCache.SplashIconType.NUM_ENTRIES));
Assert.assertEquals(0,
getHistogramTotalCountFor(
SameActivityWebappUmaCache.HISTOGRAM_SPLASHSCREEN_ICON_SIZE, 50));
WebappSplashUmaCache.HISTOGRAM_SPLASHSCREEN_ICON_SIZE, 50));
}
@Test
......
......@@ -22,7 +22,7 @@ import org.chromium.base.test.util.DisabledTest;
import org.chromium.base.test.util.Feature;
import org.chromium.chrome.browser.ChromeSwitches;
import org.chromium.chrome.browser.ShortcutHelper;
import org.chromium.chrome.browser.metrics.SameActivityWebappUmaCache;
import org.chromium.chrome.browser.metrics.WebappSplashUmaCache;
import org.chromium.chrome.browser.tab.TabTestUtils;
import org.chromium.chrome.browser.util.ColorUtils;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
......@@ -99,7 +99,7 @@ public class WebappSplashScreenThemeColorTest {
public void testUmaThemeColorCustom() {
Assert.assertEquals(1,
RecordHistogram.getHistogramValueCountForTesting(
SameActivityWebappUmaCache.HISTOGRAM_SPLASHSCREEN_THEMECOLOR,
SameActivityWebappUmaCache.SplashColorStatus.CUSTOM));
WebappSplashUmaCache.HISTOGRAM_SPLASHSCREEN_THEMECOLOR,
WebappSplashUmaCache.SplashColorStatus.CUSTOM));
}
}
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