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

2024-06-04 8316阅读

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中,可以定义与屏幕亮度相关的参数,例如默认亮度值、自动亮度调节参数等。以下是一个示例配置:




    
    true
    
    true
    
    true
    
    true
    
    
    
    
        "wifi,1,1,1,-1,true"
        "mobile,0,0,0,-1,true"
        "mobile_mms,2,0,2,60000,true"
        "mobile_supl,3,0,2,60000,true"
        "mobile_hipri,5,0,3,60000,true"
        "mobile_fota,10,0,2,60000,true"
        "mobile_ims,11,0,2,60000,true"
        "mobile_cbs,12,0,2,60000,true"
        "wifi_p2p,13,1,0,-1,true"
        "eth,9,9,4,60000,true"
    
    
    
        "1,1"
        "0,1"
        "9,1"
    
	
    10
    
    222
	
	115
    
    1
    
    false
    
    true
    
    
        com.google.android.location
        com.android.location.fused
    
    
    1
     
    true
    
      
      
    5000
    200

Android framework配置默认屏幕亮度值源码分析 第1张

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

Android framework配置默认屏幕亮度值源码分析 第2张

6、总结

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

觉得本文对您有用,麻烦点赞、关注、收藏,您的肯定是我创作的无限动力,谢谢!!!

Android framework配置默认屏幕亮度值源码分析 第3张


    免责声明:我们致力于保护作者版权,注重分享,被刊用文章因无法核实真实出处,未能及时与作者取得联系,或有版权异议的,请联系管理员,我们会立即处理! 部分文章是来自自研大数据AI进行生成,内容摘自(百度百科,百度知道,头条百科,中国民法典,刑法,牛津词典,新华词典,汉语词典,国家院校,科普平台)等数据,内容仅供学习参考,不准确地方联系删除处理! 图片声明:本站部分配图来自人工智能系统AI生成,觅知网授权图片,PxHere摄影无版权图库和百度,360,搜狗等多加搜索引擎自动关键词搜索配图,如有侵权的图片,请第一时间联系我们,邮箱:ciyunidc@ciyunshuju.com。本站只作为美观性配图使用,无任何非法侵犯第三方意图,一切解释权归图片著作权方,本站不承担任何责任。如有恶意碰瓷者,必当奉陪到底严惩不贷!

    目录[+]