The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 21 | import android.util.Printer; |
Yi Jin | 129fc6c | 2017-09-28 15:48:38 -0700 | [diff] [blame] | 22 | import android.util.proto.ProtoOutputStream; |
| 23 | |
| 24 | import com.android.server.am.proto.BroadcastFilterProto; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 25 | |
| 26 | import java.io.PrintWriter; |
| 27 | |
Dianne Hackborn | be4e6aa | 2013-06-07 13:25:29 -0700 | [diff] [blame] | 28 | final class BroadcastFilter extends IntentFilter { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 29 | // Back-pointer to the list this filter is in. |
| 30 | final ReceiverList receiverList; |
Dianne Hackborn | 6c418d5 | 2011-06-29 14:05:33 -0700 | [diff] [blame] | 31 | final String packageName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 32 | final String requiredPermission; |
Dianne Hackborn | b4163a6 | 2012-08-02 18:31:26 -0700 | [diff] [blame] | 33 | final int owningUid; |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 34 | final int owningUserId; |
Chad Brubaker | b7e34d5 | 2017-02-22 12:36:06 -0800 | [diff] [blame] | 35 | final boolean instantApp; |
Chad Brubaker | 816c83b | 2017-03-02 10:27:59 -0800 | [diff] [blame] | 36 | final boolean visibleToInstantApp; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 37 | |
| 38 | BroadcastFilter(IntentFilter _filter, ReceiverList _receiverList, |
Chad Brubaker | b7e34d5 | 2017-02-22 12:36:06 -0800 | [diff] [blame] | 39 | String _packageName, String _requiredPermission, int _owningUid, int _userId, |
Chad Brubaker | 816c83b | 2017-03-02 10:27:59 -0800 | [diff] [blame] | 40 | boolean _instantApp, boolean _visibleToInstantApp) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 41 | super(_filter); |
| 42 | receiverList = _receiverList; |
Dianne Hackborn | 6c418d5 | 2011-06-29 14:05:33 -0700 | [diff] [blame] | 43 | packageName = _packageName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 44 | requiredPermission = _requiredPermission; |
Dianne Hackborn | b4163a6 | 2012-08-02 18:31:26 -0700 | [diff] [blame] | 45 | owningUid = _owningUid; |
Dianne Hackborn | 20e8098 | 2012-08-31 19:00:44 -0700 | [diff] [blame] | 46 | owningUserId = _userId; |
Chad Brubaker | b7e34d5 | 2017-02-22 12:36:06 -0800 | [diff] [blame] | 47 | instantApp = _instantApp; |
Chad Brubaker | 816c83b | 2017-03-02 10:27:59 -0800 | [diff] [blame] | 48 | visibleToInstantApp = _visibleToInstantApp; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 49 | } |
Yi Jin | 129fc6c | 2017-09-28 15:48:38 -0700 | [diff] [blame] | 50 | |
| 51 | public void writeToProto(ProtoOutputStream proto, long fieldId) { |
| 52 | long token = proto.start(fieldId); |
| 53 | super.writeToProto(proto, BroadcastFilterProto.INTENT_FILTER); |
| 54 | if (requiredPermission != null) { |
| 55 | proto.write(BroadcastFilterProto.REQUIRED_PERMISSION, requiredPermission); |
| 56 | } |
| 57 | proto.write(BroadcastFilterProto.HEX_HASH, Integer.toHexString(System.identityHashCode(this))); |
| 58 | proto.write(BroadcastFilterProto.OWNING_USER_ID, owningUserId); |
| 59 | proto.end(token); |
| 60 | } |
| 61 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 62 | public void dump(PrintWriter pw, String prefix) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 63 | dumpInReceiverList(pw, new PrintWriterPrinter(pw), prefix); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 64 | receiverList.dumpLocal(pw, prefix); |
| 65 | } |
Yi Jin | 129fc6c | 2017-09-28 15:48:38 -0700 | [diff] [blame] | 66 | |
Dianne Hackborn | 12527f9 | 2009-11-11 17:39:50 -0800 | [diff] [blame] | 67 | public void dumpBrief(PrintWriter pw, String prefix) { |
| 68 | dumpBroadcastFilterState(pw, prefix); |
| 69 | } |
Yi Jin | 129fc6c | 2017-09-28 15:48:38 -0700 | [diff] [blame] | 70 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 71 | public void dumpInReceiverList(PrintWriter pw, Printer pr, String prefix) { |
| 72 | super.dump(pr, prefix); |
Dianne Hackborn | 12527f9 | 2009-11-11 17:39:50 -0800 | [diff] [blame] | 73 | dumpBroadcastFilterState(pw, prefix); |
| 74 | } |
Yi Jin | 129fc6c | 2017-09-28 15:48:38 -0700 | [diff] [blame] | 75 | |
Dianne Hackborn | 12527f9 | 2009-11-11 17:39:50 -0800 | [diff] [blame] | 76 | void dumpBroadcastFilterState(PrintWriter pw, String prefix) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 77 | if (requiredPermission != null) { |
| 78 | pw.print(prefix); pw.print("requiredPermission="); pw.println(requiredPermission); |
| 79 | } |
| 80 | } |
Yi Jin | 129fc6c | 2017-09-28 15:48:38 -0700 | [diff] [blame] | 81 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 82 | public String toString() { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 83 | StringBuilder sb = new StringBuilder(); |
| 84 | sb.append("BroadcastFilter{"); |
| 85 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 86 | sb.append(" u"); |
| 87 | sb.append(owningUserId); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 88 | sb.append(' '); |
| 89 | sb.append(receiverList); |
| 90 | sb.append('}'); |
| 91 | return sb.toString(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 92 | } |
| 93 | } |