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