blob: b45b66017062894af1c193ea004c98a1207babd7 [file] [log] [blame]
Mike Lockwood7ec434e2009-03-27 07:46:48 -07001/*
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 Lockwood00b74272010-03-26 10:41:48 -040017package com.android.server.location;
Mike Lockwood7ec434e2009-03-27 07:46:48 -070018
Soonil Nagarkar17d8c832020-01-29 18:02:53 -080019import static com.android.internal.util.ConcurrentUtils.DIRECT_EXECUTOR;
20
Soonil Nagarkar1575a042018-10-24 17:54:54 -070021import android.annotation.Nullable;
Mike Lockwood7ec434e2009-03-27 07:46:48 -070022import android.location.Location;
Soonil Nagarkar17d8c832020-01-29 18:02:53 -080023import android.os.Bundle;
Mike Lockwood7ec434e2009-03-27 07:46:48 -070024
Soonil Nagarkar94749f72018-11-08 11:46:43 -080025import com.android.internal.location.ProviderProperties;
26import com.android.internal.location.ProviderRequest;
Nick Pelly6fa9ad42012-07-16 12:18:23 -070027
28import java.io.FileDescriptor;
Mike Lockwood7ec434e2009-03-27 07:46:48 -070029import java.io.PrintWriter;
Soonil Nagarkar17d8c832020-01-29 18:02:53 -080030import java.util.Collections;
Mike Lockwood7ec434e2009-03-27 07:46:48 -070031
32/**
33 * A mock location provider used by LocationManagerService to implement test providers.
34 *
35 * {@hide}
36 */
Soonil Nagarkar1575a042018-10-24 17:54:54 -070037public class MockProvider extends AbstractLocationProvider {
Nick Pelly6fa9ad42012-07-16 12:18:23 -070038
Soonil Nagarkar1575a042018-10-24 17:54:54 -070039 @Nullable private Location mLocation;
Mike Lockwood7ec434e2009-03-27 07:46:48 -070040
Soonil Nagarkar17d8c832020-01-29 18:02:53 -080041 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 Nagarkar1575a042018-10-24 17:54:54 -070044 setProperties(properties);
45 }
46
Soonil Nagarkar980ce6a2020-01-23 18:06:31 -080047 /** Sets the allowed state of this mock provider. */
48 public void setProviderAllowed(boolean allowed) {
49 setAllowed(allowed);
Soonil Nagarkar1575a042018-10-24 17:54:54 -070050 }
51
52 /** Sets the location to report for this mock provider. */
Soonil Nagarkar8df02f42020-01-08 13:23:26 -080053 public void setProviderLocation(Location l) {
54 Location location = new Location(l);
55 location.setIsFromMockProvider(true);
56 mLocation = location;
57 reportLocation(location);
Soonil Nagarkar1575a042018-10-24 17:54:54 -070058 }
59
Nick Pelly6fa9ad42012-07-16 12:18:23 -070060 @Override
Soonil Nagarkar980ce6a2020-01-23 18:06:31 -080061 public void onSetRequest(ProviderRequest request) {}
62
63 @Override
Soonil Nagarkar17d8c832020-01-29 18:02:53 -080064 protected void onExtraCommand(int uid, int pid, String command, Bundle extras) {}
65
66 @Override
Soonil Nagarkar980ce6a2020-01-23 18:06:31 -080067 protected void onRequestSetAllowed(boolean allowed) {
68 setAllowed(allowed);
Mike Lockwoodd03ff942010-02-09 08:46:14 -050069 }
70
Nick Pelly6fa9ad42012-07-16 12:18:23 -070071 @Override
Soonil Nagarkar980ce6a2020-01-23 18:06:31 -080072 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
73 pw.println("last mock location=" + mLocation);
74 }
Mike Lockwood7ec434e2009-03-27 07:46:48 -070075}