Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 18 additions & 12 deletions common/src/main/java/moe/feng/wheelplay/AirPlayPersistence.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import com.shilapi.xcertplay.airplay.AirPlayIdentity
import com.shilapi.xcertplay.airplay.PairingStore
import com.shilapi.xcertplay.airplay.SafeAreaCodec
import com.shilapi.xcertplay.airplay.SafeAreaRect
import com.shilapi.xcertplay.host.R
import com.shilapi.xcertplay.orchestration.ManualHotspotBand
import com.shilapi.xcertplay.orchestration.ManualHotspotSecurity
import com.shilapi.xcertplay.orchestration.MfiTarget
Expand Down Expand Up @@ -52,7 +53,8 @@ object AirPlayPersistence {
private const val KEY_MANUFACTURER = "manufacturer"
private const val KEY_MODEL = "model"
private const val KEY_OEM_LABEL = "oem_label"
private const val KEY_OEM_LABEL_MIGRATED = "oem_label_migrated"
private const val KEY_BYD_LABEL_MIGRATED = "oem_label_migrated"
private const val KEY_OEM_LABEL_MIGRATED = "oem_label_migrated_to_app"
private const val KEY_FPS = "display_fps"
private const val KEY_STREAM_TECHNOLOGY = "web_stream_technology"
private const val KEY_RTC_RECOVERY = "web_rtc_recovery"
Expand Down Expand Up @@ -84,7 +86,6 @@ object AirPlayPersistence {
private const val CUSTOM_ICON_FILE = "airplay-icon.png"

const val DEFAULT_MODEL = "WheelPlay"
const val DEFAULT_SIMULATED_MANUFACTURER_NAME = "NIO"
const val DEFAULT_MFI_I2C_PATH = "/dev/i2c-1"

fun loadBrowserAudioPlayback(context: Context): Boolean =
Expand Down Expand Up @@ -402,22 +403,27 @@ object AirPlayPersistence {
fun loadSimulatedManufacturerName(context: Context): String {
val prefs = context.getSharedPreferences(PREFS, Context.MODE_PRIVATE)
val stored = prefs.getString(KEY_OEM_LABEL, null)
// Upgrade the previous default once, while allowing users to choose BYD again later.
val legacyDefault = stored == "BYD" && !prefs.getBoolean(KEY_OEM_LABEL_MIGRATED, false)
// iOS hides the car icon without a label.
val name = (if (legacyDefault) DEFAULT_SIMULATED_MANUFACTURER_NAME else stored)?.trim()?.takeIf { it.isNotBlank() }
?: prefs.getString(KEY_MANUFACTURER, null)
?.takeIf { it.isNotBlank() && it != "WheelPlay" && it != "DiPlay" && it != "DiPlay Web" }
?: DEFAULT_SIMULATED_MANUFACTURER_NAME
if (stored != name || !prefs.getBoolean(KEY_OEM_LABEL_MIGRATED, false)) {
prefs.edit().putString(KEY_OEM_LABEL, name).putBoolean(KEY_OEM_LABEL_MIGRATED, true).apply()
val appName = context.getString(R.string.app_name)
if (prefs.getBoolean(KEY_OEM_LABEL_MIGRATED, false)) return stored ?: appName

// Earlier versions persisted the default label alongside user-entered names.
val name = when (stored) {
"NIO" -> appName
"BYD" -> if (prefs.getBoolean(KEY_BYD_LABEL_MIGRATED, false)) stored else appName
else -> stored?.trim()?.takeIf { it.isNotEmpty() }
?: prefs.getString(KEY_MANUFACTURER, null)
?.takeIf { it.isNotBlank() && it != "DiPlay" && it != "DiPlay Web" }
?: appName
}
saveSimulatedManufacturerName(context, name)
return name
}

fun saveSimulatedManufacturerName(context: Context, name: String) {
val customName = name.trim().takeUnless { it.isEmpty() || it == context.getString(R.string.app_name) }
context.getSharedPreferences(PREFS, Context.MODE_PRIVATE).edit()
.putString(KEY_OEM_LABEL, name.trim().ifBlank { DEFAULT_SIMULATED_MANUFACTURER_NAME })
.putString(KEY_OEM_LABEL, customName)
.remove(KEY_BYD_LABEL_MIGRATED)
.putBoolean(KEY_OEM_LABEL_MIGRATED, true)
.apply()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ class CarPlayHostActivity : ComponentActivity() {
private var advancedAudioChannelMappingSupported = false
private var advancedAudioChannelMapping = false
private var model = AirPlayPersistence.DEFAULT_MODEL
private var simulatedManufacturerName = AirPlayPersistence.DEFAULT_SIMULATED_MANUFACTURER_NAME
private var simulatedManufacturerName = ""
private var fps = AirPlayDisplaySettings.DEFAULT_FPS
private var streamTechnology = com.shilapi.xcertplay.web.StreamTechnology.WEBRTC
private var widthPhysicalMm = AirPlayDisplaySettings.DEFAULT_WIDTH_PHYSICAL_MM
Expand Down Expand Up @@ -764,7 +764,7 @@ class CarPlayHostActivity : ComponentActivity() {
)

private fun normalizedManufacturer(): String =
simulatedManufacturerName.trim().ifBlank { AirPlayPersistence.DEFAULT_SIMULATED_MANUFACTURER_NAME }
simulatedManufacturerName.trim().ifBlank { getString(R.string.app_name) }

private fun normalizedModel(): String =
model.trim().ifBlank { AirPlayPersistence.DEFAULT_MODEL }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ internal class SettingsViewModel(
if (includeName)
AirPlayPersistence.saveSimulatedManufacturerName(
app,
AirPlayPersistence.DEFAULT_SIMULATED_MANUFACTURER_NAME,
app.getString(R.string.app_name),
)
reload()
}
Expand Down
Binary file modified common/src/main/res/raw/ic_car_home.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions common/src/main/res/values-zh-rCN/settings_strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
<string name="settings_restore_fullscreen">恢复全屏</string>
<string name="settings_oem">OEM 车厂名称与图标</string>
<string name="settings_icon_preview">CarPlay 车厂图标预览</string>
<string name="settings_default_icon">默认 NIO 图标</string>
<string name="settings_default_icon">默认 WheelPlay 图标</string>
<string name="settings_custom_icon">自定义图标</string>
<string name="settings_oem_description">显示在 CarPlay 应用列表的「返回车机」入口。名称与图标可分别修改,下次连接 iPhone 生效。</string>
<string name="settings_oem_name">车厂名称</string>
Expand All @@ -101,7 +101,7 @@
<string name="settings_reset_icon">恢复默认图标</string>
<string name="settings_reset_branding">恢复默认名称与图标</string>
<string name="settings_reset_branding_title">恢复默认车厂设置?</string>
<string name="settings_reset_branding_message">车厂名称和图标将恢复为 NIO。下次连接 iPhone 生效。</string>
<string name="settings_reset_branding_message">车厂名称和图标将恢复为 WheelPlay。下次连接 iPhone 生效。</string>
<string name="settings_location">定位</string>
<string name="settings_location_source">定位来源</string>
<string name="settings_location_iphone">iPhone 自身定位(默认)</string>
Expand Down Expand Up @@ -183,7 +183,7 @@
<string name="settings_export">保存诊断报告</string>
<string name="settings_export_downloads">报告保存到 Downloads/WheelPlay。不会自动上传,报告排除协议载荷和凭据。</string>
<string name="settings_export_document">请选择报告保存位置。不会自动上传,报告排除协议载荷和凭据。</string>
<string name="settings_licenses">基于 xcertplay / DiPlay,保留 GPL-3.0 与 AGPL-3.0 许可声明。CarPlay 与 NIO 图标属于各自权利人。</string>
<string name="settings_licenses">基于 xcertplay / DiPlay,保留 GPL-3.0 与 AGPL-3.0 许可声明。CarPlay 图标属于其权利人。</string>
<string name="settings_open_source">开源</string>
<string name="settings_source">源码地址</string>
<string name="settings_fingerprint_disabled">HTTPS 已关闭,请在 Web 服务中开启。</string>
Expand Down
6 changes: 3 additions & 3 deletions common/src/main/res/values-zh-rTW/settings_strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
<string name="settings_restore_fullscreen">恢復全螢幕</string>
<string name="settings_oem">OEM 車廠名稱與圖示</string>
<string name="settings_icon_preview">CarPlay 車廠圖示預覽</string>
<string name="settings_default_icon">預設 NIO 圖示</string>
<string name="settings_default_icon">預設 WheelPlay 圖示</string>
<string name="settings_custom_icon">自定義圖示</string>
<string name="settings_oem_description">顯示在 CarPlay 應用程式列表的「返回車機」入口。名稱與圖示可分別修改,下次連線 iPhone 生效。</string>
<string name="settings_oem_name">車廠名稱</string>
Expand All @@ -101,7 +101,7 @@
<string name="settings_reset_icon">恢復預設圖示</string>
<string name="settings_reset_branding">恢復預設名稱與圖示</string>
<string name="settings_reset_branding_title">恢復預設車廠設定?</string>
<string name="settings_reset_branding_message">車廠名稱和圖示將恢復為 NIO。下次連線 iPhone 生效。</string>
<string name="settings_reset_branding_message">車廠名稱和圖示將恢復為 WheelPlay。下次連線 iPhone 生效。</string>
<string name="settings_location">定位</string>
<string name="settings_location_source">定位來源</string>
<string name="settings_location_iphone">iPhone 自身定位(預設)</string>
Expand Down Expand Up @@ -183,7 +183,7 @@
<string name="settings_export">儲存診斷報告</string>
<string name="settings_export_downloads">報告儲存到 Downloads/WheelPlay。不會自動上傳,報告排除協議載荷和憑據。</string>
<string name="settings_export_document">請選擇報告儲存位置。不會自動上傳,報告排除協議載荷和憑據。</string>
<string name="settings_licenses">基於 xcertplay / DiPlay,保留 GPL-3.0 與 AGPL-3.0 許可宣告。CarPlay 與 NIO 圖示屬於各自權利人。</string>
<string name="settings_licenses">基於 xcertplay / DiPlay,保留 GPL-3.0 與 AGPL-3.0 許可宣告。CarPlay 圖示屬於其權利人。</string>
<string name="settings_open_source">開源</string>
<string name="settings_source">原始碼地址</string>
<string name="settings_fingerprint_disabled">HTTPS 已關閉,請在 Web 服務中開啟。</string>
Expand Down
6 changes: 3 additions & 3 deletions common/src/main/res/values/settings_strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
<string name="settings_restore_fullscreen">Restore full screen</string>
<string name="settings_oem">OEM name &amp; icon</string>
<string name="settings_icon_preview">CarPlay vehicle icon preview</string>
<string name="settings_default_icon">Default NIO icon</string>
<string name="settings_default_icon">Default WheelPlay icon</string>
<string name="settings_custom_icon">Custom icon</string>
<string name="settings_oem_description">Shown as the return-to-vehicle entry in CarPlay. The name and icon can be changed independently. Applies on the next iPhone connection.</string>
<string name="settings_oem_name">Vehicle manufacturer name</string>
Expand All @@ -101,7 +101,7 @@
<string name="settings_reset_icon">Restore default icon</string>
<string name="settings_reset_branding">Restore default name &amp; icon</string>
<string name="settings_reset_branding_title">Restore default vehicle settings?</string>
<string name="settings_reset_branding_message">The name and icon will revert to NIO. Applies on the next iPhone connection.</string>
<string name="settings_reset_branding_message">The name and icon will revert to WheelPlay. Applies on the next iPhone connection.</string>
<string name="settings_location">Location</string>
<string name="settings_location_source">Location source</string>
<string name="settings_location_iphone">iPhone location (default)</string>
Expand Down Expand Up @@ -183,7 +183,7 @@
<string name="settings_export">Save diagnostic report</string>
<string name="settings_export_downloads">Saved to Downloads/WheelPlay. Reports are not uploaded automatically and exclude protocol payloads and credentials.</string>
<string name="settings_export_document">Choose where to save the report. Reports are not uploaded automatically and exclude protocol payloads and credentials.</string>
<string name="settings_licenses">Based on xcertplay / DiPlay, retaining GPL-3.0 and AGPL-3.0 license notices. CarPlay and NIO icons belong to their respective owners.</string>
<string name="settings_licenses">Based on xcertplay / DiPlay, retaining GPL-3.0 and AGPL-3.0 license notices. The CarPlay icon belongs to its owner.</string>
<string name="settings_open_source">Open source</string>
<string name="settings_source">Source code</string>
<string name="settings_fingerprint_disabled">HTTPS is disabled. Enable it in Web service settings.</string>
Expand Down
53 changes: 44 additions & 9 deletions common/src/test/java/moe/feng/wheelplay/OemSettingsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,29 @@ class OemSettingsTest : ComposeSettingsTest() {
.edit()
.putString("oem_label", "BYD")
.commit()
assertEquals("NIO", AirPlayPersistence.loadSimulatedManufacturerName(context))
assertEquals("WheelPlay", AirPlayPersistence.loadSimulatedManufacturerName(context))
AirPlayPersistence.saveSimulatedManufacturerName(context, " BYD ")
repeat(2) { assertEquals("BYD", AirPlayPersistence.loadSimulatedManufacturerName(context)) }
AirPlayPersistence.saveSimulatedManufacturerName(context, " ")
assertEquals("WheelPlay", AirPlayPersistence.loadSimulatedManufacturerName(context))
}

@Test
fun previousDefaultMigratesButNamesChosenAfterUpgradeSurviveReload() {
val prefs = context.getSharedPreferences("xcertplay_airplay", 0)
prefs.edit().putString("oem_label", "NIO").putBoolean("oem_label_migrated", true).commit()
assertEquals("WheelPlay", AirPlayPersistence.loadSimulatedManufacturerName(context))
AirPlayPersistence.saveSimulatedManufacturerName(context, "NIO")
assertEquals("NIO", AirPlayPersistence.loadSimulatedManufacturerName(context))
}

@Test
fun bydChosenAfterPreviousMigrationSurvivesUpgrade() {
val prefs = context.getSharedPreferences("xcertplay_airplay", 0)
prefs.edit().putString("oem_label", "BYD").putBoolean("oem_label_migrated", true).commit()
assertEquals("BYD", AirPlayPersistence.loadSimulatedManufacturerName(context))
}

@Test
fun interruptedIconWriteRecoversLastCompleteImageAndResetRemovesIt() {
val original = png()
Expand All @@ -79,6 +95,31 @@ class OemSettingsTest : ComposeSettingsTest() {
val original = png()
AirPlayPersistence.saveSimulatedManufacturerName(context, "比亚迪")
AirPlayPersistence.saveCustomAirPlayIcon(context, original)
val (config, runtime) = phoneConfiguration()
assertEquals("比亚迪", runtime.identification.manufacturer)
val info = AirPlayInfoPlist.build(config)
assertEquals("比亚迪", info["oemIconLabel"])
val icon = (info["oemIcons"] as List<*>).single() as Map<*, *>
assertEquals(64, icon["widthPixels"])
assertEquals(64, icon["heightPixels"])
assertArrayEquals(original, icon["imageData"] as ByteArray)
}

@Test
fun phoneConfigurationAdvertisesWheelPlayByDefault() {
val (config, runtime) = phoneConfiguration()
val info = AirPlayInfoPlist.build(config)
assertEquals("WheelPlay", runtime.identification.manufacturer)
assertEquals("WheelPlay", info["oemIconLabel"])
val icon = (info["oemIcons"] as List<*>).single() as Map<*, *>
assertEquals(192, icon["widthPixels"])
assertEquals(192, icon["heightPixels"])
val expected = context.resources.openRawResource(com.shilapi.xcertplay.host.R.raw.ic_car_home)
.use { it.readBytes() }
assertArrayEquals(expected, icon["imageData"] as ByteArray)
}

private fun phoneConfiguration(): Pair<AirPlayConfig, CarPlayRuntimeConfig> {
// Build the real phone configuration without starting Bluetooth/USB or a session.
val host = Robolectric.buildActivity(CarPlayHostActivity::class.java).get()
val type = CarPlayHostActivity::class.java
Expand All @@ -101,13 +142,7 @@ class OemSettingsTest : ComposeSettingsTest() {
val runtime =
type.getDeclaredMethod("createRuntimeConfig").apply { isAccessible = true }.invoke(host)
as CarPlayRuntimeConfig
assertEquals("比亚迪", runtime.identification.manufacturer)
val info = AirPlayInfoPlist.build(config)
assertEquals("比亚迪", info["oemIconLabel"])
val icon = (info["oemIcons"] as List<*>).single() as Map<*, *>
assertEquals(64, icon["widthPixels"])
assertEquals(64, icon["heightPixels"])
assertArrayEquals(original, icon["imageData"] as ByteArray)
return config to runtime
}

@Test
Expand Down Expand Up @@ -154,7 +189,7 @@ class OemSettingsTest : ComposeSettingsTest() {
controller.pause().resume()
compose.onNodeWithText("恢复默认名称与图标").performScrollTo().performClick()
clickText("确认")
assertEquals("NIO", AirPlayPersistence.loadSimulatedManufacturerName(context))
assertEquals("WheelPlay", AirPlayPersistence.loadSimulatedManufacturerName(context))
assertNull(AirPlayPersistence.loadCustomAirPlayIconFile(context))
} finally {
controller.pause().stop().destroy()
Expand Down
4 changes: 2 additions & 2 deletions docs/UPSTREAM.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Android Gradle 工程已提升至项目根目录:`mobile/`、`common/`、`shar

## CarPlay 返回入口图标

默认名称及图标改为 `NIO`,旧安装保存的默认 `BYD` 名称在读取时迁移为 `NIO`。相关商标及图标属于其原权利人,不纳入本项目代码许可证授权范围。此变更仅影响 CarPlay 返回入口的名称和默认图标,不集成蔚来 App 功能,也不改变点击行为。
CarPlay 返回入口默认使用 WheelPlay 的应用名称和图标。入口 PNG 和 Android 桌面图标由同一份矢量图生成。用户可以在设置中自定义名称和图标,或恢复默认值。

## Material 界面组件

Expand Down Expand Up @@ -58,7 +58,7 @@ Material Components for Android 1.13.0(Apache-2.0),使用官方 Material 3
| 媒体通知下一首 · `ic_media_skip_next` | [skip_next](https://github.com/google/material-design-icons/blob/master/src/av/skip_next/materialicons/24px.svg) |
| 连接通知停止服务 · `ic_media_stop` | [stop](https://github.com/google/material-design-icons/blob/master/src/av/stop/materialicons/24px.svg) |

启动使用播放圆形图标,车机访问及服务通知使用投屏图标。通知采用白色遮罩;页面图标跟随 Material 主题、卡片颜色和导航选中状态。方向箭头保留展开旋转动画,设置选择器支持 RTL 镜像。NIO 返回入口与原有应用品牌位图不属于自绘功能图标;二维码矩阵、裁剪网格及安全区域辅助线是功能内容,不作图标替换。
启动使用播放圆形图标,车机访问及服务通知使用投屏图标。通知采用白色遮罩;页面图标跟随 Material 主题、卡片颜色和导航选中状态。方向箭头保留展开旋转动画,设置选择器支持 RTL 镜像。应用品牌位图不属于自绘功能图标;二维码矩阵、裁剪网格及安全区域辅助线是功能内容,不作图标替换。

## VPN Hotspot Root 路由适配

Expand Down
4 changes: 3 additions & 1 deletion scripts/generate-app-icons.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ for (const [density, size] of Object.entries({ mdpi: 48, hdpi: 72, xhdpi: 96, xx
.toFile(fileURLToPath(new URL(`ic_launcher${round ? '_round' : ''}.webp`, directory)));
}
}
await sharp(Buffer.from(svg(192))).png()
.toFile(fileURLToPath(new URL('common/src/main/res/raw/ic_car_home.png', root)));
await sharp(Buffer.from(svg(512))).png()
.toFile(fileURLToPath(new URL('shared/src/main/ic_launcher-playstore.png', root)));
await mkdir(new URL('docs/assets/', root), { recursive: true });
await writeFile(new URL('docs/assets/app-icon.svg', root), svg(512));
console.log('Generated launcher bitmaps, Play Store icon, and SVG export.');
console.log('Generated launcher bitmaps, CarPlay icon, Play Store icon, and SVG export.');
Loading