Android Java framework各种各样的修改经验

Android Java framework各种各样的修改经验

顺手记录下修改系统时的经验,网上很容易就能搜到的就不记录了


修改下拉快捷菜单栏的菜单列表:

主要搜索qstile相关的类

xxxx/packages/apps/SystemUI/res/values/config.xml

1
2
3
4
5
6
7
8
9
<!-- The default tiles to display in QuickSettings -->
<string name="quick_settings_tiles_default" translatable="false">
wifi,bt,dnd,rotation,battery,cell,cast
</string>

<!-- Tiles native to System UI. Order should match "quick_settings_tiles_default" -->
<string name="quick_settings_tiles_stock" translatable="false">
wifi,cell,battery,dnd,rotation,bt,location,hotspot,inversion,saver,work,cast,night
</string>

如何在framework层获取当前api被调用时的进程对应的app的application context:

ActivityThread.currentActivityThread().getApplication()


去除@hide 但 make update-api和编译出错解决方法:

如果make update-api报错的话
要看对应方法里是不是有其他@hide的类或方法,比如参数的类是hide的,调用的api是hide的
要将所有相关的变量和api都去除hide,才能update成功
比如:
void aaa(B bbb){
ccc(bbb);
}
要保证B的类和ccc函数是非hide的


如何修改系统通话UI界面:

路径为:
packages/apps/Dialer/java/com/android/incallui/incall/impl
vendor/xxxxx/proprietary/packages/apps/Dialer/java/com/android/incallui/incall/impl

InCallFragment ,InCallButtonGridFragment是关键类,有很多代理类和presenter类


UsbManager在连接usb设备时需要request权限才能连接到usb设备,如何跳过申请权限的弹框,默认赋予权限呢

可以修改framework下的UsbUserSettingsManager:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
  // Temporary mapping USB device name to list of UIDs with permissions for the device
private final HashMap<String, SparseBooleanArray> mDevicePermissionMap =
new HashMap<>();
// Temporary mapping UsbAccessory to list of UIDs with permissions for the accessory
private final HashMap<UsbAccessory, SparseBooleanArray> mAccessoryPermissionMap =
new HashMap<>();

两个hashmap分别储存的uid和对应的usbdevice,只要存在即允许了权限
public boolean hasPermission(UsbDevice device, String packageName, int uid) {
synchronized (mLock) {
if (isCameraDevicePresent(device)) {
//camera权限,usb camera需要额外的camera权限
if (!isCameraPermissionGranted(packageName, uid)) {
return false;
}
}
//如果是系统uid,或者mDisablePermissionDialogs 设置禁用usb权限询问框,则默认拥有权限
if (uid == Process.SYSTEM_UID || mDisablePermissionDialogs) {
return true;
}
//获取对应usbdevice的已允许权限uid,如果uid存在则判断拥有权限
SparseBooleanArray uidList = mDevicePermissionMap.get(device.getDeviceName());
if (uidList == null) {
return false;
}
return uidList.get(uid);

}
}

系统编译自定义覆盖代码

资源文件:

Android Overlay机制允许在不修改packages中apk的情况下,来自定义 framework/package/vendor中的资源文件,实现资源的定制。来达到显示不同的UI得目的

PRODUCT_PACKAGE_OVERLAYS := device/vendor-name/device-name/product-name/overlay

Or:

DEVICE_PACKAGE_OVERLAYS := device/vendor-name/device-name/common/overlay

注意只能修改xml之类的资源文件,java文件无法替换。

代码文件:

通过修改 envsetup 和 lunch执行的mk文件,比如在build/core/envsetup.mk添加复制替换代码:

$(shell \cp -rf vendor/mediatek/xxxx/Camera.java frameworks/base/core/java/android/hardware/Camera.java)


通讯录如何判断是否是sim卡储存的号码:

1
2
3
4
5
6
7
8
9
10
11
12
13
 private static final String ACCOUNT_TYPE_SIM = "SIM Account";
private static final String ACCOUNT_TYPE_USIM = "USIM Account";
private static final String ACCOUNT_TYPE_RUIM = "RUIM Account";
private static final String ACCOUNT_TYPE_CSIM = "CSIM Account";

private static boolean isAccountTypeIccCard(String accountTypeString) {
boolean isIccCardAccount = (ACCOUNT_TYPE_SIM.equals(accountTypeString)
|| ACCOUNT_TYPE_USIM.equals(accountTypeString)
|| ACCOUNT_TYPE_RUIM.equals(accountTypeString)
|| ACCOUNT_TYPE_CSIM.equals(accountTypeString));
//Log.d(TAG, "account " + accountTypeString + " is IccCard? " + isIccCardAccount);
return isIccCardAccount;
}

app监听短信接收,只能监听到短短信,监听不到长短信:

检查系统短信应用Mms,长短信是需要系统短信应用去操作拼接的


修改系统蓝牙功能支持类型

vendor/xxxx/proprietary/packages/apps/Bluetooth/res/values/config.xml

修改如下对应功能支持的值

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<bool name="profile_supported_a2dp">true</bool>
<bool name="profile_supported_a2dp_sink">false</bool>
<bool name="profile_supported_hdp">false</bool>
<bool name="profile_supported_hs_hfp">true</bool>
<bool name="profile_supported_hfpclient">false</bool>
<bool name="profile_supported_hid">false</bool>
<bool name="profile_supported_opp">false</bool>
<bool name="profile_supported_pan">false</bool>
<bool name="profile_supported_pbap">false</bool>
<bool name="profile_supported_gatt">true</bool>
<bool name="pbap_include_photos_in_vcard">false</bool>
<bool name="pbap_use_profile_for_owner_vcard">false</bool>
<bool name="profile_supported_map">false</bool>
<bool name="profile_supported_avrcp_controller">false</bool>
<bool name="profile_supported_sap">false</bool>
<bool name="profile_supported_pbapclient">false</bool>
<bool name="profile_supported_mapmce">false</bool>
<bool name="profile_supported_hidd">false</bool>


Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×