summaryrefslogtreecommitdiff
path: root/location/lib/java
diff options
context:
space:
mode:
author Soonil Nagarkar <sooniln@google.com> 2020-12-24 14:02:44 -0800
committer Soonil Nagarkar <sooniln@google.com> 2021-01-08 10:33:44 -0800
commit49983fcbbd085bd55dd8ef14d146120ec95cf256 (patch)
treeb1fc7efe872d7aa8e231271907817c83502a5224 /location/lib/java
parenta4c1faff5b1e280e0bae1903780b53ba08539b1f (diff)
Copy LocationProviderBase API into SystemApi surface
This allows third party location providers to link against the standard API surface. This replaces the LocationProviderBase implementation in the com.android.location.providers API. Both will temporarily coexist until third party applications can be migrated, and then old version will be removed. Only the LocationProviderBase API is migrated right now as its the only API that has undergone changes. This also restores some old, unused classes which should not have been remove from the API surface. Clients that support older API version will still need to link against these classes. Bug: 176115245 Test: builds Change-Id: I2d688447e1f59e441f5c48ff36d3f0dd8b5dc7f6
Diffstat (limited to 'location/lib/java')
-rw-r--r--location/lib/java/com/android/location/provider/FusedLocationHardware.java80
-rw-r--r--location/lib/java/com/android/location/provider/FusedLocationHardwareSink.java73
-rw-r--r--location/lib/java/com/android/location/provider/GmsFusedBatchOptions.java89
-rw-r--r--location/lib/java/com/android/location/provider/LocationProviderBase.java17
-rw-r--r--location/lib/java/com/android/location/provider/ProviderPropertiesUnbundled.java18
-rw-r--r--location/lib/java/com/android/location/provider/ProviderRequestUnbundled.java3
6 files changed, 266 insertions, 14 deletions
diff --git a/location/lib/java/com/android/location/provider/FusedLocationHardware.java b/location/lib/java/com/android/location/provider/FusedLocationHardware.java
new file mode 100644
index 000000000000..3d323867f026
--- /dev/null
+++ b/location/lib/java/com/android/location/provider/FusedLocationHardware.java
@@ -0,0 +1,80 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.location.provider;
+
+import android.annotation.SystemApi;
+import android.os.Looper;
+
+/**
+ * Class that exposes IFusedLocationHardware functionality to unbundled services.
+ *
+ * @deprecated This class may no longer be used from Android P and onwards.
+ * @hide
+ */
+@Deprecated
+@SystemApi
+public final class FusedLocationHardware {
+
+ private FusedLocationHardware() {}
+
+ /*
+ * Methods to provide a Facade for IFusedLocationHardware
+ */
+ public void registerSink(FusedLocationHardwareSink sink, Looper looper) {}
+
+ public void unregisterSink(FusedLocationHardwareSink sink) {}
+
+ public int getSupportedBatchSize() {
+ return 0;
+ }
+
+ public void startBatching(int id, GmsFusedBatchOptions batchOptions) {}
+
+ public void stopBatching(int id) {}
+
+ public void updateBatchingOptions(int id, GmsFusedBatchOptions batchOptions) {}
+
+ public void requestBatchOfLocations(int batchSizeRequest) {}
+
+ public void flushBatchedLocations() {}
+
+ public boolean supportsDiagnosticDataInjection() {
+ return false;
+ }
+
+ public void injectDiagnosticData(String data) {}
+
+ public boolean supportsDeviceContextInjection() {
+ return false;
+ }
+
+ public void injectDeviceContext(int deviceEnabledContext) {}
+
+ /**
+ * Returns the version of the FLP HAL.
+ *
+ * <p>Version 1 is the initial release.
+ * <p>Version 2 adds the ability to use {@link #flushBatchedLocations},
+ * {@link FusedLocationHardwareSink#onCapabilities}, and
+ * {@link FusedLocationHardwareSink#onStatusChanged}.
+ *
+ * <p>This method is only available on API 23 or later. Older APIs have version 1.
+ */
+ public int getVersion() {
+ return 1;
+ }
+}
diff --git a/location/lib/java/com/android/location/provider/FusedLocationHardwareSink.java b/location/lib/java/com/android/location/provider/FusedLocationHardwareSink.java
new file mode 100644
index 000000000000..30bb1b3a5476
--- /dev/null
+++ b/location/lib/java/com/android/location/provider/FusedLocationHardwareSink.java
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 2021 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.location.provider;
+
+import android.annotation.SystemApi;
+import android.location.Location;
+
+/**
+ * Base class for sinks to interact with FusedLocationHardware.
+ *
+ * <p>Default implementations allow new methods to be added without crashing
+ * clients compiled against an old library version.
+ *
+ * @deprecated This class may no longer be used from Android P and onwards.
+ * @hide
+ */
+@Deprecated
+@SystemApi
+public class FusedLocationHardwareSink {
+ /**
+ * Called when one or more locations are available from the FLP
+ * HAL.
+ */
+ public void onLocationAvailable(Location[] locations) {
+ // default do nothing
+ }
+
+ /**
+ * Called when diagnostic data is available from the FLP HAL.
+ */
+ public void onDiagnosticDataAvailable(String data) {
+ // default do nothing
+ }
+
+ /**
+ * Called when capabilities are available from the FLP HAL.
+ * Should be called once right after initialization.
+ *
+ * @param capabilities A bitmask of capabilities defined in
+ * fused_location.h.
+ */
+ public void onCapabilities(int capabilities) {
+ // default do nothing
+ }
+
+ /**
+ * Called when the status changes in the underlying FLP HAL
+ * implementation (the ability to compute location). This
+ * callback will only be made on version 2 or later
+ * (see {@link FusedLocationHardware#getVersion()}).
+ *
+ * @param status One of FLP_STATUS_LOCATION_AVAILABLE or
+ * FLP_STATUS_LOCATION_UNAVAILABLE as defined in
+ * fused_location.h.
+ */
+ public void onStatusChanged(int status) {
+ // default do nothing
+ }
+}
diff --git a/location/lib/java/com/android/location/provider/GmsFusedBatchOptions.java b/location/lib/java/com/android/location/provider/GmsFusedBatchOptions.java
new file mode 100644
index 000000000000..3647377fdcdf
--- /dev/null
+++ b/location/lib/java/com/android/location/provider/GmsFusedBatchOptions.java
@@ -0,0 +1,89 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.location.provider;
+
+import android.annotation.SystemApi;
+
+/**
+ * Class that exposes FusedBatchOptions to the GmsCore.
+ *
+ * @deprecated This class may no longer be used from Android P and onwards.
+ * @hide
+ */
+@Deprecated
+@SystemApi
+public class GmsFusedBatchOptions {
+
+ public void setMaxPowerAllocationInMW(double value) {}
+
+ public double getMaxPowerAllocationInMW() {
+ return 0;
+ }
+
+ public void setPeriodInNS(long value) {}
+
+ public long getPeriodInNS() {
+ return 0;
+ }
+
+ public void setSmallestDisplacementMeters(float value) {}
+
+ public float getSmallestDisplacementMeters() {
+ return 0;
+ }
+
+ public void setSourceToUse(int source) {}
+
+ public void resetSourceToUse(int source) {}
+
+ public boolean isSourceToUseSet(int source) {
+ return false;
+ }
+
+ public int getSourcesToUse() {
+ return 0;
+ }
+
+ public void setFlag(int flag) {}
+
+ public void resetFlag(int flag) {}
+
+ public boolean isFlagSet(int flag) {
+ return false;
+ }
+
+ public int getFlags() {
+ return 0;
+ }
+
+ /**
+ * Definition of enum flag sets needed by this class.
+ * Such values need to be kept in sync with the ones in fused_location.h
+ */
+ public static final class SourceTechnologies {
+ public static int GNSS = 1 << 0;
+ public static int WIFI = 1 << 1;
+ public static int SENSORS = 1 << 2;
+ public static int CELL = 1 << 3;
+ public static int BLUETOOTH = 1 << 4;
+ }
+
+ public static final class BatchFlags {
+ public static int WAKEUP_ON_FIFO_FULL = 1 << 0;
+ public static int CALLBACK_ON_LOCATION_FIX = 1 << 1;
+ }
+}
diff --git a/location/lib/java/com/android/location/provider/LocationProviderBase.java b/location/lib/java/com/android/location/provider/LocationProviderBase.java
index 47e425629783..b545a834529d 100644
--- a/location/lib/java/com/android/location/provider/LocationProviderBase.java
+++ b/location/lib/java/com/android/location/provider/LocationProviderBase.java
@@ -23,7 +23,10 @@ import android.location.Location;
import android.location.LocationManager;
import android.location.LocationProvider;
import android.location.LocationResult;
-import android.location.ProviderProperties;
+import android.location.provider.ILocationProvider;
+import android.location.provider.ILocationProviderManager;
+import android.location.provider.ProviderProperties;
+import android.location.provider.ProviderRequest;
import android.os.Build.VERSION_CODES;
import android.os.Bundle;
import android.os.IBinder;
@@ -34,10 +37,6 @@ import android.util.Log;
import androidx.annotation.RequiresApi;
-import com.android.internal.location.ILocationProvider;
-import com.android.internal.location.ILocationProviderManager;
-import com.android.internal.location.ProviderRequest;
-
import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.util.List;
@@ -58,7 +57,11 @@ import java.util.List;
* <p>IMPORTANT: This class is effectively a public API for unbundled
* applications, and must remain API stable. See README.txt in the root
* of this package for more information.
+ *
+ * @deprecated This class is not part of the standard API surface - use
+ * {@link android.location.provider.LocationProviderBase} instead.
*/
+@Deprecated
public abstract class LocationProviderBase {
/**
@@ -386,8 +389,8 @@ public abstract class LocationProviderBase {
}
@Override
- public void setRequest(ProviderRequest request, WorkSource ws) {
- onSetRequest(new ProviderRequestUnbundled(request), ws);
+ public void setRequest(ProviderRequest request) {
+ onSetRequest(new ProviderRequestUnbundled(request), request.getWorkSource());
}
@Override
diff --git a/location/lib/java/com/android/location/provider/ProviderPropertiesUnbundled.java b/location/lib/java/com/android/location/provider/ProviderPropertiesUnbundled.java
index 9d8ccdf62ca5..89ca2822a19d 100644
--- a/location/lib/java/com/android/location/provider/ProviderPropertiesUnbundled.java
+++ b/location/lib/java/com/android/location/provider/ProviderPropertiesUnbundled.java
@@ -17,7 +17,7 @@
package com.android.location.provider;
import android.annotation.NonNull;
-import android.location.ProviderProperties;
+import android.location.provider.ProviderProperties;
import java.util.Objects;
@@ -35,10 +35,18 @@ public final class ProviderPropertiesUnbundled {
public static @NonNull ProviderPropertiesUnbundled create(boolean requiresNetwork,
boolean requiresSatellite, boolean requiresCell, boolean hasMonetaryCost,
boolean supportsAltitude, boolean supportsSpeed, boolean supportsBearing,
- int powerRequirement, int accuracy) {
- return new ProviderPropertiesUnbundled(new ProviderProperties(requiresNetwork,
- requiresSatellite, requiresCell, hasMonetaryCost, supportsAltitude, supportsSpeed,
- supportsBearing, powerRequirement, accuracy));
+ int powerUsage, int accuracy) {
+ return new ProviderPropertiesUnbundled(new ProviderProperties.Builder()
+ .setHasNetworkRequirement(requiresNetwork)
+ .setHasSatelliteRequirement(requiresSatellite)
+ .setHasCellRequirement(requiresCell)
+ .setHasMonetaryCost(requiresCell)
+ .setHasAltitudeSupport(requiresCell)
+ .setHasSpeedSupport(requiresCell)
+ .setHasBearingSupport(requiresCell)
+ .setPowerUsage(powerUsage)
+ .setAccuracy(accuracy)
+ .build());
}
private final ProviderProperties mProperties;
diff --git a/location/lib/java/com/android/location/provider/ProviderRequestUnbundled.java b/location/lib/java/com/android/location/provider/ProviderRequestUnbundled.java
index b464fca6f596..28317fed9eee 100644
--- a/location/lib/java/com/android/location/provider/ProviderRequestUnbundled.java
+++ b/location/lib/java/com/android/location/provider/ProviderRequestUnbundled.java
@@ -18,13 +18,12 @@ package com.android.location.provider;
import android.annotation.NonNull;
import android.location.LocationRequest;
+import android.location.provider.ProviderRequest;
import android.os.Build;
import android.os.WorkSource;
import androidx.annotation.RequiresApi;
-import com.android.internal.location.ProviderRequest;
-
import java.util.Collections;
import java.util.List;