/services/java/com/android/server/am/ReceiverList.java

https://github.com/aizuzi/platform_frameworks_base · Java · 116 lines · 85 code · 11 blank · 20 comment · 9 complexity · 8eb7ed21d5c51a4ce127fdd7bd073fc5 MD5 · raw file

  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. package com.android.server.am;
  17. import android.content.IIntentReceiver;
  18. import android.content.Intent;
  19. import android.os.Binder;
  20. import android.os.Bundle;
  21. import android.os.IBinder;
  22. import android.os.RemoteException;
  23. import android.util.PrintWriterPrinter;
  24. import android.util.Printer;
  25. import java.io.PrintWriter;
  26. import java.util.ArrayList;
  27. /**
  28. * A receiver object that has registered for one or more broadcasts.
  29. * The ArrayList holds BroadcastFilter objects.
  30. */
  31. final class ReceiverList extends ArrayList<BroadcastFilter>
  32. implements IBinder.DeathRecipient {
  33. final ActivityManagerService owner;
  34. public final IIntentReceiver receiver;
  35. public final ProcessRecord app;
  36. public final int pid;
  37. public final int uid;
  38. public final int userId;
  39. BroadcastRecord curBroadcast = null;
  40. boolean linkedToDeath = false;
  41. String stringName;
  42. ReceiverList(ActivityManagerService _owner, ProcessRecord _app,
  43. int _pid, int _uid, int _userId, IIntentReceiver _receiver) {
  44. owner = _owner;
  45. receiver = _receiver;
  46. app = _app;
  47. pid = _pid;
  48. uid = _uid;
  49. userId = _userId;
  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. public void binderDied() {
  59. linkedToDeath = false;
  60. owner.unregisterReceiver(receiver);
  61. }
  62. void dumpLocal(PrintWriter pw, String prefix) {
  63. pw.print(prefix); pw.print("app="); pw.print(app != null ? app.toShortString() : null);
  64. pw.print(" pid="); pw.print(pid); pw.print(" uid="); pw.print(uid);
  65. pw.print(" user="); pw.println(userId);
  66. if (curBroadcast != null || linkedToDeath) {
  67. pw.print(prefix); pw.print("curBroadcast="); pw.print(curBroadcast);
  68. pw.print(" linkedToDeath="); pw.println(linkedToDeath);
  69. }
  70. }
  71. void dump(PrintWriter pw, String prefix) {
  72. Printer pr = new PrintWriterPrinter(pw);
  73. dumpLocal(pw, prefix);
  74. String p2 = prefix + " ";
  75. final int N = size();
  76. for (int i=0; i<N; i++) {
  77. BroadcastFilter bf = get(i);
  78. pw.print(prefix); pw.print("Filter #"); pw.print(i);
  79. pw.print(": BroadcastFilter{");
  80. pw.print(Integer.toHexString(System.identityHashCode(bf)));
  81. pw.println('}');
  82. bf.dumpInReceiverList(pw, pr, p2);
  83. }
  84. }
  85. public String toString() {
  86. if (stringName != null) {
  87. return stringName;
  88. }
  89. StringBuilder sb = new StringBuilder(128);
  90. sb.append("ReceiverList{");
  91. sb.append(Integer.toHexString(System.identityHashCode(this)));
  92. sb.append(' ');
  93. sb.append(pid);
  94. sb.append(' ');
  95. sb.append((app != null ? app.processName : "(unknown name)"));
  96. sb.append('/');
  97. sb.append(uid);
  98. sb.append("/u");
  99. sb.append(userId);
  100. sb.append((receiver.asBinder() instanceof Binder) ? " local:" : " remote:");
  101. sb.append(Integer.toHexString(System.identityHashCode(receiver.asBinder())));
  102. sb.append('}');
  103. return stringName = sb.toString();
  104. }
  105. }