blob: 9b6701e4debc52e4835b4bde7ceac0dbe8a8af45 [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
Suchi Amalapurapu1ccac752009-06-12 10:09:58 -070019import android.content.IIntentReceiver;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080020import android.content.Intent;
Dianne Hackborn1d442e02009-04-20 18:14:05 -070021import android.os.Binder;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080022import android.os.Bundle;
23import android.os.IBinder;
24import android.os.RemoteException;
Dianne Hackborn1d442e02009-04-20 18:14:05 -070025import android.util.PrintWriterPrinter;
26import android.util.Printer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080027
28import java.io.PrintWriter;
29import java.util.ArrayList;
30
31/**
32 * A receiver object that has registered for one or more broadcasts.
33 * The ArrayList holds BroadcastFilter objects.
34 */
35class ReceiverList extends ArrayList<BroadcastFilter>
36 implements IBinder.DeathRecipient {
37 final ActivityManagerService owner;
38 public final IIntentReceiver receiver;
39 public final ProcessRecord app;
40 public final int pid;
41 public final int uid;
Dianne Hackborn20e80982012-08-31 19:00:44 -070042 public final int userId;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080043 BroadcastRecord curBroadcast = null;
44 boolean linkedToDeath = false;
45
Dianne Hackbornf210d6b2009-04-13 18:42:49 -070046 String stringName;
47
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080048 ReceiverList(ActivityManagerService _owner, ProcessRecord _app,
Dianne Hackborn20e80982012-08-31 19:00:44 -070049 int _pid, int _uid, int _userId, IIntentReceiver _receiver) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080050 owner = _owner;
51 receiver = _receiver;
52 app = _app;
53 pid = _pid;
54 uid = _uid;
Dianne Hackborn20e80982012-08-31 19:00:44 -070055 userId = _userId;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080056 }
57
58 // Want object identity, not the array identity we are inheriting.
59 public boolean equals(Object o) {
60 return this == o;
61 }
62 public int hashCode() {
63 return System.identityHashCode(this);
64 }
65
66 public void binderDied() {
67 linkedToDeath = false;
68 owner.unregisterReceiver(receiver);
69 }
70
71 void dumpLocal(PrintWriter pw, String prefix) {
Dianne Hackborn20e80982012-08-31 19:00:44 -070072 pw.print(prefix); pw.print("app="); pw.print(app.toShortString());
73 pw.print(" pid="); pw.print(pid); pw.print(" uid="); pw.print(uid);
74 pw.print(" user="); pw.println(userId);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070075 if (curBroadcast != null || linkedToDeath) {
76 pw.print(prefix); pw.print("curBroadcast="); pw.print(curBroadcast);
77 pw.print(" linkedToDeath="); pw.println(linkedToDeath);
78 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080079 }
80
81 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070082 Printer pr = new PrintWriterPrinter(pw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080083 dumpLocal(pw, prefix);
84 String p2 = prefix + " ";
85 final int N = size();
86 for (int i=0; i<N; i++) {
87 BroadcastFilter bf = get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070088 pw.print(prefix); pw.print("Filter #"); pw.print(i);
89 pw.print(": BroadcastFilter{");
90 pw.print(Integer.toHexString(System.identityHashCode(bf)));
91 pw.println('}');
92 bf.dumpInReceiverList(pw, pr, p2);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080093 }
94 }
95
96 public String toString() {
Dianne Hackbornf210d6b2009-04-13 18:42:49 -070097 if (stringName != null) {
98 return stringName;
99 }
100 StringBuilder sb = new StringBuilder(128);
101 sb.append("ReceiverList{");
102 sb.append(Integer.toHexString(System.identityHashCode(this)));
103 sb.append(' ');
104 sb.append(pid);
105 sb.append(' ');
106 sb.append((app != null ? app.processName : "(unknown name)"));
107 sb.append('/');
108 sb.append(uid);
Dianne Hackborn20e80982012-08-31 19:00:44 -0700109 sb.append("/u");
110 sb.append(userId);
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700111 sb.append((receiver.asBinder() instanceof Binder) ? " local:" : " remote:");
Dianne Hackbornf210d6b2009-04-13 18:42:49 -0700112 sb.append(Integer.toHexString(System.identityHashCode(receiver.asBinder())));
113 sb.append('}');
114 return stringName = sb.toString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800115 }
116}