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 */ 16 17 package android.telephony.mbms; 18 19 import android.annotation.SystemApi; 20 import android.annotation.TestApi; 21 import android.content.ContentResolver; 22 import android.net.Uri; 23 import android.os.Parcel; 24 import android.os.Parcelable; 25 import android.telephony.mbms.vendor.VendorUtils; 26 27 /** 28 * Wrapper for a pair of {@link Uri}s that describe a temp file used by the middleware to 29 * download files via cell-broadcast. 30 * @hide 31 */ 32 @SystemApi 33 @TestApi 34 public final class UriPathPair implements Parcelable { 35 private final Uri mFilePathUri; 36 private final Uri mContentUri; 37 38 /** @hide */ UriPathPair(Uri fileUri, Uri contentUri)39 public UriPathPair(Uri fileUri, Uri contentUri) { 40 if (fileUri == null || !ContentResolver.SCHEME_FILE.equals(fileUri.getScheme())) { 41 throw new IllegalArgumentException("File URI must have file scheme"); 42 } 43 if (contentUri == null || !ContentResolver.SCHEME_CONTENT.equals(contentUri.getScheme())) { 44 throw new IllegalArgumentException("Content URI must have content scheme"); 45 } 46 47 mFilePathUri = fileUri; 48 mContentUri = contentUri; 49 } 50 51 /** @hide */ UriPathPair(Parcel in)52 private UriPathPair(Parcel in) { 53 mFilePathUri = in.readParcelable(Uri.class.getClassLoader()); 54 mContentUri = in.readParcelable(Uri.class.getClassLoader()); 55 } 56 57 public static final @android.annotation.NonNull Creator<UriPathPair> CREATOR = new Creator<UriPathPair>() { 58 @Override 59 public UriPathPair createFromParcel(Parcel in) { 60 return new UriPathPair(in); 61 } 62 63 @Override 64 public UriPathPair[] newArray(int size) { 65 return new UriPathPair[size]; 66 } 67 }; 68 69 /** 70 * Returns the file-path {@link Uri}. This has scheme {@code file} and points to the actual 71 * location on disk where the temp file resides. Use this when sending {@link Uri}s back to the 72 * app in the intents in {@link VendorUtils}. 73 * @return A {@code file} {@link Uri}. 74 */ getFilePathUri()75 public Uri getFilePathUri() { 76 return mFilePathUri; 77 } 78 79 /** 80 * Returns the content {@link Uri} that may be used with 81 * {@link ContentResolver#openFileDescriptor(Uri, String)} to obtain a 82 * {@link android.os.ParcelFileDescriptor} to a temp file to write to. This {@link Uri} will 83 * expire if the middleware process dies. 84 * @return A {@code content} {@link Uri} 85 */ getContentUri()86 public Uri getContentUri() { 87 return mContentUri; 88 } 89 90 @Override describeContents()91 public int describeContents() { 92 return 0; 93 } 94 95 @Override writeToParcel(Parcel dest, int flags)96 public void writeToParcel(Parcel dest, int flags) { 97 dest.writeParcelable(mFilePathUri, flags); 98 dest.writeParcelable(mContentUri, flags); 99 } 100 } 101