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 | |
Dianne Hackborn | 0c38049 | 2012-08-20 17:23:30 -0700 | [diff] [blame] | 19 | import android.content.Context; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 20 | import android.content.Intent; |
| 21 | import android.os.IBinder; |
Dianne Hackborn | c823051 | 2013-07-13 21:32:12 -0700 | [diff] [blame] | 22 | import android.util.ArrayMap; |
Dianne Hackborn | 24c98e8 | 2014-09-14 17:23:54 -0700 | [diff] [blame^] | 23 | import android.util.ArraySet; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 24 | |
| 25 | import java.io.PrintWriter; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 26 | |
| 27 | /** |
| 28 | * A particular Intent that has been bound to a Service. |
| 29 | */ |
Dianne Hackborn | be4e6aa | 2013-06-07 13:25:29 -0700 | [diff] [blame] | 30 | final class IntentBindRecord { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 31 | /** The running service. */ |
| 32 | final ServiceRecord service; |
| 33 | /** The intent that is bound.*/ |
| 34 | final Intent.FilterComparison intent; // |
| 35 | /** All apps that have bound to this Intent. */ |
Dianne Hackborn | c823051 | 2013-07-13 21:32:12 -0700 | [diff] [blame] | 36 | final ArrayMap<ProcessRecord, AppBindRecord> apps |
| 37 | = new ArrayMap<ProcessRecord, AppBindRecord>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 38 | /** Binder published from service. */ |
| 39 | IBinder binder; |
| 40 | /** Set when we have initiated a request for this binder. */ |
| 41 | boolean requested; |
| 42 | /** Set when we have received the requested binder. */ |
| 43 | boolean received; |
| 44 | /** Set when we still need to tell the service all clients are unbound. */ |
| 45 | boolean hasBound; |
| 46 | /** Set when the service's onUnbind() has asked to be told about new clients. */ |
| 47 | boolean doRebind; |
| 48 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 49 | String stringName; // caching of toString |
| 50 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 51 | void dump(PrintWriter pw, String prefix) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 52 | pw.print(prefix); pw.print("service="); pw.println(service); |
| 53 | dumpInService(pw, prefix); |
| 54 | } |
| 55 | |
| 56 | void dumpInService(PrintWriter pw, String prefix) { |
| 57 | pw.print(prefix); pw.print("intent={"); |
Dianne Hackborn | 21c241e | 2012-03-08 13:57:23 -0800 | [diff] [blame] | 58 | pw.print(intent.getIntent().toShortString(false, true, false, false)); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 59 | pw.println('}'); |
| 60 | pw.print(prefix); pw.print("binder="); pw.println(binder); |
| 61 | pw.print(prefix); pw.print("requested="); pw.print(requested); |
| 62 | pw.print(" received="); pw.print(received); |
| 63 | pw.print(" hasBound="); pw.print(hasBound); |
| 64 | pw.print(" doRebind="); pw.println(doRebind); |
Dianne Hackborn | c823051 | 2013-07-13 21:32:12 -0700 | [diff] [blame] | 65 | for (int i=0; i<apps.size(); i++) { |
| 66 | AppBindRecord a = apps.valueAt(i); |
| 67 | pw.print(prefix); pw.print("* Client AppBindRecord{"); |
| 68 | pw.print(Integer.toHexString(System.identityHashCode(a))); |
| 69 | pw.print(' '); pw.print(a.client); pw.println('}'); |
| 70 | a.dumpInIntentBind(pw, prefix + " "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 71 | } |
| 72 | } |
| 73 | |
| 74 | IntentBindRecord(ServiceRecord _service, Intent.FilterComparison _intent) { |
| 75 | service = _service; |
| 76 | intent = _intent; |
| 77 | } |
| 78 | |
Dianne Hackborn | 0c38049 | 2012-08-20 17:23:30 -0700 | [diff] [blame] | 79 | int collectFlags() { |
| 80 | int flags = 0; |
Dianne Hackborn | c823051 | 2013-07-13 21:32:12 -0700 | [diff] [blame] | 81 | for (int i=apps.size()-1; i>=0; i--) { |
Dianne Hackborn | 24c98e8 | 2014-09-14 17:23:54 -0700 | [diff] [blame^] | 82 | final ArraySet<ConnectionRecord> connections = apps.valueAt(i).connections; |
| 83 | for (int j=connections.size()-1; j>=0; j--) { |
| 84 | flags |= connections.valueAt(j).flags; |
Dianne Hackborn | 0c38049 | 2012-08-20 17:23:30 -0700 | [diff] [blame] | 85 | } |
| 86 | } |
| 87 | return flags; |
| 88 | } |
| 89 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 90 | public String toString() { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 91 | if (stringName != null) { |
| 92 | return stringName; |
| 93 | } |
| 94 | StringBuilder sb = new StringBuilder(128); |
| 95 | sb.append("IntentBindRecord{"); |
| 96 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 97 | sb.append(' '); |
Dianne Hackborn | 0c38049 | 2012-08-20 17:23:30 -0700 | [diff] [blame] | 98 | if ((collectFlags()&Context.BIND_AUTO_CREATE) != 0) { |
| 99 | sb.append("CR "); |
| 100 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 101 | sb.append(service.shortName); |
| 102 | sb.append(':'); |
| 103 | if (intent != null) { |
Dianne Hackborn | 21c241e | 2012-03-08 13:57:23 -0800 | [diff] [blame] | 104 | intent.getIntent().toShortString(sb, false, false, false, false); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 105 | } |
| 106 | sb.append('}'); |
| 107 | return stringName = sb.toString(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 108 | } |
| 109 | } |