Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit de151355 authored by Zhengping Jiang's avatar Zhengping Jiang Committed by Android (Google) Code Review
Browse files

Merge "Check Bluetooth HID connection status changed before wake up" into main

parents eae8a1ac 9f4aa9cc
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -261,3 +261,10 @@ flag {
  description: "Enables new keyboard shortcuts to adjust keyboard backlight"
  bug: "401626732"
}

flag {
    name: "bluetooth_wakeup_state_check"
    namespace: "desktop_pnp"
    description: "Check Bluetooth HID profile connection state is changed before waking up the device."
    bug: "440645135"
}
+17 −2
Original line number Diff line number Diff line
@@ -91,6 +91,7 @@ import static android.view.WindowManagerGlobal.ADD_OKAY;
import static android.view.WindowManagerGlobal.ADD_PERMISSION_DENIED;
import static android.view.contentprotection.flags.Flags.createAccessibilityOverlayAppOpEnabled;

import static com.android.hardware.input.Flags.bluetoothWakeupStateCheck;
import static com.android.hardware.input.Flags.enableNew25q2Keycodes;
import static com.android.internal.policy.IKeyguardService.SCREEN_TURNING_ON_REASON_DISPLAY_SWITCH;
import static com.android.internal.policy.IKeyguardService.SCREEN_TURNING_ON_REASON_UNKNOWN;
@@ -5254,10 +5255,24 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    BroadcastReceiver mBluetoothHidReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            if (bluetoothWakeupStateCheck() && !SystemProperties.getBoolean(
                    "bluetooth.power.suspend.hid_wake_up.enabled", false)) {
                Slog.d(TAG, "Bluetooth HID wake up disabled.");
                return;
            }
            if (ACTION_CONNECTION_STATE_CHANGED.equals(intent.getAction())) {
                Integer state = (Integer) intent.getExtra(BluetoothProfile.EXTRA_STATE);
                Integer newState = (Integer) intent.getExtra(BluetoothProfile.EXTRA_STATE);
                Integer prevState = (Integer) intent.getExtra(
                        BluetoothProfile.EXTRA_PREVIOUS_STATE);
                final boolean interactive = mDefaultDisplayPolicy.isAwake();
                if (state != null && !interactive && state == STATE_CONNECTED) {
                if (bluetoothWakeupStateCheck()
                        && (newState == null || prevState == null || prevState.equals(newState))) {
                    if (DEBUG_WAKEUP) {
                        Slog.w(TAG, "Bluetooth connection state does not change: " + intent);
                    }
                    return;
                }
                if (newState != null && !interactive && newState.equals(STATE_CONNECTED)) {
                    mWindowWakeUpPolicy.wakeUpFromBluetooth();
                }
            }
+19 −0
Original line number Diff line number Diff line
@@ -27,10 +27,14 @@ import static android.view.WindowManagerGlobal.ADD_OKAY;

import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;

import static com.android.internal.policy.IKeyguardService.SCREEN_TURNING_ON_REASON_UNKNOWN;
import static com.android.internal.policy.IKeyguardService.SCREEN_TURNING_ON_REASON_DISPLAY_SWITCH;
import static com.android.hardware.input.Flags.FLAG_BLUETOOTH_WAKEUP_STATE_CHECK;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.doAnswer;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.doNothing;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.mock;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.mockitoSession;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.never;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.reset;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.spy;
@@ -70,6 +74,7 @@ import android.os.Bundle;
import android.os.IBinder;
import android.os.PowerManager;
import android.os.PowerManagerInternal;
import android.os.SystemProperties;
import android.platform.test.annotations.DisableFlags;
import android.platform.test.annotations.EnableFlags;
import android.platform.test.annotations.Presubmit;
@@ -84,6 +89,7 @@ import android.view.DisplayInfo;

import androidx.test.filters.SmallTest;

import com.android.dx.mockito.inline.extended.StaticMockitoSession;
import com.android.internal.util.test.LocalServiceKeeperRule;
import com.android.internal.widget.LockPatternUtils;
import com.android.server.SystemServiceManager;
@@ -106,6 +112,7 @@ import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.quality.Strictness;

import java.util.List;

@@ -172,10 +179,16 @@ public class PhoneWindowManagerTests {

    private static final int INTERCEPT_SYSTEM_KEY_NOT_CONSUMED_DELAY = 0;

    private StaticMockitoSession mMockitoSession;

    @Before
    public void setUp() {
        MockitoAnnotations.initMocks(this);
        when(mContext.getSystemService(Context.POWER_SERVICE)).thenReturn(mPowerManager);
        mMockitoSession = mockitoSession()
                .mockStatic(SystemProperties.class)
                .strictness(Strictness.LENIENT)
                .startMocking();

        mOffsettableClock = new OffsettableClock.Stopped();

@@ -211,6 +224,7 @@ public class PhoneWindowManagerTests {
    public void tearDown() {
        reset(ActivityManager.getService());
        reset(mContext);
        mMockitoSession.finishMocking();
    }

    @Test
@@ -601,12 +615,17 @@ public class PhoneWindowManagerTests {
    }

    @Test
    @EnableFlags(FLAG_BLUETOOTH_WAKEUP_STATE_CHECK)
    public void testBluetoothHidConnectionBroadcastCanWakeup() {
        when(mContext.getPackageManager()).thenReturn(mPackageManager);
        when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_PC)).thenReturn(true);
        doReturn(true).when(() -> SystemProperties.getBoolean(
                                eq("bluetooth.power.suspend.hid_wake_up.enabled"), eq(false)));

        initNonSpyPhoneWindowManager();

        final Intent intent = new Intent(ACTION_CONNECTION_STATE_CHANGED);
        intent.putExtra(BluetoothProfile.EXTRA_PREVIOUS_STATE, BluetoothProfile.STATE_DISCONNECTED);
        intent.putExtra(BluetoothProfile.EXTRA_STATE, BluetoothProfile.STATE_CONNECTED);
        ArgumentCaptor<BroadcastReceiver> captor = ArgumentCaptor.forClass(BroadcastReceiver.class);
        verify(mContext).registerReceiver(captor.capture(), argThat(intentFilter ->