The recommended way is to use libadbd_auth (frameworks/native/libs/adbd_auth). It is a bidirectional socket originally used to handle authentication messages (hence the name). It has since evolved to carry other categories of messages.
┌────────────┐ ┌─────────────────────┐
│ ADBService ◄───────────────► AdbDebuggingManager │
└────────────┘ └──────────▲──────────┘
│
┌──────────▼──────────┐
│ AdbDebuggingThread │
└──────────▲──────────┘
│
Framework ┌───────▼───────┐
─────────────────────────────────────┤ "adbd" socket ├─────────
ADBd └───────▲───────┘
│
┌───────┐ ┌──────▼─────┐
│ ADBd ◄─────────────────────► adbd_auth │
└───────┘ └────────────┘
Example of usages (adbd-framework direction, packet header):
A hacky way which should be avoided as much as possible is to use system property setter + getter. There are threads listening on system property changes in both adbd and framework. See examples as follows.
service.adb.tls.port, framework uses a thread to monitor it.persist.adb.tls_server.enable, adbd uses a thread to monitor it.If you are an ADB maintainer or/and have a few spare cycles, it would not be a bad idea to remove these in favor of using adbd_auth.