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    /**
78     * Bit in {@link #flags}: If set, a single instance of the provider will
79     * run for all users on the device.  Set from the
80     * {@link android.R.attr#singleUser} attribute.
81     */
82    public static final int FLAG_SINGLE_USER = 0x40000000;
83
84    /**
85     * Options that have been set in the provider declaration in the
86     * manifest.
87     * These include: {@link #FLAG_SINGLE_USER}.
88     */
89    public int flags = 0;
90
91    /**
92     * Whether or not this provider is syncable.
93     * @deprecated This flag is now being ignored. The current way to make a provider
94     * syncable is to provide a SyncAdapter service for a given provider/account type.
95     */
96    @Deprecated
97    public boolean isSyncable = false;
98
99    public ProviderInfo() {
100    }
101
102    public ProviderInfo(ProviderInfo orig) {
103        super(orig);
104        authority = orig.authority;
105        readPermission = orig.readPermission;
106        writePermission = orig.writePermission;
107        grantUriPermissions = orig.grantUriPermissions;
108        uriPermissionPatterns = orig.uriPermissionPatterns;
109        pathPermissions = orig.pathPermissions;
110        multiprocess = orig.multiprocess;
111        initOrder = orig.initOrder;
112        flags = orig.flags;
113        isSyncable = orig.isSyncable;
114    }
115
116    public int describeContents() {
117        return 0;
118    }
119
120    @Override public void writeToParcel(Parcel out, int parcelableFlags) {
121        super.writeToParcel(out, parcelableFlags);
122        out.writeString(authority);
123        out.writeString(readPermission);
124        out.writeString(writePermission);
125        out.writeInt(grantUriPermissions ? 1 : 0);
126        out.writeTypedArray(uriPermissionPatterns, parcelableFlags);
127        out.writeTypedArray(pathPermissions, parcelableFlags);
128        out.writeInt(multiprocess ? 1 : 0);
129        out.writeInt(initOrder);
130        out.writeInt(flags);
131        out.writeInt(isSyncable ? 1 : 0);
132    }
133
134    public static final Parcelable.Creator<ProviderInfo> CREATOR
135            = new Parcelable.Creator<ProviderInfo>() {
136        public ProviderInfo createFromParcel(Parcel in) {
137            return new ProviderInfo(in);
138        }
139
140        public ProviderInfo[] newArray(int size) {
141            return new ProviderInfo[size];
142        }
143    };
144
145    public String toString() {
146        return "ContentProviderInfo{name=" + authority + " className=" + name + "}";
147    }
148
149    private ProviderInfo(Parcel in) {
150        super(in);
151        authority = in.readString();
152        readPermission = in.readString();
153        writePermission = in.readString();
154        grantUriPermissions = in.readInt() != 0;
155        uriPermissionPatterns = in.createTypedArray(PatternMatcher.CREATOR);
156        pathPermissions = in.createTypedArray(PathPermission.CREATOR);
157        multiprocess = in.readInt() != 0;
158        initOrder = in.readInt();
159        flags = in.readInt();
160        isSyncable = in.readInt() != 0;
161    }
162}
163