AbstractAsset.java revision 6a34bb2d6a6cbc7a70bdf0c53d238dc28e0b1d58
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 17package com.android.statementservice.retriever; 18 19/** 20 * A handle representing the identity and address of some digital asset. An asset is an online 21 * entity that typically provides some service or content. Examples of assets are websites, Android 22 * apps, Twitter feeds, and Plus Pages. 23 * 24 * <p> Asset can be represented by a JSON string. For example, the web site https://www.google.com 25 * can be represented by 26 * <pre> 27 * {"namespace": "web", "site": "https://www.google.com"} 28 * </pre> 29 * 30 * <p> The Android app with package name com.google.test that is signed by a certificate with sha256 31 * fingerprint 11:22:33 can be represented by 32 * <pre> 33 * {"namespace": "android_app", 34 * "package_name": "com.google.test", 35 * "sha256_cert_fingerprints": ["11:22:33"]} 36 * </pre> 37 * 38 * <p>Given a signed APK, Java 7's commandline keytool can compute the fingerprint using: 39 * {@code keytool -list -printcert -jarfile signed_app.apk} 40 */ 41public abstract class AbstractAsset { 42 43 /** 44 * Returns a JSON string representation of this asset. The strings returned by this function are 45 * normalized -- they can be used for equality testing. 46 */ 47 public abstract String toJson(); 48 49 /** 50 * Returns a key that can be used by {@link AbstractAssetMatcher} to lookup the asset. 51 * 52 * <p> An asset will match an {@code AssetMatcher} only if the value of this method is equal to 53 * {@code AssetMatcher.getMatchedLookupKey()}. 54 */ 55 public abstract int lookupKey(); 56 57 /** 58 * Creates a new Asset from its JSON string representation. 59 * 60 * @throws AssociationServiceException if the assetJson is not well formatted. 61 */ 62 public static AbstractAsset create(String assetJson) 63 throws AssociationServiceException { 64 return AssetFactory.create(assetJson); 65 } 66} 67