1 /*
2  * Copyright (C) 2012 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 com.android.internal.location;
18 
19 import android.os.Parcel;
20 import android.os.Parcelable;
21 
22 /**
23  * A Parcelable containing (legacy) location provider properties.
24  * This object is just used inside the framework and system services.
25  * @hide
26  */
27 public final class ProviderProperties implements Parcelable {
28     /**
29      * True if provider requires access to a
30      * data network (e.g., the Internet), false otherwise.
31      */
32     public final boolean mRequiresNetwork;
33 
34     /**
35      * True if the provider requires access to a
36      * satellite-based positioning system (e.g., GPS), false
37      * otherwise.
38      */
39     public final boolean mRequiresSatellite;
40 
41     /**
42      * True if the provider requires access to an appropriate
43      * cellular network (e.g., to make use of cell tower IDs), false
44      * otherwise.
45      */
46     public final boolean mRequiresCell;
47 
48     /**
49      * True if the use of this provider may result in a
50      * monetary charge to the user, false if use is free.  It is up to
51      * each provider to give accurate information. Cell (network) usage
52      * is not considered monetary cost.
53      */
54     public final boolean mHasMonetaryCost;
55 
56     /**
57      * True if the provider is able to provide altitude
58      * information, false otherwise.  A provider that reports altitude
59      * under most circumstances but may occasionally not report it
60      * should return true.
61      */
62     public final boolean mSupportsAltitude;
63 
64     /**
65      * True if the provider is able to provide speed
66      * information, false otherwise.  A provider that reports speed
67      * under most circumstances but may occasionally not report it
68      * should return true.
69      */
70     public final boolean mSupportsSpeed;
71 
72     /**
73      * True if the provider is able to provide bearing
74      * information, false otherwise.  A provider that reports bearing
75      * under most circumstances but may occasionally not report it
76      * should return true.
77      */
78     public final boolean mSupportsBearing;
79 
80     /**
81      * Power requirement for this provider.
82      *
83      * @return the power requirement for this provider, as one of the
84      * constants Criteria.POWER_*.
85      */
86     public final int mPowerRequirement;
87 
88     /**
89      * Constant describing the horizontal accuracy returned
90      * by this provider.
91      *
92      * @return the horizontal accuracy for this provider, as one of the
93      * constants Criteria.ACCURACY_COARSE or Criteria.ACCURACY_FINE
94      */
95     public final int mAccuracy;
96 
ProviderProperties(boolean mRequiresNetwork, boolean mRequiresSatellite, boolean mRequiresCell, boolean mHasMonetaryCost, boolean mSupportsAltitude, boolean mSupportsSpeed, boolean mSupportsBearing, int mPowerRequirement, int mAccuracy)97     public ProviderProperties(boolean mRequiresNetwork,
98             boolean mRequiresSatellite, boolean mRequiresCell, boolean mHasMonetaryCost,
99             boolean mSupportsAltitude, boolean mSupportsSpeed, boolean mSupportsBearing,
100             int mPowerRequirement, int mAccuracy) {
101         this.mRequiresNetwork = mRequiresNetwork;
102         this.mRequiresSatellite = mRequiresSatellite;
103         this.mRequiresCell = mRequiresCell;
104         this.mHasMonetaryCost = mHasMonetaryCost;
105         this.mSupportsAltitude = mSupportsAltitude;
106         this.mSupportsSpeed = mSupportsSpeed;
107         this.mSupportsBearing = mSupportsBearing;
108         this.mPowerRequirement = mPowerRequirement;
109         this.mAccuracy = mAccuracy;
110     }
111 
112     public static final Parcelable.Creator<ProviderProperties> CREATOR =
113             new Parcelable.Creator<ProviderProperties>() {
114         @Override
115         public ProviderProperties createFromParcel(Parcel in) {
116             boolean requiresNetwork = in.readInt() == 1;
117             boolean requiresSatellite = in.readInt() == 1;
118             boolean requiresCell = in.readInt() == 1;
119             boolean hasMonetaryCost = in.readInt() == 1;
120             boolean supportsAltitude = in.readInt() == 1;
121             boolean supportsSpeed = in.readInt() == 1;
122             boolean supportsBearing = in.readInt() == 1;
123             int powerRequirement = in.readInt();
124             int accuracy = in.readInt();
125             return new ProviderProperties(requiresNetwork, requiresSatellite,
126                     requiresCell, hasMonetaryCost, supportsAltitude, supportsSpeed, supportsBearing,
127                     powerRequirement, accuracy);
128         }
129         @Override
130         public ProviderProperties[] newArray(int size) {
131             return new ProviderProperties[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.writeInt(mRequiresNetwork ? 1 : 0);
143         parcel.writeInt(mRequiresSatellite ? 1 : 0);
144         parcel.writeInt(mRequiresCell ? 1 : 0);
145         parcel.writeInt(mHasMonetaryCost ? 1 : 0);
146         parcel.writeInt(mSupportsAltitude ? 1 : 0);
147         parcel.writeInt(mSupportsSpeed ? 1 : 0);
148         parcel.writeInt(mSupportsBearing ? 1 : 0);
149         parcel.writeInt(mPowerRequirement);
150         parcel.writeInt(mAccuracy);
151     }
152 }
153