All Downloads are FREE. Search and download functionalities are using the official Maven repository.

main.shark.AndroidServices.kt Maven / Gradle / Ivy

The newest version!
package shark

object AndroidServices {
  val HeapGraph.aliveAndroidServiceObjectIds: List
    get() {
      return context.getOrPut(AndroidServices::class.java.name) {
        val activityThreadClass = findClassByName("android.app.ActivityThread")!!
        val currentActivityThread = activityThreadClass
          .readStaticField("sCurrentActivityThread")!!
          .valueAsInstance!!

        val mServices = currentActivityThread["android.app.ActivityThread", "mServices"]!!
          .valueAsInstance!!

        val servicesArray = mServices["android.util.ArrayMap", "mArray"]!!.valueAsObjectArray!!

        servicesArray.readElements()
          .filterIndexed { index, heapValue ->
            // ArrayMap
            // even: key, odd: value
            index % 2 == 1
              && heapValue.isNonNullReference
          }
          .map { it.asNonNullObjectId!! }
          .toList()
      }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy