blob: 124220f17f1f648044b0625083bc2fb50df091a7 [file] [log] [blame]
destradaaea8a8a62014-06-23 18:19:03 -07001/*
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 com.android.server.location;
18
Lifu Tang30f95a72016-01-07 23:20:38 -080019import android.location.IGnssStatusListener;
destradaa6568d702014-10-27 12:47:41 -070020import android.os.Handler;
destradaaea8a8a62014-06-23 18:19:03 -070021import android.os.RemoteException;
22
23/**
Lifu Tang30f95a72016-01-07 23:20:38 -080024 * Implementation of a handler for {@link IGnssStatusListener}.
destradaaea8a8a62014-06-23 18:19:03 -070025 */
Lifu Tang30f95a72016-01-07 23:20:38 -080026abstract class GnssStatusListenerHelper extends RemoteListenerHelper<IGnssStatusListener> {
27 protected GnssStatusListenerHelper(Handler handler) {
28 super(handler, "GnssStatusListenerHelper");
29 setSupported(GnssLocationProvider.isSupported());
destradaa6568d702014-10-27 12:47:41 -070030 }
31
32 @Override
gomo48f1a642017-11-10 20:35:46 -080033 protected int registerWithService() {
34 return RemoteListenerHelper.RESULT_SUCCESS;
destradaa6568d702014-10-27 12:47:41 -070035 }
36
37 @Override
38 protected void unregisterFromService() {}
39
40 @Override
Lifu Tang30f95a72016-01-07 23:20:38 -080041 protected ListenerOperation<IGnssStatusListener> getHandlerOperation(int result) {
destradaa6568d702014-10-27 12:47:41 -070042 return null;
43 }
44
destradaa13a60b02015-01-15 18:36:01 -080045 public void onStatusChanged(boolean isNavigating) {
destradaa6568d702014-10-27 12:47:41 -070046 Operation operation;
destradaa13a60b02015-01-15 18:36:01 -080047 if (isNavigating) {
destradaa6568d702014-10-27 12:47:41 -070048 operation = new Operation() {
49 @Override
Lifu Tang30f95a72016-01-07 23:20:38 -080050 public void execute(IGnssStatusListener listener) throws RemoteException {
51 listener.onGnssStarted();
destradaa6568d702014-10-27 12:47:41 -070052 }
53 };
54 } else {
55 operation = new Operation() {
56 @Override
Lifu Tang30f95a72016-01-07 23:20:38 -080057 public void execute(IGnssStatusListener listener) throws RemoteException {
58 listener.onGnssStopped();
destradaa6568d702014-10-27 12:47:41 -070059 }
60 };
61 }
62 foreach(operation);
destradaa4b3e3932014-07-21 18:01:47 -070063 }
64
destradaaea8a8a62014-06-23 18:19:03 -070065 public void onFirstFix(final int timeToFirstFix) {
66 Operation operation = new Operation() {
67 @Override
Lifu Tang30f95a72016-01-07 23:20:38 -080068 public void execute(IGnssStatusListener listener) throws RemoteException {
destradaaea8a8a62014-06-23 18:19:03 -070069 listener.onFirstFix(timeToFirstFix);
70 }
71 };
destradaaea8a8a62014-06-23 18:19:03 -070072 foreach(operation);
73 }
74
75 public void onSvStatusChanged(
76 final int svCount,
Lifu Tang30f95a72016-01-07 23:20:38 -080077 final int[] prnWithFlags,
Lifu Tang76a620f2016-02-26 19:53:01 -080078 final float[] cn0s,
destradaaea8a8a62014-06-23 18:19:03 -070079 final float[] elevations,
gomo4402af62017-01-11 13:20:13 -080080 final float[] azimuths,
81 final float[] carrierFreqs) {
destradaaea8a8a62014-06-23 18:19:03 -070082 Operation operation = new Operation() {
83 @Override
Lifu Tang30f95a72016-01-07 23:20:38 -080084 public void execute(IGnssStatusListener listener) throws RemoteException {
destradaaea8a8a62014-06-23 18:19:03 -070085 listener.onSvStatusChanged(
86 svCount,
Lifu Tang30f95a72016-01-07 23:20:38 -080087 prnWithFlags,
Lifu Tang76a620f2016-02-26 19:53:01 -080088 cn0s,
destradaaea8a8a62014-06-23 18:19:03 -070089 elevations,
gomo4402af62017-01-11 13:20:13 -080090 azimuths,
91 carrierFreqs);
destradaaea8a8a62014-06-23 18:19:03 -070092 }
93 };
destradaaea8a8a62014-06-23 18:19:03 -070094 foreach(operation);
95 }
96
97 public void onNmeaReceived(final long timestamp, final String nmea) {
98 Operation operation = new Operation() {
99 @Override
Lifu Tang30f95a72016-01-07 23:20:38 -0800100 public void execute(IGnssStatusListener listener) throws RemoteException {
destradaaea8a8a62014-06-23 18:19:03 -0700101 listener.onNmeaReceived(timestamp, nmea);
102 }
103 };
destradaaea8a8a62014-06-23 18:19:03 -0700104 foreach(operation);
105 }
106
Lifu Tang30f95a72016-01-07 23:20:38 -0800107 private interface Operation extends ListenerOperation<IGnssStatusListener> {}
destradaaea8a8a62014-06-23 18:19:03 -0700108}