blob: 1eafd02e52bea2d3487e5823fafc000873fd704c [file] [log] [blame]
Lifu Tang818aa2c2016-02-01 01:52:00 -08001/*
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/**
Lifu Tange8abe8e2016-04-01 10:32:05 -070023 * A handler class to manage transport callback for {@link GnssNavigationMessage.Callback}.
Lifu Tang818aa2c2016-02-01 01:52:00 -080024 *
25 * @hide
26 */
27class GnssNavigationMessageCallbackTransport
Lifu Tange8abe8e2016-04-01 10:32:05 -070028 extends LocalListenerHelper<GnssNavigationMessage.Callback> {
Lifu Tang818aa2c2016-02-01 01:52:00 -080029 private final ILocationManager mLocationManager;
30
31 private final IGnssNavigationMessageListener mListenerTransport = new ListenerTransport();
32
33 public GnssNavigationMessageCallbackTransport(
34 Context context,
35 ILocationManager locationManager) {
36 super(context, "GnssNavigationMessageCallbackTransport");
37 mLocationManager = locationManager;
38 }
39
40 @Override
41 protected boolean registerWithServer() throws RemoteException {
42 return mLocationManager.addGnssNavigationMessageListener(
43 mListenerTransport,
44 getContext().getPackageName());
45 }
46
47 @Override
48 protected void unregisterFromServer() throws RemoteException {
49 mLocationManager.removeGnssNavigationMessageListener(mListenerTransport);
50 }
51
52 private class ListenerTransport extends IGnssNavigationMessageListener.Stub {
53 @Override
Lifu Tange8abe8e2016-04-01 10:32:05 -070054 public void onGnssNavigationMessageReceived(final GnssNavigationMessage event) {
55 ListenerOperation<GnssNavigationMessage.Callback> operation =
56 new ListenerOperation<GnssNavigationMessage.Callback>() {
Lifu Tang818aa2c2016-02-01 01:52:00 -080057 @Override
Lifu Tange8abe8e2016-04-01 10:32:05 -070058 public void execute(GnssNavigationMessage.Callback callback)
Lifu Tang818aa2c2016-02-01 01:52:00 -080059 throws RemoteException {
60 callback.onGnssNavigationMessageReceived(event);
61 }
62 };
63 foreach(operation);
64 }
65
66 @Override
67 public void onStatusChanged(final int status) {
Lifu Tange8abe8e2016-04-01 10:32:05 -070068 ListenerOperation<GnssNavigationMessage.Callback> operation =
69 new ListenerOperation<GnssNavigationMessage.Callback>() {
Lifu Tang818aa2c2016-02-01 01:52:00 -080070 @Override
Lifu Tange8abe8e2016-04-01 10:32:05 -070071 public void execute(GnssNavigationMessage.Callback callback)
Lifu Tang818aa2c2016-02-01 01:52:00 -080072 throws RemoteException {
73 callback.onStatusChanged(status);
74 }
75 };
76 foreach(operation);
77 }
78 }
79}