Merge "Generate ACTION_CANCEL event when screen turned off by proximity sensor." into rvc-dev

This commit is contained in:
TreeHugger Robot
2020-05-28 18:35:08 +00:00
committed by Android (Google) Code Review
4 changed files with 51 additions and 18 deletions

View File

@@ -49,6 +49,9 @@ public final class DisplayViewport {
// True if this viewport is valid.
public boolean valid;
// True if this viewport is active.
public boolean isActive;
// The logical display id.
public int displayId;
@@ -79,6 +82,7 @@ public final class DisplayViewport {
public void copyFrom(DisplayViewport viewport) {
valid = viewport.valid;
isActive = viewport.isActive;
displayId = viewport.displayId;
orientation = viewport.orientation;
logicalFrame.set(viewport.logicalFrame);
@@ -111,6 +115,7 @@ public final class DisplayViewport {
DisplayViewport other = (DisplayViewport) o;
return valid == other.valid
&& isActive == other.isActive
&& displayId == other.displayId
&& orientation == other.orientation
&& logicalFrame.equals(other.logicalFrame)
@@ -127,6 +132,7 @@ public final class DisplayViewport {
final int prime = 31;
int result = 1;
result += prime * result + (valid ? 1 : 0);
result += prime * result + (isActive ? 1 : 0);
result += prime * result + displayId;
result += prime * result + orientation;
result += prime * result + logicalFrame.hashCode();
@@ -147,6 +153,7 @@ public final class DisplayViewport {
final Integer port = physicalPort == null ? null : Byte.toUnsignedInt(physicalPort);
return "DisplayViewport{type=" + typeToString(type)
+ ", valid=" + valid
+ ", isActive=" + isActive
+ ", displayId=" + displayId
+ ", uniqueId='" + uniqueId + "'"
+ ", physicalPort=" + port

View File

@@ -34,6 +34,7 @@ static struct {
jclass clazz;
jfieldID displayId;
jfieldID isActive;
jfieldID orientation;
jfieldID logicalFrame;
jfieldID physicalFrame;
@@ -59,6 +60,7 @@ status_t android_hardware_display_DisplayViewport_toNative(JNIEnv* env, jobject
static const jmethodID byteValue = env->GetMethodID(byteClass, "byteValue", "()B");
viewport->displayId = env->GetIntField(viewportObj, gDisplayViewportClassInfo.displayId);
viewport->isActive = env->GetBooleanField(viewportObj, gDisplayViewportClassInfo.isActive);
viewport->orientation = env->GetIntField(viewportObj, gDisplayViewportClassInfo.orientation);
viewport->deviceWidth = env->GetIntField(viewportObj, gDisplayViewportClassInfo.deviceWidth);
viewport->deviceHeight = env->GetIntField(viewportObj, gDisplayViewportClassInfo.deviceHeight);
@@ -104,6 +106,9 @@ int register_android_hardware_display_DisplayViewport(JNIEnv* env) {
gDisplayViewportClassInfo.displayId = GetFieldIDOrDie(env,
gDisplayViewportClassInfo.clazz, "displayId", "I");
gDisplayViewportClassInfo.isActive =
GetFieldIDOrDie(env, gDisplayViewportClassInfo.clazz, "isActive", "Z");
gDisplayViewportClassInfo.orientation = GetFieldIDOrDie(env,
gDisplayViewportClassInfo.clazz, "orientation", "I");

View File

@@ -111,6 +111,7 @@ import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.CopyOnWriteArrayList;
/**
@@ -971,6 +972,18 @@ public final class DisplayManagerService extends SystemService {
if (diff == DisplayDeviceInfo.DIFF_STATE) {
Slog.i(TAG, "Display device changed state: \"" + info.name
+ "\", " + Display.stateToString(info.state));
final Optional<Integer> viewportType = getViewportType(info);
if (viewportType.isPresent()) {
for (DisplayViewport d : mViewports) {
if (d.type == viewportType.get() && info.uniqueId.equals(d.uniqueId)) {
// Update display view port power state
d.isActive = Display.isActiveState(info.state);
}
}
if (mInputManagerInternal != null) {
mHandler.sendEmptyMessage(MSG_UPDATE_VIEWPORT);
}
}
} else if (diff != 0) {
Slog.i(TAG, "Display device changed: " + info);
}
@@ -1507,6 +1520,23 @@ public final class DisplayManagerService extends SystemService {
mViewports.clear();
}
private Optional<Integer> getViewportType(DisplayDeviceInfo info) {
// Get the corresponding viewport type.
if ((info.flags & DisplayDeviceInfo.FLAG_DEFAULT_DISPLAY) != 0) {
return Optional.of(VIEWPORT_INTERNAL);
} else if (info.touch == DisplayDeviceInfo.TOUCH_EXTERNAL) {
return Optional.of(VIEWPORT_EXTERNAL);
} else if (info.touch == DisplayDeviceInfo.TOUCH_VIRTUAL
&& !TextUtils.isEmpty(info.uniqueId)) {
return Optional.of(VIEWPORT_VIRTUAL);
} else {
if (DEBUG) {
Slog.i(TAG, "Display " + info + " does not support input device matching.");
}
}
return Optional.empty();
}
private void configureDisplayLocked(SurfaceControl.Transaction t, DisplayDevice device) {
final DisplayDeviceInfo info = device.getDisplayDeviceInfoLocked();
final boolean ownContent = (info.flags & DisplayDeviceInfo.FLAG_OWN_CONTENT_ONLY) != 0;
@@ -1533,21 +1563,10 @@ public final class DisplayManagerService extends SystemService {
return;
}
display.configureDisplayLocked(t, device, info.state == Display.STATE_OFF);
final int viewportType;
// Update the corresponding viewport.
if ((info.flags & DisplayDeviceInfo.FLAG_DEFAULT_DISPLAY) != 0) {
viewportType = VIEWPORT_INTERNAL;
} else if (info.touch == DisplayDeviceInfo.TOUCH_EXTERNAL) {
viewportType = VIEWPORT_EXTERNAL;
} else if (info.touch == DisplayDeviceInfo.TOUCH_VIRTUAL
&& !TextUtils.isEmpty(info.uniqueId)) {
viewportType = VIEWPORT_VIRTUAL;
} else {
Slog.i(TAG, "Display " + info + " does not support input device matching.");
return;
final Optional<Integer> viewportType = getViewportType(info);
if (viewportType.isPresent()) {
populateViewportLocked(viewportType.get(), display.getDisplayIdLocked(), device, info);
}
populateViewportLocked(viewportType, display.getDisplayIdLocked(), device, info.uniqueId);
}
/**
@@ -1587,12 +1606,13 @@ public final class DisplayManagerService extends SystemService {
return viewport;
}
private void populateViewportLocked(int viewportType,
int displayId, DisplayDevice device, String uniqueId) {
final DisplayViewport viewport = getViewportLocked(viewportType, uniqueId);
private void populateViewportLocked(int viewportType, int displayId, DisplayDevice device,
DisplayDeviceInfo info) {
final DisplayViewport viewport = getViewportLocked(viewportType, info.uniqueId);
device.populateViewportLocked(viewport);
viewport.valid = true;
viewport.displayId = displayId;
viewport.isActive = Display.isActiveState(info.state);
}
private LogicalDisplay findLogicalDisplayForDeviceLocked(DisplayDevice device) {

View File

@@ -403,7 +403,8 @@ void NativeInputManager::setDisplayViewports(JNIEnv* env, jobjectArray viewportO
DisplayViewport viewport;
android_hardware_display_DisplayViewport_toNative(env, viewportObj, &viewport);
ALOGI("Viewport [%d] to add: %s", (int) i, viewport.uniqueId.c_str());
ALOGI("Viewport [%d] to add: %s, isActive: %s", (int)i, viewport.uniqueId.c_str(),
toString(viewport.isActive));
viewports.push_back(viewport);
env->DeleteLocalRef(viewportObj);