Mike Lockwood | 7ec434e | 2009-03-27 07:46:48 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009 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 | 7ec434e | 2009-03-27 07:46:48 -0700 | [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 | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 21 | import android.annotation.Nullable; |
Mike Lockwood | 7ec434e | 2009-03-27 07:46:48 -0700 | [diff] [blame] | 22 | import android.location.Location; |
Soonil Nagarkar | 17d8c83 | 2020-01-29 18:02:53 -0800 | [diff] [blame] | 23 | import android.os.Bundle; |
Mike Lockwood | 7ec434e | 2009-03-27 07:46:48 -0700 | [diff] [blame] | 24 | |
Soonil Nagarkar | 94749f7 | 2018-11-08 11:46:43 -0800 | [diff] [blame] | 25 | import com.android.internal.location.ProviderProperties; |
| 26 | import com.android.internal.location.ProviderRequest; |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 27 | |
| 28 | import java.io.FileDescriptor; |
Mike Lockwood | 7ec434e | 2009-03-27 07:46:48 -0700 | [diff] [blame] | 29 | import java.io.PrintWriter; |
Soonil Nagarkar | 17d8c83 | 2020-01-29 18:02:53 -0800 | [diff] [blame] | 30 | import java.util.Collections; |
Mike Lockwood | 7ec434e | 2009-03-27 07:46:48 -0700 | [diff] [blame] | 31 | |
| 32 | /** |
| 33 | * A mock location provider used by LocationManagerService to implement test providers. |
| 34 | * |
| 35 | * {@hide} |
| 36 | */ |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 37 | public class MockProvider extends AbstractLocationProvider { |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 38 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 39 | @Nullable private Location mLocation; |
Mike Lockwood | 7ec434e | 2009-03-27 07:46:48 -0700 | [diff] [blame] | 40 | |
Soonil Nagarkar | 17d8c83 | 2020-01-29 18:02:53 -0800 | [diff] [blame] | 41 | public MockProvider(ProviderProperties properties) { |
| 42 | // using a direct executor is ok because this class has no locks that could deadlock |
| 43 | super(DIRECT_EXECUTOR, Collections.emptySet()); |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 44 | setProperties(properties); |
| 45 | } |
| 46 | |
Soonil Nagarkar | 980ce6a | 2020-01-23 18:06:31 -0800 | [diff] [blame] | 47 | /** Sets the allowed state of this mock provider. */ |
| 48 | public void setProviderAllowed(boolean allowed) { |
| 49 | setAllowed(allowed); |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | /** Sets the location to report for this mock provider. */ |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 53 | public void setProviderLocation(Location l) { |
| 54 | Location location = new Location(l); |
| 55 | location.setIsFromMockProvider(true); |
| 56 | mLocation = location; |
| 57 | reportLocation(location); |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 58 | } |
| 59 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 60 | @Override |
Soonil Nagarkar | 980ce6a | 2020-01-23 18:06:31 -0800 | [diff] [blame] | 61 | public void onSetRequest(ProviderRequest request) {} |
| 62 | |
| 63 | @Override |
Soonil Nagarkar | 17d8c83 | 2020-01-29 18:02:53 -0800 | [diff] [blame] | 64 | protected void onExtraCommand(int uid, int pid, String command, Bundle extras) {} |
| 65 | |
| 66 | @Override |
Soonil Nagarkar | 980ce6a | 2020-01-23 18:06:31 -0800 | [diff] [blame] | 67 | protected void onRequestSetAllowed(boolean allowed) { |
| 68 | setAllowed(allowed); |
Mike Lockwood | d03ff94 | 2010-02-09 08:46:14 -0500 | [diff] [blame] | 69 | } |
| 70 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 71 | @Override |
Soonil Nagarkar | 980ce6a | 2020-01-23 18:06:31 -0800 | [diff] [blame] | 72 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 73 | pw.println("last mock location=" + mLocation); |
| 74 | } |
Mike Lockwood | 7ec434e | 2009-03-27 07:46:48 -0700 | [diff] [blame] | 75 | } |