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 17 package com.android.server.location; 18 19 import static com.android.internal.util.ConcurrentUtils.DIRECT_EXECUTOR; 20 21 import android.annotation.Nullable; 22 import android.location.Location; 23 import android.os.Bundle; 24 25 import com.android.internal.location.ProviderProperties; 26 import com.android.internal.location.ProviderRequest; 27 28 import java.io.FileDescriptor; 29 import java.io.PrintWriter; 30 import java.util.Collections; 31 32 /** 33 * A mock location provider used by LocationManagerService to implement test providers. 34 * 35 * {@hide} 36 */ 37 public class MockProvider extends AbstractLocationProvider { 38 39 @Nullable private Location mLocation; 40 MockProvider(ProviderProperties properties)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()); 44 setProperties(properties); 45 } 46 47 /** Sets the allowed state of this mock provider. */ setProviderAllowed(boolean allowed)48 public void setProviderAllowed(boolean allowed) { 49 setAllowed(allowed); 50 } 51 52 /** Sets the location to report for this mock provider. */ setProviderLocation(Location l)53 public void setProviderLocation(Location l) { 54 Location location = new Location(l); 55 location.setIsFromMockProvider(true); 56 mLocation = location; 57 reportLocation(location); 58 } 59 60 @Override onSetRequest(ProviderRequest request)61 public void onSetRequest(ProviderRequest request) {} 62 63 @Override onExtraCommand(int uid, int pid, String command, Bundle extras)64 protected void onExtraCommand(int uid, int pid, String command, Bundle extras) {} 65 66 @Override dump(FileDescriptor fd, PrintWriter pw, String[] args)67 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { 68 pw.println("last mock location=" + mLocation); 69 } 70 } 71