• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.asllib.marshallable;
18 
19 import com.android.asllib.util.XmlUtils;
20 
21 import org.w3c.dom.Document;
22 import org.w3c.dom.Element;
23 
24 import java.util.List;
25 
26 /** DeveloperInfo representation */
27 public class DeveloperInfo implements AslMarshallable {
28     public enum DeveloperRelationship {
29         OEM(0),
30         ODM(1),
31         SOC(2),
32         OTA(3),
33         CARRIER(4),
34         AOSP(5),
35         OTHER(6);
36 
37         private final int mValue;
38 
DeveloperRelationship(int value)39         DeveloperRelationship(int value) {
40             this.mValue = value;
41         }
42 
43         /** Get the int value associated with the DeveloperRelationship. */
getValue()44         public int getValue() {
45             return mValue;
46         }
47 
48         /** Get the DeveloperRelationship associated with the int value. */
forValue(int value)49         public static DeveloperInfo.DeveloperRelationship forValue(int value) {
50             for (DeveloperInfo.DeveloperRelationship e : values()) {
51                 if (e.getValue() == value) {
52                     return e;
53                 }
54             }
55             throw new IllegalArgumentException("No DeveloperRelationship enum for value: " + value);
56         }
57 
58         /** Get the DeveloperRelationship associated with the human-readable String. */
forString(String s)59         public static DeveloperInfo.DeveloperRelationship forString(String s) {
60             for (DeveloperInfo.DeveloperRelationship e : values()) {
61                 if (e.toString().equals(s)) {
62                     return e;
63                 }
64             }
65             throw new IllegalArgumentException("No DeveloperRelationship enum for str: " + s);
66         }
67 
68         /** Human-readable String representation of DeveloperRelationship. */
toString()69         public String toString() {
70             return this.name().toLowerCase();
71         }
72     }
73 
74     private final String mName;
75     private final String mEmail;
76     private final String mAddress;
77     private final String mCountryRegion;
78     private final DeveloperRelationship mDeveloperRelationship;
79     private final String mWebsite;
80     private final String mAppDeveloperRegistryId;
81 
DeveloperInfo( String name, String email, String address, String countryRegion, DeveloperRelationship developerRelationship, String website, String appDeveloperRegistryId)82     public DeveloperInfo(
83             String name,
84             String email,
85             String address,
86             String countryRegion,
87             DeveloperRelationship developerRelationship,
88             String website,
89             String appDeveloperRegistryId) {
90         this.mName = name;
91         this.mEmail = email;
92         this.mAddress = address;
93         this.mCountryRegion = countryRegion;
94         this.mDeveloperRelationship = developerRelationship;
95         this.mWebsite = website;
96         this.mAppDeveloperRegistryId = appDeveloperRegistryId;
97     }
98 
99     /** Creates an on-device DOM element from the {@link SafetyLabels}. */
100     @Override
toOdDomElements(Document doc)101     public List<Element> toOdDomElements(Document doc) {
102         Element developerInfoEle =
103                 XmlUtils.createPbundleEleWithName(doc, XmlUtils.OD_NAME_DEVELOPER_INFO);
104         if (mName != null) {
105             developerInfoEle.appendChild(
106                     XmlUtils.createOdStringEle(doc, XmlUtils.OD_NAME_NAME, mName));
107         }
108         if (mEmail != null) {
109             developerInfoEle.appendChild(
110                     XmlUtils.createOdStringEle(doc, XmlUtils.OD_NAME_EMAIL, mEmail));
111         }
112         if (mAddress != null) {
113             developerInfoEle.appendChild(
114                     XmlUtils.createOdStringEle(doc, XmlUtils.OD_NAME_ADDRESS, mAddress));
115         }
116         if (mCountryRegion != null) {
117             developerInfoEle.appendChild(
118                     XmlUtils.createOdStringEle(
119                             doc, XmlUtils.OD_NAME_COUNTRY_REGION, mCountryRegion));
120         }
121         if (mDeveloperRelationship != null) {
122             developerInfoEle.appendChild(
123                     XmlUtils.createOdLongEle(
124                             doc,
125                             XmlUtils.OD_NAME_DEVELOPER_RELATIONSHIP,
126                             mDeveloperRelationship.getValue()));
127         }
128         if (mWebsite != null) {
129             developerInfoEle.appendChild(
130                     XmlUtils.createOdStringEle(doc, XmlUtils.OD_NAME_WEBSITE, mWebsite));
131         }
132         if (mAppDeveloperRegistryId != null) {
133             developerInfoEle.appendChild(
134                     XmlUtils.createOdStringEle(
135                             doc,
136                             XmlUtils.OD_NAME_APP_DEVELOPER_REGISTRY_ID,
137                             mAppDeveloperRegistryId));
138         }
139 
140         return XmlUtils.listOf(developerInfoEle);
141     }
142 
143     /** Creates the human-readable DOM elements from the AslMarshallable Java Object. */
144     @Override
toHrDomElements(Document doc)145     public List<Element> toHrDomElements(Document doc) {
146         Element developerInfoEle = doc.createElement(XmlUtils.HR_TAG_DEVELOPER_INFO);
147         if (mName != null) {
148             developerInfoEle.setAttribute(XmlUtils.HR_ATTR_NAME, mName);
149         }
150         if (mEmail != null) {
151             developerInfoEle.setAttribute(XmlUtils.HR_ATTR_EMAIL, mEmail);
152         }
153         if (mAddress != null) {
154             developerInfoEle.setAttribute(XmlUtils.HR_ATTR_ADDRESS, mAddress);
155         }
156         if (mCountryRegion != null) {
157             developerInfoEle.setAttribute(XmlUtils.HR_ATTR_COUNTRY_REGION, mCountryRegion);
158         }
159         if (mDeveloperRelationship != null) {
160             developerInfoEle.setAttribute(
161                     XmlUtils.HR_ATTR_DEVELOPER_RELATIONSHIP, mDeveloperRelationship.toString());
162         }
163         if (mWebsite != null) {
164             developerInfoEle.setAttribute(XmlUtils.HR_ATTR_WEBSITE, mWebsite);
165         }
166         if (mAppDeveloperRegistryId != null) {
167             developerInfoEle.setAttribute(
168                     XmlUtils.HR_ATTR_APP_DEVELOPER_REGISTRY_ID, mAppDeveloperRegistryId);
169         }
170 
171         return XmlUtils.listOf(developerInfoEle);
172     }
173 }
174