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

news2024/10/7 14:29:53

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>

在这里插入图片描述

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

在这里插入图片描述

6、总结

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

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

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1835495.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

STM32学习笔记(二)--GPIO通用输入输出口详解

&#xff08;1&#xff09;配置步骤1.使用RCC开启GPIO时钟2.使用GPIO_Init函数初始化GPIO3.使用输入或输出的函数等来控制GPIO 其中涉及外设有RCC、GPIO &#xff08;2&#xff09;代码示例 案例1&#xff08;设置PA0为推挽输出&#xff09; RCC_APB2PeriphClockCmd(RCC_APB2P…

RemObjects教程

File—Other…—RemObjects Data Abstract—ComboServer Step(1) 在出现的 NewRemObjects SDK Server 对话框中 Project Folder &#xff1a;文件存档路径 Project Name &#xff1a;工程名称 Also-Create a matching client application and a project group&#xff1a;在创…

破局消费供应链,企业费用管理如何应对变与不变?

供应链管理在过去一直被局限在生产与产品供应领域&#xff0c;更多被理解为生产及流通过程中&#xff0c;涉及将产品或服务提供给最终用户活动的上游与下游企业所形成的网链结构&#xff0c;即将产品从商家送到消费者手中整个链条。因为直接对企业利润产生重大影响&#xff0c;…

工厂能耗监控与管理

随着工业4.0的浪潮席卷全球&#xff0c;工厂的能耗监控与管理已不再是简单的节能降耗问题&#xff0c;而是关乎企业竞争力、环保责任及可持续发展的核心议题。在这个关键时刻&#xff0c;HiWoo Cloud平台以其独特的视角和强大的功能&#xff0c;为工厂能耗监控与管理领域带来全…

微信客服:塑造卓越客户体验的新引擎

在数字化快速发展的今天&#xff0c;企业与客户之间的沟通方式正在发生深刻变革。微信客服&#xff0c;作为这一变革中的重要一环&#xff0c;以其高效、便捷、智能的特点&#xff0c;正在逐步成为企业塑造卓越客户体验的新引擎。 一、微信客服的崛起 微信&#xff0c;作为中…

虚拟警示教育馆如何革新安全教育?揭秘其深远意义与实际优势

一、推动警示教育的创新与普及 虚拟警示教育馆是将传统警示教育与现代科技相结合的新型教育模式。其意义主要体现在以下几个方面&#xff1a; 1、增强教育的互动性和沉浸感&#xff1a;虚拟警示教育馆通过3D建模、VR等技术&#xff0c;创建逼真的警示场景。这种身临其境的体验能…

【css】如何修改input选中历史选项后,自动填充的蓝色背景色

自动填充前&#xff1a; 自动填充后&#xff1a; 解决办法 方法一&#xff1a;设置背景透明 改变input自动填充背景颜色 // 通过拉长过渡时间&#xff0c;和延迟过渡开始时间&#xff0c;掩盖input自动填充背景颜色input:-internal-autofill-previewed,input:-internal-aut…

2024年文献数据库合集分享

无论是刚踏入学术界的新手&#xff0c;还是经验丰富的资深学者&#xff0c;在寻找专业资料时都可能感到头疼&#xff1a;这些资料太专业了&#xff0c;普通网站难以找到... 许多人可能都有过这样的经历&#xff1a;急需一篇论文&#xff0c;却发现只有海外的专业网站才有&#…

企业为何需要搭建线上虚拟品牌展厅?

在数字化时代&#xff0c;线上虚拟品牌展厅已成为企业不可或缺的一部分。以下是构建线上虚拟品牌展厅的4大关键理由&#xff1a; 1、迎合在线购物趋势 随着移动互联网的飞速发展和普及&#xff0c;消费者越来越倾向于在线购物。一个线上虚拟品牌展厅能够完美地满足这一需求&am…

flac格式如何转mp3?7大热门实用音频转换软件大PK

FLAC是Free Lossless Audio Codec&#xff08;免费无损音频编解码器&#xff09;的缩写&#xff0c;是一种在压缩文件大小的同时保留原始音乐质量的音频格式。不过&#xff0c;大多数音频格式都会在音乐质量和文件大小之间做出权衡。当你使用flac获得更好的音乐质量时&#xff…

软考阅卷将完成?!软考成绩有望六月底公布!

2024上半年软考考试已于5月25日-28日举行&#xff0c;考完试后大家最关心的事情莫过于查分了。 一、最新消息 1、不同地区在报名时对成绩公布的时间有所预示&#xff0c;但并没有一个统一的日期举个例子&#xff0c;江苏考区预计在6月下旬公布成绩&#xff0c;而黑龙江考区则预…

echart在线图表demo下载直接运行

echart 全面的数据可视化图表解决方案 | 折线图、柱状图、饼图、散点图、水球图等各类图表展示 持续更新中 三色带下表题速度仪表盘 地图自定义图标 动态环形图饼状图 动态水波动圆形 多标题指针仪表盘 温度仪表盘带下标题 横向柱状图排名 环形饼状图 双折线趋势变化

影响建筑效果图后期时间的因素有哪些?渲染100邀请码1a12

建筑效果图是建筑设计师展示设计方案的重要手段&#xff0c;为了完美展现&#xff0c;我们通常会对效果图进行后期处理&#xff0c;那么影响后期时间的因素有哪些&#xff1f;这次我们来看看吧。 1、底图的质量 底图是指原始的渲染图片&#xff0c;它决定了后期处理的难易程度…

LVGL——(2)基础对象

目录 一、对象简介 二、基础对象简介 1、概念(lv_obj) 屏幕是没有父类的基础对象 屏幕对象的创建过程 LVGL的三层屏幕 2、大小(size) 相关函数 代码示例 3、位置(position) LVGL屏幕的原点 屏幕&#xff08;部件区域&#xff09;的表示 相关函数 LV_ALIGN_...参数…

无代码爬虫八爪鱼采集器-如何采集携程网指定酒店差评信息

场景描述&#xff1a;有一些酒店会分析同行的差评原因&#xff0c;以便提前做预案&#xff0c;避免自己酒店也放同样的错误。他们通过采集携程网指定酒店的提取中差评&#xff0c;使用的采集工具为无代码爬虫软件八爪鱼采集器免费版&#xff0c;下载链接&#xff1a;1.软件分享…

颠覆行业!格行随身WiFi重新定义服务标准,线上线下无缝融合!随身WiFi行业的“海底捞”!随身WiFi哪个品牌最可靠?随身WiFi靠谱推荐!

不得不承认网络销售是现如今的重要销售方式&#xff0c;刚刚结束的618&#xff0c;以及接下来的双11&#xff0c;双12等电商购物节都是异常火爆&#xff0c;可背后也有不同的声音传来&#xff0c;网店现在生意也难做了&#xff1f;消费正回归线下实体经济&#xff1f; 这就是因…

移动硬盘分区误删?专业恢复策略与预防措施

一、认识移动硬盘分区误删 在使用移动硬盘时&#xff0c;有时我们可能会遇到分区误删的情况。这通常指的是由于某种原因&#xff0c;用户错误地删除了移动硬盘上的某个分区&#xff0c;导致该分区内的所有数据丢失。分区误删是一种常见的数据丢失问题&#xff0c;对于用户来说…

计算机组成原理网课笔记2

存储系统基本概念 主存储器的基本组成 半导体元件的原理 存储芯片的基本原理 如何实现不同的寻址方式

【每日刷题】Day68

【每日刷题】Day68 &#x1f955;个人主页&#xff1a;开敲&#x1f349; &#x1f525;所属专栏&#xff1a;每日刷题&#x1f34d; &#x1f33c;文章目录&#x1f33c; 1. 451. 根据字符出现频率排序 - 力扣&#xff08;LeetCode&#xff09; 2. 最小的K个数_牛客题霸_牛客…

暑期计划打卡清单表怎么写 暑期待办计划清单

暑假来临&#xff0c;是不是感觉时间好像突然多了起来&#xff0c;但又不知道该做些什么好&#xff1f;别担心&#xff0c;列一个暑期计划打卡清单表&#xff0c;就能让你的暑假生活变得有条不紊、充实而有意义。 计划清单&#xff0c;就像是给暑假生活绘制的一张地图。没有它…