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.app.IServiceConnection;
20 import android.app.PendingIntent;
21 import android.content.Context;
22 
23 import java.io.PrintWriter;
24 
25 /**
26  * Description of a single binding to a service.
27  */
28 final class ConnectionRecord {
29     final AppBindRecord binding;    // The application/service binding.
30     final ActivityRecord activity;  // If non-null, the owning activity.
31     final IServiceConnection conn;  // The client connection.
32     final int flags;                // Binding options.
33     final int clientLabel;          // String resource labeling this client.
34     final PendingIntent clientIntent; // How to launch the client.
35     String stringName;              // Caching of toString.
36     boolean serviceDead;            // Well is it?
37 
dump(PrintWriter pw, String prefix)38     void dump(PrintWriter pw, String prefix) {
39         pw.println(prefix + "binding=" + binding);
40         if (activity != null) {
41             pw.println(prefix + "activity=" + activity);
42         }
43         pw.println(prefix + "conn=" + conn.asBinder()
44                 + " flags=0x" + Integer.toHexString(flags));
45     }
46 
ConnectionRecord(AppBindRecord _binding, ActivityRecord _activity, IServiceConnection _conn, int _flags, int _clientLabel, PendingIntent _clientIntent)47     ConnectionRecord(AppBindRecord _binding, ActivityRecord _activity,
48                IServiceConnection _conn, int _flags,
49                int _clientLabel, PendingIntent _clientIntent) {
50         binding = _binding;
51         activity = _activity;
52         conn = _conn;
53         flags = _flags;
54         clientLabel = _clientLabel;
55         clientIntent = _clientIntent;
56     }
57 
toString()58     public String toString() {
59         if (stringName != null) {
60             return stringName;
61         }
62         StringBuilder sb = new StringBuilder(128);
63         sb.append("ConnectionRecord{");
64         sb.append(Integer.toHexString(System.identityHashCode(this)));
65         sb.append(" u");
66         sb.append(binding.client.userId);
67         sb.append(' ');
68         if ((flags&Context.BIND_AUTO_CREATE) != 0) {
69             sb.append("CR ");
70         }
71         if ((flags&Context.BIND_DEBUG_UNBIND) != 0) {
72             sb.append("DBG ");
73         }
74         if ((flags&Context.BIND_NOT_FOREGROUND) != 0) {
75             sb.append("!FG ");
76         }
77         if ((flags&Context.BIND_ABOVE_CLIENT) != 0) {
78             sb.append("ABCLT ");
79         }
80         if ((flags&Context.BIND_ALLOW_OOM_MANAGEMENT) != 0) {
81             sb.append("OOM ");
82         }
83         if ((flags&Context.BIND_WAIVE_PRIORITY) != 0) {
84             sb.append("WPRI ");
85         }
86         if ((flags&Context.BIND_IMPORTANT) != 0) {
87             sb.append("IMP ");
88         }
89         if ((flags&Context.BIND_ADJUST_WITH_ACTIVITY) != 0) {
90             sb.append("WACT ");
91         }
92         if ((flags&Context.BIND_FOREGROUND_SERVICE_WHILE_AWAKE) != 0) {
93             sb.append("FGSA ");
94         }
95         if ((flags&Context.BIND_FOREGROUND_SERVICE) != 0) {
96             sb.append("FGS ");
97         }
98         if ((flags&Context.BIND_TREAT_LIKE_ACTIVITY) != 0) {
99             sb.append("LACT ");
100         }
101         if ((flags&Context.BIND_VISIBLE) != 0) {
102             sb.append("VIS ");
103         }
104         if ((flags&Context.BIND_SHOWING_UI) != 0) {
105             sb.append("UI ");
106         }
107         if ((flags&Context.BIND_NOT_VISIBLE) != 0) {
108             sb.append("!VIS ");
109         }
110         if (serviceDead) {
111             sb.append("DEAD ");
112         }
113         sb.append(binding.service.shortName);
114         sb.append(":@");
115         sb.append(Integer.toHexString(System.identityHashCode(conn.asBinder())));
116         sb.append('}');
117         return stringName = sb.toString();
118     }
119 }
120