blob: 53ff6c24ae6b7b1a00bda617ffe90eef25f67456 [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
19import android.location.IGpsStatusListener;
destradaa6568d702014-10-27 12:47:41 -070020import android.os.Handler;
destradaaea8a8a62014-06-23 18:19:03 -070021import android.os.RemoteException;
22
23/**
24 * Implementation of a handler for {@link IGpsStatusListener}.
25 */
26abstract class GpsStatusListenerHelper extends RemoteListenerHelper<IGpsStatusListener> {
destradaa13a60b02015-01-15 18:36:01 -080027 protected GpsStatusListenerHelper(Handler handler) {
destradaa6568d702014-10-27 12:47:41 -070028 super(handler, "GpsStatusListenerHelper");
destradaa13a60b02015-01-15 18:36:01 -080029 setSupported(GpsLocationProvider.isSupported());
destradaa6568d702014-10-27 12:47:41 -070030 }
31
32 @Override
33 protected boolean registerWithService() {
34 return true;
35 }
36
37 @Override
38 protected void unregisterFromService() {}
39
40 @Override
41 protected ListenerOperation<IGpsStatusListener> getHandlerOperation(int result) {
42 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
50 public void execute(IGpsStatusListener listener) throws RemoteException {
51 listener.onGpsStarted();
52 }
53 };
54 } else {
55 operation = new Operation() {
56 @Override
57 public void execute(IGpsStatusListener listener) throws RemoteException {
58 listener.onGpsStopped();
59 }
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
68 public void execute(IGpsStatusListener listener) throws RemoteException {
69 listener.onFirstFix(timeToFirstFix);
70 }
71 };
destradaaea8a8a62014-06-23 18:19:03 -070072 foreach(operation);
73 }
74
75 public void onSvStatusChanged(
76 final int svCount,
77 final int[] prns,
78 final float[] snrs,
79 final float[] elevations,
80 final float[] azimuths,
81 final int ephemerisMask,
82 final int almanacMask,
83 final int usedInFixMask) {
84 Operation operation = new Operation() {
85 @Override
86 public void execute(IGpsStatusListener listener) throws RemoteException {
87 listener.onSvStatusChanged(
88 svCount,
89 prns,
90 snrs,
91 elevations,
92 azimuths,
93 ephemerisMask,
94 almanacMask,
95 usedInFixMask);
96 }
97 };
destradaaea8a8a62014-06-23 18:19:03 -070098 foreach(operation);
99 }
100
101 public void onNmeaReceived(final long timestamp, final String nmea) {
102 Operation operation = new Operation() {
103 @Override
104 public void execute(IGpsStatusListener listener) throws RemoteException {
105 listener.onNmeaReceived(timestamp, nmea);
106 }
107 };
destradaaea8a8a62014-06-23 18:19:03 -0700108 foreach(operation);
109 }
110
destradaa13a60b02015-01-15 18:36:01 -0800111 private interface Operation extends ListenerOperation<IGpsStatusListener> {}
destradaaea8a8a62014-06-23 18:19:03 -0700112}