Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 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 | |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 19 | import android.annotation.SystemApi; |
| 20 | import android.os.Parcel; |
| 21 | import android.os.Parcelable; |
| 22 | |
| 23 | /** |
Arthur Ishiguro | 581950c | 2018-01-05 10:57:46 -0800 | [diff] [blame] | 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 | * |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 27 | * @hide |
| 28 | */ |
| 29 | @SystemApi |
Arthur Ishiguro | 581950c | 2018-01-05 10:57:46 -0800 | [diff] [blame] | 30 | @Deprecated |
Arthur Ishiguro | f3ab9cd | 2018-02-28 11:27:50 -0800 | [diff] [blame] | 31 | public class NanoAppFilter implements Parcelable { |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 32 | |
Ashutosh Joshi | b741e3b | 2016-03-29 09:19:56 -0700 | [diff] [blame] | 33 | private static final String TAG = "NanoAppFilter"; |
| 34 | |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 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 |
Greg Kaiser | 3907049 | 2016-08-17 16:50:44 -0700 | [diff] [blame] | 48 | // TODO: Provide an API which will let us change this HubId. |
| 49 | private int mContextHubId = HUB_ANY; |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 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; |
Ashutosh Joshi | b741e3b | 2016-03-29 09:19:56 -0700 | [diff] [blame] | 63 | /** |
| 64 | * If this flag is set, only versions strictly equal to the |
| 65 | * version specified shall match. |
| 66 | */ |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 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(); |
Arthur Ishiguro | abe5a73 | 2018-06-25 11:31:33 -0700 | [diff] [blame] | 88 | mAppIdVendorMask = in.readLong(); |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | public int describeContents() { |
| 92 | return 0; |
| 93 | } |
| 94 | |
| 95 | public void writeToParcel(Parcel out, int flags) { |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 96 | 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 Xu | 9ff7d22 | 2016-02-11 13:02:05 -0800 | [diff] [blame] | 122 | * Test match method. |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 123 | * |
Peng Xu | 9ff7d22 | 2016-02-11 13:02:05 -0800 | [diff] [blame] | 124 | * @param info nano app instance info |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 125 | * |
| 126 | * @return true if this is a match, false otherwise |
| 127 | */ |
| 128 | public boolean testMatch(NanoAppInstanceInfo info) { |
Ashutosh Joshi | b741e3b | 2016-03-29 09:19:56 -0700 | [diff] [blame] | 129 | return (mContextHubId == HUB_ANY || info.getContexthubId() == mContextHubId) && |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 130 | (mAppId == APP_ANY || info.getAppId() == mAppId) && |
Ashutosh Joshi | b741e3b | 2016-03-29 09:19:56 -0700 | [diff] [blame] | 131 | (versionsMatch(mVersionRestrictionMask, mAppVersion, info.getAppVersion())); |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 132 | } |
| 133 | |
Arthur Ishiguro | afe5246 | 2017-11-22 15:18:54 -0800 | [diff] [blame] | 134 | @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 | |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 142 | public static final Parcelable.Creator<NanoAppFilter> CREATOR |
| 143 | = 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 | } |