The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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; |
Dianne Hackborn | b7bb3b3 | 2010-06-06 22:47:50 -0700 | [diff] [blame] | 20 | import android.content.ComponentName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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; |
Dianne Hackborn | b7bb3b3 | 2010-06-06 22:47:50 -0700 | [diff] [blame] | 33 | final ComponentName name; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 34 | 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 Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 37 | String stringName; |
| 38 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 39 | public ContentProviderRecord(ProviderInfo _info, ApplicationInfo ai) { |
| 40 | super(_info); |
| 41 | uid = ai.uid; |
| 42 | appInfo = ai; |
Dianne Hackborn | b7bb3b3 | 2010-06-06 22:47:50 -0700 | [diff] [blame] | 43 | name = new ComponentName(_info.packageName, _info.name); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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; |
Dianne Hackborn | b7bb3b3 | 2010-06-06 22:47:50 -0700 | [diff] [blame] | 51 | name = cpr.name; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 61 | pw.print(prefix); pw.print("package="); |
| 62 | pw.print(info.applicationInfo.packageName); |
Dianne Hackborn | e17aeb3 | 2011-04-07 15:11:57 -0700 | [diff] [blame] | 63 | pw.print(" process="); pw.println(info.processName); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 64 | 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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | public String toString() { |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 85 | 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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 95 | } |
| 96 | } |