Merge "[Wi-Fi] Add API to handle help button click event" into rvc-dev

This commit is contained in:
Goven Liu
2020-03-20 04:54:46 +00:00
committed by Android (Google) Code Review
3 changed files with 53 additions and 6 deletions

View File

@@ -7196,6 +7196,9 @@
<string name="help_url_double_tap_screen" translatable="false"></string> <string name="help_url_double_tap_screen" translatable="false"></string>
<string name="help_url_account_detail" translatable="false"></string> <string name="help_url_account_detail" translatable="false"></string>
<string name="help_url_icc_lock" translatable="false"></string> <string name="help_url_icc_lock" translatable="false"></string>
<!-- Help URI, ManageSubscription [DO NOT TRANSLATE] -->
<string name="help_url_manage_wifi_subscription" translatable="false"></string>
<string name="help_uri_process_stats_summary" translatable="false"></string> <string name="help_uri_process_stats_summary" translatable="false"></string>
<string name="help_uri_process_stats_apps" translatable="false"></string> <string name="help_uri_process_stats_apps" translatable="false"></string>
<string name="help_uri_private_dns" translatable="false"></string> <string name="help_uri_private_dns" translatable="false"></string>

View File

@@ -22,6 +22,7 @@ import static android.os.UserManager.DISALLOW_CONFIG_WIFI;
import android.app.Activity; import android.app.Activity;
import android.app.Dialog; import android.app.Dialog;
import android.app.settings.SettingsEnums; import android.app.settings.SettingsEnums;
import android.content.ActivityNotFoundException;
import android.content.ContentResolver; import android.content.ContentResolver;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
@@ -69,6 +70,7 @@ import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.widget.SwitchBarController; import com.android.settings.widget.SwitchBarController;
import com.android.settings.wifi.details2.WifiNetworkDetailsFragment2; import com.android.settings.wifi.details2.WifiNetworkDetailsFragment2;
import com.android.settings.wifi.dpp.WifiDppUtils; import com.android.settings.wifi.dpp.WifiDppUtils;
import com.android.settingslib.HelpUtils;
import com.android.settingslib.RestrictedLockUtils; import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.RestrictedLockUtilsInternal; import com.android.settingslib.RestrictedLockUtilsInternal;
import com.android.settingslib.search.Indexable; import com.android.settingslib.search.Indexable;
@@ -109,6 +111,7 @@ public class WifiSettings2 extends RestrictedSettingsFragment
@VisibleForTesting @VisibleForTesting
static final int ADD_NETWORK_REQUEST = 2; static final int ADD_NETWORK_REQUEST = 2;
static final int CONFIG_NETWORK_REQUEST = 3; static final int CONFIG_NETWORK_REQUEST = 3;
static final int MANAGE_SUBSCRIPTION = 4;
private static final String PREF_KEY_EMPTY_WIFI_LIST = "wifi_empty_list"; private static final String PREF_KEY_EMPTY_WIFI_LIST = "wifi_empty_list";
// TODO(b/70983952): Rename these to use WifiEntry instead of AccessPoint. // TODO(b/70983952): Rename these to use WifiEntry instead of AccessPoint.
@@ -428,6 +431,9 @@ public class WifiSettings2 extends RestrictedSettingsFragment
} }
} }
return; return;
} else if (requestCode == MANAGE_SUBSCRIPTION) {
//Do nothing
return;
} }
final boolean formerlyRestricted = mIsRestricted; final boolean formerlyRestricted = mIsRestricted;
@@ -750,6 +756,12 @@ public class WifiSettings2 extends RestrictedSettingsFragment
pref.setKey(wifiEntry.getKey()); pref.setKey(wifiEntry.getKey());
pref.setOrder(index++); pref.setOrder(index++);
pref.refresh(); pref.refresh();
if (wifiEntry.canManageSubscription()) {
pref.setOnButtonClickListener(preference -> {
openSubscriptionHelpPage();
});
}
mWifiEntryPreferenceCategory.addPreference(pref); mWifiEntryPreferenceCategory.addPreference(pref);
} }
removeCachedPrefs(mWifiEntryPreferenceCategory); removeCachedPrefs(mWifiEntryPreferenceCategory);
@@ -1061,4 +1073,24 @@ public class WifiSettings2 extends RestrictedSettingsFragment
int reason = networkStatus.getNetworkSelectionDisableReason(); int reason = networkStatus.getNetworkSelectionDisableReason();
return WifiConfiguration.NetworkSelectionStatus.DISABLED_BY_WRONG_PASSWORD == reason; return WifiConfiguration.NetworkSelectionStatus.DISABLED_BY_WRONG_PASSWORD == reason;
} }
@VisibleForTesting
void openSubscriptionHelpPage() {
final Intent intent = getHelpIntent(getContext());
if (intent != null) {
try {
startActivityForResult(intent, MANAGE_SUBSCRIPTION);
} catch (ActivityNotFoundException e) {
Log.e(TAG, "Activity was not found for intent, " + intent.toString());
}
}
}
@VisibleForTesting
Intent getHelpIntent(Context context) {
return HelpUtils.getHelpIntent(
context,
context.getString(R.string.help_url_manage_wifi_subscription),
context.getClass().getName());
}
} }

View File

@@ -25,6 +25,7 @@ import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy; import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
@@ -98,13 +99,14 @@ public class WifiSettings2Test {
@Test @Test
public void addNetworkFragmentSendResult_onActivityResult_shouldHandleEvent() { public void addNetworkFragmentSendResult_onActivityResult_shouldHandleEvent() {
final WifiSettings wifiSettings = spy(new WifiSettings()); final WifiSettings2 wifiSettings2 = spy(new WifiSettings2());
final Intent intent = new Intent(); final Intent intent = new Intent();
doNothing().when(wifiSettings).handleAddNetworkRequest(anyInt(), any(Intent.class)); doNothing().when(wifiSettings2).handleAddNetworkRequest(anyInt(), any(Intent.class));
wifiSettings.onActivityResult(WifiSettings.ADD_NETWORK_REQUEST, Activity.RESULT_OK, intent); wifiSettings2.onActivityResult(WifiSettings2.ADD_NETWORK_REQUEST, Activity.RESULT_OK,
intent);
verify(wifiSettings).handleAddNetworkRequest(anyInt(), any(Intent.class)); verify(wifiSettings2).handleAddNetworkRequest(anyInt(), any(Intent.class));
} }
@Test @Test
@@ -163,7 +165,7 @@ public class WifiSettings2Test {
public void setAdditionalSettingsSummaries_wifiWakeupEnabled_displayOn() { public void setAdditionalSettingsSummaries_wifiWakeupEnabled_displayOn() {
final ContentResolver contentResolver = mContext.getContentResolver(); final ContentResolver contentResolver = mContext.getContentResolver();
when(mWifiManager.isAutoWakeupEnabled()).thenReturn(true); when(mWifiManager.isAutoWakeupEnabled()).thenReturn(true);
when(mWifiManager.isScanAlwaysAvailable()).thenReturn(false); when(mWifiManager.isScanAlwaysAvailable()).thenReturn(true);
Settings.Global.putInt(contentResolver, Settings.Global.AIRPLANE_MODE_ON, 0); Settings.Global.putInt(contentResolver, Settings.Global.AIRPLANE_MODE_ON, 0);
when(mPowerManager.isPowerSaveMode()).thenReturn(false); when(mPowerManager.isPowerSaveMode()).thenReturn(false);
@@ -200,7 +202,7 @@ public class WifiSettings2Test {
when(activity.getSystemService(Context.USER_SERVICE)) when(activity.getSystemService(Context.USER_SERVICE))
.thenReturn(userManager); .thenReturn(userManager);
when(mWifiSettings2.findPreference(WifiSettings.PREF_KEY_DATA_USAGE)) when(mWifiSettings2.findPreference(WifiSettings2.PREF_KEY_DATA_USAGE))
.thenReturn(mDataUsagePreference); .thenReturn(mDataUsagePreference);
} }
@@ -268,4 +270,14 @@ public class WifiSettings2Test {
verify(mWifiSettings2).changeNextButtonState(anyBoolean()); verify(mWifiSettings2).changeNextButtonState(anyBoolean());
} }
@Test
public void openSubscriptionHelpPage_shouldCallStartActivityForResult() {
doReturn(new Intent()).when(mWifiSettings2).getHelpIntent(mContext);
doNothing().when(mWifiSettings2).startActivityForResult(any(Intent.class), anyInt());
mWifiSettings2.openSubscriptionHelpPage();
verify(mWifiSettings2, times(1)).startActivityForResult(any(), anyInt());
}
} }