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 callbacks for {@link GnssMeasurementsEvent.Callback}.
24  *
25  * @hide
26  */
27 class GnssMeasurementCallbackTransport
28         extends LocalListenerHelper<GnssMeasurementsEvent.Callback> {
29     private final ILocationManager mLocationManager;
30 
31     private final IGnssMeasurementsListener mListenerTransport = new ListenerTransport();
32 
GnssMeasurementCallbackTransport(Context context, ILocationManager locationManager)33     public GnssMeasurementCallbackTransport(Context context, ILocationManager locationManager) {
34         super(context, "GnssMeasurementListenerTransport");
35         mLocationManager = locationManager;
36     }
37 
38     @Override
registerWithServer()39     protected boolean registerWithServer() throws RemoteException {
40         return mLocationManager.addGnssMeasurementsListener(
41                 mListenerTransport,
42                 getContext().getPackageName());
43     }
44 
45     @Override
unregisterFromServer()46     protected void unregisterFromServer() throws RemoteException {
47         mLocationManager.removeGnssMeasurementsListener(mListenerTransport);
48     }
49 
50     private class ListenerTransport extends IGnssMeasurementsListener.Stub {
51         @Override
onGnssMeasurementsReceived(final GnssMeasurementsEvent event)52         public void onGnssMeasurementsReceived(final GnssMeasurementsEvent event) {
53             ListenerOperation<GnssMeasurementsEvent.Callback> operation =
54                     new ListenerOperation<GnssMeasurementsEvent.Callback>() {
55                 @Override
56                 public void execute(GnssMeasurementsEvent.Callback callback)
57                         throws RemoteException {
58                     callback.onGnssMeasurementsReceived(event);
59                 }
60             };
61             foreach(operation);
62         }
63 
64         @Override
onStatusChanged(final int status)65         public void onStatusChanged(final int status) {
66             ListenerOperation<GnssMeasurementsEvent.Callback> operation =
67                     new ListenerOperation<GnssMeasurementsEvent.Callback>() {
68                 @Override
69                 public void execute(GnssMeasurementsEvent.Callback callback)
70                         throws RemoteException {
71                     callback.onStatusChanged(status);
72                 }
73             };
74             foreach(operation);
75         }
76     }
77 }
78