diff --git a/common/src/main/java/moe/feng/wheelplay/AirPlayPersistence.kt b/common/src/main/java/moe/feng/wheelplay/AirPlayPersistence.kt index f6539a6d..9544d165 100644 --- a/common/src/main/java/moe/feng/wheelplay/AirPlayPersistence.kt +++ b/common/src/main/java/moe/feng/wheelplay/AirPlayPersistence.kt @@ -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 @@ -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" @@ -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 = @@ -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() } diff --git a/common/src/main/java/moe/feng/wheelplay/CarPlayHostActivity.kt b/common/src/main/java/moe/feng/wheelplay/CarPlayHostActivity.kt index 53048a0c..3cbde926 100644 --- a/common/src/main/java/moe/feng/wheelplay/CarPlayHostActivity.kt +++ b/common/src/main/java/moe/feng/wheelplay/CarPlayHostActivity.kt @@ -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 @@ -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 } diff --git a/common/src/main/java/moe/feng/wheelplay/settings/SettingsViewModel.kt b/common/src/main/java/moe/feng/wheelplay/settings/SettingsViewModel.kt index 8b7b5499..89ecf148 100644 --- a/common/src/main/java/moe/feng/wheelplay/settings/SettingsViewModel.kt +++ b/common/src/main/java/moe/feng/wheelplay/settings/SettingsViewModel.kt @@ -413,7 +413,7 @@ internal class SettingsViewModel( if (includeName) AirPlayPersistence.saveSimulatedManufacturerName( app, - AirPlayPersistence.DEFAULT_SIMULATED_MANUFACTURER_NAME, + app.getString(R.string.app_name), ) reload() } diff --git a/common/src/main/res/raw/ic_car_home.png b/common/src/main/res/raw/ic_car_home.png index b245fac0..af56e8fc 100644 Binary files a/common/src/main/res/raw/ic_car_home.png and b/common/src/main/res/raw/ic_car_home.png differ diff --git a/common/src/main/res/values-zh-rCN/settings_strings.xml b/common/src/main/res/values-zh-rCN/settings_strings.xml index 8979aac1..4cc235b5 100644 --- a/common/src/main/res/values-zh-rCN/settings_strings.xml +++ b/common/src/main/res/values-zh-rCN/settings_strings.xml @@ -92,7 +92,7 @@ 恢复全屏 OEM 车厂名称与图标 CarPlay 车厂图标预览 - 默认 NIO 图标 + 默认 WheelPlay 图标 自定义图标 显示在 CarPlay 应用列表的「返回车机」入口。名称与图标可分别修改,下次连接 iPhone 生效。 车厂名称 @@ -101,7 +101,7 @@ 恢复默认图标 恢复默认名称与图标 恢复默认车厂设置? - 车厂名称和图标将恢复为 NIO。下次连接 iPhone 生效。 + 车厂名称和图标将恢复为 WheelPlay。下次连接 iPhone 生效。 定位 定位来源 iPhone 自身定位(默认) @@ -183,7 +183,7 @@ 保存诊断报告 报告保存到 Downloads/WheelPlay。不会自动上传,报告排除协议载荷和凭据。 请选择报告保存位置。不会自动上传,报告排除协议载荷和凭据。 - 基于 xcertplay / DiPlay,保留 GPL-3.0 与 AGPL-3.0 许可声明。CarPlay 与 NIO 图标属于各自权利人。 + 基于 xcertplay / DiPlay,保留 GPL-3.0 与 AGPL-3.0 许可声明。CarPlay 图标属于其权利人。 开源 源码地址 HTTPS 已关闭,请在 Web 服务中开启。 diff --git a/common/src/main/res/values-zh-rTW/settings_strings.xml b/common/src/main/res/values-zh-rTW/settings_strings.xml index 79e6bfa6..c5feae76 100644 --- a/common/src/main/res/values-zh-rTW/settings_strings.xml +++ b/common/src/main/res/values-zh-rTW/settings_strings.xml @@ -92,7 +92,7 @@ 恢復全螢幕 OEM 車廠名稱與圖示 CarPlay 車廠圖示預覽 - 預設 NIO 圖示 + 預設 WheelPlay 圖示 自定義圖示 顯示在 CarPlay 應用程式列表的「返回車機」入口。名稱與圖示可分別修改,下次連線 iPhone 生效。 車廠名稱 @@ -101,7 +101,7 @@ 恢復預設圖示 恢復預設名稱與圖示 恢復預設車廠設定? - 車廠名稱和圖示將恢復為 NIO。下次連線 iPhone 生效。 + 車廠名稱和圖示將恢復為 WheelPlay。下次連線 iPhone 生效。 定位 定位來源 iPhone 自身定位(預設) @@ -183,7 +183,7 @@ 儲存診斷報告 報告儲存到 Downloads/WheelPlay。不會自動上傳,報告排除協議載荷和憑據。 請選擇報告儲存位置。不會自動上傳,報告排除協議載荷和憑據。 - 基於 xcertplay / DiPlay,保留 GPL-3.0 與 AGPL-3.0 許可宣告。CarPlay 與 NIO 圖示屬於各自權利人。 + 基於 xcertplay / DiPlay,保留 GPL-3.0 與 AGPL-3.0 許可宣告。CarPlay 圖示屬於其權利人。 開源 原始碼地址 HTTPS 已關閉,請在 Web 服務中開啟。 diff --git a/common/src/main/res/values/settings_strings.xml b/common/src/main/res/values/settings_strings.xml index 0239df11..dc8a97e5 100644 --- a/common/src/main/res/values/settings_strings.xml +++ b/common/src/main/res/values/settings_strings.xml @@ -92,7 +92,7 @@ Restore full screen OEM name & icon CarPlay vehicle icon preview - Default NIO icon + Default WheelPlay icon Custom icon Shown as the return-to-vehicle entry in CarPlay. The name and icon can be changed independently. Applies on the next iPhone connection. Vehicle manufacturer name @@ -101,7 +101,7 @@ Restore default icon Restore default name & icon Restore default vehicle settings? - The name and icon will revert to NIO. Applies on the next iPhone connection. + The name and icon will revert to WheelPlay. Applies on the next iPhone connection. Location Location source iPhone location (default) @@ -183,7 +183,7 @@ Save diagnostic report Saved to Downloads/WheelPlay. Reports are not uploaded automatically and exclude protocol payloads and credentials. Choose where to save the report. Reports are not uploaded automatically and exclude protocol payloads and credentials. - Based on xcertplay / DiPlay, retaining GPL-3.0 and AGPL-3.0 license notices. CarPlay and NIO icons belong to their respective owners. + Based on xcertplay / DiPlay, retaining GPL-3.0 and AGPL-3.0 license notices. The CarPlay icon belongs to its owner. Open source Source code HTTPS is disabled. Enable it in Web service settings. diff --git a/common/src/test/java/moe/feng/wheelplay/OemSettingsTest.kt b/common/src/test/java/moe/feng/wheelplay/OemSettingsTest.kt index 2b641ebd..ce1cd403 100644 --- a/common/src/test/java/moe/feng/wheelplay/OemSettingsTest.kt +++ b/common/src/test/java/moe/feng/wheelplay/OemSettingsTest.kt @@ -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() @@ -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 { // 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 @@ -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 @@ -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() diff --git a/docs/UPSTREAM.md b/docs/UPSTREAM.md index 5bf7d8a5..23aebf09 100644 --- a/docs/UPSTREAM.md +++ b/docs/UPSTREAM.md @@ -17,7 +17,7 @@ Android Gradle 工程已提升至项目根目录:`mobile/`、`common/`、`shar ## CarPlay 返回入口图标 -默认名称及图标改为 `NIO`,旧安装保存的默认 `BYD` 名称在读取时迁移为 `NIO`。相关商标及图标属于其原权利人,不纳入本项目代码许可证授权范围。此变更仅影响 CarPlay 返回入口的名称和默认图标,不集成蔚来 App 功能,也不改变点击行为。 +CarPlay 返回入口默认使用 WheelPlay 的应用名称和图标。入口 PNG 和 Android 桌面图标由同一份矢量图生成。用户可以在设置中自定义名称和图标,或恢复默认值。 ## Material 界面组件 @@ -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 路由适配 diff --git a/scripts/generate-app-icons.mjs b/scripts/generate-app-icons.mjs index c062cc4a..dc246bed 100644 --- a/scripts/generate-app-icons.mjs +++ b/scripts/generate-app-icons.mjs @@ -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.');