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.IIntentReceiver;
     20 import android.content.Intent;
     21 import android.os.Binder;
     22 import android.os.Bundle;
     23 import android.os.IBinder;
     24 import android.os.RemoteException;
     25 import android.util.PrintWriterPrinter;
     26 import android.util.Printer;
     27 
     28 import java.io.PrintWriter;
     29 import java.util.ArrayList;
     30 
     31 /**
     32  * A receiver object that has registered for one or more broadcasts.
     33  * The ArrayList holds BroadcastFilter objects.
     34  */
     35 final class ReceiverList extends ArrayList<BroadcastFilter>
     36         implements IBinder.DeathRecipient {
     37     final ActivityManagerService owner;
     38     public final IIntentReceiver receiver;
     39     public final ProcessRecord app;
     40     public final int pid;
     41     public final int uid;
     42     public final int userId;
     43     BroadcastRecord curBroadcast = null;
     44     boolean linkedToDeath = false;
     45 
     46     String stringName;
     47 
     48     ReceiverList(ActivityManagerService _owner, ProcessRecord _app,
     49             int _pid, int _uid, int _userId, IIntentReceiver _receiver) {
     50         owner = _owner;
     51         receiver = _receiver;
     52         app = _app;
     53         pid = _pid;
     54         uid = _uid;
     55         userId = _userId;
     56     }
     57 
     58     // Want object identity, not the array identity we are inheriting.
     59     public boolean equals(Object o) {
     60         return this == o;
     61     }
     62     public int hashCode() {
     63         return System.identityHashCode(this);
     64     }
     65 
     66     public void binderDied() {
     67         linkedToDeath = false;
     68         owner.unregisterReceiver(receiver);
     69     }
     70 
     71     void dumpLocal(PrintWriter pw, String prefix) {
     72         pw.print(prefix); pw.print("app="); pw.print(app != null ? app.toShortString() : null);
     73             pw.print(" pid="); pw.print(pid); pw.print(" uid="); pw.print(uid);
     74             pw.print(" user="); pw.println(userId);
     75         if (curBroadcast != null || linkedToDeath) {
     76             pw.print(prefix); pw.print("curBroadcast="); pw.print(curBroadcast);
     77                 pw.print(" linkedToDeath="); pw.println(linkedToDeath);
     78         }
     79     }
     80 
     81     void dump(PrintWriter pw, String prefix) {
     82         Printer pr = new PrintWriterPrinter(pw);
     83         dumpLocal(pw, prefix);
     84         String p2 = prefix + "  ";
     85         final int N = size();
     86         for (int i=0; i<N; i++) {
     87             BroadcastFilter bf = get(i);
     88             pw.print(prefix); pw.print("Filter #"); pw.print(i);
     89                     pw.print(": BroadcastFilter{");
     90                     pw.print(Integer.toHexString(System.identityHashCode(bf)));
     91                     pw.println('}');
     92             bf.dumpInReceiverList(pw, pr, p2);
     93         }
     94     }
     95 
     96     public String toString() {
     97         if (stringName != null) {
     98             return stringName;
     99         }
    100         StringBuilder sb = new StringBuilder(128);
    101         sb.append("ReceiverList{");
    102         sb.append(Integer.toHexString(System.identityHashCode(this)));
    103         sb.append(' ');
    104         sb.append(pid);
    105         sb.append(' ');
    106         sb.append((app != null ? app.processName : "(unknown name)"));
    107         sb.append('/');
    108         sb.append(uid);
    109         sb.append("/u");
    110         sb.append(userId);
    111         sb.append((receiver.asBinder() instanceof Binder) ? " local:" : " remote:");
    112         sb.append(Integer.toHexString(System.identityHashCode(receiver.asBinder())));
    113         sb.append('}');
    114         return stringName = sb.toString();
    115     }
    116 }
    117