blob: 8e2ca0691277a5ca3a23e4930a465549c79cb350 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
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.content.IntentFilter;
20import android.util.PrintWriterPrinter;
Dianne Hackborn1d442e02009-04-20 18:14:05 -070021import android.util.Printer;
Yi Jin129fc6c2017-09-28 15:48:38 -070022import android.util.proto.ProtoOutputStream;
23
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080024import java.io.PrintWriter;
25
Dianne Hackbornbe4e6aa2013-06-07 13:25:29 -070026final class BroadcastFilter extends IntentFilter {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080027 // Back-pointer to the list this filter is in.
28 final ReceiverList receiverList;
Dianne Hackborn6c418d52011-06-29 14:05:33 -070029 final String packageName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080030 final String requiredPermission;
Dianne Hackbornb4163a62012-08-02 18:31:26 -070031 final int owningUid;
Dianne Hackborn5ac72a22012-08-29 18:32:08 -070032 final int owningUserId;
Chad Brubakerb7e34d52017-02-22 12:36:06 -080033 final boolean instantApp;
Chad Brubaker816c83b2017-03-02 10:27:59 -080034 final boolean visibleToInstantApp;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080035
36 BroadcastFilter(IntentFilter _filter, ReceiverList _receiverList,
Chad Brubakerb7e34d52017-02-22 12:36:06 -080037 String _packageName, String _requiredPermission, int _owningUid, int _userId,
Chad Brubaker816c83b2017-03-02 10:27:59 -080038 boolean _instantApp, boolean _visibleToInstantApp) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080039 super(_filter);
40 receiverList = _receiverList;
Dianne Hackborn6c418d52011-06-29 14:05:33 -070041 packageName = _packageName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080042 requiredPermission = _requiredPermission;
Dianne Hackbornb4163a62012-08-02 18:31:26 -070043 owningUid = _owningUid;
Dianne Hackborn20e80982012-08-31 19:00:44 -070044 owningUserId = _userId;
Chad Brubakerb7e34d52017-02-22 12:36:06 -080045 instantApp = _instantApp;
Chad Brubaker816c83b2017-03-02 10:27:59 -080046 visibleToInstantApp = _visibleToInstantApp;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080047 }
Yi Jin129fc6c2017-09-28 15:48:38 -070048
49 public void writeToProto(ProtoOutputStream proto, long fieldId) {
50 long token = proto.start(fieldId);
51 super.writeToProto(proto, BroadcastFilterProto.INTENT_FILTER);
52 if (requiredPermission != null) {
53 proto.write(BroadcastFilterProto.REQUIRED_PERMISSION, requiredPermission);
54 }
55 proto.write(BroadcastFilterProto.HEX_HASH, Integer.toHexString(System.identityHashCode(this)));
56 proto.write(BroadcastFilterProto.OWNING_USER_ID, owningUserId);
57 proto.end(token);
58 }
59
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080060 public void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070061 dumpInReceiverList(pw, new PrintWriterPrinter(pw), prefix);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080062 receiverList.dumpLocal(pw, prefix);
63 }
Yi Jin129fc6c2017-09-28 15:48:38 -070064
Dianne Hackborn12527f92009-11-11 17:39:50 -080065 public void dumpBrief(PrintWriter pw, String prefix) {
66 dumpBroadcastFilterState(pw, prefix);
67 }
Yi Jin129fc6c2017-09-28 15:48:38 -070068
Dianne Hackborn1d442e02009-04-20 18:14:05 -070069 public void dumpInReceiverList(PrintWriter pw, Printer pr, String prefix) {
70 super.dump(pr, prefix);
Dianne Hackborn12527f92009-11-11 17:39:50 -080071 dumpBroadcastFilterState(pw, prefix);
72 }
Yi Jin129fc6c2017-09-28 15:48:38 -070073
Dianne Hackborn12527f92009-11-11 17:39:50 -080074 void dumpBroadcastFilterState(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070075 if (requiredPermission != null) {
76 pw.print(prefix); pw.print("requiredPermission="); pw.println(requiredPermission);
77 }
78 }
Yi Jin129fc6c2017-09-28 15:48:38 -070079
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080080 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070081 StringBuilder sb = new StringBuilder();
82 sb.append("BroadcastFilter{");
83 sb.append(Integer.toHexString(System.identityHashCode(this)));
Dianne Hackbornb12e1352012-09-26 11:39:20 -070084 sb.append(" u");
85 sb.append(owningUserId);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070086 sb.append(' ');
87 sb.append(receiverList);
88 sb.append('}');
89 return sb.toString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080090 }
91}