1.0Ver
/frameworks/base/core/java/com/android/internal/app/ResolverActivity.java
+ private void setDefaultLauncher() {
+ try {
+ final PackageManager pm = getPackageManager();
+
+ //String defPackageName = "com.android.launcher3";
+ String defPackageName = "com.demo.launcher3";
+ String defClassName;
+
+ //defClassName = "com.android.searchlauncher.SearchLauncher";
+ defClassName = "com.demo.launcher.MainActivity";
+
+ Log.i("deflauncher", "deflauncher : PackageName = " +
+ defPackageName + " ClassName = " + defClassName);
+
+ IntentFilter filter = new IntentFilter();
+ filter.addAction("android.intent.action.MAIN");
+ filter.addCategory("android.intent.category.HOME");
+ filter.addCategory("android.intent.category.DEFAULT");
+
+ Intent intent = new Intent(Intent.ACTION_MAIN);
+ intent.addCategory(Intent.CATEGORY_HOME);
+ List<ResolveInfo> list = new ArrayList<ResolveInfo>();
+ list = pm.queryIntentActivities(intent, 0);
+ final int N = list.size();
+ ComponentName[] set = new ComponentName[N];
+ int bestMatch = 0;
+ for (int i = 0; i < N; i++) {
+ ResolveInfo r = list.get(i);
+ set[i] = new ComponentName(r.activityInfo.packageName,
+ r.activityInfo.name);
+ if (r.match > bestMatch) bestMatch = r.match;
+ }
+ ComponentName preActivity = new ComponentName(defPackageName, defClassName);
+ pm.addPreferredActivity(filter, bestMatch, set, preActivity);
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
protected void onCreate(Bundle savedInstanceState, Intent intent,
CharSequence title, int defaultTitleRes, Intent[] initialIntents,
List<ResolveInfo> rList, boolean supportsAlwaysUseOption) {
setTheme(appliedThemeResId());
super.onCreate(savedInstanceState);
+ if(mResolvingHome){
+ setDefaultLauncher();
+ finish();
+ return;
+ }
+
...
2.0Ver
/frameworks/base/core/java/com/android/internal/app/ResolverActivity.java
public final void onPostListReady(ResolverListAdapter listAdapter, boolean doPostProcessing,
boolean rebuildCompleted) {
...
if (isAutolaunching()) {
return;
}
+ //add start
+ if(setCustomerDefLauncher()){
+ return;
+ }
+ //add end
...
}
//add start
+ private boolean setCustomerDefLauncher(){
+ String defLauncher = "com.demo.launcher3";
+ int size = mMultiProfilePagerAdapter.getActiveListAdapter().getDisplayResolveInfoCount();
+ android.util.Log.d("TAG","setCustomerDefLauncher:"+size);
+ for (int i = 0; i<size; i++){
+ DisplayResolveInfo dInfo = mMultiProfilePagerAdapter.getActiveListAdapter().getDisplayResolveInfo(i);
+ if (null != dInfo && defLauncher.equals(dInfo.getResolveInfo().activityInfo.packageName)) {
+ Log.d("TAG", "find need set default launcher, set default launcher--->" + dInfo.getResolveInfo().activityInfo. packageName);
+ startSelected(i, true, false);
+ return true;
+ }
+ }
+ return false;
+ }
//add end
多个launcher时,防止闪屏
/frameworks/base/core/java/com/android/internal/app/ResolverListAdapter.java;
protected boolean rebuildList(boolean doPostProcessing) {
...
//add start
+ String defLauncher = "com.demo.launcher3;
+ for (ResolvedComponentInfo info : currentResolveList) {
+ ResolveInfo resolveInfo = info.getResolveInfoAt(0);
+ if (defLauncher.equals(resolveInfo.activityInfo.packageName)) {
+ currentResolveList = new ArrayList<>();
+ currentResolveList.add(info);
+ Log.d("tww", "find set default launcher--->" + resolveInfo.activityInfo.packageName);
+ break;
+ }
+ }
+ //add end
+
...
}
Android预置Apk,Android.mk/Android.bp
预置apk,整个东西其实非常简单,因为系统本身它自己也内置不少apk,找到对应目录,查看它怎么写,.mk或.bp文件,依葫芦画瓢就行了!!!
系统应用:Browser2,Calendar等,一般都在packages目录下
build/make/target/product/handheld_product.mk
# /product packages
PRODUCT_PACKAGES += \
+ demo \
Browser2 \
Calendar \
Camera2 \
...
Android.bp
android_app_import {
name: "demo", //要编译生成apk名字,单编译模块时候 make MyApp
// this needs to be a privileged application
privileged: true, //当一个模块被标识为 privileged: true 时,它将被视为具有特权权限,
//可以访问系统级别的资源或执行特权操作。
// Make sure the build system doesn't try to resign the APK
dex_preopt: {
enabled: true, // 是否启用dex预优化 是否预先生成dex文件,默认为true。
// 该属性会影响应用的首次启动速度及Android系统的启动速度
},
arch: { //通过cpu平台类型选择apk
arm: {
apk: "demo.apk",
},
arm64: {
apk: "demo.apk",
},
x86: {
apk: "demo.apk",
},
x86_64: {
apk: "demo.apk",
},
},
certificate: "platform", // 指定APK的签名方式
}
//类似
android_app_import {
name: "SogouInput",
apk: "SogouInput.apk",
// 保留apk自己的签名
// presigned: true,
// 打开将放到对应分区目录的priv-app文件夹下
privileged: true,
// 使用系统签名
certificate: "platform",
// 打开将放到system_ext分区
// system_ext_specific: true,
// 打开将放到product分区
// product_specific: true,
// 打开将放到vendor分区
// proprietary: true,
// device_specific: true
dex_preopt: {
enabled: false,
},
}
Android 13 内置三方应用app zzh
可能遇到的问题,预置apk 有没有需要带so库,预置的整个apk是可以卸载还是不能卸载?
//权限问题
frameworks/base/data/etc/privapp-permissions-platform.xml
//Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
# Module name should match apk name to be installed
LOCAL_MODULE := MyExample
LOCAL_MODULE_TAGS := optional
LOCAL_SRC_FILES := $(LOCAL_MODULE).apk
LOCAL_MODULE_CLASS := APPS
LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
LOCAL_PREBUILT_JNI_LIBS := lib\arm64-v8a\xxxx.so
LOCAL_CERTIFICATE := PRESIGNED
include $(BUILD_PREBUILT)
Android预置第三方Apk,so库不能读取问题
预置无源码apk到Android系统(带so文件)
Android.mk参数解析