Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@

import org.json.JSONException;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -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);
Expand All @@ -249,7 +248,10 @@ protected void launchTwa() {
mTwaLauncher.launch(twaBuilder,
getCustomTabsCallback(),
mSplashScreenStrategy,
() -> { mBrowserWasLaunched = true; finish();},
() -> {
mBrowserWasLaunched = true;
finish();
},
getFallbackStrategy());

if (!sChromeVersionChecked) {
Expand Down Expand Up @@ -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);
}
}

Expand All @@ -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) {
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -96,7 +96,7 @@ public class TwaLauncher {
@Nullable
private CustomTabsSession mSession;

private TokenStore mTokenStore;
private final TokenStore mTokenStore;

private boolean mDestroyed;

Expand Down Expand Up @@ -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()));
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down