需要的東西
- 一個不帶google apis的模擬器
- AOSP的簽名
1. 創(chuàng)建模擬器
選擇一個不帶google apis的模擬器系統(tǒng)胳搞,Android版本里是Android Open Source Project,也就是AOSP編譯出來的系統(tǒng)鏡像
2. 啟動模擬器
# 列出所有模擬器,找到你剛創(chuàng)建的模擬器
emulator -list-avds
# 啟動模擬器虱痕,指定系統(tǒng)可以寫入餐曼,emulator -avd @<YourAVDNameHere> -writable-system
emulator @Pixel_XL_API_31 -writable-system
3. 下載AOSP簽名
找到你模擬器系統(tǒng)對應(yīng)的AOSP源碼尘吗,這里需要“科學”,比如我是Android12的版本锄俄,簽名在
https://android.googlesource.com/platform/build/+/refs/heads/android12-release/target/product/security/
需要用到的就是這兩個文件platform.pk8、platform.x509.pem
4. 對你的apk進行簽名勺拣,并推送到/system/app
adb root
adb remount
apksigner sign --key platform.pk8 --cert platform.x509.pem <YourAPK>
adb shell mkdir /system/app/<YourAppFolder>
adb push <YourAPK> /system/app/<YourAppFolder>/
adb reboot
注意奶赠,你的apk需要在AndroidManifest.xml指明android:sharedUserId="android.uid.system"
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:sharedUserId="android.uid.system"
package="<YourPackageNameHere>">
簽名也可以存成keystore進行簽名,參考:https://github.com/getfatday/keytool-importkeypair
5. 判斷是否是system app
adb shell 命令行判斷
adb shell ps -A | grep <YourPackageNameHere>
app內(nèi)代碼判斷
public static boolean isSystemApplication(Context context, String packageName){
PackageManager mPackageManager = context.getPackageManager();
try {
final PackageInfo packageInfo = mPackageManager.getPackageInfo(packageName, PackageManager.GET_CONFIGURATIONS);
if((packageInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM)!=0){
return true;
}
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
return false;
}