2 * Copyright (C) 2016 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package android.hardware.location;
19 import android.annotation.SystemApi;
20 import android.os.Parcel;
21 import android.os.Parcelable;
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.
31 public class NanoAppFilter {
33 private static final String TAG = "NanoAppFilter";
35 // The appId, can be set to APP_ID_ANY
38 // Version to filter apps
39 private int mAppVersion;
41 // filtering spec for version
42 private int mVersionRestrictionMask;
44 // If APP_ID is any, then a match is performef with the vendor mask
45 private long mAppIdVendorMask;
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;
52 * Flag indicating any version. With this flag set, all versions shall match provided version.
54 public static final int FLAGS_VERSION_ANY = -1;
56 * If this flag is set, only versions strictly greater than the version specified shall match.
58 public static final int FLAGS_VERSION_GREAT_THAN = 2;
60 * If this flag is set, only versions strictly less than the version specified shall match.
62 public static final int FLAGS_VERSION_LESS_THAN = 4;
64 * If this flag is set, only versions strictly equal to the
65 * version specified shall match.
67 public static final int FLAGS_VERSION_STRICTLY_EQUAL = 8;
70 * If this flag is set, only versions strictly equal to the version specified shall match.
72 public static final int APP_ANY = -1;
75 * If this flag is set, all vendors shall match.
77 public static final int VENDOR_ANY = -1;
80 * If this flag is set, any hub shall match.
82 public static final int HUB_ANY = -1;
84 private NanoAppFilter(Parcel in) {
85 mAppId = in.readLong();
86 mAppVersion = in.readInt();
87 mVersionRestrictionMask = in.readInt();
88 mAppIdVendorMask = in.readInt();
91 public int describeContents() {
95 public void writeToParcel(Parcel out, int flags) {
97 out.writeLong(mAppId);
98 out.writeInt(mAppVersion);
99 out.writeInt(mVersionRestrictionMask);
100 out.writeLong(mAppIdVendorMask);
106 * @param appId application id
107 * @param appVersion application version
108 * @param versionMask version
109 * @param vendorMask vendor
111 public NanoAppFilter(long appId, int appVersion, int versionMask, long vendorMask) {
113 mAppVersion = appVersion;
114 mVersionRestrictionMask = versionMask;
115 mAppIdVendorMask = vendorMask;
118 private boolean versionsMatch(int versionRestrictionMask, int expected, int actual){
119 // some refactoring of version restriction mask is needed, until then, return all
125 * @param info nano app instance info
127 * @return true if this is a match, false otherwise
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()));
136 public String toString() {
137 return "nanoAppId: 0x" + Long.toHexString(mAppId)
138 + ", nanoAppVersion: 0x" + Integer.toHexString(mAppVersion)
139 + ", versionMask: " + mVersionRestrictionMask
140 + ", vendorMask: " + mAppIdVendorMask;
143 public static final Parcelable.Creator<NanoAppFilter> CREATOR
144 = new Parcelable.Creator<NanoAppFilter>() {
145 public NanoAppFilter createFromParcel(Parcel in) {
146 return new NanoAppFilter(in);
149 public NanoAppFilter[] newArray(int size) {
150 return new NanoAppFilter[size];