-
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
99 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
app/src/main/java/com/sdex/activityrunner/manifest/ManifestParser.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package com.sdex.activityrunner.manifest | ||
|
||
import com.sdex.activityrunner.app.ActivityModel | ||
import org.xmlpull.v1.XmlPullParser | ||
import org.xmlpull.v1.XmlPullParserFactory | ||
import timber.log.Timber | ||
import java.io.StringReader | ||
|
||
class ManifestParser( | ||
private val manifestXml: String | ||
) { | ||
|
||
fun getActivities(packageName: String): List<ActivityModel> { | ||
val activities = mutableListOf<ActivityModel>() | ||
try { | ||
val factory = XmlPullParserFactory.newInstance() | ||
factory.isNamespaceAware = true | ||
val parser = factory.newPullParser() | ||
parser.setInput(StringReader(manifestXml)) | ||
var eventType = parser.eventType | ||
var activityModel: ActivityModel? = null | ||
while (eventType != XmlPullParser.END_DOCUMENT) { | ||
if (eventType == XmlPullParser.START_TAG && | ||
(parser.name == "activity" || parser.name == "activity-alias") | ||
) { | ||
val className = parser.getAttributeValue(null, "name") | ||
val activityName = className.split(".").last() | ||
val activityLabel = parser.getAttributeValue(null, "label") | ||
val enabledAttributeValue = parser.getAttributeValue(null, "enabled") | ||
val enabled = if (enabledAttributeValue.isNullOrEmpty()) { | ||
true | ||
} else { | ||
java.lang.Boolean.parseBoolean(enabledAttributeValue) | ||
} | ||
val model = ActivityModel( | ||
activityName, | ||
packageName, | ||
className, | ||
activityLabel, | ||
exported = false, | ||
enabled | ||
) | ||
|
||
val exportedAttributeValue = parser.getAttributeValue(null, "exported") | ||
if (exportedAttributeValue.isNullOrEmpty()) { | ||
// if the activity has "intent-filter" the exported is true, otherwise false | ||
activityModel = model | ||
} else { | ||
model.exported = java.lang.Boolean.parseBoolean(exportedAttributeValue) | ||
activities.add(model) | ||
} | ||
} else if (eventType == XmlPullParser.START_TAG && | ||
parser.name == "intent-filter" && activityModel != null | ||
) { | ||
activityModel.exported = true | ||
activities.add(activityModel) | ||
activityModel = null | ||
} else if (eventType == XmlPullParser.END_TAG && | ||
(parser.name == "activity" || parser.name == "activity-alias") && | ||
activityModel != null | ||
) { | ||
activityModel.exported = false | ||
activities.add(activityModel) | ||
activityModel = null | ||
} | ||
eventType = parser.next() | ||
} | ||
} catch (e: Exception) { | ||
Timber.e(e) | ||
} | ||
return activities | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
- Load manifest for bundles | ||
- Load activities of disabled apps |