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

https://github.com/aizuzi/platform_frameworks_base · Java · 112 lines · 76 code · 10 blank · 26 comment · 10 complexity · dc2984f81548a0d68354f4a5c37f2268 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.Context;
  18. import android.content.Intent;
  19. import android.os.IBinder;
  20. import android.util.ArrayMap;
  21. import java.io.PrintWriter;
  22. import java.util.HashMap;
  23. import java.util.Iterator;
  24. /**
  25. * A particular Intent that has been bound to a Service.
  26. */
  27. final class IntentBindRecord {
  28. /** The running service. */
  29. final ServiceRecord service;
  30. /** The intent that is bound.*/
  31. final Intent.FilterComparison intent; //
  32. /** All apps that have bound to this Intent. */
  33. final ArrayMap<ProcessRecord, AppBindRecord> apps
  34. = new ArrayMap<ProcessRecord, AppBindRecord>();
  35. /** Binder published from service. */
  36. IBinder binder;
  37. /** Set when we have initiated a request for this binder. */
  38. boolean requested;
  39. /** Set when we have received the requested binder. */
  40. boolean received;
  41. /** Set when we still need to tell the service all clients are unbound. */
  42. boolean hasBound;
  43. /** Set when the service's onUnbind() has asked to be told about new clients. */
  44. boolean doRebind;
  45. String stringName; // caching of toString
  46. void dump(PrintWriter pw, String prefix) {
  47. pw.print(prefix); pw.print("service="); pw.println(service);
  48. dumpInService(pw, prefix);
  49. }
  50. void dumpInService(PrintWriter pw, String prefix) {
  51. pw.print(prefix); pw.print("intent={");
  52. pw.print(intent.getIntent().toShortString(false, true, false, false));
  53. pw.println('}');
  54. pw.print(prefix); pw.print("binder="); pw.println(binder);
  55. pw.print(prefix); pw.print("requested="); pw.print(requested);
  56. pw.print(" received="); pw.print(received);
  57. pw.print(" hasBound="); pw.print(hasBound);
  58. pw.print(" doRebind="); pw.println(doRebind);
  59. for (int i=0; i<apps.size(); i++) {
  60. AppBindRecord a = apps.valueAt(i);
  61. pw.print(prefix); pw.print("* Client AppBindRecord{");
  62. pw.print(Integer.toHexString(System.identityHashCode(a)));
  63. pw.print(' '); pw.print(a.client); pw.println('}');
  64. a.dumpInIntentBind(pw, prefix + " ");
  65. }
  66. }
  67. IntentBindRecord(ServiceRecord _service, Intent.FilterComparison _intent) {
  68. service = _service;
  69. intent = _intent;
  70. }
  71. int collectFlags() {
  72. int flags = 0;
  73. for (int i=apps.size()-1; i>=0; i--) {
  74. AppBindRecord app = apps.valueAt(i);
  75. if (app.connections.size() > 0) {
  76. for (ConnectionRecord conn : app.connections) {
  77. flags |= conn.flags;
  78. }
  79. }
  80. }
  81. return flags;
  82. }
  83. public String toString() {
  84. if (stringName != null) {
  85. return stringName;
  86. }
  87. StringBuilder sb = new StringBuilder(128);
  88. sb.append("IntentBindRecord{");
  89. sb.append(Integer.toHexString(System.identityHashCode(this)));
  90. sb.append(' ');
  91. if ((collectFlags()&Context.BIND_AUTO_CREATE) != 0) {
  92. sb.append("CR ");
  93. }
  94. sb.append(service.shortName);
  95. sb.append(':');
  96. if (intent != null) {
  97. intent.getIntent().toShortString(sb, false, false, false, false);
  98. }
  99. sb.append('}');
  100. return stringName = sb.toString();
  101. }
  102. }