blob: 0a929648cf47f010313c62d730ae762fbb864a2f [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
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
17package com.android.server.am;
18
Dianne Hackborn0c380492012-08-20 17:23:30 -070019import android.content.Context;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080020import android.content.Intent;
21import android.os.IBinder;
22
23import java.io.PrintWriter;
24import java.util.HashMap;
25import java.util.Iterator;
26
27/**
28 * A particular Intent that has been bound to a Service.
29 */
30class IntentBindRecord {
31 /** The running service. */
32 final ServiceRecord service;
33 /** The intent that is bound.*/
34 final Intent.FilterComparison intent; //
35 /** All apps that have bound to this Intent. */
36 final HashMap<ProcessRecord, AppBindRecord> apps
37 = new HashMap<ProcessRecord, AppBindRecord>();
38 /** Binder published from service. */
39 IBinder binder;
40 /** Set when we have initiated a request for this binder. */
41 boolean requested;
42 /** Set when we have received the requested binder. */
43 boolean received;
44 /** Set when we still need to tell the service all clients are unbound. */
45 boolean hasBound;
46 /** Set when the service's onUnbind() has asked to be told about new clients. */
47 boolean doRebind;
48
Dianne Hackborn1d442e02009-04-20 18:14:05 -070049 String stringName; // caching of toString
50
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080051 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070052 pw.print(prefix); pw.print("service="); pw.println(service);
53 dumpInService(pw, prefix);
54 }
55
56 void dumpInService(PrintWriter pw, String prefix) {
57 pw.print(prefix); pw.print("intent={");
Dianne Hackborn21c241e2012-03-08 13:57:23 -080058 pw.print(intent.getIntent().toShortString(false, true, false, false));
Dianne Hackborn1d442e02009-04-20 18:14:05 -070059 pw.println('}');
60 pw.print(prefix); pw.print("binder="); pw.println(binder);
61 pw.print(prefix); pw.print("requested="); pw.print(requested);
62 pw.print(" received="); pw.print(received);
63 pw.print(" hasBound="); pw.print(hasBound);
64 pw.print(" doRebind="); pw.println(doRebind);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080065 if (apps.size() > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080066 Iterator<AppBindRecord> it = apps.values().iterator();
67 while (it.hasNext()) {
68 AppBindRecord a = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070069 pw.print(prefix); pw.print("* Client AppBindRecord{");
70 pw.print(Integer.toHexString(System.identityHashCode(a)));
71 pw.print(' '); pw.print(a.client); pw.println('}');
72 a.dumpInIntentBind(pw, prefix + " ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080073 }
74 }
75 }
76
77 IntentBindRecord(ServiceRecord _service, Intent.FilterComparison _intent) {
78 service = _service;
79 intent = _intent;
80 }
81
Dianne Hackborn0c380492012-08-20 17:23:30 -070082 int collectFlags() {
83 int flags = 0;
84 if (apps.size() > 0) {
85 for (AppBindRecord app : apps.values()) {
86 if (app.connections.size() > 0) {
87 for (ConnectionRecord conn : app.connections) {
88 flags |= conn.flags;
89 }
90 }
91 }
92 }
93 return flags;
94 }
95
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080096 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070097 if (stringName != null) {
98 return stringName;
99 }
100 StringBuilder sb = new StringBuilder(128);
101 sb.append("IntentBindRecord{");
102 sb.append(Integer.toHexString(System.identityHashCode(this)));
103 sb.append(' ');
Dianne Hackborn0c380492012-08-20 17:23:30 -0700104 if ((collectFlags()&Context.BIND_AUTO_CREATE) != 0) {
105 sb.append("CR ");
106 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700107 sb.append(service.shortName);
108 sb.append(':');
109 if (intent != null) {
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800110 intent.getIntent().toShortString(sb, false, false, false, false);
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700111 }
112 sb.append('}');
113 return stringName = sb.toString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800114 }
115}