aboutsummaryrefslogtreecommitdiff
path: root/java/com/android/libraries/entitlement/odsa/CheckEligibilityOperation.java
blob: bd609bfd9d3f3618116c69c75910fe804511d6aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
/*
 * Copyright (C) 2023 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.libraries.entitlement.odsa;

import androidx.annotation.IntDef;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.android.libraries.entitlement.odsa.OdsaOperation.CompanionService;
import com.android.libraries.entitlement.utils.HttpConstants;
import com.android.libraries.entitlement.utils.HttpConstants.ContentType;
import com.android.libraries.entitlement.utils.Ts43Constants;
import com.android.libraries.entitlement.utils.Ts43Constants.AppId;
import com.android.libraries.entitlement.utils.Ts43Constants.NotificationAction;

import com.google.auto.value.AutoValue;
import com.google.common.collect.ImmutableList;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.net.URL;

/** Check eligibility operation described in GSMA Service Entitlement Configuration section 6. */
public final class CheckEligibilityOperation {
    /** ODSA app check eligibility result unknown. */
    public static final int ELIGIBILITY_RESULT_UNKNOWN = -1;

    /** ODSA app cannot be offered and invoked by the end-user. */
    public static final int ELIGIBILITY_RESULT_DISABLED = 0;

    /** ODSA app can be invoked by end-user or to activate a new subscription. */
    public static final int ELIGIBILITY_RESULT_ENABLED = 1;

    /** ODSA app is not compatible with the device or server. */
    public static final int ELIGIBILITY_RESULT_INCOMPATIBLE = 2;

    @Retention(RetentionPolicy.SOURCE)
    @IntDef({
            ELIGIBILITY_RESULT_UNKNOWN,
            ELIGIBILITY_RESULT_DISABLED,
            ELIGIBILITY_RESULT_ENABLED,
            ELIGIBILITY_RESULT_INCOMPATIBLE
    })
    public @interface EligibilityResult {
    }

    /**
     * HTTP request parameters specific to on device service activation (ODSA).
     * See GSMA spec TS.43 section 6.2.
     */
    @AutoValue
    public abstract static class CheckEligibilityRequest {
        /**
         * Returns the application id. Can only be {@link Ts43Constants#APP_ODSA_COMPANION},
         * {@link Ts43Constants#APP_ODSA_PRIMARY}, or
         * {@link Ts43Constants#APP_ODSA_SERVER_INITIATED_REQUESTS}.
         */
        @AppId
        public abstract String appId();

        /**
         * Returns the unique identifier of the companion device, like IMEI. Used by HTTP parameter
         * {@code companion_terminal_id}.
         */
        @NonNull
        public abstract String companionTerminalId();

        /**
         * Returns the OEM of the companion device. Used by HTTP parameter
         * {@code companion_terminal_vendor}.
         */
        @NonNull
        public abstract String companionTerminalVendor();

        /**
         * Returns the model of the companion device. Used by HTTP parameter
         * {@code companion_terminal_model}.
         */
        @NonNull
        public abstract String companionTerminalModel();

        /**
         * Returns the software version of the companion device. Used by HTTP parameter
         * {@code companion_terminal_sw_version}.
         */
        @NonNull
        public abstract String companionTerminalSoftwareVersion();

        /**
         * Returns the user-friendly version of the companion device. Used by HTTP parameter
         * {@code companion_terminal_friendly_name}.
         */
        @NonNull
        public abstract String companionTerminalFriendlyName();

        /**
         * Returns the notification token used to register for entitlement configuration request
         * from network. Used by HTTP parameter {@code notif_token}.
         */
        @NonNull
        public abstract String notificationToken();

        /**
         * Returns the action associated with the notification token. Used by HTTP parameter
         * {@code notif_action}.
         */
        @NotificationAction
        public abstract int notificationAction();

        /** Returns a new {@link Builder} object. */
        @NonNull
        public static Builder builder() {
            return new AutoValue_CheckEligibilityOperation_CheckEligibilityRequest.Builder()
                    .setAppId(Ts43Constants.APP_UNKNOWN)
                    .setCompanionTerminalId("")
                    .setCompanionTerminalVendor("")
                    .setCompanionTerminalModel("")
                    .setCompanionTerminalSoftwareVersion("")
                    .setCompanionTerminalFriendlyName("")
                    .setNotificationToken("")
                    .setNotificationAction(Ts43Constants.NOTIFICATION_ACTION_ENABLE_FCM);
        }

        /** Builder */
        @AutoValue.Builder
        public abstract static class Builder {
            /**
             * Sets the application id.
             *
             * @param appId The application id. Can only be
             *              {@link Ts43Constants#APP_ODSA_COMPANION},
             *              {@link Ts43Constants#APP_ODSA_PRIMARY}, or {@link
             *              Ts43Constants#APP_ODSA_SERVER_INITIATED_REQUESTS}.
             * @return The builder.
             */
            @NonNull
            public abstract Builder setAppId(@NonNull @AppId String appId);

            /**
             * Sets the unique identifier of the companion device, like IMEI. Used by HTTP parameter
             * {@code companion_terminal_id} if set.
             *
             * <p>Used by companion device ODSA operation.
             *
             * @param companionTerminalId The unique identifier of the companion device.
             * @return The builder.
             */
            @NonNull
            public abstract Builder setCompanionTerminalId(@NonNull String companionTerminalId);

            /**
             * Sets the OEM of the companion device. Used by HTTP parameter
             * {@code companion_terminal_vendor} if set.
             *
             * <p>Used by companion device ODSA operation.
             *
             * @param companionTerminalVendor The OEM of the companion device.
             * @return The builder.
             */
            @NonNull
            public abstract Builder setCompanionTerminalVendor(
                    @NonNull String companionTerminalVendor);

            /**
             * Sets the model of the companion device. Used by HTTP parameter
             * {@code companion_terminal_model} if set.
             *
             * <p>Used by companion device ODSA operation.
             *
             * @param companionTerminalModel The model of the companion device.
             * @return The builder.
             */
            @NonNull
            public abstract Builder setCompanionTerminalModel(
                    @NonNull String companionTerminalModel);

            /**
             * Sets the software version of the companion device. Used by HTTP parameter
             * {@code companion_terminal_sw_version} if set.
             *
             * <p>Used by companion device ODSA operation.
             *
             * @param companionTerminalSoftwareVersion The software version of the companion device.
             * @return The builder.
             */
            @NonNull
            public abstract Builder setCompanionTerminalSoftwareVersion(
                    @NonNull String companionTerminalSoftwareVersion);

            /**
             * Sets the user-friendly version of the companion device. Used by HTTP parameter
             * {@code companion_terminal_friendly_name} if set.
             *
             * <p>Used by companion device ODSA operation.
             *
             * @param companionTerminalFriendlyName The user-friendly version of the companion
             *                                      device.
             * @return The builder.
             */
            @NonNull
            public abstract Builder setCompanionTerminalFriendlyName(
                    @NonNull String companionTerminalFriendlyName);

            /**
             * Sets the notification token used to register for entitlement configuration request
             * from network. Used by HTTP parameter {@code notif_token} if set.
             *
             * <p>Used by primary device ODSA operation.
             *
             * @param notificationToken The notification token used to register for entitlement
             *                          configuration request from network.
             * @return The builder.
             */
            @NonNull
            public abstract Builder setNotificationToken(@NonNull String notificationToken);

            /**
             * Sets the action associated with the notification token. Used by HTTP parameter
             * {@code notif_action} if set.
             *
             * <p>Used by primary device ODSA operation.
             *
             * @param notificationAction The action associated with the notification token.
             * @return The builder.
             */
            @NonNull
            public abstract Builder setNotificationAction(
                    @NotificationAction int notificationAction);

            /** Returns the {@link CheckEligibilityRequest} object. */
            @NonNull
            public abstract CheckEligibilityRequest build();
        }
    }

    /**
     * Check eligibility response described in GSMA Service Entitlement Configuration section 6.5.2.
     */
    @AutoValue
    public abstract static class CheckEligibilityResponse extends OdsaResponse {
        /** Returns the result of check eligibility request. */
        @EligibilityResult
        public abstract int appEligibility();

        /** Indicates the applicable companion device services. */
        @NonNull
        @CompanionService
        public abstract ImmutableList<String> companionDeviceServices();

        /**
         * The provided URL shall present a web view to user on the reason(s) why the ODSA app
         * cannot be used/invoked.
         */
        @Nullable
        public abstract URL notEnabledUrl();

        /**
         * User data sent to the Service Provider when requesting the {@link #notEnabledUrl()} web
         * view. It should contain user-specific attributes to improve user experience. The format
         * must follow the {@link #notEnabledContentsType()} parameter. For content types of
         * {@code JSON} and {@code XML}, it is possible to provide the base64 encoding of the value
         * by preceding it with {@code encodedValue=}.
         */
        @NonNull
        public abstract String notEnabledUserData();

        /**
         * Specifies content and HTTP method to use when reaching out to the web server specified in
         * {@link #notEnabledUrl()}.
         */
        @ContentType
        public abstract int notEnabledContentsType();

        /** Returns the builder. */
        public static Builder builder() {
            return new AutoValue_CheckEligibilityOperation_CheckEligibilityResponse.Builder()
                    .setAppEligibility(ELIGIBILITY_RESULT_UNKNOWN)
                    .setCompanionDeviceServices(ImmutableList.of())
                    .setNotEnabledUserData("")
                    .setNotEnabledContentsType(HttpConstants.UNKNOWN);
        }

        /** The builder. */
        @AutoValue.Builder
        public abstract static class Builder extends OdsaResponse.Builder {
            /**
             * Set the eligibility.
             *
             * @param eligibility The result of check eligibility request.
             * @return The builder.
             */
            @NonNull
            public abstract Builder setAppEligibility(@EligibilityResult int eligibility);

            /**
             * Set the companion device services.
             *
             * @param companionDeviceServices The applicable companion device services.
             * @return The builder.
             */
            @NonNull
            public abstract Builder setCompanionDeviceServices(
                    @NonNull @CompanionService ImmutableList<String> companionDeviceServices);

            /**
             * Set the URL presenting a web view to user on the reason(s) why the ODSA app cannot be
             * used/invoked.
             *
             * @param url The provided URL shall present a web view to user on the reason(s) why the
             *            ODSA app cannot be used/invoked.
             * @return The builder.
             */
            @NonNull
            public abstract Builder setNotEnabledUrl(@NonNull URL url);

            /**
             * Set the user data sent to the Service Provider when requesting the
             * {@link #notEnabledUrl()} web view.
             *
             * @param notEnabledUserData User data sent to the Service Provider when requesting the
             *                           {@link #notEnabledUrl()} web view. It should contain
             *                           user-specific attributes to improve user experience. The
             *                           format must follow the {@link #notEnabledContentsType()}
             *                           parameter. For content types of {@link HttpConstants#JSON}
             *                           and {@link HttpConstants#XML}, it is possible to provide
             *                           the base64 encoding of the value by preceding it with
             *                           {@code encodedValue=}.
             * @return The builder.
             */
            @NonNull
            public abstract Builder setNotEnabledUserData(@NonNull String notEnabledUserData);

            /**
             * Set the content and HTTP method to use when reaching out to the web server specified
             * in {@link #notEnabledUrl()}.
             *
             * @param notEnabledContentsType Specifies content and HTTP method to use when reaching
             *                               out to the web server specified in
             *                               {@link #notEnabledUrl()}.
             * @return The builder.
             */
            @NonNull
            public abstract Builder setNotEnabledContentsType(
                    @ContentType int notEnabledContentsType);

            /** Build the {@link CheckEligibilityResponse} object. */
            public abstract CheckEligibilityResponse build();
        }
    }

    private CheckEligibilityOperation() {
    }
}