blob: c764635fa79d48983b5409c6106940629698b3e3 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
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.
Dianne Hackbornf210d6b2009-04-13 18:42:49 -070035 String stringName;
36
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080037 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) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070057 pw.print(prefix); pw.print("package=");
58 pw.print(info.applicationInfo.packageName);
59 pw.print("process="); pw.println(info.processName);
60 pw.print(prefix); pw.print("app="); pw.println(app);
61 if (launchingApp != null) {
62 pw.print(prefix); pw.print("launchingApp="); pw.println(launchingApp);
63 }
64 pw.print(prefix); pw.print("uid="); pw.print(uid);
65 pw.print(" provider="); pw.println(provider);
66 pw.print(prefix); pw.print("name="); pw.println(info.authority);
67 if (info.isSyncable || info.multiprocess || info.initOrder != 0) {
68 pw.print(prefix); pw.print("isSyncable="); pw.print(info.isSyncable);
69 pw.print("multiprocess="); pw.print(info.multiprocess);
70 pw.print(" initOrder="); pw.println(info.initOrder);
71 }
72 if (clients.size() > 0) {
73 pw.print(prefix); pw.print("clients="); pw.println(clients);
74 }
75 if (externals != 0) {
76 pw.print(prefix); pw.print("externals="); pw.println(externals);
77 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080078 }
79
80 public String toString() {
Dianne Hackbornf210d6b2009-04-13 18:42:49 -070081 if (stringName != null) {
82 return stringName;
83 }
84 StringBuilder sb = new StringBuilder(128);
85 sb.append("ContentProviderRecord{");
86 sb.append(Integer.toHexString(System.identityHashCode(this)));
87 sb.append(' ');
88 sb.append(info.name);
89 sb.append('}');
90 return stringName = sb.toString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080091 }
92}