[DPP R2] Update ACTION_PROCESS_WIFI_EASY_CONNECT_URI intent

Update ACTION_PROCESS_WIFI_EASY_CONNECT_URI intent to include
additional information in case of a failure. The intent will
return an extra field with result code for R1 and R2 devices,
and additional details for R2 devices: SSID, channe list,
and band list.

Bug: 139381558
Test: Manual test
Change-Id: I6f1805f3b1ff72efc83961083c1311a24d6ebd3e
This commit is contained in:
Hai Shalom
2019-12-23 14:30:17 -08:00
parent 7b77b497d8
commit 457203e156

View File

@@ -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<int[]> 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);
}
}
}