Mike Lockwood | a4903f2 | 2010-02-17 06:42:23 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 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 | |
Mike Lockwood | 00b7427 | 2010-03-26 10:41:48 -0400 | [diff] [blame] | 17 | package com.android.server.location; |
Mike Lockwood | a4903f2 | 2010-02-17 06:42:23 -0500 | [diff] [blame] | 18 | |
Soonil Nagarkar | 17d8c83 | 2020-01-29 18:02:53 -0800 | [diff] [blame] | 19 | import static com.android.internal.util.ConcurrentUtils.DIRECT_EXECUTOR; |
| 20 | |
Soonil Nagarkar | 0d77ea6 | 2019-01-31 14:36:56 -0800 | [diff] [blame] | 21 | import android.content.Context; |
Mike Lockwood | 03ca216 | 2010-04-01 08:10:09 -0700 | [diff] [blame] | 22 | import android.location.Criteria; |
Mike Lockwood | a4903f2 | 2010-02-17 06:42:23 -0500 | [diff] [blame] | 23 | import android.location.Location; |
Soonil Nagarkar | 17d8c83 | 2020-01-29 18:02:53 -0800 | [diff] [blame] | 24 | import android.os.Bundle; |
Mike Lockwood | a4903f2 | 2010-02-17 06:42:23 -0500 | [diff] [blame] | 25 | |
Soonil Nagarkar | 94749f7 | 2018-11-08 11:46:43 -0800 | [diff] [blame] | 26 | import com.android.internal.location.ProviderProperties; |
| 27 | import com.android.internal.location.ProviderRequest; |
| 28 | |
| 29 | import java.io.FileDescriptor; |
| 30 | import java.io.PrintWriter; |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 31 | |
Mike Lockwood | a4903f2 | 2010-02-17 06:42:23 -0500 | [diff] [blame] | 32 | /** |
| 33 | * A passive location provider reports locations received from other providers |
| 34 | * for clients that want to listen passively without actually triggering |
| 35 | * location updates. |
| 36 | * |
| 37 | * {@hide} |
| 38 | */ |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 39 | public class PassiveProvider extends AbstractLocationProvider { |
Mike Lockwood | a4903f2 | 2010-02-17 06:42:23 -0500 | [diff] [blame] | 40 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 41 | private static final ProviderProperties PROPERTIES = new ProviderProperties( |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 42 | /* requiresNetwork = */false, |
| 43 | /* requiresSatellite = */false, |
| 44 | /* requiresCell = */false, |
| 45 | /* hasMonetaryCost = */false, |
| 46 | /* supportsAltitude = */false, |
| 47 | /* supportsSpeed = */false, |
| 48 | /* supportsBearing = */false, |
| 49 | Criteria.POWER_LOW, |
| 50 | Criteria.ACCURACY_COARSE); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 51 | |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 52 | private volatile boolean mReportLocation; |
Mike Lockwood | a4903f2 | 2010-02-17 06:42:23 -0500 | [diff] [blame] | 53 | |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 54 | public PassiveProvider(Context context) { |
Soonil Nagarkar | 17d8c83 | 2020-01-29 18:02:53 -0800 | [diff] [blame] | 55 | // using a direct executor is ok because this class has no locks that could deadlock |
| 56 | super(DIRECT_EXECUTOR, context); |
Mike Lockwood | a4903f2 | 2010-02-17 06:42:23 -0500 | [diff] [blame] | 57 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 58 | mReportLocation = false; |
Mike Lockwood | a4903f2 | 2010-02-17 06:42:23 -0500 | [diff] [blame] | 59 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 60 | setProperties(PROPERTIES); |
Soonil Nagarkar | 980ce6a | 2020-01-23 18:06:31 -0800 | [diff] [blame] | 61 | setAllowed(true); |
Mike Lockwood | a4903f2 | 2010-02-17 06:42:23 -0500 | [diff] [blame] | 62 | } |
| 63 | |
Soonil Nagarkar | 17d8c83 | 2020-01-29 18:02:53 -0800 | [diff] [blame] | 64 | /** |
| 65 | * Pass a location into the passive provider. |
| 66 | */ |
| 67 | public void updateLocation(Location location) { |
| 68 | if (mReportLocation) { |
| 69 | reportLocation(location); |
| 70 | } |
| 71 | } |
| 72 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 73 | @Override |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 74 | public void onSetRequest(ProviderRequest request) { |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 75 | mReportLocation = request.reportLocation; |
Mike Lockwood | a4903f2 | 2010-02-17 06:42:23 -0500 | [diff] [blame] | 76 | } |
| 77 | |
Soonil Nagarkar | 17d8c83 | 2020-01-29 18:02:53 -0800 | [diff] [blame] | 78 | @Override |
| 79 | protected void onExtraCommand(int uid, int pid, String command, Bundle extras) {} |
| 80 | |
| 81 | @Override |
| 82 | protected void onRequestSetAllowed(boolean allowed) { |
| 83 | // do nothing - the passive provider is always allowed |
Mike Lockwood | a4903f2 | 2010-02-17 06:42:23 -0500 | [diff] [blame] | 84 | } |
| 85 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 86 | @Override |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 87 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {} |
Mike Lockwood | a4903f2 | 2010-02-17 06:42:23 -0500 | [diff] [blame] | 88 | } |