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 requiredPermission; 31 final int owningUid; 32 final int owningUserId; 33 final boolean instantApp; 34 final boolean visibleToInstantApp; 35 BroadcastFilter(IntentFilter _filter, ReceiverList _receiverList, String _packageName, String _requiredPermission, int _owningUid, int _userId, boolean _instantApp, boolean _visibleToInstantApp)36 BroadcastFilter(IntentFilter _filter, ReceiverList _receiverList, 37 String _packageName, String _requiredPermission, int _owningUid, int _userId, 38 boolean _instantApp, boolean _visibleToInstantApp) { 39 super(_filter); 40 receiverList = _receiverList; 41 packageName = _packageName; 42 requiredPermission = _requiredPermission; 43 owningUid = _owningUid; 44 owningUserId = _userId; 45 instantApp = _instantApp; 46 visibleToInstantApp = _visibleToInstantApp; 47 } 48 writeToProto(ProtoOutputStream proto, long fieldId)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 dump(PrintWriter pw, String prefix)60 public void dump(PrintWriter pw, String prefix) { 61 dumpInReceiverList(pw, new PrintWriterPrinter(pw), prefix); 62 receiverList.dumpLocal(pw, prefix); 63 } 64 dumpBrief(PrintWriter pw, String prefix)65 public void dumpBrief(PrintWriter pw, String prefix) { 66 dumpBroadcastFilterState(pw, prefix); 67 } 68 dumpInReceiverList(PrintWriter pw, Printer pr, String prefix)69 public void dumpInReceiverList(PrintWriter pw, Printer pr, String prefix) { 70 super.dump(pr, prefix); 71 dumpBroadcastFilterState(pw, prefix); 72 } 73 dumpBroadcastFilterState(PrintWriter pw, String prefix)74 void dumpBroadcastFilterState(PrintWriter pw, String prefix) { 75 if (requiredPermission != null) { 76 pw.print(prefix); pw.print("requiredPermission="); pw.println(requiredPermission); 77 } 78 } 79 toString()80 public String toString() { 81 StringBuilder sb = new StringBuilder(); 82 sb.append("BroadcastFilter{"); 83 sb.append(Integer.toHexString(System.identityHashCode(this))); 84 sb.append(' '); 85 sb.append(owningUid); 86 sb.append("/u"); 87 sb.append(owningUserId); 88 sb.append(' '); 89 sb.append(receiverList); 90 sb.append('}'); 91 return sb.toString(); 92 } 93 } 94