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 customizedfor 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 delaybefore automatically restore the default connection. Set -1 if the connectiondoes 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 activitytimeout expires. May be less than the minimum allowed brightness settingthat 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 beautodetected 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 toverify 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 dzyresolver.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系统提供默认的亮度设置和自动亮度调节的参数。这些配置会在系统服务中被读取并应用,从而影响系统的亮度控制行为。通过这种方式,开发者可以灵活地配置和管理屏幕亮度,确保提供良好的用户体验。
觉得本文对您有用,麻烦点赞、关注、收藏,您的肯定是我创作的无限动力,谢谢!!!