diff --git a/androidbrowserhelper/src/main/java/com/google/androidbrowserhelper/trusted/LauncherActivity.java b/androidbrowserhelper/src/main/java/com/google/androidbrowserhelper/trusted/LauncherActivity.java index e379fba5..1b71aa19 100644 --- a/androidbrowserhelper/src/main/java/com/google/androidbrowserhelper/trusted/LauncherActivity.java +++ b/androidbrowserhelper/src/main/java/com/google/androidbrowserhelper/trusted/LauncherActivity.java @@ -43,7 +43,6 @@ import org.json.JSONException; -import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Map; @@ -232,10 +231,10 @@ protected void launchTwa() { .setScreenOrientation(mMetadata.screenOrientation) .setLaunchHandlerClientMode(mMetadata.launchHandlerClientMode); - Uri intentUrl = getUrlForIntent(getIntent()); - if (!launchUrl.equals(intentUrl)) { + Uri intentUrl = getUrlForIntent(getIntent()); + if (!launchUrl.equals(intentUrl) && intentUrl != null) { twaBuilder.setOriginalLaunchUrl(intentUrl); - } + } if (mMetadata.additionalTrustedOrigins != null) { twaBuilder.setAdditionalTrustedOrigins(mMetadata.additionalTrustedOrigins); @@ -249,7 +248,10 @@ protected void launchTwa() { mTwaLauncher.launch(twaBuilder, getCustomTabsCallback(), mSplashScreenStrategy, - () -> { mBrowserWasLaunched = true; finish();}, + () -> { + mBrowserWasLaunched = true; + finish(); + }, getFallbackStrategy()); if (!sChromeVersionChecked) { @@ -302,7 +304,7 @@ private void addShareDataIfPresent(TrustedWebActivityIntentBuilder twaBuilder) { ShareTarget shareTarget = SharingUtils.parseShareTargetJson(mMetadata.shareTarget); twaBuilder.setShareParams(shareTarget, shareData); } catch (JSONException e) { - Log.d(TAG, "Failed to parse share target json: " + e.toString()); + Log.d(TAG, "Failed to parse share target json: " + e); } } @@ -314,7 +316,7 @@ private void addFileDataIfPresent(TrustedWebActivityIntentBuilder twaBuilder) { if (bundle == null) return; uris = FileHandlingData.fromBundle(bundle).uris; } else { - uris = Arrays.asList(getIntent().getData()); + uris = Collections.singletonList(getIntent().getData()); } for (Uri uri : uris) { @@ -378,7 +380,7 @@ protected void onDestroy() { } @Override - protected void onSaveInstanceState(Bundle outState) { + protected void onSaveInstanceState(@NonNull Bundle outState) { super.onSaveInstanceState(outState); outState.putBoolean(BROWSER_WAS_LAUNCHED_KEY, mBrowserWasLaunched); } @@ -451,7 +453,7 @@ protected Uri getLaunchingUrl() { Uri format = protocolHandlers.get(scheme); if (format != null) { String target = Uri.encode(intentUrl.toString()); - Uri targetUrl = Uri.parse(String.format(format.toString(), target)); + Uri targetUrl = Uri.parse(String.format(format.toString(), target)); Log.d(TAG, "Using protocol handler url: " + targetUrl); return targetUrl; } diff --git a/androidbrowserhelper/src/main/java/com/google/androidbrowserhelper/trusted/TwaLauncher.java b/androidbrowserhelper/src/main/java/com/google/androidbrowserhelper/trusted/TwaLauncher.java index 7635d9b3..c376261a 100644 --- a/androidbrowserhelper/src/main/java/com/google/androidbrowserhelper/trusted/TwaLauncher.java +++ b/androidbrowserhelper/src/main/java/com/google/androidbrowserhelper/trusted/TwaLauncher.java @@ -20,8 +20,7 @@ import android.net.Uri; import android.util.Log; -import com.google.androidbrowserhelper.trusted.splashscreens.SplashScreenStrategy; - +import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.browser.customtabs.CustomTabsCallback; import androidx.browser.customtabs.CustomTabsClient; @@ -36,6 +35,7 @@ import androidx.browser.trusted.TrustedWebActivityIntentBuilder; import com.google.androidbrowserhelper.BuildConfig; +import com.google.androidbrowserhelper.trusted.splashscreens.SplashScreenStrategy; /** * Encapsulates the steps necessary to launch a Trusted Web Activity, such as establishing a @@ -96,7 +96,7 @@ public class TwaLauncher { @Nullable private CustomTabsSession mSession; - private TokenStore mTokenStore; + private final TokenStore mTokenStore; private boolean mDestroyed; @@ -209,7 +209,7 @@ public void launch(TrustedWebActivityIntentBuilder twaBuilder, // Remember who we connect to as the package that is allowed to delegate notifications // to us. - if (!ChromeOsSupport.isRunningOnArc(mContext.getPackageManager())) { + if (!ChromeOsSupport.isRunningOnArc(mContext.getPackageManager()) && mProviderPackage != null) { // Since ChromeOS may not follow this path when launching a TWA, we set the verified // provider in DelegationService instead. mTokenStore.store(Token.create(mProviderPackage, mContext.getPackageManager())); @@ -341,7 +341,7 @@ public void setStartupUptimeMillis(long startupUptimeMillis) { private class TwaCustomTabsServiceConnection extends CustomTabsServiceConnection { private Runnable mOnSessionCreatedRunnable; private Runnable mOnSessionCreationFailedRunnable; - private CustomTabsCallback mCustomTabsCallback; + private final CustomTabsCallback mCustomTabsCallback; TwaCustomTabsServiceConnection(CustomTabsCallback callback) { mCustomTabsCallback = callback; @@ -354,8 +354,8 @@ private void setSessionCreationRunnables(@Nullable Runnable onSuccess, } @Override - public void onCustomTabsServiceConnected(ComponentName componentName, - CustomTabsClient client) { + public void onCustomTabsServiceConnected(@NonNull ComponentName componentName, + @NonNull CustomTabsClient client) { if (!ChromeLegacyUtils .supportsLaunchWithoutWarmup(mContext.getPackageManager(), mProviderPackage)) { client.warmup(0);