Merge "Avoid launching captive portal pages when uri is empty" into main

This commit is contained in:
Treehugger Robot
2024-09-16 10:40:36 +00:00
committed by Android (Google) Code Review
2 changed files with 32 additions and 6 deletions

View File

@@ -392,12 +392,7 @@ public class WifiDetailPreferenceController2 extends AbstractPreferenceControlle
mButtonsPref.setButton2Text(R.string.wifi_venue_website_button_text)
.setButton2Icon(R.drawable.ic_settings_sign_in)
.setButton2OnClickListener(view -> {
final Intent infoIntent = new Intent(Intent.ACTION_VIEW);
infoIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
infoIntent.setData(venueInfoUrl);
mContext.startActivity(infoIntent);
});
.setButton2OnClickListener(view -> launchCaptivePortal(venueInfoUrl));
// Only show the venue website when the network is connected.
return mWifiEntry.getConnectedState() == WifiEntry.CONNECTED_STATE_CONNECTED;
}
@@ -414,6 +409,18 @@ public class WifiDetailPreferenceController2 extends AbstractPreferenceControlle
return data.getVenueInfoUrl();
}
@VisibleForTesting
void launchCaptivePortal(Uri uri) {
if (uri == null) {
Log.e(TAG, "Launch captive portal with a null Uri!");
return;
}
final Intent infoIntent = new Intent(Intent.ACTION_VIEW);
infoIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
infoIntent.setData(uri);
mContext.startActivity(infoIntent);
}
private void setupEntityHeader(PreferenceScreen screen) {
LayoutPreference headerPref = screen.findPreference(KEY_HEADER);