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 android.location;
     18 
     19 import android.annotation.IntDef;
     20 import android.annotation.NonNull;
     21 import android.os.Parcel;
     22 import android.os.Parcelable;
     23 
     24 import java.lang.annotation.Retention;
     25 import java.lang.annotation.RetentionPolicy;
     26 import java.security.InvalidParameterException;
     27 
     28 /**
     29  * A class implementing a container for data associated with a navigation message event.
     30  * Events are delivered to registered instances of {@link Callback}.
     31  * @removed
     32  */
     33 public final class GnssNavigationMessageEvent implements Parcelable {
     34     /**
     35      * The status of GNSS measurements event.
     36      * @hide
     37      */
     38     @Retention(RetentionPolicy.SOURCE)
     39     @IntDef({STATUS_NOT_SUPPORTED, STATUS_READY, STATUS_GNSS_LOCATION_DISABLED})
     40     public @interface GnssNavigationMessageStatus {}
     41 
     42     /**
     43      * The system does not support tracking of GNSS Navigation Messages.
     44      *
     45      * This status will not change in the future.
     46      */
     47     public static final int STATUS_NOT_SUPPORTED = 0;
     48 
     49     /**
     50      * GNSS Navigation Messages are successfully being tracked, it will receive updates once they
     51      * are available.
     52      */
     53     public static final int STATUS_READY = 1;
     54 
     55     /**
     56      * GNSS provider or Location is disabled, updated will not be received until they are enabled.
     57      */
     58     public static final int STATUS_GNSS_LOCATION_DISABLED = 2;
     59 
     60     private final GnssNavigationMessage mNavigationMessage;
     61 
     62     /**
     63      * Used for receiving GNSS satellite Navigation Messages from the GNSS engine.
     64      *
     65      * <p>You can implement this interface and call
     66      * {@link LocationManager#registerGnssNavigationMessageCallback}.
     67      */
     68     public static abstract class Callback {
     69 
     70         /**
     71          * Returns the latest collected GNSS Navigation Message.
     72          */
     73         public void onGnssNavigationMessageReceived(GnssNavigationMessageEvent event) {}
     74 
     75         /**
     76          * Returns the latest status of the GNSS Navigation Messages sub-system.
     77          */
     78         public void onStatusChanged(@GnssNavigationMessageStatus int status) {}
     79     }
     80 
     81     public GnssNavigationMessageEvent(GnssNavigationMessage message) {
     82         if (message == null) {
     83             throw new InvalidParameterException("Parameter 'message' must not be null.");
     84         }
     85         mNavigationMessage = message;
     86     }
     87 
     88     @NonNull
     89     public GnssNavigationMessage getNavigationMessage() {
     90         return mNavigationMessage;
     91     }
     92 
     93     public static final Creator<GnssNavigationMessageEvent> CREATOR =
     94             new Creator<GnssNavigationMessageEvent>() {
     95                 @Override
     96                 public GnssNavigationMessageEvent createFromParcel(Parcel in) {
     97                     ClassLoader classLoader = getClass().getClassLoader();
     98                     GnssNavigationMessage navigationMessage = in.readParcelable(classLoader);
     99                     return new GnssNavigationMessageEvent(navigationMessage);
    100                 }
    101 
    102                 @Override
    103                 public GnssNavigationMessageEvent[] newArray(int size) {
    104                     return new GnssNavigationMessageEvent[size];
    105                 }
    106             };
    107 
    108     @Override
    109     public int describeContents() {
    110         return 0;
    111     }
    112 
    113     @Override
    114     public void writeToParcel(Parcel parcel, int flags) {
    115         parcel.writeParcelable(mNavigationMessage, flags);
    116     }
    117 
    118     @Override
    119     public String toString() {
    120         StringBuilder builder = new StringBuilder("[ GnssNavigationMessageEvent:\n\n");
    121         builder.append(mNavigationMessage.toString());
    122         builder.append("\n]");
    123         return builder.toString();
    124     }
    125 }
    126