Skip to content

Commit

Permalink
Remove KitKat-specific code from //services and //devices
Browse files Browse the repository at this point in the history
Bug: 1041930
Change-Id: Ie22490b7e1f6ec3e6ef49ddbf9af2f028021f6ac
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2298939
Reviewed-by: Reilly Grant <reillyg@chromium.org>
Commit-Queue: Andrew Grieve <agrieve@chromium.org>
Auto-Submit: Andrew Grieve <agrieve@chromium.org>
Cr-Commit-Position: refs/heads/master@{#788902}
  • Loading branch information
agrieve authored and Commit Bot committed Jul 16, 2020
1 parent 3427192 commit 9406e49
Show file tree
Hide file tree
Showing 13 changed files with 128 additions and 225 deletions.
74 changes: 35 additions & 39 deletions device/bluetooth/bluetooth_adapter_android_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// found in the LICENSE file.

#include "device/bluetooth/bluetooth_adapter_android.h"
#include "base/android/build_info.h"
#include "base/android/jni_string.h"
#include "base/bind.h"
#include "device/bluetooth/android/wrappers.h"
Expand All @@ -28,44 +27,41 @@ class BluetoothAdapterAndroidTest : public BluetoothTestAndroid {
};

TEST_F(BluetoothAdapterAndroidTest, ScanFilterTest) {
auto* build_info = base::android::BuildInfo::GetInstance();
if (build_info->sdk_int() >= base::android::SDK_VERSION_LOLLIPOP) {
auto discovery_filter =
std::make_unique<BluetoothDiscoveryFilter>(BLUETOOTH_TRANSPORT_LE);
std::string test_uuid = "00000000-0000-0000-8000-000000000001";
std::string test_uuid2 = "00000000-0000-0000-8000-000000000002";
BluetoothDiscoveryFilter::DeviceInfoFilter device_filter;
device_filter.uuids.insert(BluetoothUUID(test_uuid));
device_filter.uuids.insert(BluetoothUUID(test_uuid2));
discovery_filter->AddDeviceFilter(device_filter);
std::string test_uuid3 = "00000000-0000-0000-8000-000000000003";
BluetoothDiscoveryFilter::DeviceInfoFilter device_filter2;
std::string test_name = "test name";
device_filter2.name = test_name;
device_filter2.uuids.insert(BluetoothUUID(test_uuid3));
discovery_filter->AddDeviceFilter(device_filter2);
auto scan_filter_list_java_object =
android_adapter_->CreateAndroidFilter(discovery_filter.get());
auto scan_filter_java_object = Java_ChromeBluetoothScanFilter_getFromList(
AttachCurrentThread(), scan_filter_list_java_object, /*index=*/0);
auto scan_filter_java_object_2 = Java_ChromeBluetoothScanFilter_getFromList(
AttachCurrentThread(), scan_filter_list_java_object, /*index=*/1);
std::string uuid = ConvertJavaStringToUTF8(
AttachCurrentThread(),
Java_ChromeBluetoothScanFilter_getServiceUuid(AttachCurrentThread(),
scan_filter_java_object));
EXPECT_EQ(uuid, test_uuid);
std::string uuid3 = ConvertJavaStringToUTF8(
AttachCurrentThread(),
Java_ChromeBluetoothScanFilter_getServiceUuid(
AttachCurrentThread(), scan_filter_java_object_2));
EXPECT_EQ(uuid3, test_uuid3);
std::string name = ConvertJavaStringToUTF8(
AttachCurrentThread(),
Java_ChromeBluetoothScanFilter_getDeviceName(
AttachCurrentThread(), scan_filter_java_object_2));
EXPECT_EQ(name, test_name);
}
auto discovery_filter =
std::make_unique<BluetoothDiscoveryFilter>(BLUETOOTH_TRANSPORT_LE);
std::string test_uuid = "00000000-0000-0000-8000-000000000001";
std::string test_uuid2 = "00000000-0000-0000-8000-000000000002";
BluetoothDiscoveryFilter::DeviceInfoFilter device_filter;
device_filter.uuids.insert(BluetoothUUID(test_uuid));
device_filter.uuids.insert(BluetoothUUID(test_uuid2));
discovery_filter->AddDeviceFilter(device_filter);
std::string test_uuid3 = "00000000-0000-0000-8000-000000000003";
BluetoothDiscoveryFilter::DeviceInfoFilter device_filter2;
std::string test_name = "test name";
device_filter2.name = test_name;
device_filter2.uuids.insert(BluetoothUUID(test_uuid3));
discovery_filter->AddDeviceFilter(device_filter2);
auto scan_filter_list_java_object =
android_adapter_->CreateAndroidFilter(discovery_filter.get());
auto scan_filter_java_object = Java_ChromeBluetoothScanFilter_getFromList(
AttachCurrentThread(), scan_filter_list_java_object, /*index=*/0);
auto scan_filter_java_object_2 = Java_ChromeBluetoothScanFilter_getFromList(
AttachCurrentThread(), scan_filter_list_java_object, /*index=*/1);
std::string uuid = ConvertJavaStringToUTF8(
AttachCurrentThread(),
Java_ChromeBluetoothScanFilter_getServiceUuid(AttachCurrentThread(),
scan_filter_java_object));
EXPECT_EQ(uuid, test_uuid);
std::string uuid3 = ConvertJavaStringToUTF8(
AttachCurrentThread(),
Java_ChromeBluetoothScanFilter_getServiceUuid(AttachCurrentThread(),
scan_filter_java_object_2));
EXPECT_EQ(uuid3, test_uuid3);
std::string name = ConvertJavaStringToUTF8(
AttachCurrentThread(),
Java_ChromeBluetoothScanFilter_getDeviceName(AttachCurrentThread(),
scan_filter_java_object_2));
EXPECT_EQ(name, test_name);
}

} // namespace device
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

package org.chromium.device.gamepad;

import android.annotation.TargetApi;
import android.os.Build;
import android.view.InputDevice;
import android.view.KeyEvent;
Expand Down Expand Up @@ -54,10 +53,7 @@ abstract class GamepadMappings {
private static final float BUTTON_AXIS_DEADZONE = 0.01f;

public static GamepadMappings getMappings(InputDevice device, int[] axes, BitSet buttons) {
GamepadMappings mappings = null;
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
mappings = getMappings(device.getProductId(), device.getVendorId(), axes);
}
GamepadMappings mappings = getMappings(device.getProductId(), device.getVendorId(), axes);
if (mappings == null) {
mappings = getMappings(device.getName());
}
Expand All @@ -67,7 +63,6 @@ public static GamepadMappings getMappings(InputDevice device, int[] axes, BitSet
return mappings;
}

@TargetApi(Build.VERSION_CODES.KITKAT)
@VisibleForTesting
static GamepadMappings getMappings(int productId, int vendorId, int[] axes) {
// Device name of a DualShock 4 gamepad is "Wireless Controller". This is not reliably
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -432,69 +432,65 @@ public void testPS4GamepadMappings() {
@Test
@Feature({"Gamepad"})
public void testXboxOneSBluetooth2016FirmwareMappings() {
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
int[] axes = new int[] {MotionEvent.AXIS_X, MotionEvent.AXIS_Y, MotionEvent.AXIS_Z,
MotionEvent.AXIS_RZ, MotionEvent.AXIS_LTRIGGER, MotionEvent.AXIS_RTRIGGER,
MotionEvent.AXIS_HAT_X, MotionEvent.AXIS_HAT_Y};
GamepadMappings mappings =
GamepadMappings.getMappings(GamepadMappings.XBOX_ONE_S_2016_FIRMWARE_PRODUCT_ID,
GamepadMappings.XBOX_ONE_S_2016_FIRMWARE_VENDOR_ID, axes);
mappings.mapToStandardGamepad(mMappedAxes, mMappedButtons, mRawAxes, mRawButtons);
int[] axes = new int[] {MotionEvent.AXIS_X, MotionEvent.AXIS_Y, MotionEvent.AXIS_Z,
MotionEvent.AXIS_RZ, MotionEvent.AXIS_LTRIGGER, MotionEvent.AXIS_RTRIGGER,
MotionEvent.AXIS_HAT_X, MotionEvent.AXIS_HAT_Y};
GamepadMappings mappings =
GamepadMappings.getMappings(GamepadMappings.XBOX_ONE_S_2016_FIRMWARE_PRODUCT_ID,
GamepadMappings.XBOX_ONE_S_2016_FIRMWARE_VENDOR_ID, axes);
mappings.mapToStandardGamepad(mMappedAxes, mMappedButtons, mRawAxes, mRawButtons);

Assert.assertEquals(mMappedButtons[CanonicalButtonIndex.PRIMARY],
mRawButtons[KeyEvent.KEYCODE_BUTTON_A], ERROR_TOLERANCE);
Assert.assertEquals(mMappedButtons[CanonicalButtonIndex.SECONDARY],
mRawButtons[KeyEvent.KEYCODE_BUTTON_B], ERROR_TOLERANCE);
Assert.assertEquals(mMappedButtons[CanonicalButtonIndex.TERTIARY],
mRawButtons[KeyEvent.KEYCODE_BUTTON_C], ERROR_TOLERANCE);
Assert.assertEquals(mMappedButtons[CanonicalButtonIndex.QUATERNARY],
mRawButtons[KeyEvent.KEYCODE_BUTTON_X], ERROR_TOLERANCE);
Assert.assertEquals(mMappedButtons[CanonicalButtonIndex.PRIMARY],
mRawButtons[KeyEvent.KEYCODE_BUTTON_A], ERROR_TOLERANCE);
Assert.assertEquals(mMappedButtons[CanonicalButtonIndex.SECONDARY],
mRawButtons[KeyEvent.KEYCODE_BUTTON_B], ERROR_TOLERANCE);
Assert.assertEquals(mMappedButtons[CanonicalButtonIndex.TERTIARY],
mRawButtons[KeyEvent.KEYCODE_BUTTON_C], ERROR_TOLERANCE);
Assert.assertEquals(mMappedButtons[CanonicalButtonIndex.QUATERNARY],
mRawButtons[KeyEvent.KEYCODE_BUTTON_X], ERROR_TOLERANCE);

Assert.assertEquals(mMappedButtons[CanonicalButtonIndex.LEFT_SHOULDER],
mRawButtons[KeyEvent.KEYCODE_BUTTON_Y], ERROR_TOLERANCE);
Assert.assertEquals(mMappedButtons[CanonicalButtonIndex.RIGHT_SHOULDER],
mRawButtons[KeyEvent.KEYCODE_BUTTON_Z], ERROR_TOLERANCE);
Assert.assertEquals(mMappedButtons[CanonicalButtonIndex.LEFT_SHOULDER],
mRawButtons[KeyEvent.KEYCODE_BUTTON_Y], ERROR_TOLERANCE);
Assert.assertEquals(mMappedButtons[CanonicalButtonIndex.RIGHT_SHOULDER],
mRawButtons[KeyEvent.KEYCODE_BUTTON_Z], ERROR_TOLERANCE);

Assert.assertEquals(mMappedButtons[CanonicalButtonIndex.LEFT_THUMBSTICK],
mRawButtons[KeyEvent.KEYCODE_BUTTON_L2], ERROR_TOLERANCE);
Assert.assertEquals(mMappedButtons[CanonicalButtonIndex.RIGHT_THUMBSTICK],
mRawButtons[KeyEvent.KEYCODE_BUTTON_R2], ERROR_TOLERANCE);
Assert.assertEquals(mMappedButtons[CanonicalButtonIndex.LEFT_THUMBSTICK],
mRawButtons[KeyEvent.KEYCODE_BUTTON_L2], ERROR_TOLERANCE);
Assert.assertEquals(mMappedButtons[CanonicalButtonIndex.RIGHT_THUMBSTICK],
mRawButtons[KeyEvent.KEYCODE_BUTTON_R2], ERROR_TOLERANCE);

Assert.assertEquals(mMappedButtons[CanonicalButtonIndex.BACK_SELECT],
mRawButtons[KeyEvent.KEYCODE_BUTTON_L1], ERROR_TOLERANCE);
Assert.assertEquals(mMappedButtons[CanonicalButtonIndex.START],
mRawButtons[KeyEvent.KEYCODE_BUTTON_R1], ERROR_TOLERANCE);
Assert.assertEquals(mMappedButtons[CanonicalButtonIndex.BACK_SELECT],
mRawButtons[KeyEvent.KEYCODE_BUTTON_L1], ERROR_TOLERANCE);
Assert.assertEquals(mMappedButtons[CanonicalButtonIndex.START],
mRawButtons[KeyEvent.KEYCODE_BUTTON_R1], ERROR_TOLERANCE);

// The triggers range from -1 to 1 with -1 as the idle value.
float leftTriggerValue = (mRawAxes[MotionEvent.AXIS_Z] + 1.0f) / 2.0f;
float rightTriggerValue = (mRawAxes[MotionEvent.AXIS_RZ] + 1.0f) / 2.0f;
Assert.assertEquals(mMappedButtons[CanonicalButtonIndex.LEFT_TRIGGER], leftTriggerValue,
ERROR_TOLERANCE);
Assert.assertEquals(mMappedButtons[CanonicalButtonIndex.RIGHT_TRIGGER],
rightTriggerValue, ERROR_TOLERANCE);
// The triggers range from -1 to 1 with -1 as the idle value.
float leftTriggerValue = (mRawAxes[MotionEvent.AXIS_Z] + 1.0f) / 2.0f;
float rightTriggerValue = (mRawAxes[MotionEvent.AXIS_RZ] + 1.0f) / 2.0f;
Assert.assertEquals(mMappedButtons[CanonicalButtonIndex.LEFT_TRIGGER], leftTriggerValue,
ERROR_TOLERANCE);
Assert.assertEquals(mMappedButtons[CanonicalButtonIndex.RIGHT_TRIGGER], rightTriggerValue,
ERROR_TOLERANCE);

assertMappedHatAxisToDpadButtons();
assertMappedXYAxes();
assertMappedRXAndRYAxesToRightStick();
expectNoMetaButton(mappings);
assertMappedHatAxisToDpadButtons();
assertMappedXYAxes();
assertMappedRXAndRYAxesToRightStick();
expectNoMetaButton(mappings);

assertMapping(mappings);
}
assertMapping(mappings);
}

@Test
@Feature({"Gamepad"})
public void testXboxOneSBluetoothUsesDefaultMappings() {
// Test that Xbox One S gamepads with updated firmware connected over Bluetooth use the
// default mapping.
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
int[] axes = new int[] {MotionEvent.AXIS_X, MotionEvent.AXIS_Y, MotionEvent.AXIS_Z,
MotionEvent.AXIS_RZ, MotionEvent.AXIS_LTRIGGER, MotionEvent.AXIS_RTRIGGER,
MotionEvent.AXIS_HAT_X, MotionEvent.AXIS_HAT_Y};
GamepadMappings deviceIdMappings = GamepadMappings.getMappings(XBOX_ONE_S_PRODUCT_ID,
GamepadMappings.XBOX_ONE_S_2016_FIRMWARE_VENDOR_ID, axes);
Assert.assertNull(deviceIdMappings);
}
int[] axes = new int[] {MotionEvent.AXIS_X, MotionEvent.AXIS_Y, MotionEvent.AXIS_Z,
MotionEvent.AXIS_RZ, MotionEvent.AXIS_LTRIGGER, MotionEvent.AXIS_RTRIGGER,
MotionEvent.AXIS_HAT_X, MotionEvent.AXIS_HAT_Y};
GamepadMappings deviceIdMappings = GamepadMappings.getMappings(
XBOX_ONE_S_PRODUCT_ID, GamepadMappings.XBOX_ONE_S_2016_FIRMWARE_VENDOR_ID, axes);
Assert.assertNull(deviceIdMappings);

GamepadMappings deviceNameMappings = GamepadMappings.getMappings(XBOX_WIRELESS_DEVICE_NAME);
Assert.assertNull(deviceNameMappings);
Expand Down
5 changes: 1 addition & 4 deletions device/vr/android/gvr/gvr_device_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,10 @@ void GvrDeviceProvider::Initialize(
add_device_callback,
base::RepeatingCallback<void(mojom::XRDeviceId)> remove_device_callback,
base::OnceClosure initialization_complete) {
// Version check should match MIN_SDK_VERSION in VrCoreVersionChecker.java.
// We only expose GvrDevice if
// - we could potentially install VRServices to support presentation, and
// - this build is a bundle and, thus, supports installing the VR module.
if (base::android::BuildInfo::GetInstance()->sdk_int() >=
base::android::SDK_VERSION_LOLLIPOP &&
base::android::BundleUtils::IsBundle()) {
if (base::android::BundleUtils::IsBundle()) {
vr_device_ = base::WrapUnique(new GvrDevice());
}
if (vr_device_) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@

package org.chromium.device.battery;

import android.annotation.TargetApi;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.BatteryManager;
import android.os.Build;

import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
Expand Down Expand Up @@ -39,13 +37,7 @@ public void onReceive(Context context, Intent intent) {
BatteryStatusManager.this.onReceive(intent);
}
};

// This is to workaround a Galaxy Nexus bug, see the comment in the constructor.
private final boolean mIgnoreBatteryPresentState;

// Only used in L (API level 21) and higher.
private AndroidBatteryManagerWrapper mAndroidBatteryManager;

private boolean mEnabled;

@VisibleForTesting
Expand All @@ -56,37 +48,31 @@ protected AndroidBatteryManagerWrapper(BatteryManager batteryManager) {
mBatteryManager = batteryManager;
}

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public int getIntProperty(int id) {
return mBatteryManager.getIntProperty(id);
}
}

private BatteryStatusManager(BatteryStatusCallback callback, boolean ignoreBatteryPresentState,
@Nullable AndroidBatteryManagerWrapper batteryManager) {
private BatteryStatusManager(
BatteryStatusCallback callback, @Nullable AndroidBatteryManagerWrapper batteryManager) {
mCallback = callback;
mIgnoreBatteryPresentState = ignoreBatteryPresentState;
mAndroidBatteryManager = batteryManager;
}

BatteryStatusManager(BatteryStatusCallback callback) {
// BatteryManager.EXTRA_PRESENT appears to be unreliable on Galaxy Nexus,
// Android 4.2.1, it always reports false. See http://crbug.com/384348.
this(callback, Build.MODEL.equals("Galaxy Nexus"),
Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP
? new AndroidBatteryManagerWrapper(
(BatteryManager) ContextUtils.getApplicationContext()
.getSystemService(Context.BATTERY_SERVICE))
: null);
this(callback,
new AndroidBatteryManagerWrapper(
(BatteryManager) ContextUtils.getApplicationContext().getSystemService(
Context.BATTERY_SERVICE)));
}

/**
* Creates a BatteryStatusManager without the Galaxy Nexus workaround for consistency in
* testing.
*/
static BatteryStatusManager createBatteryStatusManagerForTesting(Context context,
static BatteryStatusManager createBatteryStatusManagerForTesting(
BatteryStatusCallback callback, @Nullable AndroidBatteryManagerWrapper batteryManager) {
return new BatteryStatusManager(callback, false, batteryManager);
return new BatteryStatusManager(callback, batteryManager);
}

/**
Expand Down Expand Up @@ -120,9 +106,7 @@ void onReceive(Intent intent) {
return;
}

boolean present = mIgnoreBatteryPresentState
? true
: intent.getBooleanExtra(BatteryManager.EXTRA_PRESENT, false);
boolean present = intent.getBooleanExtra(BatteryManager.EXTRA_PRESENT, false);
int pluggedStatus = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1);

if (!present || pluggedStatus == -1) {
Expand Down Expand Up @@ -156,16 +140,13 @@ void onReceive(Intent intent) {
batteryStatus.level = level;

if (mAndroidBatteryManager != null) {
updateBatteryStatusForLollipop(batteryStatus);
updateBatteryStatus(batteryStatus);
}

mCallback.onBatteryStatusChanged(batteryStatus);
}

private void updateBatteryStatusForLollipop(BatteryStatus batteryStatus) {
assert mAndroidBatteryManager != null;

// On Lollipop we can provide a better estimate for chargingTime and dischargingTime.
private void updateBatteryStatus(BatteryStatus batteryStatus) {
double remainingCapacityRatio =
mAndroidBatteryManager.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY)
/ 100.0;
Expand Down

0 comments on commit 9406e49

Please sign in to comment.