Battery level 在指定范围内对Camera flash的状态控制(lock && unlock)

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);
        }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值