diff options
Diffstat (limited to 'location/lib')
10 files changed, 821 insertions, 5 deletions
diff --git a/location/lib/java/com/android/location/provider/ActivityChangedEvent.java b/location/lib/java/com/android/location/provider/ActivityChangedEvent.java new file mode 100644 index 0000000..c7dfc88 --- /dev/null +++ b/location/lib/java/com/android/location/provider/ActivityChangedEvent.java @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2014 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.NonNull; + +import java.security.InvalidParameterException; +import java.util.List; + +/** + * A class representing an event for Activity changes. + */ +public class ActivityChangedEvent { + private final List<ActivityRecognitionEvent> mActivityRecognitionEvents; + + public ActivityChangedEvent(List<ActivityRecognitionEvent> activityRecognitionEvents) { + if (activityRecognitionEvents == null) { + throw new InvalidParameterException( + "Parameter 'activityRecognitionEvents' must not be null."); + } + + mActivityRecognitionEvents = activityRecognitionEvents; + } + + @NonNull + public Iterable<ActivityRecognitionEvent> getActivityRecognitionEvents() { + return mActivityRecognitionEvents; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder("[ ActivityChangedEvent:"); + + for (ActivityRecognitionEvent event : mActivityRecognitionEvents) { + builder.append("\n "); + builder.append(event.toString()); + } + builder.append("\n]"); + + return builder.toString(); + } +} diff --git a/location/lib/java/com/android/location/provider/ActivityRecognitionEvent.java b/location/lib/java/com/android/location/provider/ActivityRecognitionEvent.java new file mode 100644 index 0000000..a39cff2 --- /dev/null +++ b/location/lib/java/com/android/location/provider/ActivityRecognitionEvent.java @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2014 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; + +/** + * A class that represents an Activity Recognition Event. + */ +public class ActivityRecognitionEvent { + private final String mActivity; + private final int mEventType; + private final long mTimestampNs; + + public ActivityRecognitionEvent(String activity, int eventType, long timestampNs) { + mActivity = activity; + mEventType = eventType; + mTimestampNs = timestampNs; + } + + public String getActivity() { + return mActivity; + } + + public int getEventType() { + return mEventType; + } + + public long getTimestampNs() { + return mTimestampNs; + } + + @Override + public String toString() { + String eventString; + switch (mEventType) { + case ActivityRecognitionProvider.EVENT_TYPE_ENTER: + eventString = "Enter"; + break; + case ActivityRecognitionProvider.EVENT_TYPE_EXIT: + eventString = "Exit"; + break; + case ActivityRecognitionProvider.EVENT_TYPE_FLUSH_COMPLETE: + eventString = "FlushComplete"; + break; + default: + eventString = "<Invalid>"; + break; + } + + return String.format( + "Activity='%s', EventType=%s(%s), TimestampNs=%s", + mActivity, + eventString, + mEventType, + mTimestampNs); + } +} diff --git a/location/lib/java/com/android/location/provider/ActivityRecognitionProvider.java b/location/lib/java/com/android/location/provider/ActivityRecognitionProvider.java new file mode 100644 index 0000000..da33464 --- /dev/null +++ b/location/lib/java/com/android/location/provider/ActivityRecognitionProvider.java @@ -0,0 +1,134 @@ +/* + * Copyright (C) 2014 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 com.android.internal.util.Preconditions; + +import android.hardware.location.IActivityRecognitionHardware; +import android.hardware.location.IActivityRecognitionHardwareSink; +import android.os.RemoteException; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; + +/** + * A class that exposes {@link IActivityRecognitionHardware} functionality to unbundled services. + */ +public final class ActivityRecognitionProvider { + private final IActivityRecognitionHardware mService; + private final HashSet<Sink> mSinkSet = new HashSet<Sink>(); + private final SinkTransport mSinkTransport = new SinkTransport(); + + // the following constants must remain in sync with activity_recognition.h + + public static final String ACTIVITY_IN_VEHICLE = "android.activity_recognition.in_vehicle"; + public static final String ACTIVITY_ON_BICYCLE = "android.activity_recognition.on_bicycle"; + public static final String ACTIVITY_WALKING = "android.activity_recognition.walking"; + public static final String ACTIVITY_RUNNING = "android.activity_recognition.running"; + public static final String ACTIVITY_STILL = "android.activity_recognition.still"; + public static final String ACTIVITY_TILTING = "android.activity_recognition.tilting"; + + public static final int EVENT_TYPE_FLUSH_COMPLETE = 0; + public static final int EVENT_TYPE_ENTER = 1; + public static final int EVENT_TYPE_EXIT = 2; + + // end constants activity_recognition.h + + /** + * Used to receive Activity-Recognition events. + */ + public interface Sink { + void onActivityChanged(ActivityChangedEvent event); + } + + public ActivityRecognitionProvider(IActivityRecognitionHardware service) + throws RemoteException { + Preconditions.checkNotNull(service); + mService = service; + mService.registerSink(mSinkTransport); + } + + public String[] getSupportedActivities() throws RemoteException { + return mService.getSupportedActivities(); + } + + public boolean isActivitySupported(String activity) throws RemoteException { + return mService.isActivitySupported(activity); + } + + public void registerSink(Sink sink) { + Preconditions.checkNotNull(sink); + synchronized (mSinkSet) { + mSinkSet.add(sink); + } + } + + // TODO: if this functionality is exposed to 3rd party developers, handle unregistration (here + // and in the service) of all sinks while failing to disable all events + public void unregisterSink(Sink sink) { + Preconditions.checkNotNull(sink); + synchronized (mSinkSet) { + mSinkSet.remove(sink); + } + } + + public boolean enableActivityEvent(String activity, int eventType, long reportLatencyNs) + throws RemoteException { + return mService.enableActivityEvent(activity, eventType, reportLatencyNs); + } + + public boolean disableActivityEvent(String activity, int eventType) throws RemoteException { + return mService.disableActivityEvent(activity, eventType); + } + + public boolean flush() throws RemoteException { + return mService.flush(); + } + + private final class SinkTransport extends IActivityRecognitionHardwareSink.Stub { + @Override + public void onActivityChanged( + android.hardware.location.ActivityChangedEvent activityChangedEvent) { + Collection<Sink> sinks; + synchronized (mSinkSet) { + if (mSinkSet.isEmpty()) { + return; + } + + sinks = new ArrayList<Sink>(mSinkSet); + } + + // translate the event from platform internal and GmsCore types + ArrayList<ActivityRecognitionEvent> gmsEvents = + new ArrayList<ActivityRecognitionEvent>(); + for (android.hardware.location.ActivityRecognitionEvent event + : activityChangedEvent.getActivityRecognitionEvents()) { + ActivityRecognitionEvent gmsEvent = new ActivityRecognitionEvent( + event.getActivity(), + event.getEventType(), + event.getTimestampNs()); + gmsEvents.add(gmsEvent); + } + ActivityChangedEvent gmsEvent = new ActivityChangedEvent(gmsEvents); + + for (Sink sink : sinks) { + sink.onActivityChanged(gmsEvent); + } + } + } +} diff --git a/location/lib/java/com/android/location/provider/ActivityRecognitionProviderWatcher.java b/location/lib/java/com/android/location/provider/ActivityRecognitionProviderWatcher.java new file mode 100644 index 0000000..03dd042 --- /dev/null +++ b/location/lib/java/com/android/location/provider/ActivityRecognitionProviderWatcher.java @@ -0,0 +1,86 @@ +/* + * Copyright (C) 2014 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.NonNull; +import android.annotation.Nullable; +import android.hardware.location.IActivityRecognitionHardware; +import android.hardware.location.IActivityRecognitionHardwareWatcher; +import android.os.Binder; +import android.os.IBinder; +import android.os.Process; +import android.os.RemoteException; +import android.util.Log; + +/** + * A watcher class for Activity-Recognition instances. + */ +public class ActivityRecognitionProviderWatcher { + private static final String TAG = "ActivityRecognitionProviderWatcher"; + + private static ActivityRecognitionProviderWatcher sWatcher; + private static final Object sWatcherLock = new Object(); + + private ActivityRecognitionProvider mActivityRecognitionProvider; + + private ActivityRecognitionProviderWatcher() {} + + public static ActivityRecognitionProviderWatcher getInstance() { + synchronized (sWatcherLock) { + if (sWatcher == null) { + sWatcher = new ActivityRecognitionProviderWatcher(); + } + return sWatcher; + } + } + + private IActivityRecognitionHardwareWatcher.Stub mWatcherStub = + new IActivityRecognitionHardwareWatcher.Stub() { + @Override + public void onInstanceChanged(IActivityRecognitionHardware instance) { + int callingUid = Binder.getCallingUid(); + if (callingUid != Process.SYSTEM_UID) { + Log.d(TAG, "Ignoring calls from non-system server. Uid: " + callingUid); + return; + } + + try { + mActivityRecognitionProvider = new ActivityRecognitionProvider(instance); + } catch (RemoteException e) { + Log.e(TAG, "Error creating Hardware Activity-Recognition", e); + } + } + }; + + /** + * Gets the binder needed to interact with proxy provider in the platform. + */ + @NonNull + public IBinder getBinder() { + return mWatcherStub; + } + + /** + * Gets an object that supports the functionality of {@link ActivityRecognitionProvider}. + * + * @return Non-null value if the functionality is supported by the platform, false otherwise. + */ + @Nullable + public ActivityRecognitionProvider getActivityRecognitionProvider() { + return mActivityRecognitionProvider; + } +} 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..bc5a8a1 --- /dev/null +++ b/location/lib/java/com/android/location/provider/FusedLocationHardware.java @@ -0,0 +1,280 @@ +/* + * 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.hardware.location.IFusedLocationHardwareSink; + +import android.location.Location; + +import android.os.Handler; +import android.os.Looper; +import android.os.Message; +import android.os.RemoteException; +import android.util.Log; + +import java.util.HashMap; +import java.util.Map; + +/** + * Class that exposes IFusedLocationHardware functionality to unbundled services. + */ +public final class FusedLocationHardware { + private final String TAG = "FusedLocationHardware"; + + private IFusedLocationHardware mLocationHardware; + + // the list uses a copy-on-write pattern to update its contents + HashMap<FusedLocationHardwareSink, DispatcherHandler> mSinkList = + new HashMap<FusedLocationHardwareSink, DispatcherHandler>(); + + private IFusedLocationHardwareSink mInternalSink = new IFusedLocationHardwareSink.Stub() { + @Override + public void onLocationAvailable(Location[] locations) { + dispatchLocations(locations); + } + + @Override + public void onDiagnosticDataAvailable(String data) { + dispatchDiagnosticData(data); + } + }; + + /** + * @hide + */ + public FusedLocationHardware(IFusedLocationHardware locationHardware) { + mLocationHardware = locationHardware; + } + + /* + * Methods to provide a Facade for IFusedLocationHardware + */ + public void registerSink(FusedLocationHardwareSink sink, Looper looper) { + if(sink == null || looper == null) { + throw new IllegalArgumentException("Parameter sink and looper cannot be null."); + } + + boolean registerSink; + synchronized (mSinkList) { + // register only on first insertion + registerSink = mSinkList.size() == 0; + // guarantee uniqueness + if(mSinkList.containsKey(sink)) { + return; + } + + HashMap<FusedLocationHardwareSink, DispatcherHandler> newSinkList = + new HashMap<FusedLocationHardwareSink, DispatcherHandler>(mSinkList); + newSinkList.put(sink, new DispatcherHandler(looper)); + mSinkList = newSinkList; + } + + if(registerSink) { + try { + mLocationHardware.registerSink(mInternalSink); + } catch(RemoteException e) { + Log.e(TAG, "RemoteException at registerSink"); + } + } + } + + public void unregisterSink(FusedLocationHardwareSink sink) { + if(sink == null) { + throw new IllegalArgumentException("Parameter sink cannot be null."); + } + + boolean unregisterSink; + synchronized(mSinkList) { + if(!mSinkList.containsKey(sink)) { + //done + return; + } + + HashMap<FusedLocationHardwareSink, DispatcherHandler> newSinkList = + new HashMap<FusedLocationHardwareSink, DispatcherHandler>(mSinkList); + newSinkList.remove(sink); + //unregister after the last sink + unregisterSink = newSinkList.size() == 0; + + mSinkList = newSinkList; + } + + 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 and classes + */ + private class DispatcherHandler extends Handler { + public static final int DISPATCH_LOCATION = 1; + public static final int DISPATCH_DIAGNOSTIC_DATA = 2; + + public DispatcherHandler(Looper looper) { + super(looper, null /*callback*/ , true /*async*/); + } + + @Override + public void handleMessage(Message message) { + MessageCommand command = (MessageCommand) message.obj; + switch(message.what) { + case DISPATCH_LOCATION: + command.dispatchLocation(); + break; + case DISPATCH_DIAGNOSTIC_DATA: + command.dispatchDiagnosticData(); + default: + Log.e(TAG, "Invalid dispatch message"); + break; + } + } + } + + private class MessageCommand { + private final FusedLocationHardwareSink mSink; + private final Location[] mLocations; + private final String mData; + + public MessageCommand( + FusedLocationHardwareSink sink, + Location[] locations, + String data) { + mSink = sink; + mLocations = locations; + mData = data; + } + + public void dispatchLocation() { + mSink.onLocationAvailable(mLocations); + } + + public void dispatchDiagnosticData() { + mSink.onDiagnosticDataAvailable(mData); + } + } + + private void dispatchLocations(Location[] locations) { + HashMap<FusedLocationHardwareSink, DispatcherHandler> sinks; + synchronized (mSinkList) { + sinks = mSinkList; + } + + for(Map.Entry<FusedLocationHardwareSink, DispatcherHandler> entry : sinks.entrySet()) { + Message message = Message.obtain( + entry.getValue(), + DispatcherHandler.DISPATCH_LOCATION, + new MessageCommand(entry.getKey(), locations, null /*data*/)); + message.sendToTarget(); + } + } + + private void dispatchDiagnosticData(String data) { + HashMap<FusedLocationHardwareSink, DispatcherHandler> sinks; + synchronized(mSinkList) { + sinks = mSinkList; + } + + for(Map.Entry<FusedLocationHardwareSink, DispatcherHandler> entry : sinks.entrySet()) { + Message message = Message.obtain( + entry.getValue(), + DispatcherHandler.DISPATCH_DIAGNOSTIC_DATA, + new MessageCommand(entry.getKey(), null /*locations*/, data)); + message.sendToTarget(); + } + } +} 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..2c39fa8 --- /dev/null +++ b/location/lib/java/com/android/location/provider/FusedLocationHardwareSink.java @@ -0,0 +1,30 @@ +/* + * 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. + */ +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..c966ade --- /dev/null +++ b/location/lib/java/com/android/location/provider/FusedProvider.java @@ -0,0 +1,57 @@ +/* + * 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. + */ +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/GeofenceProvider.java b/location/lib/java/com/android/location/provider/GeofenceProvider.java index 2618f34..fafaa84 100644 --- a/location/lib/java/com/android/location/provider/GeofenceProvider.java +++ b/location/lib/java/com/android/location/provider/GeofenceProvider.java @@ -21,9 +21,6 @@ import android.hardware.location.IGeofenceHardware; import android.os.IBinder; import android.location.IGeofenceProvider; -import android.util.Log; - -import java.lang.Long; /** * Base class for geofence providers implemented as unbundled services. 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; + } +} diff --git a/location/lib/java/com/android/location/provider/LocationProviderBase.java b/location/lib/java/com/android/location/provider/LocationProviderBase.java index 8a5a739..d717f40 100644 --- a/location/lib/java/com/android/location/provider/LocationProviderBase.java +++ b/location/lib/java/com/android/location/provider/LocationProviderBase.java @@ -24,7 +24,6 @@ import android.content.Context; import android.location.ILocationManager; import android.location.Location; import android.location.LocationManager; -import android.location.LocationRequest; import android.os.Bundle; import android.os.IBinder; import android.os.RemoteException; @@ -35,6 +34,7 @@ import android.util.Log; import com.android.internal.location.ILocationProvider; import com.android.internal.location.ProviderProperties; import com.android.internal.location.ProviderRequest; +import com.android.internal.util.FastPrintWriter; /** * Base class for location providers implemented as unbundled services. @@ -106,7 +106,7 @@ public abstract class LocationProviderBase { } @Override public void dump(FileDescriptor fd, String[] args) { - PrintWriter pw = new PrintWriter(new FileOutputStream(fd)); + PrintWriter pw = new FastPrintWriter(new FileOutputStream(fd)); onDump(fd, pw, args); pw.flush(); } |