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 | |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 19 | import android.location.IGnssStatusListener; |
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 | /** |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 24 | * Implementation of a handler for {@link IGnssStatusListener}. |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 25 | */ |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 26 | abstract class GnssStatusListenerHelper extends RemoteListenerHelper<IGnssStatusListener> { |
| 27 | protected GnssStatusListenerHelper(Handler handler) { |
| 28 | super(handler, "GnssStatusListenerHelper"); |
| 29 | setSupported(GnssLocationProvider.isSupported()); |
destradaa | 6568d70 | 2014-10-27 12:47:41 -0700 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | @Override |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 33 | protected int registerWithService() { |
| 34 | return RemoteListenerHelper.RESULT_SUCCESS; |
destradaa | 6568d70 | 2014-10-27 12:47:41 -0700 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | @Override |
| 38 | protected void unregisterFromService() {} |
| 39 | |
| 40 | @Override |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 41 | protected ListenerOperation<IGnssStatusListener> getHandlerOperation(int result) { |
destradaa | 6568d70 | 2014-10-27 12:47:41 -0700 | [diff] [blame] | 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 |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 50 | public void execute(IGnssStatusListener listener) throws RemoteException { |
| 51 | listener.onGnssStarted(); |
destradaa | 6568d70 | 2014-10-27 12:47:41 -0700 | [diff] [blame] | 52 | } |
| 53 | }; |
| 54 | } else { |
| 55 | operation = new Operation() { |
| 56 | @Override |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 57 | public void execute(IGnssStatusListener listener) throws RemoteException { |
| 58 | listener.onGnssStopped(); |
destradaa | 6568d70 | 2014-10-27 12:47:41 -0700 | [diff] [blame] | 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 |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 68 | public void execute(IGnssStatusListener listener) throws RemoteException { |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 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, |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 77 | final int[] prnWithFlags, |
Lifu Tang | 76a620f | 2016-02-26 19:53:01 -0800 | [diff] [blame] | 78 | final float[] cn0s, |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 79 | final float[] elevations, |
gomo | 4402af6 | 2017-01-11 13:20:13 -0800 | [diff] [blame] | 80 | final float[] azimuths, |
| 81 | final float[] carrierFreqs) { |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 82 | Operation operation = new Operation() { |
| 83 | @Override |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 84 | public void execute(IGnssStatusListener listener) throws RemoteException { |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 85 | listener.onSvStatusChanged( |
| 86 | svCount, |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 87 | prnWithFlags, |
Lifu Tang | 76a620f | 2016-02-26 19:53:01 -0800 | [diff] [blame] | 88 | cn0s, |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 89 | elevations, |
gomo | 4402af6 | 2017-01-11 13:20:13 -0800 | [diff] [blame] | 90 | azimuths, |
| 91 | carrierFreqs); |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 92 | } |
| 93 | }; |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 94 | foreach(operation); |
| 95 | } |
| 96 | |
| 97 | public void onNmeaReceived(final long timestamp, final String nmea) { |
| 98 | Operation operation = new Operation() { |
| 99 | @Override |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 100 | public void execute(IGnssStatusListener listener) throws RemoteException { |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 101 | listener.onNmeaReceived(timestamp, nmea); |
| 102 | } |
| 103 | }; |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 104 | foreach(operation); |
| 105 | } |
| 106 | |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 107 | private interface Operation extends ListenerOperation<IGnssStatusListener> {} |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 108 | } |