blob: 369f9e44e8d94490bb41db04b8959780e2e73c29 [file] [log] [blame]
Ashutosh Joshi1d1ac542016-01-18 17:19:27 -08001/*
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
17package android.hardware.location;
18
19
20import android.annotation.SystemApi;
21import android.os.Parcel;
22import android.os.Parcelable;
23
24/**
25 * @hide
26 */
27@SystemApi
28public class NanoAppFilter {
29
30 // The appId, can be set to APP_ID_ANY
31 private long mAppId;
32
33 // Version to filter apps
34 private int mAppVersion;
35
36 // filtering spec for version
37 private int mVersionRestrictionMask;
38
39 // If APP_ID is any, then a match is performef with the vendor mask
40 private long mAppIdVendorMask;
41
42 // Id of the context hub this instance is expected on
43 private int mContextHubId;
44
45 /**
46 * Flag indicating any version. With this flag set, all versions shall match provided version.
47 */
48 public static final int FLAGS_VERSION_ANY = -1;
49 /**
50 * If this flag is set, only versions strictly greater than the version specified shall match.
51 */
52 public static final int FLAGS_VERSION_GREAT_THAN = 2;
53 /**
54 * If this flag is set, only versions strictly less than the version specified shall match.
55 */
56 public static final int FLAGS_VERSION_LESS_THAN = 4;
57 public static final int FLAGS_VERSION_STRICTLY_EQUAL = 8;
58
59 /**
60 * If this flag is set, only versions strictly equal to the version specified shall match.
61 */
62 public static final int APP_ANY = -1;
63
64 /**
65 * If this flag is set, all vendors shall match.
66 */
67 public static final int VENDOR_ANY = -1;
68
69 /**
70 * If this flag is set, any hub shall match.
71 */
72 public static final int HUB_ANY = -1;
73
74 private NanoAppFilter(Parcel in) {
75 mAppId = in.readLong();
76 mAppVersion = in.readInt();
77 mVersionRestrictionMask = in.readInt();
78 mAppIdVendorMask = in.readInt();
79 }
80
81 public int describeContents() {
82 return 0;
83 }
84
85 public void writeToParcel(Parcel out, int flags) {
86
87 out.writeLong(mAppId);
88 out.writeInt(mAppVersion);
89 out.writeInt(mVersionRestrictionMask);
90 out.writeLong(mAppIdVendorMask);
91 }
92
93 /**
94 * Create a filter
95 *
96 * @param appId application id
97 * @param appVersion application version
98 * @param versionMask version
99 * @param vendorMask vendor
100 */
101 public NanoAppFilter(long appId, int appVersion, int versionMask, long vendorMask) {
102 mAppId = appId;
103 mAppVersion = appVersion;
104 mVersionRestrictionMask = versionMask;
105 mAppIdVendorMask = vendorMask;
106 }
107
108 private boolean versionsMatch(int versionRestrictionMask, int expected, int actual){
109 // some refactoring of version restriction mask is needed, until then, return all
110 return true;
111 }
112 /**
Peng Xu9ff7d222016-02-11 13:02:05 -0800113 * Test match method.
Ashutosh Joshi1d1ac542016-01-18 17:19:27 -0800114 *
Peng Xu9ff7d222016-02-11 13:02:05 -0800115 * @param info nano app instance info
Ashutosh Joshi1d1ac542016-01-18 17:19:27 -0800116 *
117 * @return true if this is a match, false otherwise
118 */
119 public boolean testMatch(NanoAppInstanceInfo info) {
120 if ((mContextHubId == HUB_ANY || info.getContexthubId() == mContextHubId) &&
121 (mAppId == APP_ANY || info.getAppId() == mAppId) &&
122 // (mAppIdVendorMask == VENDOR_ANY) TODO : Expose Vendor mask cleanly
123 (versionsMatch(mVersionRestrictionMask, mAppVersion, info.getAppVersion()))) {
124 return true;
125 } else {
126 return false;
127 }
128 }
129
130 public static final Parcelable.Creator<NanoAppFilter> CREATOR
131 = new Parcelable.Creator<NanoAppFilter>() {
132 public NanoAppFilter createFromParcel(Parcel in) {
133 return new NanoAppFilter(in);
134 }
135
136 public NanoAppFilter[] newArray(int size) {
137 return new NanoAppFilter[size];
138 }
139 };
140}