Skip to content

Commit

Permalink
Merge cherrypicks of [9428111, 9427928, 9427929, 9428294, 9428403, 94…
Browse files Browse the repository at this point in the history
…28295, 9428355, 9428112, 9428113, 9428356, 9428152, 9428153, 9428154, 9427868, 9428357, 9428358, 9427373] into qt-release

Change-Id: Id1174c3d6d93c6b57f16a6091f42f13f5ca4ddd1
  • Loading branch information
android-build-team Robot committed Sep 20, 2019
2 parents 74f4c0e + d096899 commit 37a24f5
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 4 deletions.
57 changes: 57 additions & 0 deletions data/keyboards/Vendor_045e_Product_02dd.kl
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Copyright (C) 2019 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

#
# XBox One Controller - Model 1697 - USB
#

# Mapping according to https://developer.android.com/training/game-controllers/controller-input.html

key 304 BUTTON_A
key 305 BUTTON_B
key 307 BUTTON_X
key 308 BUTTON_Y

key 310 BUTTON_L1
key 311 BUTTON_R1

# Triggers.
axis 0x02 LTRIGGER
axis 0x05 RTRIGGER

# Left and right stick.
# The reported value for flat is 128 out of a range from -32767 to 32768, which is absurd.
# This confuses applications that rely on the flat value because the joystick actually
# settles in a flat range of +/- 4096 or so.
axis 0x00 X flat 4096
axis 0x01 Y flat 4096
axis 0x03 Z flat 4096
axis 0x04 RZ flat 4096

key 317 BUTTON_THUMBL
key 318 BUTTON_THUMBR

# Hat.
axis 0x10 HAT_X
axis 0x11 HAT_Y


# Mapping according to https://www.kernel.org/doc/Documentation/input/gamepad.txt
# Two overlapping rectangles
key 314 BUTTON_SELECT
# Hamburger - 3 parallel lines
key 315 BUTTON_START

# Xbox key
key 316 BUTTON_MODE
7 changes: 6 additions & 1 deletion data/keyboards/Vendor_045e_Product_02fd.kl
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,10 @@ key 158 BUTTON_SELECT
# Hamburger - 3 parallel lines
key 315 BUTTON_START

# Xbox key
# There are at least two versions of firmware out for this controller.
# They send different linux keys for the "Xbox" button.
# Xbox key (original firmware)
key 172 BUTTON_MODE

# Xbox key (newer firmware)
key 316 BUTTON_MODE
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public void systemReady(Context context) {

context.getContentResolver().registerContentObserver(Settings.System.getUriFor(
Settings.System.ADAPTIVE_SLEEP),
false, new ContentObserver(new Handler()) {
false, new ContentObserver(new Handler(context.getMainLooper())) {
@Override
public void onChange(boolean selfChange) {
updateEnabledFromSettings(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2724,6 +2724,14 @@ private boolean needDisplaySuspendBlockerLocked() {
return true;
}
}

if (mDisplayPowerRequest.policy == DisplayPowerRequest.POLICY_DOZE
&& mDisplayPowerRequest.dozeScreenState == Display.STATE_ON) {
// Although we are in DOZE and would normally allow the device to suspend,
// the doze service has explicitly requested the display to remain in the ON
// state which means we should hold the display suspend blocker.
return true;
}
if (mScreenBrightnessBoostInProgress) {
return true;
}
Expand Down Expand Up @@ -4858,7 +4866,8 @@ private PowerManager.WakeData getLastWakeupInternal() {
}
}

private final class LocalService extends PowerManagerInternal {
@VisibleForTesting
final class LocalService extends PowerManagerInternal {
@Override
public void setScreenBrightnessOverrideFromWindowManager(int screenBrightness) {
if (screenBrightness < PowerManager.BRIGHTNESS_DEFAULT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@

import static com.google.common.truth.Truth.assertThat;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.argThat;
Expand Down Expand Up @@ -59,6 +62,7 @@
import android.os.SystemProperties;
import android.os.UserHandle;
import android.provider.Settings;
import android.view.Display;

import androidx.test.InstrumentationRegistry;

Expand Down Expand Up @@ -157,6 +161,10 @@ public void setUp() throws Exception {
mResourcesSpy = spy(mContextSpy.getResources());
when(mContextSpy.getResources()).thenReturn(mResourcesSpy);

when(mDisplayManagerInternalMock.requestPowerState(any(), anyBoolean())).thenReturn(true);
}

private PowerManagerService createService() {
mService = new PowerManagerService(mContextSpy, new Injector() {
@Override
Notifier createNotifier(Looper looper, Context context, IBatteryStats batteryStats,
Expand All @@ -166,7 +174,7 @@ Notifier createNotifier(Looper looper, Context context, IBatteryStats batterySta

@Override
SuspendBlocker createSuspendBlocker(PowerManagerService service, String name) {
return mock(SuspendBlocker.class);
return super.createSuspendBlocker(service, name);
}

@Override
Expand All @@ -191,6 +199,7 @@ AmbientDisplayConfiguration createAmbientDisplayConfiguration(Context context) {
return mAmbientDisplayConfigurationMock;
}
});
return mService;
}

@After
Expand Down Expand Up @@ -262,6 +271,7 @@ private void setPluggedIn(boolean isPluggedIn) {

@Test
public void testUpdatePowerScreenPolicy_UpdateDisplayPowerRequest() {
createService();
mService.updatePowerRequestFromBatterySaverPolicy(mDisplayPowerRequest);
assertThat(mDisplayPowerRequest.lowPowerMode).isEqualTo(BATTERY_SAVER_ENABLED);
assertThat(mDisplayPowerRequest.screenLowPowerBrightnessFactor)
Expand All @@ -270,6 +280,7 @@ public void testUpdatePowerScreenPolicy_UpdateDisplayPowerRequest() {

@Test
public void testGetLastShutdownReasonInternal() {
createService();
SystemProperties.set(TEST_LAST_REBOOT_PROPERTY, "shutdown,thermal");
int reason = mService.getLastShutdownReasonInternal(TEST_LAST_REBOOT_PROPERTY);
SystemProperties.set(TEST_LAST_REBOOT_PROPERTY, "");
Expand All @@ -278,6 +289,7 @@ public void testGetLastShutdownReasonInternal() {

@Test
public void testGetDesiredScreenPolicy_WithVR() throws Exception {
createService();
// Brighten up the screen
mService.setWakefulnessLocked(WAKEFULNESS_AWAKE, PowerManager.WAKE_REASON_UNKNOWN, 0);
assertThat(mService.getDesiredScreenPolicyLocked()).isEqualTo(
Expand Down Expand Up @@ -307,11 +319,13 @@ public void testGetDesiredScreenPolicy_WithVR() throws Exception {

@Test
public void testWakefulnessAwake_InitialValue() throws Exception {
createService();
assertThat(mService.getWakefulness()).isEqualTo(WAKEFULNESS_AWAKE);
}

@Test
public void testWakefulnessSleep_NoDozeSleepFlag() throws Exception {
createService();
// Start with AWAKE state
startSystem();
assertThat(mService.getWakefulness()).isEqualTo(WAKEFULNESS_AWAKE);
Expand All @@ -324,6 +338,7 @@ public void testWakefulnessSleep_NoDozeSleepFlag() throws Exception {

@Test
public void testWakefulnessAwake_AcquireCausesWakeup() throws Exception {
createService();
startSystem();
forceSleep();

Expand Down Expand Up @@ -355,6 +370,7 @@ public void testWakefulnessAwake_AcquireCausesWakeup() throws Exception {

@Test
public void testWakefulnessAwake_IPowerManagerWakeUp() throws Exception {
createService();
startSystem();
forceSleep();
mService.getBinderServiceInstance().wakeUp(SystemClock.uptimeMillis(),
Expand All @@ -369,6 +385,8 @@ public void testWakefulnessAwake_IPowerManagerWakeUp() throws Exception {
@Test
public void testWakefulnessAwake_ShouldWakeUpWhenPluggedIn() throws Exception {
boolean powerState;

createService();
startSystem();
forceSleep();

Expand Down Expand Up @@ -444,6 +462,7 @@ public void testWakefulnessAwake_ShouldWakeUpWhenPluggedIn() throws Exception {

@Test
public void testWakefulnessDoze_goToSleep() throws Exception {
createService();
// Start with AWAKE state
startSystem();
assertThat(mService.getWakefulness()).isEqualTo(WAKEFULNESS_AWAKE);
Expand All @@ -457,6 +476,7 @@ public void testWakefulnessDoze_goToSleep() throws Exception {
@Test
public void testWasDeviceIdleFor_true() {
int interval = 1000;
createService();
mService.onUserActivity();
SystemClock.sleep(interval + 1 /* just a little more */);
assertThat(mService.wasDeviceIdleForInternal(interval)).isTrue();
Expand All @@ -465,12 +485,14 @@ public void testWasDeviceIdleFor_true() {
@Test
public void testWasDeviceIdleFor_false() {
int interval = 1000;
createService();
mService.onUserActivity();
assertThat(mService.wasDeviceIdleForInternal(interval)).isFalse();
}

@Test
public void testForceSuspend_putsDeviceToSleep() {
createService();
mService.systemReady(null);
mService.onBootPhase(SystemService.PHASE_BOOT_COMPLETED);

Expand All @@ -497,6 +519,8 @@ public void testForceSuspend_pakeLocksDisabled() {
final int flags = PowerManager.PARTIAL_WAKE_LOCK;
final String pkg = mContextSpy.getOpPackageName();

createService();

// Set up the Notification mock to keep track of the wakelocks that are currently
// active or disabled. We'll use this to verify that wakelocks are disabled when
// they should be.
Expand Down Expand Up @@ -541,7 +565,54 @@ public void testForceSuspend_pakeLocksDisabled() {

@Test
public void testForceSuspend_forceSuspendFailurePropogated() {
createService();
when(mNativeWrapperMock.nativeForceSuspend()).thenReturn(false);
assertThat(mService.getBinderServiceInstance().forceSuspend()).isFalse();
}

@Test
public void testSetDozeOverrideFromDreamManager_triggersSuspendBlocker() throws Exception {
final String suspendBlockerName = "PowerManagerService.Display";
final String tag = "acq_causes_wakeup";
final String packageName = "pkg.name";
final IBinder token = new Binder();

final boolean[] isAcquired = new boolean[1];
doAnswer(inv -> {
if (suspendBlockerName.equals(inv.getArguments()[0])) {
isAcquired[0] = false;
}
return null;
}).when(mNativeWrapperMock).nativeReleaseSuspendBlocker(any());

doAnswer(inv -> {
if (suspendBlockerName.equals(inv.getArguments()[0])) {
isAcquired[0] = true;
}
return null;
}).when(mNativeWrapperMock).nativeAcquireSuspendBlocker(any());

// Need to create the service after we stub the mocks for this test because some of the
// mocks are used during the constructor.
createService();

// Start with AWAKE state
startSystem();
assertThat(mService.getWakefulness()).isEqualTo(WAKEFULNESS_AWAKE);
assertTrue(isAcquired[0]);

// Take a nap and verify we no longer hold the blocker
int flags = PowerManager.DOZE_WAKE_LOCK;
mService.getBinderServiceInstance().acquireWakeLock(token, flags, tag, packageName,
null /* workSource */, null /* historyTag */);
mService.getBinderServiceInstance().goToSleep(SystemClock.uptimeMillis(),
PowerManager.GO_TO_SLEEP_REASON_APPLICATION, 0);
assertThat(mService.getWakefulness()).isEqualTo(WAKEFULNESS_DOZING);
assertFalse(isAcquired[0]);

// Override the display state by DreamManager and verify is reacquires the blocker.
mService.getLocalServiceInstance()
.setDozeOverrideFromDreamManager(Display.STATE_ON, PowerManager.BRIGHTNESS_DEFAULT);
assertTrue(isAcquired[0]);
}
}

0 comments on commit 37a24f5

Please sign in to comment.