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 17 package com.android.server.am; 18 19 import android.app.IActivityManager.ContentProviderHolder; 20 import android.content.ComponentName; 21 import android.content.pm.ApplicationInfo; 22 import android.content.pm.ProviderInfo; 23 import android.os.Process; 24 25 import java.io.PrintWriter; 26 import java.util.HashSet; 27 28 class ContentProviderRecord extends ContentProviderHolder { 29 // All attached clients 30 final HashSet<ProcessRecord> clients = new HashSet<ProcessRecord>(); 31 final int uid; 32 final ApplicationInfo appInfo; 33 final ComponentName name; 34 int externals; // number of non-framework processes supported by this provider 35 ProcessRecord proc; // if non-null, hosting process. 36 ProcessRecord launchingApp; // if non-null, waiting for this app to be launched. 37 String stringName; 38 39 public ContentProviderRecord(ProviderInfo _info, ApplicationInfo ai, ComponentName _name) { 40 super(_info); 41 uid = ai.uid; 42 appInfo = ai; 43 name = _name; 44 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; 51 name = cpr.name; 52 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) { 61 pw.print(prefix); pw.print("package="); 62 pw.print(info.applicationInfo.packageName); 63 pw.print(" process="); pw.println(info.processName); 64 pw.print(prefix); pw.print("proc="); pw.println(proc); 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 (externals != 0) { 77 pw.print(prefix); pw.print("externals="); pw.println(externals); 78 } 79 if (clients.size() > 0) { 80 pw.print(prefix); pw.println("Clients:"); 81 for (ProcessRecord cproc : clients) { 82 pw.print(prefix); pw.print(" - "); pw.println(cproc.toShortString()); 83 } 84 } 85 } 86 87 public String toString() { 88 if (stringName != null) { 89 return stringName; 90 } 91 StringBuilder sb = new StringBuilder(128); 92 sb.append("ContentProviderRecord{"); 93 sb.append(Integer.toHexString(System.identityHashCode(this))); 94 sb.append(' '); 95 sb.append(info.name); 96 sb.append('}'); 97 return stringName = sb.toString(); 98 } 99 } 100