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