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.odsa; 18 19 import androidx.annotation.NonNull; 20 import androidx.annotation.StringDef; 21 22 import com.google.auto.value.AutoValue; 23 24 import java.lang.annotation.Retention; 25 import java.lang.annotation.RetentionPolicy; 26 27 /** 28 * MSG information described in GSMA Service Entitlement Configuration section 6.5.5 table 43. 29 */ 30 @AutoValue 31 public abstract class MessageInfo { 32 /** Indicates the button or freetext is absent. */ 33 public static final String MESSAGE_VALUE_ABSENT = "0"; 34 35 /** Indicates the button or freetext is present. */ 36 public static final String MESSAGE_VALUE_PRESENT = "1"; 37 38 @Retention(RetentionPolicy.SOURCE) 39 @StringDef({ 40 MESSAGE_VALUE_ABSENT, 41 MESSAGE_VALUE_PRESENT 42 }) 43 public @interface MessageValue { 44 } 45 46 /** The message that is displayed to the user. */ 47 @NonNull message()48 public abstract String message(); 49 50 /** 51 * Whether an {@code Accept} button is shown with the {@link #message()} on device UI. 52 * The action associated with the {@code Accept} button on the device/client is to clear the 53 * message box. 54 */ 55 @NonNull 56 @MessageValue acceptButton()57 public abstract String acceptButton(); 58 59 /** The label for the {@code Accept} button to be presented to the user. */ 60 @NonNull acceptButtonLabel()61 public abstract String acceptButtonLabel(); 62 63 /** 64 * Whether a {@code Reject} button is shown with the {@link #message()} on device UI. 65 * The action associated with the {@code Reject} button on the device/client is to revert the 66 * configured services to their defined default behaviour. 67 */ 68 @NonNull 69 @MessageValue rejectButton()70 public abstract String rejectButton(); 71 72 /** The label for the {@code Reject} button to be presented to the user. */ 73 @NonNull rejectButtonLabel()74 public abstract String rejectButtonLabel(); 75 76 /** Whether a free text entry field is shown with the message on device UI. */ 77 @NonNull 78 @MessageValue acceptFreetext()79 public abstract String acceptFreetext(); 80 81 /** Returns builder of {@link MessageInfo}. */ 82 @NonNull builder()83 public static Builder builder() { 84 return new AutoValue_MessageInfo.Builder() 85 .setMessage("") 86 .setAcceptButton("") 87 .setAcceptButtonLabel("") 88 .setRejectButton("") 89 .setRejectButtonLabel("") 90 .setAcceptFreetext(""); 91 } 92 93 /** Builder of MessageInfo. */ 94 @AutoValue.Builder 95 public abstract static class Builder { 96 /** 97 * Set the message that is displayed to the user. 98 * 99 * @param message The message to display to the user. 100 * @return The builder. 101 */ 102 @NonNull setMessage(@onNull String message)103 public abstract Builder setMessage(@NonNull String message); 104 105 /** 106 * Set whether an {@code Accept} button is shown with the {@link #message()} on device UI. 107 * 108 * @param button {@link #MESSAGE_VALUE_PRESENT} to show and 109 * {@link #MESSAGE_VALUE_ABSENT} to hide. 110 * @return The builder. 111 */ 112 @NonNull setAcceptButton(@onNull String button)113 public abstract Builder setAcceptButton(@NonNull String button); 114 115 /** 116 * Set the label for the {@code Accept} button to be presented to the user. 117 * 118 * @param label The label for the {@code Accept} button. 119 * @return The builder. 120 */ 121 @NonNull setAcceptButtonLabel(@onNull String label)122 public abstract Builder setAcceptButtonLabel(@NonNull String label); 123 124 /** 125 * Set whether an {@code Reject} button is shown with the {@link #message()} on device UI. 126 * 127 * @param button {@link #MESSAGE_VALUE_PRESENT} to show and 128 * {@link #MESSAGE_VALUE_ABSENT} to hide. 129 * @return The builder. 130 */ 131 @NonNull setRejectButton(@onNull String button)132 public abstract Builder setRejectButton(@NonNull String button); 133 134 /** 135 * Set the label for the {@code Reject} button to be presented to the user. 136 * 137 * @param label The label for the {@code Reject} button. 138 * @return The builder. 139 */ 140 @NonNull setRejectButtonLabel(@onNull String label)141 public abstract Builder setRejectButtonLabel(@NonNull String label); 142 143 /** 144 * Set whether a free text entry field is shown with the message on device UI. 145 * 146 * @param accept {@link #MESSAGE_VALUE_PRESENT} to show and 147 * {@link #MESSAGE_VALUE_ABSENT} to hide. 148 * @return The builder. 149 */ 150 @NonNull setAcceptFreetext(@onNull String accept)151 public abstract Builder setAcceptFreetext(@NonNull String accept); 152 153 /** Build the MessageInfo object. */ 154 @NonNull build()155 public abstract MessageInfo build(); 156 } 157 } 158