• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 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.phone.satellite.entitlement;
18 
19 import android.annotation.NonNull;
20 import android.content.Context;
21 import android.os.PersistableBundle;
22 import android.telephony.CarrierConfigManager;
23 
24 import com.android.libraries.entitlement.CarrierConfig;
25 import com.android.libraries.entitlement.ServiceEntitlement;
26 import com.android.libraries.entitlement.ServiceEntitlementException;
27 import com.android.libraries.entitlement.ServiceEntitlementRequest;
28 
29 /**
30  * Class that sends an HTTP request to the entitlement server and processes the response to check
31  * whether satellite service can be activated.
32  * @hide
33  */
34 public class SatelliteEntitlementApi {
35     private static final String DEFAULT_APP_NAME = "androidSatmode";
36     @NonNull
37     private final ServiceEntitlement mServiceEntitlement;
38     private final Context mContext;
39     private final PersistableBundle mCarrierConfig;
40 
SatelliteEntitlementApi(@onNull Context context, @NonNull PersistableBundle carrierConfig, @NonNull int subId)41     public SatelliteEntitlementApi(@NonNull Context context,
42             @NonNull PersistableBundle carrierConfig, @NonNull int subId) {
43         mContext = context;
44         mServiceEntitlement = new ServiceEntitlement(mContext,
45                 getCarrierConfigFromEntitlementServerUrl(carrierConfig), subId);
46         mCarrierConfig = carrierConfig;
47     }
48 
49     /**
50      * Returns satellite entitlement result from the entitlement server.
51      * @return The SatelliteEntitlementResult
52      */
checkEntitlementStatus()53     public SatelliteEntitlementResult checkEntitlementStatus() throws ServiceEntitlementException {
54         ServiceEntitlementRequest.Builder requestBuilder = ServiceEntitlementRequest.builder();
55         requestBuilder.setAcceptContentType(ServiceEntitlementRequest.ACCEPT_CONTENT_TYPE_JSON);
56         requestBuilder.setAppName(getSatelliteEntitlementAppName(mCarrierConfig));
57         ServiceEntitlementRequest request = requestBuilder.build();
58 
59         String response = mServiceEntitlement.queryEntitlementStatus(
60                 ServiceEntitlement.APP_SATELLITE_ENTITLEMENT, request);
61         SatelliteEntitlementResponse satelliteEntitlementResponse =
62                 new SatelliteEntitlementResponse(response);
63         return new SatelliteEntitlementResult(satelliteEntitlementResponse.getEntitlementStatus(),
64                 satelliteEntitlementResponse.getPlmnAllowed(),
65                 satelliteEntitlementResponse.getPlmnBarredList());
66     }
67 
68     @NonNull
getCarrierConfigFromEntitlementServerUrl( @onNull PersistableBundle carrierConfig)69     private CarrierConfig getCarrierConfigFromEntitlementServerUrl(
70             @NonNull PersistableBundle carrierConfig) {
71         String entitlementServiceUrl = carrierConfig.getString(
72                 CarrierConfigManager.ImsServiceEntitlement.KEY_ENTITLEMENT_SERVER_URL_STRING,
73                 "");
74         return CarrierConfig.builder().setServerUrl(entitlementServiceUrl).build();
75     }
76 
77     @NonNull
getSatelliteEntitlementAppName(@onNull PersistableBundle carrierConfig)78     private String getSatelliteEntitlementAppName(@NonNull PersistableBundle carrierConfig) {
79         return carrierConfig.getString(
80                 CarrierConfigManager.KEY_SATELLITE_ENTITLEMENT_APP_NAME_STRING, DEFAULT_APP_NAME);
81     }
82 }
83