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