• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
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
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 == null, ERROR.SIGN_ERROR,
197                 "Require provision not empty!");
198         ValidateUtils.throwIfMatches(provision.versionName == null, ERROR.SIGN_ERROR,
199                 "Require provision version name!");
200         ValidateUtils.throwIfMatches(provision.versionCode == 0, ERROR.SIGN_ERROR,
201                 "Require provision version code!");
202         ValidateUtils.throwIfMatches(provision.uuid == null, ERROR.SIGN_ERROR,
203                 "Require provision uuid!");
204         ValidateUtils.throwIfMatches(provision.type == null || !isBuildTypeValid(provision.type),
205                 ERROR.SIGN_ERROR, "Require build type must be debug or release, current is :" + provision.type);
206 
207         ValidateUtils.throwIfMatches(isBuildTypeRelease(provision.type)
208                         && (provision.appDistributionType == null
209                         || !isAppDistTypeValid(provision.appDistributionType)), ERROR.SIGN_ERROR,
210                 "Require app distribution type must be one of app_gallery, "
211                         + "enterprise or os_integration, current is " + provision.appDistributionType);
212         ValidateUtils.throwIfMatches(provision.bundleInfo == null, ERROR.SIGN_ERROR,
213                 "Require bundleInfo in provision!");
214         provision.bundleInfo.enforceValid(provision.type);
215         ValidateUtils.throwIfMatches(provision.validity == null, ERROR.SIGN_ERROR,
216                 "Require validity in provision!");
217         provision.validity.enforceValid();
218         if (provision.debuginfo != null) {
219             provision.debuginfo.enforceValid();
220         }
221         ValidateUtils.throwIfMatches(provision.issuer == null, ERROR.SIGN_ERROR,
222                 "Require issuer in provision!");
223     }
224 
getVersionCode()225     public Integer getVersionCode() {
226         return versionCode;
227     }
228 
setVersionCode(Integer versionCode)229     public void setVersionCode(Integer versionCode) {
230         this.versionCode = versionCode;
231     }
232 
getVersionName()233     public String getVersionName() {
234         return versionName;
235     }
236 
setVersionName(String versionName)237     public void setVersionName(String versionName) {
238         this.versionName = versionName;
239     }
240 
getUuid()241     public String getUuid() {
242         return uuid;
243     }
244 
setUuid(String uuid)245     public void setUuid(String uuid) {
246         this.uuid = uuid;
247     }
248 
getType()249     public String getType() {
250         return type;
251     }
252 
setType(String type)253     public void setType(String type) {
254         this.type = type;
255     }
256 
getAppDistributionType()257     public String getAppDistributionType() {
258         return appDistributionType;
259     }
260 
setAppDistributionType(String appDistributionType)261     public void setAppDistributionType(String appDistributionType) {
262         this.appDistributionType = appDistributionType;
263     }
264 
getValidity()265     public Validity getValidity() {
266         return validity;
267     }
268 
setValidity(Validity validity)269     public void setValidity(Validity validity) {
270         this.validity = validity;
271     }
272 
getBundleInfo()273     public BundleInfo getBundleInfo() {
274         return bundleInfo;
275     }
276 
setBundleInfo(BundleInfo bundleInfo)277     public void setBundleInfo(BundleInfo bundleInfo) {
278         this.bundleInfo = bundleInfo;
279     }
280 
getAcls()281     public Acls getAcls() {
282         return acls;
283     }
284 
setAcls(Acls acls)285     public void setAcls(Acls acls) {
286         this.acls = acls;
287     }
288 
getPermissions()289     public Permissions getPermissions() {
290         return permissions;
291     }
292 
setPermissions(Permissions permissions)293     public void setPermissions(Permissions permissions) {
294         this.permissions = permissions;
295     }
296 
getDebuginfo()297     public DebugInfo getDebuginfo() {
298         return debuginfo;
299     }
300 
setDebuginfo(DebugInfo debuginfo)301     public void setDebuginfo(DebugInfo debuginfo) {
302         this.debuginfo = debuginfo;
303     }
304 
getIssuer()305     public String getIssuer() {
306         return issuer;
307     }
308 
setIssuer(String issuer)309     public void setIssuer(String issuer) {
310         this.issuer = issuer;
311     }
312 
313     @Override
toString()314     public String toString() {
315         return NEWLINE_CHARACTER + "version-code:" + versionCode + NEWLINE_CHARACTER
316                 + "version-name:" + versionCode + NEWLINE_CHARACTER
317                 + "uuid:" + uuid + NEWLINE_CHARACTER
318                 + "type:" + type + NEWLINE_CHARACTER
319                 + "app-distribution-type:" + appDistributionType + NEWLINE_CHARACTER
320                 + "validity:"+NEWLINE_CHARACTER
321                 + "\t not-before:" + getValidity().getNotBefore() + NEWLINE_CHARACTER
322                 + "\t not-after:" + getValidity().getNotAfter() + NEWLINE_CHARACTER
323                 + "bundle-info"+NEWLINE_CHARACTER
324                 + "\t developer-id:" + getBundleInfo().getDeveloperId() + NEWLINE_CHARACTER
325                 + "\t development-certificate:" + getBundleInfo().getDevelopmentCertificate() + NEWLINE_CHARACTER
326                 + "\t distribution-certificate:" + getBundleInfo().getDistributionCertificate() + NEWLINE_CHARACTER
327                 + "\t bundle-name:" + getBundleInfo().getBundleName() + NEWLINE_CHARACTER
328                 + "\t apl:" + getBundleInfo().getApl() + NEWLINE_CHARACTER
329                 + "\t app-feature:" + getBundleInfo().getAppFeature() + NEWLINE_CHARACTER
330                 + "acls:"+NEWLINE_CHARACTER
331                 + "\t allowed-acls:" + getAcls().getAllowedAcls() + NEWLINE_CHARACTER
332                 + "permissions:"+NEWLINE_CHARACTER
333                 + "\t restricted-permissions:" + getPermissions().getRestrictedPermissions() + NEWLINE_CHARACTER
334                 + "\t restricted-capabilities:" + getPermissions().getRestrictedCapabilities() + NEWLINE_CHARACTER
335                 + "debug-info"+NEWLINE_CHARACTER
336                 + "\t device-id-type:" + getDebuginfo().getDeviceIdType() + NEWLINE_CHARACTER
337                 + "\t device-ids:" + getDebuginfo().getDeviceIds() + NEWLINE_CHARACTER
338                 + "issuer:" + getIssuer();
339     }
340 }
341