• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 java.util.HashSet;
20 import java.util.Set;
21 
22 /**
23  * Match assets that have the same 'package_name' field and have at least one common certificate
24  * fingerprint in 'sha256_cert_fingerprints' field.
25  */
26 public final class AndroidAppAssetMatcher extends AbstractAssetMatcher {
27 
28     private final AndroidAppAsset mQuery;
29 
AndroidAppAssetMatcher(AndroidAppAsset query)30     public AndroidAppAssetMatcher(AndroidAppAsset query) {
31         mQuery = query;
32     }
33 
34     @Override
matches(AbstractAsset asset)35     public boolean matches(AbstractAsset asset) {
36         if (asset instanceof AndroidAppAsset) {
37             AndroidAppAsset androidAppAsset = (AndroidAppAsset) asset;
38             if (!androidAppAsset.getPackageName().equals(mQuery.getPackageName())) {
39                 return false;
40             }
41 
42             Set<String> certs = new HashSet<String>(mQuery.getCertFingerprints());
43             for (String cert : androidAppAsset.getCertFingerprints()) {
44                 if (certs.contains(cert)) {
45                     return true;
46                 }
47             }
48         }
49         return false;
50     }
51 
52     @Override
getMatchedLookupKey()53     public int getMatchedLookupKey() {
54         return mQuery.lookupKey();
55     }
56 }
57