Skip to content

Commit

Permalink
Pass AppInfo as Parcelable between Activities instead of relying on s…
Browse files Browse the repository at this point in the history
…toring it in memory in a Singleton manner

- Add Kotlin Parcelize dependency and make AppInfo Parcelable
- Remove no longer necessary custom Application class (that was previously used to temporarily store the selected AppInfo while navigating between Activities)
- Some UI improvements
- Improve nullability handling, visibility and mutability
  • Loading branch information
balazsgerlei committed Sep 3, 2024
1 parent a11b56b commit 74ab0f9
Show file tree
Hide file tree
Showing 14 changed files with 166 additions and 191 deletions.
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.jetbrains.kotlin.android)
alias(libs.plugins.jetbrains.kotlin.parcelize)
}

android {
Expand Down
1 change: 0 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
tools:ignore="QueryAllPackagesPermission" />

<application
android:name=".IntentFuzzerApp"
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
Expand Down
39 changes: 18 additions & 21 deletions app/src/main/java/dev/gerlot/intentfuzzer/AppInfoActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ class AppInfoActivity : AppCompatActivity() {
override fun handleMessage(msg: Message) {
when (msg.what) {
Utils.MSG_DONE -> {
progressBar!!.visibility = View.GONE
listView!!.adapter = appInfoAdapter
progressBar?.visibility = View.GONE
listView?.adapter = appInfoAdapter
}

Utils.MSG_PROCESSING -> progressBar!!.visibility = View.VISIBLE
Utils.MSG_PROCESSING -> progressBar?.visibility = View.VISIBLE
Utils.MSG_ERROR -> {}
}
}
Expand All @@ -51,7 +51,6 @@ class AppInfoActivity : AppCompatActivity() {
mHandler.obtainMessage(msg).sendToTarget()
}


override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setProgressBarVisibility(true)
Expand All @@ -62,33 +61,31 @@ class AppInfoActivity : AppCompatActivity() {
progressBar = findViewById<View>(R.id.progressbar) as ProgressBar
listView = findViewById<View>(R.id.app_listview) as ListView

progressBar!!.isIndeterminate = false
progressBar?.isIndeterminate = false

mHandler.obtainMessage(msg).sendToTarget()

val intent = intent
if (intent.hasExtra("type")) {
appType = intent.getIntExtra("type", Utils.ALL_APPS)
if (intent.hasExtra(Utils.APPTYPE_KEY)) {
appType = intent.getIntExtra(Utils.APPTYPE_KEY, Utils.ALL_APPS)
}

if (mGetPkgInfoThread == null) {
mGetPkgInfoThread = Thread(pkgInfoRunnable)
mGetPkgInfoThread!!.start()
}

listView!!.onItemClickListener =
OnItemClickListener { parent, view, position, id ->
val appInfo: AppInfo = appInfoAdapter!!.getItem(position) as AppInfo
(application as IntentFuzzerApp).packageInfo = appInfo.packageInfo

val intent = Intent(
this@AppInfoActivity,
FuzzerActivity::class.java
)
//Bundle bundle = new Bundle();
//bundle.putParcelable(Utils.PKGINFO_KEY, appInfo.getPackageInfo());
//intent.putExtras(bundle);
startActivity(intent)
listView?.onItemClickListener =
OnItemClickListener { _, _, position, _ ->
(appInfoAdapter?.getItem(position) as AppInfo).let { appInfo ->
Intent(this, FuzzerActivity::class.java).also { newIntent ->
Bundle().apply {
putParcelable(Utils.APPINFO_KEY, appInfo)
}.also {
newIntent.putExtras(it);
startActivity(newIntent)
}
}
}
}
}

Expand Down
16 changes: 8 additions & 8 deletions app/src/main/java/dev/gerlot/intentfuzzer/AppInfoAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import android.view.ViewGroup
import android.widget.BaseAdapter
import android.widget.ImageView
import android.widget.TextView
import androidx.core.graphics.drawable.toDrawable
import dev.gerlot.intentfuzzer.util.AppInfo

class AppInfoAdapter(context: Context, appInfos: List<AppInfo>?) :
BaseAdapter() {
class AppInfoAdapter(context: Context, appInfos: List<AppInfo>?) : BaseAdapter() {
private var mlistAppInfo: List<AppInfo>? = null

var infater: LayoutInflater? = null
private var infater: LayoutInflater? = null

init {
infater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
Expand All @@ -38,16 +38,16 @@ class AppInfoAdapter(context: Context, appInfos: List<AppInfo>?) :
if (convertview?.tag == null) {
view = infater?.inflate(R.layout.package_info, null)
holder = ViewHolder(view!!)
view!!.tag = holder
view.tag = holder
} else {
view = convertview
holder = convertview.tag as ViewHolder
}
val appInfo: AppInfo = getItem(position) as AppInfo
holder!!.appIcon.setImageDrawable(appInfo.appIcon)
holder.appName.setText(appInfo.appName)
holder.packageName.setText(appInfo.packageName)
return view!!
holder.appIcon.setImageBitmap(appInfo.appIcon)
holder.appName.text = appInfo.appName
holder.packageName.text = appInfo.packageName
return view
}

internal inner class ViewHolder(view: View) {
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/java/dev/gerlot/intentfuzzer/ComponentAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class ComponentAdapter(context: Context, componentInfos: List<ComponentInfo>?) :
BaseAdapter() {
private var mlistComponentInfo: List<ComponentInfo>? = null

var infater: LayoutInflater? = null
private var infater: LayoutInflater? = null

init {
infater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
Expand All @@ -32,8 +32,8 @@ class ComponentAdapter(context: Context, componentInfos: List<ComponentInfo>?) :
}

override fun getView(position: Int, convertview: View?, viewGroup: ViewGroup): View {
var view: View? = null
var holder: ViewHolder? = null
val view: View?
val holder: ViewHolder?
if (convertview?.tag == null) {
view = infater?.inflate(R.layout.component, null)
holder = ViewHolder(view!!)
Expand Down
Loading

0 comments on commit 74ab0f9

Please sign in to comment.