1 /* 2 * Copyright (C) 2023 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.server.wifi.entitlement.response; 18 19 import android.text.TextUtils; 20 import android.util.Log; 21 22 import com.android.server.wifi.entitlement.RequestFactory; 23 24 import org.json.JSONArray; 25 import org.json.JSONException; 26 import org.json.JSONObject; 27 28 /** The response of authentication challenge request. */ 29 public class ChallengeResponse extends Response { 30 private static final String TAG = "WifiEntitlement(ChallengeResponse)"; 31 ChallengeResponse(String responseBody)32 public ChallengeResponse(String responseBody) { 33 if (TextUtils.isEmpty(responseBody)) { 34 Log.e(TAG, "Error! Empty responseBody!"); 35 return; 36 } 37 try { 38 JSONArray array = new JSONArray(responseBody); 39 for (int i = 0; i < array.length(); i++) { 40 JSONObject object = array.optJSONObject(i); 41 if (object == null) { 42 continue; 43 } 44 int id = object.optInt(JSON_KEY_MESSAGE_ID, -1); 45 if (id == RequestFactory.MESSAGE_ID_3GPP_AUTHENTICATION) { 46 parse3gppAuthentication(object); 47 } else { 48 Log.e(TAG, "Unexpected Message ID >> " + id); 49 } 50 } 51 } catch (JSONException e) { 52 Log.e(TAG, "ERROR! not a valid JSONArray String![" + responseBody + "]", e); 53 } 54 } 55 /** Returns {@code mEapAkaChallenge}. */ getEapAkaChallenge()56 public String getEapAkaChallenge() { 57 return mEapAkaChallenge; 58 } 59 } 60 61