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