Home | History | Annotate | Download | only in location
      1 /*
      2  * Copyright (C) 2016 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.hardware.location;
     18 
     19 import android.annotation.SystemApi;
     20 import android.os.Parcel;
     21 import android.os.Parcelable;
     22 
     23 /**
     24  * @deprecated Use {@link android.hardware.location.ContextHubManager#queryNanoApps(ContextHubInfo)}
     25  *             to find loaded nanoapps, which doesn't require using this class as a parameter.
     26  *
     27  * @hide
     28  */
     29 @SystemApi
     30 @Deprecated
     31 public class NanoAppFilter implements Parcelable {
     32 
     33     private static final String TAG = "NanoAppFilter";
     34 
     35     // The appId, can be set to APP_ID_ANY
     36     private long mAppId;
     37 
     38     // Version to filter apps
     39     private int mAppVersion;
     40 
     41     // filtering spec for version
     42     private int mVersionRestrictionMask;
     43 
     44     // If APP_ID is any, then a match is performef with the vendor mask
     45     private long mAppIdVendorMask;
     46 
     47     // Id of the context hub this instance is expected on
     48     // TODO: Provide an API which will let us change this HubId.
     49     private int mContextHubId = HUB_ANY;
     50 
     51     /**
     52      * Flag indicating any version. With this flag set, all versions shall match provided version.
     53      */
     54     public static final int FLAGS_VERSION_ANY = -1;
     55     /**
     56      * If this flag is set, only versions strictly greater than the version specified shall match.
     57      */
     58     public static final int FLAGS_VERSION_GREAT_THAN  = 2;
     59     /**
     60      * If this flag is set, only versions strictly less than the version specified shall match.
     61      */
     62     public static final int FLAGS_VERSION_LESS_THAN   = 4;
     63     /**
     64      * If this flag is set, only versions strictly equal to the
     65      * version specified shall match.
     66      */
     67     public static final int FLAGS_VERSION_STRICTLY_EQUAL = 8;
     68 
     69     /**
     70      * If this flag is set, only versions strictly equal to the version specified shall match.
     71      */
     72     public static final int APP_ANY = -1;
     73 
     74     /**
     75      * If this flag is set, all vendors shall match.
     76      */
     77     public static final int VENDOR_ANY = -1;
     78 
     79     /**
     80      * If this flag is set, any hub shall match.
     81      */
     82     public static final int HUB_ANY = -1;
     83 
     84     private NanoAppFilter(Parcel in) {
     85         mAppId = in.readLong();
     86         mAppVersion = in.readInt();
     87         mVersionRestrictionMask = in.readInt();
     88         mAppIdVendorMask = in.readInt();
     89     }
     90 
     91     public int describeContents() {
     92         return 0;
     93     }
     94 
     95     public void writeToParcel(Parcel out, int flags) {
     96 
     97         out.writeLong(mAppId);
     98         out.writeInt(mAppVersion);
     99         out.writeInt(mVersionRestrictionMask);
    100         out.writeLong(mAppIdVendorMask);
    101     }
    102 
    103     /**
    104      * Create a filter
    105      *
    106      * @param appId       application id
    107      * @param appVersion  application version
    108      * @param versionMask version
    109      * @param vendorMask  vendor
    110      */
    111     public NanoAppFilter(long appId, int appVersion, int versionMask, long vendorMask) {
    112         mAppId = appId;
    113         mAppVersion = appVersion;
    114         mVersionRestrictionMask = versionMask;
    115         mAppIdVendorMask = vendorMask;
    116     }
    117 
    118     private boolean versionsMatch(int versionRestrictionMask, int expected, int actual){
    119         // some refactoring of version restriction mask is needed, until then, return all
    120         return true;
    121     }
    122     /**
    123      * Test match method.
    124      *
    125      * @param info nano app instance info
    126      *
    127      * @return true if this is a match, false otherwise
    128      */
    129     public boolean testMatch(NanoAppInstanceInfo info) {
    130         return (mContextHubId == HUB_ANY || info.getContexthubId() == mContextHubId) &&
    131                 (mAppId == APP_ANY || info.getAppId() == mAppId) &&
    132                 (versionsMatch(mVersionRestrictionMask, mAppVersion, info.getAppVersion()));
    133     }
    134 
    135     @Override
    136     public String toString() {
    137         return "nanoAppId: 0x" + Long.toHexString(mAppId)
    138                 + ", nanoAppVersion: 0x" + Integer.toHexString(mAppVersion)
    139                 + ", versionMask: " + mVersionRestrictionMask
    140                 + ", vendorMask: " + mAppIdVendorMask;
    141     }
    142 
    143     public static final Parcelable.Creator<NanoAppFilter> CREATOR
    144             = new Parcelable.Creator<NanoAppFilter>() {
    145         public NanoAppFilter createFromParcel(Parcel in) {
    146             return new NanoAppFilter(in);
    147         }
    148 
    149         public NanoAppFilter[] newArray(int size) {
    150             return new NanoAppFilter[size];
    151         }
    152     };
    153 }
    154