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
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user