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