Camera: add post RAW sensitivity keys

Bug: 26625646
Change-Id: I6c58d5a3da0e5091063eb3a6f746ba28ced45410
diff --git a/camera/docs/docs.html b/camera/docs/docs.html
index cae3b34..fbbd63c 100644
--- a/camera/docs/docs.html
+++ b/camera/docs/docs.html
@@ -188,6 +188,8 @@
             ><a href="#controls_android.control.sceneMode">android.control.sceneMode</a></li>
             <li
             ><a href="#controls_android.control.videoStabilizationMode">android.control.videoStabilizationMode</a></li>
+            <li
+            ><a href="#controls_android.control.postRawSensitivityBoost">android.control.postRawSensitivityBoost</a></li>
           </ul>
         </li>
         <li>
@@ -231,6 +233,8 @@
             ><a href="#static_android.control.awbLockAvailable">android.control.awbLockAvailable</a></li>
             <li
             ><a href="#static_android.control.availableModes">android.control.availableModes</a></li>
+            <li
+            ><a href="#static_android.control.postRawSensitivityBoostRange">android.control.postRawSensitivityBoostRange</a></li>
           </ul>
         </li>
         <li>
@@ -284,6 +288,8 @@
             ><a href="#dynamic_android.control.sceneMode">android.control.sceneMode</a></li>
             <li
             ><a href="#dynamic_android.control.videoStabilizationMode">android.control.videoStabilizationMode</a></li>
+            <li
+            ><a href="#dynamic_android.control.postRawSensitivityBoost">android.control.postRawSensitivityBoost</a></li>
           </ul>
         </li>
       </ul> <!-- toc_section -->
@@ -4129,6 +4135,70 @@
           <tr class="entry_spacer"><td class="entry_spacer" colspan="6"></td></tr>
            <!-- end of entry -->
         
+                
+          <tr class="entry" id="controls_android.control.postRawSensitivityBoost">
+            <td class="entry_name
+             " rowspan="3">
+              android.<wbr/>control.<wbr/>post<wbr/>Raw<wbr/>Sensitivity<wbr/>Boost
+            </td>
+            <td class="entry_type">
+                <span class="entry_type_name">int32</span>
+
+              <span class="entry_type_visibility"> [public]</span>
+
+
+
+
+
+
+            </td> <!-- entry_type -->
+
+            <td class="entry_description">
+              <p>The amount of additional sesnsitivity boost applied to output images
+after RAW sensor data is captured.<wbr/></p>
+            </td>
+
+            <td class="entry_units">
+              ISO arithmetic units,<wbr/> the same as android.<wbr/>sensor.<wbr/>sensitivity
+            </td>
+
+            <td class="entry_range">
+              <p><a href="#static_android.control.postRawSensitivityBoostRange">android.<wbr/>control.<wbr/>post<wbr/>Raw<wbr/>Sensitivity<wbr/>Boost<wbr/>Range</a></p>
+            </td>
+
+            <td class="entry_tags">
+            </td>
+
+          </tr>
+          <tr class="entries_header">
+            <th class="th_details" colspan="5">Details</th>
+          </tr>
+          <tr class="entry_cont">
+            <td class="entry_details" colspan="5">
+              <p>Some camera devices support additional digital sensitivity boosting in the
+camera processing pipeline after sensor RAW image is captured.<wbr/>
+Such a boost will be applied to YUV/<wbr/>JPEG format output images but will not
+have effect on RAW output formats like RAW_<wbr/>SENSOR,<wbr/> RAW10,<wbr/> RAW12 or RAW_<wbr/>OPAQUE.<wbr/></p>
+<p>This key is optional.<wbr/> Applications can assume there is no boost applied
+after RAW is captured if this key is not available.<wbr/>
+When this key is available,<wbr/> the sensitivity boost value must be within
+<a href="#controls_android.control.postRawSensitivityBoost">android.<wbr/>control.<wbr/>post<wbr/>Raw<wbr/>Sensitivity<wbr/>Boost</a>.<wbr/></p>
+<p>If the camera device cannot apply the exact boost requested,<wbr/> it will reduce the
+boost to the nearest supported value.<wbr/>
+The final boost value used will be available in the output capture result.<wbr/></p>
+<p>For devices that support post RAW sensitivity boost,<wbr/> the YUV/<wbr/>JPEG output images
+of such device will have the total sensitivity of
+<code><a href="#controls_android.sensor.sensitivity">android.<wbr/>sensor.<wbr/>sensitivity</a> * android.<wbr/>control.<wbr/>isp<wbr/>Sensitivity /<wbr/> 100</code>
+The sensitivity of RAW format images will always be <code><a href="#controls_android.sensor.sensitivity">android.<wbr/>sensor.<wbr/>sensitivity</a></code></p>
+<p>This control is only effective if <a href="#controls_android.control.aeMode">android.<wbr/>control.<wbr/>ae<wbr/>Mode</a> or <a href="#controls_android.control.mode">android.<wbr/>control.<wbr/>mode</a> is set to
+OFF; otherwise the auto-exposure algorithm will override this value.<wbr/></p>
+            </td>
+          </tr>
+
+
+          <tr class="entry_spacer"><td class="entry_spacer" colspan="6"></td></tr>
+           <!-- end of entry -->
+        
         
 
       <!-- end of kind -->
@@ -5397,6 +5467,75 @@
           <tr class="entry_spacer"><td class="entry_spacer" colspan="6"></td></tr>
            <!-- end of entry -->
         
+                
+          <tr class="entry" id="static_android.control.postRawSensitivityBoostRange">
+            <td class="entry_name
+             " rowspan="5">
+              android.<wbr/>control.<wbr/>post<wbr/>Raw<wbr/>Sensitivity<wbr/>Boost<wbr/>Range
+            </td>
+            <td class="entry_type">
+                <span class="entry_type_name">int32</span>
+                <span class="entry_type_container">x</span>
+
+                <span class="entry_type_array">
+                  2
+                </span>
+              <span class="entry_type_visibility"> [public as rangeInt]</span>
+
+
+
+
+                <div class="entry_type_notes">Range of supported post RAW sensitivitiy boosts</div>
+
+
+            </td> <!-- entry_type -->
+
+            <td class="entry_description">
+              <p>Range of boosts for <a href="#controls_android.control.postRawSensitivityBoost">android.<wbr/>control.<wbr/>post<wbr/>Raw<wbr/>Sensitivity<wbr/>Boost</a> supported
+by this camera device.<wbr/></p>
+            </td>
+
+            <td class="entry_units">
+              ISO arithmetic units,<wbr/> the same as android.<wbr/>sensor.<wbr/>sensitivity
+            </td>
+
+            <td class="entry_range">
+            </td>
+
+            <td class="entry_tags">
+            </td>
+
+          </tr>
+          <tr class="entries_header">
+            <th class="th_details" colspan="5">Details</th>
+          </tr>
+          <tr class="entry_cont">
+            <td class="entry_details" colspan="5">
+              <p>Devices support post RAW sensitivity boost  will advertise
+<a href="#controls_android.control.postRawSensitivityBoost">android.<wbr/>control.<wbr/>post<wbr/>Raw<wbr/>Sensitivity<wbr/>Boost</a> key for controling
+post RAW sensitivity boost.<wbr/></p>
+<p>This key will be <code>null</code> for devices that do not support any RAW format
+outputs.<wbr/> For devices that do support RAW format outputs,<wbr/> this key will always
+present,<wbr/> and if a device does not support post RAW sensitivity boost,<wbr/> it will
+list <code>(100,<wbr/> 100)</code> in this key.<wbr/></p>
+            </td>
+          </tr>
+
+          <tr class="entries_header">
+            <th class="th_details" colspan="5">HAL Implementation Details</th>
+          </tr>
+          <tr class="entry_cont">
+            <td class="entry_details" colspan="5">
+              <p>This key is added in HAL3.<wbr/>4.<wbr/> For HAL3.<wbr/>3 or earlier devices,<wbr/> camera framework will
+generate this key as <code>(100,<wbr/> 100)</code> if device supports any of RAW output formats.<wbr/>
+All HAL3.<wbr/>4 and above devices should list this key if device supports any of RAW
+output formats.<wbr/></p>
+            </td>
+          </tr>
+
+          <tr class="entry_spacer"><td class="entry_spacer" colspan="6"></td></tr>
+           <!-- end of entry -->
+        
         
 
       <!-- end of kind -->
@@ -8615,6 +8754,70 @@
           <tr class="entry_spacer"><td class="entry_spacer" colspan="6"></td></tr>
            <!-- end of entry -->
         
+                
+          <tr class="entry" id="dynamic_android.control.postRawSensitivityBoost">
+            <td class="entry_name
+             " rowspan="3">
+              android.<wbr/>control.<wbr/>post<wbr/>Raw<wbr/>Sensitivity<wbr/>Boost
+            </td>
+            <td class="entry_type">
+                <span class="entry_type_name">int32</span>
+
+              <span class="entry_type_visibility"> [public]</span>
+
+
+
+
+
+
+            </td> <!-- entry_type -->
+
+            <td class="entry_description">
+              <p>The amount of additional sesnsitivity boost applied to output images
+after RAW sensor data is captured.<wbr/></p>
+            </td>
+
+            <td class="entry_units">
+              ISO arithmetic units,<wbr/> the same as android.<wbr/>sensor.<wbr/>sensitivity
+            </td>
+
+            <td class="entry_range">
+              <p><a href="#static_android.control.postRawSensitivityBoostRange">android.<wbr/>control.<wbr/>post<wbr/>Raw<wbr/>Sensitivity<wbr/>Boost<wbr/>Range</a></p>
+            </td>
+
+            <td class="entry_tags">
+            </td>
+
+          </tr>
+          <tr class="entries_header">
+            <th class="th_details" colspan="5">Details</th>
+          </tr>
+          <tr class="entry_cont">
+            <td class="entry_details" colspan="5">
+              <p>Some camera devices support additional digital sensitivity boosting in the
+camera processing pipeline after sensor RAW image is captured.<wbr/>
+Such a boost will be applied to YUV/<wbr/>JPEG format output images but will not
+have effect on RAW output formats like RAW_<wbr/>SENSOR,<wbr/> RAW10,<wbr/> RAW12 or RAW_<wbr/>OPAQUE.<wbr/></p>
+<p>This key is optional.<wbr/> Applications can assume there is no boost applied
+after RAW is captured if this key is not available.<wbr/>
+When this key is available,<wbr/> the sensitivity boost value must be within
+<a href="#controls_android.control.postRawSensitivityBoost">android.<wbr/>control.<wbr/>post<wbr/>Raw<wbr/>Sensitivity<wbr/>Boost</a>.<wbr/></p>
+<p>If the camera device cannot apply the exact boost requested,<wbr/> it will reduce the
+boost to the nearest supported value.<wbr/>
+The final boost value used will be available in the output capture result.<wbr/></p>
+<p>For devices that support post RAW sensitivity boost,<wbr/> the YUV/<wbr/>JPEG output images
+of such device will have the total sensitivity of
+<code><a href="#controls_android.sensor.sensitivity">android.<wbr/>sensor.<wbr/>sensitivity</a> * android.<wbr/>control.<wbr/>isp<wbr/>Sensitivity /<wbr/> 100</code>
+The sensitivity of RAW format images will always be <code><a href="#controls_android.sensor.sensitivity">android.<wbr/>sensor.<wbr/>sensitivity</a></code></p>
+<p>This control is only effective if <a href="#controls_android.control.aeMode">android.<wbr/>control.<wbr/>ae<wbr/>Mode</a> or <a href="#controls_android.control.mode">android.<wbr/>control.<wbr/>mode</a> is set to
+OFF; otherwise the auto-exposure algorithm will override this value.<wbr/></p>
+            </td>
+          </tr>
+
+
+          <tr class="entry_spacer"><td class="entry_spacer" colspan="6"></td></tr>
+           <!-- end of entry -->
+        
         
 
       <!-- end of kind -->
@@ -18152,6 +18355,8 @@
 requested,<wbr/> it will reduce the gain to the nearest supported
 value.<wbr/> The final sensitivity used will be available in the
 output capture result.<wbr/></p>
+<p>This control is only effective if <a href="#controls_android.control.aeMode">android.<wbr/>control.<wbr/>ae<wbr/>Mode</a> or <a href="#controls_android.control.mode">android.<wbr/>control.<wbr/>mode</a> is set to
+OFF; otherwise the auto-exposure algorithm will override this value.<wbr/></p>
             </td>
           </tr>
 
@@ -20574,6 +20779,8 @@
 requested,<wbr/> it will reduce the gain to the nearest supported
 value.<wbr/> The final sensitivity used will be available in the
 output capture result.<wbr/></p>
+<p>This control is only effective if <a href="#controls_android.control.aeMode">android.<wbr/>control.<wbr/>ae<wbr/>Mode</a> or <a href="#controls_android.control.mode">android.<wbr/>control.<wbr/>mode</a> is set to
+OFF; otherwise the auto-exposure algorithm will override this value.<wbr/></p>
             </td>
           </tr>
 
diff --git a/camera/docs/metadata_properties.xml b/camera/docs/metadata_properties.xml
index 5b09a63..d1c109f 100644
--- a/camera/docs/metadata_properties.xml
+++ b/camera/docs/metadata_properties.xml
@@ -2703,7 +2703,70 @@
               devices will always support OFF, AUTO modes.
           </details>
         </entry>
+        <entry name="postRawSensitivityBoostRange" type="int32" visibility="public"
+            type_notes="Range of supported post RAW sensitivitiy boosts"
+            container="array" typedef="rangeInt">
+          <array>
+            <size>2</size>
+          </array>
+          <description>Range of boosts for android.control.postRawSensitivityBoost supported
+            by this camera device.
+          </description>
+          <units>ISO arithmetic units, the same as android.sensor.sensitivity</units>
+          <details>
+            Devices support post RAW sensitivity boost  will advertise
+            android.control.postRawSensitivityBoost key for controling
+            post RAW sensitivity boost.
+
+            This key will be `null` for devices that do not support any RAW format
+            outputs. For devices that do support RAW format outputs, this key will always
+            present, and if a device does not support post RAW sensitivity boost, it will
+            list `(100, 100)` in this key.
+          </details>
+          <hal_details>
+             This key is added in HAL3.4. For HAL3.3 or earlier devices, camera framework will
+             generate this key as `(100, 100)` if device supports any of RAW output formats.
+             All HAL3.4 and above devices should list this key if device supports any of RAW
+             output formats.
+          </hal_details>
+        </entry>
       </static>
+      <controls>
+        <entry name="postRawSensitivityBoost" type="int32" visibility="public">
+          <description>The amount of additional sesnsitivity boost applied to output images
+             after RAW sensor data is captured.
+          </description>
+          <units>ISO arithmetic units, the same as android.sensor.sensitivity</units>
+          <range>android.control.postRawSensitivityBoostRange</range>
+          <details>
+          Some camera devices support additional digital sensitivity boosting in the
+          camera processing pipeline after sensor RAW image is captured.
+          Such a boost will be applied to YUV/JPEG format output images but will not
+          have effect on RAW output formats like RAW_SENSOR, RAW10, RAW12 or RAW_OPAQUE.
+
+          This key is optional. Applications can assume there is no boost applied
+          after RAW is captured if this key is not available.
+          When this key is available, the sensitivity boost value must be within
+          android.control.postRawSensitivityBoost.
+
+          If the camera device cannot apply the exact boost requested, it will reduce the
+          boost to the nearest supported value.
+          The final boost value used will be available in the output capture result.
+
+          For devices that support post RAW sensitivity boost, the YUV/JPEG output images
+          of such device will have the total sensitivity of
+          `android.sensor.sensitivity * android.control.ispSensitivity / 100`
+          The sensitivity of RAW format images will always be `android.sensor.sensitivity`
+
+          This control is only effective if android.control.aeMode or android.control.mode is set to
+          OFF; otherwise the auto-exposure algorithm will override this value.
+          </details>
+        </entry>
+      </controls>
+      <dynamic>
+        <clone entry="android.control.postRawSensitivityBoost" kind="controls">
+        </clone>
+      </dynamic>
     </section>
     <section name="demosaic">
       <controls>
@@ -5903,6 +5966,9 @@
           requested, it will reduce the gain to the nearest supported
           value. The final sensitivity used will be available in the
           output capture result.
+
+          This control is only effective if android.control.aeMode or android.control.mode is set to
+          OFF; otherwise the auto-exposure algorithm will override this value.
           </details>
           <hal_details>ISO 12232:2006 REI method is acceptable.</hal_details>
           <tag id="V1" />
diff --git a/camera/include/system/camera_metadata_tags.h b/camera/include/system/camera_metadata_tags.h
index 3d54003..0fc4ed1 100644
--- a/camera/include/system/camera_metadata_tags.h
+++ b/camera/include/system/camera_metadata_tags.h
@@ -158,6 +158,8 @@
     ANDROID_CONTROL_AE_LOCK_AVAILABLE,                // enum         | public
     ANDROID_CONTROL_AWB_LOCK_AVAILABLE,               // enum         | public
     ANDROID_CONTROL_AVAILABLE_MODES,                  // byte[]       | public
+    ANDROID_CONTROL_POST_RAW_SENSITIVITY_BOOST_RANGE, // int32[]      | public
+    ANDROID_CONTROL_POST_RAW_SENSITIVITY_BOOST,       // int32        | public
     ANDROID_CONTROL_END,
 
     ANDROID_DEMOSAIC_MODE =                           // enum         | system
diff --git a/camera/src/camera_metadata_tag_info.c b/camera/src/camera_metadata_tag_info.c
index 89879a7..f9d3eb6 100644
--- a/camera/src/camera_metadata_tag_info.c
+++ b/camera/src/camera_metadata_tag_info.c
@@ -212,6 +212,10 @@
     { "awbLockAvailable",              TYPE_BYTE   },
     [ ANDROID_CONTROL_AVAILABLE_MODES - ANDROID_CONTROL_START ] =
     { "availableModes",                TYPE_BYTE   },
+    [ ANDROID_CONTROL_POST_RAW_SENSITIVITY_BOOST_RANGE - ANDROID_CONTROL_START ] =
+    { "postRawSensitivityBoostRange",  TYPE_INT32  },
+    [ ANDROID_CONTROL_POST_RAW_SENSITIVITY_BOOST - ANDROID_CONTROL_START ] =
+    { "postRawSensitivityBoost",       TYPE_INT32  },
 };
 
 static tag_info_t android_demosaic[ANDROID_DEMOSAIC_END -
@@ -1332,6 +1336,12 @@
         case ANDROID_CONTROL_AVAILABLE_MODES: {
             break;
         }
+        case ANDROID_CONTROL_POST_RAW_SENSITIVITY_BOOST_RANGE: {
+            break;
+        }
+        case ANDROID_CONTROL_POST_RAW_SENSITIVITY_BOOST: {
+            break;
+        }
 
         case ANDROID_DEMOSAIC_MODE: {
             switch (value) {