DownloadableSubscription.java revision f83ccd0e6c7140e1a3149168e67e550fb2b596d4
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 */ 16package android.telephony.euicc; 17 18import android.annotation.Nullable; 19import android.os.Parcel; 20import android.os.Parcelable; 21import android.telephony.UiccAccessRule; 22 23import com.android.internal.util.Preconditions; 24 25/** 26 * Information about a subscription which is available for download. 27 * 28 * TODO(b/35851809): Make this public. 29 * @hide 30 */ 31public final class DownloadableSubscription implements Parcelable { 32 33 public static final Creator<DownloadableSubscription> CREATOR = 34 new Creator<DownloadableSubscription>() { 35 @Override 36 public DownloadableSubscription createFromParcel(Parcel in) { 37 return new DownloadableSubscription(in); 38 } 39 40 @Override 41 public DownloadableSubscription[] newArray(int size) { 42 return new DownloadableSubscription[size]; 43 } 44 }; 45 46 /** 47 * Activation code. May be null for subscriptions which are not based on activation codes, e.g. 48 * to download a default subscription assigned to this device. 49 * @hide 50 * 51 * TODO(b/35851809): Make this a SystemApi. 52 */ 53 @Nullable 54 public final String encodedActivationCode; 55 56 // see getCarrierName and setCarrierName 57 @Nullable 58 private String carrierName; 59 // see isConsentGranted and setConsentGranted 60 private boolean consentGranted; 61 // see getAccessRules and setAccessRules 62 private UiccAccessRule[] accessRules; 63 64 /** @hide */ 65 private DownloadableSubscription(String encodedActivationCode) { 66 this.encodedActivationCode = encodedActivationCode; 67 } 68 69 private DownloadableSubscription(Parcel in) { 70 encodedActivationCode = in.readString(); 71 carrierName = in.readString(); 72 consentGranted = in.readInt() == 1; 73 accessRules = in.createTypedArray(UiccAccessRule.CREATOR); 74 } 75 76 /** 77 * Create a DownloadableSubscription for the given activation code. 78 * 79 * @param encodedActivationCode the activation code to use. Must not be null. 80 * @return the {@link DownloadableSubscription} which may be passed to 81 * {@link EuiccManager#downloadSubscription}. 82 */ 83 public static DownloadableSubscription forActivationCode(String encodedActivationCode) { 84 Preconditions.checkNotNull(encodedActivationCode, "Activation code may not be null"); 85 return new DownloadableSubscription(encodedActivationCode); 86 } 87 88 /** 89 * Set the user-visible carrier name. 90 * @hide 91 * 92 * TODO(b/35851809): Make this a SystemApi. 93 */ 94 public void setCarrierName(String carrierName) { 95 this.carrierName = carrierName; 96 } 97 98 /** 99 * Returns the user-visible carrier name. 100 * 101 * <p>Only present for downloadable subscriptions that were queried from a server (as opposed to 102 * those created with {@link #forActivationCode}). May be populated with 103 * {@link EuiccManager#getDownloadableSubscriptionMetadata}. 104 * @hide 105 * 106 * TODO(b/35851809): Make this a SystemApi. 107 */ 108 @Nullable 109 public String getCarrierName() { 110 return carrierName; 111 } 112 113 114 /** 115 * Mark this download as being consented to by the user. 116 * @hide 117 */ 118 public void setConsentGranted() { 119 consentGranted = true; 120 } 121 122 /** 123 * Returns whether the user has granted consent to download this subscription. 124 * 125 * <p>The {@link android.service.euicc.EuiccService} implementation should permit a subscription 126 * download if this is set, even if the calling app doesn't have permission to download it. 127 * @hide 128 * 129 * TODO(b/35851809): Make this a SystemApi. 130 */ 131 public boolean isConsentGranted() { 132 return consentGranted; 133 } 134 135 /** 136 * Returns the {@link UiccAccessRule}s dictating access to this subscription. 137 * 138 * <p>Only present for downloadable subscriptions that were queried from a server (as opposed to 139 * those created with {@link #forActivationCode}). May be populated with 140 * {@link EuiccManager#getDownloadableSubscriptionMetadata}. 141 * @hide 142 * 143 * TODO(b/35851809): Make this a SystemApi. 144 */ 145 public UiccAccessRule[] getAccessRules() { 146 return accessRules; 147 } 148 149 /** 150 * Set the {@link UiccAccessRule}s dictating access to this subscription. 151 * @hide 152 * 153 * TODO(b/35851809): Make this a SystemApi. 154 */ 155 public void setAccessRules(UiccAccessRule[] accessRules) { 156 this.accessRules = accessRules; 157 } 158 159 /** 160 * Unset any untrusted fields. 161 * 162 * <p>Should be called by the platform whenever an instance is received from an untrusted 163 * source to reset any secure fields that may only be set by the platform. 164 * @hide 165 */ 166 public final void clearUntrustedFields() { 167 this.consentGranted = false; 168 } 169 170 @Override 171 public void writeToParcel(Parcel dest, int flags) { 172 dest.writeString(encodedActivationCode); 173 dest.writeString(carrierName); 174 dest.writeInt(consentGranted ? 1 : 0); 175 dest.writeTypedArray(accessRules, flags); 176 } 177 178 @Override 179 public int describeContents() { 180 return 0; 181 } 182} 183