1、Android指定某个文件的权限
当需要修改某文件或路径权限时,我们可以在init.rc开机启动某节点添加chmod命令进行修改。但是对于system分区,由于是ro权限,在init.rc使用chmod修改权限无效。需要在文件编译时,对权限进行修改。不同的Android版本改法一样,但是文件所在目录有差异,Android O主要修改文件是system\core\libcutils\fs_config.cpp。此文件可以修改目录和文件权限,具体可参考代码现有例子进行修改。
比如,修改su命令的权限为“04755”:
#ifdef CUSTOM_ROOT
{ 04755, AID_ROOT, AID_SHELL, 0, "system/xbin/su" },
#else
{ 04750, AID_ROOT, AID_SHELL, 0, "system/xbin/su" },
#endif
编译libcutils.so模块:
$ mmm system/core/libcutils/
重新编译system.img,再烧录system分区验证:
$ make systemimage -j32
2、Android增加信号强度(假)
该方案纯粹为了使WiFi信号从表面看上去更强,使原来3格信号的热点变为满格,以满足一些特殊需求。可以通过属性『ro.wifi.rssigain』配置 rssi 虚增多少db。
diff --git a/frameworks/opt/net/wifi/service/java/com/android/server/wifi/WificondControl.java b/frameworks/opt/ne
old mode 100644
new mode 100755
index b6104a8..2a71926
--- a/frameworks/opt/net/wifi/service/java/com/android/server/wifi/WificondControl.java
+++ b/frameworks/opt/net/wifi/service/java/com/android/server/wifi/WificondControl.java
@@ -28,6 +28,8 @@ import android.net.wifi.WifiSsid;
import android.os.Binder;
import android.os.RemoteException;
import android.util.Log;
+import android.os.SystemProperties;
+import android.text.TextUtils;
import com.android.server.wifi.hotspot2.NetworkDetail;
import com.android.server.wifi.util.InformationElementUtil;
@@ -72,6 +74,15 @@ public class WificondControl {
private String mClientInterfaceName;
+ // Added by ayst.shen@foxmail.com, for enhance signals.
+ private static int sRssiGain = 0;
+ static {
+ String gain = SystemProperties.get("ro.wifi.rssigain", "");
+ if (!TextUtils.isEmpty(gain)) {
+ sRssiGain = Integer.parseInt(gain);
+ }
+ }
+ // Added end
private class ScanEventHandler extends IScanEvent.Stub {
@Override
@@ -303,7 +314,7 @@ public class WificondControl {
return null;
}
WifiNative.SignalPollResult pollResult = new WifiNative.SignalPollResult();
- pollResult.currentRssi = resultArray[0];
+ pollResult.currentRssi = resultArray[0] + sRssiGain; // Modified by ayst.shen@foxmail.com, for enhance si
pollResult.txBitrate = resultArray[1];
pollResult.associationFrequency = resultArray[2];
return pollResult;
@@ -382,8 +393,9 @@ public class WificondControl {
continue;
}
+ // Modified by ayst.shen@foxmail.com, for enhance signals.
ScanDetail scanDetail = new ScanDetail(networkDetail, wifiSsid, bssid, flags,
- result.signalMbm / 100, result.frequency, result.tsf, ies, null);
+ (result.signalMbm / 100) + sRssiGain, result.frequency, result.tsf, ies, null);
// Update carrier network info if this AP's SSID is associated with a carrier Wi-Fi
// network and it uses EAP.
if (ScanResultUtil.isScanResultForEapNetwork(scanDetail.getScanResult())
属性配置:
# 值:整数,rssi增加的db值
ro.wifi.rssigain=6
3、Android 双路背光控制
双屏项目有时两个屏背光需要单独调节,而Android默认只有一路背光控制逻辑,因此,此方案从驱动到Android Framework增加一路背光控制逻辑,使得Android同时支持两路背光控制。
以下方案基于Rockchip平台实现,如果是其它平台,驱动和dts可能稍有变化。
kernel
dts
复制一份原背光配置,compatible 改为“pwm-backlight-ext”。
kernel\arch\arm\boot\dts\rk3288-android.dtsi
backlight_extend: backlight_extend {
compatible = "pwm-backlight-ext";
brightness-levels = <
255 231 231 230 230 229 229 229 228 228
228 227 227 227 226 226 226 226 225 225
225 224 224 224 224 223 223 223 222 222
222 221 221 221 220 220 219 218 217 216
215 214 213 212 211 210 209 208 207 206
205 204 203 202 201 200 199 198 197 196
195 194 193 192 191 190 189 188 187 186
185 184 183 182 181 180 179 178 177 176
175 174 173 172 171 170 169 168 167 166
165 164 163 162 161 169 159 158 157 156
155 154 153 152 151 150 149 148 147 146
145 143 142 141 140 139 138 137 136 135
134 133 132 131 130 129 128 127 126 125
124 123 122 121 120 119 118 117 116 115
114 113 112 111 110 109 108 107 106 105
104 103 102 101 100 99 98 97 96
95 94 93 92 91 90 89 88 87 86
85 84 83 82 81 80 79 78 77 76
75 74 73 72 71 70 69 68 67 66
65 64 63 62 61 60 59 58 57 56
55 54 53 52 51 50 49 48 47 46
45 44 43 42 41 40 39 38 37 36
35 34 33 32 31 30 29 28 27 26
25 24 23 22 21 20 19 18 17 16
15 14 13 12 11 10 9 8 7 6
5 4 3 2 1 0>;
default-brightness-level = <128>;
pwms = <&pwm2 0 25000 0>;
};
driver
修改kernel原背光驱动,of_device_id 数组增加“pwm-backlight-ext”。
kernel\drivers\video\backlight\pwm_bl.c
static struct of_device_id pwm_backlight_of_match[] = {
{ .compatible = "pwm-backlight" },
{ .compatible = "pwm-backlight-ext" },
{ }
};
开机后,驱动会创建对应的设备节点:
/sys/class/backlight/backlight/brightness
/sys/class/backlight/backlight_extend/brightness
Framework
参考 Android-DualBacklightAdjust 合入Framework补丁。
使用
系统设置
『设置->显示->副屏亮度』。
方法1 只调节亮度不保存值文章来源:https://www.toymoban.com/news/detail-489521.html
- 新建 app/src/main/aidl/android/os/ILightsService.aidl,内容如下:
package android.os;
/** {@hide} */
interface ILightsService
{
boolean setBrightness(int type, int brightness);
}
2.调用 setBrightness 方法。文章来源地址https://www.toymoban.com/news/detail-489521.html
package com.ayst.sample.items.backlight;
import android.annotation.SuppressLint;
import android.content.Context;
import android.os.IBinder;
import android.os.ILightsService;
import android.os.RemoteException;
import android.util.Log;
import java.lang.reflect.Method;
/**
* Created by Administrator on 2018/11/6.
*/
public class Lights {
private ILightsService mLightsService;
@SuppressLint("WrongConstant")
public Lights(Context context) {
Method method = null;
try {
method = Class.forName("android.os.ServiceManager").getMethod("getService", String.class);
IBinder binder = (IBinder) method.invoke(null, new Object[]{"lights"});
mLightsService = ILightsService.Stub.asInterface(binder);
if (mLightsService == null) {
Log.i("Lights", "mLightsService is null");
}
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* @param type
* BACKLIGHT=0,
* BACKLIGHT_EXT=1,
* KEYBOARD=2,
* BUTTONS=3,
* BATTERY=4,
* NOTIFICATIONS=5,
* ATTENTION=6,
* BLUETOOTH=7,
* WIFI=8,
* @param brightness 0~255
* @return
*/
public boolean setBrightness(int type, int brightness) {
if (null != mLightsService) {
try {
return mLightsService.setBrightness(type, brightness);
} catch (RemoteException e) {
e.printStackTrace();
}
}
return false;
}
}
方法2 调节亮度并保存值(推荐)
public void saveMainBrightness(int brightness) {
try {
Settings.System.putInt(mContext.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS, brightness);
} catch (Exception localException) {
localException.printStackTrace();
}
}
public void saveSubBrightness(int brightness) {
try {
/**
* Settings.System.SCREEN_BRIGHTNESS_EXT = "screen_brightness_ext"
*/
Settings.System.putInt(mContext.getContentResolver(), "screen_brightness_ext", brightness);
} catch (Exception localException) {
localException.printStackTrace();
}
}
到了这里,关于【干货】Android系统定制基础篇:第一部分(文件权限、增加信号强度、双路背光控制)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!