Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.server.am; |
| 18 | |
| 19 | import android.os.Binder; |
Dianne Hackborn | d9137ca | 2012-05-30 15:29:36 -0700 | [diff] [blame] | 20 | import android.os.SystemClock; |
| 21 | import android.util.TimeUtils; |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 22 | |
| 23 | /** |
| 24 | * Represents a link between a content provider and client. |
| 25 | */ |
| 26 | public class ContentProviderConnection extends Binder { |
| 27 | public final ContentProviderRecord provider; |
| 28 | public final ProcessRecord client; |
Dianne Hackborn | d9137ca | 2012-05-30 15:29:36 -0700 | [diff] [blame] | 29 | public final long createTime; |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 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; |
| 41 | |
| 42 | public ContentProviderConnection(ContentProviderRecord _provider, ProcessRecord _client) { |
| 43 | provider = _provider; |
| 44 | client = _client; |
Dianne Hackborn | d9137ca | 2012-05-30 15:29:36 -0700 | [diff] [blame] | 45 | createTime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 46 | } |
| 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 Hackborn | d9137ca | 2012-05-30 15:29:36 -0700 | [diff] [blame] | 90 | long nowReal = SystemClock.elapsedRealtime(); |
| 91 | sb.append(" "); |
| 92 | TimeUtils.formatDuration(nowReal-createTime, sb); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 93 | } |
| 94 | } |