diff options
| author | 2021-08-09 16:02:48 +0200 | |
|---|---|---|
| committer | 2021-12-15 21:27:39 +0100 | |
| commit | e66a2d5f888e7139c1dc865dc7c29ada3b2ca703 (patch) | |
| tree | 5cea70a8fcf6e50de888c8a26c8842629defeda3 | |
| parent | 0b77c138ad6c589409fd49141b53d944004247da (diff) | |
Notify CameraService on USB host events
For handling external (USB) cameras when using
lazy camera HALs.
Test: atest cameraservice_test
Bug: 191248460
Change-Id: I65b683e449577f576dc210a768ca7756394742a3
| -rw-r--r-- | services/core/java/com/android/server/camera/CameraServiceProxy.java | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/services/core/java/com/android/server/camera/CameraServiceProxy.java b/services/core/java/com/android/server/camera/CameraServiceProxy.java index 3120dc58eebd..272d003566c5 100644 --- a/services/core/java/com/android/server/camera/CameraServiceProxy.java +++ b/services/core/java/com/android/server/camera/CameraServiceProxy.java @@ -46,6 +46,8 @@ import android.hardware.camera2.CaptureRequest; import android.hardware.devicestate.DeviceStateManager; import android.hardware.devicestate.DeviceStateManager.FoldStateListener; import android.hardware.display.DisplayManager; +import android.hardware.usb.UsbDevice; +import android.hardware.usb.UsbManager; import android.media.AudioManager; import android.nfc.INfcAdapter; import android.os.Binder; @@ -335,6 +337,16 @@ public class CameraServiceProxy extends SystemService switchUserLocked(mLastUser); } break; + case UsbManager.ACTION_USB_DEVICE_ATTACHED: + case UsbManager.ACTION_USB_DEVICE_DETACHED: + synchronized (mLock) { + UsbDevice device = intent.getParcelableExtra(UsbManager.EXTRA_DEVICE); + if (device != null) { + notifyUsbDeviceHotplugLocked(device, + action.equals(UsbManager.ACTION_USB_DEVICE_ATTACHED)); + } + } + break; default: break; // do nothing } @@ -645,6 +657,8 @@ public class CameraServiceProxy extends SystemService filter.addAction(Intent.ACTION_USER_INFO_CHANGED); filter.addAction(Intent.ACTION_MANAGED_PROFILE_ADDED); filter.addAction(Intent.ACTION_MANAGED_PROFILE_REMOVED); + filter.addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED); + filter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED); mContext.registerReceiver(mIntentReceiver, filter); publishBinderService(CAMERA_SERVICE_PROXY_BINDER_NAME, mCameraServiceProxy); @@ -961,6 +975,32 @@ public class CameraServiceProxy extends SystemService return true; } + private boolean notifyUsbDeviceHotplugLocked(@NonNull UsbDevice device, boolean attached) { + // Only handle external USB camera devices + if (device.getHasVideoCapture()) { + // Forward the usb hotplug event to the native camera service running in the + // cameraserver + // process. + ICameraService cameraService = getCameraServiceRawLocked(); + if (cameraService == null) { + Slog.w(TAG, "Could not notify cameraserver, camera service not available."); + return false; + } + + try { + int eventType = attached ? ICameraService.EVENT_USB_DEVICE_ATTACHED + : ICameraService.EVENT_USB_DEVICE_DETACHED; + mCameraServiceRaw.notifySystemEvent(eventType, new int[]{device.getDeviceId()}); + } catch (RemoteException e) { + Slog.w(TAG, "Could not notify cameraserver, remote exception: " + e); + // Not much we can do if camera service is dead. + return false; + } + return true; + } + return false; + } + private void updateActivityCount(CameraSessionStats cameraState) { String cameraId = cameraState.getCameraId(); int newCameraState = cameraState.getNewCameraState(); |