Merge "Have CameraServiceProxy listen directly to DeviceStateManager." into sc-v2-dev

This commit is contained in:
Darryl Johnson
2021-06-23 18:46:24 +00:00
committed by Android (Google) Code Review
2 changed files with 21 additions and 28 deletions

View File

@@ -35,11 +35,14 @@ import android.hardware.CameraStreamStats;
import android.hardware.ICameraService;
import android.hardware.ICameraServiceProxy;
import android.hardware.camera2.CameraMetadata;
import android.hardware.devicestate.DeviceStateManager;
import android.hardware.devicestate.DeviceStateManager.FoldStateListener;
import android.hardware.display.DisplayManager;
import android.media.AudioManager;
import android.nfc.INfcAdapter;
import android.os.Binder;
import android.os.Handler;
import android.os.HandlerExecutor;
import android.os.IBinder;
import android.os.Message;
import android.os.Process;
@@ -57,8 +60,8 @@ import android.view.IDisplayWindowListener;
import android.view.Surface;
import android.view.WindowManagerGlobal;
import com.android.internal.annotations.GuardedBy;
import com.android.framework.protobuf.nano.MessageNano;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.util.FrameworkStatsLog;
import com.android.server.LocalServices;
import com.android.server.ServiceThread;
@@ -447,6 +450,8 @@ public class CameraServiceProxy extends SystemService
}
};
private final FoldStateListener mFoldStateListener;
public CameraServiceProxy(Context context) {
super(context);
mContext = context;
@@ -459,6 +464,14 @@ public class CameraServiceProxy extends SystemService
// Don't keep any extra logging threads if not needed
mLogWriterService.setKeepAliveTime(1, TimeUnit.SECONDS);
mLogWriterService.allowCoreThreadTimeOut(true);
mFoldStateListener = new FoldStateListener(mContext, folded -> {
if (folded) {
setDeviceStateFlags(ICameraService.DEVICE_STATE_FOLDED);
} else {
clearDeviceStateFlags(ICameraService.DEVICE_STATE_FOLDED);
}
});
}
/**
@@ -471,7 +484,7 @@ public class CameraServiceProxy extends SystemService
*
* @see #clearDeviceStateFlags(int)
*/
public void setDeviceStateFlags(@DeviceStateFlags int deviceStateFlags) {
private void setDeviceStateFlags(@DeviceStateFlags int deviceStateFlags) {
synchronized (mLock) {
mHandler.removeMessages(MSG_NOTIFY_DEVICE_STATE);
mDeviceState |= deviceStateFlags;
@@ -491,7 +504,7 @@ public class CameraServiceProxy extends SystemService
*
* @see #setDeviceStateFlags(int)
*/
public void clearDeviceStateFlags(@DeviceStateFlags int deviceStateFlags) {
private void clearDeviceStateFlags(@DeviceStateFlags int deviceStateFlags) {
synchronized (mLock) {
mHandler.removeMessages(MSG_NOTIFY_DEVICE_STATE);
mDeviceState &= ~deviceStateFlags;
@@ -555,6 +568,9 @@ public class CameraServiceProxy extends SystemService
} catch (RemoteException e) {
Log.e(TAG, "Failed to register display window listener!");
}
mContext.getSystemService(DeviceStateManager.class)
.registerCallback(new HandlerExecutor(mHandler), mFoldStateListener);
}
}

View File

@@ -16,10 +16,8 @@
package com.android.server.policy;
import android.annotation.Nullable;
import android.content.Context;
import android.graphics.Rect;
import android.hardware.ICameraService;
import android.hardware.devicestate.DeviceStateManager;
import android.hardware.devicestate.DeviceStateManager.FoldStateListener;
import android.hardware.display.DisplayManagerInternal;
@@ -27,13 +25,11 @@ import android.os.Handler;
import android.os.HandlerExecutor;
import android.os.RemoteCallbackList;
import android.os.RemoteException;
import android.util.Slog;
import android.view.DisplayInfo;
import android.view.IDisplayFoldListener;
import com.android.server.DisplayThread;
import com.android.server.LocalServices;
import com.android.server.camera.CameraServiceProxy;
import com.android.server.wm.WindowManagerInternal;
/**
@@ -41,13 +37,8 @@ import com.android.server.wm.WindowManagerInternal;
* TODO(b/126160895): Move DisplayFoldController from PhoneWindowManager to DisplayPolicy.
*/
class DisplayFoldController {
private static final String TAG = "DisplayFoldController";
private final WindowManagerInternal mWindowManagerInternal;
private final DisplayManagerInternal mDisplayManagerInternal;
// Camera service proxy can be disabled through a config.
@Nullable
private final CameraServiceProxy mCameraServiceProxy;
private final int mDisplayId;
private final Handler mHandler;
@@ -64,12 +55,10 @@ class DisplayFoldController {
DisplayFoldController(
Context context, WindowManagerInternal windowManagerInternal,
DisplayManagerInternal displayManagerInternal,
@Nullable CameraServiceProxy cameraServiceProxy, int displayId, Rect foldedArea,
DisplayManagerInternal displayManagerInternal, int displayId, Rect foldedArea,
Handler handler) {
mWindowManagerInternal = windowManagerInternal;
mDisplayManagerInternal = displayManagerInternal;
mCameraServiceProxy = cameraServiceProxy;
mDisplayId = displayId;
mFoldedArea = new Rect(foldedArea);
mHandler = handler;
@@ -124,16 +113,6 @@ class DisplayFoldController {
}
}
if (mCameraServiceProxy != null) {
if (folded) {
mCameraServiceProxy.setDeviceStateFlags(ICameraService.DEVICE_STATE_FOLDED);
} else {
mCameraServiceProxy.clearDeviceStateFlags(ICameraService.DEVICE_STATE_FOLDED);
}
} else {
Slog.w(TAG, "Camera service unavailable to toggle folded state.");
}
mDurationLogger.setDeviceFolded(folded);
mDurationLogger.logFocusedAppWithFoldState(folded, mFocusedApp);
mFolded = folded;
@@ -188,8 +167,6 @@ class DisplayFoldController {
LocalServices.getService(WindowManagerInternal.class);
final DisplayManagerInternal displayService =
LocalServices.getService(DisplayManagerInternal.class);
final CameraServiceProxy cameraServiceProxy =
LocalServices.getService(CameraServiceProxy.class);
final String configFoldedArea = context.getResources().getString(
com.android.internal.R.string.config_foldedArea);
@@ -201,6 +178,6 @@ class DisplayFoldController {
}
return new DisplayFoldController(context, windowManagerService, displayService,
cameraServiceProxy, displayId, foldedArea, DisplayThread.getHandler());
displayId, foldedArea, DisplayThread.getHandler());
}
}