1.新增一个全局的flag用来判断是否对flash做 disable/enable的动作
device/xx/xx/sepolicy/private/property_contexts
#OSX Security Changes Starts Here
ro.symbol.osx.version u:object_r:exported_system_prop:s0
ro.symbol.osx.version_legacy u:object_r:exported_system_prop:s0
#OSX Security Changes Ends Here
# Disabled/enabled flashlight when the battery reaches the specified conditions.
persist.sys.flash_enable u:object_r:exported_system_prop:s0 exact bool
2.在BatteryService中对当前Battery Level进行监控判断其是否在指定范围内从而对新的flag 进行赋值操作[/frameworks/base/services/core/java/com/android/server/BatteryService.java]
private void processValuesLocked(boolean force) {
boolean logOutlier = false;
...
//Disabled/enabled flashlight when the battery reaches the specified conditions.
if(xx)) {
if ((mHealthInfo.batteryLevel <= 20 && mHealthInfo.batteryTemperature / 10 <= -5) || (mHealthInfo.batteryLevel <= 30 && mHealthInfo.batteryTemperature / 10 <= -15)) {
if (!SystemProperties.get("persist.sys.flash_enable", "1").equals("0")) {
SystemProperties.set("persist.sys.flash_enable", "0");
}
} else {
if (!SystemProperties.get("persist.sys.flash_enable", "0").equals("1")) {
SystemProperties.set("persist.sys.flash_enable", "1");
}
}
}
...
}
3.在CameraRequest中对flash做相应的操作[/frameworks/base/core/java/android/hardware/camera2/CaptureRequest.java]
private String flashEnabled;
/**
* Initialize the builder using the template; the request takes
* ownership of the template.
*
* @param template Template settings for this capture request.
* @param reprocess Indicates whether to create a reprocess capture request. {@code true}
* to create a reprocess capture request. {@code false} to create a regular
* capture request.
* @param reprocessableSessionId The ID of the camera capture session this capture is
* created for. This is used to validate if the application
* submits a reprocess capture request to the same session
* where the {@link TotalCaptureResult}, used to create the
* reprocess capture, came from.
* @param logicalCameraId Camera Id of the actively open camera that instantiates the
* Builder.
* @param physicalCameraIdSet A set of physical camera ids that can be used to customize
* the request for a specific physical camera.
*
* @throws IllegalArgumentException If creating a reprocess capture request with an invalid
* reprocessableSessionId.
* @hide
*/
public Builder(CameraMetadataNative template, boolean reprocess,
int reprocessableSessionId, String logicalCameraId,
Set<String> physicalCameraIdSet) {
mRequest = new CaptureRequest(template, reprocess, reprocessableSessionId,
logicalCameraId, physicalCameraIdSet);
flashEnabled = SystemProperties.get("persist.sys.flash_enable", "1");
}
public <T> void set(@NonNull Key<T> key, T value) {
//Disabled/enabled flashlight when the battery reaches the specified conditions.
if (flashEnabled.equals("0")) {
if (key.getName().equals("android.flash.mode")) {
value = (T)new Integer(0); //FLASH_MODE_OFF
} else if (key.getName().equals("android.control.aeMode")) {
value = (T)new Integer(1); //CONTROL_AE_MODE_ON
}
}
mRequest.mLogicalCameraSettings.set(key, value);
}