Clara Bayarri | b0812a3 | 2016-10-20 10:42:13 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 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 | */ |
Seigo Nonaka | 080b054 | 2017-04-26 09:53:38 -0700 | [diff] [blame] | 16 | package android.provider; |
Clara Bayarri | b0812a3 | 2016-10-20 10:42:13 +0100 | [diff] [blame] | 17 | |
| 18 | import android.annotation.NonNull; |
Clara Bayarri | 3c4be77 | 2017-02-07 15:33:40 +0000 | [diff] [blame] | 19 | import android.util.Base64; |
Clara Bayarri | b0812a3 | 2016-10-20 10:42:13 +0100 | [diff] [blame] | 20 | |
| 21 | import com.android.internal.util.Preconditions; |
| 22 | |
Clara Bayarri | 3c4be77 | 2017-02-07 15:33:40 +0000 | [diff] [blame] | 23 | import java.util.ArrayList; |
| 24 | import java.util.Collections; |
| 25 | import java.util.List; |
| 26 | |
Clara Bayarri | b0812a3 | 2016-10-20 10:42:13 +0100 | [diff] [blame] | 27 | /** |
| 28 | * Information about a font request that may be sent to a Font Provider. |
| 29 | */ |
Seigo Nonaka | 080b054 | 2017-04-26 09:53:38 -0700 | [diff] [blame] | 30 | public final class FontRequest { |
Clara Bayarri | b0812a3 | 2016-10-20 10:42:13 +0100 | [diff] [blame] | 31 | private final String mProviderAuthority; |
Clara Bayarri | 3c4be77 | 2017-02-07 15:33:40 +0000 | [diff] [blame] | 32 | private final String mProviderPackage; |
Clara Bayarri | b0812a3 | 2016-10-20 10:42:13 +0100 | [diff] [blame] | 33 | private final String mQuery; |
Clara Bayarri | 3c4be77 | 2017-02-07 15:33:40 +0000 | [diff] [blame] | 34 | private final List<List<byte[]>> mCertificates; |
| 35 | |
Seigo Nonaka | daa8dfc | 2017-04-19 12:16:39 -0700 | [diff] [blame] | 36 | // Used for key of the cache. |
| 37 | private final String mIdentifier; |
| 38 | |
Clara Bayarri | 3c4be77 | 2017-02-07 15:33:40 +0000 | [diff] [blame] | 39 | /** |
| 40 | * @param providerAuthority The authority of the Font Provider to be used for the request. This |
| 41 | * should be a system installed app. |
| 42 | * @param providerPackage The package for the Font Provider to be used for the request. This is |
| 43 | * used to verify the identity of the provider. |
| 44 | * @param query The query to be sent over to the provider. Refer to your font provider's |
| 45 | * documentation on the format of this string. |
| 46 | */ |
| 47 | public FontRequest(@NonNull String providerAuthority, @NonNull String providerPackage, |
| 48 | @NonNull String query) { |
| 49 | mProviderAuthority = Preconditions.checkNotNull(providerAuthority); |
| 50 | mQuery = Preconditions.checkNotNull(query); |
| 51 | mProviderPackage = Preconditions.checkNotNull(providerPackage); |
| 52 | mCertificates = Collections.emptyList(); |
Seigo Nonaka | daa8dfc | 2017-04-19 12:16:39 -0700 | [diff] [blame] | 53 | mIdentifier = new StringBuilder(mProviderAuthority).append("-").append(mProviderPackage) |
| 54 | .append("-").append(mQuery).toString(); |
Clara Bayarri | 3c4be77 | 2017-02-07 15:33:40 +0000 | [diff] [blame] | 55 | } |
Clara Bayarri | b0812a3 | 2016-10-20 10:42:13 +0100 | [diff] [blame] | 56 | |
| 57 | /** |
| 58 | * @param providerAuthority The authority of the Font Provider to be used for the request. |
| 59 | * @param query The query to be sent over to the provider. Refer to your font provider's |
Clara Bayarri | 3c4be77 | 2017-02-07 15:33:40 +0000 | [diff] [blame] | 60 | * documentation on the format of this string. |
| 61 | * @param providerPackage The package for the Font Provider to be used for the request. This is |
| 62 | * used to verify the identity of the provider. |
| 63 | * @param certificates The list of sets of hashes for the certificates the provider should be |
| 64 | * signed with. This is used to verify the identity of the provider. Each set in the |
| 65 | * list represents one collection of signature hashes. Refer to your font provider's |
| 66 | * documentation for these values. |
Clara Bayarri | b0812a3 | 2016-10-20 10:42:13 +0100 | [diff] [blame] | 67 | */ |
Clara Bayarri | 3c4be77 | 2017-02-07 15:33:40 +0000 | [diff] [blame] | 68 | public FontRequest(@NonNull String providerAuthority, @NonNull String providerPackage, |
| 69 | @NonNull String query, @NonNull List<List<byte[]>> certificates) { |
Clara Bayarri | b0812a3 | 2016-10-20 10:42:13 +0100 | [diff] [blame] | 70 | mProviderAuthority = Preconditions.checkNotNull(providerAuthority); |
Clara Bayarri | 3c4be77 | 2017-02-07 15:33:40 +0000 | [diff] [blame] | 71 | mProviderPackage = Preconditions.checkNotNull(providerPackage); |
Clara Bayarri | b0812a3 | 2016-10-20 10:42:13 +0100 | [diff] [blame] | 72 | mQuery = Preconditions.checkNotNull(query); |
Clara Bayarri | 3c4be77 | 2017-02-07 15:33:40 +0000 | [diff] [blame] | 73 | mCertificates = Preconditions.checkNotNull(certificates); |
Seigo Nonaka | daa8dfc | 2017-04-19 12:16:39 -0700 | [diff] [blame] | 74 | mIdentifier = new StringBuilder(mProviderAuthority).append("-").append(mProviderPackage) |
| 75 | .append("-").append(mQuery).toString(); |
Clara Bayarri | b0812a3 | 2016-10-20 10:42:13 +0100 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Returns the selected font provider's authority. This tells the system what font provider |
| 80 | * it should request the font from. |
| 81 | */ |
| 82 | public String getProviderAuthority() { |
| 83 | return mProviderAuthority; |
| 84 | } |
| 85 | |
| 86 | /** |
Clara Bayarri | 3c4be77 | 2017-02-07 15:33:40 +0000 | [diff] [blame] | 87 | * Returns the selected font provider's package. This helps the system verify that the provider |
| 88 | * identified by the given authority is the one requested. |
| 89 | */ |
| 90 | public String getProviderPackage() { |
| 91 | return mProviderPackage; |
| 92 | } |
| 93 | |
| 94 | /** |
Clara Bayarri | b0812a3 | 2016-10-20 10:42:13 +0100 | [diff] [blame] | 95 | * Returns the query string. Refer to your font provider's documentation on the format of this |
| 96 | * string. |
| 97 | */ |
| 98 | public String getQuery() { |
| 99 | return mQuery; |
| 100 | } |
| 101 | |
Clara Bayarri | 3c4be77 | 2017-02-07 15:33:40 +0000 | [diff] [blame] | 102 | /** |
| 103 | * Returns the list of certificate sets given for this provider. This helps the system verify |
| 104 | * that the provider identified by the given authority is the one requested. |
| 105 | */ |
| 106 | public List<List<byte[]>> getCertificates() { |
| 107 | return mCertificates; |
| 108 | } |
| 109 | |
Seigo Nonaka | daa8dfc | 2017-04-19 12:16:39 -0700 | [diff] [blame] | 110 | /** @hide */ |
| 111 | public String getIdentifier() { |
| 112 | return mIdentifier; |
| 113 | } |
| 114 | |
Clara Bayarri | b0812a3 | 2016-10-20 10:42:13 +0100 | [diff] [blame] | 115 | @Override |
Clara Bayarri | b0812a3 | 2016-10-20 10:42:13 +0100 | [diff] [blame] | 116 | public String toString() { |
Clara Bayarri | 3c4be77 | 2017-02-07 15:33:40 +0000 | [diff] [blame] | 117 | StringBuilder builder = new StringBuilder(); |
| 118 | builder.append("FontRequest {" |
Clara Bayarri | b0812a3 | 2016-10-20 10:42:13 +0100 | [diff] [blame] | 119 | + "mProviderAuthority: " + mProviderAuthority |
Clara Bayarri | 3c4be77 | 2017-02-07 15:33:40 +0000 | [diff] [blame] | 120 | + ", mProviderPackage: " + mProviderPackage |
Clara Bayarri | b0812a3 | 2016-10-20 10:42:13 +0100 | [diff] [blame] | 121 | + ", mQuery: " + mQuery |
Clara Bayarri | 3c4be77 | 2017-02-07 15:33:40 +0000 | [diff] [blame] | 122 | + ", mCertificates:"); |
| 123 | for (int i = 0; i < mCertificates.size(); i++) { |
| 124 | builder.append(" ["); |
| 125 | List<byte[]> set = mCertificates.get(i); |
| 126 | for (int j = 0; j < set.size(); j++) { |
| 127 | builder.append(" \""); |
| 128 | byte[] array = set.get(j); |
| 129 | builder.append(Base64.encodeToString(array, Base64.DEFAULT)); |
| 130 | builder.append("\""); |
| 131 | } |
| 132 | builder.append(" ]"); |
| 133 | } |
| 134 | builder.append("}"); |
| 135 | return builder.toString(); |
Clara Bayarri | b0812a3 | 2016-10-20 10:42:13 +0100 | [diff] [blame] | 136 | } |
| 137 | } |