Skip to content

Commit ad03ed3

Browse files
committed
refactor: type improvements
1 parent 38c04ca commit ad03ed3

File tree

2 files changed

+22
-20
lines changed

2 files changed

+22
-20
lines changed

androidbrowserhelper/src/main/java/com/google/androidbrowserhelper/trusted/LauncherActivity.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343

4444
import org.json.JSONException;
4545

46-
import java.util.Arrays;
4746
import java.util.Collections;
4847
import java.util.List;
4948
import java.util.Map;
@@ -232,10 +231,10 @@ protected void launchTwa() {
232231
.setScreenOrientation(mMetadata.screenOrientation)
233232
.setLaunchHandlerClientMode(mMetadata.launchHandlerClientMode);
234233

235-
Uri intentUrl = getUrlForIntent(getIntent());
236-
if (!launchUrl.equals(intentUrl)) {
234+
Uri intentUrl = getUrlForIntent(getIntent());
235+
if (!launchUrl.equals(intentUrl) && intentUrl != null) {
237236
twaBuilder.setOriginalLaunchUrl(intentUrl);
238-
}
237+
}
239238

240239
if (mMetadata.additionalTrustedOrigins != null) {
241240
twaBuilder.setAdditionalTrustedOrigins(mMetadata.additionalTrustedOrigins);
@@ -249,7 +248,10 @@ protected void launchTwa() {
249248
mTwaLauncher.launch(twaBuilder,
250249
getCustomTabsCallback(),
251250
mSplashScreenStrategy,
252-
() -> { mBrowserWasLaunched = true; finish();},
251+
() -> {
252+
mBrowserWasLaunched = true;
253+
finish();
254+
},
253255
getFallbackStrategy());
254256

255257
if (!sChromeVersionChecked) {
@@ -302,7 +304,7 @@ private void addShareDataIfPresent(TrustedWebActivityIntentBuilder twaBuilder) {
302304
ShareTarget shareTarget = SharingUtils.parseShareTargetJson(mMetadata.shareTarget);
303305
twaBuilder.setShareParams(shareTarget, shareData);
304306
} catch (JSONException e) {
305-
Log.d(TAG, "Failed to parse share target json: " + e.toString());
307+
Log.d(TAG, "Failed to parse share target json: " + e);
306308
}
307309
}
308310

@@ -314,7 +316,7 @@ private void addFileDataIfPresent(TrustedWebActivityIntentBuilder twaBuilder) {
314316
if (bundle == null) return;
315317
uris = FileHandlingData.fromBundle(bundle).uris;
316318
} else {
317-
uris = Arrays.asList(getIntent().getData());
319+
uris = Collections.singletonList(getIntent().getData());
318320
}
319321

320322
for (Uri uri : uris) {
@@ -378,7 +380,7 @@ protected void onDestroy() {
378380
}
379381

380382
@Override
381-
protected void onSaveInstanceState(Bundle outState) {
383+
protected void onSaveInstanceState(@NonNull Bundle outState) {
382384
super.onSaveInstanceState(outState);
383385
outState.putBoolean(BROWSER_WAS_LAUNCHED_KEY, mBrowserWasLaunched);
384386
}
@@ -451,7 +453,7 @@ protected Uri getLaunchingUrl() {
451453
Uri format = protocolHandlers.get(scheme);
452454
if (format != null) {
453455
String target = Uri.encode(intentUrl.toString());
454-
Uri targetUrl = Uri.parse(String.format(format.toString(), target));
456+
Uri targetUrl = Uri.parse(String.format(format.toString(), target));
455457
Log.d(TAG, "Using protocol handler url: " + targetUrl);
456458
return targetUrl;
457459
}

androidbrowserhelper/src/main/java/com/google/androidbrowserhelper/trusted/TwaLauncher.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
import android.app.Activity;
1919
import android.app.AlertDialog;
20-
import android.content.ActivityNotFoundException;
2120
import android.content.ComponentName;
2221
import android.content.Context;
2322
import android.content.Intent;
@@ -26,9 +25,9 @@
2625
import android.net.Uri;
2726
import android.util.Log;
2827

29-
import com.google.androidbrowserhelper.trusted.splashscreens.SplashScreenStrategy;
30-
28+
import androidx.annotation.NonNull;
3129
import androidx.annotation.Nullable;
30+
import androidx.annotation.VisibleForTesting;
3231
import androidx.browser.customtabs.CustomTabsCallback;
3332
import androidx.browser.customtabs.CustomTabsClient;
3433
import androidx.browser.customtabs.CustomTabsIntent;
@@ -40,11 +39,12 @@
4039
import androidx.browser.trusted.TokenStore;
4140
import androidx.browser.trusted.TrustedWebActivityIntent;
4241
import androidx.browser.trusted.TrustedWebActivityIntentBuilder;
43-
import com.google.androidbrowserhelper.R;
44-
import java.util.List;
4542

4643
import com.google.androidbrowserhelper.BuildConfig;
47-
import androidx.annotation.VisibleForTesting;
44+
import com.google.androidbrowserhelper.R;
45+
import com.google.androidbrowserhelper.trusted.splashscreens.SplashScreenStrategy;
46+
47+
import java.util.List;
4848

4949
/**
5050
* Encapsulates the steps necessary to launch a Trusted Web Activity, such as establishing a
@@ -135,7 +135,7 @@ public static void setDialogStrategyForTesting(BrowserUnavailableDialogStrategy
135135
@Nullable
136136
private CustomTabsSession mSession;
137137

138-
private TokenStore mTokenStore;
138+
private final TokenStore mTokenStore;
139139

140140
private boolean mDestroyed;
141141

@@ -248,7 +248,7 @@ public void launch(TrustedWebActivityIntentBuilder twaBuilder,
248248

249249
// Remember who we connect to as the package that is allowed to delegate notifications
250250
// to us.
251-
if (!ChromeOsSupport.isRunningOnArc(mContext.getPackageManager())) {
251+
if (!ChromeOsSupport.isRunningOnArc(mContext.getPackageManager()) && mProviderPackage != null) {
252252
// Since ChromeOS may not follow this path when launching a TWA, we set the verified
253253
// provider in DelegationService instead.
254254
mTokenStore.store(Token.create(mProviderPackage, mContext.getPackageManager()));
@@ -413,7 +413,7 @@ private static void showBrowserUnavailableDialog(Activity activity) {
413413
private class TwaCustomTabsServiceConnection extends CustomTabsServiceConnection {
414414
private Runnable mOnSessionCreatedRunnable;
415415
private Runnable mOnSessionCreationFailedRunnable;
416-
private CustomTabsCallback mCustomTabsCallback;
416+
private final CustomTabsCallback mCustomTabsCallback;
417417

418418
TwaCustomTabsServiceConnection(CustomTabsCallback callback) {
419419
mCustomTabsCallback = callback;
@@ -426,8 +426,8 @@ private void setSessionCreationRunnables(@Nullable Runnable onSuccess,
426426
}
427427

428428
@Override
429-
public void onCustomTabsServiceConnected(ComponentName componentName,
430-
CustomTabsClient client) {
429+
public void onCustomTabsServiceConnected(@NonNull ComponentName componentName,
430+
@NonNull CustomTabsClient client) {
431431
if (!ChromeLegacyUtils
432432
.supportsLaunchWithoutWarmup(mContext.getPackageManager(), mProviderPackage)) {
433433
client.warmup(0);

0 commit comments

Comments
 (0)