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 19 import android.util.ArraySet; 20 import android.util.proto.ProtoOutputStream; 21 22 import java.io.PrintWriter; 23 24 /** 25 * An association between a service and one of its client applications. 26 */ 27 final class AppBindRecord { 28 final ServiceRecord service; // The running service. 29 final IntentBindRecord intent; // The intent we are bound to. 30 final ProcessRecord client; // Who has started/bound the service. 31 final ProcessRecord attributedClient; // The binding was done by the system on behalf 32 // of 'attributedClient' 33 final ArraySet<ConnectionRecord> connections = new ArraySet<>(); 34 // All ConnectionRecord for this client. 35 dump(PrintWriter pw, String prefix)36 void dump(PrintWriter pw, String prefix) { 37 pw.println(prefix + "service=" + service); 38 pw.println(prefix + "client=" + client); 39 pw.println(prefix + "attributedClient=" + attributedClient); 40 dumpInIntentBind(pw, prefix); 41 } 42 dumpInIntentBind(PrintWriter pw, String prefix)43 void dumpInIntentBind(PrintWriter pw, String prefix) { 44 final int N = connections.size(); 45 if (N > 0) { 46 pw.println(prefix + "Per-process Connections:"); 47 for (int i=0; i<N; i++) { 48 ConnectionRecord c = connections.valueAt(i); 49 pw.println(prefix + " " + c); 50 } 51 } 52 } 53 AppBindRecord(ServiceRecord _service, IntentBindRecord _intent, ProcessRecord _client, ProcessRecord _attributedClient)54 AppBindRecord(ServiceRecord _service, IntentBindRecord _intent, 55 ProcessRecord _client, ProcessRecord _attributedClient) { 56 service = _service; 57 intent = _intent; 58 client = _client; 59 attributedClient = _attributedClient; 60 } 61 toString()62 public String toString() { 63 return "AppBindRecord{" 64 + Integer.toHexString(System.identityHashCode(this)) 65 + " " + service.shortInstanceName + ":" + client.processName + "}"; 66 } 67 dumpDebug(ProtoOutputStream proto, long fieldId)68 void dumpDebug(ProtoOutputStream proto, long fieldId) { 69 long token = proto.start(fieldId); 70 proto.write(AppBindRecordProto.SERVICE_NAME, service.shortInstanceName); 71 proto.write(AppBindRecordProto.CLIENT_PROC_NAME, client.processName); 72 final int N = connections.size(); 73 for (int i=0; i<N; i++) { 74 ConnectionRecord conn = connections.valueAt(i); 75 proto.write(AppBindRecordProto.CONNECTIONS, 76 Integer.toHexString(System.identityHashCode(conn))); 77 } 78 proto.end(token); 79 } 80 } 81