GpsStatusListenerHelper.java revision ea8a8a6076f04360de2d25b3e5853cde8026cd5f
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
17package com.android.server.location;
18
19import android.location.IGpsStatusListener;
20import android.os.RemoteException;
21
22/**
23 * Implementation of a handler for {@link IGpsStatusListener}.
24 */
25abstract class GpsStatusListenerHelper extends RemoteListenerHelper<IGpsStatusListener> {
26    public void onFirstFix(final int timeToFirstFix) {
27        Operation operation = new Operation() {
28            @Override
29            public void execute(IGpsStatusListener listener) throws RemoteException {
30                listener.onFirstFix(timeToFirstFix);
31            }
32        };
33
34        foreach(operation);
35    }
36
37    public void onStatusChanged(final boolean isNavigating) {
38        Operation operation = new Operation() {
39            @Override
40            public void execute(IGpsStatusListener listener) throws RemoteException {
41                if (isNavigating) {
42                    listener.onGpsStarted();
43                } else {
44                    listener.onGpsStopped();
45                }
46            }
47        };
48
49        foreach(operation);
50    }
51
52    public void onSvStatusChanged(
53            final int svCount,
54            final int[] prns,
55            final float[] snrs,
56            final float[] elevations,
57            final float[] azimuths,
58            final int ephemerisMask,
59            final int almanacMask,
60            final int usedInFixMask) {
61        Operation operation = new Operation() {
62            @Override
63            public void execute(IGpsStatusListener listener) throws RemoteException {
64                listener.onSvStatusChanged(
65                        svCount,
66                        prns,
67                        snrs,
68                        elevations,
69                        azimuths,
70                        ephemerisMask,
71                        almanacMask,
72                        usedInFixMask);
73            }
74        };
75
76        foreach(operation);
77    }
78
79    public void onNmeaReceived(final long timestamp, final String nmea) {
80        Operation operation = new Operation() {
81            @Override
82            public void execute(IGpsStatusListener listener) throws RemoteException {
83                listener.onNmeaReceived(timestamp, nmea);
84            }
85        };
86
87        foreach(operation);
88    }
89
90    private abstract class Operation implements ListenerOperation<IGpsStatusListener> { }
91}
92