1 /* 2 * Copyright (C) 2007 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.annotation.Nullable; 20 import android.location.provider.ProviderProperties; 21 22 /** 23 * Information about the properties of a location provider. 24 * 25 * @deprecated This class is incapable of representing unknown provider properties and may return 26 * incorrect results on the rare occasion when a provider's properties are unknown. Prefer using 27 * {@link LocationManager#getProviderProperties(String)} to retrieve {@link ProviderProperties} 28 * instead. 29 */ 30 @Deprecated 31 public class LocationProvider { 32 33 /** 34 * @deprecated Location provider statuses are no longer supported. 35 */ 36 @Deprecated 37 public static final int OUT_OF_SERVICE = 0; 38 39 /** 40 * @deprecated Location provider statuses are no longer supported. 41 */ 42 @Deprecated 43 public static final int TEMPORARILY_UNAVAILABLE = 1; 44 45 /** 46 * @deprecated Location provider statuses are no longer supported. 47 */ 48 @Deprecated 49 public static final int AVAILABLE = 2; 50 51 private final String mName; 52 private final @Nullable ProviderProperties mProperties; 53 LocationProvider(String name, @Nullable ProviderProperties properties)54 LocationProvider(String name, @Nullable ProviderProperties properties) { 55 mName = name; 56 mProperties = properties; 57 } 58 59 /** 60 * Returns the name of this provider. 61 */ getName()62 public String getName() { 63 return mName; 64 } 65 66 /** 67 * Returns true if this provider meets the given criteria, 68 * false otherwise. 69 */ meetsCriteria(Criteria criteria)70 public boolean meetsCriteria(Criteria criteria) { 71 return propertiesMeetCriteria(mName, mProperties, criteria); 72 } 73 74 /** 75 * @hide 76 */ propertiesMeetCriteria(String name, ProviderProperties properties, Criteria criteria)77 public static boolean propertiesMeetCriteria(String name, ProviderProperties properties, 78 Criteria criteria) { 79 if (LocationManager.PASSIVE_PROVIDER.equals(name)) { 80 // passive provider never matches 81 return false; 82 } 83 if (properties == null) { 84 // unfortunately this can happen for provider in remote services 85 // that have not finished binding yet 86 return false; 87 } 88 89 if (criteria.getAccuracy() != Criteria.NO_REQUIREMENT && 90 criteria.getAccuracy() < properties.getAccuracy()) { 91 return false; 92 } 93 if (criteria.getPowerRequirement() != Criteria.NO_REQUIREMENT && 94 criteria.getPowerRequirement() < properties.getPowerUsage()) { 95 return false; 96 } 97 if (criteria.isAltitudeRequired() && !properties.hasAltitudeSupport()) { 98 return false; 99 } 100 if (criteria.isSpeedRequired() && !properties.hasSpeedSupport()) { 101 return false; 102 } 103 if (criteria.isBearingRequired() && !properties.hasBearingSupport()) { 104 return false; 105 } 106 if (!criteria.isCostAllowed() && properties.hasMonetaryCost()) { 107 return false; 108 } 109 return true; 110 } 111 112 /** 113 * Returns true if the provider requires access to a 114 * data network (e.g., the Internet), false otherwise. 115 */ requiresNetwork()116 public boolean requiresNetwork() { 117 if (mProperties == null) { 118 return false; 119 } else { 120 return mProperties.hasNetworkRequirement(); 121 } 122 } 123 124 /** 125 * Returns true if the provider requires access to a 126 * satellite-based positioning system (e.g., GPS), false 127 * otherwise. 128 */ requiresSatellite()129 public boolean requiresSatellite() { 130 if (mProperties == null) { 131 return false; 132 } else { 133 return mProperties.hasSatelliteRequirement(); 134 } 135 } 136 137 /** 138 * Returns true if the provider requires access to an appropriate 139 * cellular network (e.g., to make use of cell tower IDs), false 140 * otherwise. 141 */ requiresCell()142 public boolean requiresCell() { 143 if (mProperties == null) { 144 return false; 145 } else { 146 return mProperties.hasCellRequirement(); 147 } 148 } 149 150 /** 151 * Returns true if the use of this provider may result in a 152 * monetary charge to the user, false if use is free. It is up to 153 * each provider to give accurate information. 154 */ hasMonetaryCost()155 public boolean hasMonetaryCost() { 156 if (mProperties == null) { 157 return false; 158 } else { 159 return mProperties.hasMonetaryCost(); 160 } 161 } 162 163 /** 164 * Returns true if the provider is able to provide altitude 165 * information, false otherwise. A provider that reports altitude 166 * under most circumstances but may occassionally not report it 167 * should return true. 168 */ supportsAltitude()169 public boolean supportsAltitude() { 170 if (mProperties == null) { 171 return false; 172 } else { 173 return mProperties.hasAltitudeSupport(); 174 } 175 } 176 177 /** 178 * Returns true if the provider is able to provide speed 179 * information, false otherwise. A provider that reports speed 180 * under most circumstances but may occassionally not report it 181 * should return true. 182 */ supportsSpeed()183 public boolean supportsSpeed() { 184 if (mProperties == null) { 185 return false; 186 } else { 187 return mProperties.hasSpeedSupport(); 188 } 189 } 190 191 /** 192 * Returns true if the provider is able to provide bearing 193 * information, false otherwise. A provider that reports bearing 194 * under most circumstances but may occassionally not report it 195 * should return true. 196 */ supportsBearing()197 public boolean supportsBearing() { 198 if (mProperties == null) { 199 return false; 200 } else { 201 return mProperties.hasBearingSupport(); 202 } 203 } 204 205 /** 206 * Returns the power requirement for this provider, one of the ProviderProperties.POWER_USAGE_* 207 * constants. 208 */ getPowerRequirement()209 public int getPowerRequirement() { 210 if (mProperties == null) { 211 return ProviderProperties.POWER_USAGE_HIGH; 212 } else { 213 return mProperties.getPowerUsage(); 214 } 215 } 216 217 /** 218 * Returns the rough accuracy of this provider, one of the ProviderProperties.ACCURACY_* 219 * constants. 220 */ getAccuracy()221 public int getAccuracy() { 222 if (mProperties == null) { 223 return ProviderProperties.ACCURACY_COARSE; 224 } else { 225 return mProperties.getAccuracy(); 226 } 227 } 228 } 229