1. 亮度控制策略
/decompile-hw/decompile/app/HwPowerGenieEngine3/src/main/res/xml/backlight_policy.xml
<?xml version="1.0" encoding="utf-8"?>
2 <backlight_policy xmlns:android="http://schemas.android.com/apk/res/android" version="1">
3 <mode id="0" />
4 <mode id="1">
5 <action name="browser front" id="203">
6 <item name="policy_auto"
7 1 />
8 <item name="policy_ratio"
9 70 />
10 </action>
11 <action name="special front" id="-1">
12 <item name="policy_auto"
13 1 />
14 <item name="policy_ratio"
15 95 />
16 <item name="package_name"
17 com.huawei.appmarket />
18 <item name="package_name"
19 com.android.email />
20 <item name="package_name"
21 com.android.contacts />
22 <item name="package_name"
23 com.huawei.hidisk />
24 <item name="package_name"
25 com.qzone />
26 <item name="package_name"
27 com.tencent.mm />
28 </action>
29 <action name="game2d front" id="233">
30 <item name="policy_auto"
31 1 />
32 </action>
33 <action name="game3d front" id="204">
34 <item name="policy_auto"
35 1 />
36 </action>
37 <action name="office front" id="225">
38 <item name="policy_auto"
39 1 />
40 <item name="policy_ratio"
41 65 />
42 </action>
43 <action name="video front" id="228">
44 <item name="policy_auto"
45 1 />
46 <item name="policy_ratio"
47 85 />
48 </action>
49 <action name="video start" id="246">
50 <item name="policy_auto"
51 1 />
52 <item name="policy_ratio"
53 85 />
54 </action>
55 <action name="video end" id="247" />
56 <action name="ebook front" id="205">
57 <item name="policy_auto"
58 1 />
59 <item name="policy_ratio"
60 65 />
61 </action>
62 <action name="mms front" id="235">
63 <item name="policy_auto"
64 1 />
65 <item name="policy_ratio"
66 80 />
67 </action>
68 </mode>
69 <mode id="2">
70 <action name="browser front" id="203">
71 <item name="policy_ratio"
72 70 />
73 <item name="policy_auto"
74 1 />
75 </action>
76 <action name="office front" id="225">
77 <item name="policy_ratio"
78 70 />
79 <item name="policy_auto"
80 1 />
81 </action>
82 <action name="mms front" id="235">
83 <item name="policy_ratio"
84 85 />
85 <item name="policy_auto"
86 1 />
87 </action>
88 <action name="ebook front" id="205">
89 <item name="policy_ratio"
90 70 />
91 <item name="policy_auto"
92 1 />
93 </action>
94 <action name="special front" id="-1">
95 <item name="policy_auto"
96 1 />
97 <item name="policy_ratio"
98 95 />
99 <item name="package_name"
100 com.android.email />
101 <item name="package_name"
102 com.google.android.gm />
103 <item name="package_name"
104 com.huawei.hidisk />
105 <item name="package_name"
106 com.qzone />
107 <item name="package_name"
108 com.tencent.mm />
109 <item name="package_name"
110 com.android.contacts />
111 <item name="package_name"
112 com.taobao.taobao />
113 <item name="package_name"
114 com.jingdong.app.mall />
115 </action>
116 <action name="special front" id="-1">
117 <item name="policy_auto"
118 1 />
119 <item name="policy_ratio"
120 70 />
121 <item name="package_name"
122 com.huawei.android.webcustomize />
123 </action>
124 <action name="special front" id="-1">
125 <item name="policy_auto"
126 1 />
127 <item name="policy_ratio"
128 80 />
129 <item name="package_name"
130 com.huawei.hwmwlauncher />
131 </action>
132 <action name="fuzzy front" id="-2">
133 <item name="policy_auto"
134 1 />
135 <item name="policy_ratio"
136 95 />
137 <item name="package_name"
138 *blog />
139 <item name="package_name"
140 *weibo />
141 <item name="package_name"
142 *zaker />
143 <item name="package_name"
144 *mobileqq />
145 <item name="package_name"
146 *.news />
147 </action>
148 </mode>
149 <mode id="3" />
150 <mode id="4" />
151 </backlight_policy>
2. 策略加载,存放到数据库中
xref: /decompile-hw/decompile/app/HwPowerGenieEngine3/src/main/java/com/huawei/powergenie/core/policy/PolicyInitialization.java
public final class PolicyInitialization {
24 private static String CUSTDIR_BACKLIGHT_POLICY = "/product/etc/hwpg/backlight_policy.xml";07 public Uri addBacklightPolicy(int actionId, int powerMode, int policy, int value, String pkg) {
108 ContentValues values = new ContentValues(5);
109 values.put("action_id", Integer.valueOf(actionId));
110 values.put("power_mode", Integer.valueOf(powerMode));
111 values.put("policy_type", Integer.valueOf(policy));
112 values.put("policy_value", Integer.valueOf(value));
113 if (pkg != null) {
114 values.put("pkg_name", pkg);
115 }
116 return this.mResolver.insert(PolicyProvider.BACKLIGHT_URI, values);
117 }
3.从数据库中读取策略
/decompile-hw/decompile/app/HwPowerGenieEngine3/src/main/java/com/huawei/powergenie/modules/displaypower/BacklightControl.java (revision f5955e2b)
private boolean loadPolicy(int mode) {
271 Policy item;
272 this.mActionMapPolicy.clear();
273 this.mPkgMapPolicy.clear();
274 this.mFuzzyMatchPkgList.clear();
275 Cursor cursor = this.mContext.getContentResolver().query(PolicyProvider.BACKLIGHT_URI, null, "power_mode=? OR power_mode=? ", new String[]{Integer.toString(mode), "0"}, null);
276 if (cursor == null) {
277 Log.w("BacklightControl", "backlight table is not exist. ");
278 return false;
279 }
280 int idCol = cursor.getColumnIndex("action_id");
281 int typeCol = cursor.getColumnIndex("policy_type");
282 int valueCol = cursor.getColumnIndex("policy_value");
283 int pkgCol = cursor.getColumnIndex("pkg_name");
4.控制亮度的接口
/decompile-hw/decompile/framework/services/com/android/server/pg/PGManagerService.java (revision f5955e2b)
207 public void setLcdRatio(int ratio, boolean autoAdjust) {
208 if (!this.mSystemReady) {
209 Log.w(TAG, "not ready for setLcdRatio");
210 } else if (1000 != Binder.getCallingUid()) {
211 Log.e(TAG, "setLcdRatio permission not allowed. uid = " + Binder.getCallingUid());
212 } else {
213 this.mPms.setLcdRatio(ratio, autoAdjust);
214 }
215 }/decompile-hw/decompile/framework/hwServices/com/android/server/power/HwPowerManagerService.java (revision f5955e2b)public void setLcdRatio(int ratio, boolean autoAdjust) {
644 this.mLightsManager.getLight(0).setLcdRatio(ratio, autoAdjust);
645 }xref: /decompile-hw/decompile/framework/services/com/android/server/lights/LightsService.java (revision f5955e2b)94 public void setLcdRatio(int ratio, boolean autoAdjust) {
95 LightsService.mIsAutoAdjust = autoAdjust;
96 if (ratio > 100 || ratio < 1) {
97 LightsService.mRatio = 1.0d;
98 } else {
99 LightsService.mRatio = ((double) ratio) / 100.0d;
100 }
101 Slog.i(LightsService.TAG, "setLcdRatio ratio:" + ratio + " autoAdjust:" + autoAdjust);
102 setLightGradualChange(LightsService.mLcdBrightness, 0, true);
103 }