Avoid launching captive portal pages when uri is empty
- If uri is empty it will cause ActivityNotFoundException when calling startActivity Bug: 363782926 Flag: EXEMPT bugfix Test: Manual testing atest -c WifiDetailPreferenceController2Test Change-Id: I48b9a53afe08a7c5e8e512c1961d6aea22a12a21
This commit is contained in:
@@ -392,12 +392,7 @@ public class WifiDetailPreferenceController2 extends AbstractPreferenceControlle
|
|||||||
|
|
||||||
mButtonsPref.setButton2Text(R.string.wifi_venue_website_button_text)
|
mButtonsPref.setButton2Text(R.string.wifi_venue_website_button_text)
|
||||||
.setButton2Icon(R.drawable.ic_settings_sign_in)
|
.setButton2Icon(R.drawable.ic_settings_sign_in)
|
||||||
.setButton2OnClickListener(view -> {
|
.setButton2OnClickListener(view -> launchCaptivePortal(venueInfoUrl));
|
||||||
final Intent infoIntent = new Intent(Intent.ACTION_VIEW);
|
|
||||||
infoIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
||||||
infoIntent.setData(venueInfoUrl);
|
|
||||||
mContext.startActivity(infoIntent);
|
|
||||||
});
|
|
||||||
// Only show the venue website when the network is connected.
|
// Only show the venue website when the network is connected.
|
||||||
return mWifiEntry.getConnectedState() == WifiEntry.CONNECTED_STATE_CONNECTED;
|
return mWifiEntry.getConnectedState() == WifiEntry.CONNECTED_STATE_CONNECTED;
|
||||||
}
|
}
|
||||||
@@ -414,6 +409,18 @@ public class WifiDetailPreferenceController2 extends AbstractPreferenceControlle
|
|||||||
return data.getVenueInfoUrl();
|
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) {
|
private void setupEntityHeader(PreferenceScreen screen) {
|
||||||
LayoutPreference headerPref = screen.findPreference(KEY_HEADER);
|
LayoutPreference headerPref = screen.findPreference(KEY_HEADER);
|
||||||
|
|
||||||
|
@@ -137,6 +137,7 @@ public class WifiDetailPreferenceController2Test {
|
|||||||
private static final String FACTORY_MAC_ADDRESS = "FACTORY_MAC_ADDRESS";
|
private static final String FACTORY_MAC_ADDRESS = "FACTORY_MAC_ADDRESS";
|
||||||
private static final String SECURITY = "None";
|
private static final String SECURITY = "None";
|
||||||
private static final String FQDN = "fqdn";
|
private static final String FQDN = "fqdn";
|
||||||
|
private static final Uri TEST_URI = Uri.parse("content://test/test");
|
||||||
|
|
||||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||||
private PreferenceScreen mMockScreen;
|
private PreferenceScreen mMockScreen;
|
||||||
@@ -1876,6 +1877,24 @@ public class WifiDetailPreferenceController2Test {
|
|||||||
verify(mMockSignalStrengthPref).setTitle(R.string.hotspot_connection_strength);
|
verify(mMockSignalStrengthPref).setTitle(R.string.hotspot_connection_strength);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void launchCaptivePortal_uriNull_doNothing() {
|
||||||
|
setUpSpyController();
|
||||||
|
|
||||||
|
mController.launchCaptivePortal(null);
|
||||||
|
|
||||||
|
verify(mContext, never()).startActivity(any());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void launchCaptivePortal_uriNotNull_startActivity() {
|
||||||
|
setUpSpyController();
|
||||||
|
|
||||||
|
mController.launchCaptivePortal(TEST_URI);
|
||||||
|
|
||||||
|
verify(mContext).startActivity(any());
|
||||||
|
}
|
||||||
|
|
||||||
private SubscriptionInfo mockSubscriptionInfo(int subId, String displayName, int carrierId) {
|
private SubscriptionInfo mockSubscriptionInfo(int subId, String displayName, int carrierId) {
|
||||||
SubscriptionInfo info = mock(SubscriptionInfo.class);
|
SubscriptionInfo info = mock(SubscriptionInfo.class);
|
||||||
when(info.getSubscriptionId()).thenReturn(subId);
|
when(info.getSubscriptionId()).thenReturn(subId);
|
||||||
|
Reference in New Issue
Block a user