[Wi-Fi] Add a new intent handler process for adding new networks panel page.

For the R feature "Add saved networks to the
device for apps", need to handle the new intent case to update the content to be the specific networks in the new intent.

Bug: 146105504
Test: Add following unit test case to check if UI list had been updated:
      getThreeNetworksNewIntent_shouldHaveThreeItemsInUiList.

Change-Id: Id043fabb16ba5a75aa81be8cacd403e62e5268b8
This commit is contained in:
govenliu
2019-12-23 09:39:00 +08:00
parent 80e1cf7b79
commit d9a414b61e
3 changed files with 69 additions and 20 deletions

View File

@@ -24,6 +24,7 @@ import android.view.Window;
import android.view.WindowManager; import android.view.WindowManager;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentManager;
@@ -77,10 +78,13 @@ public class AddAppNetworksActivity extends FragmentActivity {
getIntent().getParcelableArrayListExtra(Settings.EXTRA_WIFI_CONFIGURATION_LIST)); getIntent().getParcelableArrayListExtra(Settings.EXTRA_WIFI_CONFIGURATION_LIST));
final FragmentManager fragmentManager = getSupportFragmentManager(); final FragmentManager fragmentManager = getSupportFragmentManager();
if (fragmentManager.findFragmentByTag(TAG) == null) { Fragment fragment = fragmentManager.findFragmentByTag(TAG);
final AddAppNetworksFragment fragment = new AddAppNetworksFragment(); if (fragment == null) {
fragment = new AddAppNetworksFragment();
fragment.setArguments(mBundle); fragment.setArguments(mBundle);
fragmentManager.beginTransaction().add(R.id.main_content, fragment, TAG).commit(); fragmentManager.beginTransaction().add(R.id.main_content, fragment, TAG).commit();
} else {
((AddAppNetworksFragment) fragment).createContent(mBundle);
} }
} }
} }

View File

@@ -184,7 +184,19 @@ public class AddAppNetworksFragment extends InstrumentedFragment {
createContent(bundle); createContent(bundle);
} }
private void createContent(Bundle bundle) { /**
* Updates the UI contents to be aligned with the parameters in Bundle. This API may be called
* by the Activity directly when get a new intent.
*/
@VisibleForTesting
void createContent(Bundle bundle) {
// For new intent case, if device is saving those networks specified in old intent, just
// ignore this new intent for preventing status error.
if (mSaveButton != null && !mSaveButton.isEnabled()) {
Log.d(TAG, "Network saving, ignore new intent");
return;
}
mAllSpecifiedNetworksList = mAllSpecifiedNetworksList =
bundle.getParcelableArrayList(Settings.EXTRA_WIFI_CONFIGURATION_LIST); bundle.getParcelableArrayList(Settings.EXTRA_WIFI_CONFIGURATION_LIST);
@@ -199,7 +211,7 @@ public class AddAppNetworksFragment extends InstrumentedFragment {
// Initial the result arry. // Initial the result arry.
initializeResultCodeArray(); initializeResultCodeArray();
// Filter the saved networks, and prepare a not saved networks list for UI to present. // Filter the saved networks, and prepare a not saved networks list for UI to present.
mUiToRequestedList = filterSavedNetworks(mWifiManager.getPrivilegedConfiguredNetworks()); filterSavedNetworks(mWifiManager.getPrivilegedConfiguredNetworks());
// If all the specific networks are all exist, we just need to finish with result. // If all the specific networks are all exist, we just need to finish with result.
if (mUiToRequestedList.size() == 0) { if (mUiToRequestedList.size() == 0) {
@@ -209,8 +221,11 @@ public class AddAppNetworksFragment extends InstrumentedFragment {
if (mAllSpecifiedNetworksList.size() == 1) { if (mAllSpecifiedNetworksList.size() == 1) {
mIsSingleNetwork = true; mIsSingleNetwork = true;
// Set the multiple networks related layout as GONE. // Set the multiple networks related layout to be gone, and the single network layout
// items to be visible.
mLayoutView.findViewById(R.id.multiple_networks).setVisibility(View.GONE); mLayoutView.findViewById(R.id.multiple_networks).setVisibility(View.GONE);
mLayoutView.findViewById(R.id.single_network).setVisibility(View.VISIBLE);
// Show signal icon for single network case. // Show signal icon for single network case.
setSingleNetworkSignalIcon(); setSingleNetworkSignalIcon();
// Show the SSID of the proposed network. // Show the SSID of the proposed network.
@@ -221,13 +236,21 @@ public class AddAppNetworksFragment extends InstrumentedFragment {
} else { } else {
// Multiple networks request case. // Multiple networks request case.
mIsSingleNetwork = false; mIsSingleNetwork = false;
// Set the single network related layout as GONE. // Set the single network related layout to be gone, and the multiple networks layout
// items to be visible.
mLayoutView.findViewById(R.id.single_network).setVisibility(View.GONE); mLayoutView.findViewById(R.id.single_network).setVisibility(View.GONE);
// Prepare a UI adapter and set to UI listview. mLayoutView.findViewById(R.id.multiple_networks).setVisibility(View.VISIBLE);
final ListView uiNetworkListView = mLayoutView.findViewById(R.id.config_list);
mUiConfigurationItemAdapter = new UiConfigurationItemAdapter(mActivity, if (mUiConfigurationItemAdapter == null) {
com.android.settingslib.R.layout.preference_access_point, mUiToRequestedList); // Prepare a UI adapter and set to UI listview.
uiNetworkListView.setAdapter(mUiConfigurationItemAdapter); final ListView uiNetworkListView = mLayoutView.findViewById(R.id.config_list);
mUiConfigurationItemAdapter = new UiConfigurationItemAdapter(mActivity,
com.android.settingslib.R.layout.preference_access_point,
mUiToRequestedList);
uiNetworkListView.setAdapter(mUiConfigurationItemAdapter);
} else {
mUiConfigurationItemAdapter.notifyDataSetChanged();
}
} }
// Assigns caller app icon, title, and summary. // Assigns caller app icon, title, and summary.
@@ -269,13 +292,17 @@ public class AddAppNetworksFragment extends InstrumentedFragment {
/** /**
* For the APP specified networks, filter saved ones and mark those saved as existed. And * For the APP specified networks, filter saved ones and mark those saved as existed. And
* finally return a new UiConfigurationItem list, which contains those new or need to be * prepare a new UiConfigurationItem list, which contains those new or need to be updated
* updated networks, back to caller for creating UI to user. * networks, for creating UI to user.
*/ */
@VisibleForTesting @VisibleForTesting
ArrayList<UiConfigurationItem> filterSavedNetworks( void filterSavedNetworks(
List<WifiConfiguration> savedWifiConfigurations) { List<WifiConfiguration> savedWifiConfigurations) {
ArrayList<UiConfigurationItem> uiToRequestedList = new ArrayList<>(); if (mUiToRequestedList == null) {
mUiToRequestedList = new ArrayList<>();
} else {
mUiToRequestedList.clear();
}
boolean foundInSavedList; boolean foundInSavedList;
int networkPositionInBundle = 0; int networkPositionInBundle = 0;
@@ -327,12 +354,10 @@ public class AddAppNetworksFragment extends InstrumentedFragment {
// Prepare to add to UI list to show to user // Prepare to add to UI list to show to user
UiConfigurationItem uiConfigurationIcon = new UiConfigurationItem(displayedSsid, UiConfigurationItem uiConfigurationIcon = new UiConfigurationItem(displayedSsid,
specifiecConfig, networkPositionInBundle); specifiecConfig, networkPositionInBundle);
uiToRequestedList.add(uiConfigurationIcon); mUiToRequestedList.add(uiConfigurationIcon);
} }
networkPositionInBundle++; networkPositionInBundle++;
} }
return uiToRequestedList;
} }
private void setSingleNetworkSignalIcon() { private void setSingleNetworkSignalIcon() {
@@ -573,6 +598,10 @@ public class AddAppNetworksFragment extends InstrumentedFragment {
} }
private void finishWithResult(int resultCode, List<Integer> resultArrayList) { private void finishWithResult(int resultCode, List<Integer> resultArrayList) {
if (mActivity == null) {
return;
}
if (resultArrayList != null) { if (resultArrayList != null) {
Intent intent = new Intent(); Intent intent = new Intent();
intent.putIntegerArrayListExtra(Settings.EXTRA_WIFI_CONFIGURATION_RESULT_LIST, intent.putIntegerArrayListExtra(Settings.EXTRA_WIFI_CONFIGURATION_RESULT_LIST,

View File

@@ -129,8 +129,7 @@ public class AddAppNetworksFragmentTest {
mAddAppNetworksFragment.mResultCodeArrayList = mFakedResultArrayList; mAddAppNetworksFragment.mResultCodeArrayList = mFakedResultArrayList;
// Act // Act
mAddAppNetworksFragment.mUiToRequestedList = mAddAppNetworksFragment.filterSavedNetworks( mAddAppNetworksFragment.filterSavedNetworks(mFakeSavedNetworksList);
mFakeSavedNetworksList);
// Assert // Assert
assertThat(mAddAppNetworksFragment.mUiToRequestedList).hasSize(1); assertThat(mAddAppNetworksFragment.mUiToRequestedList).hasSize(1);
@@ -146,6 +145,23 @@ public class AddAppNetworksFragmentTest {
SettingsEnums.PANEL_ADD_WIFI_NETWORKS); SettingsEnums.PANEL_ADD_WIFI_NETWORKS);
} }
@Test
public void getThreeNetworksNewIntent_shouldHaveThreeItemsInUiList() {
addOneSpecifiedNetworkConfig(mNewWpaConfigEntry);
setUpBundle(mFakedSpecifiedNetworksList);
setupFragment();
// Add two more networks and update framework bundle.
addOneSpecifiedNetworkConfig(mNewWpaConfigEntry);
addOneSpecifiedNetworkConfig(mNewOpenConfigEntry);
setUpBundle(mFakedSpecifiedNetworksList);
Bundle bundle = mAddAppNetworksFragment.getArguments();
mAddAppNetworksFragment.createContent(bundle);
// Ui list should contain 3 networks.
assertThat(mAddAppNetworksFragment.mUiToRequestedList).hasSize(3);
}
private void addOneSavedNetworkConfig(@NonNull WifiConfiguration wifiConfiguration) { private void addOneSavedNetworkConfig(@NonNull WifiConfiguration wifiConfiguration) {
if (mFakeSavedNetworksList == null) { if (mFakeSavedNetworksList == null) {
mFakeSavedNetworksList = new ArrayList<>(); mFakeSavedNetworksList = new ArrayList<>();