destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 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 com.android.server.location; |
| 18 | |
| 19 | import android.location.IGpsStatusListener; |
destradaa | 6568d70 | 2014-10-27 12:47:41 -0700 | [diff] [blame] | 20 | import android.os.Handler; |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 21 | import android.os.RemoteException; |
| 22 | |
| 23 | /** |
| 24 | * Implementation of a handler for {@link IGpsStatusListener}. |
| 25 | */ |
| 26 | abstract class GpsStatusListenerHelper extends RemoteListenerHelper<IGpsStatusListener> { |
destradaa | 13a60b0 | 2015-01-15 18:36:01 -0800 | [diff] [blame^] | 27 | protected GpsStatusListenerHelper(Handler handler) { |
destradaa | 6568d70 | 2014-10-27 12:47:41 -0700 | [diff] [blame] | 28 | super(handler, "GpsStatusListenerHelper"); |
destradaa | 13a60b0 | 2015-01-15 18:36:01 -0800 | [diff] [blame^] | 29 | setSupported(GpsLocationProvider.isSupported()); |
destradaa | 6568d70 | 2014-10-27 12:47:41 -0700 | [diff] [blame] | 30 | } |
| 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 | |
destradaa | 13a60b0 | 2015-01-15 18:36:01 -0800 | [diff] [blame^] | 45 | public void onStatusChanged(boolean isNavigating) { |
destradaa | 6568d70 | 2014-10-27 12:47:41 -0700 | [diff] [blame] | 46 | Operation operation; |
destradaa | 13a60b0 | 2015-01-15 18:36:01 -0800 | [diff] [blame^] | 47 | if (isNavigating) { |
destradaa | 6568d70 | 2014-10-27 12:47:41 -0700 | [diff] [blame] | 48 | 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); |
destradaa | 4b3e393 | 2014-07-21 18:01:47 -0700 | [diff] [blame] | 63 | } |
| 64 | |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 65 | 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 | }; |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 72 | 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 | }; |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 98 | 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 | }; |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 108 | foreach(operation); |
| 109 | } |
| 110 | |
destradaa | 13a60b0 | 2015-01-15 18:36:01 -0800 | [diff] [blame^] | 111 | private interface Operation extends ListenerOperation<IGpsStatusListener> {} |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 112 | } |