All Downloads are FREE. Search and download functionalities are using the official Maven repository.

src.com.android.server.am.ReceiverList Maven / Gradle / Ivy

/*
 * Copyright (C) 2006 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.server.am;

import android.content.IIntentReceiver;
import android.content.IntentFilter;
import android.os.Binder;
import android.os.IBinder;
import android.util.PrintWriterPrinter;
import android.util.Printer;
import android.util.proto.ProtoOutputStream;

import com.android.server.IntentResolver;

import java.io.PrintWriter;
import java.util.ArrayList;

/**
 * A receiver object that has registered for one or more broadcasts.
 * The ArrayList holds BroadcastFilter objects.
 */
final class ReceiverList extends ArrayList
        implements IBinder.DeathRecipient {
    final ActivityManagerService owner;
    public final IIntentReceiver receiver;
    public final ProcessRecord app;
    public final int pid;
    public final int uid;
    public final int userId;
    BroadcastRecord curBroadcast = null;
    boolean linkedToDeath = false;

    String stringName;

    ReceiverList(ActivityManagerService _owner, ProcessRecord _app,
            int _pid, int _uid, int _userId, IIntentReceiver _receiver) {
        owner = _owner;
        receiver = _receiver;
        app = _app;
        pid = _pid;
        uid = _uid;
        userId = _userId;
    }

    // Want object identity, not the array identity we are inheriting.
    public boolean equals(Object o) {
        return this == o;
    }
    public int hashCode() {
        return System.identityHashCode(this);
    }

    public void binderDied() {
        linkedToDeath = false;
        owner.unregisterReceiver(receiver);
    }

    public boolean containsFilter(IntentFilter filter) {
        final int N = size();
        for (int i = 0; i < N; i++) {
            final BroadcastFilter f = get(i);
            if (IntentResolver.filterEquals(f, filter)) {
                return true;
            }
        }
        return false;
    }

    void writeToProto(ProtoOutputStream proto, long fieldId) {
        long token = proto.start(fieldId);
        app.writeToProto(proto, ReceiverListProto.APP);
        proto.write(ReceiverListProto.PID, pid);
        proto.write(ReceiverListProto.UID, uid);
        proto.write(ReceiverListProto.USER, userId);
        if (curBroadcast != null) {
            curBroadcast.writeToProto(proto, ReceiverListProto.CURRENT);
        }
        proto.write(ReceiverListProto.LINKED_TO_DEATH, linkedToDeath);
        final int N = size();
        for (int i=0; i




© 2015 - 2025 Weber Informatics LLC | Privacy Policy