1、将需要的添加包放在/frameworks/base/core/java/com目录下,比如devmgr/devicemgr/DeviceMgr.java
package com.devmgr.devicemgr;
import android.content.Context;
public class DeviceMgr {
private volatile static DeviceMgr instance = null;
private Context mContext;
public static DeviceMgr getInstance(Context context) {
if(instance==null){
instance=new DeviceMgr(context);
}
return instance;
}
private DeviceMgr(Context context){
this.mContext=context;
}
public int createApn(String apnInfo){
return 0;
}
public boolean deleteApn(int apnId){
return true;
}
..................................
}
2、打开/build/soong/scripts/check_boot_jars/package_allowed_list.txt
在文件最后增加:
com\.devmgr\.devicemgr
com\.devmgr\.devicemgr\..*
编译系统。
需要注意的是反斜杠和包名对应关系。
剩下的就是实现包里面的方法了。
结合
Android13增加一个systemservice,并允许APP访问-CSDN博客
就是按照定制,方法访问systemservice,并实现其方法:
public int createApn(String apnInfo) {
try {
return mService.createApn(apnInfo);
} catch (RemoteException e) {
e.printStackTrace();
throw e.rethrowAsRuntimeException();
}
}
普通APP可以compileOnly files jar包,调用系统实现,操作一些普通APP做不了的事情了。