camera_metadata: add non-full hw level optional tag

Bug: 10838063
Change-Id: If6d1ef5bd58aca3a9a722e4317f5ce6804dd6680
diff --git a/camera/docs/CameraCharacteristicsTest.mako b/camera/docs/CameraCharacteristicsTest.mako
index 2c6c869..a983e67 100644
--- a/camera/docs/CameraCharacteristicsTest.mako
+++ b/camera/docs/CameraCharacteristicsTest.mako
@@ -67,14 +67,26 @@
             CameraCharacteristics props = mCameraManager.getCameraCharacteristics(ids[i]);
             assertNotNull(String.format("Can't get camera characteristics from: ID %s", ids[i]),
                                         props);
-            assertNotNull("Invalid property: ${entry.name}",
-                    props.get(CameraCharacteristics.${jkey_identifier(entry.name)}));
 
-            List<Key<?>> allKeys = props.getKeys();
-            assertNotNull(String.format("Can't get camera characteristics keys from: ID %s", ids[i],
-                                        props));
-            assertTrue("Key not in keys list: ${entry.name}",
-                    allKeys.contains(CameraCharacteristics.${jkey_identifier(entry.name)}));
+          % if entry.applied_optional:
+            Integer hwLevel = props.get(CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL);
+            assertNotNull("No hardware level reported! android.info.supportedHardwareLevel",
+                    hwLevel);
+            if (hwLevel == CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_FULL)
+          % endif
+            {
+
+                assertNotNull("Invalid property: ${entry.name}",
+                        props.get(CameraCharacteristics.${jkey_identifier(entry.name)}));
+
+                List<Key<?>> allKeys = props.getKeys();
+                assertNotNull(String.format("Can't get camera characteristics keys from: ID %s",
+                        ids[i], props));
+                assertTrue("Key not in keys list: ${entry.name}", allKeys.contains(
+                        CameraCharacteristics.${jkey_identifier(entry.name)}));
+
+            }
+
         }
     }
         % endif
diff --git a/camera/docs/CameraMetadataKeys.mako b/camera/docs/CameraMetadataKeys.mako
index 5e2f1c5..5c7ff2d 100644
--- a/camera/docs/CameraMetadataKeys.mako
+++ b/camera/docs/CameraMetadataKeys.mako
@@ -39,6 +39,16 @@
      * @see #${jenum_value(entry, value)}
     % endfor
   % endif
+  % if entry.optional:
+     *
+     * <b>Optional</b> - This value may be null on some devices.
+  % endif
+  % if any(tag.name == 'FULL' for tag in entry.tags):
+     *
+     * <b>{@link CameraCharacteristics#INFO_SUPPORTED_HARDWARE_LEVEL_FULL HARDWARE_LEVEL_FULL}</b> -
+     * Present on all devices that report being FULL level hardware devices in the
+     * {@link CameraCharacteristics#INFO_SUPPORTED_HARDWARE_LEVEL HARDWARE_LEVEL} key.
+  % endif
   % if entry.applied_visibility == 'hidden':
      *
      * @hide
@@ -82,4 +92,4 @@
 ${single_kind_keys(java_class, xml_kind)}\
     /*~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~
      * End generated code
-     *~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~O@*/
\ No newline at end of file
+     *~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~O@*/
diff --git a/camera/docs/docs.html b/camera/docs/docs.html
index 259bb72..6a70c32 100644
--- a/camera/docs/docs.html
+++ b/camera/docs/docs.html
@@ -8247,6 +8247,7 @@
             <td class="entry_tags">
               <ul class="entry_tags">
                   <li><a href="#tag_V1">V1</a></li>
+                  <li><a href="#tag_FULL">FULL</a></li>
               </ul>
             </td>
 
@@ -8558,6 +8559,7 @@
             <td class="entry_tags">
               <ul class="entry_tags">
                   <li><a href="#tag_V1">V1</a></li>
+                  <li><a href="#tag_FULL">FULL</a></li>
               </ul>
             </td>
 
@@ -9015,6 +9017,9 @@
             </td>
 
             <td class="entry_tags">
+              <ul class="entry_tags">
+                  <li><a href="#tag_FULL">FULL</a></li>
+              </ul>
             </td>
 
           </tr> <!-- end of entry -->
@@ -11380,7 +11385,7 @@
         </ul>
       </li> <!-- tag_EXIF -->
       <li id="tag_HAL2">HAL2 - 
-        Tag only used by camera device HAL 2.x
+        Entry is only used by camera device HAL 2.x
     
         <ul class="tags_entries">
           <li><a href="#controls_android.request.inputStreams">android.request.inputStreams</a> (controls)</li>
@@ -11389,6 +11394,15 @@
           <li><a href="#controls_android.blackLevel.lock">android.blackLevel.lock</a> (controls)</li>
         </ul>
       </li> <!-- tag_HAL2 -->
+      <li id="tag_FULL">FULL - 
+        Entry is required for full hardware level devices, and optional for other hardware levels
+    
+        <ul class="tags_entries">
+          <li><a href="#static_android.sensor.baseGainFactor">android.sensor.baseGainFactor</a> (static)</li>
+          <li><a href="#static_android.sensor.maxAnalogSensitivity">android.sensor.maxAnalogSensitivity</a> (static)</li>
+          <li><a href="#dynamic_android.sensor.temperature">android.sensor.temperature</a> (dynamic)</li>
+        </ul>
+      </li> <!-- tag_FULL -->
     </ul>
   </div>
 
diff --git a/camera/docs/metadata_model.py b/camera/docs/metadata_model.py
index 66fe9d6..7db5ffe 100644
--- a/camera/docs/metadata_model.py
+++ b/camera/docs/metadata_model.py
@@ -1018,6 +1018,11 @@
                 public entries are visible in the Android SDK.
     applied_visibility: As visibility, but always valid, defaulting to 'system'
                         if no visibility is given for an entry.
+    optional: a bool representing the optional attribute, which denotes the entry
+              is required for hardware level full devices, but optional for other
+              hardware levels.  None if not present.
+    applied_optional: As optional but always valid, defaulting to False if no
+                      optional attribute is present.
     tuple_values: A sequence of strings describing the tuple values,
                   None if container is not 'tuple'.
     description: A string description, or None.
@@ -1066,6 +1071,7 @@
       type_notes: A string with the notes for the type
       visibility: A string describing the visibility, eg 'system', 'hidden',
                   'public'
+      optional: A bool to mark whether optional for non-full hardware devices
       typedef: A string corresponding to a typedef's name attribute.
     """
 
@@ -1099,6 +1105,14 @@
     return self._visibility or 'system'
 
   @property
+  def optional(self):
+    return self._optional
+
+  @property
+  def applied_optional(self):
+    return self._optional or False
+
+  @property
   def name_short(self):
     return self.get_name_minimal()
 
@@ -1203,6 +1217,7 @@
       self._enum = None
 
     self._visibility = kwargs.get('visibility')
+    self._optional = kwargs.get('optional')
 
     self._property_keys = kwargs
 
@@ -1397,6 +1412,7 @@
                     'type',
                     'type_notes',
                     'visibility',
+                    'optional',
                     'typedef'
                    ]
 
diff --git a/camera/docs/metadata_parser_xml.py b/camera/docs/metadata_parser_xml.py
index f0ed12e..ec6957f 100755
--- a/camera/docs/metadata_parser_xml.py
+++ b/camera/docs/metadata_parser_xml.py
@@ -158,6 +158,11 @@
     d['visibility'] = entry.get('visibility')
 
     #
+    # Optional for non-full hardware level devices
+    #
+    d['optional'] = entry.get('optional') == 'true'
+
+    #
     # Typedef
     #
     d['type_name'] = entry.get('typedef')
diff --git a/camera/docs/metadata_properties.xml b/camera/docs/metadata_properties.xml
index abb9b5d..4c8960b 100644
--- a/camera/docs/metadata_properties.xml
+++ b/camera/docs/metadata_properties.xml
@@ -37,7 +37,10 @@
       <!-- TODO: fill the tag description -->
     </tag>
     <tag id="HAL2">
-        Tag only used by camera device HAL 2.x
+        Entry is only used by camera device HAL 2.x
+    </tag>
+    <tag id="FULL">
+        Entry is required for full hardware level devices, and optional for other hardware levels
     </tag>
   </tags>
 
@@ -1938,10 +1941,12 @@
             <tag id="DNG" />
           </entry>
         </namespace>
-        <entry name="baseGainFactor" type="rational" visibility="public">
+        <entry name="baseGainFactor" type="rational" visibility="public"
+        optional="true">
           <description>Gain factor from electrons to raw units when
           ISO=100</description>
           <tag id="V1" />
+          <tag id="FULL" />
         </entry>
         <entry name="blackLevelPattern" type="int32"
         type_notes="2x2 raw count block" container="array">
@@ -2020,7 +2025,8 @@
           adaptation</description>
           <tag id="DNG" />
         </entry>
-        <entry name="maxAnalogSensitivity" type="int32" visibility="public">
+        <entry name="maxAnalogSensitivity" type="int32" visibility="public"
+        optional="true">
           <description>Maximum sensitivity that is implemented
           purely through analog gain</description>
           <notes>For android.sensor.sensitivity values less than or
@@ -2028,6 +2034,7 @@
           values above this, it can be a mix of analog and
           digital</notes>
           <tag id="V1" />
+          <tag id="FULL" />
         </entry>
         <entry name="noiseModelCoefficients" type="float"
         type_notes="float constants A, B for the noise variance model"
@@ -2114,7 +2121,8 @@
           system</notes>
           <tag id="BC" />
         </entry>
-        <entry name="temperature" type="float" visibility="public">
+        <entry name="temperature" type="float" visibility="public"
+        optional="true">
           <description>The temperature of the sensor, sampled at the time
           exposure began for this frame.
 
@@ -2124,6 +2132,7 @@
 
           <units>celsius</units>
           <range>Optional. This value is missing if no temperature is available.</range>
+          <tag id="FULL" />
         </entry>
       </dynamic>
     </section>
diff --git a/camera/docs/metadata_properties.xsd b/camera/docs/metadata_properties.xsd
index 4e990bb..851dfd6 100644
--- a/camera/docs/metadata_properties.xsd
+++ b/camera/docs/metadata_properties.xsd
@@ -197,6 +197,14 @@
                 </restriction>
             </simpleType>
         </attribute>
+        <attribute name="optional" default="false">
+            <simpleType>
+                <restriction base="string">
+                    <enumeration value="false" />
+                    <enumeration value="true" />
+                </restriction>
+            </simpleType>
+        </attribute>
         <attribute name="typedef" type="string" />
     </complexType>
 
diff --git a/camera/docs/metadata_template.mako b/camera/docs/metadata_template.mako
index 5c03d3d..da15103 100644
--- a/camera/docs/metadata_template.mako
+++ b/camera/docs/metadata_template.mako
@@ -85,6 +85,9 @@
           % if prop.visibility:
                 visibility="${prop.visibility}"
           % endif
+          % if prop.optional:
+                optional="${str(prop.optional).lower()}"
+          % endif
           % if prop.enum:
                 enum="true"
           % endif