首页 > 其他分享 >Android 11--设置第三方Launcher并默认 与 如何预置apk

Android 11--设置第三方Launcher并默认 与 如何预置apk

时间:2024-04-14 19:33:26浏览次数:26  
标签:预置 11 -- demo apk com Android true android

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
+ 
        ...
}

参考1

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参数解析

标签:预置,11,--,demo,apk,com,Android,true,android
From: https://www.cnblogs.com/kato-T/p/18134560

相关文章

  • 原型设计工具比较及实践
    墨刀:适用领域:墨刀适用于快速原型设计和协作,特别适合团队协作和迭代设计。优点:界面简洁直观,易于上手。提供丰富的交互组件和模板,能够快速搭建原型。支持多人协作,实时同步编辑,方便团队合作。缺点:功能相对较简单,适用范围有限。在复杂交互和动效方面可能不如其他工具。Axure......
  • Rust所有权__Ownership
    OwnershipisasetofrulesthatgovernhowaRustprogrammanagesmemory.Allprogramshavetomanagethewaytheyuseacomputer'smemorywhileruning.Somelanguageshave garbagecollectionthatregularlylooksforno-longer-usedmemoryasthepro......
  • 利用工具对特定恶意网站实行打击报复(一)
    以下内容属于纯技术记录,不存在恶意教唆他人去对非法分子实行打击报复,如造成相关利益损害,或者对受害人提供一些帮助,都与我无关,我只是想要打击报复那些广东深圳害中国人的王八蛋罢了。背景:本人因为想要试试某网站的水有多深,开始了一次小小随机的尝试,然后发现,这玩意一点也不概率,更......
  • 实验一-密码引擎-3-加密API
    实验一-密码引擎-3-加密API研究任务详情密码引擎API的主要标准和规范包括:微软的CryptoAPIRAS公司的PKCS#11标准中国商用密码标准:GMT0016-2012智能密码钥匙密码应用接口规范,GMT0018-2012密码设备应用接口规范等研究以上API接口,总结他们的异同,并以龙脉GM3000Key为例,写出......
  • 积木大赛
    转化成差分之后,差分数组里面正数的和一定不会小于负数的和的绝对值(因为\(h_i>0\)),所以答案的下界是正数的和我们来证明一定存在一种方案达到下界用数学归纳法。设差分数组为\(d\)显然\(d_1≥0\);也有\(d_1+d_2≥0\)(假设\(d_2\)为负),也就是说,我们可以通过先操作\(d_1\)和\(d_2\)来......
  • 实验一-密码引擎-3-加密API研究
    密码引擎API的主要标准和规范包括:微软的CryptoAPIRAS公司的PKCS#11标准中国商用密码标准:GMT0016-2012智能密码钥匙密码应用接口规范,GMT0018-2012密码设备应用接口规范等研究以上API接口,总结他们的异同,并以龙脉GM3000Key为例,写出调用不同接口的代码,提交博客链接和代码链......
  • 第十周
    第十周完成nginx编译安装脚本#!/bin/bashNGINX_VERSION=1.22.1NGINX_FILE=nginx-${NGINX_VERSION}.tar.gzNGINX_URL=http://nginx.org/download/NGINX_INSTALL_DIR=/apps/nginxSRC_DIR=/usr/local/srcCPUS=`lscpu|awk'/^CPU\(s\)/{print$2}'`./etc/os-rel......
  • 实验2C语言分支与循环基础应用编程
    #include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5intmain(){intnumber;inti;srand(time(0));for(i=0;i<N;++i){number=rand()%65+1;printf("20238331%04d\n"......
  • 抽象代数课程笔记
    抽象代数的意义:\(\newcommand{\a}{\alpha}\newcommand{\b}{\beta}\newcommand{\D}{\Delta}\newcommand{\eps}{\varepsilon}\newcommand{\ph}{\varphi}\newcommand{\t}{\theta}\newcommand{\la}{\lambda}\newcommand{\si}{\sigma}\newcommand{\d......
  • Ubuntu下离线安装PostgreSQL
      首先,我的环境是Ubuntu20.04  如果是在线安装,根据官网的介绍很简单#安装包sudoaptupdatesudoaptinstallwgetgnupg#导入仓库sudosh-c'echo"debhttps://apt.postgresql.org/pub/repos/apt$(lsb_release-cs)-pgdgmain">/etc/apt/......