aboutsummaryrefslogtreecommitdiff
path: root/java/com/android/libraries
diff options
context:
space:
mode:
authorKiwon Park <kiwonp@google.com>2022-08-24 23:20:27 +0000
committerKiwon Park <kiwonp@google.com>2022-10-04 00:10:11 +0000
commit00d7763e6db1568259872680725025e12234d816 (patch)
tree2949634f84828094397442aa8cd97b305070dd49 /java/com/android/libraries
parent5d4fc15dc48a6361155178c6cb56be4c0eace72c (diff)
downloadservice_entitlement-00d7763e6db1568259872680725025e12234d816.tar.gz
Add ability to save the HTTP request/responses.
Bug: 223430297 Test: HttpClientTest Change-Id: I395c26dff80e44a1531b70ca8310de1298b95613 Merged-In: I395c26dff80e44a1531b70ca8310de1298b95613
Diffstat (limited to 'java/com/android/libraries')
-rw-r--r--java/com/android/libraries/entitlement/ServiceEntitlement.java40
-rw-r--r--java/com/android/libraries/entitlement/eapaka/EapAkaApi.java20
-rw-r--r--java/com/android/libraries/entitlement/http/HttpClient.java28
-rw-r--r--java/com/android/libraries/entitlement/http/HttpResponse.java18
4 files changed, 85 insertions, 21 deletions
diff --git a/java/com/android/libraries/entitlement/ServiceEntitlement.java b/java/com/android/libraries/entitlement/ServiceEntitlement.java
index d723e4c..ef57e73 100644
--- a/java/com/android/libraries/entitlement/ServiceEntitlement.java
+++ b/java/com/android/libraries/entitlement/ServiceEntitlement.java
@@ -25,6 +25,8 @@ import com.android.libraries.entitlement.eapaka.EapAkaApi;
import com.google.common.collect.ImmutableList;
+import java.util.List;
+
/**
* Implemnets protocol for carrier service entitlement configuration query and operation, based on
* GSMA TS.43 spec.
@@ -68,7 +70,28 @@ public class ServiceEntitlement {
*/
public ServiceEntitlement(Context context, CarrierConfig carrierConfig, int simSubscriptionId) {
this.carrierConfig = carrierConfig;
- this.eapAkaApi = new EapAkaApi(context, simSubscriptionId);
+ this.eapAkaApi = new EapAkaApi(context, simSubscriptionId, false);
+ }
+
+ /**
+ * Creates an instance for service entitlement configuration query and operation for the
+ * carrier.
+ *
+ * @param context context of application
+ * @param carrierConfig carrier specific configs used in the queries and operations.
+ * @param simSubscriptionId the subscroption ID of the carrier's SIM on device. This indicates
+ * which SIM to retrieve IMEI/IMSI from and perform EAP-AKA authentication with. See {@link
+ * android.telephony.SubscriptionManager} for how to get the subscroption ID.
+ * @param saveHttpHistory set to {@code true} to save the history of request and response which
+ * can later be retrieved by {@code getHistory()}. Intended for debugging.
+ */
+ public ServiceEntitlement(
+ Context context,
+ CarrierConfig carrierConfig,
+ int simSubscriptionId,
+ boolean saveHttpHistory) {
+ this.carrierConfig = carrierConfig;
+ this.eapAkaApi = new EapAkaApi(context, simSubscriptionId, saveHttpHistory);
}
@VisibleForTesting
@@ -151,4 +174,19 @@ public class ServiceEntitlement {
throws ServiceEntitlementException {
return eapAkaApi.performEsimOdsaOperation(appId, carrierConfig, request, operation);
}
+
+ /**
+ * Retrieves the history of past HTTP request and responses if {@code saveHttpHistory} was set
+ * in constructor.
+ */
+ public List<String> getHistory() {
+ return eapAkaApi.getHistory();
+ }
+
+ /**
+ * Clears the history of past HTTP request and responses.
+ */
+ public void clearHistory() {
+ eapAkaApi.clearHistory();
+ }
}
diff --git a/java/com/android/libraries/entitlement/eapaka/EapAkaApi.java b/java/com/android/libraries/entitlement/eapaka/EapAkaApi.java
index d7d4644..a0c8c24 100644
--- a/java/com/android/libraries/entitlement/eapaka/EapAkaApi.java
+++ b/java/com/android/libraries/entitlement/eapaka/EapAkaApi.java
@@ -43,6 +43,8 @@ import com.google.common.net.HttpHeaders;
import org.json.JSONException;
import org.json.JSONObject;
+import java.util.List;
+
public class EapAkaApi {
private static final String TAG = "ServiceEntitlement";
@@ -94,8 +96,8 @@ public class EapAkaApi {
private final int mSimSubscriptionId;
private final HttpClient mHttpClient;
- public EapAkaApi(Context context, int simSubscriptionId) {
- this(context, simSubscriptionId, new HttpClient());
+ public EapAkaApi(Context context, int simSubscriptionId, boolean saveHistory) {
+ this(context, simSubscriptionId, new HttpClient(saveHistory));
}
@VisibleForTesting
@@ -402,4 +404,18 @@ public class EapAkaApi {
}
return "0" + imsi + "@nai.epc.mnc" + mnc + ".mcc" + mcc + ".3gppnetwork.org";
}
+
+ /**
+ * Retrieves the history of past HTTP request and responses.
+ */
+ public List<String> getHistory() {
+ return mHttpClient.getHistory();
+ }
+
+ /**
+ * Clears the history of past HTTP request and responses.
+ */
+ public void clearHistory() {
+ mHttpClient.clearHistory();
+ }
}
diff --git a/java/com/android/libraries/entitlement/http/HttpClient.java b/java/com/android/libraries/entitlement/http/HttpClient.java
index 9ccb5ee..39275e8 100644
--- a/java/com/android/libraries/entitlement/http/HttpClient.java
+++ b/java/com/android/libraries/entitlement/http/HttpClient.java
@@ -47,6 +47,7 @@ import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
+import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -55,9 +56,19 @@ public class HttpClient {
private static final String TAG = "ServiceEntitlement";
private HttpURLConnection mConnection;
+ private boolean mSaveHistory;
+ private ArrayList<String> mHistory;
+
+ public HttpClient(boolean saveHistory) {
+ mSaveHistory = saveHistory;
+ mHistory = new ArrayList<>();
+ }
@WorkerThread
public HttpResponse request(HttpRequest request) throws ServiceEntitlementException {
+ if (mSaveHistory) {
+ mHistory.add(request.toString());
+ }
logPii("HttpClient.request url: " + request.url());
createConnection(request);
logPii("HttpClient.request headers (partial): " + mConnection.getRequestProperties());
@@ -74,6 +85,9 @@ public class HttpClient {
mConnection.connect(); // This is to trigger SocketTimeoutException early
HttpResponse response = getHttpResponse(mConnection);
Log.d(TAG, "HttpClient.response : " + response);
+ if (mSaveHistory) {
+ mHistory.add(response.toString());
+ }
return response;
} catch (IOException ioe) {
throw new ServiceEntitlementException(
@@ -85,6 +99,20 @@ public class HttpClient {
}
}
+ /**
+ * Retrieves the history of past HTTP request and responses.
+ */
+ public List<String> getHistory() {
+ return mHistory;
+ }
+
+ /**
+ * Clears the history of past HTTP request and responses.
+ */
+ public void clearHistory() {
+ mHistory.clear();
+ }
+
private void createConnection(HttpRequest request) throws ServiceEntitlementException {
try {
URL url = new URL(request.url());
diff --git a/java/com/android/libraries/entitlement/http/HttpResponse.java b/java/com/android/libraries/entitlement/http/HttpResponse.java
index f495578..f76fdd6 100644
--- a/java/com/android/libraries/entitlement/http/HttpResponse.java
+++ b/java/com/android/libraries/entitlement/http/HttpResponse.java
@@ -73,22 +73,4 @@ public abstract class HttpResponse {
.setResponseMessage("")
.setCookies(ImmutableList.of());
}
-
- @Override
- public final String toString() {
- return new StringBuilder("HttpResponse{")
- .append("contentType=")
- .append(contentType())
- .append(" body=(")
- .append(body().length())
- .append(" characters)")
- .append(" responseCode=")
- .append(responseCode())
- .append(" responseMessage=")
- .append(responseMessage())
- .append(" cookies=[")
- .append(cookies().size())
- .append(" cookies]}")
- .toString();
- }
}