Home | History | Annotate | Download | only in location
      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      */
     37     public void setMaxPowerAllocationInMW(double value) {
     38         mMaxPowerAllocationInMW = value;
     39     }
     40 
     41     public double getMaxPowerAllocationInMW() {
     42         return mMaxPowerAllocationInMW;
     43     }
     44 
     45     public void setPeriodInNS(long value) {
     46         mPeriodInNS = value;
     47     }
     48 
     49     public long getPeriodInNS() {
     50         return mPeriodInNS;
     51     }
     52 
     53     public void setSourceToUse(int source) {
     54         mSourcesToUse |= source;
     55     }
     56 
     57     public void resetSourceToUse(int source) {
     58         mSourcesToUse &= ~source;
     59     }
     60 
     61     public boolean isSourceToUseSet(int source) {
     62         return (mSourcesToUse & source) != 0;
     63     }
     64 
     65     public int getSourcesToUse() {
     66         return mSourcesToUse;
     67     }
     68 
     69     public void setFlag(int flag) {
     70         mFlags |= flag;
     71     }
     72 
     73     public void resetFlag(int flag) {
     74         mFlags &= ~flag;
     75     }
     76 
     77     public boolean isFlagSet(int flag) {
     78         return (mFlags & flag) != 0;
     79     }
     80 
     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         public static int WAKEUP_ON_FIFO_FULL = 1<<0;
     99         public static int CALLBACK_ON_LOCATION_FIX = 1<<1;
    100     }
    101 
    102     /*
    103      * Method definitions to support Parcelable operations.
    104      */
    105     public static final Parcelable.Creator<FusedBatchOptions> CREATOR =
    106             new Parcelable.Creator<FusedBatchOptions>() {
    107         @Override
    108         public FusedBatchOptions createFromParcel(Parcel parcel) {
    109             FusedBatchOptions options = new FusedBatchOptions();
    110             options.setMaxPowerAllocationInMW(parcel.readDouble());
    111             options.setPeriodInNS(parcel.readLong());
    112             options.setSourceToUse(parcel.readInt());
    113             options.setFlag(parcel.readInt());
    114             return options;
    115         }
    116 
    117         @Override
    118         public FusedBatchOptions[] newArray(int size) {
    119             return new FusedBatchOptions[size];
    120         }
    121     };
    122 
    123     @Override
    124     public int describeContents() {
    125         return 0;
    126     }
    127 
    128     @Override
    129     public void writeToParcel(Parcel parcel, int flags) {
    130         parcel.writeDouble(mMaxPowerAllocationInMW);
    131         parcel.writeLong(mPeriodInNS);
    132         parcel.writeInt(mSourcesToUse);
    133         parcel.writeInt(mFlags);
    134     }
    135 }
    136