Class: Android::Manifest::IntentFilter

Inherits:
Object
  • Object
show all
Defined in:
lib/android/manifest.rb

Overview

intent-filter element in components

Direct Known Subclasses

Queries::Intent

Defined Under Namespace

Classes: Action, Category, Data

Constant Summary collapse

TYPES =

filter types (action is required, category and data are optional)

['action', 'category', 'data']
CATEGORY_BROWSABLE =

browsable of category

'android.intent.category.BROWSABLE'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filter) ⇒ IntentFilter

Returns a new instance of IntentFilter.



161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/android/manifest.rb', line 161

def initialize(filter)
  @activity = filter.parent
  @actions = []
  @categories = []
  @data = []

  filter.elements.each do |element|
    type = element.name.downcase
    next unless TYPES.include?(type)

    case type
    when 'action'
      @actions << Action.new(element)
    when 'category'
      @categories << Category.new(element)
    when 'data'
      @data << Data.new(element)
    end
  end
end

Instance Attribute Details

#actionsIntentFilter::Action (readonly)

Returns intent-filter actions.

Returns:



153
154
155
# File 'lib/android/manifest.rb', line 153

def actions
  @actions
end

#activityIntentFilter::Data (readonly)

Returns intent-filter data.

Returns:



159
160
161
# File 'lib/android/manifest.rb', line 159

def activity
  @activity
end

#categoriesIntentFilter::Category (readonly)

Returns intent-filter categories.

Returns:



155
156
157
# File 'lib/android/manifest.rb', line 155

def categories
  @categories
end

#dataIntentFilter::Data (readonly)

Returns intent-filter data.

Returns:



157
158
159
# File 'lib/android/manifest.rb', line 157

def data
  @data
end

Class Method Details

.valid?(filter) ⇒ Boolean

the element is valid IntentFilter element or not

Parameters:

  • elem (REXML::Element)

    xml element

Returns:

  • (Boolean)


144
145
146
147
148
149
150
# File 'lib/android/manifest.rb', line 144

def self.valid?(filter)
  filter&.elements&.any? do |elem|
    TYPES.include?(elem&.name&.downcase)
  end
rescue
  false
end

Instance Method Details

#browsable?Boolean

the browsable category vaild or not

Returns:

  • (Boolean)

Since:

  • 2.5.0



248
249
250
# File 'lib/android/manifest.rb', line 248

def browsable?
  exist?(CATEGORY_BROWSABLE)
end
Note:

return empty array when the manifest include no http or https scheme of data

Returns all data elements.

Returns:

  • (Array<String>)

    all data elements

Since:

  • 2.5.0



212
213
214
215
216
217
218
# File 'lib/android/manifest.rb', line 212

def deep_links
  return unless deep_links?

  data.select {|d| !d.host.nil?  }
      .map { |d| d.host }
      .uniq
end

#deep_links?Boolean

the deep links exists with http or https in data element or not

Returns:

  • (Boolean)

Since:

  • 2.5.0



223
224
225
# File 'lib/android/manifest.rb', line 223

def deep_links?
  browsable? && data.any? { |d| ['http', 'https'].include?(d.scheme) }
end

#empty?Boolean

Returns true if self contains no [IntentFilter::Action] elements.

Returns:

  • (Boolean)


184
185
186
# File 'lib/android/manifest.rb', line 184

def empty?
  @actions.empty?
end

#exist?(name, type: nil) ⇒ Boolean

Returns:

  • (Boolean)


188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
# File 'lib/android/manifest.rb', line 188

def exist?(name, type: nil)
  if type.to_s.empty? && !name.start_with?('android.intent.')
    raise 'Fill type or use correct name'
  end

  type ||= name.split('.')[2]
  raise 'Not found type' unless TYPES.include?(type)

  method_name = case type
                when 'action'
                  :actions
                when 'category'
                  :categories
                when 'data'
                  :data
                end

  values = send(method_name).select { |e| e.name == name }
  values.empty? ? false : values #(values.size == 1 ? values.first : values)
end

#schemesArray<String>

Note:

return empty array when the manifest not include http or https scheme(s) of data

Returns all data elements.

Returns:

  • (Array<String>)

    all data elements

Since:

  • 2.5.0



230
231
232
233
234
235
236
# File 'lib/android/manifest.rb', line 230

def schemes
  return unless schemes?

  data.select {|d| !d.scheme.nil? && !['http', 'https'].include?(d.scheme) }
      .map { |d| d.scheme }
      .uniq
end

#schemes?Boolean

the deep links exists with non-http or non-https in data element or not

Returns:

  • (Boolean)

Since:

  • 2.5.0



241
242
243
# File 'lib/android/manifest.rb', line 241

def schemes?
  browsable? && data.any? { |d| !['http', 'https'].include?(d.scheme) }
end