OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.device.bluetooth; | 5 package org.chromium.device.bluetooth; |
6 | 6 |
7 import android.Manifest; | 7 import android.Manifest; |
8 import android.annotation.TargetApi; | 8 import android.annotation.TargetApi; |
9 import android.bluetooth.BluetoothAdapter; | 9 import android.bluetooth.BluetoothAdapter; |
10 import android.bluetooth.BluetoothDevice; | 10 import android.bluetooth.BluetoothDevice; |
11 import android.bluetooth.BluetoothGatt; | 11 import android.bluetooth.BluetoothGatt; |
12 import android.bluetooth.BluetoothGattCallback; | 12 import android.bluetooth.BluetoothGattCallback; |
13 import android.bluetooth.BluetoothGattCharacteristic; | 13 import android.bluetooth.BluetoothGattCharacteristic; |
14 import android.bluetooth.BluetoothGattDescriptor; | 14 import android.bluetooth.BluetoothGattDescriptor; |
15 import android.bluetooth.BluetoothGattService; | 15 import android.bluetooth.BluetoothGattService; |
16 import android.bluetooth.le.BluetoothLeScanner; | 16 import android.bluetooth.le.BluetoothLeScanner; |
17 import android.bluetooth.le.ScanCallback; | 17 import android.bluetooth.le.ScanCallback; |
18 import android.bluetooth.le.ScanFilter; | 18 import android.bluetooth.le.ScanFilter; |
19 import android.bluetooth.le.ScanResult; | 19 import android.bluetooth.le.ScanResult; |
20 import android.bluetooth.le.ScanSettings; | 20 import android.bluetooth.le.ScanSettings; |
21 import android.content.BroadcastReceiver; | 21 import android.content.BroadcastReceiver; |
22 import android.content.Context; | 22 import android.content.Context; |
23 import android.content.Intent; | 23 import android.content.Intent; |
24 import android.content.IntentFilter; | 24 import android.content.IntentFilter; |
25 import android.content.pm.PackageManager; | 25 import android.content.pm.PackageManager; |
| 26 import android.location.LocationManager; |
26 import android.os.Build; | 27 import android.os.Build; |
27 import android.os.ParcelUuid; | 28 import android.os.ParcelUuid; |
28 import android.os.Process; | 29 import android.os.Process; |
29 | 30 |
30 import org.chromium.base.Log; | 31 import org.chromium.base.Log; |
31 import org.chromium.base.annotations.CalledByNative; | 32 import org.chromium.base.annotations.CalledByNative; |
32 import org.chromium.base.annotations.JNINamespace; | 33 import org.chromium.base.annotations.JNINamespace; |
33 | 34 |
34 import java.util.ArrayList; | 35 import java.util.ArrayList; |
35 import java.util.HashMap; | 36 import java.util.HashMap; |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 | 161 |
161 public ContextWrapper(Context context) { | 162 public ContextWrapper(Context context) { |
162 mContext = context; | 163 mContext = context; |
163 } | 164 } |
164 | 165 |
165 public boolean checkPermission(String permission) { | 166 public boolean checkPermission(String permission) { |
166 return mContext.checkPermission(permission, Process.myPid(), Process
.myUid()) | 167 return mContext.checkPermission(permission, Process.myPid(), Process
.myUid()) |
167 == PackageManager.PERMISSION_GRANTED; | 168 == PackageManager.PERMISSION_GRANTED; |
168 } | 169 } |
169 | 170 |
| 171 public LocationManagerWrapper getLocationManager() { |
| 172 return new LocationManagerWrapper( |
| 173 (LocationManager) mContext.getSystemService(Context.LOCATION
_SERVICE)); |
| 174 } |
| 175 |
170 public Intent registerReceiver(BroadcastReceiver receiver, IntentFilter
filter) { | 176 public Intent registerReceiver(BroadcastReceiver receiver, IntentFilter
filter) { |
171 return mContext.registerReceiver(receiver, filter); | 177 return mContext.registerReceiver(receiver, filter); |
172 } | 178 } |
173 | 179 |
174 public void unregisterReceiver(BroadcastReceiver receiver) { | 180 public void unregisterReceiver(BroadcastReceiver receiver) { |
175 mContext.unregisterReceiver(receiver); | 181 mContext.unregisterReceiver(receiver); |
176 } | 182 } |
177 } | 183 } |
178 | 184 |
| 185 static class LocationManagerWrapper { |
| 186 private final LocationManager mLocationManager; |
| 187 |
| 188 public LocationManagerWrapper(LocationManager locationManager) { |
| 189 mLocationManager = locationManager; |
| 190 } |
| 191 |
| 192 public boolean isProviderEnabled(String name) { |
| 193 return mLocationManager.isProviderEnabled(name); |
| 194 } |
| 195 } |
| 196 |
179 /** | 197 /** |
180 * Wraps android.bluetooth.BluetoothLeScanner. | 198 * Wraps android.bluetooth.BluetoothLeScanner. |
181 */ | 199 */ |
182 static class BluetoothLeScannerWrapper { | 200 static class BluetoothLeScannerWrapper { |
183 protected final BluetoothLeScanner mScanner; | 201 protected final BluetoothLeScanner mScanner; |
184 private final HashMap<ScanCallbackWrapper, ForwardScanCallbackToWrapper>
mCallbacks; | 202 private final HashMap<ScanCallbackWrapper, ForwardScanCallbackToWrapper>
mCallbacks; |
185 | 203 |
186 public BluetoothLeScannerWrapper(BluetoothLeScanner scanner) { | 204 public BluetoothLeScannerWrapper(BluetoothLeScanner scanner) { |
187 mScanner = scanner; | 205 mScanner = scanner; |
188 mCallbacks = new HashMap<ScanCallbackWrapper, ForwardScanCallbackToW
rapper>(); | 206 mCallbacks = new HashMap<ScanCallbackWrapper, ForwardScanCallbackToW
rapper>(); |
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
580 | 598 |
581 public byte[] getValue() { | 599 public byte[] getValue() { |
582 return mDescriptor.getValue(); | 600 return mDescriptor.getValue(); |
583 } | 601 } |
584 | 602 |
585 public boolean setValue(byte[] value) { | 603 public boolean setValue(byte[] value) { |
586 return mDescriptor.setValue(value); | 604 return mDescriptor.setValue(value); |
587 } | 605 } |
588 } | 606 } |
589 } | 607 } |
OLD | NEW |