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.ts43;
18 
19 import com.android.imsserviceentitlement.ts43.Ts43Constants.EntitlementStatus;
20 import com.android.imsserviceentitlement.ts43.Ts43Constants.ResponseXmlAttributes;
21 import com.android.imsserviceentitlement.utils.XmlDoc;
22 
23 import com.google.auto.value.AutoValue;
24 
25 /**
26  * Implementation of Vowifi entitlement status and server data availability for TS.43 entitlement
27  * solution. This class is only used to report the entitlement status of Vowifi.
28  */
29 @AutoValue
30 public abstract class Ts43VowifiStatus {
31     /** The emergency address status of vowifi service. */
32     public static class AddrStatus {
AddrStatus()33         public AddrStatus() {}
34 
35         public static final int NOT_AVAILABLE = 0;
36         public static final int AVAILABLE = 1;
37         public static final int NOT_REQUIRED = 2;
38         public static final int IN_PROGRESS = 3;
39     }
40 
41     /** The terms and condition status of vowifi service. */
42     public static class TcStatus {
TcStatus()43         public TcStatus() {}
44 
45         public static final int NOT_AVAILABLE = 0;
46         public static final int AVAILABLE = 1;
47         public static final int NOT_REQUIRED = 2;
48         public static final int IN_PROGRESS = 3;
49     }
50 
51     /** The provision status of vowifi service. */
52     public static class ProvStatus {
ProvStatus()53         public ProvStatus() {}
54 
55         public static final int NOT_PROVISIONED = 0;
56         public static final int PROVISIONED = 1;
57         public static final int NOT_REQUIRED = 2;
58         public static final int IN_PROGRESS = 3;
59     }
60 
61     /** The entitlement status of vowifi service. */
entitlementStatus()62     public abstract int entitlementStatus();
63     /** The terms and condition status of vowifi service. */
tcStatus()64     public abstract int tcStatus();
65     /** The emergency address status of vowifi service. */
addrStatus()66     public abstract int addrStatus();
67     /** The provision status of vowifi service. */
provStatus()68     public abstract int provStatus();
69 
builder()70     public static Ts43VowifiStatus.Builder builder() {
71         return new AutoValue_Ts43VowifiStatus.Builder()
72                 .setEntitlementStatus(EntitlementStatus.DISABLED)
73                 .setTcStatus(TcStatus.NOT_AVAILABLE)
74                 .setAddrStatus(AddrStatus.NOT_AVAILABLE)
75                 .setProvStatus(ProvStatus.NOT_PROVISIONED);
76     }
77 
builder(XmlDoc doc)78     public static Ts43VowifiStatus.Builder builder(XmlDoc doc) {
79         return builder()
80                 .setEntitlementStatus(
81                         doc.getFromVowifi(ResponseXmlAttributes.ENTITLEMENT_STATUS)
82                                 .map(status -> Integer.parseInt(status))
83                                 .orElse(EntitlementStatus.INCOMPATIBLE))
84                 .setTcStatus(
85                         doc.getFromVowifi(ResponseXmlAttributes.TC_STATUS)
86                                 .map(status -> Integer.parseInt(status))
87                                 .orElse(TcStatus.NOT_REQUIRED))
88                 .setAddrStatus(
89                         doc.getFromVowifi(ResponseXmlAttributes.ADDR_STATUS)
90                                 .map(status -> Integer.parseInt(status))
91                                 .orElse(AddrStatus.NOT_REQUIRED))
92                 .setProvStatus(
93                         doc.getFromVowifi(ResponseXmlAttributes.PROVISION_STATUS)
94                                 .map(status -> Integer.parseInt(status))
95                                 .orElse(ProvStatus.NOT_REQUIRED));
96     }
97 
98     /** Builder of {@link Ts43VowifiStatus}. */
99     @AutoValue.Builder
100     public abstract static class Builder {
build()101         public abstract Ts43VowifiStatus build();
102 
setEntitlementStatus(int entitlementStatus)103         public abstract Builder setEntitlementStatus(int entitlementStatus);
104 
setTcStatus(int tcStatus)105         public abstract Builder setTcStatus(int tcStatus);
106 
setAddrStatus(int addrStatus)107         public abstract Builder setAddrStatus(int addrStatus);
108 
setProvStatus(int provStatus)109         public abstract Builder setProvStatus(int provStatus);
110     }
111 
vowifiEntitled()112     public boolean vowifiEntitled() {
113         return entitlementStatus() == EntitlementStatus.ENABLED
114                 && (provStatus() == ProvStatus.PROVISIONED
115                 || provStatus() == ProvStatus.NOT_REQUIRED)
116                 && (tcStatus() == TcStatus.AVAILABLE || tcStatus() == TcStatus.NOT_REQUIRED)
117                 && (addrStatus() == AddrStatus.AVAILABLE
118                 || addrStatus() == AddrStatus.NOT_REQUIRED);
119     }
120 
serverDataMissing()121     public boolean serverDataMissing() {
122         return entitlementStatus() == EntitlementStatus.DISABLED
123                 && (tcStatus() == TcStatus.NOT_AVAILABLE
124                 || addrStatus() == AddrStatus.NOT_AVAILABLE);
125     }
126 
inProgress()127     public boolean inProgress() {
128         return entitlementStatus() == EntitlementStatus.PROVISIONING
129                 || (entitlementStatus() == EntitlementStatus.DISABLED
130                 && (tcStatus() == TcStatus.IN_PROGRESS || addrStatus() == AddrStatus.IN_PROGRESS))
131                 || (entitlementStatus() == EntitlementStatus.DISABLED
132                 && (provStatus() == ProvStatus.NOT_PROVISIONED
133                 || provStatus() == ProvStatus.IN_PROGRESS)
134                 && (tcStatus() == TcStatus.AVAILABLE || tcStatus() == TcStatus.NOT_REQUIRED)
135                 && (addrStatus() == AddrStatus.AVAILABLE
136                 || addrStatus() == AddrStatus.NOT_REQUIRED));
137     }
138 
incompatible()139     public boolean incompatible() {
140         return entitlementStatus() == EntitlementStatus.INCOMPATIBLE;
141     }
142 
143     @Override
toString()144     public final String toString() {
145         return "Ts43VowifiStatus {"
146                 + "entitlementStatus="
147                 + entitlementStatus()
148                 + ",tcStatus="
149                 + tcStatus()
150                 + ",addrStatus="
151                 + addrStatus()
152                 + ",provStatus="
153                 + provStatus()
154                 + "}";
155     }
156 }
157