当前位置:   article > 正文

Android framework配置默认屏幕亮度值源码分析_framework亮度调节

framework亮度调节

1、概述

Android中,config.xml文件用于配置各种系统设置和资源。对于屏幕亮度的配置,config.xml并不是直接用于设置屏幕亮度的地方,但它可以包含默认的系统设置和一些相关的参数。以下是如何在config.xml中配置一些与屏幕亮度相关的设置的详细步骤。

2、找到或创建config.xml

在Android系统源码中,config.xml通常位于以下路径:
frameworks/base/core/res/res/values/config.xml
如果项目中没有config.xml文件,可以在相应的路径下创建一个。

3、配置屏幕亮度相关参数

在config.xml中,可以定义与屏幕亮度相关的参数,例如默认亮度值、自动亮度调节参数等。以下是一个示例配置:

<?xml version="1.0" encoding="utf-8"?>
<!--
/*
** Copyright 2009, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
**     http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/
-->

<!-- These resources are around just to allow their values to be customized
     for different hardware and product builds. -->
<resources>
    <!-- Software blur is too slow on this device. -->
    <bool name="config_sf_slowBlur">true</bool>

    <!-- This device is not "voice capable"; it's data-only. -->
    <bool name="config_voice_capable">true</bool>

    <!-- This device does not allow sms service. -->
    <bool name="config_sms_capable">true</bool>

    <!-- Enable puk unlockscreen -->
    <bool name="config_enable_puk_unlock_screen">true</bool>

    <!-- An Array of "[Connection name],[ConnectivityManager.TYPE_xxxx],
         [associated radio-type],[priority],[restoral-timer(ms)],[dependencyMet]  -->
    <!-- the 5th element "resore-time" indicates the number of milliseconds to delay
         before automatically restore the default connection.  Set -1 if the connection
         does not require auto-restore. -->
    <!-- the 6th element indicates boot-time dependency-met value. -->
    <string-array translatable="false" name="networkAttributes">
        <item>"wifi,1,1,1,-1,true"</item>
        <item>"mobile,0,0,0,-1,true"</item>
        <item>"mobile_mms,2,0,2,60000,true"</item>
        <item>"mobile_supl,3,0,2,60000,true"</item>
        <item>"mobile_hipri,5,0,3,60000,true"</item>
        <item>"mobile_fota,10,0,2,60000,true"</item>
        <item>"mobile_ims,11,0,2,60000,true"</item>
        <item>"mobile_cbs,12,0,2,60000,true"</item>
        <item>"wifi_p2p,13,1,0,-1,true"</item>
        <item>"eth,9,9,4,60000,true"</item>
    </string-array>

    <!-- An Array of "[ConnectivityManager connectionType],
                      [# simultaneous connection types]"  -->
    <string-array translatable="false" name="radioAttributes">
        <item>"1,1"</item>
        <item>"0,1"</item>
        <item>"9,1"</item>
    </string-array>

	<!-- Minimum screen brightness setting allowed by the power manager.
	     The user is forbidden from setting the brightness below this level. -->
    <integer name="config_screenBrightnessSettingMinimum">10</integer>

    <!-- Maximum screen brightness allowed by the power manager.
         The user is forbidden from setting the brightness above this level. -->
    <integer name="config_screenBrightnessSettingMaximum">222</integer>

	<!-- Default screen brightness setting.
	     Must be in the range specified by minimum and maximum. -->
	<integer name="config_screenBrightnessSettingDefault">115</integer>


    <!-- Screen brightness used to dim the screen when the user activity
         timeout expires.  May be less than the minimum allowed brightness setting
         that can be set by the user. -->
    <integer name="config_screenBrightnessDim">1</integer>

    <!-- Whether a software navigation bar should be shown. NOTE: in the future this may be
         autodetected from the Configuration. -->
    <bool name="config_showNavigationBar">false</bool>

    <!-- If this is true, the screen will come on when you unplug usb/power/whatever. -->
    <bool name="config_unplugTurnsOnScreen">true</bool>

    <!--
       Sets the package names whose certificates should be used to
       verify location providers are allowed to be loaded.
    -->
    <string-array name="config_locationProviderPackageNames" translatable="false">
        <item>com.google.android.location</item>
        <item>com.android.location.fused</item>
    </string-array>

    <!--  Maximum number of supported users -->
    <integer name="config_multiuserMaximumUsers">1</integer>

    <!-- we don't want use hard menu key to unlock keyguard --> 
    <bool name="config_disableMenuKeyInLockScreen">true</bool>


    <!-- out side base package resource, we add it -->
    <add-resource type="integer" name="config_immersive_mode_confirmation_panic" />  
    <add-resource type="integer" name="config_max_over_scroll" />  

    <integer name="config_immersive_mode_confirmation_panic">5000</integer>
    <integer name="config_max_over_scroll">200</integer>

</resources>

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111

在这里插入图片描述

4、部分参数解读

config_screenBrightnessSettingDefault:设置屏幕亮度的默认值。这个值会在系统初始化时使用,范围是0到255。

config_screenBrightnessSettingMinimum:设置屏幕亮度的最低值。这个值确保屏幕亮度不会低于这个值,范围是0到255。

config_screenBrightnessSettingMaximum:设置屏幕亮度的最高值。这个值确保屏幕亮度不会高于这个值,范围是0到255。

5、使用配置

这些配置会被系统服务(如PowerManagerService、DisplayManagerService)读取并应用,具体实现可以参考前面提到的服务类。

例如,在PowerManagerService中,可以读取配置并应用默认亮度值:

 public void systemReady(TwilightService twilight, DreamManagerService dreamManager) {
        synchronized (mLock) {
            mSystemReady = true;
            mDreamManager = dreamManager;

            PowerManager pm = (PowerManager)mContext.getSystemService(Context.POWER_SERVICE);
            mScreenBrightnessSettingMinimum = pm.getMinimumScreenBrightnessSetting();
            mScreenBrightnessSettingMaximum = pm.getMaximumScreenBrightnessSetting();
            mScreenBrightnessSettingDefault = pm.getDefaultScreenBrightnessSetting();

            SensorManager sensorManager = new SystemSensorManager(mHandler.getLooper());

            // The notifier runs on the system server's main looper so as not to interfere
            // with the animations and other critical functions of the power manager.
            mNotifier = new Notifier(Looper.getMainLooper(), mContext, mBatteryStats,
                    createSuspendBlockerLocked("PowerManagerService.Broadcasts"),
                    mScreenOnBlocker, mPolicy);

            // The display power controller runs on the power manager service's
            // own handler thread to ensure timely operation.
            mDisplayPowerController = new DisplayPowerController(mHandler.getLooper(),
                    mContext, mNotifier, mLightsService, twilight, sensorManager,
                    mDisplayManagerService, mDisplayBlanker,
                    mDisplayPowerControllerCallbacks, mHandler);

            mWirelessChargerDetector = new WirelessChargerDetector(sensorManager,
                    createSuspendBlockerLocked("PowerManagerService.WirelessChargerDetector"));
            mSettingsObserver = new SettingsObserver(mHandler);
            mAttentionLight = mLightsService.getLight(LightsService.LIGHT_ID_ATTENTION);

            // Register for broadcasts from other components of the system.
            IntentFilter filter = new IntentFilter();
            filter.addAction(Intent.ACTION_BATTERY_CHANGED);
            mContext.registerReceiver(new BatteryReceiver(), filter, null, mHandler);

            filter = new IntentFilter();
            filter.addAction(Intent.ACTION_BOOT_COMPLETED);
            mContext.registerReceiver(new BootCompletedReceiver(), filter, null, mHandler);

            filter = new IntentFilter();
            filter.addAction(Intent.ACTION_DREAMING_STARTED);
            filter.addAction(Intent.ACTION_DREAMING_STOPPED);
            mContext.registerReceiver(new DreamReceiver(), filter, null, mHandler);

            filter = new IntentFilter();
            filter.addAction(Intent.ACTION_USER_SWITCHED);
            mContext.registerReceiver(new UserSwitchedReceiver(), filter, null, mHandler);

            filter = new IntentFilter();
            filter.addAction(Intent.ACTION_DOCK_EVENT);
            mContext.registerReceiver(new DockReceiver(), filter, null, mHandler);

            // Register for settings changes.
            final ContentResolver resolver = mContext.getContentResolver();
            resolver.registerContentObserver(Settings.Secure.getUriFor(
                    Settings.Secure.SCREENSAVER_ENABLED),
                    false, mSettingsObserver, UserHandle.USER_ALL);
            resolver.registerContentObserver(Settings.Secure.getUriFor(
                    Settings.Secure.SCREENSAVER_ACTIVATE_ON_SLEEP),
                    false, mSettingsObserver, UserHandle.USER_ALL);
            resolver.registerContentObserver(Settings.Secure.getUriFor(
                    Settings.Secure.SCREENSAVER_ACTIVATE_ON_DOCK),
                    false, mSettingsObserver, UserHandle.USER_ALL);
            resolver.registerContentObserver(Settings.System.getUriFor(
                    Settings.System.SCREEN_OFF_TIMEOUT),
                    false, mSettingsObserver, UserHandle.USER_ALL);
            resolver.registerContentObserver(Settings.Global.getUriFor(
                    Settings.Global.STAY_ON_WHILE_PLUGGED_IN),
                    false, mSettingsObserver, UserHandle.USER_ALL);
            resolver.registerContentObserver(Settings.System.getUriFor(
                    Settings.System.SCREEN_BRIGHTNESS),
                    false, mSettingsObserver, UserHandle.USER_ALL);
            resolver.registerContentObserver(Settings.System.getUriFor(
                    Settings.System.SCREEN_BRIGHTNESS_MODE),
                    false, mSettingsObserver, UserHandle.USER_ALL);
            //--------------for hdmi timeout add by dzy
            resolver.registerContentObserver(Settings.System.getUriFor(
                    Settings.System.HDMI_LCD_TIMEOUT),
                    false, mSettingsObserver, UserHandle.USER_ALL);
            //-----------------end------------------
            // Go.
            readConfigurationLocked();
            updateSettingsLocked();
            mDirty |= DIRTY_BATTERY_STATE;
            updatePowerStateLocked();
            
            new Thread() {
            public void run() {
                boolean waitSuspendOK;
                while(true) {
                    waitSuspendOK = false;
                    try {
                        Slog.d(TAG, "--- nativeWaitSuspendTimeout");
                        nativeWaitSuspendTimeout();
                        waitSuspendOK = true;
                    } catch (IOException e) {
                        Slog.e(TAG, "--- nativeWaitSuspendTimeout: " + e);
                    }


                    if (waitSuspendOK) {
                        int status = -1;
                        try {
                            status = nativeGetChargingStatus();
                            Slog.d(TAG, "--- charging status=" + status);
                        }  catch (IOException e) {
                            Slog.e(TAG, "--- nativeGetChargingStatus: " + e);
                        }

                        if (status != 1) {
                            PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
                            PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "suspend timeout to shutdownNormal");
                            wl.acquire(5000);

                            Slog.d(TAG, "--- shutdown now");

                            shutdownNormal();
                        }
                    } else {
                        try {
                            Thread.sleep(500);
                        } catch (InterruptedException e) {
                        }
                    }
                }
            }
        }.start();
        }
    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129

在这里插入图片描述

6、总结

通过在config.xml中配置屏幕亮度相关的参数,可以为Android系统提供默认的亮度设置和自动亮度调节的参数。这些配置会在系统服务中被读取并应用,从而影响系统的亮度控制行为。通过这种方式,开发者可以灵活地配置和管理屏幕亮度,确保提供良好的用户体验。

觉得本文对您有用,麻烦点赞、关注、收藏,您的肯定是我创作的无限动力,谢谢!!!
在这里插入图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/642918
推荐阅读
相关标签
  

闽ICP备14008679号