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     @Retention(RetentionPolicy.SOURCE)
65     @StringDef({
66             APP_UNKNOWN,
67             APP_VOLTE,
68             APP_VOWIFI,
69             APP_SMSOIP,
70             APP_ODSA_COMPANION,
71             APP_ODSA_PRIMARY,
72             APP_DATA_PLAN_BOOST,
73             APP_ODSA_SERVER_INITIATED_REQUESTS,
74             APP_DIRECT_CARRIER_BILLING,
75             APP_PRIVATE_USER_IDENTITY,
76             APP_PHONE_NUMBER_INFORMATION,
77             APP_SATELLITE_ENTITLEMENT
78     })
79     public @interface AppId {
80     }
81 
82     /**
83      * Check if the application id is valid.
84      *
85      * @param appId The application id.
86      * @return {@code true} if valid, otherwise {@code false}.
87      */
isValidAppId(@onNull @ppId String appId)88     public static boolean isValidAppId(@NonNull @AppId String appId) {
89         switch (appId) {
90             case APP_VOLTE:
91             case APP_VOWIFI:
92             case APP_SMSOIP:
93             case APP_ODSA_COMPANION:
94             case APP_ODSA_PRIMARY:
95             case APP_DATA_PLAN_BOOST:
96             case APP_ODSA_SERVER_INITIATED_REQUESTS:
97             case APP_DIRECT_CARRIER_BILLING:
98             case APP_PRIVATE_USER_IDENTITY:
99             case APP_PHONE_NUMBER_INFORMATION:
100             case APP_SATELLITE_ENTITLEMENT:
101                 return true;
102             default: // fall through
103         }
104         return false;
105     }
106 
107     /**
108      * Action to disable notification token.
109      */
110     public static final int NOTIFICATION_ACTION_DISABLE = 0;
111 
112     /**
113      * Action to enable GCM notification token.
114      */
115     public static final int NOTIFICATION_ACTION_ENABLE_GCM = 1;
116 
117     /**
118      * Action to enable FCM notification token.
119      */
120     public static final int NOTIFICATION_ACTION_ENABLE_FCM = 2;
121 
122     /**
123      * Action to enable WNS push notification token.
124      */
125     public static final int NOTIFICATION_ACTION_ENABLE_WNS = 3;
126 
127     /**
128      * Action to enable APNS notification token.
129      */
130     public static final int NOTIFICATION_ACTION_ENABLE_APNS = 4;
131 
132     @Retention(RetentionPolicy.SOURCE)
133     @IntDef({
134             NOTIFICATION_ACTION_DISABLE,
135             NOTIFICATION_ACTION_ENABLE_GCM,
136             NOTIFICATION_ACTION_ENABLE_FCM,
137             NOTIFICATION_ACTION_ENABLE_WNS,
138             NOTIFICATION_ACTION_ENABLE_APNS,
139     })
140     public @interface NotificationAction {}
141 
142     /**
143      * Check if the notification action is valid.
144      *
145      * @param notificationAction The notification action.
146      * @return {@code true} if valid, otherwise {@code false}.
147      */
isValidNotificationAction(@otificationAction int notificationAction)148     public static boolean isValidNotificationAction(@NotificationAction int notificationAction) {
149         switch (notificationAction) {
150             case NOTIFICATION_ACTION_DISABLE:
151             case NOTIFICATION_ACTION_ENABLE_GCM:
152             case NOTIFICATION_ACTION_ENABLE_FCM:
153             case NOTIFICATION_ACTION_ENABLE_WNS:
154             case NOTIFICATION_ACTION_ENABLE_APNS:
155                 return true;
156             default: // fall through
157         }
158         return false;
159     }
160 
161     /** Default entitlement version. */
162     public static final String DEFAULT_ENTITLEMENT_VERSION = "2.0";
163 
Ts43Constants()164     private Ts43Constants() {
165     }
166 }