OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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.geolocation; | 5 package org.chromium.device.geolocation; |
6 | 6 |
7 import android.content.Context; | 7 import android.content.Context; |
8 import android.location.Location; | |
9 | 8 |
10 import org.chromium.base.Log; | |
11 import org.chromium.base.ThreadUtils; | 9 import org.chromium.base.ThreadUtils; |
12 import org.chromium.base.VisibleForTesting; | 10 import org.chromium.base.VisibleForTesting; |
13 import org.chromium.base.annotations.CalledByNative; | 11 import org.chromium.base.annotations.CalledByNative; |
14 import org.chromium.base.annotations.MainDex; | 12 import org.chromium.base.annotations.MainDex; |
15 | 13 |
16 import java.util.concurrent.FutureTask; | 14 import java.util.concurrent.FutureTask; |
17 | 15 |
18 /** | 16 /** |
19 * Implements the Java side of LocationProviderAndroid. | 17 * Implements the Java side of LocationProviderAndroid. |
20 * Delegates all real functionality to the implementation | 18 * Delegates all real functionality to the implementation |
21 * returned from LocationProviderFactory. | 19 * returned from LocationProviderFactory. |
22 * See detailed documentation on | 20 * See detailed documentation on |
23 * content/browser/geolocation/location_api_adapter_android.h. | 21 * content/browser/geolocation/location_api_adapter_android.h. |
24 * Based on android.webkit.GeolocationService.java | 22 * Based on android.webkit.GeolocationService.java |
25 */ | 23 */ |
26 @MainDex | 24 @MainDex |
27 @VisibleForTesting | 25 @VisibleForTesting |
28 public class LocationProviderAdapter { | 26 public class LocationProviderAdapter { |
29 private static final String TAG = "cr_LocationProvider"; | |
30 | |
31 // Delegate handling the real work in the main thread. | 27 // Delegate handling the real work in the main thread. |
32 private LocationProviderFactory.LocationProvider mImpl; | 28 private LocationProviderFactory.LocationProvider mImpl; |
33 | 29 |
34 private LocationProviderAdapter(Context context) { | 30 private LocationProviderAdapter(Context context) { |
35 mImpl = LocationProviderFactory.create(context); | 31 mImpl = LocationProviderFactory.create(context); |
36 } | 32 } |
37 | 33 |
38 @CalledByNative | 34 @CalledByNative |
39 public static LocationProviderAdapter create(Context context) { | 35 public static LocationProviderAdapter create(Context context) { |
40 return new LocationProviderAdapter(context); | 36 return new LocationProviderAdapter(context); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 | 68 |
73 /** | 69 /** |
74 * Returns true if we are currently listening for location updates, false if
not. | 70 * Returns true if we are currently listening for location updates, false if
not. |
75 * Must be called only in the UI thread. | 71 * Must be called only in the UI thread. |
76 */ | 72 */ |
77 public boolean isRunning() { | 73 public boolean isRunning() { |
78 assert ThreadUtils.runningOnUiThread(); | 74 assert ThreadUtils.runningOnUiThread(); |
79 return mImpl.isRunning(); | 75 return mImpl.isRunning(); |
80 } | 76 } |
81 | 77 |
82 public static void onNewLocationAvailable(Location location) { | 78 public static void newLocationAvailable(double latitude, double longitude, d
ouble timestamp, |
83 nativeNewLocationAvailable(location.getLatitude(), location.getLongitude
(), | 79 boolean hasAltitude, double altitude, boolean hasAccuracy, double ac
curacy, |
84 location.getTime() / 1000.0, location.hasAltitude(), location.ge
tAltitude(), | 80 boolean hasHeading, double heading, boolean hasSpeed, double speed)
{ |
85 location.hasAccuracy(), location.getAccuracy(), location.hasBear
ing(), | 81 nativeNewLocationAvailable(latitude, longitude, timestamp, hasAltitude,
altitude, |
86 location.getBearing(), location.hasSpeed(), location.getSpeed())
; | 82 hasAccuracy, accuracy, hasHeading, heading, hasSpeed, speed); |
87 } | 83 } |
88 | 84 |
89 public static void newErrorAvailable(String message) { | 85 public static void newErrorAvailable(String message) { |
90 Log.e(TAG, "newErrorAvailable %s", message); | |
91 nativeNewErrorAvailable(message); | 86 nativeNewErrorAvailable(message); |
92 } | 87 } |
93 | 88 |
94 // Native functions | 89 // Native functions |
95 private static native void nativeNewLocationAvailable(double latitude, doubl
e longitude, | 90 private static native void nativeNewLocationAvailable(double latitude, doubl
e longitude, |
96 double timeStamp, boolean hasAltitude, double altitude, boolean hasA
ccuracy, | 91 double timeStamp, boolean hasAltitude, double altitude, boolean hasA
ccuracy, |
97 double accuracy, boolean hasHeading, double heading, boolean hasSpee
d, double speed); | 92 double accuracy, boolean hasHeading, double heading, boolean hasSpee
d, double speed); |
98 private static native void nativeNewErrorAvailable(String message); | 93 private static native void nativeNewErrorAvailable(String message); |
99 } | 94 } |
OLD | NEW |