1 /* 2 * Copyright (C) 2018 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.app; 18 19 import android.annotation.NonNull; 20 import android.annotation.Nullable; 21 import android.content.UriPermission; 22 import android.net.Uri; 23 import android.os.Parcel; 24 import android.os.Parcelable; 25 26 /** 27 * Represents an {@link UriPermission} granted to a package. 28 * 29 * {@hide} 30 */ 31 public class GrantedUriPermission implements Parcelable { 32 33 public final Uri uri; 34 public final String packageName; 35 GrantedUriPermission(@onNull Uri uri, @Nullable String packageName)36 public GrantedUriPermission(@NonNull Uri uri, @Nullable String packageName) { 37 this.uri = uri; 38 this.packageName = packageName; 39 } 40 41 @Override toString()42 public String toString() { 43 return packageName + ":" + uri; 44 } 45 46 @Override describeContents()47 public int describeContents() { 48 return 0; 49 } 50 51 @Override writeToParcel(Parcel out, int flags)52 public void writeToParcel(Parcel out, int flags) { 53 out.writeParcelable(uri, flags); 54 out.writeString(packageName); 55 } 56 57 public static final @android.annotation.NonNull Parcelable.Creator<GrantedUriPermission> CREATOR = 58 new Parcelable.Creator<GrantedUriPermission>() { 59 @Override 60 public GrantedUriPermission createFromParcel(Parcel in) { 61 return new GrantedUriPermission(in); 62 } 63 64 @Override 65 public GrantedUriPermission[] newArray(int size) { 66 return new GrantedUriPermission[size]; 67 } 68 }; 69 GrantedUriPermission(Parcel in)70 private GrantedUriPermission(Parcel in) { 71 uri = in.readParcelable(null); 72 packageName = in.readString(); 73 } 74 } 75