• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.IntentFilter;
20 import android.util.PrintWriterPrinter;
21 import android.util.Printer;
22 import android.util.proto.ProtoOutputStream;
23 
24 import java.io.PrintWriter;
25 
26 final class BroadcastFilter extends IntentFilter {
27     // Back-pointer to the list this filter is in.
28     final ReceiverList receiverList;
29     final String packageName;
30     final String featureId;
31     final String receiverId;
32     final String requiredPermission;
33     final int owningUid;
34     final int owningUserId;
35     final boolean instantApp;
36     final boolean visibleToInstantApp;
37     final boolean exported;
38 
BroadcastFilter(IntentFilter _filter, ReceiverList _receiverList, String _packageName, String _featureId, String _receiverId, String _requiredPermission, int _owningUid, int _userId, boolean _instantApp, boolean _visibleToInstantApp, boolean _exported)39     BroadcastFilter(IntentFilter _filter, ReceiverList _receiverList,
40             String _packageName, String _featureId, String _receiverId, String _requiredPermission,
41             int _owningUid, int _userId, boolean _instantApp, boolean _visibleToInstantApp,
42             boolean _exported) {
43         super(_filter);
44         receiverList = _receiverList;
45         packageName = _packageName;
46         featureId = _featureId;
47         receiverId = _receiverId;
48         requiredPermission = _requiredPermission;
49         owningUid = _owningUid;
50         owningUserId = _userId;
51         instantApp = _instantApp;
52         visibleToInstantApp = _visibleToInstantApp;
53         exported = _exported;
54     }
55 
dumpDebug(ProtoOutputStream proto, long fieldId)56     public void dumpDebug(ProtoOutputStream proto, long fieldId) {
57         long token = proto.start(fieldId);
58         super.dumpDebug(proto, BroadcastFilterProto.INTENT_FILTER);
59         if (requiredPermission != null) {
60             proto.write(BroadcastFilterProto.REQUIRED_PERMISSION, requiredPermission);
61         }
62         proto.write(BroadcastFilterProto.HEX_HASH, Integer.toHexString(System.identityHashCode(this)));
63         proto.write(BroadcastFilterProto.OWNING_USER_ID, owningUserId);
64         proto.end(token);
65     }
66 
dump(PrintWriter pw, String prefix)67     public void dump(PrintWriter pw, String prefix) {
68         dumpInReceiverList(pw, new PrintWriterPrinter(pw), prefix);
69         receiverList.dumpLocal(pw, prefix);
70     }
71 
dumpBrief(PrintWriter pw, String prefix)72     public void dumpBrief(PrintWriter pw, String prefix) {
73         dumpBroadcastFilterState(pw, prefix);
74     }
75 
dumpInReceiverList(PrintWriter pw, Printer pr, String prefix)76     public void dumpInReceiverList(PrintWriter pw, Printer pr, String prefix) {
77         super.dump(pr, prefix);
78         dumpBroadcastFilterState(pw, prefix);
79     }
80 
dumpBroadcastFilterState(PrintWriter pw, String prefix)81     void dumpBroadcastFilterState(PrintWriter pw, String prefix) {
82         if (requiredPermission != null) {
83             pw.print(prefix); pw.print("requiredPermission="); pw.println(requiredPermission);
84         }
85     }
86 
toString()87     public String toString() {
88         StringBuilder sb = new StringBuilder();
89         sb.append("BroadcastFilter{");
90         sb.append(Integer.toHexString(System.identityHashCode(this)));
91         sb.append(' ');
92         sb.append(owningUid);
93         sb.append("/u");
94         sb.append(owningUserId);
95         sb.append(' ');
96         sb.append(receiverList);
97         sb.append('}');
98         return sb.toString();
99     }
100 }
101