blob: 21cf266c62b1974ca829d9686a454e1d69b54d90 [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;
Dianne Hackbornc8230512013-07-13 21:32:12 -070022import android.util.ArrayMap;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080023
24import java.io.PrintWriter;
25import java.util.HashMap;
26import java.util.Iterator;
27
28/**
29 * A particular Intent that has been bound to a Service.
30 */
Dianne Hackbornbe4e6aa2013-06-07 13:25:29 -070031final class IntentBindRecord {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080032 /** The running service. */
33 final ServiceRecord service;
34 /** The intent that is bound.*/
35 final Intent.FilterComparison intent; //
36 /** All apps that have bound to this Intent. */
Dianne Hackbornc8230512013-07-13 21:32:12 -070037 final ArrayMap<ProcessRecord, AppBindRecord> apps
38 = new ArrayMap<ProcessRecord, AppBindRecord>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080039 /** Binder published from service. */
40 IBinder binder;
41 /** Set when we have initiated a request for this binder. */
42 boolean requested;
43 /** Set when we have received the requested binder. */
44 boolean received;
45 /** Set when we still need to tell the service all clients are unbound. */
46 boolean hasBound;
47 /** Set when the service's onUnbind() has asked to be told about new clients. */
48 boolean doRebind;
49
Dianne Hackborn1d442e02009-04-20 18:14:05 -070050 String stringName; // caching of toString
51
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080052 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070053 pw.print(prefix); pw.print("service="); pw.println(service);
54 dumpInService(pw, prefix);
55 }
56
57 void dumpInService(PrintWriter pw, String prefix) {
58 pw.print(prefix); pw.print("intent={");
Dianne Hackborn21c241e2012-03-08 13:57:23 -080059 pw.print(intent.getIntent().toShortString(false, true, false, false));
Dianne Hackborn1d442e02009-04-20 18:14:05 -070060 pw.println('}');
61 pw.print(prefix); pw.print("binder="); pw.println(binder);
62 pw.print(prefix); pw.print("requested="); pw.print(requested);
63 pw.print(" received="); pw.print(received);
64 pw.print(" hasBound="); pw.print(hasBound);
65 pw.print(" doRebind="); pw.println(doRebind);
Dianne Hackbornc8230512013-07-13 21:32:12 -070066 for (int i=0; i<apps.size(); i++) {
67 AppBindRecord a = apps.valueAt(i);
68 pw.print(prefix); pw.print("* Client AppBindRecord{");
69 pw.print(Integer.toHexString(System.identityHashCode(a)));
70 pw.print(' '); pw.print(a.client); pw.println('}');
71 a.dumpInIntentBind(pw, prefix + " ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080072 }
73 }
74
75 IntentBindRecord(ServiceRecord _service, Intent.FilterComparison _intent) {
76 service = _service;
77 intent = _intent;
78 }
79
Dianne Hackborn0c380492012-08-20 17:23:30 -070080 int collectFlags() {
81 int flags = 0;
Dianne Hackbornc8230512013-07-13 21:32:12 -070082 for (int i=apps.size()-1; i>=0; i--) {
83 AppBindRecord app = apps.valueAt(i);
84 if (app.connections.size() > 0) {
85 for (ConnectionRecord conn : app.connections) {
86 flags |= conn.flags;
Dianne Hackborn0c380492012-08-20 17:23:30 -070087 }
88 }
89 }
90 return flags;
91 }
92
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080093 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070094 if (stringName != null) {
95 return stringName;
96 }
97 StringBuilder sb = new StringBuilder(128);
98 sb.append("IntentBindRecord{");
99 sb.append(Integer.toHexString(System.identityHashCode(this)));
100 sb.append(' ');
Dianne Hackborn0c380492012-08-20 17:23:30 -0700101 if ((collectFlags()&Context.BIND_AUTO_CREATE) != 0) {
102 sb.append("CR ");
103 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700104 sb.append(service.shortName);
105 sb.append(':');
106 if (intent != null) {
Dianne Hackborn21c241e2012-03-08 13:57:23 -0800107 intent.getIntent().toShortString(sb, false, false, false, false);
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700108 }
109 sb.append('}');
110 return stringName = sb.toString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800111 }
112}