ReceiverList.java revision 1ccac75e1f1b97eccb916a8de04fc1012b30f6e5
1cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn/*
2ac5fe7c617c66850fff75a9fce9979c6e5674b0fAurimas Liutikas * Copyright (C) 2006 The Android Open Source Project
3cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn *
4cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Licensed under the Apache License, Version 2.0 (the "License");
5cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * you may not use this file except in compliance with the License.
6cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * You may obtain a copy of the License at
7cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn *
8cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn *      http://www.apache.org/licenses/LICENSE-2.0
9cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn *
10cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Unless required by applicable law or agreed to in writing, software
11cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * distributed under the License is distributed on an "AS IS" BASIS,
12cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * See the License for the specific language governing permissions and
14cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * limitations under the License.
15cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */
16cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
17ac5fe7c617c66850fff75a9fce9979c6e5674b0fAurimas Liutikaspackage com.android.server.am;
18cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
19ac5fe7c617c66850fff75a9fce9979c6e5674b0fAurimas Liutikasimport android.content.IIntentReceiver;
2077f11e921b9be7645b74a33b2ca11c1c4e24fbabGeorge Mountimport android.content.Intent;
2115e593ea3575512d7072240d1db9d74fad8749a3George Mountimport android.os.Binder;
2215e593ea3575512d7072240d1db9d74fad8749a3George Mountimport android.os.Bundle;
2315e593ea3575512d7072240d1db9d74fad8749a3George Mountimport android.os.IBinder;
2415e593ea3575512d7072240d1db9d74fad8749a3George Mountimport android.os.RemoteException;
2515e593ea3575512d7072240d1db9d74fad8749a3George Mountimport android.util.PrintWriterPrinter;
2615e593ea3575512d7072240d1db9d74fad8749a3George Mountimport android.util.Printer;
279277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn
28cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport java.io.PrintWriter;
2936bd1e9880a74cc53edef99040bbb24fc1cad909Adam Powellimport java.util.ArrayList;
300f3dfb28a503b3fb3e51666dd565b0d17eaebfbbAdam Powell
315e63ab9505a3a4d11374cbbec418c1aba921409dChris Banes/**
32cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * A receiver object that has registered for one or more broadcasts.
33cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * The ArrayList holds BroadcastFilter objects.
34cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */
35cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornclass ReceiverList extends ArrayList<BroadcastFilter>
360f3dfb28a503b3fb3e51666dd565b0d17eaebfbbAdam Powell        implements IBinder.DeathRecipient {
37cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    final ActivityManagerService owner;
38cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public final IIntentReceiver receiver;
39267b02ebf455fa4d7de59150548676e406b2dd2bAdam Powell    public final ProcessRecord app;
40990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    public final int pid;
41990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    public final int uid;
42990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    BroadcastRecord curBroadcast = null;
43990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    boolean linkedToDeath = false;
44990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount
459277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn    String stringName;
469277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn
47cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    ReceiverList(ActivityManagerService _owner, ProcessRecord _app,
48990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount            int _pid, int _uid, IIntentReceiver _receiver) {
499277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn        owner = _owner;
50cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        receiver = _receiver;
519277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn        app = _app;
529277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn        pid = _pid;
539277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn        uid = _uid;
54e62545fdf58881a2d0426285648f71ce9323ca15George Mount    }
55cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
56320113721c2e14bbc2403809046fa2959a665c11Aurimas Liutikas    // Want object identity, not the array identity we are inheriting.
57320113721c2e14bbc2403809046fa2959a665c11Aurimas Liutikas    public boolean equals(Object o) {
58320113721c2e14bbc2403809046fa2959a665c11Aurimas Liutikas        return this == o;
59380e247f873d0adf2be42bd9eb41d02322094f11Jake Wharton    }
60320113721c2e14bbc2403809046fa2959a665c11Aurimas Liutikas    public int hashCode() {
61320113721c2e14bbc2403809046fa2959a665c11Aurimas Liutikas        return System.identityHashCode(this);
62320113721c2e14bbc2403809046fa2959a665c11Aurimas Liutikas    }
63320113721c2e14bbc2403809046fa2959a665c11Aurimas Liutikas
64320113721c2e14bbc2403809046fa2959a665c11Aurimas Liutikas    public void binderDied() {
65320113721c2e14bbc2403809046fa2959a665c11Aurimas Liutikas        linkedToDeath = false;
66ba069d50913c3fb250bb60ec310439db36895337Alan Viverette        owner.unregisterReceiver(receiver);
67320113721c2e14bbc2403809046fa2959a665c11Aurimas Liutikas    }
68cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
69cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    void dumpLocal(PrintWriter pw, String prefix) {
70d02828a3781590e76fe86f2bf4ae8fbff4f5e2bdDoris Liu        pw.print(prefix); pw.print("app="); pw.print(app);
71cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            pw.print(" pid="); pw.print(pid); pw.print(" uid="); pw.println(uid);
72cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (curBroadcast != null || linkedToDeath) {
7396221034e4a23a2abb83f772a0281bb197ac5ac0George Mount            pw.print(prefix); pw.print("curBroadcast="); pw.print(curBroadcast);
743a1a7fff9873abbf8097c96f7654a459bf34f223Jeff Brown                pw.print(" linkedToDeath="); pw.println(linkedToDeath);
75267b02ebf455fa4d7de59150548676e406b2dd2bAdam Powell        }
76267b02ebf455fa4d7de59150548676e406b2dd2bAdam Powell    }
77cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
78cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    void dump(PrintWriter pw, String prefix) {
79cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        Printer pr = new PrintWriterPrinter(pw);
80cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        dumpLocal(pw, prefix);
819dcd2e58138ca4eb4b18f80b50e8979329e859d6Scott Main        String p2 = prefix + "  ";
82cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        final int N = size();
839dcd2e58138ca4eb4b18f80b50e8979329e859d6Scott Main        for (int i=0; i<N; i++) {
849dcd2e58138ca4eb4b18f80b50e8979329e859d6Scott Main            BroadcastFilter bf = get(i);
859dcd2e58138ca4eb4b18f80b50e8979329e859d6Scott Main            pw.print(prefix); pw.print("Filter #"); pw.print(i);
869dcd2e58138ca4eb4b18f80b50e8979329e859d6Scott Main                    pw.print(": BroadcastFilter{");
87cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    pw.print(Integer.toHexString(System.identityHashCode(bf)));
88cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    pw.println('}');
89cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            bf.dumpInReceiverList(pw, pr, p2);
90cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
91cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
92cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
93cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public String toString() {
94fd28b81e0501d11989a8ad095c1a54619000df19Aurimas Liutikas        if (stringName != null) {
95cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            return stringName;
96cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
97cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        StringBuilder sb = new StringBuilder(128);
98cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        sb.append("ReceiverList{");
99cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        sb.append(Integer.toHexString(System.identityHashCode(this)));
100cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        sb.append(' ');
101cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        sb.append(pid);
102cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        sb.append(' ');
103cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        sb.append((app != null ? app.processName : "(unknown name)"));
104cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        sb.append('/');
105cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        sb.append(uid);
106cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        sb.append((receiver.asBinder() instanceof Binder) ? " local:" : " remote:");
107cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        sb.append(Integer.toHexString(System.identityHashCode(receiver.asBinder())));
108cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        sb.append('}');
1092a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn        return stringName = sb.toString();
1102a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn    }
1112a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn}
1122a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn