1 /*
2  * Copyright (C) 2006 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;
18 
19 import android.os.Parcel;
20 import android.os.Parcelable;
21 import android.os.PatternMatcher;
22 import android.util.Printer;
23 
24 /**
25  * Holds information about a specific
26  * {@link android.content.ContentProvider content provider}. This is returned by
27  * {@link android.content.pm.PackageManager#resolveContentProvider(java.lang.String, int)
28  * PackageManager.resolveContentProvider()}.
29  */
30 public final class ProviderInfo extends ComponentInfo
31         implements Parcelable {
32 
33     /** The name provider is published under content:// */
34     public String authority = null;
35 
36     /** Optional permission required for read-only access this content
37      * provider. */
38     public String readPermission = null;
39 
40     /** Optional permission required for read/write access this content
41      * provider. */
42     public String writePermission = null;
43 
44     /** If true, additional permissions to specific Uris in this content
45      * provider can be granted, as per the
46      * {@link android.R.styleable#AndroidManifestProvider_grantUriPermissions
47      * grantUriPermissions} attribute.
48      */
49     public boolean grantUriPermissions = false;
50 
51     /**
52      * If non-null, these are the patterns that are allowed for granting URI
53      * permissions.  Any URI that does not match one of these patterns will not
54      * allowed to be granted.  If null, all URIs are allowed.  The
55      * {@link PackageManager#GET_URI_PERMISSION_PATTERNS
56      * PackageManager.GET_URI_PERMISSION_PATTERNS} flag must be specified for
57      * this field to be filled in.
58      */
59     public PatternMatcher[] uriPermissionPatterns = null;
60 
61     /**
62      * If non-null, these are path-specific permissions that are allowed for
63      * accessing the provider.  Any permissions listed here will allow a
64      * holding client to access the provider, and the provider will check
65      * the URI it provides when making calls against the patterns here.
66      */
67     public PathPermission[] pathPermissions = null;
68 
69     /** If true, this content provider allows multiple instances of itself
70      *  to run in different process.  If false, a single instances is always
71      *  run in {@link #processName}. */
72     public boolean multiprocess = false;
73 
74     /** Used to control initialization order of single-process providers
75      *  running in the same process.  Higher goes first. */
76     public int initOrder = 0;
77 
78     /**
79      * Bit in {@link #flags}: If set, a single instance of the provider will
80      * run for all users on the device.  Set from the
81      * {@link android.R.attr#singleUser} attribute.
82      */
83     public static final int FLAG_SINGLE_USER = 0x40000000;
84 
85     /**
86      * Options that have been set in the provider declaration in the
87      * manifest.
88      * These include: {@link #FLAG_SINGLE_USER}.
89      */
90     public int flags = 0;
91 
92     /**
93      * Whether or not this provider is syncable.
94      * @deprecated This flag is now being ignored. The current way to make a provider
95      * syncable is to provide a SyncAdapter service for a given provider/account type.
96      */
97     @Deprecated
98     public boolean isSyncable = false;
99 
ProviderInfo()100     public ProviderInfo() {
101     }
102 
ProviderInfo(ProviderInfo orig)103     public ProviderInfo(ProviderInfo orig) {
104         super(orig);
105         authority = orig.authority;
106         readPermission = orig.readPermission;
107         writePermission = orig.writePermission;
108         grantUriPermissions = orig.grantUriPermissions;
109         uriPermissionPatterns = orig.uriPermissionPatterns;
110         pathPermissions = orig.pathPermissions;
111         multiprocess = orig.multiprocess;
112         initOrder = orig.initOrder;
113         flags = orig.flags;
114         isSyncable = orig.isSyncable;
115     }
116 
dump(Printer pw, String prefix)117     public void dump(Printer pw, String prefix) {
118         dump(pw, prefix, DUMP_FLAG_ALL);
119     }
120 
121     /** @hide */
dump(Printer pw, String prefix, int flags)122     public void dump(Printer pw, String prefix, int flags) {
123         super.dumpFront(pw, prefix);
124         pw.println(prefix + "authority=" + authority);
125         pw.println(prefix + "flags=0x" + Integer.toHexString(flags));
126         super.dumpBack(pw, prefix, flags);
127     }
128 
describeContents()129     public int describeContents() {
130         return 0;
131     }
132 
writeToParcel(Parcel out, int parcelableFlags)133     @Override public void writeToParcel(Parcel out, int parcelableFlags) {
134         super.writeToParcel(out, parcelableFlags);
135         out.writeString(authority);
136         out.writeString(readPermission);
137         out.writeString(writePermission);
138         out.writeInt(grantUriPermissions ? 1 : 0);
139         out.writeTypedArray(uriPermissionPatterns, parcelableFlags);
140         out.writeTypedArray(pathPermissions, parcelableFlags);
141         out.writeInt(multiprocess ? 1 : 0);
142         out.writeInt(initOrder);
143         out.writeInt(flags);
144         out.writeInt(isSyncable ? 1 : 0);
145     }
146 
147     public static final Parcelable.Creator<ProviderInfo> CREATOR
148             = new Parcelable.Creator<ProviderInfo>() {
149         public ProviderInfo createFromParcel(Parcel in) {
150             return new ProviderInfo(in);
151         }
152 
153         public ProviderInfo[] newArray(int size) {
154             return new ProviderInfo[size];
155         }
156     };
157 
toString()158     public String toString() {
159         return "ContentProviderInfo{name=" + authority + " className=" + name + "}";
160     }
161 
ProviderInfo(Parcel in)162     private ProviderInfo(Parcel in) {
163         super(in);
164         authority = in.readString();
165         readPermission = in.readString();
166         writePermission = in.readString();
167         grantUriPermissions = in.readInt() != 0;
168         uriPermissionPatterns = in.createTypedArray(PatternMatcher.CREATOR);
169         pathPermissions = in.createTypedArray(PathPermission.CREATOR);
170         multiprocess = in.readInt() != 0;
171         initOrder = in.readInt();
172         flags = in.readInt();
173         isSyncable = in.readInt() != 0;
174     }
175 }
176