1 /* 2 * Copyright (C) 2022 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.phone.slice; 18 19 import android.annotation.IntDef; 20 import android.annotation.NonNull; 21 22 /** 23 * Response class containing the entitlement status, provisioning status, and service flow URL 24 * for premium network entitlement checks. 25 * 26 * The relationship between entitlement status (left column) and provision status (top row) 27 * is defined in the table below: 28 * +--------------+-----------------+-------------------+-------------------+-----------------+ 29 * | | Not Provisioned | Provisioned | Not Available | In Progress | 30 * +--------------+-----------------+-------------------+-------------------+-----------------+ 31 * | Disabled | Check failed | Check failed | Check failed | Check failed | 32 * +--------------+-----------------+-------------------+-------------------+-----------------+ 33 * | Enabled | Display webview | Already purchased | Already purchased | In progress | 34 * +--------------+-----------------+-------------------+-------------------+-----------------+ 35 * | Incompatible | Check failed | Check failed | Check failed | Check failed | 36 * +--------------+-----------------+-------------------+-------------------+-----------------+ 37 * | Provisioning | Carrier error | Carrier error | In progress | In progress | 38 * +--------------+-----------------+-------------------+-------------------+-----------------+ 39 * | Included | Carrier error | Already purchased | Already purchased | Carrier error | 40 * +--------------+-----------------+-------------------+-------------------+-----------------+ 41 */ 42 public class PremiumNetworkEntitlementResponse { 43 public static final int PREMIUM_NETWORK_ENTITLEMENT_STATUS_DISABLED = 0; 44 public static final int PREMIUM_NETWORK_ENTITLEMENT_STATUS_ENABLED = 1; 45 public static final int PREMIUM_NETWORK_ENTITLEMENT_STATUS_INCOMPATIBLE = 2; 46 public static final int PREMIUM_NETWORK_ENTITLEMENT_STATUS_PROVISIONING = 3; 47 public static final int PREMIUM_NETWORK_ENTITLEMENT_STATUS_INCLUDED = 4; 48 49 @IntDef(prefix = {"PREMIUM_NETWORK_ENTITLEMENT_STATUS_"}, value = { 50 PREMIUM_NETWORK_ENTITLEMENT_STATUS_DISABLED, 51 PREMIUM_NETWORK_ENTITLEMENT_STATUS_ENABLED, 52 PREMIUM_NETWORK_ENTITLEMENT_STATUS_INCOMPATIBLE, 53 PREMIUM_NETWORK_ENTITLEMENT_STATUS_PROVISIONING, 54 PREMIUM_NETWORK_ENTITLEMENT_STATUS_INCLUDED 55 }) 56 public @interface PremiumNetworkEntitlementStatus {} 57 58 public static final int PREMIUM_NETWORK_PROVISION_STATUS_NOT_PROVISIONED = 0; 59 public static final int PREMIUM_NETWORK_PROVISION_STATUS_PROVISIONED = 1; 60 public static final int PREMIUM_NETWORK_PROVISION_STATUS_NOT_AVAILABLE = 2; 61 public static final int PREMIUM_NETWORK_PROVISION_STATUS_IN_PROGRESS = 3; 62 63 @IntDef(prefix = {"PREMIUM_NETWORK_PROVISION_STATUS_"}, value = { 64 PREMIUM_NETWORK_PROVISION_STATUS_NOT_PROVISIONED, 65 PREMIUM_NETWORK_PROVISION_STATUS_PROVISIONED, 66 PREMIUM_NETWORK_PROVISION_STATUS_NOT_AVAILABLE, 67 PREMIUM_NETWORK_PROVISION_STATUS_IN_PROGRESS 68 }) 69 public @interface PremiumNetworkProvisionStatus {} 70 71 @PremiumNetworkEntitlementStatus public int mEntitlementStatus; 72 @PremiumNetworkProvisionStatus public int mProvisionStatus; 73 @NonNull public String mServiceFlowURL; 74 @NonNull public String mServiceFlowUserData; 75 @NonNull public String mServiceFlowContentsType; 76 77 /** 78 * @return {@code true} if the premium network is already purchased and {@code false} otherwise. 79 */ isAlreadyPurchased()80 public boolean isAlreadyPurchased() { 81 switch (mEntitlementStatus) { 82 case PREMIUM_NETWORK_ENTITLEMENT_STATUS_ENABLED: 83 case PREMIUM_NETWORK_ENTITLEMENT_STATUS_INCLUDED: 84 return mProvisionStatus == PREMIUM_NETWORK_PROVISION_STATUS_PROVISIONED 85 || mProvisionStatus == PREMIUM_NETWORK_PROVISION_STATUS_NOT_AVAILABLE; 86 } 87 return false; 88 } 89 90 /** 91 * @return {@code true} if provisioning the premium network is in progress and 92 * {@code false} otherwise. 93 */ isProvisioningInProgress()94 public boolean isProvisioningInProgress() { 95 switch (mEntitlementStatus) { 96 case PREMIUM_NETWORK_ENTITLEMENT_STATUS_ENABLED: 97 return mProvisionStatus == PREMIUM_NETWORK_PROVISION_STATUS_IN_PROGRESS; 98 case PREMIUM_NETWORK_ENTITLEMENT_STATUS_PROVISIONING: 99 return mProvisionStatus == PREMIUM_NETWORK_PROVISION_STATUS_IN_PROGRESS 100 || mProvisionStatus == PREMIUM_NETWORK_PROVISION_STATUS_NOT_AVAILABLE; 101 } 102 return false; 103 } 104 105 /** 106 * @return {@code true} if the premium network capability is allowed and 107 * {@code false} otherwise. 108 */ isPremiumNetworkCapabilityAllowed()109 public boolean isPremiumNetworkCapabilityAllowed() { 110 switch (mEntitlementStatus) { 111 case PREMIUM_NETWORK_ENTITLEMENT_STATUS_DISABLED: 112 case PREMIUM_NETWORK_ENTITLEMENT_STATUS_INCOMPATIBLE: 113 return false; 114 } 115 return !isInvalidResponse(); 116 } 117 118 /** 119 * @return {@code true} if the response is invalid and {@code false} if it is valid. 120 */ isInvalidResponse()121 public boolean isInvalidResponse() { 122 switch (mEntitlementStatus) { 123 case PREMIUM_NETWORK_ENTITLEMENT_STATUS_INCLUDED: 124 return mProvisionStatus == PREMIUM_NETWORK_PROVISION_STATUS_NOT_PROVISIONED 125 || mProvisionStatus == PREMIUM_NETWORK_PROVISION_STATUS_IN_PROGRESS; 126 case PREMIUM_NETWORK_ENTITLEMENT_STATUS_PROVISIONING: 127 return mProvisionStatus == PREMIUM_NETWORK_PROVISION_STATUS_NOT_PROVISIONED 128 || mProvisionStatus == PREMIUM_NETWORK_PROVISION_STATUS_PROVISIONED; 129 } 130 return false; 131 } 132 133 @Override toString()134 @NonNull public String toString() { 135 return "PremiumNetworkEntitlementResponse{mEntitlementStatus=" + mEntitlementStatus 136 + ", mProvisionStatus=" + mProvisionStatus + ", mServiceFlowURL=" + mServiceFlowURL 137 + ", mServiceFlowUserData=" + mServiceFlowUserData + ", mServiceFlowContentsType=" 138 + mServiceFlowContentsType + "}"; 139 } 140 } 141