Commit 9406e494 authored by Andrew Grieve's avatar Andrew Grieve Committed by Commit Bot

Remove KitKat-specific code from //services and //devices

Bug: 1041930
Change-Id: Ie22490b7e1f6ec3e6ef49ddbf9af2f028021f6ac
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2298939Reviewed-by: default avatarReilly 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}
parent 34271926
......@@ -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"
......@@ -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
......@@ -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;
......@@ -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());
}
......@@ -67,7 +63,6 @@ abstract class GamepadMappings {
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
......
......@@ -432,54 +432,52 @@ public class GamepadMappingsTest {
@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
......@@ -487,14 +485,12 @@ public class GamepadMappingsTest {
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);
......
......@@ -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_) {
......
......@@ -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;
......@@ -39,13 +37,7 @@ class BatteryStatusManager {
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
......@@ -56,37 +48,31 @@ class BatteryStatusManager {
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);
}
/**
......@@ -120,9 +106,7 @@ class BatteryStatusManager {
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) {
......@@ -156,16 +140,13 @@ class BatteryStatusManager {
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;
......
......@@ -6,8 +6,6 @@ package org.chromium.device.battery;
import android.content.Intent;
import android.os.BatteryManager;
import android.os.Build;
import android.support.test.InstrumentationRegistry;
import androidx.test.filters.SmallTest;
......@@ -99,7 +97,7 @@ public class BatteryStatusManagerTest {
public void initializeBatteryManager(FakeAndroidBatteryManager managerForTesting) {
mManager = BatteryStatusManager.createBatteryStatusManagerForTesting(
InstrumentationRegistry.getContext(), mCallback, managerForTesting);
mCallback, managerForTesting);
}
@Test
......@@ -188,9 +186,7 @@ public class BatteryStatusManagerTest {
@Test
@SmallTest
public void testLollipopChargingTimeEstimate() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) return;
public void testChargingTimeEstimate() {
Intent intent = new Intent(Intent.ACTION_BATTERY_CHANGED);
intent.putExtra(BatteryManager.EXTRA_PRESENT, true);
intent.putExtra(BatteryManager.EXTRA_PLUGGED, BatteryManager.BATTERY_PLUGGED_USB);
......@@ -209,9 +205,7 @@ public class BatteryStatusManagerTest {
@Test
@SmallTest
public void testLollipopDischargingTimeEstimate() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) return;
public void testDischargingTimeEstimate() {
Intent intent = new Intent(Intent.ACTION_BATTERY_CHANGED);
intent.putExtra(BatteryManager.EXTRA_PRESENT, true);
intent.putExtra(BatteryManager.EXTRA_PLUGGED, 0);
......@@ -231,9 +225,7 @@ public class BatteryStatusManagerTest {
@Test
@SmallTest
public void testLollipopDischargingTimeEstimateRounding() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) return;
public void testDischargingTimeEstimateRounding() {
Intent intent = new Intent(Intent.ACTION_BATTERY_CHANGED);
intent.putExtra(BatteryManager.EXTRA_PRESENT, true);
intent.putExtra(BatteryManager.EXTRA_PLUGGED, 0);
......
......@@ -7,7 +7,6 @@ package org.chromium.device.sensors;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.os.Build;
import org.chromium.base.Log;
import org.chromium.base.annotations.CalledByNative;
......@@ -109,12 +108,9 @@ public class PlatformSensor implements SensorEventListener {
*/
@CalledByNative
protected int getReportingMode() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
return mSensor.getReportingMode() == Sensor.REPORTING_MODE_CONTINUOUS
? ReportingMode.CONTINUOUS
: ReportingMode.ON_CHANGE;
}
return ReportingMode.CONTINUOUS;
return mSensor.getReportingMode() == Sensor.REPORTING_MODE_CONTINUOUS
? ReportingMode.CONTINUOUS
: ReportingMode.ON_CHANGE;
}
/**
......
......@@ -5,7 +5,6 @@
package org.chromium.device.nfc;
import android.Manifest;
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Context;
import android.content.pm.PackageManager;
......@@ -15,7 +14,6 @@ import android.nfc.NfcAdapter.ReaderCallback;
import android.nfc.NfcManager;
import android.nfc.Tag;
import android.nfc.TagLostException;
import android.os.Build;
import android.os.Process;
import android.os.Vibrator;
import android.util.SparseArray;
......@@ -413,7 +411,6 @@ public class NfcImpl implements Nfc {
* discovered, Tag object is delegated to mojo service implementation method
* NfcImpl.onTagDiscovered().
*/
@TargetApi(Build.VERSION_CODES.KITKAT)
private static class ReaderCallbackHandler implements ReaderCallback {
private final NfcImpl mNfcImpl;
......@@ -449,7 +446,6 @@ public class NfcImpl implements Nfc {
* Disables reader mode.
* @see android.nfc.NfcAdapter#disableReaderMode
*/
@TargetApi(Build.VERSION_CODES.KITKAT)
private void disableReaderMode() {
// There is no API that could query whether reader mode is enabled for adapter.
// If mReaderCallbackHandler is null, reader mode is not enabled.
......
......@@ -4,10 +4,8 @@
package org.chromium.device.usb;
import android.annotation.TargetApi;
import android.hardware.usb.UsbConfiguration;
import android.hardware.usb.UsbInterface;
import android.os.Build;
import org.chromium.base.Log;
import org.chromium.base.annotations.CalledByNative;
......@@ -20,7 +18,6 @@ import org.chromium.base.annotations.JNINamespace;
* Lifetime is controlled by device::UsbConfigurationAndroid.
*/
@JNINamespace("device")
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
final class ChromeUsbConfiguration {
private static final String TAG = "Usb";
......
......@@ -7,7 +7,6 @@ package org.chromium.device.usb;
import android.annotation.TargetApi;
import android.hardware.usb.UsbConfiguration;
import android.hardware.usb.UsbDevice;
import android.hardware.usb.UsbInterface;
import android.os.Build;
import org.chromium.base.Log;
......@@ -83,25 +82,21 @@ final class ChromeUsbDevice {
return Integer.parseInt(parts[0]) << 8 | Integer.parseInt(parts[1]);
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@CalledByNative
private String getManufacturerName() {
return mDevice.getManufacturerName();
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@CalledByNative
private String getProductName() {
return mDevice.getProductName();
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@CalledByNative
private String getSerialNumber() {
return mDevice.getSerialNumber();
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@CalledByNative
private UsbConfiguration[] getConfigurations() {
int count = mDevice.getConfigurationCount();
......@@ -111,14 +106,4 @@ final class ChromeUsbDevice {
}
return configurations;
}
@CalledByNative
private UsbInterface[] getInterfaces() {
int count = mDevice.getInterfaceCount();
UsbInterface[] interfaces = new UsbInterface[count];
for (int i = 0; i < count; ++i) {
interfaces[i] = mDevice.getInterface(i);
}
return interfaces;
}
}
......@@ -4,10 +4,8 @@
package org.chromium.device.usb;
import android.annotation.TargetApi;
import android.hardware.usb.UsbEndpoint;
import android.hardware.usb.UsbInterface;
import android.os.Build;
import org.chromium.base.Log;
import org.chromium.base.annotations.CalledByNative;
......@@ -40,7 +38,6 @@ final class ChromeUsbInterface {
return mInterface.getId();
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@CalledByNative
private int getAlternateSetting() {
return mInterface.getAlternateSetting();
......
......@@ -41,25 +41,26 @@ scoped_refptr<UsbDeviceAndroid> UsbDeviceAndroid::Create(
if (build_info->sdk_int() >= base::android::SDK_VERSION_MARSHMALLOW)
device_version = Java_ChromeUsbDevice_getDeviceVersion(env, wrapper);
base::string16 manufacturer_string, product_string, serial_number;
if (build_info->sdk_int() >= base::android::SDK_VERSION_LOLLIPOP) {
ScopedJavaLocalRef<jstring> manufacturer_jstring =
Java_ChromeUsbDevice_getManufacturerName(env, wrapper);
if (!manufacturer_jstring.is_null())
manufacturer_string = ConvertJavaStringToUTF16(env, manufacturer_jstring);
ScopedJavaLocalRef<jstring> product_jstring =
Java_ChromeUsbDevice_getProductName(env, wrapper);
if (!product_jstring.is_null())
product_string = ConvertJavaStringToUTF16(env, product_jstring);
// Reading the serial number requires device access permission when
// targeting the Q SDK.
if (service->HasDevicePermission(wrapper) || !build_info->is_at_least_q()) {
ScopedJavaLocalRef<jstring> serial_jstring =
Java_ChromeUsbDevice_getSerialNumber(env, wrapper);
if (!serial_jstring.is_null())
serial_number = ConvertJavaStringToUTF16(env, serial_jstring);
}
base::string16 manufacturer_string;
ScopedJavaLocalRef<jstring> manufacturer_jstring =
Java_ChromeUsbDevice_getManufacturerName(env, wrapper);
if (!manufacturer_jstring.is_null())
manufacturer_string = ConvertJavaStringToUTF16(env, manufacturer_jstring);
base::string16 product_string;
ScopedJavaLocalRef<jstring> product_jstring =
Java_ChromeUsbDevice_getProductName(env, wrapper);
if (!product_jstring.is_null())
product_string = ConvertJavaStringToUTF16(env, product_jstring);
// Reading the serial number requires device access permission when
// targeting the Q SDK.
base::string16 serial_number;
if (service->HasDevicePermission(wrapper) || !build_info->is_at_least_q()) {
ScopedJavaLocalRef<jstring> serial_jstring =
Java_ChromeUsbDevice_getSerialNumber(env, wrapper);
if (!serial_jstring.is_null())
serial_number = ConvertJavaStringToUTF16(env, serial_jstring);
}
return base::WrapRefCounted(new UsbDeviceAndroid(
......@@ -134,33 +135,12 @@ UsbDeviceAndroid::UsbDeviceAndroid(JNIEnv* env,
device_id_(Java_ChromeUsbDevice_getDeviceId(env, wrapper)),
service_(service),
j_object_(wrapper) {
if (base::android::BuildInfo::GetInstance()->sdk_int() >=
base::android::SDK_VERSION_LOLLIPOP) {
JavaObjectArrayReader<jobject> configurations(
Java_ChromeUsbDevice_getConfigurations(env, j_object_));
device_info_->configurations.reserve(configurations.size());
for (auto config : configurations) {
device_info_->configurations.push_back(
UsbConfigurationAndroid::Convert(env, config));
}
} else {
// Pre-lollipop only the first configuration was supported. Build a basic
// configuration out of the available interfaces.
mojom::UsbConfigurationInfoPtr config = BuildUsbConfigurationInfoPtr(
1, // Configuration value, reasonable guess.
false, // Self powered, arbitrary default.
false, // Remote wakeup, rbitrary default.
0); // Maximum power, aitrary default.
JavaObjectArrayReader<jobject> interfaces(
Java_ChromeUsbDevice_getInterfaces(env, wrapper));
config->interfaces.reserve(interfaces.size());
for (auto interface : interfaces) {
config->interfaces.push_back(
UsbInterfaceAndroid::Convert(env, interface));
}
AggregateInterfacesForConfig(config.get());
device_info_->configurations.push_back(std::move(config));
JavaObjectArrayReader<jobject> configs(
Java_ChromeUsbDevice_getConfigurations(env, j_object_));
device_info_->configurations.reserve(configs.size());
for (auto config : configs) {
device_info_->configurations.push_back(
UsbConfigurationAndroid::Convert(env, config));
}
if (configurations().size() > 0)
......
......@@ -4,7 +4,6 @@
#include "services/device/usb/usb_interface_android.h"
#include "base/android/build_info.h"
#include "services/device/usb/jni_headers/ChromeUsbInterface_jni.h"
#include "services/device/usb/usb_endpoint_android.h"
......@@ -19,12 +18,8 @@ mojom::UsbInterfaceInfoPtr UsbInterfaceAndroid::Convert(
ScopedJavaLocalRef<jobject> wrapper =
Java_ChromeUsbInterface_create(env, usb_interface);
uint8_t alternate_setting = 0;
if (base::android::BuildInfo::GetInstance()->sdk_int() >=
base::android::SDK_VERSION_LOLLIPOP) {
alternate_setting =
Java_ChromeUsbInterface_getAlternateSetting(env, wrapper);
}
uint8_t alternate_setting =
Java_ChromeUsbInterface_getAlternateSetting(env, wrapper);
auto interface = BuildUsbInterfaceInfoPtr(
Java_ChromeUsbInterface_getInterfaceNumber(env, wrapper),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment