android 开机向导OOBE源码分析

news/2025/1/31 4:01:37/

OOBE是开机向导,普通的理解就是一个界面跳另一个界面再跳下一个界面,OOBE却不是这么实现的。下面分析OOBE界面跳转实现:

打开OOBE目录,找到入口是WizardActivity.java,该Activity随后跳转到MainActivity.java。OOBE界面跳转逻辑都在MainActivity.java里实现。

对于一个陌生的Activity,我们先看它的onCreate方法:

@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);Log.i("xsslog","OOBE MainActivity onCreate() ----------111");	this.getWindow().setFlags(FLAG_HOMEKEY_DISPATCHED, FLAG_HOMEKEY_DISPATCHED);//forbid homeKeymSimExist = isSimExist();Xlog.d(TAG, "onCreate mSimExist = " + mSimExist);if (savedInstanceState != null) {mCurrentStep = savedInstanceState.getInt("currentStep");mTotalStep = savedInstanceState.getInt("totalSteps");Log.i("xsslog", "restore saved instance state mCurrentStep=" + mCurrentStep + "mTotalStep="+ mTotalStep);setActivityList();}//Diable window rotate for phone.  setWindowRotation(false);//disable quick start guide for tablet//disableQSG();mIsFirstRun = Settings.System.getInt(getContentResolver(), Utils.OOBE_HAS_RUN_KEY, 0) == 0; Log.i("xsslog","OOBE MainActivity onCreate() -----222-----mIsFirstRun="+mIsFirstRun);	if (mIsFirstRun) {Settings.System.putInt(getContentResolver(),Settings.System.OOBE_DISPLAY, Settings.System.OOBE_DISPLAY_ON);Settings.Global.putInt(getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0);enableStatusBar(false);}mBootMode = getBootMode();      if (mIsFirstRun && mBootMode != BOOT_MODE_ADV_META && !Utils.isWifiOnly(this)) {mHandler.sendEmptyMessageDelayed(EVENT_MONITOR_SIM_TIME_OUT, TIME_MONITOR_SIM);Log.i("xsslog","OOBE MainActivity ()=========");		 //showDialog(DIALOG_WAITING_SIM);} else {mHandler.sendEmptyMessage(EVENT_SIM_DETECTING_READY);}mSIMIntentFilter = new IntentFilter(TelephonyIntents.ACTION_SIM_INFO_UPDATE);registerReceiver(mSIMStateReceiver, mSIMIntentFilter);pm = getPackageManager();name = new ComponentName(this, WizardActivity.class);if(pm != null)//added by lzpstate = pm.getComponentEnabledSetting(name);
/*	  mVelocityTracker = VelocityTracker.obtain();mScreenOffReceiverFilter = new IntentFilter();mScreenOffReceiverFilter.addAction(Intent.ACTION_SCREEN_ON);registerReceiver(mScreenOffReceiver,mScreenOffReceiverFilter);*/      }
其中mCurrentStep是指当前界面数,mTotalStep是指OOBE总界面数。mIsFirstRun判断是否第一次进入OOBE,做相应处理

这里的重点是看setActivityList();

protected void setActivityList() {boolean mIphoneFlag = Settings.System.getInt(this.getContentResolver(), Settings.System.ISIPHONE, 0) == 1;//added by lzpboolean noIphoneChars = "1".equals(SystemProperties.get("ro.cenon_setting_no_iPhone"));//added by lzpboolean switchPagesByLogo = "1".equals(SystemProperties.get("cenon.switch_oobe_pages_by_logo"));//added by lzpXlog.d(TAG, "setActivityList() mIphoneFlag="+mIphoneFlag);mStepActivityies.clear();if((!switchPagesByLogo && !noIphoneChars) || mIphoneFlag) {mStepActivityies.add(mLanguageSettings);mStepActivityies.add(mCountrySettings);mStepActivityies.add(iMessageAndFaceTime);// add by csc for ios 10mStepActivityies.add(mInputMethodSettings);mStepActivityies.add(mWifiSettings);	mStepActivityies.add(mfinishOobe);} else {//added by lzp mStepActivityies.add(mLanguageSettings);mStepActivityies.add(mCountrySettings);mStepActivityies.add(mInputMethodSettings);mStepActivityies.add(mfinishOobe);}mTotalStep = mStepActivityies.size();}

可以看到每个界面都被加到了mStepActivityies里面,mTotalStep就是在这里得出

private List<OobeActivityInfo> mStepActivityies = new ArrayList<OobeActivityInfo>();
我们发现里面有个mHandler处理,于是我们跳到该mHandler:

private Handler mHandler = new Handler() {@Overridepublic void handleMessage(android.os.Message msg) {switch (msg.what) {case EVENT_MONITOR_SIM_TIME_OUT:Xlog.v(TAG, "handler wait SIM time out");break;case EVENT_SIM_DETECTING_READY:Xlog.v(TAG, "handler SIM initialization finish");mHandler.removeMessages(EVENT_MONITOR_SIM_TIME_OUT);break;			case EVENT_PREPAREING_END_OOBE:mHandler.removeMessages(EVENT_PREPAREING_END_OOBE);finish();break;	default:break;}initStep();//removeDialog(DIALOG_WAITING_SIM);};};
可以看到有EVENT_MONITOR_SIM_TIME_OUT,EVENT_SIM_DETECTING_READY,EVENT_PREPAREING_END_OOBE等情况的处理,我们主要研究OOBE界面是如何进行跳转的,上面的就不细做分析了。然后就注意到initStep()方法
private void initStep() {       if (mIsStepInitiated) {return;}mIsStepInitiated = true;setActivityList();if (mCurrentStep == -1) {nextActivity(true);}}
setActivityList()上面说了把界面都放入list,重点看nextActivity方法
protected void nextActivity(boolean nextStep) {     if (nextStep) {if(mCurrentStep<0){mCurrentStep++;Intent lockScreenIntent = new Intent(ACTION_LOCK_SCREEN);startActivityForResult(lockScreenIntent, REQUEST_CODE_ADVANCED_SETTINGS);return;}else mCurrentStep++;} else {mCurrentStep--;}if (mCurrentStep >= 0 && mCurrentStep < mStepActivityies.size()) {Intent intent = mStepActivityies.get(mCurrentStep).getIntent();intent.putExtra(Utils.OOBE_BASIC_STEP_TOTAL, mTotalStep);intent.putExtra(Utils.OOBE_BASIC_STEP_INDEX, mCurrentStep + 1);intent.putExtra(EXTRA_IS_OOBE, true);startActivityForResult(intent, mCurrentStep);if (nextStep) {overridePendingTransition(R.anim.slide_right_in, R.anim.slide_left_out);//overridePendingTransition(R.anim.zoomin, R.anim.zoomout);} else {overridePendingTransition(R.anim.slide_left_in, R.anim.slide_right_out);//overridePendingTransition(R.anim.zoomin, R.anim.zoomout);}}}
nextStep用来判断下一步还是上一步,mCurrentStep是要跳转界面的值,知道这个前一部分代码就好理解了
Intent intent = mStepActivityies.get(mCurrentStep).getIntent();intent.putExtra(Utils.OOBE_BASIC_STEP_TOTAL, mTotalStep);intent.putExtra(Utils.OOBE_BASIC_STEP_INDEX, mCurrentStep + 1);intent.putExtra(EXTRA_IS_OOBE, true);startActivityForResult(intent, mCurrentStep);
根据mCurrentStep从mStepActivityies取出该界面的包名,用startActivityForResult方法进行跳转,我们可以看下回传的参数用来干嘛

其他界面点击上一步或者下一步的时候就调用finishActivityByResult(Utils.RESULT_CODE_TO_NO_STEP);

@Overridepublic void onClick(View view) {switch (view.getId()) {case R.id.back_settings_btn:finishActivityByResult(Utils.RESULT_CODE_TO_NO_STEP);break;case R.id.next_settings_btn:/*  Intent intent = new Intent();intent.setClass(OobeLoginiCloudActivity.this,OobeTermsAndConditionsActivity.class);intent.putExtra("GOTO_BY_ICLOUD",true);startActivity(intent);finish();*/finishActivityByResult(Utils.RESULT_CODE_TO_TWO_STEP);break;}}
 private void finishActivityByResult(int resultCode) {Intent intent = new Intent();setResult(resultCode, intent);finish();}
然后把这个是跳上一步还是下一步传回MainActivity,由MainActivity进行统一跳转,而不是从当前界面直接往下跳。


@Overrideprotected void onActivityResult(int requestCode, int resultCode, Intent intent) {Xlog.d(TAG, "onActivityResult resultCode = " + resultCode);switch (resultCode) {case Utils.RESULT_CODE_BACK:if (0 == mCurrentStep) {finish();} else {nextActivity(false);}break;case Utils.RESULT_CODE_NEXT:nextActivity(true);break;case Utils.RESULT_CODE_FINISH:finishOOBE();break;case Utils.RESULT_CODE_TO_ONE_STEP:// add by csc for ios 10mCurrentStep++;nextActivity(true);break;case Utils.RESULT_CODE_TO_TWO_STEP:// add by csc for ios 10mCurrentStep=mCurrentStep+2;nextActivity(true);break;case Utils.RESULT_CODE_TO_LOGIN_ICLOUD:// add by csc for ios 10intent = new Intent();intent.setClass(MainActivity.this,OobeLoginiCloudActivity.class);startActivityForResult(intent, 1001);break;case Utils.RESULT_CODE_TO_FORGET_PASSWORD:intent = new Intent();intent.setClass(MainActivity.this,OobeForgetPasswordActivity.class);startActivityForResult(intent, 1001);break;case Utils.RESULT_CODE_TO_CREATE_APPLE_ID:// add by csc for ios 10intent = new Intent();intent.setClass(MainActivity.this,OobeCreateAppleIdActivity.class);startActivityForResult(intent, 1001);break;case Utils.RESULT_CODE_TO_FORGET_APPLE_ID:// add by csc for ios 10intent = new Intent();intent.setClass(MainActivity.this,OobeForgetAppleIDActivity.class);startActivityForResult(intent, 1001);break;case Utils.RESULT_CODE_TO_NO_STEP:// add by csc for ios 10mCurrentStep--;nextActivity(true);break;case 100:{/**Begin: added by lzp **/if(mCurrentStep < 0) {mHandler.sendEmptyMessage(EVENT_SIM_DETECTING_READY);return;}/**End: added by lzp **/Intent backIntent = mStepActivityies.get(mCurrentStep).getIntent();backIntent.putExtra(Utils.OOBE_BASIC_STEP_TOTAL, mTotalStep);backIntent.putExtra(Utils.OOBE_BASIC_STEP_INDEX, mCurrentStep + 1);backIntent.putExtra(EXTRA_IS_OOBE, true);startActivityForResult(backIntent, mCurrentStep);overridePendingTransition(R.anim.slide_left_in, R.anim.slide_right_out);//overridePendingTransition(R.anim.zoomin, R.anim.zoomout);}break;case Utils.RESULT_SCREEN_OFF:{Intent lockScreenIntent = new Intent(ACTION_LOCK_SCREEN);startActivityForResult(lockScreenIntent, REQUEST_CODE_ADVANCED_SETTINGS);overridePendingTransition(R.anim.slide_left_in, R.anim.slide_right_out);	//overridePendingTransition(R.anim.zoomin, R.anim.zoomout);}break;default:break;}}

到这里就完成了OOBE的界面跳转。






http://www.ppmy.cn/news/685328.html

相关文章

Android OOBE开发

什么是OOBE 就是开机向导&#xff0c;在 Android 设备首次开机的时候&#xff0c;会先进行一系列的初始化&#xff0c;然后再进入主页。 初始化的操作一般有 登录或注册厂商账号、选择时区、选择语言等&#xff0c;TV的话还可能包括搜台等。 初始化的操作只在首次开机和安卓复…

系统准备工具 (Sysprep.exe) 实现OOBE用法

MSDN&#xff1a; sysprep 一.系统准备工具介绍 系统准备工具 (Sysprep.exe)用于准备供映像或交付给客户的 Windows 安装。 二.OOBE流程 Sysprep.exe->审核模式Audit->重启->删除用户->OOBE->关机 三.操作步骤 测试完成后&#xff0c;整机设置出货状态&…

android OOBE创建方法

OOBE就是ANDROID第一次开机时候的系统设置&#xff0c;只在机器第一次开机的时候运行一次&#xff0c;之后都不会再运行&#xff0c;除非erase userdata和erase cache。 创建OOBE很简单&#xff0c;只需要把Google的APK应用套件拷贝到自己的系统里就可以了&#xff0c;其中有一…

Windows 11 首次开机OOBE阶段跳过连接网络及登录微软账户,使用本地账号登录的方法

2022/11/25更新&#xff1a; 以下方法最新版本的Win11 22H1上已失效&#xff0c;最新的方法是在第二步呼出cmd窗口&#xff0c;输入oobe\bypassnro&#xff0c;电脑会重启&#xff0c;再次来到连接网络的页面时选择“我没有Internet连接”的选项&#xff0c;就可以跳过联网了。…

IMU 互补滤波

IMU学名惯性测量单元&#xff0c;所有的运动都可以分解为一个直线运动和一个旋转运动&#xff0c;故这个惯性测量单元就是测量这两种运动&#xff0c;直线运动通过加速度计可以测量&#xff0c;旋转运动则通过陀螺。 void IMUupdate(float gx, float gy, float gz, float ax,fl…

html当连接失败自动,DNF爆满频道服务器自动连接失败怎么办

DNF从3月24日更新后登陆游戏会自动选择上次最后登陆游戏的频道进入&#xff0c;不会再出现频道选择界面&#xff0c;当上次的频道爆满后&#xff0c;玩家就无法登陆进入游戏了&#xff0c;小编也遇到过这种情况&#xff0c;后来经过多方查找终于找到了解决的办法&#xff0c;下…

dnf服务器炸团门票怎么找回,DNF:打团掉线被献祭点这里免费补门票,再也不怕被献祭没牌了...

原标题&#xff1a;DNF&#xff1a;打团掉线被献祭点这里免费补门票&#xff0c;再也不怕被献祭没牌了 Hello大家好 我是帅帅&#xff0c;欢迎来到阿拉德密室&#xff0c;今天给大家带来一期超级福利 就是当我们在打团超时空的时候&#xff0c;有很多玩家会因为掉线&#xff0c…