1 /* 2 * Copyright (C) 2023 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 static com.android.imsserviceentitlement.ts43.Ts43Constants.ResponseXmlAttributes.ENTITLEMENT_STATUS; 20 import static com.android.imsserviceentitlement.ts43.Ts43Constants.ResponseXmlAttributes.NETWORK_VOICE_IRAT_CAPABILITY; 21 22 import com.android.imsserviceentitlement.utils.XmlDoc; 23 import com.android.imsserviceentitlement.ts43.Ts43Constants.EntitlementStatus; 24 25 import com.google.auto.value.AutoValue; 26 27 /** 28 * Implementation of Vonr entitlement status and server data availability for TS.43 entitlement 29 * solution. This class is only used to report the entitlement status of Vonr. 30 */ 31 @AutoValue 32 public abstract class Ts43VonrStatus { 33 /** The entitlement status of Vonr service in Home network. */ homeEntitlementStatus()34 public abstract int homeEntitlementStatus(); 35 36 /** The entitlement status of Vonr service in Roaming network.. */ roamingEntitlementStatus()37 public abstract int roamingEntitlementStatus(); 38 39 /** The voice rat capability status of vonr service in home network. */ homeNetworkVoiceIRatCapability()40 public abstract String homeNetworkVoiceIRatCapability(); 41 42 /** The voice rat capability status of vonr service in roaming network. */ roamingNetworkVoiceIRatCapability()43 public abstract String roamingNetworkVoiceIRatCapability(); 44 builder()45 public static Ts43VonrStatus.Builder builder() { 46 return new AutoValue_Ts43VonrStatus.Builder() 47 .setHomeEntitlementStatus(EntitlementStatus.INCOMPATIBLE) 48 .setRoamingNetworkVoiceIRatCapability("") 49 .setRoamingEntitlementStatus(EntitlementStatus.INCOMPATIBLE) 50 .setHomeNetworkVoiceIRatCapability(""); 51 } 52 builder(XmlDoc doc)53 public static Ts43VonrStatus.Builder builder(XmlDoc doc) { 54 return builder() 55 .setHomeEntitlementStatus( 56 doc.getFromVonrHome(ENTITLEMENT_STATUS) 57 .map(status -> Integer.parseInt(status)) 58 .orElse(EntitlementStatus.INCOMPATIBLE)) 59 .setHomeNetworkVoiceIRatCapability( 60 doc.getFromVonrHome(NETWORK_VOICE_IRAT_CAPABILITY).orElse("")) 61 .setRoamingEntitlementStatus( 62 doc.getFromVonrRoaming(ENTITLEMENT_STATUS) 63 .map(status -> Integer.parseInt(status)) 64 .orElse(EntitlementStatus.INCOMPATIBLE)) 65 .setRoamingNetworkVoiceIRatCapability( 66 doc.getFromVonrRoaming(NETWORK_VOICE_IRAT_CAPABILITY).orElse("")); 67 } 68 69 /** Builder of {@link Ts43VonrStatus}. */ 70 @AutoValue.Builder 71 public abstract static class Builder { build()72 public abstract Ts43VonrStatus build(); 73 setHomeEntitlementStatus(int entitlementStatus)74 public abstract Builder setHomeEntitlementStatus(int entitlementStatus); 75 setRoamingEntitlementStatus(int entitlementStatus)76 public abstract Builder setRoamingEntitlementStatus(int entitlementStatus); 77 setHomeNetworkVoiceIRatCapability( String networkVoiceIRatCapability)78 public abstract Builder setHomeNetworkVoiceIRatCapability( 79 String networkVoiceIRatCapability); 80 setRoamingNetworkVoiceIRatCapability( String networkVoiceIRatCapability)81 public abstract Builder setRoamingNetworkVoiceIRatCapability( 82 String networkVoiceIRatCapability); 83 } 84 isHomeActive()85 public boolean isHomeActive() { 86 return homeEntitlementStatus() == EntitlementStatus.ENABLED; 87 } 88 isRoamingActive()89 public boolean isRoamingActive() { 90 return roamingEntitlementStatus() == EntitlementStatus.ENABLED; 91 } 92 toString()93 public final String toString() { 94 return "Ts43VonrStatus {" 95 + "HomeEntitlementStatus=" 96 + homeEntitlementStatus() 97 + ", HomeNetworkVoiceIRatCapability=" 98 + homeNetworkVoiceIRatCapability() 99 + ", RomaingEntitlementStatus=" 100 + roamingEntitlementStatus() 101 + ", RoamingNetworkVoiceIRatCapability=" 102 + roamingNetworkVoiceIRatCapability() 103 + "}"; 104 } 105 } 106