Commit Graph

299 Commits

Author SHA1 Message Date
Raphael Kim
cf44275a59 Force associated devices to be strongly typed and expose AssociatedDevice.
Bug: 254279707
Test: atest CtsCompanionDeviceManagerUiAutomationTestCases
      atest CtsCompanionDeviceManagerCoreTestCases
Change-Id: I1a505132ff52b14b6838e6404ecafae483b4b623
2022-10-27 11:35:04 -07:00
Sandro Meier
b03a7b7d07 Add id to InputDeviceDesc of VirtualInputDevice
Virtual input devices did not store the deviceId as this was not needed.
This change stores the deviceId during the device initialization (deviceId
is given to InputDeviceListener callback, which is used to wait for a
virtual device to be initialized and configured)

The deviceId is needed to restrict an input device to a display group.

Bug: 244516415
Test: atest android.hardware.input.cts.tests.VirtualKeyboardTest
Change-Id: I982191d543556e2728e41d6da01ab1a631e50e1a
2022-10-19 16:31:59 +00:00
Vladimir Komsiyski
cd8f204717 Merge changes from topic "virtual-device-context"
* changes:
  Add deviceId to Context and allow for creating Contexts with different deviceId.
  Open the visibility of VirtualDeviceManager and VirtualDeviceManager#getVirtualDevices.
  Add an API to get the details of all virtual devices.
2022-10-18 06:36:52 +00:00
Vladimir Komsiyski
0050a51961 Open the visibility of VirtualDeviceManager and VirtualDeviceManager#getVirtualDevices.
Bug: 239152561
Test: n/a
Change-Id: Ib504a3bad36072730a527b139de945874ec4741a
2022-10-17 17:44:12 +02:00
Vladimir Komsiyski
156763aa02 Add an API to get the details of all virtual devices.
Expose minimal information about a virtual device in `VirtualDevice` and allow clients to access it via VDM.

Bug: 239152561
Test: atest VirtualDeviceTest, CTS sent separately
Change-Id: I7e21009444205925707821692888dad50b58316f
2022-10-17 17:42:12 +02:00
Raphael Kim
9a029c8e22 Clean up codegen templates from core companion package.
Bug: 249830557
Test: N/A (File reformat)
Change-Id: Ife53e3095e3d4aecb1528cfce7369a62860b1ae4
2022-10-13 17:38:35 +00:00
Raphael Kim
f4ca0b7191 Add associated device property to AssociationInfo
Bug: 225377622
Test: atest CtsCompanionDeviceManagerUiAutomationTestCases
Change-Id: If09c506e73aab404f684201ada7f63704113af5c
2022-10-07 20:32:22 +00:00
Vladimir Komsiyski
624334fd63 Merge "Add a unique ID to a virtual device." 2022-10-04 19:29:00 +00:00
Guojing Yuan
218a8db85f Merge "Update CDM owners" am: 7f8431f3ec am: 71ff01c2da am: 05fdac447a am: ea20fb86ae am: f731f8a295
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/2240179

Change-Id: I5156cc051e1ebc3bc38be5c142ee8be1474097ab
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-10-04 17:10:42 +00:00
Phill Hayers
7b67b35997 Add a unique ID to a virtual device.
This will be used in a later CL to allow virtual displays to be
associated with their virtual device.

Bug: 205343547
Test: atest VirtualDeviceManagerServiceTest

Change-Id: Ibbf5a8c834d5d7a7bac4816a0ea151adad4e7ea7
2022-10-04 08:58:17 +02:00
Guojing Yuan
f731f8a295 Merge "Update CDM owners" am: 7f8431f3ec am: 71ff01c2da am: 05fdac447a am: ea20fb86ae
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/2240179

Change-Id: I21f419d660d66a8cc7259ee0586f9363e6b5d4c1
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-10-04 06:25:19 +00:00
Evan Chen
3c30656e87 Merge "Must cancel bt discovery before calling cdm.assoicate()" 2022-10-04 03:43:26 +00:00
Evan Chen
877759fdfa Must cancel bt discovery before calling cdm.assoicate()
Update the javadoc that application must caancel it's own
bt discovery before calling assoicate api.

Test: make
Fix: 245763762
Change-Id: I41746f0d52d58e69edf453047416b6fc235db72e
2022-10-04 00:22:14 +00:00
Evan Chen
2428d28e65 Merge "Add an API for cancelling current CDM activity" 2022-10-03 23:48:55 +00:00
Guojing Yuan
4aebac9428 Update CDM owners
Fix: 249841197

Test: build

Change-Id: I6c0c81debf6de862bec489f48ec9f1a05b181b2f
2022-10-03 22:18:28 +00:00
Raphael Kim
488e0e9977 Update javadoc to reflect API limitation in API < 33
Bug: 243460453
Test: Not applicable (javadoc update)
Change-Id: I3b3c8755dbefdfaa5339e176dbad6fb2ee434833
2022-09-29 23:11:13 +00:00
Yuanjia Hsu
0cb7161d8c Merge "Remove reference when VirtualAudioDevice is closed" 2022-09-28 01:57:25 +00:00
Evan Chen
3b70638477 Add an API for cancelling current CDM activity
Test: atest CtsCompanionDeviceManagerCoreTestCases
      atest CtsCompanionDeviceManagerUiAutomationTestCases
      atest CtsOsTestCases:CompanionDeviceManagerTest
Bug: 242012556
Change-Id: If76ed8ccaef1982d7bd1f188f112c35338352f78
2022-09-28 00:31:01 +00:00
yuanjiahsu
a8b3b3d4de Remove reference when VirtualAudioDevice is closed
Adds close listener so that VirtualDevice can remove the cached reference when VirtualAudioDevice is closed.

Bug: 224917468
Test: atest FrameworksCoreTests:android.companion.virtual
Change-Id: I0fa27818568684f7bfb7edd62a6d6eebdb648f29
2022-09-27 21:18:11 +08:00
Phill Hayers
060ded7841 Add a virtual Dpad.
Bug: 244519097
Test: atest VirtualDpadTest and atest VirtualDeviceManagerServiceTest

Change-Id: Iafce6fccee9f761e79e8fd845bb6e9b1e1490b26
2022-09-20 08:44:40 +00:00
Guojing Yuan
db96169507 Update the CDM device presence javadoc and overall logs
Fix: 245749527

Test: build
Change-Id: If20e50a95763aa2f318f0f5f5dee8cc0ae446259
2022-09-08 17:43:21 +00:00
Cole Faust
9acf46f66f [conflict] Merge "Fix array-related errorprone warnings" am: a1eb8cf128 am: 44f8576073 am: 91d6c5b564 am: 6a79ae2567 am: 9b3a5fc03b
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/2186016

Change-Id: I5e59b8549df348c181cd3b72311798a5d7602a67
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-08-30 21:03:54 +00:00
Cole Faust
9b3a5fc03b Merge "Fix array-related errorprone warnings" am: a1eb8cf128 am: 44f8576073 am: 91d6c5b564 am: 6a79ae2567
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/2186016

Change-Id: I7052a1f7391ed6701fe0e1036c27368609032e35
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-08-30 20:44:00 +00:00
Cole Faust
584140c83a Fix array-related errorprone warnings
The ArrayEquals, ArrayHashCode, ArrayToString, and
ArraysAsListPrimitiveArray errorprone findings were
demoted from errors to warnings. Fix existing
occurrences of them so they can be made errors again.

Bug: 242630963
Test: RUN_ERROR_PRONE=true m javac-check
Change-Id: Ia6f216cc36ad0a5758f39fd9b34962cd4adf9d8e
2022-08-25 10:57:12 -07:00
Raphael Kim
1c0d605cfd Add hidden API for testing application bound state
Bug: 234851406
Test: atest CtsCompanionDeviceManagerMultiProcessTestCases:BinderLifecycleTest
Change-Id: I721cd99e837b81ade13a12d0c7e364022e9475d3
2022-08-23 10:55:48 -07:00
Jeff Sharkey
7ae966c3f9 Handle null callbacks, add missing breaks.
The ISystemDataTransferCallback argument can be null, so quietly
handle that case.  Also fix bug where we forgot "break" statements
when processing responses.

Finally, always detach transport before closing streams to avoid
misleading warning logs being emitted from system.

Bug: 237030169
Test: manual
Change-Id: Id6d2d93a1c6872152112f877a2b92f4656277803
2022-06-30 14:46:12 -06:00
Jeff Sharkey
9ac551161b Progress on permissions sync transport migration.
An earlier change introduced a socketpair() based CDM transport,
which is robust "streaming" interface between two devices.

This change updates the existing permissions sync logic to use this
new transport for its payloads.  It also begins returning success or
failure messages so the requesting side knows when the permissions
have been applied.

We also rename the package and class hosting the transport logic,
and migrate our socketpair() based transport logic there.  Since
the initial version of this protocol won't be using protobufs,
and doesn't need to implement manual pagination, this change also
removes that logic to reduce the size of our backports.

Finally, since this transport isn't ready to be used by third-party
apps, we add security checks to only allow built-in apps.

Bug: 237030169
Test: atest CompanionTests
Change-Id: Ia0dab24d44f1973d5af6ad8a2abb198408a681df
2022-06-29 16:33:30 -06:00
Guojing Yuan
592a33f868 [CDM perm sync] Introduce a new startSystemDataTransfer API with
callback

This new trigger API accpets a callback which would be executed when the
system data transfer finishes successfully or with error.

The callback hasn't been fully implemented because we need signals from
transport layer when the transfer finishes.

Bug: 237030169

Test: m builds
Change-Id: I7e57d3e53e5f019c8730df10f7ec6c840e446f67
2022-06-27 23:18:42 +00:00
Jeff Sharkey
464ed18be6 Initial pass at socketpair() based CDM transport.
Based on design conversations with the team, it's more robust to
rely on a CDM companion service to provide a "streaming" interface
between two devices, instead of building our own message
fragmentation and reassembly logic.  (Most transports such as
Bluetooth RFCOMM will already be doing their own fragmentation, so
we don't need to duplicate that work.)

Additionally, this change uses socketpair() for the bidirectional
data transfer between the companion service and the system_server,
avoiding additional Binder transaction load while handling its own
chunking, at the expense of dedicating two threads to "shovel" data
in each direction.

This change attempts to implement the design in the most
straightforward way possible to reduce risk; there are several
opportunities to optimize the thread usage using tools like
MessageQueue.addOnFileDescriptorEventListener(), but those will
need to wait for a future iteration.

Also includes basic functionality tests that exercise a PING/PONG
command to verify many different edge cases; they're currently all
passing.

Bug: 237030169
Test: atest CompanionTests
Change-Id: I075128fa60379f47400345b211a07d9a32391155
2022-06-24 09:57:47 +02:00
Evan Chen
3f9ae86e45 Delay role revoke when the app is not visible to the user
This cl fixes the problem that CDM calls RoleManager.removeRoleHolderAsUser()
will kill the application's process that lead to the poor user
experience.

In order to fix the problem:

1. Introduce a new OnUidImportanceListener which watches the
importance of the packages. In this class, we only interested in
the importance of the running process is greater than
IMPORTANCE_VISIBLE.

2. Introduce a new field in AssociationInfo class: 'mRevoked' to
indicate the associaiton has been reovked and pending for
role holder removal. So that the revoked association can store
in the same place as the active associaiton -> easy maintenance.

3. Finally remove the role holder for the packages are not visible to
the users.

Bug: 189250370
Test: atest CtsCompanionDeviceManagerCoreTestCases
      atest CtsCompanionDeviceManagerUiAutomationTestCases
      atest CtsOsTestCases:CompanionDeviceManagerTest
Change-Id: Ib7fb08b0d800c62a9ee708ddd52cd174de1829d9
Merged-In: Ib7fb08b0d800c62a9ee708ddd52cd174de1829d9
2022-06-23 18:20:29 +00:00
Evan Chen
9ba08918e9 Delay role revoke when the app is not visible to the user
This cl fixes the problem that CDM calls RoleManager.removeRoleHolderAsUser()
will kill the application's process that lead to the poor user
experience.

In order to fix the problem:

1. Introduce a new OnUidImportanceListener which watches the
importance of the packages. In this class, we only interested in
the importance of the running process is greater than
IMPORTANCE_VISIBLE.

2. Introduce a new field in AssociationInfo class: 'mRevoked' to
indicate the associaiton has been reovked and pending for
role holder removal. So that the revoked association can store
in the same place as the active associaiton -> easy maintenance.

3. Finally remove the role holder for the packages are not visible to
the users.

Bug: 189250370
Test: atest CtsCompanionDeviceManagerCoreTestCases
      atest CtsCompanionDeviceManagerUiAutomationTestCases
      atest CtsOsTestCases:CompanionDeviceManagerTest
Change-Id: Ib7fb08b0d800c62a9ee708ddd52cd174de1829d9
Merged-In: Ib7fb08b0d800c62a9ee708ddd52cd174de1829d9
2022-06-07 22:38:33 +00:00
Antony Sargent
6bd3385f2d Merge "Prevent deadlocks during VirtualDisplay creation" into tm-dev am: fc6eb70e0e am: e81140f065
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/18246032

Change-Id: I6d3c6ed0afba23492d3c9481777156be6e3872d0
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-05-30 00:58:35 +00:00
Antony Sargent
725dad7d71 Prevent deadlocks during VirtualDisplay creation
When creating a VirtualDisplay for a VirtualDevice, we need to do some
extra work like setting up for input injection, creating a
DisplayWindowPolicyController, and grabbing a wakelock to keep the
display awake. Some parts of this extra work end up calling back into
the DisplayManagerService from another thread, but since we're already
holding the mSyncRoot lock we sometimes get into situations where
those threads get blocked trying to acquire mSyncRoot, while holding a
lock that another thread ends up needing like the global window
manager one, so we get deadlock.

The fix in this CL is to break up the extra work the
VirtualDeviceManagerService needs to do into two parts: one part that
happens before the VirtualDisplay is created, and one part
after. Neither of these needs mSyncRoot to be held.

Fixes: 230544802
Test: atest CreateVirtualDisplayTest
Change-Id: I6a6e03f816567579510b3f1ef0705375549a3c88
2022-05-29 11:18:36 -07:00
Yuanjia Hsu
15a4ed366d Merge "Add OWNER to Virtual Device Manager" into tm-dev am: b1dd0c9e04 am: 3227ee09bc
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/18178883

Change-Id: I44f59b7650ea58231aa4a9e708140c530577442b
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-05-12 14:52:45 +00:00
yuanjiahsu
36a660756e Add OWNER to Virtual Device Manager
Test: presubmit
Change-Id: I4a8a2b45835b7838ab41ae6867dc230471eb5952
2022-05-06 02:41:50 +00:00
Guojing Yuan
3c250d9d63 [CDM perm sync] Backup and restore permissions
Main changes:
1. Backup/restore permissions into/from CompanionMessage. ~95% of the
B+R code is copied from PermissionController and minimal changes have
been made to accomodate the CDM perm sync case. The main logical changes are
near the commented blocks in the files.
2. Message pagination

Bug: 228228540

Test: Manually tested on CDM test app, checked the output proto bytes.
Restore hasn't been tested, will test when the test app is done.

Change-Id: I21cdb6106b4237b72ea798ba3f206db5ee136916
2022-05-04 21:13:33 +00:00
Guojing Yuan
2831bdd0f0 [CDM perm sync] Update user consent text
BUG: 222121838

Test: manually tested user consent dialog.
Change-Id: I128f48d5902f34ad757496b076243ee3e5d812f8
2022-04-05 21:28:23 +00:00
TreeHugger Robot
c8d997df31 Merge "Add launch complete status to launchPendingIntent" into tm-dev am: 3ece298e8b
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/17039962

Change-Id: Ia389457e357da80503d314d67d7618bf9384bb58
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-03-30 22:57:53 +00:00
TreeHugger Robot
3ece298e8b Merge "Add launch complete status to launchPendingIntent" into tm-dev 2022-03-30 22:47:56 +00:00
Yuanjia Hsu
994d8893a1 Merge "Don't register playback/recording change if caller doesn't care it" into tm-dev am: 9270d9fd53
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/17321718

Change-Id: I17239b07c09c4242bbc8a75132a63ac99e455ba0
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-03-30 22:04:55 +00:00
Guojing Yuan
89460fbdd3 Merge "[CDM perm sync] Add CDM APIs for permission sync" 2022-03-30 17:22:49 +00:00
yuanjiahsu
ad1bf17965 Don't register playback/recording change if caller doesn't care it
When calling VirtualDeviceManager#createVirtualAudioDevice(), if the
caller pass null AudioConfigurationChangeCallback parameter, it means
the caller doesn't care the audio playback/recording change in virtual
display, and we should not register it with AudioManager for
optimization.

Bug: 218528439
Test: atest CtsVirtualDevicesTestCases
Change-Id: I00120f2506f593100ef8c523a4f6addffe46597b
2022-03-30 04:10:17 +00:00
Guojing Yuan
8139e9792a [CDM perm sync] Add CDM APIs for permission sync
Design doc: go/cdm-perm-sync

There are 3 parts of the APIs:
1. Data transfer APIs (onMessageDispatchedFromSystem/dispatchMessageToSystem) - For communication between the companion app and CDM. Previously been reviewed: ag/15741895, ag/15899622
2. Building user consent dialog
   intent (buildPermissionTransferConfirmationIntent) for system data transfer. Previously been reviewed: ag/16422340
3. Trigger API for the actual system data transfer (startSystemDataTranfser) - It allows apps to trigger
   system data transfer when the comms channel between the apps on two
   devices is established and ready to communicate.

Bug: 204593788

Test: manually tested user consent dialog via the CDM test app.
Change-Id: Id7bf2628f75b35dbb546781524f1a968b0ac27a2
2022-03-30 00:43:15 +00:00
Maurice Lam
5cecf5331a Add launch complete status to launchPendingIntent
Instead of separate onLaunchSuccess and onLaunchFailure methods, combine
them into onLaunchComplete(int status), which can either be SUCCESS or
indicate the reason for failure.

Bug: 219985243
Test: atest CtsVirtualDevicesTestCases
Change-Id: I822c189b4bfc49ce936f072ff6e06f504c8eb80d
2022-03-28 23:29:52 -07:00
TreeHugger Robot
fb6b8b6494 Merge "Don't send callback with null topActivity" into tm-dev am: 78e9029df3
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/17130583

Change-Id: I3314424ac68e0f3c167bd843a447f2ba8f92df64
Signed-off-by: Automerger Merge Worker
2022-03-24 21:26:21 +00:00
yuanjiahsu
ab63d0671c Don't send callback with null topActivity
The topActivity defined in ActivityListener#onTopActivityChanged is @NonNull, so GenericWindowPolicyController should not send the callback when topActivity is null.

Bug: 222771130
Test: manual testing
Change-Id: I227d1d83e0e191975ab45b110909938022bb1d0c
2022-03-24 16:39:58 +00:00
Shaun Corkran
a96ed781bc Merge "Add CrossTaskNavigations API to restrict navigation from current task" into tm-dev am: a4889a2180
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/17161301

Change-Id: I4728b9bacfef7b331d0db3e47158df454e2a708b
2022-03-24 00:44:33 +00:00
Shaun Corkran
a4889a2180 Merge "Add CrossTaskNavigations API to restrict navigation from current task" into tm-dev 2022-03-23 17:57:37 +00:00
Evan Chen
4c8c621772 Merge "Add a new association request failure code" into tm-dev am: 3b7b98946a
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/17211807

Change-Id: Icda0a81216da21c70e3b30a3683dff0c05ed203c
2022-03-21 21:54:56 +00:00
Evan Chen
8fedd4796e Add a new association request failure code
1. Add the new association request failure codes
   RESULT_USER_REJECTED, RESULT_DISCOVERY_TIMEOUT
   RESULT_INTERNAL_ERROR

2. Add the new association failure reason:
   REASON_CANCELED, REASON_DISCOVERY_TIMEOUT,
   REASON_USER_REJECTED

The change helps to identify user's action that
the association request explicitly declined by the user

Test: atest CtsCompanionDeviceManagerCoreTestCases
      atest CtsCompanionDeviceManagerUiAutomationTestCases
      atest CtsOsTestCases:CompanionDeviceManagerTest

Bug: 223706865
Fix: 224559263
Change-Id: I50fe40780a977c5bbe0aac5b67e1925ea75058bb
2022-03-21 17:20:06 +00:00