ContentProviderRecord.java revision f210d6b75e2c0fe60b90c074ff9f615c1137f23e
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 com.android.server.am;
18
19import android.app.IActivityManager.ContentProviderHolder;
20import android.content.pm.ApplicationInfo;
21import android.content.pm.ProviderInfo;
22import android.os.Process;
23
24import java.io.PrintWriter;
25import java.util.HashSet;
26
27class ContentProviderRecord extends ContentProviderHolder {
28    // All attached clients
29    final HashSet<ProcessRecord> clients = new HashSet<ProcessRecord>();
30    final int uid;
31    final ApplicationInfo appInfo;
32    int externals;     // number of non-framework processes supported by this provider
33    ProcessRecord app; // if non-null, hosting application
34    ProcessRecord launchingApp; // if non-null, waiting for this app to be launched.
35    String stringName;
36
37    public ContentProviderRecord(ProviderInfo _info, ApplicationInfo ai) {
38        super(_info);
39        uid = ai.uid;
40        appInfo = ai;
41        noReleaseNeeded = uid == 0 || uid == Process.SYSTEM_UID;
42    }
43
44    public ContentProviderRecord(ContentProviderRecord cpr) {
45        super(cpr.info);
46        uid = cpr.uid;
47        appInfo = cpr.appInfo;
48        noReleaseNeeded = cpr.noReleaseNeeded;
49    }
50
51    public boolean canRunHere(ProcessRecord app) {
52        return (info.multiprocess || info.processName.equals(app.processName))
53                && (uid == Process.SYSTEM_UID || uid == app.info.uid);
54    }
55
56    void dump(PrintWriter pw, String prefix) {
57        pw.println(prefix + this);
58        pw.println(prefix + "package=" + info.applicationInfo.packageName
59              + " process=" + info.processName);
60        pw.println(prefix + "app=" + app);
61        pw.println(prefix + "launchingApp=" + launchingApp);
62        pw.println(prefix + "provider=" + provider);
63        pw.println(prefix + "name=" + info.authority);
64        pw.println(prefix + "isSyncable=" + info.isSyncable);
65        pw.println(prefix + "multiprocess=" + info.multiprocess
66              + " initOrder=" + info.initOrder
67              + " uid=" + uid);
68        pw.println(prefix + "clients=" + clients);
69        pw.println(prefix + "externals=" + externals);
70    }
71
72    public String toString() {
73        if (stringName != null) {
74            return stringName;
75        }
76        StringBuilder sb = new StringBuilder(128);
77        sb.append("ContentProviderRecord{");
78        sb.append(Integer.toHexString(System.identityHashCode(this)));
79        sb.append(' ');
80        sb.append(info.name);
81        sb.append('}');
82        return stringName = sb.toString();
83    }
84}
85