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