Home | History | Annotate | Download | only in manifest
      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 
     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 
     28   public List<String> getActions() {
     29     return actions;
     30   }
     31 
     32   public void addAction(String action) {
     33     this.actions.add(action);
     34   }
     35 
     36   public void setPermission(final String permission) {
     37     attributes.put(PERMISSION, permission);
     38   }
     39 
     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    */
     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    */
     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    */
     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