• 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 import java.util.List;
24 
25 /**
26  * Sub dto of Provision.
27  *
28  * @since 2021/12/28
29  */
30 public class DebugInfo {
31     /**
32      * Max number of debug device.
33      */
34     private static final int MAX_DEBUG_DEVICE_NUM = 100;
35 
36     /**
37      * Field device-id-type.
38      */
39     @SerializedName("device-id-type")
40     private String deviceIdType;
41 
42     /**
43      * Field device-ids.
44      */
45     @SerializedName("device-ids")
46     private List<String> deviceIds;
47 
48     /**
49      * Sub dto of Provision.
50      */
DebugInfo()51     public DebugInfo() {
52         // Empty constructor of DebugInfo.
53     }
54 
getDeviceIdType()55     public String getDeviceIdType() {
56         return deviceIdType;
57     }
58 
setDeviceIdType(String deviceIdType)59     public void setDeviceIdType(String deviceIdType) {
60         this.deviceIdType = deviceIdType;
61     }
62 
getDeviceIds()63     public List<String> getDeviceIds() {
64         return deviceIds;
65     }
66 
setDeviceIds(List<String> deviceIds)67     public void setDeviceIds(List<String> deviceIds) {
68         this.deviceIds = deviceIds;
69     }
70 
71     /**
72      * Enforce valid.
73      */
enforceValid()74     public void enforceValid() {
75         if (this.deviceIds != null) {
76             ValidateUtils.throwIfMatches(this.deviceIds.size() > MAX_DEBUG_DEVICE_NUM, ERROR.SIGN_ERROR,
77                     SignToolErrMsg.SIGNATURE_FAILED.toString("Support at most: 100 devices!"));
78             ValidateUtils.throwIfMatches(!this.isDeviceIdTypeValid(), ERROR.SIGN_ERROR, SignToolErrMsg.SIGNATURE_FAILED
79                     .toString("Device id type must be sn or udid, current is " + this.deviceIdType));
80         }
81     }
82 
isDeviceIdTypeValid()83     private boolean isDeviceIdTypeValid() {
84         return "sn".equals(this.deviceIdType) || "udid".equals(this.deviceIdType);
85     }
86 }
87