The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | |
| 17 | package com.android.server.am; |
| 18 | |
Suchi Amalapurapu | 1ccac75 | 2009-06-12 10:09:58 -0700 | [diff] [blame] | 19 | import android.content.IIntentReceiver; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 20 | import android.content.Intent; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 21 | import android.os.Binder; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 22 | import android.os.Bundle; |
| 23 | import android.os.IBinder; |
| 24 | import android.os.RemoteException; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 25 | import android.util.PrintWriterPrinter; |
| 26 | import android.util.Printer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 27 | |
| 28 | import java.io.PrintWriter; |
| 29 | import java.util.ArrayList; |
| 30 | |
| 31 | /** |
| 32 | * A receiver object that has registered for one or more broadcasts. |
| 33 | * The ArrayList holds BroadcastFilter objects. |
| 34 | */ |
| 35 | class 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 Hackborn | 20e8098 | 2012-08-31 19:00:44 -0700 | [diff] [blame] | 42 | public final int userId; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 43 | BroadcastRecord curBroadcast = null; |
| 44 | boolean linkedToDeath = false; |
| 45 | |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 46 | String stringName; |
| 47 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 48 | ReceiverList(ActivityManagerService _owner, ProcessRecord _app, |
Dianne Hackborn | 20e8098 | 2012-08-31 19:00:44 -0700 | [diff] [blame] | 49 | int _pid, int _uid, int _userId, IIntentReceiver _receiver) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 50 | owner = _owner; |
| 51 | receiver = _receiver; |
| 52 | app = _app; |
| 53 | pid = _pid; |
| 54 | uid = _uid; |
Dianne Hackborn | 20e8098 | 2012-08-31 19:00:44 -0700 | [diff] [blame] | 55 | userId = _userId; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 56 | } |
| 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 Hackborn | 20e8098 | 2012-08-31 19:00:44 -0700 | [diff] [blame] | 72 | 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 Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 75 | 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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | void dump(PrintWriter pw, String prefix) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 82 | Printer pr = new PrintWriterPrinter(pw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 83 | 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 Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 88 | 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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 93 | } |
| 94 | } |
| 95 | |
| 96 | public String toString() { |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 97 | 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 Hackborn | 20e8098 | 2012-08-31 19:00:44 -0700 | [diff] [blame] | 109 | sb.append("/u"); |
| 110 | sb.append(userId); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 111 | sb.append((receiver.asBinder() instanceof Binder) ? " local:" : " remote:"); |
Dianne Hackborn | f210d6b | 2009-04-13 18:42:49 -0700 | [diff] [blame] | 112 | sb.append(Integer.toHexString(System.identityHashCode(receiver.asBinder()))); |
| 113 | sb.append('}'); |
| 114 | return stringName = sb.toString(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 115 | } |
| 116 | } |