1 /* 2 * Copyright (C) 2017 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 android.location; 18 19 import android.content.Context; 20 import android.os.RemoteException; 21 22 import java.util.List; 23 24 /** 25 * A handler class to manage transport callbacks for {@link BatchedLocationCallback}. 26 * 27 * @hide 28 */ 29 class BatchedLocationCallbackTransport 30 extends LocalListenerHelper<BatchedLocationCallback> { 31 private final ILocationManager mLocationManager; 32 33 private final IBatchedLocationCallback mCallbackTransport = new CallbackTransport(); 34 BatchedLocationCallbackTransport(Context context, ILocationManager locationManager)35 public BatchedLocationCallbackTransport(Context context, ILocationManager locationManager) { 36 super(context, "BatchedLocationCallbackTransport"); 37 mLocationManager = locationManager; 38 } 39 40 @Override registerWithServer()41 protected boolean registerWithServer() throws RemoteException { 42 return mLocationManager.addGnssBatchingCallback( 43 mCallbackTransport, 44 getContext().getPackageName()); 45 } 46 47 @Override unregisterFromServer()48 protected void unregisterFromServer() throws RemoteException { 49 mLocationManager.removeGnssBatchingCallback(); 50 } 51 52 private class CallbackTransport extends IBatchedLocationCallback.Stub { 53 @Override onLocationBatch(final List<Location> locations)54 public void onLocationBatch(final List<Location> locations) { 55 ListenerOperation<BatchedLocationCallback> operation = 56 new ListenerOperation<BatchedLocationCallback>() { 57 @Override 58 public void execute(BatchedLocationCallback callback) 59 throws RemoteException { 60 callback.onLocationBatch(locations); 61 } 62 }; 63 foreach(operation); 64 } 65 } 66 } 67