@@ -14,6 +14,7 @@ import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.provider.Settings
|
||||
import android.util.Log
|
||||
import android.util.Rational
|
||||
import android.view.InputDevice
|
||||
@@ -189,6 +190,17 @@ class MainActivity : FlutterActivity() {
|
||||
)
|
||||
}
|
||||
|
||||
/** User-assigned device name (Settings > About > Device name), or null. */
|
||||
private fun getDeviceName(): String? {
|
||||
// The name the user gave the device; also used by Cast/Nearby.
|
||||
val name = Settings.Global.getString(contentResolver, Settings.Global.DEVICE_NAME)
|
||||
if (!name.isNullOrBlank()) return name
|
||||
// Fallback: the Bluetooth name usually mirrors the device name. Reading the
|
||||
// settings string needs no BLUETOOTH permission (unlike BluetoothAdapter).
|
||||
val bt = Settings.Secure.getString(contentResolver, "bluetooth_name")
|
||||
return if (!bt.isNullOrBlank()) bt else null
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
// Apply persisted theme color to the window background before anything
|
||||
// else renders. This prevents a white flash between the native splash
|
||||
@@ -427,6 +439,7 @@ class MainActivity : FlutterActivity() {
|
||||
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, DEVICE_CHANNEL).setMethodCallHandler { call, result ->
|
||||
when (call.method) {
|
||||
"getTvDetection" -> result.success(getAndroidTvDetection())
|
||||
"getDeviceName" -> result.success(getDeviceName())
|
||||
else -> result.notImplemented()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ import '../services/companion_remote/lan_discovery_service.dart';
|
||||
import '../services/companion_remote/remote_auth_context.dart';
|
||||
import '../services/companion_remote/remote_auth_service.dart';
|
||||
import '../utils/app_logger.dart';
|
||||
import '../utils/platform_detector.dart';
|
||||
import '../mixins/disposable_change_notifier_mixin.dart';
|
||||
|
||||
export '../services/companion_remote/lan_discovery_service.dart' show DiscoveredHost;
|
||||
@@ -79,7 +80,8 @@ class CompanionRemoteProvider with ChangeNotifier, DisposableChangeNotifierMixin
|
||||
try {
|
||||
if (Platform.isAndroid) {
|
||||
final androidInfo = await deviceInfo.androidInfo;
|
||||
_deviceName = '${androidInfo.brand} ${androidInfo.model}';
|
||||
final osName = await TvDetectionService.getAndroidDeviceName();
|
||||
_deviceName = osName ?? '${androidInfo.brand} ${androidInfo.model}';
|
||||
_platform = 'Android';
|
||||
} else if (Platform.isIOS) {
|
||||
final iosInfo = await deviceInfo.iosInfo;
|
||||
@@ -94,8 +96,8 @@ class CompanionRemoteProvider with ChangeNotifier, DisposableChangeNotifierMixin
|
||||
_deviceName = windowsInfo.computerName;
|
||||
_platform = 'Windows';
|
||||
} else if (Platform.isLinux) {
|
||||
final linuxInfo = await deviceInfo.linuxInfo;
|
||||
_deviceName = linuxInfo.name;
|
||||
final host = Platform.localHostname.trim();
|
||||
_deviceName = (host.isNotEmpty && host != 'localhost') ? host : (await deviceInfo.linuxInfo).name;
|
||||
_platform = 'Linux';
|
||||
}
|
||||
} catch (e) {
|
||||
|
||||
@@ -116,6 +116,20 @@ class TvDetectionService {
|
||||
}
|
||||
}
|
||||
|
||||
/// User-assigned Android device name (Settings > About > Device name), or
|
||||
/// null if unavailable. Android only.
|
||||
static Future<String?> getAndroidDeviceName() async {
|
||||
if (!Platform.isAndroid) return null;
|
||||
try {
|
||||
final name = (await _deviceChannel.invokeMethod<String>('getDeviceName'))?.trim();
|
||||
return (name == null || name.isEmpty) ? null : name;
|
||||
} on MissingPluginException {
|
||||
return null;
|
||||
} on PlatformException {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// Update the user force-TV override and recompute the effective flag.
|
||||
void setForceTv(bool value) {
|
||||
_forceTv = value;
|
||||
|
||||
Reference in New Issue
Block a user