Android Google 开机向导定制 setup wizard

news/2024/7/24 3:11:13 标签: android

Android 开机向导定制

采用 rro_overlays 机制来定制开机向导,定制文件如下:

GmsSampleIntegrationOverlay$ tree
.
├── Android.bp
├── AndroidManifest.xml
└── res
└── raw
├── wizard_script_common_flow.xml
├── wizard_script_customize_flow.xml
└── wizard_script.xml

Android.bp

runtime_resource_overlay {
    name: "GmsSampleIntegrationOverlay",
    product_specific: true,
}

在项目对应的.mk 文件添加编译引用

PRODUCT_PACKAGES += \
        GmsSampleIntegrationOverlay

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<!--
#/*
# * Copyright (C) 2023 Lens Technology (Xiangtan) Co.,Ltd, All rights reserved.
# * Author: XT900109
# */
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.xxxx.gmssampleintegrationsoverlay"
    android:versionCode="1"
    android:versionName="1.0">

    <application android:hasCode="false" />

    <overlay android:targetPackage="com.google.android.gmsintegration"
        android:priority="0"
        android:isStatic="true" />
</manifest>

rro_overlays/GmsSampleIntegrationOverlay/res/raw/wizard_script_lens_customize_flow.xml

自定义 wizard_script_customize_flow.xml

<?xml version="1.0" encoding="UTF-8"?>
<!--
    The wizard:uris recorded here have the inconvenience of being generated by hand, but they allow
    for the full spread of launch flags (we need FLAG_ACTIVITY_NEW_TASK [0x10000000]), where the
    <intent> tag processed by Intent.parseIntent() does not.

    adb shell am to-intent-uri -a com.android.setupwizard.WELCOME -f 0x10000000 \-\-ez firstRun true
-->

<WizardScript xmlns:wizard="http://schemas.android.com/apk/res/com.google.android.setupwizard"
    wizard:firstAction="user_terms_of_service1">

    <WizardAction id="user_terms_of_service1"
        wizard:uri="intent:#Intent;action=com.android.setupwizard.USER_TERMS_OF_SERVICE;end" >
        <result wizard:action="user_service_notice" />
    </WizardAction>

    <WizardAction id="user_service_notice"
        wizard:uri="intent:#Intent;action=com.android.setupwizard.USER_SETUP_FINISH;end" >
    </WizardAction>

<!--    <WizardAction id="END_OF_SCRIPT"
        wizard:uri="intent:#Intent;action=com.android.setupwizard.EXIT;end" />-->
</WizardScript>

在 wizard_script_common_flow.xml 文件里面添加引用

<WizardAction id="user_terms_of_service"
    wizard:script="android.resource://com.xxxx.gmssampleintegrationsoverlay/raw/wizard_script_customize_flow">
</WizardAction>

注意这里的 com.xxxx.gmssampleintegrationsoverlay 需要对应上面AndroidManifest.xml package


    <!-- Set screen lock options. The action must precede the payments action [RECOMMENDED, CUSTOMIZABLE] -->
    <WizardAction id="lock_screen"
        wizard:uri="intent:#Intent;action=com.google.android.setupwizard.LOCK_SCREEN;end" >
    </WizardAction>

    <!-- MY completion [CUSTOMIZABLE] -->
    <WizardAction id="user_terms_of_service"
        wizard:script="android.resource://com.xxxx.gmssampleintegrationsoverlay/raw/wizard_script_customize_flow">
    </WizardAction>

    <!-- Labeled end of script (for branching) [RECOMMENDED, CUSTOMIZABLE] -->
    <WizardAction id="END_OF_SCRIPT" />

定义 com.android.setupwizard.USER_TERMS_OF_SERVICE

在项目的 AndroidManifest.xml


	<activity android:name=".setupwizard.SetupWFinishActivity"
            android:exported="true" >
            <intent-filter>
                <action android:name="com.android.setupwizard.USER_SETUP_FINISH" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>

SetupWFinishActivity.java

package com.android.settings.setupwizard;

import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;

import com.android.settings.R;

public class SetupWFinishActivity extends Activity {
    public static final String TAG = "SetupWFinishActivity";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        getWindow().setStatusBarColor(Color.WHITE);
        getWindow().setNavigationBarColor(Color.WHITE);
        getWindow().setNavigationBarDividerColor(Color.WHITE);

        getActionBar().hide();
        setContentView(R.layout.activity_setup_wfinish);

        findViewById(R.id.button3).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //: TODO 
                onNext();
            }
        });
    }

    public void onNext() {
        int resultCode = Activity.RESULT_OK;
        Intent intent = WizardManagerHelper.getNextIntent(getIntent(), resultCode);
        Log.e(TAG, "onNext() intent:" + intent);
        try {
            startActivityForResult(intent, Activity.RESULT_OK);
        } catch (ActivityNotFoundException e) {
            Log.e(TAG, e.getMessage());
        }
        Intent returnIntent = new Intent();
        setResult(Activity.RESULT_OK,returnIntent);
        finish();
    }
}

WizardManagerHelper的实现

static class WizardManagerHelper {

        private static final String ACTION_NEXT = "com.android.wizard.NEXT";
        static final String EXTRA_SCRIPT_URI = "scriptUri";
        static final String EXTRA_ACTION_ID = "actionId";
        private static final String EXTRA_RESULT_CODE = "com.android.setupwizard.ResultCode";
        public static final String EXTRA_THEME = "theme";
        static final String EXTRA_WIZARD_BUNDLE = "wizardBundle";
        static final String EXTRA_IS_FIRST_RUN = "firstRun";
        static final String EXTRA_IS_DEFERRED_SETUP = "deferredSetup";
        static final String EXTRA_IS_PRE_DEFERRED_SETUP = "preDeferredSetup";
        public static final String EXTRA_IS_SETUP_FLOW = "isSetupFlow";

        public static Intent getNextIntent(Intent originalIntent, int resultCode) {
            return getNextIntent(originalIntent, resultCode, null);
        }

        public static Intent getNextIntent(Intent originalIntent, int resultCode, Intent data) {
            Intent intent = new Intent(ACTION_NEXT);
            copyWizardManagerExtras(originalIntent, intent);
            intent.putExtra(EXTRA_RESULT_CODE, resultCode);
            if (data != null && data.getExtras() != null) {
                intent.putExtras(data.getExtras());
            }
            intent.putExtra(EXTRA_THEME, originalIntent.getStringExtra(EXTRA_THEME));

            return intent;
        }

        public static void copyWizardManagerExtras(Intent srcIntent, Intent dstIntent) {
            dstIntent.putExtra(EXTRA_WIZARD_BUNDLE, srcIntent.getBundleExtra(EXTRA_WIZARD_BUNDLE));
            for (String key :
                    Arrays.asList(
                            EXTRA_IS_FIRST_RUN,
                            EXTRA_IS_DEFERRED_SETUP,
                            EXTRA_IS_PRE_DEFERRED_SETUP,
                            EXTRA_IS_SETUP_FLOW)) {
                dstIntent.putExtra(key, srcIntent.getBooleanExtra(key, false));
            }

            for (String key : Arrays.asList(EXTRA_THEME, EXTRA_SCRIPT_URI, EXTRA_ACTION_ID)) {
                dstIntent.putExtra(key, srcIntent.getStringExtra(key));
            }
        }
    }

http://www.niftyadmin.cn/n/5333035.html

相关文章

【Python3】【力扣题】392. 判断子序列

【力扣题】题目描述&#xff1a; 【Python3】代码&#xff1a; 1、解题思路&#xff1a;遍历字符串s&#xff0c;使用一个列表依次记录在字符串t中的位置&#xff0c;若没有该字母则返回False&#xff0c;若索引号小于上一个字母的索引号&#xff0c;返回False。否则返回True。…

centos7 arm服务器编译升级安装动态库libstdc++.so.6,解决GLIBC和CXXABI版本低的问题

前言 由于centos7内置的libstdc.so.6版本太低&#xff0c;导致安装第三方包的时候&#xff0c;会报“CXXABI_1.3.8”不存在等问题。 自带的打印如下&#xff1a; strings /usr/lib64/libstdc.so.6 | grep GLIBC strings /usr/lib64/libstdc.so.6 | grep CXXABI 如图 升级 注…

外观模式介绍

目录 一、外观模式介绍 1.1 外观模式定义 1.2 外观模式原理 1.2.1 外观模式类图 1.2.2 模式角色说明 1.2.3 示例代码 二、外观模式的应用 2.1 需求说明 2.2 需求实现 2.2.1 类图 2.2.2 具体实现 2.2.2.1 灯光类 2.2.2.2 电视类 2.2.2.3 空调类 2.2.2.4 外观面板类…

阿里云国外云服务器多少钱?2024年最新价格

阿里云国外服务器优惠活动「全球云服务器精选特惠」&#xff0c;国外服务器租用价格24元一个月起&#xff0c;免备案适合搭建网站&#xff0c;部署独立站等业务场景&#xff0c;阿里云服务器网aliyunfuwuqi.com分享阿里云国外服务器优惠活动&#xff1a; 全球云服务器精选特惠…

Linux 常用的一些命令

目录 一、常用文件管理命令二、tmux 和 vimtmuxvim 三、[Shell语法](https://blog.csdn.net/weixin_43288201/article/details/105643692)四、git五、sshReference 一、常用文件管理命令 (1) ctrl c: 取消命令&#xff0c;并且换行 (2) ctrl u: 清空本行命令 (3) tab键&#x…

亚信安慧AntDB:聚焦执行性能,带给用户前所未有的数据库体验

亚信安慧AntDB数据库是一款国产数据库产品&#xff0c;以其独特之处和出色表现而备受瞩目。它的诞生源于对现实问题的深入思考和实践经验&#xff0c;旨在提供一种高效、稳定、可靠的数据库解决方案。下面将从多个角度介绍AntDB的特点和优势。 首先&#xff0c;AntDB以服务人数…

java基础之线程安全问题以及线程安全集合类

线程安全问题 当多个线程同时访问同一个临界资源时,原子操作可能被破坏,会导致数据丢失, 就会触发线程安全问题 临界资源: 被多个线程同时访问的对象 原子操作: 线程访问临界资源的过程中不可更改和缺失的操作 互斥锁 每个对象都默认拥有互斥锁, 该锁默认不开启. 当开启互斥…

IOS-UIAlertController简单使用-Swift

UIAlertControlle时IOS的对话框控制器&#xff08;警报控制器&#xff09;&#xff0c;简单使用方法如下&#xff1a; 步骤都一样&#xff0c;先是创建UIAlertController&#xff0c;然后创建UIAlertAction&#xff0c;再将UIAlertAction添加到UIAlertController中&#xff0c;…