ContentProvider相关数据结构
2018-12-12 本文已影响0人
weiinter105
客户端/服务端App数据结构
ActivityThread
322 // The lock of mProviderMap protects the following variables.
323 final ArrayMap<ProviderKey, ProviderClientRecord> mProviderMap
324 = new ArrayMap<ProviderKey, ProviderClientRecord>();
332 final ArrayMap<IBinder, ProviderClientRecord> mLocalProviders
333 = new ArrayMap<IBinder, ProviderClientRecord>();
//IBinder ->IContentProvider 代表服务端ContentProvider的代理
298 private static final class ProviderKey {
299 final String authority;
300 final int userId; //包含URL authority字符串
分三个角度来保存ProviderClientRecord
与AMS端的ContentProviderRecord想对应,主要保存IContentProvider (ContentProvider binder proxy)
465 final class ProviderClientRecord {
466 final String[] mNames;
467 final IContentProvider mProvider;
468 final ContentProvider mLocalProvider;
469 final ContentProviderHolder mHolder;
470
471 ProviderClientRecord(String[] names, IContentProvider provider,
472 ContentProvider localProvider, ContentProviderHolder holder) {
473 mNames = names;
474 mProvider = provider;
475 mLocalProvider = localProvider;
476 mHolder = holder;
477 }
478 }
frameworks/base/core/java/android/app/ContentProviderHolder
31public class ContentProviderHolder implements Parcelable {
32 public final ProviderInfo info;
33 public IContentProvider provider; //服务端ContentProvider proxy
34 public IBinder connection; //客户端在AMS中的表示,ContentProviderConnection对象的proxy,用于操作AMS中ContentProviderConnection对象的引用技术
35 public boolean noReleaseNeeded;
330 final ArrayMap<IBinder, ProviderRefCount> mProviderRefCountMap
331 = new ArrayMap<IBinder, ProviderRefCount>();
ProviderRefCount: 封装了stable, unstable两种引用
4003 private static final class ProviderRefCount {
4004 public final ContentProviderHolder holder;
4005 public final ProviderClientRecord client;
4006 public int stableCount;
4007 public int unstableCount;
provider_app.jpg
system_server AMS中的数据结构
frameworks/base/services/core/java/com/android/server/am/ActivityManagerService
mProviderMap = new ProviderMap(this);
AMS端用来缓存ContentProviderRecord的对象,提供四种不同的查询方式
36/**
37 * Keeps track of content providers by authority (name) and class. It separates the mapping by
38 * user and ones that are not user-specific (system providers).
39 */
40public final class ProviderMap {
41
42 private static final String TAG = "ProviderMap";
43
44 private static final boolean DBG = false;
45
46 private final ActivityManagerService mAm;
47
48 private final HashMap<String, ContentProviderRecord> mSingletonByName
49 = new HashMap<String, ContentProviderRecord>();
50 private final HashMap<ComponentName, ContentProviderRecord> mSingletonByClass
51 = new HashMap<ComponentName, ContentProviderRecord>();
52
53 private final SparseArray<HashMap<String, ContentProviderRecord>> mProvidersByNamePerUser
54 = new SparseArray<HashMap<String, ContentProviderRecord>>();
55 private final SparseArray<HashMap<ComponentName, ContentProviderRecord>> mProvidersByClassPerUser
56 = new SparseArray<HashMap<ComponentName, ContentProviderRecord>>();
frameworks/base/services/core/java/com/android/server/am/ContentProviderRecord.java
provider在AMS中的封装类,主要引用了provider binder proxy、进程信息
35final class ContentProviderRecord {
36 final ActivityManagerService service;
37 public final ProviderInfo info;
38 final int uid;
39 final ApplicationInfo appInfo;
40 final ComponentName name;
41 final boolean singleton;
42 public IContentProvider provider; //服务端ContentProvider实例的binder对象
43 public boolean noReleaseNeeded;
44 // All attached clients
45 final ArrayList<ContentProviderConnection> connections
46 = new ArrayList<ContentProviderConnection>(); //对这个ContentProvider进行操作的客户端信息
47 //final HashSet<ProcessRecord> clients = new HashSet<ProcessRecord>();
48 // Handles for non-framework processes supported by this provider
49 HashMap<IBinder, ExternalProcessHandle> externalProcessTokenToHandle;
50 // Count for external process for which we have no handles.
51 int externalProcessNoHandleCount;
52 ProcessRecord proc; // if non-null, hosting process. //ContentProvider所在的宿主进程
53 ProcessRecord launchingApp; // if non-null, waiting for this app to be launched.
54 String stringName;
55 String shortStringName;
frameworks/base/services/core/java/com/android/server/am/ContentProviderConnection.java
主要引用了provider客户端的进程抽象,包含其要操作的ContentProvider端的信息ContentProviderRecord,以及客户端stable,unstable的引用计数
23/**
24 * Represents a link between a content provider and client.
25 */
26public final class ContentProviderConnection extends Binder {
27 public final ContentProviderRecord provider;
28 public final ProcessRecord client;
29 public final long createTime;
30 public int stableCount;
31 public int unstableCount;
32 // The client of this connection is currently waiting for the provider to appear.
33 // Protected by the provider lock.
34 public boolean waiting;
35 // The provider of this connection is now dead.
36 public boolean dead;
37
38 // For debugging.
39 public int numStableIncs;
40 public int numUnstableIncs;
provider_system_server.jpg