Android14 启动launcher流程 (二)

根据前面 Android14 启动launcher流程 (一) 接着分析

一、修改启动主页(刷机生效)

frameworks/base/core/java/com/android/internal/app/ResolverActivity.java

protected void onCreate(Bundle savedInstanceState, Intent intent,
            CharSequence title, int defaultTitleRes, Intent[] initialIntents,
            List<ResolveInfo> rList, boolean supportsAlwaysUseOption) {
    // The last argument of createResolverListAdapter is whether to do special handling
    // of the last used choice to highlight it in the list.  We need to always
    // turn this off when running under voice interaction, since it results in
    // a more complicated UI that the current voice interaction flow is not able
    // to handle. We also turn it off when the work tab is shown to simplify the UX.
    // We also turn it off when clonedProfile is present on the device, because we might have
    // different "last chosen" activities in the different profiles, and PackageManager doesn't
    // provide any more information to help us select between them.
    boolean filterLastUsed = mSupportsAlwaysUseOption && !isVoiceInteraction()
            && !shouldShowTabs() && !hasCloneProfile();
    mMultiProfilePagerAdapter = createMultiProfilePagerAdapter(initialIntents, rList, filterLastUsed);

    //add by dunn start
    String launcherPackagename = SystemProperties.get("ro.default.start.pkg", "com.coocaa.study.jxw");
    String launcherActivityname = SystemProperties.get("ro.default.start.cls", "com.ccos.cooui.study.MainActivity");
    Log.e("deflauncher", "onCreate : launcherPackagename = " +launcherPackagename + " launcherActivityname = " + launcherActivityname);
    //String launcherPackagename = "com.coocaa.study.jxw";
    //String launcherActivityname = "com.ccos.cooui.study.MainActivity";
    //String launcherPackagename = "com.ksj.cloud.zone";
    //String launcherActivityname = "com.ksj.cloud.zone.activity.EmptyActivity";
    if(launcherPackagename != null && launcherPackagename.length()>0 &&launcherActivityname != null && launcherActivityname.length()>0){
        if(mResolvingHome){
            setDefaultLauncher(launcherPackagename,launcherActivityname);
            finish();
            return;
        }
            }
    //add by dunn end

    if (configureContentView()) {
        return;
    }            
}

//add by dunn start
private void setDefaultLauncher(String defPackageName,String defClassName) {
    try {
        final PackageManager pm = getPackageManager();
        Log.e("deflauncher", "setDefaultLauncher : 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);
            Log.e("deflauncher","setDefaultLauncher: r="+r);
            set[i] = new ComponentName(r.activityInfo.packageName,
                    r.activityInfo.name);
            Log.e("deflauncher","setDefaultLauncher: ComponentName="+set[i]);
            if (r.match > bestMatch) bestMatch = r.match;
        }
        ComponentName preActivity = new ComponentName(defPackageName, defClassName);
        //设置选定的主页
        pm.addPreferredActivity(filter, bestMatch, set, preActivity);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
//add by dunn end

打印信息:

07-04 10:50:19.084  4339  4339 E deflauncher: onCreate : launcherPackagename = com.dunn.instrument launcherActivityname =
© 版权声明
THE END
如果内容对您有所帮助,就支持一下吧!
点赞0 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容