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