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 BroadcastFilter(IntentFilter _filter, ReceiverList _receiverList, String _packageName, String _featureId, String _receiverId, String _requiredPermission, int _owningUid, int _userId, boolean _instantApp, boolean _visibleToInstantApp)38 BroadcastFilter(IntentFilter _filter, ReceiverList _receiverList, 39 String _packageName, String _featureId, String _receiverId, String _requiredPermission, 40 int _owningUid, int _userId, boolean _instantApp, boolean _visibleToInstantApp) { 41 super(_filter); 42 receiverList = _receiverList; 43 packageName = _packageName; 44 featureId = _featureId; 45 receiverId = _receiverId; 46 requiredPermission = _requiredPermission; 47 owningUid = _owningUid; 48 owningUserId = _userId; 49 instantApp = _instantApp; 50 visibleToInstantApp = _visibleToInstantApp; 51 } 52 dumpDebug(ProtoOutputStream proto, long fieldId)53 public void dumpDebug(ProtoOutputStream proto, long fieldId) { 54 long token = proto.start(fieldId); 55 super.dumpDebug(proto, BroadcastFilterProto.INTENT_FILTER); 56 if (requiredPermission != null) { 57 proto.write(BroadcastFilterProto.REQUIRED_PERMISSION, requiredPermission); 58 } 59 proto.write(BroadcastFilterProto.HEX_HASH, Integer.toHexString(System.identityHashCode(this))); 60 proto.write(BroadcastFilterProto.OWNING_USER_ID, owningUserId); 61 proto.end(token); 62 } 63 dump(PrintWriter pw, String prefix)64 public void dump(PrintWriter pw, String prefix) { 65 dumpInReceiverList(pw, new PrintWriterPrinter(pw), prefix); 66 receiverList.dumpLocal(pw, prefix); 67 } 68 dumpBrief(PrintWriter pw, String prefix)69 public void dumpBrief(PrintWriter pw, String prefix) { 70 dumpBroadcastFilterState(pw, prefix); 71 } 72 dumpInReceiverList(PrintWriter pw, Printer pr, String prefix)73 public void dumpInReceiverList(PrintWriter pw, Printer pr, String prefix) { 74 super.dump(pr, prefix); 75 dumpBroadcastFilterState(pw, prefix); 76 } 77 dumpBroadcastFilterState(PrintWriter pw, String prefix)78 void dumpBroadcastFilterState(PrintWriter pw, String prefix) { 79 if (requiredPermission != null) { 80 pw.print(prefix); pw.print("requiredPermission="); pw.println(requiredPermission); 81 } 82 } 83 toString()84 public String toString() { 85 StringBuilder sb = new StringBuilder(); 86 sb.append("BroadcastFilter{"); 87 sb.append(Integer.toHexString(System.identityHashCode(this))); 88 sb.append(' '); 89 sb.append(owningUid); 90 sb.append("/u"); 91 sb.append(owningUserId); 92 sb.append(' '); 93 sb.append(receiverList); 94 sb.append('}'); 95 return sb.toString(); 96 } 97 } 98