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