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.IGnssStatusListener; 20 import android.os.Handler; 21 import android.os.RemoteException; 22 23 /** 24 * Implementation of a handler for {@link IGnssStatusListener}. 25 */ 26 abstract class GnssStatusListenerHelper extends RemoteListenerHelper<IGnssStatusListener> { 27 protected GnssStatusListenerHelper(Handler handler) { 28 super(handler, "GnssStatusListenerHelper"); 29 setSupported(GnssLocationProvider.isSupported()); 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<IGnssStatusListener> getHandlerOperation(int result) { 42 return null; 43 } 44 45 public void onStatusChanged(boolean isNavigating) { 46 Operation operation; 47 if (isNavigating) { 48 operation = new Operation() { 49 @Override 50 public void execute(IGnssStatusListener listener) throws RemoteException { 51 listener.onGnssStarted(); 52 } 53 }; 54 } else { 55 operation = new Operation() { 56 @Override 57 public void execute(IGnssStatusListener listener) throws RemoteException { 58 listener.onGnssStopped(); 59 } 60 }; 61 } 62 foreach(operation); 63 } 64 65 public void onFirstFix(final int timeToFirstFix) { 66 Operation operation = new Operation() { 67 @Override 68 public void execute(IGnssStatusListener listener) throws RemoteException { 69 listener.onFirstFix(timeToFirstFix); 70 } 71 }; 72 foreach(operation); 73 } 74 75 public void onSvStatusChanged( 76 final int svCount, 77 final int[] prnWithFlags, 78 final float[] cn0s, 79 final float[] elevations, 80 final float[] azimuths) { 81 Operation operation = new Operation() { 82 @Override 83 public void execute(IGnssStatusListener listener) throws RemoteException { 84 listener.onSvStatusChanged( 85 svCount, 86 prnWithFlags, 87 cn0s, 88 elevations, 89 azimuths); 90 } 91 }; 92 foreach(operation); 93 } 94 95 public void onNmeaReceived(final long timestamp, final String nmea) { 96 Operation operation = new Operation() { 97 @Override 98 public void execute(IGnssStatusListener listener) throws RemoteException { 99 listener.onNmeaReceived(timestamp, nmea); 100 } 101 }; 102 foreach(operation); 103 } 104 105 private interface Operation extends ListenerOperation<IGnssStatusListener> {} 106 } 107