ReceiverList.java revision 54b6cfa9a9e5b861a9930af873580d6dc20f773c
1/*
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
19import android.app.IIntentReceiver;
20import android.content.Intent;
21import android.os.Bundle;
22import android.os.IBinder;
23import android.os.RemoteException;
24
25import java.io.PrintWriter;
26import java.util.ArrayList;
27
28/**
29 * A receiver object that has registered for one or more broadcasts.
30 * The ArrayList holds BroadcastFilter objects.
31 */
32class ReceiverList extends ArrayList<BroadcastFilter>
33        implements IBinder.DeathRecipient {
34    final ActivityManagerService owner;
35    public final IIntentReceiver receiver;
36    public final ProcessRecord app;
37    public final int pid;
38    public final int uid;
39    BroadcastRecord curBroadcast = null;
40    boolean linkedToDeath = false;
41
42    ReceiverList(ActivityManagerService _owner, ProcessRecord _app,
43            int _pid, int _uid, IIntentReceiver _receiver) {
44        owner = _owner;
45        receiver = _receiver;
46        app = _app;
47        pid = _pid;
48        uid = _uid;
49    }
50
51    // Want object identity, not the array identity we are inheriting.
52    public boolean equals(Object o) {
53        return this == o;
54    }
55    public int hashCode() {
56        return System.identityHashCode(this);
57    }
58
59    public void binderDied() {
60        linkedToDeath = false;
61        owner.unregisterReceiver(receiver);
62    }
63
64    void dumpLocal(PrintWriter pw, String prefix) {
65        pw.println(prefix + "receiver=IBinder "
66                + Integer.toHexString(System.identityHashCode(receiver.asBinder())));
67        pw.println(prefix + "app=" + app + " pid=" + pid + " uid=" + uid);
68        pw.println(prefix + "curBroadcast=" + curBroadcast
69                + " linkedToDeath=" + linkedToDeath);
70    }
71
72    void dump(PrintWriter pw, String prefix) {
73        pw.println(prefix + this);
74        dumpLocal(pw, prefix);
75        String p2 = prefix + "  ";
76        final int N = size();
77        for (int i=0; i<N; i++) {
78            BroadcastFilter bf = get(i);
79            pw.println(prefix + "Filter #" + i + ": " + bf);
80            bf.dump(pw, p2);
81        }
82    }
83
84    public String toString() {
85        return "ReceiverList{"
86            + Integer.toHexString(System.identityHashCode(this))
87            + " " + pid + " " + (app != null ? app.processName : "(unknown name)")
88            + "/" + uid + " client "
89            + Integer.toHexString(System.identityHashCode(receiver.asBinder()))
90            + "}";
91    }
92}
93