1 /* 2 * Copyright (C) 2015 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 com.android.statementservice.retriever; 18 19 import org.json.JSONException; 20 21 /** 22 * An asset matcher that can match asset with the given query. 23 */ 24 public abstract class AbstractAssetMatcher { 25 26 /** 27 * Returns true if this AssetMatcher matches the asset. 28 */ matches(AbstractAsset asset)29 public abstract boolean matches(AbstractAsset asset); 30 31 /** 32 * This AssetMatcher will only match Asset with {@code lookupKey()} equal to the value returned 33 * by this method. 34 */ getMatchedLookupKey()35 public abstract int getMatchedLookupKey(); 36 37 /** 38 * Creates a new AssetMatcher from its JSON string representation. 39 * 40 * <p> For web namespace, {@code query} will match assets that have the same 'site' field. 41 * 42 * <p> For Android namespace, {@code query} will match assets that have the same 43 * 'package_name' field and have at least one common certificate fingerprint in 44 * 'sha256_cert_fingerprints' field. 45 */ createMatcher(String query)46 public static AbstractAssetMatcher createMatcher(String query) 47 throws AssociationServiceException, JSONException { 48 return AssetMatcherFactory.create(query); 49 } 50 } 51