blob: db235ee849e2e8a5fe9cda0ce91b60a1fa8875a0 [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;
Dianne Hackbornb7bb3b32010-06-06 22:47:50 -070020import android.content.ComponentName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080021import android.content.pm.ApplicationInfo;
22import android.content.pm.ProviderInfo;
23import android.os.Process;
24
25import java.io.PrintWriter;
26import java.util.HashSet;
27
28class ContentProviderRecord extends ContentProviderHolder {
29 // All attached clients
30 final HashSet<ProcessRecord> clients = new HashSet<ProcessRecord>();
31 final int uid;
32 final ApplicationInfo appInfo;
Dianne Hackbornb7bb3b32010-06-06 22:47:50 -070033 final ComponentName name;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080034 int externals; // number of non-framework processes supported by this provider
35 ProcessRecord app; // if non-null, hosting application
36 ProcessRecord launchingApp; // if non-null, waiting for this app to be launched.
Dianne Hackbornf210d6b2009-04-13 18:42:49 -070037 String stringName;
38
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080039 public ContentProviderRecord(ProviderInfo _info, ApplicationInfo ai) {
40 super(_info);
41 uid = ai.uid;
42 appInfo = ai;
Dianne Hackbornb7bb3b32010-06-06 22:47:50 -070043 name = new ComponentName(_info.packageName, _info.name);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080044 noReleaseNeeded = uid == 0 || uid == Process.SYSTEM_UID;
45 }
46
47 public ContentProviderRecord(ContentProviderRecord cpr) {
48 super(cpr.info);
49 uid = cpr.uid;
50 appInfo = cpr.appInfo;
Dianne Hackbornb7bb3b32010-06-06 22:47:50 -070051 name = cpr.name;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080052 noReleaseNeeded = cpr.noReleaseNeeded;
53 }
54
55 public boolean canRunHere(ProcessRecord app) {
56 return (info.multiprocess || info.processName.equals(app.processName))
57 && (uid == Process.SYSTEM_UID || uid == app.info.uid);
58 }
59
60 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070061 pw.print(prefix); pw.print("package=");
62 pw.print(info.applicationInfo.packageName);
Dianne Hackborne17aeb32011-04-07 15:11:57 -070063 pw.print(" process="); pw.println(info.processName);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070064 pw.print(prefix); pw.print("app="); pw.println(app);
65 if (launchingApp != null) {
66 pw.print(prefix); pw.print("launchingApp="); pw.println(launchingApp);
67 }
68 pw.print(prefix); pw.print("uid="); pw.print(uid);
69 pw.print(" provider="); pw.println(provider);
70 pw.print(prefix); pw.print("name="); pw.println(info.authority);
71 if (info.isSyncable || info.multiprocess || info.initOrder != 0) {
72 pw.print(prefix); pw.print("isSyncable="); pw.print(info.isSyncable);
73 pw.print("multiprocess="); pw.print(info.multiprocess);
74 pw.print(" initOrder="); pw.println(info.initOrder);
75 }
76 if (clients.size() > 0) {
77 pw.print(prefix); pw.print("clients="); pw.println(clients);
78 }
79 if (externals != 0) {
80 pw.print(prefix); pw.print("externals="); pw.println(externals);
81 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080082 }
83
84 public String toString() {
Dianne Hackbornf210d6b2009-04-13 18:42:49 -070085 if (stringName != null) {
86 return stringName;
87 }
88 StringBuilder sb = new StringBuilder(128);
89 sb.append("ContentProviderRecord{");
90 sb.append(Integer.toHexString(System.identityHashCode(this)));
91 sb.append(' ');
92 sb.append(info.name);
93 sb.append('}');
94 return stringName = sb.toString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080095 }
96}