GpsStatusListenerHelper.java revision 4b3e3931270f8e406fc806bc7fa1c2788256687d
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 GpsStatusListenerHelper() { 27 super("GpsStatusListenerHelper"); 28 } 29 30 public void onFirstFix(final int timeToFirstFix) { 31 Operation operation = new Operation() { 32 @Override 33 public void execute(IGpsStatusListener listener) throws RemoteException { 34 listener.onFirstFix(timeToFirstFix); 35 } 36 }; 37 38 foreach(operation); 39 } 40 41 public void onStatusChanged(final boolean isNavigating) { 42 Operation operation = new Operation() { 43 @Override 44 public void execute(IGpsStatusListener listener) throws RemoteException { 45 if (isNavigating) { 46 listener.onGpsStarted(); 47 } else { 48 listener.onGpsStopped(); 49 } 50 } 51 }; 52 53 foreach(operation); 54 } 55 56 public void onSvStatusChanged( 57 final int svCount, 58 final int[] prns, 59 final float[] snrs, 60 final float[] elevations, 61 final float[] azimuths, 62 final int ephemerisMask, 63 final int almanacMask, 64 final int usedInFixMask) { 65 Operation operation = new Operation() { 66 @Override 67 public void execute(IGpsStatusListener listener) throws RemoteException { 68 listener.onSvStatusChanged( 69 svCount, 70 prns, 71 snrs, 72 elevations, 73 azimuths, 74 ephemerisMask, 75 almanacMask, 76 usedInFixMask); 77 } 78 }; 79 80 foreach(operation); 81 } 82 83 public void onNmeaReceived(final long timestamp, final String nmea) { 84 Operation operation = new Operation() { 85 @Override 86 public void execute(IGpsStatusListener listener) throws RemoteException { 87 listener.onNmeaReceived(timestamp, nmea); 88 } 89 }; 90 91 foreach(operation); 92 } 93 94 private abstract class Operation implements ListenerOperation<IGpsStatusListener> { } 95} 96