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.libraries.entitlement.utils; 18 19 import androidx.annotation.IntDef; 20 import androidx.annotation.NonNull; 21 import androidx.annotation.StringDef; 22 23 import java.lang.annotation.Retention; 24 import java.lang.annotation.RetentionPolicy; 25 26 /** Defines the constants used for TS43 operations. */ 27 public final class Ts43Constants { 28 /** App ID unknown. For initialization only. */ 29 public static final String APP_UNKNOWN = ""; 30 31 /** App ID for Voice-Over-LTE entitlement. */ 32 public static final String APP_VOLTE = "ap2003"; 33 34 /** App ID for Voice-Over-WiFi entitlement. */ 35 public static final String APP_VOWIFI = "ap2004"; 36 37 /** App ID for SMS-Over-IP entitlement. */ 38 public static final String APP_SMSOIP = "ap2005"; 39 40 /** App ID for on device service activation (ODSA) for companion device. */ 41 public static final String APP_ODSA_COMPANION = "ap2006"; 42 43 /** App ID for on device service activation (ODSA) for primary device. */ 44 public static final String APP_ODSA_PRIMARY = "ap2009"; 45 46 /** App ID for data plan information entitlement. */ 47 public static final String APP_DATA_PLAN_BOOST = "ap2010"; 48 49 /** App ID for server initiated requests, entitlement and activation. */ 50 public static final String APP_ODSA_SERVER_INITIATED_REQUESTS = "ap2011"; 51 52 /** App ID for direct carrier billing. */ 53 public static final String APP_DIRECT_CARRIER_BILLING = "ap2012"; 54 55 /** App ID for private user identity. */ 56 public static final String APP_PRIVATE_USER_IDENTITY = "ap2013"; 57 58 /** App ID for phone number information. */ 59 public static final String APP_PHONE_NUMBER_INFORMATION = "ap2014"; 60 61 /** App ID for satellite entitlement. */ 62 public static final String APP_SATELLITE_ENTITLEMENT = "ap2016"; 63 64 /** 65 * App ID for ODSA for Cross-TS.43 platform device, Entitlement and Activation 66 * 67 * @deprecated use {@code target_terminal_entitlement_protocol} and 68 * {@code old_terminal_entitlement_protocol} in the request instead. 69 */ 70 @Deprecated 71 public static final String APP_ODSA_CROSS_TS43 = "ap2017"; 72 73 @Retention(RetentionPolicy.SOURCE) 74 @StringDef({ 75 APP_UNKNOWN, 76 APP_VOLTE, 77 APP_VOWIFI, 78 APP_SMSOIP, 79 APP_ODSA_COMPANION, 80 APP_ODSA_PRIMARY, 81 APP_DATA_PLAN_BOOST, 82 APP_ODSA_SERVER_INITIATED_REQUESTS, 83 APP_DIRECT_CARRIER_BILLING, 84 APP_PRIVATE_USER_IDENTITY, 85 APP_PHONE_NUMBER_INFORMATION, 86 APP_SATELLITE_ENTITLEMENT, 87 APP_ODSA_CROSS_TS43 88 }) 89 public @interface AppId { 90 } 91 92 /** 93 * Check if the application id is valid. 94 * 95 * @param appId The application id. 96 * @return {@code true} if valid, otherwise {@code false}. 97 */ isValidAppId(@onNull @ppId String appId)98 public static boolean isValidAppId(@NonNull @AppId String appId) { 99 switch (appId) { 100 case APP_VOLTE: 101 case APP_VOWIFI: 102 case APP_SMSOIP: 103 case APP_ODSA_COMPANION: 104 case APP_ODSA_PRIMARY: 105 case APP_DATA_PLAN_BOOST: 106 case APP_ODSA_SERVER_INITIATED_REQUESTS: 107 case APP_DIRECT_CARRIER_BILLING: 108 case APP_PRIVATE_USER_IDENTITY: 109 case APP_PHONE_NUMBER_INFORMATION: 110 case APP_SATELLITE_ENTITLEMENT: 111 case APP_ODSA_CROSS_TS43: 112 return true; 113 default: // fall through 114 } 115 return false; 116 } 117 118 /** 119 * Action to disable notification token. 120 */ 121 public static final int NOTIFICATION_ACTION_DISABLE = 0; 122 123 /** 124 * Action to enable GCM notification token. 125 */ 126 public static final int NOTIFICATION_ACTION_ENABLE_GCM = 1; 127 128 /** 129 * Action to enable FCM notification token. 130 */ 131 public static final int NOTIFICATION_ACTION_ENABLE_FCM = 2; 132 133 /** 134 * Action to enable WNS push notification token. 135 */ 136 public static final int NOTIFICATION_ACTION_ENABLE_WNS = 3; 137 138 /** 139 * Action to enable APNS notification token. 140 */ 141 public static final int NOTIFICATION_ACTION_ENABLE_APNS = 4; 142 143 @Retention(RetentionPolicy.SOURCE) 144 @IntDef({ 145 NOTIFICATION_ACTION_DISABLE, 146 NOTIFICATION_ACTION_ENABLE_GCM, 147 NOTIFICATION_ACTION_ENABLE_FCM, 148 NOTIFICATION_ACTION_ENABLE_WNS, 149 NOTIFICATION_ACTION_ENABLE_APNS, 150 }) 151 public @interface NotificationAction {} 152 153 /** 154 * Check if the notification action is valid. 155 * 156 * @param notificationAction The notification action. 157 * @return {@code true} if valid, otherwise {@code false}. 158 */ isValidNotificationAction(@otificationAction int notificationAction)159 public static boolean isValidNotificationAction(@NotificationAction int notificationAction) { 160 switch (notificationAction) { 161 case NOTIFICATION_ACTION_DISABLE: 162 case NOTIFICATION_ACTION_ENABLE_GCM: 163 case NOTIFICATION_ACTION_ENABLE_FCM: 164 case NOTIFICATION_ACTION_ENABLE_WNS: 165 case NOTIFICATION_ACTION_ENABLE_APNS: 166 return true; 167 default: // fall through 168 } 169 return false; 170 } 171 172 /** Default entitlement version. */ 173 public static final String DEFAULT_ENTITLEMENT_VERSION = "2.0"; 174 Ts43Constants()175 private Ts43Constants() { 176 } 177 } 178