blob: 54dffff8b1df63324e042f0b88688ea4050b557c [file] [log] [blame]
Mike Lockwooda4903f22010-02-17 06:42:23 -05001/*
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 Lockwood00b74272010-03-26 10:41:48 -040017package com.android.server.location;
Mike Lockwooda4903f22010-02-17 06:42:23 -050018
Soonil Nagarkar17d8c832020-01-29 18:02:53 -080019import static com.android.internal.util.ConcurrentUtils.DIRECT_EXECUTOR;
20
Soonil Nagarkar0d77ea62019-01-31 14:36:56 -080021import android.content.Context;
Mike Lockwood03ca2162010-04-01 08:10:09 -070022import android.location.Criteria;
Mike Lockwooda4903f22010-02-17 06:42:23 -050023import android.location.Location;
Soonil Nagarkar17d8c832020-01-29 18:02:53 -080024import android.os.Bundle;
Mike Lockwooda4903f22010-02-17 06:42:23 -050025
Soonil Nagarkar94749f72018-11-08 11:46:43 -080026import com.android.internal.location.ProviderProperties;
27import com.android.internal.location.ProviderRequest;
28
29import java.io.FileDescriptor;
30import java.io.PrintWriter;
Nick Pelly6fa9ad42012-07-16 12:18:23 -070031
Mike Lockwooda4903f22010-02-17 06:42:23 -050032/**
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 Nagarkar1575a042018-10-24 17:54:54 -070039public class PassiveProvider extends AbstractLocationProvider {
Mike Lockwooda4903f22010-02-17 06:42:23 -050040
Nick Pelly6fa9ad42012-07-16 12:18:23 -070041 private static final ProviderProperties PROPERTIES = new ProviderProperties(
Soonil Nagarkar8df02f42020-01-08 13:23:26 -080042 /* 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 Pelly6fa9ad42012-07-16 12:18:23 -070051
Soonil Nagarkar8df02f42020-01-08 13:23:26 -080052 private volatile boolean mReportLocation;
Mike Lockwooda4903f22010-02-17 06:42:23 -050053
Soonil Nagarkar8df02f42020-01-08 13:23:26 -080054 public PassiveProvider(Context context) {
Soonil Nagarkar17d8c832020-01-29 18:02:53 -080055 // using a direct executor is ok because this class has no locks that could deadlock
56 super(DIRECT_EXECUTOR, context);
Mike Lockwooda4903f22010-02-17 06:42:23 -050057
Soonil Nagarkar1575a042018-10-24 17:54:54 -070058 mReportLocation = false;
Mike Lockwooda4903f22010-02-17 06:42:23 -050059
Soonil Nagarkar1575a042018-10-24 17:54:54 -070060 setProperties(PROPERTIES);
Soonil Nagarkar980ce6a2020-01-23 18:06:31 -080061 setAllowed(true);
Mike Lockwooda4903f22010-02-17 06:42:23 -050062 }
63
Soonil Nagarkar17d8c832020-01-29 18:02:53 -080064 /**
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 Pelly6fa9ad42012-07-16 12:18:23 -070073 @Override
Soonil Nagarkar8df02f42020-01-08 13:23:26 -080074 public void onSetRequest(ProviderRequest request) {
Nick Pelly6fa9ad42012-07-16 12:18:23 -070075 mReportLocation = request.reportLocation;
Mike Lockwooda4903f22010-02-17 06:42:23 -050076 }
77
Soonil Nagarkar17d8c832020-01-29 18:02:53 -080078 @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 Lockwooda4903f22010-02-17 06:42:23 -050084 }
85
Nick Pelly6fa9ad42012-07-16 12:18:23 -070086 @Override
Soonil Nagarkar8df02f42020-01-08 13:23:26 -080087 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {}
Mike Lockwooda4903f22010-02-17 06:42:23 -050088}