• 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 /** DeveloperInfo representation */
25 public class DeveloperInfo implements AslMarshallable {
26     public enum DeveloperRelationship {
27         OEM(0),
28         ODM(1),
29         SOC(2),
30         OTA(3),
31         CARRIER(4),
32         AOSP(5),
33         OTHER(6);
34 
35         private final int mValue;
36 
DeveloperRelationship(int value)37         DeveloperRelationship(int value) {
38             this.mValue = value;
39         }
40 
41         /** Get the int value associated with the DeveloperRelationship. */
getValue()42         public int getValue() {
43             return mValue;
44         }
45 
46         /** Get the DeveloperRelationship associated with the int value. */
forValue(int value)47         public static DeveloperInfo.DeveloperRelationship forValue(int value) {
48             for (DeveloperInfo.DeveloperRelationship e : values()) {
49                 if (e.getValue() == value) {
50                     return e;
51                 }
52             }
53             throw new IllegalArgumentException("No DeveloperRelationship enum for value: " + value);
54         }
55 
56         /** Get the DeveloperRelationship associated with the human-readable String. */
forString(String s)57         public static DeveloperInfo.DeveloperRelationship forString(String s) {
58             for (DeveloperInfo.DeveloperRelationship e : values()) {
59                 if (e.toString().equals(s)) {
60                     return e;
61                 }
62             }
63             throw new IllegalArgumentException("No DeveloperRelationship enum for str: " + s);
64         }
65 
66         /** Human-readable String representation of DeveloperRelationship. */
toString()67         public String toString() {
68             return this.name().toLowerCase();
69         }
70     }
71 
72     private final String mName;
73     private final String mEmail;
74     private final String mAddress;
75     private final String mCountryRegion;
76     private final DeveloperRelationship mDeveloperRelationship;
77     private final String mWebsite;
78     private final String mAppDeveloperRegistryId;
79 
DeveloperInfo( String name, String email, String address, String countryRegion, DeveloperRelationship developerRelationship, String website, String appDeveloperRegistryId)80     public DeveloperInfo(
81             String name,
82             String email,
83             String address,
84             String countryRegion,
85             DeveloperRelationship developerRelationship,
86             String website,
87             String appDeveloperRegistryId) {
88         this.mName = name;
89         this.mEmail = email;
90         this.mAddress = address;
91         this.mCountryRegion = countryRegion;
92         this.mDeveloperRelationship = developerRelationship;
93         this.mWebsite = website;
94         this.mAppDeveloperRegistryId = appDeveloperRegistryId;
95     }
96 
97     /** Creates an on-device DOM element from the {@link SafetyLabels}. */
toOdDomElement(Document doc)98     public Element toOdDomElement(Document doc) {
99         Element developerInfoEle =
100                 XmlUtils.createPbundleEleWithName(doc, XmlUtils.OD_NAME_DEVELOPER_INFO);
101         if (mName != null) {
102             developerInfoEle.appendChild(
103                     XmlUtils.createOdStringEle(doc, XmlUtils.OD_NAME_NAME, mName));
104         }
105         if (mEmail != null) {
106             developerInfoEle.appendChild(
107                     XmlUtils.createOdStringEle(doc, XmlUtils.OD_NAME_EMAIL, mEmail));
108         }
109         if (mAddress != null) {
110             developerInfoEle.appendChild(
111                     XmlUtils.createOdStringEle(doc, XmlUtils.OD_NAME_ADDRESS, mAddress));
112         }
113         if (mCountryRegion != null) {
114             developerInfoEle.appendChild(
115                     XmlUtils.createOdStringEle(
116                             doc, XmlUtils.OD_NAME_COUNTRY_REGION, mCountryRegion));
117         }
118         if (mDeveloperRelationship != null) {
119             developerInfoEle.appendChild(
120                     XmlUtils.createOdLongEle(
121                             doc,
122                             XmlUtils.OD_NAME_DEVELOPER_RELATIONSHIP,
123                             mDeveloperRelationship.getValue()));
124         }
125         if (mWebsite != null) {
126             developerInfoEle.appendChild(
127                     XmlUtils.createOdStringEle(doc, XmlUtils.OD_NAME_WEBSITE, mWebsite));
128         }
129         if (mAppDeveloperRegistryId != null) {
130             developerInfoEle.appendChild(
131                     XmlUtils.createOdStringEle(
132                             doc,
133                             XmlUtils.OD_NAME_APP_DEVELOPER_REGISTRY_ID,
134                             mAppDeveloperRegistryId));
135         }
136         return developerInfoEle;
137     }
138 
139     /** Creates the human-readable DOM elements from the AslMarshallable Java Object. */
toHrDomElement(Document doc)140     public Element toHrDomElement(Document doc) {
141         Element developerInfoEle = doc.createElement(XmlUtils.HR_TAG_DEVELOPER_INFO);
142         if (mName != null) {
143             developerInfoEle.setAttribute(XmlUtils.HR_ATTR_NAME, mName);
144         }
145         if (mEmail != null) {
146             developerInfoEle.setAttribute(XmlUtils.HR_ATTR_EMAIL, mEmail);
147         }
148         if (mAddress != null) {
149             developerInfoEle.setAttribute(XmlUtils.HR_ATTR_ADDRESS, mAddress);
150         }
151         if (mCountryRegion != null) {
152             developerInfoEle.setAttribute(XmlUtils.HR_ATTR_COUNTRY_REGION, mCountryRegion);
153         }
154         if (mDeveloperRelationship != null) {
155             developerInfoEle.setAttribute(
156                     XmlUtils.HR_ATTR_DEVELOPER_RELATIONSHIP, mDeveloperRelationship.toString());
157         }
158         if (mWebsite != null) {
159             developerInfoEle.setAttribute(XmlUtils.HR_ATTR_WEBSITE, mWebsite);
160         }
161         if (mAppDeveloperRegistryId != null) {
162             developerInfoEle.setAttribute(
163                     XmlUtils.HR_ATTR_APP_DEVELOPER_REGISTRY_ID, mAppDeveloperRegistryId);
164         }
165         return developerInfoEle;
166     }
167 }
168