GpsMeasurementListenerTransport.java revision 6568d709e78d6ccaf256b7d0e4a19cdfb26deafb
1/* 2 * Copyright (C) 2014 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 17package android.location; 18 19import android.content.Context; 20import android.os.RemoteException; 21 22/** 23 * A handler class to manage transport listeners for {@link GpsMeasurementsEvent.Listener}. 24 * 25 * @hide 26 */ 27class GpsMeasurementListenerTransport 28 extends LocalListenerHelper<GpsMeasurementsEvent.Listener> { 29 private final ILocationManager mLocationManager; 30 31 private final IGpsMeasurementsListener mListenerTransport = new ListenerTransport(); 32 33 public GpsMeasurementListenerTransport(Context context, ILocationManager locationManager) { 34 super(context, "GpsMeasurementListenerTransport"); 35 mLocationManager = locationManager; 36 } 37 38 @Override 39 protected boolean registerWithServer() throws RemoteException { 40 return mLocationManager.addGpsMeasurementsListener( 41 mListenerTransport, 42 getContext().getPackageName()); 43 } 44 45 @Override 46 protected void unregisterFromServer() throws RemoteException { 47 mLocationManager.removeGpsMeasurementsListener(mListenerTransport); 48 } 49 50 private class ListenerTransport extends IGpsMeasurementsListener.Stub { 51 @Override 52 public void onGpsMeasurementsReceived(final GpsMeasurementsEvent event) { 53 ListenerOperation<GpsMeasurementsEvent.Listener> operation = 54 new ListenerOperation<GpsMeasurementsEvent.Listener>() { 55 @Override 56 public void execute(GpsMeasurementsEvent.Listener listener) throws RemoteException { 57 listener.onGpsMeasurementsReceived(event); 58 } 59 }; 60 foreach(operation); 61 } 62 63 @Override 64 public void onStatusChanged(final int status) { 65 ListenerOperation<GpsMeasurementsEvent.Listener> operation = 66 new ListenerOperation<GpsMeasurementsEvent.Listener>() { 67 @Override 68 public void execute(GpsMeasurementsEvent.Listener listener) throws RemoteException { 69 listener.onStatusChanged(status); 70 } 71 }; 72 foreach(operation); 73 } 74 } 75} 76