




版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、android6.0 power顯示(亮度等)深入分析(二)DisplayManagerService一、DisplayManagerService注冊(cè)localDisplay的適配層我們先來(lái)看構(gòu)造函數(shù):cpp view plain copy 在CODE上查看代碼片派生到我的代碼片public DisplayManagerService(Context context) super(context); mContext = context; mHandler = new DisplayManagerHandler(DisplayThread.get().getLooper();/消息處理 mU
2、iHandler = UiThread.getHandler(); mDisplayAdapterListener = new DisplayAdapterListener();/display適配層監(jiān)視器 mSingleDisplayDemoMode = SystemProperties.getBoolean("persist.demo.singledisplay", false); PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE); mGlobalDispl
3、ayBrightness = pm.getDefaultScreenBrightnessSetting();/成員變量屏幕亮度 我們?cè)賮?lái)看onStart函數(shù),publish了一個(gè)BinderService和LocalService,還有發(fā)送了一個(gè)消息。cpp view plain copy 在CODE上查看代碼片派生到我的代碼片Override public void onStart() mHandler.sendEmptyMessage(MSG_REGISTER_DEFAULT_DISPLAY_ADAPTER); publishBinderService(Context.DISPLAY_SE
4、RVICE, new BinderService(), true /*allowIsolated*/); publishLocalService(DisplayManagerInternal.class, new LocalService(); 我們看消息處理,就是調(diào)用了registerDefaultDisplayAdapter函數(shù):cpp view plain copy 在CODE上查看代碼片派生到我的代碼片Override public void handleMessage(Message msg) switch (msg.what) case MSG_REGISTER_DEFAULT_D
5、ISPLAY_ADAPTER: registerDefaultDisplayAdapter(); break; registerDefaultDisplayAdapter函數(shù)cpp view plain copy 在CODE上查看代碼片派生到我的代碼片private void registerDefaultDisplayAdapter() / Register default display adapter. synchronized (mSyncRoot) registerDisplayAdapterLocked(new LocalDisplayAdapter( mSyncRoot, mCo
6、ntext, mHandler, mDisplayAdapterListener); 再來(lái)看看registerDisplayAdapterLockedcpp view plain copy 在CODE上查看代碼片派生到我的代碼片private void registerDisplayAdapterLocked(DisplayAdapter adapter) mDisplayAdapters.add(adapter); adapter.registerLocked(); 這里就是register了DefaultDisplay的適配層,就是和背光相關(guān)的。在新建LocalDisplayAdapter
7、的時(shí)候我們把mDisplayAdapterListener傳過(guò)去了。二、LocalDisplayAdapter & LocalDisplayDeviceLocalDisplayAdapter構(gòu)造函數(shù)調(diào)用了父類的,而父類也就是保存了變量cpp view plain copy 在CODE上查看代碼片派生到我的代碼片public LocalDisplayAdapter(DisplayManagerService.SyncRoot syncRoot, Context context, Handler handler, Listener listener) super(syncRoot, con
8、text, handler, listener, TAG); 上面又緊跟著調(diào)用了registerLocked函數(shù)cpp view plain copy 在CODE上查看代碼片派生到我的代碼片public void registerLocked() super.registerLocked(); mHotplugReceiver = new HotplugDisplayEventReceiver(getHandler().getLooper(); for (int builtInDisplayId : BUILT_IN_DISPLAY_IDS_TO_SCAN) tryConnectDisplay
9、Locked(builtInDisplayId); tryConnectDisplayLocked函數(shù),先是看傳入的builtInDisplayId是否支持,一個(gè)是main,一個(gè)是hdmi的。cpp view plain copy 在CODE上查看代碼片派生到我的代碼片private void tryConnectDisplayLocked(int builtInDisplayId) IBinder displayToken = SurfaceControl.getBuiltInDisplay(builtInDisplayId); if (displayToken != null) Surfa
10、ceControl.PhysicalDisplayInfo configs = SurfaceControl.getDisplayConfigs(displayToken); if (configs = null) / There are no valid configs for this device, so we can't use it Slog.w(TAG, "No valid configs found for display device " + builtInDisplayId); return; int activeConfig = SurfaceC
11、ontrol.getActiveConfig(displayToken); if (activeConfig < 0) / There is no active config, and for now we don't have the / policy to set one. Slog.w(TAG, "No active config found for display device " + builtInDisplayId); return; LocalDisplayDevice device = mDevices.get(builtInDisplayId
12、); if (device = null) / Display was added. device = new LocalDisplayDevice(displayToken, builtInDisplayId, configs, activeConfig); mDevices.put(builtInDisplayId, device); sendDisplayDeviceEventLocked(device, DISPLAY_DEVICE_EVENT_ADDED); else if (device.updatePhysicalDisplayInfoLocked(configs, active
13、Config) / Display properties changed. sendDisplayDeviceEventLocked(device, DISPLAY_DEVICE_EVENT_CHANGED); else / The display is no longer available. Ignore the attempt to add it. / If it was connected but has already been disconnected, we'll get a / disconnect event that will remove it from mDev
14、ices. 然后再去查找這個(gè)LocalDisplayDevice,如果是找到了需要更新下configs,沒(méi)找到需要新建一個(gè)LocalDisplayDevice。最后都調(diào)用了sendDisplayDeviceEventLocked函數(shù)。我們?cè)賮?lái)看LocalDisplayDevice,如果傳入的是BUILT_IN_DISPLAY_ID_MAIN就是背光的,我們獲取背光的Light,保存在mBackLight變量。cpp view plain copy 在CODE上查看代碼片派生到我的代碼片public LocalDisplayDevice(IBinder displayToken, int bui
15、ltInDisplayId, SurfaceControl.PhysicalDisplayInfo physicalDisplayInfos, int activeDisplayInfo) super(LocalDisplayAdapter.this, displayToken, UNIQUE_ID_PREFIX + builtInDisplayId); mBuiltInDisplayId = builtInDisplayId; updatePhysicalDisplayInfoLocked(physicalDisplayInfos, activeDisplayInfo); if (mBuil
16、tInDisplayId = SurfaceControl.BUILT_IN_DISPLAY_ID_MAIN) LightsManager lights = LocalServices.getService(LightsManager.class); mBacklight = lights.getLight(LightsManager.LIGHT_ID_BACKLIGHT); else mBacklight = null; 然后上面函數(shù)調(diào)用了sendDisplayDeviceEventLocked函數(shù),就是調(diào)用了傳入的參數(shù)DisplayAdapterListenercpp view plain
17、 copy 在CODE上查看代碼片派生到我的代碼片protected final void sendDisplayDeviceEventLocked( final DisplayDevice device, final int event) mHandler.post(new Runnable() Override public void run() mListener.onDisplayDeviceEvent(device, event); ); 如果是新建就調(diào)用了handleDisplayDeviceAdded函數(shù),cpp view plain copy 在CODE上查看代碼片派生到我的代
18、碼片private final class DisplayAdapterListener implements DisplayAdapter.Listener Override public void onDisplayDeviceEvent(DisplayDevice device, int event) switch (event) case DisplayAdapter.DISPLAY_DEVICE_EVENT_ADDED: handleDisplayDeviceAdded(device); break; case DisplayAdapter.DISPLAY_DEVICE_EVENT_
19、CHANGED: handleDisplayDeviceChanged(device); break; case DisplayAdapter.DISPLAY_DEVICE_EVENT_REMOVED: handleDisplayDeviceRemoved(device); break; Override public void onTraversalRequested() synchronized (mSyncRoot) scheduleTraversalLocked(false); 我們先來(lái)看看handleDisplayDeviceAdded,最后將device保存在了mDisplayDe
20、vices中。cpp view plain copy 在CODE上查看代碼片派生到我的代碼片private void handleDisplayDeviceAdded(DisplayDevice device) synchronized (mSyncRoot) handleDisplayDeviceAddedLocked(device); private void handleDisplayDeviceAddedLocked(DisplayDevice device) DisplayDeviceInfo info = device.getDisplayDeviceInfoLocked(); i
21、f (mDisplayDevices.contains(device) Slog.w(TAG, "Attempted to add already added display device: " + info); return; Slog.i(TAG, "Display device added: " + info); device.mDebugLastLoggedDeviceInfo = info; mDisplayDevices.add(device); addLogicalDisplayLocked(device); Runnable work =
22、 updateDisplayStateLocked(device); if (work != null) work.run(); scheduleTraversalLocked(false); 三、設(shè)置背光現(xiàn)在我們?cè)谏掀┛筒皇钦f(shuō)背光的調(diào)制最后是在DisplayManagerService中,是在下面函數(shù)的requestGlobalDisplayStateInternal中調(diào)用的cpp view plain copy 在CODE上查看代碼片派生到我的代碼片public void initPowerManagement(final DisplayPowerCallbacks callbacks,
23、 Handler handler, SensorManager sensorManager) synchronized (mSyncRoot) DisplayBlanker blanker = new DisplayBlanker() Override public void requestDisplayState(int state, int brightness) / The order of operations is important for legacy reasons. if (state = Display.STATE_OFF) requestGlobalDisplayStat
24、eInternal(state, brightness); callbacks.onDisplayStateChange(state); if (state != Display.STATE_OFF) requestGlobalDisplayStateInternal(state, brightness); ; mDisplayPowerController = new DisplayPowerController( mContext, callbacks, handler, sensorManager, blanker); 我們?cè)賮?lái)看看requestGlobalDisplayStateInt
25、ernal函數(shù):cpp view plain copy 在CODE上查看代碼片派生到我的代碼片private void requestGlobalDisplayStateInternal(int state, int brightness) if (state = Display.STATE_UNKNOWN) state = Display.STATE_ON; if (state = Display.STATE_OFF) brightness = PowerManager.BRIGHTNESS_OFF; else if (brightness < 0) brightness = Powe
26、rManager.BRIGHTNESS_DEFAULT; else if (brightness > PowerManager.BRIGHTNESS_ON) brightness = PowerManager.BRIGHTNESS_ON; synchronized (mTempDisplayStateWorkQueue) try / Update the display state within the lock. / Note that we do not need to schedule traversals here although it / may happen as a si
27、de-effect of displays changing state. synchronized (mSyncRoot) if (mGlobalDisplayState = state && mGlobalDisplayBrightness = brightness) return; / no change Trace.traceBegin(Trace.TRACE_TAG_POWER, "requestGlobalDisplayState(" + Display.stateToString(state) + ", brightness=&quo
28、t; + brightness + ")"); mGlobalDisplayState = state; mGlobalDisplayBrightness = brightness; applyGlobalDisplayStateLocked(mTempDisplayStateWorkQueue); / Setting the display power state can take hundreds of milliseconds / to complete so we defer the most expensive part of the work until / a
29、fter we have exited the critical section to avoid blocking other / threads for a long time. for (int i = 0; i < mTempDisplayStateWorkQueue.size(); i+) mTempDisplayStateWorkQueue.get(i).run(); Trace.traceEnd(Trace.TRACE_TAG_POWER); finally mTempDisplayStateWorkQueue.clear(); 再看看applyGlobalDisplayS
30、tateLocked函數(shù),最后遍歷device調(diào)用updateDisplayStateLocked函數(shù)cpp view plain copy 在CODE上查看代碼片派生到我的代碼片private void applyGlobalDisplayStateLocked(List<Runnable> workQueue) final int count = mDisplayDevices.size(); for (int i = 0; i < count; i+) DisplayDevice device = mDisplayDevices.get(i); Runnable run
31、nable = updateDisplayStateLocked(device); if (runnable != null) workQueue.add(runnable); updateDisplayStateLocked函數(shù)調(diào)用device的requestDisplayStateLocked返回是Runnable,最后放在workQueue隊(duì)列中cpp view plain copy 在CODE上查看代碼片派生到我的代碼片private Runnable updateDisplayStateLocked(DisplayDevice device) / Blank or unblank t
32、he display immediately to match the state requested / by the display power controller (if known). DisplayDeviceInfo info = device.getDisplayDeviceInfoLocked(); if (info.flags & DisplayDeviceInfo.FLAG_NEVER_BLANK) = 0) return device.requestDisplayStateLocked(mGlobalDisplayState, mGlobalDisplayBri
33、ghtness); return null; 我們?cè)賮?lái)看看LocalDisplayDevice的requestDisplayStateLocked函數(shù)cpp view plain copy 在CODE上查看代碼片派生到我的代碼片public Runnable requestDisplayStateLocked(final int state, final int brightness) / Assume that the brightness is off if the display is being turned off. assert state != Display.STATE_OFF
34、 | brightness = PowerManager.BRIGHTNESS_OFF; final boolean stateChanged = (mState != state); final boolean brightnessChanged = (mBrightness != brightness) && mBacklight != null; if (stateChanged | brightnessChanged) final int displayId = mBuiltInDisplayId; final IBinder token = getDisplayTok
35、enLocked(); final int oldState = mState; if (stateChanged) mState = state;/ 狀態(tài) updateDeviceInfoLocked(); if (brightnessChanged) mBrightness = brightness;/保存亮度 / Defer actually setting the display state until after we have exited / the critical section since it can take hundreds of milliseconds / to
36、complete. return new Runnable() Override public void run() / Exit a suspended state before making any changes. int currentState = oldState; if (Display.isSuspendedState(oldState) | oldState = Display.STATE_UNKNOWN) if (!Display.isSuspendedState(state) setDisplayState(state); currentState = state; el
37、se if (state = Display.STATE_DOZE_SUSPEND | oldState = Display.STATE_DOZE_SUSPEND) setDisplayState(Display.STATE_DOZE); currentState = Display.STATE_DOZE; else return; / old state and new state is off / Apply brightness changes given that we are in a non-suspended state. if (brightnessChanged) setDi
38、splayBrightness(brightness);/設(shè)置亮度 / Enter the final desired state, possibly suspended. if (state != currentState) setDisplayState(state); private void setDisplayState(int state) if (DEBUG) Slog.d(TAG, "setDisplayState(" + "id=" + displayId + ", state=" + Display.stateTo
39、String(state) + ")"); Trace.traceBegin(Trace.TRACE_TAG_POWER, "setDisplayState(" + "id=" + displayId + ", state=" + Display.stateToString(state) + ")"); try final int mode = getPowerModeForState(state); SurfaceControl.setDisplayPowerMode(token, mode)
40、; finally Trace.traceEnd(Trace.TRACE_TAG_POWER); private void setDisplayBrightness(int brightness) if (DEBUG) Slog.d(TAG, "setDisplayBrightness(" + "id=" + displayId + ", brightness=" + brightness + ")"); Trace.traceBegin(Trace.TRACE_TAG_POWER, "setDispla
41、yBrightness(" + "id=" + displayId + ", brightness=" + brightness + ")"); try mBacklight.setBrightness(brightness);/真正的設(shè)置背光 finally Trace.traceEnd(Trace.TRACE_TAG_POWER); ; return null; 上面函數(shù)返回一個(gè)Runnable放在workQueue,在Runnable 中會(huì)調(diào)用mBacklight.setBrightness設(shè)置背光。之前是將Runna
42、ble接口都放在了mTempDisplayStateWorkQueue中,然后遍歷調(diào)用了run函數(shù)。最后就調(diào)用到了LocalDisplayDevice的Runnable接口中設(shè)置背光了。cpp view plain copy 在CODE上查看代碼片派生到我的代碼片synchronized (mSyncRoot) if (mGlobalDisplayState = state && mGlobalDisplayBrightness = brightness) return; / no change Trace.traceBegin(Trace.TRACE_TAG_POWER, &
43、quot;requestGlobalDisplayState(" + Display.stateToString(state) + ", brightness=" + brightness + ")"); mGlobalDisplayState = state; mGlobalDisplayBrightness = brightness; applyGlobalDisplayStateLocked(mTempDisplayStateWorkQueue); / Setting the display power state can take hu
44、ndreds of milliseconds / to complete so we defer the most expensive part of the work until / after we have exited the critical section to avoid blocking other / threads for a long time. for (int i = 0; i < mTempDisplayStateWorkQueue.size(); i+) mTempDisplayStateWorkQueue.get(i).run(); 四、背光hal層我們先
45、來(lái)看看LightsServicecpp view plain copy 在CODE上查看代碼片派生到我的代碼片public class LightsService extends SystemService static final String TAG = "LightsService" static final boolean DEBUG = false; final LightImpl mLights = new LightImplLightsManager.LIGHT_ID_COUNT; private final class LightImpl extends Light private LightImpl(int id) mId = id; Override public void setBrightness(int brightness) setBrightness(brightness, BRIGHTNESS_MODE_USER); Ove
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 配電臺(tái)區(qū)光儲(chǔ)協(xié)同優(yōu)化配置技術(shù)研究
- 嬰兒呼吸系統(tǒng)護(hù)理操作
- 初中學(xué)校管理課件
- 初中外研社說(shuō)課課件
- 保育員基礎(chǔ)知識(shí)課件
- 保持口腔健康的方法
- 初中創(chuàng)文主題班會(huì)課件
- TDO-IN-2-生命科學(xué)試劑-MCE
- Shikimate-3-phosphate-trisodium-生命科學(xué)試劑-MCE
- 交通運(yùn)輸與物流:物流行業(yè)無(wú)人機(jī)配送技術(shù)應(yīng)用與政策分析報(bào)告
- 2025年4月自考00908網(wǎng)絡(luò)營(yíng)銷與策劃試題及答案
- 南通國(guó)家級(jí)南通經(jīng)濟(jì)技術(shù)開發(fā)區(qū)公開招聘招商人員筆試歷年參考題庫(kù)附帶答案詳解
- 2025年數(shù)字媒體藝術(shù)專業(yè)考試試卷及答案
- 留疆戰(zhàn)士考試試題及答案
- 一般飼料企業(yè)質(zhì)量安全管理規(guī)范文件參考含制度記錄表格
- 2025+CSCO前列腺癌診療指南進(jìn)展
- 砂紙契房訂金合同協(xié)議
- 總體概述:施工組織總體設(shè)想、方案針對(duì)性及施工段劃分
- 2025年浙江金華義烏市水利工程管理有限公司招聘筆試參考題庫(kù)附帶答案詳解
- 義務(wù)教育物理課程標(biāo)準(zhǔn)解讀全文
- 2025年云南新華印刷五廠有限責(zé)任公司招聘筆試參考題庫(kù)含答案解析
評(píng)論
0/150
提交評(píng)論