diff --git a/src/com/android/settings/wifi/dpp/WifiDppAddDeviceFragment.java b/src/com/android/settings/wifi/dpp/WifiDppAddDeviceFragment.java index caba227777a..82c6ce4e4f0 100644 --- a/src/com/android/settings/wifi/dpp/WifiDppAddDeviceFragment.java +++ b/src/com/android/settings/wifi/dpp/WifiDppAddDeviceFragment.java @@ -16,9 +16,15 @@ package com.android.settings.wifi.dpp; +import static android.provider.Settings.EXTRA_EASY_CONNECT_ATTEMPTED_SSID; +import static android.provider.Settings.EXTRA_EASY_CONNECT_BAND_LIST; +import static android.provider.Settings.EXTRA_EASY_CONNECT_CHANNEL_LIST; +import static android.provider.Settings.EXTRA_EASY_CONNECT_ERROR_CODE; + import android.app.Activity; import android.app.settings.SettingsEnums; import android.content.Context; +import android.content.Intent; import android.net.wifi.EasyConnectStatusCallback; import android.net.wifi.WifiManager; import android.os.Bundle; @@ -35,6 +41,9 @@ import androidx.lifecycle.ViewModelProviders; import com.android.settings.R; +import org.json.JSONArray; +import org.json.JSONObject; + /** * After getting Wi-Fi network information and(or) QR code, this fragment config a device to connect * to the Wi-Fi network. @@ -79,7 +88,8 @@ public class WifiDppAddDeviceFragment extends WifiDppQrCodeBaseFragment { Log.d(TAG, sb.toString()); } - showErrorUi(code, /* isConfigurationChange */ false); + showErrorUi(code, ssid, channelListArray, operatingClassArray, + /* isConfigurationChange */ false); } @Override @@ -110,7 +120,8 @@ public class WifiDppAddDeviceFragment extends WifiDppQrCodeBaseFragment { } } - private void showErrorUi(int code, boolean isConfigurationChange) { + private void showErrorUi(int code, String ssid, SparseArray channelListArray, + int[] operatingClassArray, boolean isConfigurationChange) { CharSequence summaryCharSequence; switch (code) { case EasyConnectStatusCallback.EASY_CONNECT_EVENT_FAILURE_INVALID_URI: @@ -191,7 +202,50 @@ public class WifiDppAddDeviceFragment extends WifiDppQrCodeBaseFragment { mRightButton.setText(getContext(), R.string.retry); } else { mRightButton.setText(getContext(), R.string.done); - mRightButton.setOnClickListener(v -> getActivity().finish()); + mRightButton.setOnClickListener(v -> { + final Activity activity = getActivity(); + final Intent intent = activity.getIntent(); + intent.putExtra(EXTRA_EASY_CONNECT_ERROR_CODE, code); + + if (!TextUtils.isEmpty(ssid)) { + intent.putExtra(EXTRA_EASY_CONNECT_ATTEMPTED_SSID, ssid); + } + if (channelListArray != null && channelListArray.size() != 0) { + int key; + int index = 0; + JSONObject formattedChannelList = new JSONObject(); + + // Build a JSON array of operating classes, with an array of channels for each + // operating class. + do { + try { + key = channelListArray.keyAt(index); + } catch (java.lang.ArrayIndexOutOfBoundsException e) { + break; + } + JSONArray channelsInClassArray = new JSONArray(); + + int[] output = channelListArray.get(key); + for (int i = 0; i < output.length; i++) { + channelsInClassArray.put(output[i]); + } + try { + formattedChannelList.put(Integer.toString(key), channelsInClassArray); + } catch (org.json.JSONException e) { + formattedChannelList = new JSONObject(); + break; + } + index++; + } while (true); + + intent.putExtra(EXTRA_EASY_CONNECT_CHANNEL_LIST, + formattedChannelList.toString()); + } + if (operatingClassArray != null && operatingClassArray.length != 0) { + intent.putExtra(EXTRA_EASY_CONNECT_BAND_LIST, operatingClassArray); + } + activity.finish(); + }); mLeftButton.setVisibility(View.INVISIBLE); } @@ -302,7 +356,8 @@ public class WifiDppAddDeviceFragment extends WifiDppQrCodeBaseFragment { mRightButton.setVisibility(isEasyConnectHandshaking() ? View.INVISIBLE : View.VISIBLE); } else { - showErrorUi(mLatestStatusCode, /* isConfigurationChange */ true); + showErrorUi(mLatestStatusCode, /*ssid */null, /* channelListArray */ + null, /* operatingClassArray */ null, /* isConfigurationChange */ true); } } }