ProviderInfo.java revision 2af632f87d487deaa5b2eb71341cfc4f0c0d1173
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
17package android.content.pm;
18
19import android.os.Parcel;
20import android.os.Parcelable;
21import android.os.PatternMatcher;
22
23/**
24 * Holds information about a specific
25 * {@link android.content.ContentProvider content provider}. This is returned by
26 * {@link android.content.pm.PackageManager#resolveContentProvider(java.lang.String, int)
27 * PackageManager.resolveContentProvider()}.
28 */
29public final class ProviderInfo extends ComponentInfo
30        implements Parcelable {
31
32    /** The name provider is published under content:// */
33    public String authority = null;
34
35    /** Optional permission required for read-only access this content
36     * provider. */
37    public String readPermission = null;
38
39    /** Optional permission required for read/write access this content
40     * provider. */
41    public String writePermission = null;
42
43    /** If true, additional permissions to specific Uris in this content
44     * provider can be granted, as per the
45     * {@link android.R.styleable#AndroidManifestProvider_grantUriPermissions
46     * grantUriPermissions} attribute.
47     */
48    public boolean grantUriPermissions = false;
49
50    /**
51     * If non-null, these are the patterns that are allowed for granting URI
52     * permissions.  Any URI that does not match one of these patterns will not
53     * allowed to be granted.  If null, all URIs are allowed.  The
54     * {@link PackageManager#GET_URI_PERMISSION_PATTERNS
55     * PackageManager.GET_URI_PERMISSION_PATTERNS} flag must be specified for
56     * this field to be filled in.
57     */
58    public PatternMatcher[] uriPermissionPatterns = null;
59
60    /**
61     * If non-null, these are path-specific permissions that are allowed for
62     * accessing the provider.  Any permissions listed here will allow a
63     * holding client to access the provider, and the provider will check
64     * the URI it provides when making calls against the patterns here.
65     */
66    public PathPermission[] pathPermissions = null;
67
68    /** If true, this content provider allows multiple instances of itself
69     *  to run in different process.  If false, a single instances is always
70     *  run in {@link #processName}. */
71    public boolean multiprocess = false;
72
73    /** Used to control initialization order of single-process providers
74     *  running in the same process.  Higher goes first. */
75    public int initOrder = 0;
76
77    /** Whether or not this provider is syncable. */
78    public boolean isSyncable = false;
79
80    public ProviderInfo() {
81    }
82
83    public ProviderInfo(ProviderInfo orig) {
84        super(orig);
85        authority = orig.authority;
86        readPermission = orig.readPermission;
87        writePermission = orig.writePermission;
88        grantUriPermissions = orig.grantUriPermissions;
89        uriPermissionPatterns = orig.uriPermissionPatterns;
90        pathPermissions = orig.pathPermissions;
91        multiprocess = orig.multiprocess;
92        initOrder = orig.initOrder;
93        isSyncable = orig.isSyncable;
94    }
95
96    public int describeContents() {
97        return 0;
98    }
99
100    @Override public void writeToParcel(Parcel out, int parcelableFlags) {
101        super.writeToParcel(out, parcelableFlags);
102        out.writeString(authority);
103        out.writeString(readPermission);
104        out.writeString(writePermission);
105        out.writeInt(grantUriPermissions ? 1 : 0);
106        out.writeTypedArray(uriPermissionPatterns, parcelableFlags);
107        out.writeTypedArray(pathPermissions, parcelableFlags);
108        out.writeInt(multiprocess ? 1 : 0);
109        out.writeInt(initOrder);
110        out.writeInt(isSyncable ? 1 : 0);
111    }
112
113    public static final Parcelable.Creator<ProviderInfo> CREATOR
114            = new Parcelable.Creator<ProviderInfo>() {
115        public ProviderInfo createFromParcel(Parcel in) {
116            return new ProviderInfo(in);
117        }
118
119        public ProviderInfo[] newArray(int size) {
120            return new ProviderInfo[size];
121        }
122    };
123
124    public String toString() {
125        return "ContentProviderInfo{name=" + authority + " className=" + name
126            + " isSyncable=" + (isSyncable ? "true" : "false") + "}";
127    }
128
129    private ProviderInfo(Parcel in) {
130        super(in);
131        authority = in.readString();
132        readPermission = in.readString();
133        writePermission = in.readString();
134        grantUriPermissions = in.readInt() != 0;
135        uriPermissionPatterns = in.createTypedArray(PatternMatcher.CREATOR);
136        pathPermissions = in.createTypedArray(PathPermission.CREATOR);
137        multiprocess = in.readInt() != 0;
138        initOrder = in.readInt();
139        isSyncable = in.readInt() != 0;
140    }
141}
142