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.NonNull; 20 import android.annotation.SystemApi; 21 import android.os.Parcel; 22 import android.os.Parcelable; 23 24 /** 25 * @deprecated Use {@link android.hardware.location.ContextHubManager#queryNanoApps(ContextHubInfo)} 26 * to find loaded nanoapps, which doesn't require using this class as a parameter. 27 * 28 * @hide 29 */ 30 @SystemApi 31 @Deprecated 32 public class NanoAppFilter implements Parcelable { 33 34 private static final String TAG = "NanoAppFilter"; 35 36 // The appId, can be set to APP_ID_ANY 37 private long mAppId; 38 39 // Version to filter apps 40 private int mAppVersion; 41 42 // filtering spec for version 43 private int mVersionRestrictionMask; 44 45 // If APP_ID is any, then a match is performef with the vendor mask 46 private long mAppIdVendorMask; 47 48 // Id of the context hub this instance is expected on 49 // TODO: Provide an API which will let us change this HubId. 50 private int mContextHubId = HUB_ANY; 51 52 /** 53 * Flag indicating any version. With this flag set, all versions shall match provided version. 54 */ 55 public static final int FLAGS_VERSION_ANY = -1; 56 /** 57 * If this flag is set, only versions strictly greater than the version specified shall match. 58 */ 59 public static final int FLAGS_VERSION_GREAT_THAN = 2; 60 /** 61 * If this flag is set, only versions strictly less than the version specified shall match. 62 */ 63 public static final int FLAGS_VERSION_LESS_THAN = 4; 64 /** 65 * If this flag is set, only versions strictly equal to the 66 * version specified shall match. 67 */ 68 public static final int FLAGS_VERSION_STRICTLY_EQUAL = 8; 69 70 /** 71 * If this flag is set, only versions strictly equal to the version specified shall match. 72 */ 73 public static final int APP_ANY = -1; 74 75 /** 76 * If this flag is set, all vendors shall match. 77 */ 78 public static final int VENDOR_ANY = -1; 79 80 /** 81 * If this flag is set, any hub shall match. 82 */ 83 public static final int HUB_ANY = -1; 84 NanoAppFilter(Parcel in)85 private NanoAppFilter(Parcel in) { 86 mAppId = in.readLong(); 87 mAppVersion = in.readInt(); 88 mVersionRestrictionMask = in.readInt(); 89 mAppIdVendorMask = in.readLong(); 90 } 91 describeContents()92 public int describeContents() { 93 return 0; 94 } 95 writeToParcel(Parcel out, int flags)96 public void writeToParcel(Parcel out, int flags) { 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 */ NanoAppFilter(long appId, int appVersion, int versionMask, long vendorMask)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 versionsMatch(int versionRestrictionMask, int expected, int actual)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 */ testMatch(NanoAppInstanceInfo info)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 @NonNull 136 @Override toString()137 public String toString() { 138 return "nanoAppId: 0x" + Long.toHexString(mAppId) 139 + ", nanoAppVersion: 0x" + Integer.toHexString(mAppVersion) 140 + ", versionMask: " + mVersionRestrictionMask 141 + ", vendorMask: " + mAppIdVendorMask; 142 } 143 144 public static final @android.annotation.NonNull Parcelable.Creator<NanoAppFilter> CREATOR 145 = new Parcelable.Creator<NanoAppFilter>() { 146 public NanoAppFilter createFromParcel(Parcel in) { 147 return new NanoAppFilter(in); 148 } 149 150 public NanoAppFilter[] newArray(int size) { 151 return new NanoAppFilter[size]; 152 } 153 }; 154 } 155