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 android.webkit;
18 
19 import android.annotation.SystemApi;
20 import android.annotation.UnsupportedAppUsage;
21 import android.content.pm.Signature;
22 import android.os.Parcel;
23 import android.os.Parcelable;
24 import android.util.Base64;
25 
26 /**
27  * @hide
28  */
29 @SystemApi
30 public final class WebViewProviderInfo implements Parcelable {
31 
WebViewProviderInfo(String packageName, String description, boolean availableByDefault, boolean isFallback, String[] signatures)32     public WebViewProviderInfo(String packageName, String description,
33             boolean availableByDefault, boolean isFallback, String[] signatures) {
34         this.packageName = packageName;
35         this.description = description;
36         this.availableByDefault = availableByDefault;
37         this.isFallback = isFallback;
38         if (signatures == null) {
39             this.signatures = new Signature[0];
40         } else {
41             this.signatures = new Signature[signatures.length];
42             for (int n = 0; n < signatures.length; n++) {
43                 this.signatures[n] = new Signature(Base64.decode(signatures[n], Base64.DEFAULT));
44             }
45         }
46     }
47 
48     // aidl stuff
49     public static final @android.annotation.NonNull Parcelable.Creator<WebViewProviderInfo> CREATOR =
50         new Parcelable.Creator<WebViewProviderInfo>() {
51             public WebViewProviderInfo createFromParcel(Parcel in) {
52                 return new WebViewProviderInfo(in);
53             }
54 
55             public WebViewProviderInfo[] newArray(int size) {
56                 return new WebViewProviderInfo[size];
57             }
58         };
59 
60     @UnsupportedAppUsage
WebViewProviderInfo(Parcel in)61     private WebViewProviderInfo(Parcel in) {
62         packageName = in.readString();
63         description = in.readString();
64         availableByDefault = (in.readInt() > 0);
65         isFallback = (in.readInt() > 0);
66         signatures = in.createTypedArray(Signature.CREATOR);
67     }
68 
69     @Override
describeContents()70     public int describeContents() {
71         return 0;
72     }
73 
74     @Override
writeToParcel(Parcel out, int flags)75     public void writeToParcel(Parcel out, int flags) {
76         out.writeString(packageName);
77         out.writeString(description);
78         out.writeInt(availableByDefault ? 1 : 0);
79         out.writeInt(isFallback ? 1 : 0);
80         out.writeTypedArray(signatures, 0);
81     }
82 
83     // fields read from framework resource
84     public final String packageName;
85     public final String description;
86     public final boolean availableByDefault;
87     public final boolean isFallback;
88     public final Signature[] signatures;
89 }
90