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 Volte entitlement status and server data availability for TS.43 entitlement
27  * solution. This class is only used to report the entitlement status of Volte.
28  */
29 @AutoValue
30 public abstract class Ts43VolteStatus {
31     /** The entitlement status of Volte service. */
entitlementStatus()32     public abstract int entitlementStatus();
33 
builder()34     public static Ts43VolteStatus.Builder builder() {
35         return new AutoValue_Ts43VolteStatus.Builder()
36                 .setEntitlementStatus(EntitlementStatus.DISABLED);
37     }
38 
builder(XmlDoc doc)39     public static Ts43VolteStatus.Builder builder(XmlDoc doc) {
40         return builder()
41                 .setEntitlementStatus(
42                         doc.getFromVolte(ResponseXmlAttributes.ENTITLEMENT_STATUS)
43                                 .map(status -> Integer.parseInt(status))
44                                 .orElse(EntitlementStatus.INCOMPATIBLE));
45     }
46 
47     /** Builder of {@link Ts43VolteStatus}. */
48     @AutoValue.Builder
49     public abstract static class Builder {
build()50         public abstract Ts43VolteStatus build();
51 
setEntitlementStatus(int entitlementStatus)52         public abstract Builder setEntitlementStatus(int entitlementStatus);
53     }
54 
isActive()55     public boolean isActive() {
56         return entitlementStatus() == EntitlementStatus.ENABLED;
57     }
58 
toString()59     public final String toString() {
60         return "Ts43VolteStatus {"
61                 + "entitlementStatus="
62                 + entitlementStatus()
63                 + "}";
64     }
65 }
66