leejunyoung5819 wayland-android-remote
공개Ubuntu(Wayland/X11)에서 Android 기기 화면 미러링 및 원격 제어 (Rust)
| 1 | package com.androidremote.companion |
| 2 | |
| 3 | import android.content.BroadcastReceiver |
| 4 | import android.content.Context |
| 5 | import android.content.Intent |
| 6 | |
| 7 | /** |
| 8 | * 데몬이 시작할 때 보내는 접속 토큰·포트를 저장한다. 매니페스트에서 DUMP 권한으로 보호해 |
| 9 | * shell·system만 보낼 수 있다. |
| 10 | */ |
| 11 | class TokenReceiver : BroadcastReceiver() { |
| 12 | override fun onReceive(context: Context, intent: Intent) { |
| 13 | DaemonEndpoint.save(context, intent.getStringExtra("token"), intent.getIntExtra("port", 0)) |
| 14 | } |
| 15 | } |
| 16 | |
| 17 | /** 데몬 접속 정보 (127.0.0.1 포트와 토큰). */ |
| 18 | object DaemonEndpoint { |
| 19 | private const val PREFS = "daemon" |
| 20 | |
| 21 | fun save(context: Context, token: String?, port: Int) { |
| 22 | if (token.isNullOrEmpty() || port <= 0) return |
| 23 | context.getSharedPreferences(PREFS, Context.MODE_PRIVATE).edit() |
| 24 | .putString("token", token).putInt("port", port).apply() |
| 25 | } |
| 26 | |
| 27 | fun load(context: Context): Pair<String, Int>? { |
| 28 | val p = context.getSharedPreferences(PREFS, Context.MODE_PRIVATE) |
| 29 | val token = p.getString("token", null) ?: return null |
| 30 | return token to p.getInt("port", 27201) |
| 31 | } |
| 32 | } |