Home | History | Annotate | Download | only in location
      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             final float[] carrierFreqs) {
     82         Operation operation = new Operation() {
     83             @Override
     84             public void execute(IGnssStatusListener listener) throws RemoteException {
     85                 listener.onSvStatusChanged(
     86                         svCount,
     87                         prnWithFlags,
     88                         cn0s,
     89                         elevations,
     90                         azimuths,
     91                         carrierFreqs);
     92             }
     93         };
     94         foreach(operation);
     95     }
     96 
     97     public void onNmeaReceived(final long timestamp, final String nmea) {
     98         Operation operation = new Operation() {
     99             @Override
    100             public void execute(IGnssStatusListener listener) throws RemoteException {
    101                 listener.onNmeaReceived(timestamp, nmea);
    102             }
    103         };
    104         foreach(operation);
    105     }
    106 
    107     private interface Operation extends ListenerOperation<IGnssStatusListener> {}
    108 }
    109