`

PowerManagerService sensor

阅读更多

默认分类 2010-12-24 14:34:55 阅读144 评论1   字号: 订阅

frameworks/base/services/java/com/android/server/PowerManagerService.java

首先通过sensormanager来获得service 这里以light sensor为例

 void systemReady() {
        mSensorManager = new SensorManager(mHandlerThread.getLooper());
        mProximitySensor = mSensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY);
        // don't bother with the light sensor if auto brightness is handled in hardware
        if (mUseSoftwareAutoBrightness) {
            mLightSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_LIGHT);
            enableLightSensor(true);
        }
这里使用enableLightSensor来确定是不是lightsensor有效

    private void enableLightSensor(boolean enable) {
        if (mDebugLightSensor) {
            Slog.d(TAG, "enableLightSensor " + enable);
        }
        if (mSensorManager != null && mLightSensorEnabled != enable) {
            mLightSensorEnabled = enable;
            // clear calling identity so sensor manager battery stats are accurate
            long identity = Binder.clearCallingIdentity();
            try {
                if (enable) {
                    mSensorManager.registerListener(mLightListener, mLightSensor,
                            SensorManager.SENSOR_DELAY_NORMAL);
                } else {
                    mSensorManager.unregisterListener(mLightListener);
                    mHandler.removeCallbacks(mAutoBrightnessTask);
                }
            } finally {
                Binder.restoreCallingIdentity(identity);
            }
        }
    }
如果有效就注册一下监听事件 监听mLightListener事件响应

    SensorEventListener mLightListener = new SensorEventListener() {
        public void onSensorChanged(SensorEvent event) {
            synchronized (mLocks) {
                // ignore light sensor while screen is turning off
                if (isScreenTurningOffLocked()) {
                    return;
                }

                int value = (int)event.values[0];
                long milliseconds = SystemClock.elapsedRealtime();
                if (mDebugLightSensor) {
                    Slog.d(TAG, "onSensorChanged: light value: " + value);
                }
                mHandler.removeCallbacks(mAutoBrightnessTask);
                if (mLightSensorValue != value) {
                    if (mLightSensorValue == -1 ||
                            milliseconds < mLastScreenOnTime + mLightSensorWarmupTime) {
                        // process the value immediately if screen has just turned on
                        lightSensorChangedLocked(value);
                    } else {
                        // delay processing to debounce the sensor
                        mLightSensorPendingValue = value;
                        mHandler.postDelayed(mAutoBrightnessTask, LIGHT_SENSOR_DELAY);
                    }
                } else {
                    mLightSensorPendingValue = -1;
                }
            }
        }

        public void onAccuracyChanged(Sensor sensor, int accuracy) {
            // ignore
        }
    };
看到onsensorchanged事件了吧 这里做事情 用handler来实现一个延迟消息发送 标准用法 执行什么样的任务呢?继续看

    private Runnable mAutoBrightnessTask = new Runnable() {
        public void run() {
            synchronized (mLocks) {
                int value = (int)mLightSensorPendingValue;
                if (value >= 0) {
                    mLightSensorPendingValue = -1;
                    lightSensorChangedLocked(value);
                }
            }
        }
    };
然后lightSensorChangedLocked函数里就是各个具体的灯的控制了 比如 mButtonLight.setBrightness(buttonValue);等等 还有很多灯的动画 比如呼吸灯之类的 目前的LightAnimator好像只有一种就是隔几秒闪一下。。。

分享到:
评论

相关推荐

    android system crash 总结

    通过分析系统 Dump 出的\data\anr\目录下的 Trace 文件,发现多处线程 waiting to lock 某个 object 导致死锁,根据这个 object 被锁死的 tid 跟踪到 PowerManagerService,并定位到 setScreenStateLocked() 方法,...

    backlight.zip

    这个界面与PowerManagerService进行通信,改变sysfs中的相关参数。 5. **自动亮度**:Android还支持自动亮度模式,通过环境光传感器(Ambient Light Sensor, ALS)感知周围光线,动态调整屏幕亮度。这涉及到硬件...

    Android屏幕自动调整亮度

    深入代码层面,可以看到`PowerManagerService.java`扮演了核心角色。在系统初始化阶段,通过检查`mUseSoftwareAutoBrightness`变量,如果为`true`,表示系统将启用软件级别的自动亮度调整功能。此时,会通过`...

    让你定制的Launcher成为系统中唯一的Launcher.txt

    - `PowerManagerService` - `TelephonyRegistry` - `PackageManagerService` - `AccountManagerService` - `BatteryService` - `HardwareService` - `Watchdog` - `SensorService` - `BluetoothService` -...

    android 屏幕亮度调节方法详解

    3. **PowerManagerService.java**:在系统服务层,`PowerManagerService` 是负责管理设备电源的组件,包括屏幕亮度的自动调节。`mUseSoftwareAutoBrightness` 变量控制是否启用软件自动亮度调节,其值同样在 `config...

    TestBrightness2.zip

    在Android源码中,这些功能主要由`SettingsProvider`、`WindowManagerService`和`PowerManagerService`等组件协同实现。 "项目说明.rar"可能是对"TestBrightness2"项目的详细解释,涵盖了项目目标、实现方法、使用...

    驱动综合能力面试-V1.21

    23. Android Framework系统级服务示例:Activity Manager Service(AMS)、Power Manager Service(PMS)。 短文翻译: 我们已经将最新的Android N代码推送到openlinux,适用于S905X、S905D、S805X和S912。这个版本...

    蓝牙芯片DA14531 DATASHEET.pdf

    The BLE firmware includes the L2CAP service layer protocols, Security Manager (SM), Attribute Protocol (ATT), the Generic Attribute Profile (GATT), and the Generic Access Profile (GAP). All profiles ...

    UPnP&DLNARefrence.7z

    │ │ │ ├── UPnP-av-ConnectionManager-v2-Service-20060531.pdf │ │ │ ├── UPnP-av-ContentDirectory-v2-Service-20060531.pdf │ │ │ ├── UPnP-av-MediaRenderer-v2-Device-20060531.pdf...

    ap6212a0_a33_sc3817r_神舟验证版本_借用nvram_ap6210这个配置文件_20170626_1834没有外层目录.7z

    &lt; &gt; Broadcom Bluetooth Low Power Manager Support &lt;*&gt; Realtek Bluesleep driver support 修改为: &lt;*&gt; Broadcom Bluetooth Low Power Manager Support &lt; &gt; An inverter between bt hostwake pin ...

    ap6212a0_bb16v3_sina33验证通过BT的功能_wifi部分有问题_20170626_1148没有外层目录.7z

    &lt; &gt; Broadcom Bluetooth Low Power Manager Support &lt;*&gt; Realtek Bluesleep driver support 修改为: &lt;*&gt; Broadcom Bluetooth Low Power Manager Support &lt; &gt; An inverter between bt hostwake pin ...

    !!!!ap6212a0_a33_sc3817r_验证通过_修正wifi的配置文件为nvram_ap6212.txt

    &lt; &gt; Broadcom Bluetooth Low Power Manager Support &lt;*&gt; Realtek Bluesleep driver support 修改为: &lt;*&gt; Broadcom Bluetooth Low Power Manager Support &lt; &gt; An inverter between bt hostwake pin ...

    ap6212a0_a33_sc3817r_服务器验证通过_bt已经通了_wifi需要修改配置_需要再次验证_20170626_1549.7z

    &lt; &gt; Broadcom Bluetooth Low Power Manager Support &lt;*&gt; Realtek Bluesleep driver support 修改为: &lt;*&gt; Broadcom Bluetooth Low Power Manager Support &lt; &gt; An inverter between bt hostwake pin ...

    WISE-PaaS快速实践物联网应用之关键技术与平台发展

    WISE-PaaS作为一款面向物联网应用的PaaS(Platform as a Service)平台,通过集成一系列关键技术和组件,为用户提供了一套全面且灵活的解决方案,帮助其实现物联网项目的快速部署与管理。 #### 关键技术与平台架构 ...

    windows-driver-kit-81-cpp

    2018\09\10 周一 17:27 &lt;DIR&gt; Metadata Manager File System Minifilter Driver 2018\09\10 周一 17:27 &lt;DIR&gt; Microsoft slate system virtual audio device driver sample 2018\09\10 周一 17:27 &lt;DIR&gt; Microsoft ...

Global site tag (gtag.js) - Google Analytics