blob: 7f69b2467868a407eafa4deb3d35adae982d2a69 [file] [log] [blame]
Dianne Hackborn6ae8d182012-05-23 13:12:42 -07001/*
2 * Copyright (C) 2012 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.os.Binder;
Dianne Hackbornd9137ca2012-05-30 15:29:36 -070020import android.os.SystemClock;
21import android.util.TimeUtils;
Dianne Hackborn6ae8d182012-05-23 13:12:42 -070022
23/**
24 * Represents a link between a content provider and client.
25 */
26public class ContentProviderConnection extends Binder {
27 public final ContentProviderRecord provider;
28 public final ProcessRecord client;
Dianne Hackbornd9137ca2012-05-30 15:29:36 -070029 public final long createTime;
Dianne Hackborn6ae8d182012-05-23 13:12:42 -070030 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;
41
42 public ContentProviderConnection(ContentProviderRecord _provider, ProcessRecord _client) {
43 provider = _provider;
44 client = _client;
Dianne Hackbornd9137ca2012-05-30 15:29:36 -070045 createTime = SystemClock.elapsedRealtime();
Dianne Hackborn6ae8d182012-05-23 13:12:42 -070046 }
47
48 public String toString() {
49 StringBuilder sb = new StringBuilder(128);
50 sb.append("ContentProviderConnection{");
51 toShortString(sb);
52 sb.append('}');
53 return sb.toString();
54 }
55
56 public String toShortString() {
57 StringBuilder sb = new StringBuilder(128);
58 toShortString(sb);
59 return sb.toString();
60 }
61
62 public String toClientString() {
63 StringBuilder sb = new StringBuilder(128);
64 toClientString(sb);
65 return sb.toString();
66 }
67
68 public void toShortString(StringBuilder sb) {
69 sb.append(provider.toShortString());
70 sb.append("->");
71 toClientString(sb);
72 }
73
74 public void toClientString(StringBuilder sb) {
75 sb.append(client.toShortString());
76 sb.append(" s");
77 sb.append(stableCount);
78 sb.append("/");
79 sb.append(numStableIncs);
80 sb.append(" u");
81 sb.append(unstableCount);
82 sb.append("/");
83 sb.append(numUnstableIncs);
84 if (waiting) {
85 sb.append(" WAITING");
86 }
87 if (dead) {
88 sb.append(" DEAD");
89 }
Dianne Hackbornd9137ca2012-05-30 15:29:36 -070090 long nowReal = SystemClock.elapsedRealtime();
91 sb.append(" ");
92 TimeUtils.formatDuration(nowReal-createTime, sb);
Dianne Hackborn6ae8d182012-05-23 13:12:42 -070093 }
94}