android 7.1 缺少设置directBootAware导致无法启动指定Launcher

平台:

Amlogic s905X + Android 7.1

问题:

内置指定应用作为Launcher并默认启动(PS: 同时存在MboxLauncher).
开机后, 无法进入指定Launcher, 但是, 在输入HOME键后, 却可以显示存在两个Launcher, 
通过代码检测, 也可以检测出指定Launcher存在.

分析:

|–frameworks/base/services/core/java/com/android/server/am/ActivityManagerService.java

    boolean startHomeActivityLocked(int userId, String reason) {
        if (mFactoryTest == FactoryTest.FACTORY_TEST_LOW_LEVEL
                && mTopAction == null) {
            // We are running in factory test mode, but unable to find
            // the factory test app, so just sit around displaying the
            // error message and don't try to start anything.
            return false;
        }
//新增代码:
		Intent intent = null;
		ActivityInfo aInfo = null;
		final String spPkg = "com.android.launcher";
		final String spCls = "com.android.launcher.Launcher";
		if(!android.text.TextUtils.isEmpty(spPkg) && !android.text.TextUtils.isEmpty(spCls)){
/*源码中Launcher2的Intent包含:
*				<action android:name="android.intent.action.MAIN" />
*               <category android:name="android.intent.category.HOME" />
*               <category android:name="android.intent.category.DEFAULT" />
*               <category android:name="android.intent.category.MONKEY"/>
*/
			intent = new Intent(mTopAction);
			intent.addCategory(Intent.CATEGORY_HOME);
//指定包类名
			intent.setComponent(new ComponentName(spPkg, spCls));
			intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_DEBUG_TRIAGED_MISSING);
			try{
				List<ResolveInfo> ris = AppGlobals.getPackageManager().queryIntentActivities(intent, null, 0, userId).getList();
//异常时:ris.size == 0, 即找不到所想要的Activity组件
//正常时:ris.size == 1
				if(ris != null && ris.size() > 0){
					ResolveInfo rinfo = ris.get(0);
					if(rinfo != null)aInfo = rinfo.activityInfo;
				}
			}catch(Exception e){e.printStackTrace();}
		}

//以下为原有代码
		if(aInfo == null){
			intent = getHomeIntent();
			aInfo = resolveActivityInfo(intent, STOCK_PM_FLAGS, userId);
		}
        if (aInfo != null) {
            intent.setComponent(new ComponentName(aInfo.applicationInfo.packageName, aInfo.name));
            // Don't do this if the home app is currently being
            // instrumented.
            aInfo = new ActivityInfo(aInfo);
            aInfo.applicationInfo = getAppInfoForUser(aInfo.applicationInfo, userId);
            ProcessRecord app = getProcessRecordLocked(aInfo.processName,
                    aInfo.applicationInfo.uid, true);
            if (app == null || app.instrumentationClass == null) {
                intent.setFlags(intent.getFlags() | Intent.FLAG_ACTIVITY_NEW_TASK);
                mActivityStarter.startHomeActivityLocked(intent, aInfo, reason);
            }
        } else {
            Slog.wtf(TAG, "No home screen found for " + intent, new Throwable());
        }

        return true;
    }

逻辑上并没有问题, 问题的根本原因在:
|-- device/amlogic/XXX/overlay/vendor/amlogic/apps/MboxLauncher2/AndroidManifest.xml

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
        android:directBootAware="true" >

        <activity
            android:name=".Launcher"
            android:clearTaskOnLaunch="true"
            android:label="@string/app_name"
            android:launchMode="singleTask"
            android:stateNotNeeded="true" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.HOME" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.MONKEY" />
            </intent-filter>
        </activity>
    </application>

指定Launcher 缺少了上面 android:directBootAware="true" 定义.

加入此属性后测试, 解决!

参考:

https://blog.csdn.net/ch853199769/article/details/78666187

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值