blob: 0700dd1be423572d09835e0e92816e6521cb3dc3 [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
Ashutosh Joshi1d1ac542016-01-18 17:19:27 -080019import android.annotation.SystemApi;
20import android.os.Parcel;
21import android.os.Parcelable;
22
23/**
Arthur Ishiguro581950c2018-01-05 10:57:46 -080024 * @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 *
Ashutosh Joshi1d1ac542016-01-18 17:19:27 -080027 * @hide
28 */
29@SystemApi
Arthur Ishiguro581950c2018-01-05 10:57:46 -080030@Deprecated
Arthur Ishigurof3ab9cd2018-02-28 11:27:50 -080031public class NanoAppFilter implements Parcelable {
Ashutosh Joshi1d1ac542016-01-18 17:19:27 -080032
Ashutosh Joshib741e3b2016-03-29 09:19:56 -070033 private static final String TAG = "NanoAppFilter";
34
Ashutosh Joshi1d1ac542016-01-18 17:19:27 -080035 // 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
Greg Kaiser39070492016-08-17 16:50:44 -070048 // TODO: Provide an API which will let us change this HubId.
49 private int mContextHubId = HUB_ANY;
Ashutosh Joshi1d1ac542016-01-18 17:19:27 -080050
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;
Ashutosh Joshib741e3b2016-03-29 09:19:56 -070063 /**
64 * If this flag is set, only versions strictly equal to the
65 * version specified shall match.
66 */
Ashutosh Joshi1d1ac542016-01-18 17:19:27 -080067 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();
Arthur Ishiguroabe5a732018-06-25 11:31:33 -070088 mAppIdVendorMask = in.readLong();
Ashutosh Joshi1d1ac542016-01-18 17:19:27 -080089 }
90
91 public int describeContents() {
92 return 0;
93 }
94
95 public void writeToParcel(Parcel out, int flags) {
Ashutosh Joshi1d1ac542016-01-18 17:19:27 -080096 out.writeLong(mAppId);
97 out.writeInt(mAppVersion);
98 out.writeInt(mVersionRestrictionMask);
99 out.writeLong(mAppIdVendorMask);
100 }
101
102 /**
103 * Create a filter
104 *
105 * @param appId application id
106 * @param appVersion application version
107 * @param versionMask version
108 * @param vendorMask vendor
109 */
110 public NanoAppFilter(long appId, int appVersion, int versionMask, long vendorMask) {
111 mAppId = appId;
112 mAppVersion = appVersion;
113 mVersionRestrictionMask = versionMask;
114 mAppIdVendorMask = vendorMask;
115 }
116
117 private boolean versionsMatch(int versionRestrictionMask, int expected, int actual){
118 // some refactoring of version restriction mask is needed, until then, return all
119 return true;
120 }
121 /**
Peng Xu9ff7d222016-02-11 13:02:05 -0800122 * Test match method.
Ashutosh Joshi1d1ac542016-01-18 17:19:27 -0800123 *
Peng Xu9ff7d222016-02-11 13:02:05 -0800124 * @param info nano app instance info
Ashutosh Joshi1d1ac542016-01-18 17:19:27 -0800125 *
126 * @return true if this is a match, false otherwise
127 */
128 public boolean testMatch(NanoAppInstanceInfo info) {
Ashutosh Joshib741e3b2016-03-29 09:19:56 -0700129 return (mContextHubId == HUB_ANY || info.getContexthubId() == mContextHubId) &&
Ashutosh Joshi1d1ac542016-01-18 17:19:27 -0800130 (mAppId == APP_ANY || info.getAppId() == mAppId) &&
Ashutosh Joshib741e3b2016-03-29 09:19:56 -0700131 (versionsMatch(mVersionRestrictionMask, mAppVersion, info.getAppVersion()));
Ashutosh Joshi1d1ac542016-01-18 17:19:27 -0800132 }
133
Arthur Ishiguroafe52462017-11-22 15:18:54 -0800134 @Override
135 public String toString() {
136 return "nanoAppId: 0x" + Long.toHexString(mAppId)
137 + ", nanoAppVersion: 0x" + Integer.toHexString(mAppVersion)
138 + ", versionMask: " + mVersionRestrictionMask
139 + ", vendorMask: " + mAppIdVendorMask;
140 }
141
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -0700142 public static final @android.annotation.NonNull Parcelable.Creator<NanoAppFilter> CREATOR
Ashutosh Joshi1d1ac542016-01-18 17:19:27 -0800143 = new Parcelable.Creator<NanoAppFilter>() {
144 public NanoAppFilter createFromParcel(Parcel in) {
145 return new NanoAppFilter(in);
146 }
147
148 public NanoAppFilter[] newArray(int size) {
149 return new NanoAppFilter[size];
150 }
151 };
152}