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
17package com.android.server.am;
18
19import android.app.IServiceConnection;
20import android.app.PendingIntent;
21import android.content.Context;
22
23import java.io.PrintWriter;
24
25/**
26 * Description of a single binding to a service.
27 */
28final 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
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
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
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_IMPORTANT_BACKGROUND) != 0) {
78            sb.append("IMPB ");
79        }
80        if ((flags&Context.BIND_ABOVE_CLIENT) != 0) {
81            sb.append("ABCLT ");
82        }
83        if ((flags&Context.BIND_ALLOW_OOM_MANAGEMENT) != 0) {
84            sb.append("OOM ");
85        }
86        if ((flags&Context.BIND_WAIVE_PRIORITY) != 0) {
87            sb.append("WPRI ");
88        }
89        if ((flags&Context.BIND_IMPORTANT) != 0) {
90            sb.append("IMP ");
91        }
92        if ((flags&Context.BIND_ADJUST_WITH_ACTIVITY) != 0) {
93            sb.append("WACT ");
94        }
95        if ((flags&Context.BIND_FOREGROUND_SERVICE_WHILE_AWAKE) != 0) {
96            sb.append("FGSA ");
97        }
98        if ((flags&Context.BIND_FOREGROUND_SERVICE) != 0) {
99            sb.append("FGS ");
100        }
101        if ((flags&Context.BIND_TREAT_LIKE_ACTIVITY) != 0) {
102            sb.append("LACT ");
103        }
104        if ((flags&Context.BIND_VISIBLE) != 0) {
105            sb.append("VIS ");
106        }
107        if ((flags&Context.BIND_SHOWING_UI) != 0) {
108            sb.append("UI ");
109        }
110        if ((flags&Context.BIND_NOT_VISIBLE) != 0) {
111            sb.append("!VIS ");
112        }
113        if (serviceDead) {
114            sb.append("DEAD ");
115        }
116        sb.append(binding.service.shortName);
117        sb.append(":@");
118        sb.append(Integer.toHexString(System.identityHashCode(conn.asBinder())));
119        sb.append('}');
120        return stringName = sb.toString();
121    }
122}
123