• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 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 package android.telephony.euicc;
17 
18 import android.annotation.NonNull;
19 import android.annotation.Nullable;
20 import android.annotation.SystemApi;
21 import android.app.PendingIntent;
22 import android.compat.annotation.UnsupportedAppUsage;
23 import android.os.Build;
24 import android.os.Parcel;
25 import android.os.Parcelable;
26 import android.telephony.UiccAccessRule;
27 
28 import com.android.internal.util.Preconditions;
29 
30 import java.util.ArrayList;
31 import java.util.Arrays;
32 import java.util.List;
33 
34 /**
35  * Information about a subscription which is downloadable to an eUICC using
36  * {@link EuiccManager#downloadSubscription(DownloadableSubscription, boolean, PendingIntent).
37  *
38  * <p>For example, a DownloadableSubscription can be created through an activation code parsed from
39  * a QR code. A server address can be parsed from the activation code to download more information
40  * about the profile, such as carrier name, access rules, etc.
41  */
42 public final class DownloadableSubscription implements Parcelable {
43 
44     public static final @android.annotation.NonNull Creator<DownloadableSubscription> CREATOR =
45             new Creator<DownloadableSubscription>() {
46                 @Override
47                 public DownloadableSubscription createFromParcel(Parcel in) {
48                     return new DownloadableSubscription(in);
49                 }
50 
51                 @Override
52                 public DownloadableSubscription[] newArray(int size) {
53                     return new DownloadableSubscription[size];
54                 }
55             };
56 
57     /**
58      * Activation code. May be null for subscriptions which are not based on activation codes, e.g.
59      * to download a default subscription assigned to this device.
60      * Should use getEncodedActivationCode() instead.
61      * @hide
62      * @deprecated - Do not use. This will be private. Use getEncodedActivationCode() instead.
63      */
64     @Nullable
65     @Deprecated
66     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
67     public final String encodedActivationCode;
68 
69     @Nullable private String confirmationCode;
70 
71     // see getCarrierName and setCarrierName
72     @Nullable
73     private String carrierName;
74 
75     // see getAccessRules and setAccessRules
76     @Nullable
77     private List<UiccAccessRule> accessRules;
78 
79     /** Gets the activation code. */
80     @Nullable
getEncodedActivationCode()81     public String getEncodedActivationCode() {
82         return encodedActivationCode;
83     }
84 
85     /** @hide */
DownloadableSubscription(String encodedActivationCode)86     private DownloadableSubscription(String encodedActivationCode) {
87         this.encodedActivationCode = encodedActivationCode;
88     }
89 
DownloadableSubscription(Parcel in)90     private DownloadableSubscription(Parcel in) {
91         encodedActivationCode = in.readString();
92         confirmationCode = in.readString();
93         carrierName = in.readString();
94         accessRules = new ArrayList<UiccAccessRule>();
95         in.readTypedList(accessRules, UiccAccessRule.CREATOR);
96     }
97 
DownloadableSubscription(String encodedActivationCode, String confirmationCode, String carrierName, List<UiccAccessRule> accessRules)98     private DownloadableSubscription(String encodedActivationCode, String confirmationCode,
99             String carrierName, List<UiccAccessRule> accessRules) {
100         this.encodedActivationCode = encodedActivationCode;
101         this.confirmationCode = confirmationCode;
102         this.carrierName = carrierName;
103         this.accessRules = accessRules;
104     }
105 
106     public static final class Builder {
107         @Nullable private String encodedActivationCode;
108         @Nullable private String confirmationCode;
109         @Nullable private String carrierName;
110         List<UiccAccessRule> accessRules;
111 
112         /** @hide */
113         @SystemApi
Builder()114         public Builder() {}
115 
Builder(@onNull DownloadableSubscription baseSubscription)116         public Builder(@NonNull DownloadableSubscription baseSubscription) {
117             encodedActivationCode = baseSubscription.getEncodedActivationCode();
118             confirmationCode = baseSubscription.getConfirmationCode();
119             carrierName = baseSubscription.getCarrierName();
120             accessRules = baseSubscription.getAccessRules();
121         }
122 
Builder(@onNull String encodedActivationCode)123         public Builder(@NonNull String encodedActivationCode) {
124             this.encodedActivationCode = encodedActivationCode;
125         }
126 
127         /**
128          * Builds a {@link DownloadableSubscription} object.
129          * @return a non-null {@link DownloadableSubscription} object.
130          */
131         @NonNull
build()132         public DownloadableSubscription build() {
133             return new DownloadableSubscription(encodedActivationCode, confirmationCode,
134                     carrierName, accessRules);
135         }
136 
137         /**
138          * Sets the encoded activation code.
139          * @param value the activation code to use. An activation code can be parsed from a user
140          *              scanned QR code. The format of activation code is defined in SGP.22. For
141          *              example, "1$SMDP.GSMA.COM$04386-AGYFT-A74Y8-3F815$1.3.6.1.4.1.31746". For
142          *              detail, see {@code com.android.euicc.data.ActivationCode}. Must not be null.
143          */
144         @NonNull
setEncodedActivationCode(@onNull String value)145         public Builder setEncodedActivationCode(@NonNull String value) {
146             encodedActivationCode = value;
147             return this;
148         }
149 
150         /**
151          * Sets the confirmation code.
152          * @param value the confirmation code to use to authenticate the carrier server got
153          *              subscription download.
154          */
155         @NonNull
setConfirmationCode(@onNull String value)156         public Builder setConfirmationCode(@NonNull String value) {
157             confirmationCode = value;
158             return this;
159         }
160 
161         /**
162          * Sets the user-visible carrier name.
163          * @param value carrier name.
164          * @hide
165          */
166         @NonNull
167         @SystemApi
setCarrierName(@onNull String value)168         public Builder setCarrierName(@NonNull String value) {
169             carrierName = value;
170             return this;
171         }
172 
173         /**
174          * Sets the {@link UiccAccessRule}s dictating access to this subscription.
175          * @param value A list of {@link UiccAccessRule}s.
176          * @hide
177          */
178         @NonNull
179         @SystemApi
setAccessRules(@onNull List<UiccAccessRule> value)180         public Builder setAccessRules(@NonNull List<UiccAccessRule> value) {
181             accessRules = value;
182             return this;
183         }
184     }
185 
186     /**
187      * Create a DownloadableSubscription for the given activation code.
188      *
189      * <p>This fills the encodedActivationCode field. Other fields like confirmationCode,
190      * carrierName and accessRules may be filled in the implementation of
191      * {@code android.service.euicc.EuiccService} if exists.
192      *
193      * @param encodedActivationCode the activation code to use. An activation code can be parsed
194      *         from a user scanned QR code. The format of activation code is defined in SGP.22. For
195      *         example, "1$SMDP.GSMA.COM$04386-AGYFT-A74Y8-3F815$1.3.6.1.4.1.31746". For detail, see
196      *         {@code com.android.euicc.data.ActivationCode}. Must not be null.
197      *
198      * @return the {@link DownloadableSubscription} which may be passed to
199      *     {@link EuiccManager#downloadSubscription}.
200      */
forActivationCode(String encodedActivationCode)201     public static DownloadableSubscription forActivationCode(String encodedActivationCode) {
202         Preconditions.checkNotNull(encodedActivationCode, "Activation code may not be null");
203         return new DownloadableSubscription(encodedActivationCode);
204     }
205 
206     /**
207      * Sets the confirmation code.
208      * @hide
209      * @deprecated - Do not use.
210      */
211     @Deprecated
setConfirmationCode(String confirmationCode)212     public void setConfirmationCode(String confirmationCode) {
213         this.confirmationCode = confirmationCode;
214     }
215 
216     /**
217      * Returns the confirmation code.
218      *
219      * <p>As an example, the confirmation code can be input by the user through a carrier app or the
220      * UI component of the eUICC local profile assistant (LPA) application.
221      */
222     @Nullable
getConfirmationCode()223     public String getConfirmationCode() {
224         return confirmationCode;
225     }
226 
227     /**
228      * Set the user-visible carrier name.
229      * @hide
230      * @deprecated - Do not use.
231      */
232     @Deprecated
233     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
setCarrierName(String carrierName)234     public void setCarrierName(String carrierName) {
235         this.carrierName = carrierName;
236     }
237 
238     /**
239      * Returns the user-visible carrier name.
240      *
241      * <p>Only present for downloadable subscriptions that were queried from a server (as opposed to
242      * those created with {@link #forActivationCode}). May be populated with
243      * {@link EuiccManager#getDownloadableSubscriptionMetadata}.
244      * @hide
245      */
246     @SystemApi
247     @Nullable
getCarrierName()248     public String getCarrierName() {
249         return carrierName;
250     }
251 
252     /**
253      * Returns the {@link UiccAccessRule}s in list dictating access to this subscription.
254      *
255      * <p>Only present for downloadable subscriptions that were queried from a server (as opposed to
256      * those created with {@link #forActivationCode}). May be populated with
257      * {@link EuiccManager#getDownloadableSubscriptionMetadata}.
258      * @hide
259      */
260     @SystemApi
getAccessRules()261     public List<UiccAccessRule> getAccessRules() {
262         return accessRules;
263     }
264 
265     /**
266      * Set the {@link UiccAccessRule}s dictating access to this subscription.
267      * @hide
268      * @deprecated - Do not use.
269      */
270     @Deprecated
setAccessRules(List<UiccAccessRule> accessRules)271     public void setAccessRules(List<UiccAccessRule> accessRules) {
272         this.accessRules = accessRules;
273     }
274 
275     /**
276      * @hide
277      * @deprecated - Do not use.
278      */
279     @Deprecated
280     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
setAccessRules(UiccAccessRule[] accessRules)281     public void setAccessRules(UiccAccessRule[] accessRules) {
282         this.accessRules = Arrays.asList(accessRules);
283     }
284 
285     @Override
writeToParcel(Parcel dest, int flags)286     public void writeToParcel(Parcel dest, int flags) {
287         dest.writeString(encodedActivationCode);
288         dest.writeString(confirmationCode);
289         dest.writeString(carrierName);
290         dest.writeTypedList(accessRules);
291     }
292 
293     @Override
describeContents()294     public int describeContents() {
295         return 0;
296     }
297 }
298