summaryrefslogtreecommitdiffstats
path: root/location/lib
diff options
context:
space:
mode:
authordestradaa <destradaa@google.com>2013-07-12 15:43:36 -0700
committerdestradaa <destradaa@google.com>2013-08-08 15:27:38 -0700
commit1af4b0280af406cfc7eb46810f6b76e57b983e11 (patch)
tree1f7f8d5a86c8dcd42cb24474e93b58bb0775071e /location/lib
parent8ffe17ae32e72e5d872a36d5048bf912d28e766f (diff)
downloadframeworks_base-1af4b0280af406cfc7eb46810f6b76e57b983e11.zip
frameworks_base-1af4b0280af406cfc7eb46810f6b76e57b983e11.tar.gz
frameworks_base-1af4b0280af406cfc7eb46810f6b76e57b983e11.tar.bz2
Add FlpHal layer to support Location Batching.
Change-Id: Ia3a57d869dfb3f067a1b95fa66d54f311ddcfdc3
Diffstat (limited to 'location/lib')
-rw-r--r--location/lib/java/com/android/location/provider/FusedLocationHardware.java202
-rw-r--r--location/lib/java/com/android/location/provider/FusedLocationHardwareSink.java31
-rw-r--r--location/lib/java/com/android/location/provider/FusedProvider.java59
-rw-r--r--location/lib/java/com/android/location/provider/GmsFusedBatchOptions.java106
4 files changed, 398 insertions, 0 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 0000000..abea9fb
--- /dev/null
+++ b/location/lib/java/com/android/location/provider/FusedLocationHardware.java
@@ -0,0 +1,202 @@
+/*
+ * Copyright (C) 2013 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 CONDITIOS 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.hardware.location.IFusedLocationHardware;
+import android.hardware.location.IFusedLocationHardwareSink;
+
+import android.location.Location;
+
+import android.os.RemoteException;
+import android.util.Log;
+
+import java.util.ArrayList;
+
+/**
+ * Class that exposes IFusedLocationHardware functionality to unbundled services.
+ * Namely this is used by GmsCore Fused Location Provider.
+ */
+public final class FusedLocationHardware {
+ private final String TAG = "FusedLocationHardware";
+
+ private IFusedLocationHardware mLocationHardware;
+ ArrayList<FusedLocationHardwareSink> mSinkList = new ArrayList<FusedLocationHardwareSink>();
+
+ private IFusedLocationHardwareSink mInternalSink = new IFusedLocationHardwareSink.Stub() {
+ @Override
+ public void onLocationAvailable(Location[] locations) {
+ dispatchLocations(locations);
+ }
+
+ @Override
+ public void onDiagnosticDataAvailable(String data) {
+ dispatchDiagnosticData(data);
+ }
+ };
+
+ public FusedLocationHardware(IFusedLocationHardware locationHardware) {
+ mLocationHardware = locationHardware;
+ }
+
+ /*
+ * Methods to provide a Facade for IFusedLocationHardware
+ */
+ public void registerSink(FusedLocationHardwareSink sink) {
+ if(sink == null) {
+ return;
+ }
+
+ boolean registerSink = false;
+ synchronized (mSinkList) {
+ // register only on first insertion
+ registerSink = mSinkList.size() == 0;
+ // guarantee uniqueness
+ if(!mSinkList.contains(sink)) {
+ mSinkList.add(sink);
+ }
+ }
+
+ if(registerSink) {
+ try {
+ mLocationHardware.registerSink(mInternalSink);
+ } catch(RemoteException e) {
+ Log.e(TAG, "RemoteException at registerSink");
+ }
+ }
+ }
+
+ public void unregisterSink(FusedLocationHardwareSink sink) {
+ if(sink == null) {
+ return;
+ }
+
+ boolean unregisterSink = false;
+ synchronized(mSinkList) {
+ mSinkList.remove(sink);
+ // unregister after the last sink
+ unregisterSink = mSinkList.size() == 0;
+ }
+
+ if(unregisterSink) {
+ try {
+ mLocationHardware.unregisterSink(mInternalSink);
+ } catch(RemoteException e) {
+ Log.e(TAG, "RemoteException at unregisterSink");
+ }
+ }
+ }
+
+ public int getSupportedBatchSize() {
+ try {
+ return mLocationHardware.getSupportedBatchSize();
+ } catch(RemoteException e) {
+ Log.e(TAG, "RemoteException at getSupportedBatchSize");
+ return 0;
+ }
+ }
+
+ public void startBatching(int id, GmsFusedBatchOptions batchOptions) {
+ try {
+ mLocationHardware.startBatching(id, batchOptions.getParcelableOptions());
+ } catch(RemoteException e) {
+ Log.e(TAG, "RemoteException at startBatching");
+ }
+ }
+
+ public void stopBatching(int id) {
+ try {
+ mLocationHardware.stopBatching(id);
+ } catch(RemoteException e) {
+ Log.e(TAG, "RemoteException at stopBatching");
+ }
+ }
+
+ public void updateBatchingOptions(int id, GmsFusedBatchOptions batchOptions) {
+ try {
+ mLocationHardware.updateBatchingOptions(id, batchOptions.getParcelableOptions());
+ } catch(RemoteException e) {
+ Log.e(TAG, "RemoteException at updateBatchingOptions");
+ }
+ }
+
+ public void requestBatchOfLocations(int batchSizeRequest) {
+ try {
+ mLocationHardware.requestBatchOfLocations(batchSizeRequest);
+ } catch(RemoteException e) {
+ Log.e(TAG, "RemoteException at requestBatchOfLocations");
+ }
+ }
+
+ public boolean supportsDiagnosticDataInjection() {
+ try {
+ return mLocationHardware.supportsDiagnosticDataInjection();
+ } catch(RemoteException e) {
+ Log.e(TAG, "RemoteException at supportsDiagnisticDataInjection");
+ return false;
+ }
+ }
+
+ public void injectDiagnosticData(String data) {
+ try {
+ mLocationHardware.injectDiagnosticData(data);
+ } catch(RemoteException e) {
+ Log.e(TAG, "RemoteException at injectDiagnosticData");
+ }
+ }
+
+ public boolean supportsDeviceContextInjection() {
+ try {
+ return mLocationHardware.supportsDeviceContextInjection();
+ } catch(RemoteException e) {
+ Log.e(TAG, "RemoteException at supportsDeviceContextInjection");
+ return false;
+ }
+ }
+
+ public void injectDeviceContext(int deviceEnabledContext) {
+ try {
+ mLocationHardware.injectDeviceContext(deviceEnabledContext);
+ } catch(RemoteException e) {
+ Log.e(TAG, "RemoteException at injectDeviceContext");
+ }
+ }
+
+ /*
+ * Helper methods
+ */
+ private void dispatchLocations(Location[] locations) {
+ ArrayList<FusedLocationHardwareSink> sinks = null;
+ synchronized (mSinkList) {
+ sinks = new ArrayList<FusedLocationHardwareSink>(mSinkList);
+ }
+
+ for(FusedLocationHardwareSink sink : sinks) {
+ sink.onLocationAvailable(locations);
+ }
+ }
+
+ private void dispatchDiagnosticData(String data) {
+ ArrayList<FusedLocationHardwareSink> sinks = null;
+ synchronized(mSinkList) {
+ sinks = new ArrayList<FusedLocationHardwareSink>(mSinkList);
+ }
+
+ for(FusedLocationHardwareSink sink : sinks) {
+ sink.onDiagnosticDataAvailable(data);
+ }
+ }
+}
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 0000000..118b663
--- /dev/null
+++ b/location/lib/java/com/android/location/provider/FusedLocationHardwareSink.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2013 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.location.Location;
+
+/**
+ * Base class for sinks to interact with FusedLocationHardware.
+ * This is mainly used by GmsCore Fused Provider.
+ */
+public abstract class FusedLocationHardwareSink {
+ /*
+ * Methods to provide a facade for IFusedLocationHardware
+ */
+ public abstract void onLocationAvailable(Location[] locations);
+ public abstract void onDiagnosticDataAvailable(String data);
+} \ No newline at end of file
diff --git a/location/lib/java/com/android/location/provider/FusedProvider.java b/location/lib/java/com/android/location/provider/FusedProvider.java
new file mode 100644
index 0000000..bc9feef
--- /dev/null
+++ b/location/lib/java/com/android/location/provider/FusedProvider.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2013 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.hardware.location.IFusedLocationHardware;
+import android.location.IFusedProvider;
+import android.os.IBinder;
+
+/**
+ * Base class for Fused providers implemented as unbundled services.
+ *
+ * <p>Fused providers can be implemented as services and return the result of
+ * {@link com.android.location.provider.FusedProvider#getBinder()} in its getBinder() method.
+ *
+ * <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.
+ *
+ * @hide
+ */
+public abstract class FusedProvider {
+ private IFusedProvider.Stub mProvider = new IFusedProvider.Stub() {
+ @Override
+ public void onFusedLocationHardwareChange(IFusedLocationHardware instance) {
+ setFusedLocationHardware(new FusedLocationHardware(instance));
+ }
+ };
+
+ /**
+ * Gets the Binder associated with the provider.
+ * This is intended to be used for the onBind() method of a service that implements a fused
+ * service.
+ *
+ * @return The IBinder instance associated with the provider.
+ */
+ public IBinder getBinder() {
+ return mProvider;
+ }
+
+ /**
+ * Sets the FusedLocationHardware instance in the provider..
+ * @param value The instance to set. This can be null in cases where the service connection
+ * is disconnected.
+ */
+ public abstract void setFusedLocationHardware(FusedLocationHardware value);
+}
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 0000000..fd3f402
--- /dev/null
+++ b/location/lib/java/com/android/location/provider/GmsFusedBatchOptions.java
@@ -0,0 +1,106 @@
+/*
+ * Copyright (C) 2013 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.location.FusedBatchOptions;
+
+/**
+ * Class that exposes FusedBatchOptions to the GmsCore .
+ */
+public class GmsFusedBatchOptions {
+ private FusedBatchOptions mOptions = new FusedBatchOptions();
+
+ /*
+ * Methods that provide a facade for properties in FusedBatchOptions.
+ */
+ public void setMaxPowerAllocationInMW(double value) {
+ mOptions.setMaxPowerAllocationInMW(value);
+ }
+
+ public double getMaxPowerAllocationInMW() {
+ return mOptions.getMaxPowerAllocationInMW();
+ }
+
+ public void setPeriodInNS(long value) {
+ mOptions.setPeriodInNS(value);
+ }
+
+ public long getPeriodInNS() {
+ return mOptions.getPeriodInNS();
+ }
+
+ public void setSourceToUse(int source) {
+ mOptions.setSourceToUse(source);
+ }
+
+ public void resetSourceToUse(int source) {
+ mOptions.resetSourceToUse(source);
+ }
+
+ public boolean isSourceToUseSet(int source) {
+ return mOptions.isSourceToUseSet(source);
+ }
+
+ public int getSourcesToUse() {
+ return mOptions.getSourcesToUse();
+ }
+
+ public void setFlag(int flag) {
+ mOptions.setFlag(flag);
+ }
+
+ public void resetFlag(int flag) {
+ mOptions.resetFlag(flag);
+ }
+
+ public boolean isFlagSet(int flag) {
+ return mOptions.isFlagSet(flag);
+ }
+
+ public int getFlags() {
+ return mOptions.getFlags();
+ }
+
+ /**
+ * 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;
+ }
+
+ /*
+ * Method definitions for internal use.
+ */
+
+ /*
+ * @hide
+ */
+ public FusedBatchOptions getParcelableOptions() {
+ return mOptions;
+ }
+}