• 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 static android.telephony.CarrierConfigManager.SATELLITE_DATA_SUPPORT_ALL;
20 import static android.telephony.CarrierConfigManager.SATELLITE_DATA_SUPPORT_BANDWIDTH_CONSTRAINED;
21 import static android.telephony.NetworkRegistrationInfo.SERVICE_TYPE_DATA;
22 import static android.telephony.NetworkRegistrationInfo.SERVICE_TYPE_VOICE;
23 import static android.telephony.NetworkRegistrationInfo.SERVICE_TYPE_SMS;
24 
25 import static com.android.internal.telephony.satellite.SatelliteController.SATELLITE_DATA_PLAN_METERED;
26 import static com.android.internal.telephony.satellite.SatelliteController.SATELLITE_DATA_PLAN_UNMETERED;
27 
28 import android.annotation.IntDef;
29 
30 import com.android.internal.telephony.satellite.SatelliteNetworkInfo;
31 
32 import java.util.ArrayList;
33 import java.util.HashMap;
34 import java.util.List;
35 import java.util.Map;
36 import java.util.stream.Collectors;
37 
38 /**
39  * This class stores the result of the satellite entitlement query and passes them to
40  * SatelliteEntitlementController.
41  */
42 public class SatelliteEntitlementResult {
43     /** SatMode allowed, but not yet provisioned and activated on the network. */
44     public static final int SATELLITE_ENTITLEMENT_STATUS_DISABLED = 0;
45     /** SatMode service allowed, provisioned and activated on the network. User can access the
46      * satellite service. */
47     public static final int SATELLITE_ENTITLEMENT_STATUS_ENABLED = 1;
48     /** SatMode cannot be offered for network or device. */
49     public static final int SATELLITE_ENTITLEMENT_STATUS_INCOMPATIBLE = 2;
50     /** SatMode is being provisioned on the network. Not yet activated. */
51     public static final int SATELLITE_ENTITLEMENT_STATUS_PROVISIONING = 3;
52 
53     @IntDef(prefix = {"SATELLITE_ENTITLEMENT_STATUS_"}, value = {
54             SATELLITE_ENTITLEMENT_STATUS_DISABLED,
55             SATELLITE_ENTITLEMENT_STATUS_ENABLED,
56             SATELLITE_ENTITLEMENT_STATUS_INCOMPATIBLE,
57             SATELLITE_ENTITLEMENT_STATUS_PROVISIONING
58     })
59     public @interface SatelliteEntitlementStatus {}
60 
61     private @SatelliteEntitlementStatus int mEntitlementStatus;
62     /**
63      * An SatelliteNetworkInfo list consisting of the PLMN and the DataPlanType in the PLMNAlowed
64      * item of the satellite configuration received from the entitlement server.
65      */
66     private List<SatelliteNetworkInfo> mAllowedSatelliteNetworkInfoList;
67     /**
68      * List consisting of the PLMN in the PLMNBarred item of the satellite configuration received
69      * from the entitlement server
70      */
71     private List<String> mBarredPlmnList;
72 
73     /**
74      * Store the result of the satellite entitlement response.
75      *
76      * @param entitlementStatus The entitlement status.
77      * @param allowedSatelliteNetworkInfoList The allowedSatelliteNetworkInfoList
78      * @param barredPlmnList The barred plmn list
79      */
SatelliteEntitlementResult(@atelliteEntitlementStatus int entitlementStatus, List<SatelliteNetworkInfo> allowedSatelliteNetworkInfoList, List<String> barredPlmnList)80     public SatelliteEntitlementResult(@SatelliteEntitlementStatus int entitlementStatus,
81             List<SatelliteNetworkInfo> allowedSatelliteNetworkInfoList,
82             List<String> barredPlmnList) {
83         mEntitlementStatus = entitlementStatus;
84         mAllowedSatelliteNetworkInfoList = allowedSatelliteNetworkInfoList;
85         mBarredPlmnList = barredPlmnList;
86     }
87 
88     /**
89      * Get the entitlement status.
90      *
91      * @return The entitlement status.
92      */
getEntitlementStatus()93     public @SatelliteEntitlementStatus int getEntitlementStatus() {
94         return mEntitlementStatus;
95     }
96 
97     /**
98      * Get the plmn allowed list
99      *
100      * @return The plmn allowed list.
101      */
getAllowedPLMNList()102     public List<String> getAllowedPLMNList() {
103         return mAllowedSatelliteNetworkInfoList.stream().map(info -> info.mPlmn).collect(
104                 Collectors.toList());
105     }
106 
107     /**
108      * Get the plmn barred list
109      *
110      * @return The plmn barred list.
111      */
getBarredPLMNList()112     public List<String> getBarredPLMNList() {
113         return mBarredPlmnList.stream().map(String::new).collect(Collectors.toList());
114     }
115 
116     /**
117      * Get the default SatelliteEntitlementResult. EntitlementStatus set to
118      * `SATELLITE_ENTITLEMENT_STATUS_DISABLED` and SatelliteNetworkInfo list set to empty.
119      *
120      * @return If there is no response, return default SatelliteEntitlementResult
121      */
getDefaultResult()122     public static SatelliteEntitlementResult getDefaultResult() {
123         return new SatelliteEntitlementResult(SATELLITE_ENTITLEMENT_STATUS_DISABLED,
124                 new ArrayList<>(), new ArrayList<>());
125     }
126 
127     /**
128      * Get the data plan for the plmn List
129      *
130      * @return data plan for the plmn List
131      */
getDataPlanInfoForPlmnList()132     public Map<String, Integer> getDataPlanInfoForPlmnList() {
133         Map<String, Integer> dataPlanInfo = new HashMap<>();
134 
135         for (SatelliteNetworkInfo plmnInfo :  mAllowedSatelliteNetworkInfoList) {
136             int dataPlan = SATELLITE_DATA_PLAN_METERED; // default metered is available
137             if (plmnInfo.mDataPlanType.equalsIgnoreCase("unmetered")) {
138                 dataPlan = SATELLITE_DATA_PLAN_UNMETERED; // overwrite data plan if unmetered
139             }
140             dataPlanInfo.put(plmnInfo.mPlmn, dataPlan);
141         }
142         return dataPlanInfo;
143     }
144 
145     /**
146      * Get ServiceType at Allowed Services for the plmn List
147      *
148      * @return The Allowed Services for the plmn List
149      */
getAvailableServiceTypeInfoForPlmnList()150     public Map<String, List<Integer>> getAvailableServiceTypeInfoForPlmnList() {
151         Map<String, List<Integer>> availableServicesInfo = new HashMap<>();
152         for (SatelliteNetworkInfo plmnInfo : mAllowedSatelliteNetworkInfoList) {
153             List<Integer> allowedServicesList = new ArrayList<>();
154             if (plmnInfo.mAllowedServicesInfo != null) {
155                 for (String key : plmnInfo.mAllowedServicesInfo.keySet()) {
156                     if (key.equalsIgnoreCase("data")) {
157                         allowedServicesList.add(SERVICE_TYPE_DATA);
158                     } else if (key.equalsIgnoreCase("voice")) {
159                         allowedServicesList.add(SERVICE_TYPE_VOICE);
160                     }
161                 }
162                 // By default sms is added to the allowed services
163                 allowedServicesList.add(SERVICE_TYPE_SMS);
164                 availableServicesInfo.put(plmnInfo.mPlmn, allowedServicesList);
165             }
166         }
167         return availableServicesInfo;
168     }
169 
170     /**
171      * Get ServicePolicy for data at Allowed Services for the plmn List
172      *
173      * @return The Allowed Services for the plmn List
174      */
getDataServicePolicyInfoForPlmnList()175     public Map<String, Integer> getDataServicePolicyInfoForPlmnList() {
176         return getServicePolicyInfoForServiceType("data");
177     }
178 
179     /**
180      * Get ServicePolicy for voice at Allowed Services for the plmn List
181      *
182      * @return The Allowed Services for the plmn List
183      */
getVoiceServicePolicyInfoForPlmnList()184     public Map<String, Integer> getVoiceServicePolicyInfoForPlmnList() {
185         return getServicePolicyInfoForServiceType("voice");
186     }
187 
getServicePolicyInfoForServiceType(String serviceType)188     public Map<String, Integer> getServicePolicyInfoForServiceType(String serviceType) {
189         Map<String, Integer> servicePolicyInfo = new HashMap<>();
190         for (SatelliteNetworkInfo plmnInfo : mAllowedSatelliteNetworkInfoList) {
191             if (plmnInfo.mAllowedServicesInfo != null) {
192                 for (String key : plmnInfo.mAllowedServicesInfo.keySet()) {
193                     if (key.equalsIgnoreCase(serviceType)) {
194                         String servicePolicy = plmnInfo.mAllowedServicesInfo.get(key);
195                         if (servicePolicy.equalsIgnoreCase("constrained")) {
196                             servicePolicyInfo.put(plmnInfo.mPlmn,
197                                     SATELLITE_DATA_SUPPORT_BANDWIDTH_CONSTRAINED);
198                         } else if (servicePolicy.equalsIgnoreCase("unconstrained")) {
199                             servicePolicyInfo.put(plmnInfo.mPlmn, SATELLITE_DATA_SUPPORT_ALL);
200                         }
201                     }
202                 }
203             }
204         }
205         return servicePolicyInfo;
206     }
207 }
208