[[["わかりやすい","easyToUnderstand","thumb-up"],["問題の解決に役立った","solvedMyProblem","thumb-up"],["その他","otherUp","thumb-up"]],[["必要な情報がない","missingTheInformationINeed","thumb-down"],["複雑すぎる / 手順が多すぎる","tooComplicatedTooManySteps","thumb-down"],["最新ではない","outOfDate","thumb-down"],["翻訳に関する問題","translationIssue","thumb-down"],["サンプル / コードに問題がある","samplesCodeIssue","thumb-down"],["その他","otherDown","thumb-down"]],["最終更新日 2025-03-26 UTC。"],[],[],null,["# Companion app streaming\n\nIn Android 13, the app streaming feature lets phones\nstream their apps to connected devices, and lets those devices interact with the\napps. A new [`COMPANION_DEVICE_APP_STREAMING`](https://cs.android.com/android/platform/superproject/+/android-latest-release:packages/modules/Permission/PermissionController/res/xml/roles.xml;drc=7816a6a2bfed3e4727f6b6f767a3e0f825dce880;l=1070)\nrole lets an app create and manage proxies for connected remote devices to\nstream apps from the local device to the remote device. The app holding the\n`COMPANION_DEVICE_APP_STREAMING` role can obtain permissions to create a virtual\ndisplay, launch an app on it, and then stream a video of the launched app to\nanother device. The role holder app can also inject input and microphone events\nreceived from a remote device back into the local device, as if that device were\nconnected as a peripheral.\n\nArchitecture\n------------\n\nBeginning in Android 13, the new [Virtual Device\nManager](https://cs.android.com/android/platform/superproject/+/android-latest-release:frameworks/base/core/java/android/companion/virtual/VirtualDeviceManager.java)\nand the [Companion Device Manager\n(CDM)](https://developer.android.com/reference/android/companion/CompanionDeviceManager)\nform the key building blocks to support app streaming and interaction with\nremote, connected devices.\n\n### Virtual Device Manager\n\nApp streaming works by taking advantage of *virtual displays*. The Virtual\nDevice Manager creates a virtual display that's separate from the visible\nprimary display. When the user consents to start streaming an app, the app is\nlaunched on, or transferred to, the virtual display. The contents of the virtual\ndisplay are transferred in a video stream to the connected device to be\ndisplayed.\n\nThe Virtual Device Manager includes APIs that enable the creation, registration,\nand management of\n[`VirtualDevice`](https://cs.android.com/android/platform/superproject/+/android-latest-release:frameworks/base/core/java/android/companion/virtual/VirtualDeviceManager.java;drc=725dad7d717fc641d3ee3adb782270b82ee92cd8;l=152) instances.\n\nA `VirtualDevice` instance is a proxy for the connected device and its\ncapabilities. A `VirtualDevice` instance enables a connected device to receive,\ndisplay and interact with an incoming app stream, by doing the following:\n\n- Creating a [`VirtualDisplay`](https://cs.android.com/android/platform/superproject/+/android-latest-release:frameworks/base/core/java/android/hardware/display/VirtualDisplay.java) instance intended to be displayed on a connected device's display.\n- Injecting a remote audio stream, such as from the connected device's microphone, into the local device for playback.\n- Injecting remote input events, such as the from the connected device's keyboard, into the local device for playback.\n\n### Companion Device Manager\n\nThe CDM manages the connectivity state and enforces the role requirements that\nmust be met to enable app streaming.\n\nThe following figure illustrates the interactions between the local and remote\ndevice during app streaming:\n\n**Figure 1.** Interactions between the local and remote devices during app streaming\n\nImplementation of the companion app streaming role\n--------------------------------------------------\n\nOEMs can implement an app with the `COMPANION_DEVICE_APP_STREAMING` role to\nenable a rich and secure cross-device experience on their devices.\n| **Note:** Only preinstalled priv-apps are allowed to hold the `COMPANION_DEVICE_APP_STREAMING` role. OEMs must ensure that the app is submitted for review as part of the device verification process. Reach out to your Google point of contact for more information.\n\nTo create a virtual device to enable app streaming, an app must be a role holder\nof the `COMPANION_DEVICE_APP_STREAMING` role. When the role is granted, the app\nreceives the\n[`CREATE_VIRTUAL_DEVICE`](https://cs.android.com/android/platform/superproject/+/android-latest-release:frameworks/base/core/res/AndroidManifest.xml;drc=14543d1ec72202422373622ee818fe7549be5c7a;l=6440) permission, which enables\nthe app to create a virtual device. Role\nholders are expected to implement app streaming by creating a `VirtualDevice`\ninstance that acts as a proxy for a connected device. The `VirtualDevice` class\nprovides methods that enable the extraction of a composited surface of a virtual\ndisplay, suitable for streaming to another device. The `VirtualDevice` class\nalso provides APIs for injecting input events that occur on a remote device into\nthe local device, enabling an app that's running on a local device to appear as\nif it's running natively on a remote device.\n\nFollow these steps to implement the companion app streaming role:\n\n1. Create an app that requests the\n [`REQUEST_COMPANION_PROFILE_APP_STREAMING`](https://developer.android.com/reference/android/Manifest.permission#REQUEST_COMPANION_PROFILE_APP_STREAMING)\n permission in the manifest.\n\n2. Prompt the user to grant the app permission to perform app streaming.\n\n3. Create a CDM\n [`AssociationRequest`](https://developer.android.com/reference/android/companion/CompanionDeviceManager#associate(android.companion.AssociationRequest,%20java.util.concurrent.Executor,%20android.companion.CompanionDeviceManager.Callback))\n instance to request a `COMPANION_DEVICE_APP_STREAMING` role. The app\n receives the `CREATE_VIRTUAL_DEVICE` permission when the role is granted.\n\n4. Call\n [`VirtualDeviceManager#create()`](https://cs.android.com/android/platform/superproject/+/android-latest-release:frameworks/base/core/java/android/companion/virtual/VirtualDeviceManager.java;drc=725dad7d717fc641d3ee3adb782270b82ee92cd8;l=67)\n to create a `VirtualDevice` instance. With a `VirtualDevice` instance, the\n app can create and manage virtual displays and virtual inputs.\n\n5. Launch the notification's pending intent on the virtual display and create a\n video capture of that display.\n\n6. Create a connection to the connected device and stream the virtual display\n over to the connected device.\n\n7. Inject back input events from the connected device into the local device\n through the `VirtualDevice` APIs.\n\n8. When the user closes the streaming app on the remote device, end the stream\n and tear down the `VirtualDevice` instance. At this point, the previously\n streaming app runs in the background on the local device and the connection\n is closed.\n\n9. If needed, await more signals from the connected device to restart the app\n streaming.\n\nThe app is responsible for connecting to the remote device, reporting the\nconnectivity state to CDM, and enforcing security requirements as described in\nthe [CDD](/docs/compatibility/13/android-13-cdd#316_companion_device_pairing).\n| **Note:** Google offers a closed-source implementation called Cross Device Service that enables app streaming from any Android phone running Android 13 or higher, to a Chromebook. OEMs can preload the Cross Device Service APK under the priv-app directory.\n\n### COMPANION_DEVICE_APP_STREAMING role holder requirements\n\nThe CDM grants the `COMPANION_DEVICE_APP_STREAMING` role when the user\nassociates an app streaming app with a device. This role is associated with a\ndevice profile so there's some control over which apps can be added to the Play\nStore that match this profile. See [Android\nroles](/docs/core/permissions/android-roles)\nfor a list of the `COMPANION_DEVICE_APP_STREAMING` role requirements. Reach out\nto your Google point of contact for more information.\n\n### COMPANION_DEVICE_APP_STREAMING role holder capabilities\n\nTo perform app streaming, the `COMPANION_DEVICE_APP_STREAMING` role assumes that\nthe role holder app has the following capabilities and behaviors:\n\n- Create and manage connections to other devices.\n- Create and manage trusted virtual displays, including unlocked displays, as follows:\n - Start activities on the virtual display.\n - Inject events that happen on a streamed app on a connected device back on the local device, such as playing a touch event on the tablet at the same coordinates on the phone.\n - Capture audio data from the streamed app.\n - Replace the local device's microphone stream with a connected device's microphone stream while a streamed app is using the microphone.\n - Replace the local device's camera stream with a connected device's camera stream while a streamed app is using the camera.\n- Manage and stream notifications from the local device to the connected device, and take actions on notifications.\n- Stream metadata from the local device, such as the list of apps available on the local device, to the connected device.\n- Request device verification."]]