1 /* 2 * Copyright (C) 2020 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.content.pm.parsing.component; 18 19 import static android.content.pm.parsing.ParsingPackageImpl.sForInternedString; 20 21 import android.annotation.NonNull; 22 import android.annotation.Nullable; 23 import android.content.ComponentName; 24 import android.content.pm.PathPermission; 25 import android.os.Parcel; 26 import android.os.Parcelable; 27 import android.os.PatternMatcher; 28 import android.text.TextUtils; 29 30 import com.android.internal.util.DataClass; 31 import com.android.internal.util.Parcelling.BuiltIn.ForInternedString; 32 33 /** @hide **/ 34 public class ParsedProvider extends ParsedMainComponent { 35 36 @NonNull 37 @DataClass.ParcelWith(ForInternedString.class) 38 private String authority; 39 boolean syncable; 40 @Nullable 41 @DataClass.ParcelWith(ForInternedString.class) 42 private String readPermission; 43 @Nullable 44 @DataClass.ParcelWith(ForInternedString.class) 45 private String writePermission; 46 boolean grantUriPermissions; 47 boolean forceUriPermissions; 48 boolean multiProcess; 49 int initOrder; 50 @Nullable 51 PatternMatcher[] uriPermissionPatterns; 52 @Nullable 53 PathPermission[] pathPermissions; 54 ParsedProvider(ParsedProvider other)55 public ParsedProvider(ParsedProvider other) { 56 super(other); 57 58 this.authority = other.authority; 59 this.syncable = other.syncable; 60 this.readPermission = other.readPermission; 61 this.writePermission = other.writePermission; 62 this.grantUriPermissions = other.grantUriPermissions; 63 this.forceUriPermissions = other.forceUriPermissions; 64 this.multiProcess = other.multiProcess; 65 this.initOrder = other.initOrder; 66 this.uriPermissionPatterns = other.uriPermissionPatterns; 67 this.pathPermissions = other.pathPermissions; 68 } 69 setAuthority(String authority)70 public void setAuthority(String authority) { 71 this.authority = TextUtils.safeIntern(authority); 72 } 73 setSyncable(boolean syncable)74 public void setSyncable(boolean syncable) { 75 this.syncable = syncable; 76 } 77 setReadPermission(String readPermission)78 public void setReadPermission(String readPermission) { 79 // Empty string must be converted to null 80 this.readPermission = TextUtils.isEmpty(readPermission) 81 ? null : readPermission.intern(); 82 } 83 setWritePermission(String writePermission)84 public void setWritePermission(String writePermission) { 85 // Empty string must be converted to null 86 this.writePermission = TextUtils.isEmpty(writePermission) 87 ? null : writePermission.intern(); 88 } 89 toString()90 public String toString() { 91 StringBuilder sb = new StringBuilder(128); 92 sb.append("Provider{"); 93 sb.append(Integer.toHexString(System.identityHashCode(this))); 94 sb.append(' '); 95 ComponentName.appendShortString(sb, getPackageName(), getName()); 96 sb.append('}'); 97 return sb.toString(); 98 } 99 100 @Override describeContents()101 public int describeContents() { 102 return 0; 103 } 104 105 @Override writeToParcel(Parcel dest, int flags)106 public void writeToParcel(Parcel dest, int flags) { 107 super.writeToParcel(dest, flags); 108 dest.writeString(this.authority); 109 dest.writeBoolean(this.syncable); 110 sForInternedString.parcel(this.readPermission, dest, flags); 111 sForInternedString.parcel(this.writePermission, dest, flags); 112 dest.writeBoolean(this.grantUriPermissions); 113 dest.writeBoolean(this.forceUriPermissions); 114 dest.writeBoolean(this.multiProcess); 115 dest.writeInt(this.initOrder); 116 dest.writeTypedArray(this.uriPermissionPatterns, flags); 117 dest.writeTypedArray(this.pathPermissions, flags); 118 } 119 ParsedProvider()120 public ParsedProvider() { 121 } 122 ParsedProvider(Parcel in)123 protected ParsedProvider(Parcel in) { 124 super(in); 125 //noinspection ConstantConditions 126 this.authority = in.readString(); 127 this.syncable = in.readBoolean(); 128 this.readPermission = sForInternedString.unparcel(in); 129 this.writePermission = sForInternedString.unparcel(in); 130 this.grantUriPermissions = in.readBoolean(); 131 this.forceUriPermissions = in.readBoolean(); 132 this.multiProcess = in.readBoolean(); 133 this.initOrder = in.readInt(); 134 this.uriPermissionPatterns = in.createTypedArray(PatternMatcher.CREATOR); 135 this.pathPermissions = in.createTypedArray(PathPermission.CREATOR); 136 } 137 138 public static final Parcelable.Creator<ParsedProvider> CREATOR = new Creator<ParsedProvider>() { 139 @Override 140 public ParsedProvider createFromParcel(Parcel source) { 141 return new ParsedProvider(source); 142 } 143 144 @Override 145 public ParsedProvider[] newArray(int size) { 146 return new ParsedProvider[size]; 147 } 148 }; 149 150 @NonNull getAuthority()151 public String getAuthority() { 152 return authority; 153 } 154 isSyncable()155 public boolean isSyncable() { 156 return syncable; 157 } 158 159 @Nullable getReadPermission()160 public String getReadPermission() { 161 return readPermission; 162 } 163 164 @Nullable getWritePermission()165 public String getWritePermission() { 166 return writePermission; 167 } 168 isGrantUriPermissions()169 public boolean isGrantUriPermissions() { 170 return grantUriPermissions; 171 } 172 isForceUriPermissions()173 public boolean isForceUriPermissions() { 174 return forceUriPermissions; 175 } 176 isMultiProcess()177 public boolean isMultiProcess() { 178 return multiProcess; 179 } 180 getInitOrder()181 public int getInitOrder() { 182 return initOrder; 183 } 184 185 @Nullable getUriPermissionPatterns()186 public PatternMatcher[] getUriPermissionPatterns() { 187 return uriPermissionPatterns; 188 } 189 190 @Nullable getPathPermissions()191 public PathPermission[] getPathPermissions() { 192 return pathPermissions; 193 } 194 } 195