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 
34     /*
35      * Getters and setters for properties needed to hold the options.
36      */
setMaxPowerAllocationInMW(double value)37     public void setMaxPowerAllocationInMW(double value) {
38         mMaxPowerAllocationInMW = value;
39     }
40 
getMaxPowerAllocationInMW()41     public double getMaxPowerAllocationInMW() {
42         return mMaxPowerAllocationInMW;
43     }
44 
setPeriodInNS(long value)45     public void setPeriodInNS(long value) {
46         mPeriodInNS = value;
47     }
48 
getPeriodInNS()49     public long getPeriodInNS() {
50         return mPeriodInNS;
51     }
52 
setSourceToUse(int source)53     public void setSourceToUse(int source) {
54         mSourcesToUse |= source;
55     }
56 
resetSourceToUse(int source)57     public void resetSourceToUse(int source) {
58         mSourcesToUse &= ~source;
59     }
60 
isSourceToUseSet(int source)61     public boolean isSourceToUseSet(int source) {
62         return (mSourcesToUse & source) != 0;
63     }
64 
getSourcesToUse()65     public int getSourcesToUse() {
66         return mSourcesToUse;
67     }
68 
setFlag(int flag)69     public void setFlag(int flag) {
70         mFlags |= flag;
71     }
72 
resetFlag(int flag)73     public void resetFlag(int flag) {
74         mFlags &= ~flag;
75     }
76 
isFlagSet(int flag)77     public boolean isFlagSet(int flag) {
78         return (mFlags & flag) != 0;
79     }
80 
getFlags()81     public int getFlags() {
82         return mFlags;
83     }
84 
85     /**
86      * Definition of enum flag sets needed by this class.
87      * Such values need to be kept in sync with the ones in fused_location.h
88      */
89     public static final class SourceTechnologies {
90         public static int GNSS = 1<<0;
91         public static int WIFI = 1<<1;
92         public static int SENSORS = 1<<2;
93         public static int CELL = 1<<3;
94         public static int BLUETOOTH = 1<<4;
95     }
96 
97     public static final class BatchFlags {
98         // follow the definitions to the letter in fused_location.h
99         public static int WAKEUP_ON_FIFO_FULL = 0x0000001;
100         public static int CALLBACK_ON_LOCATION_FIX =0x0000002;
101     }
102 
103     /*
104      * Method definitions to support Parcelable operations.
105      */
106     public static final Parcelable.Creator<FusedBatchOptions> CREATOR =
107             new Parcelable.Creator<FusedBatchOptions>() {
108         @Override
109         public FusedBatchOptions createFromParcel(Parcel parcel) {
110             FusedBatchOptions options = new FusedBatchOptions();
111             options.setMaxPowerAllocationInMW(parcel.readDouble());
112             options.setPeriodInNS(parcel.readLong());
113             options.setSourceToUse(parcel.readInt());
114             options.setFlag(parcel.readInt());
115             return options;
116         }
117 
118         @Override
119         public FusedBatchOptions[] newArray(int size) {
120             return new FusedBatchOptions[size];
121         }
122     };
123 
124     @Override
describeContents()125     public int describeContents() {
126         return 0;
127     }
128 
129     @Override
writeToParcel(Parcel parcel, int flags)130     public void writeToParcel(Parcel parcel, int flags) {
131         parcel.writeDouble(mMaxPowerAllocationInMW);
132         parcel.writeLong(mPeriodInNS);
133         parcel.writeInt(mSourcesToUse);
134         parcel.writeInt(mFlags);
135     }
136 }
137