1 /* 2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 package com.ohos.hapsigntool.profile.model; 17 18 import com.google.gson.annotations.SerializedName; 19 import com.ohos.hapsigntool.error.ERROR; 20 import com.ohos.hapsigntool.utils.ValidateUtils; 21 22 /** 23 * Json object of provision profile. 24 * 25 * @since 2021/12/28 26 */ 27 public class Provision { 28 /** 29 * Field DEBUG. 30 */ 31 public static final String DEBUG = "debug"; 32 33 /** 34 * Field RELEASE. 35 */ 36 public static final String RELEASE = "release"; 37 38 /** 39 * Field HOS_SYSTEM_APP. 40 */ 41 public static final String HOS_SYSTEM_APP = "hos_system_app"; 42 43 /** 44 * Field HOS_NORMAL_APP. 45 */ 46 public static final String HOS_NORMAL_APP = "hos_normal_app"; 47 48 /** 49 * Field NORMAL. 50 */ 51 public static final String NORMAL = "normal"; 52 53 /** 54 * Field SYSTEM_BASIC. 55 */ 56 public static final String SYSTEM_BASIC = "system_basic"; 57 58 /** 59 * Field SYSTEM_CORE. 60 */ 61 public static final String SYSTEM_CORE = "system_core"; 62 63 /** 64 * Field APP_GALLERY. 65 */ 66 public static final String APP_GALLERY = "app_gallery"; 67 68 /** 69 * Field ENTERPRISE. 70 */ 71 public static final String ENTERPRISE = "enterprise"; 72 73 /** 74 * Field OS_INTEGRATION. 75 */ 76 public static final String OS_INTEGRATION = "os_integration"; 77 78 /** 79 * Number 100. 80 */ 81 public static final int NUM_ONE_HUNDRED = 100; 82 83 /** 84 * newline character 85 */ 86 public static final String NEWLINE_CHARACTER = System.lineSeparator(); 87 88 /** 89 * Field version-code. 90 */ 91 @SerializedName("version-code") 92 private Integer versionCode; 93 94 /** 95 * Field version-name. 96 */ 97 @SerializedName("version-name") 98 private String versionName; 99 100 /** 101 * Field uuid. 102 */ 103 @SerializedName("uuid") 104 private String uuid; 105 106 /** 107 * Field type. 108 */ 109 @SerializedName("type") 110 private String type; 111 112 /** 113 * Field app-distribution-type. 114 */ 115 @SerializedName("app-distribution-type") 116 private String appDistributionType; 117 118 /** 119 * Field validity. 120 */ 121 @SerializedName("validity") 122 private Validity validity; 123 124 /** 125 * Field bundle-info. 126 */ 127 @SerializedName("bundle-info") 128 private BundleInfo bundleInfo; 129 130 /** 131 * Field acls. 132 */ 133 @SerializedName("acls") 134 private Acls acls; 135 136 /** 137 * Field permissions. 138 */ 139 @SerializedName("permissions") 140 private Permissions permissions; 141 142 /** 143 * Field debug-info. 144 */ 145 @SerializedName("debug-info") 146 private DebugInfo debuginfo; 147 148 /** 149 * Field issuer. 150 */ 151 @SerializedName("issuer") 152 private String issuer; 153 154 /** 155 * Dto for provision profile. 156 */ Provision()157 public Provision() {} 158 159 /** 160 * buildType valid 161 * 162 * @param buildType buildType 163 * @return BuildType Valid 164 */ isBuildTypeValid(String buildType)165 public static boolean isBuildTypeValid(String buildType) { 166 return DEBUG.equals(buildType) || RELEASE.equals(buildType); 167 } 168 169 /** 170 * buildType valid 171 * 172 * @param buildType buildType 173 * @return Is the buildType release 174 */ isBuildTypeRelease(String buildType)175 public static boolean isBuildTypeRelease(String buildType) { 176 return RELEASE.equals(buildType); 177 } 178 179 /** 180 * Check if dist type in scope. 181 * 182 * @param appDistType Input type 183 * @return Is type in scope 184 */ isAppDistTypeValid(String appDistType)185 public static boolean isAppDistTypeValid(String appDistType) { 186 return APP_GALLERY.equals(appDistType) 187 || ENTERPRISE.equals(appDistType) 188 || OS_INTEGRATION.equals(appDistType); 189 } 190 191 /** 192 * Enforce valid. 193 * 194 * @param provision provision 195 */ enforceValid(Provision provision)196 public static void enforceValid(Provision provision) { 197 ValidateUtils.throwIfMatches(provision.type == null || !isBuildTypeValid(provision.type), 198 ERROR.SIGN_ERROR, "Require build type must be debug or release, current is :" + provision.type); 199 200 ValidateUtils.throwIfMatches(provision.bundleInfo == null, ERROR.SIGN_ERROR, 201 "Require bundleInfo in provision!"); 202 provision.bundleInfo.enforceValid(provision.type); 203 } 204 getVersionCode()205 public Integer getVersionCode() { 206 return versionCode; 207 } 208 setVersionCode(Integer versionCode)209 public void setVersionCode(Integer versionCode) { 210 this.versionCode = versionCode; 211 } 212 getVersionName()213 public String getVersionName() { 214 return versionName; 215 } 216 setVersionName(String versionName)217 public void setVersionName(String versionName) { 218 this.versionName = versionName; 219 } 220 getUuid()221 public String getUuid() { 222 return uuid; 223 } 224 setUuid(String uuid)225 public void setUuid(String uuid) { 226 this.uuid = uuid; 227 } 228 getType()229 public String getType() { 230 return type; 231 } 232 setType(String type)233 public void setType(String type) { 234 this.type = type; 235 } 236 getAppDistributionType()237 public String getAppDistributionType() { 238 return appDistributionType; 239 } 240 setAppDistributionType(String appDistributionType)241 public void setAppDistributionType(String appDistributionType) { 242 this.appDistributionType = appDistributionType; 243 } 244 getValidity()245 public Validity getValidity() { 246 return validity; 247 } 248 setValidity(Validity validity)249 public void setValidity(Validity validity) { 250 this.validity = validity; 251 } 252 getBundleInfo()253 public BundleInfo getBundleInfo() { 254 return bundleInfo; 255 } 256 setBundleInfo(BundleInfo bundleInfo)257 public void setBundleInfo(BundleInfo bundleInfo) { 258 this.bundleInfo = bundleInfo; 259 } 260 getAcls()261 public Acls getAcls() { 262 return acls; 263 } 264 setAcls(Acls acls)265 public void setAcls(Acls acls) { 266 this.acls = acls; 267 } 268 getPermissions()269 public Permissions getPermissions() { 270 return permissions; 271 } 272 setPermissions(Permissions permissions)273 public void setPermissions(Permissions permissions) { 274 this.permissions = permissions; 275 } 276 getDebuginfo()277 public DebugInfo getDebuginfo() { 278 return debuginfo; 279 } 280 setDebuginfo(DebugInfo debuginfo)281 public void setDebuginfo(DebugInfo debuginfo) { 282 this.debuginfo = debuginfo; 283 } 284 getIssuer()285 public String getIssuer() { 286 return issuer; 287 } 288 setIssuer(String issuer)289 public void setIssuer(String issuer) { 290 this.issuer = issuer; 291 } 292 293 @Override toString()294 public String toString() { 295 return NEWLINE_CHARACTER + "version-code:" + versionCode + NEWLINE_CHARACTER 296 + "version-name:" + versionCode + NEWLINE_CHARACTER 297 + "uuid:" + uuid + NEWLINE_CHARACTER 298 + "type:" + type + NEWLINE_CHARACTER 299 + "app-distribution-type:" + appDistributionType + NEWLINE_CHARACTER 300 + "validity:" + NEWLINE_CHARACTER 301 + "\t not-before:" + getValidity().getNotBefore() + NEWLINE_CHARACTER 302 + "\t not-after:" + getValidity().getNotAfter() + NEWLINE_CHARACTER 303 + "bundle-info" + NEWLINE_CHARACTER 304 + "\t developer-id:" + getBundleInfo().getDeveloperId() + NEWLINE_CHARACTER 305 + "\t development-certificate:" + getBundleInfo().getDevelopmentCertificate() + NEWLINE_CHARACTER 306 + "\t distribution-certificate:" + getBundleInfo().getDistributionCertificate() + NEWLINE_CHARACTER 307 + "\t bundle-name:" + getBundleInfo().getBundleName() + NEWLINE_CHARACTER 308 + "\t apl:" + getBundleInfo().getApl() + NEWLINE_CHARACTER 309 + "\t app-feature:" + getBundleInfo().getAppFeature() + NEWLINE_CHARACTER 310 + "acls:" + NEWLINE_CHARACTER 311 + "\t allowed-acls:" + getAcls().getAllowedAcls() + NEWLINE_CHARACTER 312 + "permissions:" + NEWLINE_CHARACTER 313 + "\t restricted-permissions:" + getPermissions().getRestrictedPermissions() + NEWLINE_CHARACTER 314 + "\t restricted-capabilities:" + getPermissions().getRestrictedCapabilities() + NEWLINE_CHARACTER 315 + "debug-info" + NEWLINE_CHARACTER 316 + "\t device-id-type:" + getDebuginfo().getDeviceIdType() + NEWLINE_CHARACTER 317 + "\t device-ids:" + getDebuginfo().getDeviceIds() + NEWLINE_CHARACTER 318 + "issuer:" + getIssuer(); 319 } 320 } 321