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 * newline character 84 */ 85 public static final String NEWLINE_CHARACTER = System.lineSeparator(); 86 87 /** 88 * Field version-code. 89 */ 90 @SerializedName("version-code") 91 private Integer versionCode; 92 93 /** 94 * Field version-name. 95 */ 96 @SerializedName("version-name") 97 private String versionName; 98 99 /** 100 * Field uuid. 101 */ 102 @SerializedName("uuid") 103 private String uuid; 104 105 /** 106 * Field type. 107 */ 108 @SerializedName("type") 109 private String type; 110 111 /** 112 * Field app-distribution-type. 113 */ 114 @SerializedName("app-distribution-type") 115 private String appDistributionType; 116 117 /** 118 * Field validity. 119 */ 120 @SerializedName("validity") 121 private Validity validity; 122 123 /** 124 * Field bundle-info. 125 */ 126 @SerializedName("bundle-info") 127 private BundleInfo bundleInfo; 128 129 /** 130 * Field acls. 131 */ 132 @SerializedName("acls") 133 private Acls acls; 134 135 /** 136 * Field permissions. 137 */ 138 @SerializedName("permissions") 139 private Permissions permissions; 140 141 /** 142 * Field debug-info. 143 */ 144 @SerializedName("debug-info") 145 private DebugInfo debuginfo; 146 147 /** 148 * Field issuer. 149 */ 150 @SerializedName("issuer") 151 private String issuer; 152 153 /** 154 * Dto for provision profile. 155 */ Provision()156 public Provision() { 157 // Empty constructor of Provision. 158 } 159 160 /** 161 * buildType valid 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 * @param buildType buildType 172 * @return Is the buildType release 173 */ isBuildTypeRelease(String buildType)174 public static boolean isBuildTypeRelease(String buildType) { 175 return RELEASE.equals(buildType); 176 } 177 178 /** 179 * Check if dist type in scope. 180 * 181 * @param appDistType Input type 182 * @return Is type in scope 183 */ isAppDistTypeValid(String appDistType)184 public static boolean isAppDistTypeValid(String appDistType) { 185 return APP_GALLERY.equals(appDistType) 186 || ENTERPRISE.equals(appDistType) 187 || OS_INTEGRATION.equals(appDistType); 188 } 189 190 /** 191 * Enforce valid. 192 * 193 * @param provision provision 194 */ enforceValid(Provision provision)195 public static void enforceValid(Provision provision) { 196 ValidateUtils.throwIfMatches(provision.type == null || !isBuildTypeValid(provision.type), 197 ERROR.SIGN_ERROR, "Require build type must be debug or release, current is :" + provision.type); 198 199 ValidateUtils.throwIfMatches(provision.bundleInfo == null, ERROR.SIGN_ERROR, 200 "Require bundleInfo in provision!"); 201 provision.bundleInfo.enforceValid(provision.type); 202 } 203 getVersionCode()204 public Integer getVersionCode() { 205 return versionCode; 206 } 207 setVersionCode(Integer versionCode)208 public void setVersionCode(Integer versionCode) { 209 this.versionCode = versionCode; 210 } 211 getVersionName()212 public String getVersionName() { 213 return versionName; 214 } 215 setVersionName(String versionName)216 public void setVersionName(String versionName) { 217 this.versionName = versionName; 218 } 219 getUuid()220 public String getUuid() { 221 return uuid; 222 } 223 setUuid(String uuid)224 public void setUuid(String uuid) { 225 this.uuid = uuid; 226 } 227 getType()228 public String getType() { 229 return type; 230 } 231 setType(String type)232 public void setType(String type) { 233 this.type = type; 234 } 235 getAppDistributionType()236 public String getAppDistributionType() { 237 return appDistributionType; 238 } 239 setAppDistributionType(String appDistributionType)240 public void setAppDistributionType(String appDistributionType) { 241 this.appDistributionType = appDistributionType; 242 } 243 getValidity()244 public Validity getValidity() { 245 return validity; 246 } 247 setValidity(Validity validity)248 public void setValidity(Validity validity) { 249 this.validity = validity; 250 } 251 getBundleInfo()252 public BundleInfo getBundleInfo() { 253 return bundleInfo; 254 } 255 setBundleInfo(BundleInfo bundleInfo)256 public void setBundleInfo(BundleInfo bundleInfo) { 257 this.bundleInfo = bundleInfo; 258 } 259 getAcls()260 public Acls getAcls() { 261 return acls; 262 } 263 setAcls(Acls acls)264 public void setAcls(Acls acls) { 265 this.acls = acls; 266 } 267 getPermissions()268 public Permissions getPermissions() { 269 return permissions; 270 } 271 setPermissions(Permissions permissions)272 public void setPermissions(Permissions permissions) { 273 this.permissions = permissions; 274 } 275 getDebuginfo()276 public DebugInfo getDebuginfo() { 277 return debuginfo; 278 } 279 setDebuginfo(DebugInfo debuginfo)280 public void setDebuginfo(DebugInfo debuginfo) { 281 this.debuginfo = debuginfo; 282 } 283 getIssuer()284 public String getIssuer() { 285 return issuer; 286 } 287 setIssuer(String issuer)288 public void setIssuer(String issuer) { 289 this.issuer = issuer; 290 } 291 292 @Override toString()293 public String toString() { 294 return NEWLINE_CHARACTER + "version-code:" + versionCode + NEWLINE_CHARACTER 295 + "version-name:" + versionCode + NEWLINE_CHARACTER 296 + "uuid:" + uuid + NEWLINE_CHARACTER 297 + "type:" + type + NEWLINE_CHARACTER 298 + "app-distribution-type:" + appDistributionType + NEWLINE_CHARACTER 299 + "validity:"+NEWLINE_CHARACTER 300 + "\t not-before:" + getValidity().getNotBefore() + NEWLINE_CHARACTER 301 + "\t not-after:" + getValidity().getNotAfter() + NEWLINE_CHARACTER 302 + "bundle-info"+NEWLINE_CHARACTER 303 + "\t developer-id:" + getBundleInfo().getDeveloperId() + NEWLINE_CHARACTER 304 + "\t development-certificate:" + getBundleInfo().getDevelopmentCertificate() + NEWLINE_CHARACTER 305 + "\t distribution-certificate:" + getBundleInfo().getDistributionCertificate() + NEWLINE_CHARACTER 306 + "\t bundle-name:" + getBundleInfo().getBundleName() + NEWLINE_CHARACTER 307 + "\t apl:" + getBundleInfo().getApl() + NEWLINE_CHARACTER 308 + "\t app-feature:" + getBundleInfo().getAppFeature() + NEWLINE_CHARACTER 309 + "acls:"+NEWLINE_CHARACTER 310 + "\t allowed-acls:" + getAcls().getAllowedAcls() + NEWLINE_CHARACTER 311 + "permissions:"+NEWLINE_CHARACTER 312 + "\t restricted-permissions:" + getPermissions().getRestrictedPermissions() + NEWLINE_CHARACTER 313 + "\t restricted-capabilities:" + getPermissions().getRestrictedCapabilities() + NEWLINE_CHARACTER 314 + "debug-info"+NEWLINE_CHARACTER 315 + "\t device-id-type:" + getDebuginfo().getDeviceIdType() + NEWLINE_CHARACTER 316 + "\t device-ids:" + getDebuginfo().getDeviceIds() + NEWLINE_CHARACTER 317 + "issuer:" + getIssuer(); 318 } 319 } 320