• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package org.robolectric.manifest;
2 
3 import java.util.ArrayList;
4 import java.util.HashMap;
5 import java.util.List;
6 import java.util.Map;
7 
8 public class BroadcastReceiverData extends PackageItemData {
9 
10   private static final String EXPORTED = "android:exported";
11   private static final String NAME = "android:name";
12   private static final String PERMISSION = "android:permission";
13 
14   private final Map<String, String> attributes;
15   private final List<String> actions;
16   private List<IntentFilterData> intentFilters;
17 
BroadcastReceiverData( Map<String, String> attributes, MetaData metaData, List<IntentFilterData> intentFilters)18   public BroadcastReceiverData(
19       Map<String, String> attributes, MetaData metaData, List<IntentFilterData> intentFilters) {
20     super(attributes.get(NAME), metaData);
21     this.attributes = attributes;
22     this.actions = new ArrayList<>();
23     this.intentFilters = new ArrayList<>(intentFilters);
24   }
25 
BroadcastReceiverData(String className, MetaData metaData)26   public BroadcastReceiverData(String className, MetaData metaData) {
27     super(className, metaData);
28     this.actions = new ArrayList<>();
29     this.attributes = new HashMap<>();
30     intentFilters = new ArrayList<>();
31   }
32 
getActions()33   public List<String> getActions() {
34     return actions;
35   }
36 
addAction(String action)37   public void addAction(String action) {
38     this.actions.add(action);
39   }
40 
setPermission(final String permission)41   public void setPermission(final String permission) {
42     attributes.put(PERMISSION, permission);
43   }
44 
getPermission()45   public String getPermission() {
46     return attributes.get(PERMISSION);
47   }
48 
49   /**
50    * Get the intent filters defined for the broadcast receiver.
51    *
52    * @return A list of intent filters.
53    */
getIntentFilters()54   public List<IntentFilterData> getIntentFilters() {
55     return intentFilters;
56   }
57 
58   /**
59    * Get the map for all attributes defined for the broadcast receiver.
60    *
61    * @return map of attributes names to values from the manifest.
62    */
getAllAttributes()63   public Map<String, String> getAllAttributes() {
64     return attributes;
65   }
66 
67   /**
68    * Returns whether this broadcast receiver is exported by checking the XML attribute.
69    *
70    * @return true if the broadcast receiver is exported
71    */
isExported()72   public boolean isExported() {
73     boolean defaultValue = !intentFilters.isEmpty();
74     return (attributes.containsKey(EXPORTED)
75         ? Boolean.parseBoolean(attributes.get(EXPORTED))
76         : defaultValue);
77   }
78 }
79