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