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 com.android.internal.annotations.VisibleForTesting;
20 
21 import org.json.JSONObject;
22 
23 /** The response of any entitlement request. */
24 public abstract class Response {
25     static final String JSON_KEY_MESSAGE_ID = "message-id";
26     static final String JSON_KEY_RESPONSE_CODE = "response-code";
27     @VisibleForTesting
28     static final String JSON_KEY_EAP_AKA_CHALLENGE = "aka-challenge";
29     @VisibleForTesting
30     static final String JSON_KEY_AKA_TOKEN = "aka-token";
31     public static final int RESPONSE_CODE_REQUEST_SUCCESSFUL = 1000;
32     public static final int RESPONSE_CODE_AKA_CHALLENGE = 1003;
33     public static final int RESPONSE_CODE_INVALID_REQUEST = 1004;
34     public static final int RESPONSE_CODE_AKA_AUTH_FAILED = 1006;
35 
36     // The request is not applicable to this subscriber or the imsi-pseudonym cannot be retrieved.
37     public static final int RESPONSE_CODE_FORBIDDEN_REQUEST = 1007;
38     public static final int RESPONSE_CODE_SERVER_ERROR = 1111;
39     public static final int RESPONSE_CODE_3GPP_AUTH_ONGOING = 1112;
40 
41     // The method is not supported by the installed version of SES
42     public static final int RESPONSE_CODE_UNSUPPORTED_OPERATION = 9999;
43     protected int mAuthResponseCode;
44     protected String mEapAkaChallenge;
45     protected String mAkaToken;
46 
parse3gppAuthentication(JSONObject object)47     protected void parse3gppAuthentication(JSONObject object) {
48         mAuthResponseCode = object.optInt(JSON_KEY_RESPONSE_CODE, -1);
49         mEapAkaChallenge = object.optString(JSON_KEY_EAP_AKA_CHALLENGE, null);
50         mAkaToken = object.optString(JSON_KEY_AKA_TOKEN, null);
51     }
52 
getAuthResponseCode()53     public int getAuthResponseCode() {
54         return mAuthResponseCode;
55     }
56 }
57 
58