




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、android6.0 power顯示(亮度等)深入分析(二)DisplayManagerService一、DisplayManagerService注冊localDisplay的適配層我們先來看構(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();/成員變量屏幕亮度 我們再來看onStart函數(shù),publish了一個BinderService和LocalService,還有發(fā)送了一個消息。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); 再來看看registerDisplayAdapterLockedcpp view plain copy 在CODE上查看代碼片派生到我的代碼片private void registerDisplayAdapterLocked(DisplayAdapter adapter) mDisplayAdapters.add(adapter); adapter.registerLocked(); 這里就是register了DefaultDisplay的適配層,就是和背光相關(guān)的。在新建LocalDisplayAdapter
7、的時候我們把mDisplayAdapterListener傳過去了。二、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是否支持,一個是main,一個是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. 然后再去查找這個LocalDisplayDevice,如果是找到了需要更新下configs,沒找到需要新建一個LocalDisplayDevice。最后都調(diào)用了sendDisplayDeviceEventLocked函數(shù)。我們再來看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); 我們先來看看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)在我們在上篇博客不是說背光的調(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); 我們再來看看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隊列中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; 我們再來看看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ù)返回一個Runnable放在workQueue,在Runnable 中會調(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、來看看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. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 體育個人課題申報書范例
- 課題申報書點(diǎn)評模板
- 兵團(tuán)立項課題申報書
- 課題申報書格式
- 陜西課題申報書范文樣本
- 烏魯木齊供用熱合同范本
- 怎么填課題申報書
- 品牌專利持有合同范本
- 會展場館租賃合同范本
- 科學(xué)技術(shù)課題申報書
- 膿毒血癥護(hù)理查房
- 蘇科版七年級數(shù)學(xué)下冊期末復(fù)習(xí)+10(專題-幾何圖形的證明)
- 西方經(jīng)濟(jì)學(xué)(第二版)完整整套教學(xué)課件
- 《零基礎(chǔ)玩轉(zhuǎn)小紅書:吃透爆款邏輯漲粉、變現(xiàn)不再難》
- 圍術(shù)期下肢深靜脈血栓預(yù)防的術(shù)中護(hù)理
- 《云南瀾滄鉛礦有限公司勐濱煤礦采礦權(quán)價款退還計算說明》
- GB/T 9113.1-2000平面、突面整體鋼制管法蘭
- GB/T 2423.18-2021環(huán)境試驗第2部分:試驗方法試驗Kb:鹽霧,交變(氯化鈉溶液)
- 2021年湖北師范學(xué)院專升本C語言程序設(shè)計試卷
- CB/T 3136-1995船體建造精度標(biāo)準(zhǔn)
- 疫苗冰箱溫度記錄表
評論
0/150
提交評論