1 /*
2  * Copyright (C) 2021 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.imsserviceentitlement.entitlement;
18 
19 import com.android.imsserviceentitlement.ts43.Ts43Constants.EntitlementStatus;
20 import com.android.imsserviceentitlement.ts43.Ts43SmsOverIpStatus;
21 import com.android.imsserviceentitlement.ts43.Ts43VolteStatus;
22 import com.android.imsserviceentitlement.ts43.Ts43VonrStatus;
23 import com.android.imsserviceentitlement.ts43.Ts43VowifiStatus;
24 
25 import com.google.auto.value.AutoValue;
26 
27 /** The result of the entitlement status check. */
28 @AutoValue
29 public abstract class EntitlementResult {
30     private static final Ts43VowifiStatus INACTIVE_VOWIFI_STATUS =
31             Ts43VowifiStatus.builder()
32                     .setEntitlementStatus(EntitlementStatus.INCOMPATIBLE)
33                     .setTcStatus(Ts43VowifiStatus.TcStatus.NOT_AVAILABLE)
34                     .setAddrStatus(Ts43VowifiStatus.AddrStatus.NOT_AVAILABLE)
35                     .setProvStatus(Ts43VowifiStatus.ProvStatus.NOT_PROVISIONED)
36                     .build();
37 
38     private static final Ts43VowifiStatus ACTIVE_VOWIFI_STATUS =
39             Ts43VowifiStatus.builder()
40                     .setEntitlementStatus(EntitlementStatus.ENABLED)
41                     .setTcStatus(Ts43VowifiStatus.TcStatus.NOT_REQUIRED)
42                     .setAddrStatus(Ts43VowifiStatus.AddrStatus.NOT_REQUIRED)
43                     .setProvStatus(Ts43VowifiStatus.ProvStatus.NOT_REQUIRED)
44                     .build();
45 
46     private static final Ts43VolteStatus INACTIVE_VOLTE_STATUS =
47             Ts43VolteStatus.builder()
48                     .setEntitlementStatus(EntitlementStatus.INCOMPATIBLE)
49                     .build();
50 
51     private static final Ts43VolteStatus ACTIVE_VOLTE_STATUS =
52             Ts43VolteStatus.builder()
53                     .setEntitlementStatus(EntitlementStatus.ENABLED)
54                     .build();
55 
56     private static final Ts43VonrStatus INACTIVE_VONR_STATUS =
57             Ts43VonrStatus.builder()
58                     .setHomeEntitlementStatus(EntitlementStatus.INCOMPATIBLE)
59                     .setRoamingEntitlementStatus(EntitlementStatus.INCOMPATIBLE)
60                     .build();
61 
62     private static final Ts43VonrStatus ACTIVE_VONR_STATUS =
63             Ts43VonrStatus.builder()
64                     .setHomeEntitlementStatus(EntitlementStatus.ENABLED)
65                     .setRoamingEntitlementStatus(EntitlementStatus.ENABLED)
66                     .build();
67 
68     private static final Ts43SmsOverIpStatus INACTIVE_SMSOVERIP_STATUS =
69             Ts43SmsOverIpStatus.builder()
70                     .setEntitlementStatus(EntitlementStatus.INCOMPATIBLE)
71                     .build();
72 
73     private static final Ts43SmsOverIpStatus ACTIVE_SMSOVERIP_STATUS =
74             Ts43SmsOverIpStatus.builder()
75                     .setEntitlementStatus(EntitlementStatus.ENABLED)
76                     .build();
77 
78     /** Returns a new {@link Builder} object. */
builder(boolean isDefaultEnabled)79     public static Builder builder(boolean isDefaultEnabled) {
80         return new AutoValue_EntitlementResult.Builder()
81                 .setVowifiStatus(isDefaultEnabled ? ACTIVE_VOWIFI_STATUS : INACTIVE_VOWIFI_STATUS)
82                 .setVolteStatus(isDefaultEnabled ? ACTIVE_VOLTE_STATUS : INACTIVE_VOLTE_STATUS)
83                 .setSmsoveripStatus(
84                         isDefaultEnabled ? ACTIVE_SMSOVERIP_STATUS : INACTIVE_SMSOVERIP_STATUS)
85                 .setVonrStatus(isDefaultEnabled ? ACTIVE_VONR_STATUS : INACTIVE_VONR_STATUS)
86                 .setEmergencyAddressWebUrl("")
87                 .setEmergencyAddressWebData("")
88                 .setTermsAndConditionsWebUrl("")
89                 .setRetryAfterSeconds(-1);
90     }
91 
92     /** The entitlement and service status of VoWiFi. */
getVowifiStatus()93     public abstract Ts43VowifiStatus getVowifiStatus();
94     /** The entitlement and service status of VoLTE. */
getVolteStatus()95     public abstract Ts43VolteStatus getVolteStatus();
96     /** The entitlement and service status of VoNR. */
getVonrStatus()97     public abstract Ts43VonrStatus getVonrStatus();
98     /** The entitlement and service status of SMSoIP. */
getSmsoveripStatus()99     public abstract Ts43SmsOverIpStatus getSmsoveripStatus();
100     /** The URL to the WFC emergency address web form. */
getEmergencyAddressWebUrl()101     public abstract String getEmergencyAddressWebUrl();
102     /** The data associated with the POST request to the WFC emergency address web form. */
getEmergencyAddressWebData()103     public abstract String getEmergencyAddressWebData();
104     /** The URL to the WFC T&C web form. */
getTermsAndConditionsWebUrl()105     public abstract String getTermsAndConditionsWebUrl();
106     /** Service temporary unavailable, retry the status check after a delay in seconds. */
getRetryAfterSeconds()107     public abstract long getRetryAfterSeconds();
108 
109     /** Builder of {@link EntitlementResult}. */
110     @AutoValue.Builder
111     public abstract static class Builder {
build()112         public abstract EntitlementResult build();
setVowifiStatus(Ts43VowifiStatus vowifiStatus)113         public abstract Builder setVowifiStatus(Ts43VowifiStatus vowifiStatus);
setVolteStatus(Ts43VolteStatus volteStatus)114         public abstract Builder setVolteStatus(Ts43VolteStatus volteStatus);
setVonrStatus(Ts43VonrStatus vonrStatus)115         public abstract Builder setVonrStatus(Ts43VonrStatus vonrStatus);
setSmsoveripStatus(Ts43SmsOverIpStatus smsoveripStatus)116         public abstract Builder setSmsoveripStatus(Ts43SmsOverIpStatus smsoveripStatus);
setEmergencyAddressWebUrl(String emergencyAddressWebUrl)117         public abstract Builder setEmergencyAddressWebUrl(String emergencyAddressWebUrl);
setEmergencyAddressWebData(String emergencyAddressWebData)118         public abstract Builder setEmergencyAddressWebData(String emergencyAddressWebData);
setTermsAndConditionsWebUrl(String termsAndConditionsWebUrl)119         public abstract Builder setTermsAndConditionsWebUrl(String termsAndConditionsWebUrl);
setRetryAfterSeconds(long retryAfter)120         public abstract Builder setRetryAfterSeconds(long retryAfter);
121     }
122 
123     @Override
toString()124     public final String toString() {
125         StringBuilder builder = new StringBuilder("EntitlementResult{");
126         builder.append(",getVowifiStatus=").append(getVowifiStatus());
127         builder.append(",getVolteStatus=").append(getVolteStatus());
128         builder.append(",getVonrStatus=").append(getVonrStatus());
129         builder.append(",getSmsoveripStatus=").append(getSmsoveripStatus());
130         builder.append(",getEmergencyAddressWebUrl=").append(opaque(getEmergencyAddressWebUrl()));
131         builder.append(",getEmergencyAddressWebData=").append(opaque(getEmergencyAddressWebData()));
132         builder.append(",getTermsAndConditionsWebUrl=").append(getTermsAndConditionsWebUrl());
133         builder.append(",getRetryAfter=").append(getRetryAfterSeconds());
134         builder.append("}");
135         return builder.toString();
136     }
137 
opaque(String string)138     private static String opaque(String string) {
139         if (string == null) {
140             return "null";
141         }
142         return "string_of_length_" + string.length();
143     }
144 }
145