01 · 代码结构与地区差异

一、两个入口 Fragment(编译期 overlay 选择)

FragmentXML继承
AutopilotSettingsFragment(国内/ECE)com.android.micar.settings.autopilotisEce ? _ece : 国内TopLevelSettingsFragment(带 @MonitorFragment)
GlobalAutopilotSettingsFragment(海外)固定 _globalBaseXmlParserSettingsFragment( TopLevel, @MonitorFragment)

选择机制(编译期,非运行时 if-else):

  • app/src/region/cn/res/xml/miauto_top_level_menu_fragment.xmlAutopilotSettingsFragment
  • app/src/region/global/res/xml/miauto_top_level_menu_fragment.xmlGlobalAutopilotSettingsFragment

XML 运行期选择(仅国内 Fragment 内判 ECE):

static int getPreferenceScreenResIdByRegion() {
    if (MiCarSettings.isEce()) return R.xml.micar_autopilot_settings_fragment_ece;
    return R.xml.micar_autopilot_settings_fragment;
}

右栏:AutopilotScrollRightFragment(智驾状态可视化车模,行车/泊车两类)。

二、三个 XML 完整对比(地区差异核心)

功能国内 CN(415行)海外 Global(252行)ECE(65行)
智驾学堂入口
ACC/LCC/NOA 三联卡(ADS_MODE)
状态横幅 Banner
NOA 范围/里程/驾驶风格/ETC/收费站/XLA
NOA 变道确认
LCC 拨杆变道 ALC
LCC 辅助驾驶接管
自动形成应急车道
ACC 整组(避免右超车/道路特征限速/限速联动)
小爱行车播报 + 动态车速
APA 泊车
HPP/自学习/众包建图/AVP
前向 AEB/FCW✓(UN-R152 强制)
低速 LAEB/RAEB
车道保持 LDWP✓(UN-R159 强制)
ELKTab 3 档Switch
AES 紧急转向
RCW/RCTAB
限高提醒/调整✓(仅 Kunlun)
BSD/LCA
DOW 开门预警
超速告警✓(ISA 强制)
国家代码选择✓(ECE 独有)
TLA 红绿灯/MAI 误加速
智驾休眠 + 辅助驾驶灯

ECE 仅 AEB/FCW + LDW + 超速告警 + 国家选择(UN-R152/R159/ISA 法规强制),其他全部移除。

三、CountrySelectDialogFragment(ECE 独有)

  • 27 个欧洲国家(奥/比/保/克/塞/捷/丹/爱/芬/德/法/希/匈/爱/意/拉/立/卢/马/荷/波/葡/罗/斯/斯/西/瑞),默认德国(index 9)
  • 通过 INTENT_ACTION_COUNTRY_SELECT 广播回传 index,MiCarAutoPilotNavOverSpeedCountryController 接收后写 COUNTRY_CODE_SWITCH 信号
  • 车端按国家码应用不同限速阈值(UI 只是选择器,不按单国家做代码分支)

四、Controller 体系(60+,双基类)

Switch 基类 BaseAutopilotSwitchController

继承 BaseVehicleNewSwitchPrefController。提供:

  • 统一开关流水线(isInOperationBlock → needSecondConfirm → setCarProperty)
  • 车模联动(triggerCarModelChange)
  • 统一禁用原因(showDisableReason,枚举 SwitchUnavlReason 全集:DEFAULT/NOT_P_GEAR/ACCOUNT_NOT_LOG_IN/LOW_POWER/EXTREME_ECO/PRIVACY/FUNCTION_ACTIVE/ERROR/NOT_AUTHORIZED/NOT_LEARNED)
  • License 校验(AutopilotLicenseConfig + MiCarLcsControlHelper)
  • 未学习引导(showToggleInterceptDialog → 跳智驾学堂 com.xiaomi.ad.school
  • CTA 授权(requestAuthorize → Guard.AUTO_VEHICLE_SERVICE_AUTH)
  • 功能详情弹窗(onTitleIconClicked → AutopilotConfig.sFunctionList)

Tab 基类 BaseAutoPilotTabControllerNew

继承 BaseVehicleTabPreferenceController。提供:

  • 多档 Tab 构建(createTab)
  • 父子折叠(setFoldMode + getDependencyPropId)
  • Tab 二次确认(needSecondConfirm(tab))
  • 不可用原因分类(tab 维度)
  • 子项联动 UI 先行(onTriggerChildPrefVisibleChange)
  • per-tab License(isTabLicenseFeatureValid)

60+ Controller 按功能分类

子系统Controller 数代表
NOA 领航8AdsModTab(总闸)/ReleaseArea/DriveStyle/LaneChange/MileageProgress/ETC/TollStation/AdsCategory
泊车7APA/APAStyle/AVP/HPP/HppBgLearn/CrowdSourcedMap/ParkAudioMode
AEB/AES4Aebfcw/AEBBeta/AES/MAI
车道6Ldw/LdwpWarn/ELK(Tab)/ELK(Global)/ALC/XLA + OsEmergAcs/AvoidRightLaneChange
后向6BSDLCA/RCTAB/RCTASwitch(废弃)/Rcw/DOW(Tab)/DOW(Switch)
限速10NavOverSpeed/Country/OverSpdOffset/MiPilotIntelgntSpd/RdFeatSpdLimit/AccSpdLimit/SpdLimitAdjustment/FixSpdMode/FixSpdPref/FixSpdPercentage(+L2版)/FixSpdLimitAdjust
ADS 模式4AdsLight/AudioMode/ParkAudioMode/StateBanner
其他7+TakeOver/TLA/Sleep/Studio(学堂入口)/HeightLimit(×2)/ShortRangeObstacle(跨模块)

五、AutopilotScrollRightFragment(右栏智驾可视化)

  • 继承 BaseScrollModelRightFragment
  • 两类车模:CAR_MODEL_FLAG_DRIVING(行车) / CAR_MODEL_FLAG_PARKING(泊车)
  • 按 ADS_MODE 切车模:NOA_ON→高速 / LCC_ON→LCC / ACC_ON→ACC / HPP 开→HPP
  • 关注 pk_autopilot_ads_mod_switch_entry(行车,距顶 5)+ pk_autopilot_hpp_switch_entry_sub(泊车,距顶 4)
  • 行车态忽略 HPP 信号,泊车态忽略 ADS_MODE(避免错乱)

六、privacy 包(GDPR/PIPL 数据合规)

实际 XML 在 settingsSystem 模块micar_autopilot_privacy_service_fragment.xml),Controller 在 AutoPilot/privacy 包。

Controller信号作用
AutopilotAuthBtnToggleControllerGuard.AUTO_VEHICLE_SERVICE_AUTH智驾服务授权总开关(AUTHORIZED/UNAUTHORIZED),跳 CTA 授权页(com.mi.car.defaultapps
AutoPilotExperienceSwitchPrefControllerGuard.AUTO_VEHICLE_EXP_IMPROVE_SWITCH用户体验改进计划(依附服务授权,未授权置灰)
AutopilotPrivacyUtils + AutoPilotPrivacyJobService构造 CTA Intent + JobScheduler 上传授权日志(生产 terms.api.xiaomiev.com/UAT terms-gateway-uat.ev.mioffice.cn

GDPR/PIPL 合规:数据采集需明示授权,与 ADAS 功能开关解耦,但通过 AUTO_VEHICLE_SERVICE_AUTH 与整车上传链路绑定。不按 isEce/isOverseas 分支(中外通用)。

七、特殊非基类 Controller(7 个)

不继承 Switch/Tab 两个 ADAS 基类:

  • MiCarAutoPilotNoaMileageProgressController(网络请求,10 分钟轮询)
  • MiCarAutoPilotAdsCategoryController(PreferenceCategory 容器)
  • MiCarAutoPilotStateBannerController(顶部状态横幅)
  • MiCarAutoPilotStudioController(智驾学堂跳转入口)
  • MiCarAutoPilotNavOverSpeedCountryController(国家选择)
  • FixSpd*Controller(继承 BaseVehicleProgressPrefController,Slider)
  • ShortRangeObstacleWarningTabController(跨模块给 Driving 用)

八、代码异味(对抗验证)

#异味
1AES 注释笔误(写”Automated-Valet-Parking”,实际 Autonomous Emergency Steering)
2RCTASwitchController 注释错误(写”RCW”但读 RCTAB 信号),且 XML 注释掉
3不用 hiddenFeatures(与其他车控模块不同,全靠 license 裁剪)
4CN/Global 两套独立 license(*_GLOBAL 系列值不同)
5privacy 包 XML 跨模块在 settingsSystem
6ShortRangeObstacleWarning 跨模块(定义 AutoPilot,挂载 Driving XML)
73 个 XML 大量重复 Controller(国内外不同实现/挂载)