@@ -129,6 +129,42 @@ class AndroidApplicationXmlElement extends XmlElement {
129129 */
130130class AndroidActivityXmlElement extends AndroidComponentXmlElement {
131131 AndroidActivityXmlElement ( ) { this .getName ( ) = "activity" }
132+
133+ /**
134+ * Gets an `<activity-alias>` element aliasing the activity.
135+ */
136+ AndroidActivityAliasXmlElement getAnAlias ( ) {
137+ exists ( AndroidActivityAliasXmlElement alias | this = alias .getTarget ( ) | result = alias )
138+ }
139+ }
140+
141+ /**
142+ * An `<activity-alias>` element in an Android manifest file.
143+ */
144+ class AndroidActivityAliasXmlElement extends AndroidComponentXmlElement {
145+ AndroidActivityAliasXmlElement ( ) { this .getName ( ) = "activity-alias" }
146+
147+ /**
148+ * Get and resolve the name of the target activity from the `android:targetActivity` attribute.
149+ */
150+ string getResolvedTargetActivityName ( ) {
151+ exists ( AndroidXmlAttribute attr |
152+ attr = this .getAnAttribute ( ) and attr .getName ( ) = "targetActivity"
153+ |
154+ result = this .getResolvedIdentifier ( attr )
155+ )
156+ }
157+
158+ /**
159+ * Gets the `<activity>` element referenced by the `android:targetActivity` attribute.
160+ */
161+ AndroidActivityXmlElement getTarget ( ) {
162+ exists ( AndroidActivityXmlElement activity |
163+ activity .getResolvedComponentName ( ) = this .getResolvedTargetActivityName ( )
164+ |
165+ result = activity
166+ )
167+ }
132168}
133169
134170/**
@@ -212,6 +248,13 @@ class AndroidPermissionXmlAttribute extends XmlAttribute {
212248 predicate isWrite ( ) { this .getName ( ) = "writePermission" }
213249}
214250
251+ /**
252+ * The attribute `android:name` or `android:targetActivity`.
253+ */
254+ class AndroidIdentifierXmlAttribute extends AndroidXmlAttribute {
255+ AndroidIdentifierXmlAttribute ( ) { this .getName ( ) = [ "name" , "targetActivity" ] }
256+ }
257+
215258/**
216259 * The `<path-permission`> element of a `<provider>` in an Android manifest file.
217260 */
@@ -228,7 +271,7 @@ class AndroidPathPermissionXmlElement extends XmlElement {
228271class AndroidComponentXmlElement extends XmlElement {
229272 AndroidComponentXmlElement ( ) {
230273 this .getParent ( ) instanceof AndroidApplicationXmlElement and
231- this .getName ( ) .regexpMatch ( "(activity|service|receiver|provider)" )
274+ this .getName ( ) .regexpMatch ( "(activity|activity-alias| service|receiver|provider)" )
232275 }
233276
234277 /**
@@ -254,19 +297,30 @@ class AndroidComponentXmlElement extends XmlElement {
254297 )
255298 }
256299
300+ /**
301+ * Gets the value of an identifier attribute, and tries to resolve it into a fully qualified identifier.
302+ */
303+ string getResolvedIdentifier ( AndroidIdentifierXmlAttribute identifier ) {
304+ exists ( string name | name = identifier .getValue ( ) |
305+ if name .matches ( ".%" )
306+ then
307+ result =
308+ this .getParent ( )
309+ .( XmlElement )
310+ .getParent ( )
311+ .( AndroidManifestXmlElement )
312+ .getPackageAttributeValue ( ) + name
313+ else result = name
314+ )
315+ }
316+
257317 /**
258318 * Gets the resolved value of the `android:name` attribute of this component element.
259319 */
260320 string getResolvedComponentName ( ) {
261- if this .getComponentName ( ) .matches ( ".%" )
262- then
263- result =
264- this .getParent ( )
265- .( XmlElement )
266- .getParent ( )
267- .( AndroidManifestXmlElement )
268- .getPackageAttributeValue ( ) + this .getComponentName ( )
269- else result = this .getComponentName ( )
321+ exists ( AndroidXmlAttribute attr | attr = this .getAnAttribute ( ) and attr .getName ( ) = "name" |
322+ result = this .getResolvedIdentifier ( attr )
323+ )
270324 }
271325
272326 /**
0 commit comments