• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2013 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package android.location;
18 
19 import android.os.Parcel;
20 import android.os.Parcelable;
21 
22 /**
23  * A data class representing a set of options to configure batching sessions.
24  * @hide
25  */
26 public class FusedBatchOptions implements Parcelable {
27     private volatile long mPeriodInNS = 0;
28     private volatile int mSourcesToUse = 0;
29     private volatile int mFlags = 0;
30 
31     // the default value is set to request fixes at no cost
32     private volatile double mMaxPowerAllocationInMW = 0;
33     // If non-zero can be used for power savings by throttling location when device hasn't moved.
34     private volatile float mSmallestDisplacementMeters = 0;
35 
36     /*
37      * Getters and setters for properties needed to hold the options.
38      */
setMaxPowerAllocationInMW(double value)39     public void setMaxPowerAllocationInMW(double value) {
40         mMaxPowerAllocationInMW = value;
41     }
42 
getMaxPowerAllocationInMW()43     public double getMaxPowerAllocationInMW() {
44         return mMaxPowerAllocationInMW;
45     }
46 
setPeriodInNS(long value)47     public void setPeriodInNS(long value) {
48         mPeriodInNS = value;
49     }
50 
getPeriodInNS()51     public long getPeriodInNS() {
52         return mPeriodInNS;
53     }
54 
setSmallestDisplacementMeters(float value)55     public void setSmallestDisplacementMeters(float value) {
56         mSmallestDisplacementMeters = value;
57     }
58 
getSmallestDisplacementMeters()59     public float getSmallestDisplacementMeters() {
60         return mSmallestDisplacementMeters;
61     }
62 
setSourceToUse(int source)63     public void setSourceToUse(int source) {
64         mSourcesToUse |= source;
65     }
66 
resetSourceToUse(int source)67     public void resetSourceToUse(int source) {
68         mSourcesToUse &= ~source;
69     }
70 
isSourceToUseSet(int source)71     public boolean isSourceToUseSet(int source) {
72         return (mSourcesToUse & source) != 0;
73     }
74 
getSourcesToUse()75     public int getSourcesToUse() {
76         return mSourcesToUse;
77     }
78 
setFlag(int flag)79     public void setFlag(int flag) {
80         mFlags |= flag;
81     }
82 
resetFlag(int flag)83     public void resetFlag(int flag) {
84         mFlags &= ~flag;
85     }
86 
isFlagSet(int flag)87     public boolean isFlagSet(int flag) {
88         return (mFlags & flag) != 0;
89     }
90 
getFlags()91     public int getFlags() {
92         return mFlags;
93     }
94 
95     /**
96      * Definition of enum flag sets needed by this class.
97      * Such values need to be kept in sync with the ones in fused_location.h
98      */
99     public static final class SourceTechnologies {
100         public static int GNSS = 1<<0;
101         public static int WIFI = 1<<1;
102         public static int SENSORS = 1<<2;
103         public static int CELL = 1<<3;
104         public static int BLUETOOTH = 1<<4;
105     }
106 
107     public static final class BatchFlags {
108         // follow the definitions to the letter in fused_location.h
109         public static int WAKEUP_ON_FIFO_FULL = 0x0000001;
110         public static int CALLBACK_ON_LOCATION_FIX =0x0000002;
111     }
112 
113     /*
114      * Method definitions to support Parcelable operations.
115      */
116     public static final @android.annotation.NonNull Parcelable.Creator<FusedBatchOptions> CREATOR =
117             new Parcelable.Creator<FusedBatchOptions>() {
118         @Override
119         public FusedBatchOptions createFromParcel(Parcel parcel) {
120             FusedBatchOptions options = new FusedBatchOptions();
121             options.setMaxPowerAllocationInMW(parcel.readDouble());
122             options.setPeriodInNS(parcel.readLong());
123             options.setSourceToUse(parcel.readInt());
124             options.setFlag(parcel.readInt());
125             options.setSmallestDisplacementMeters(parcel.readFloat());
126             return options;
127         }
128 
129         @Override
130         public FusedBatchOptions[] newArray(int size) {
131             return new FusedBatchOptions[size];
132         }
133     };
134 
135     @Override
describeContents()136     public int describeContents() {
137         return 0;
138     }
139 
140     @Override
writeToParcel(Parcel parcel, int flags)141     public void writeToParcel(Parcel parcel, int flags) {
142         parcel.writeDouble(mMaxPowerAllocationInMW);
143         parcel.writeLong(mPeriodInNS);
144         parcel.writeInt(mSourcesToUse);
145         parcel.writeInt(mFlags);
146         parcel.writeFloat(mSmallestDisplacementMeters);
147     }
148 }
149