Skip to content

Commit 8d3a751

Browse files
committed
Add doc blocks
1 parent bfebe68 commit 8d3a751

20 files changed

Lines changed: 173 additions & 12 deletions

app/src/main/kotlin/com/njlabs/showjava/activities/about/AboutActivity.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,16 @@ import com.njlabs.showjava.R
2727
import com.njlabs.showjava.activities.BaseActivity
2828
import kotlinx.android.synthetic.main.activity_about.*
2929

30+
/**
31+
* Show information about the app, its version & licenses to all open source libraries used
32+
*/
3033
class AboutActivity : BaseActivity() {
3134
override fun init(savedInstanceState: Bundle?) {
3235
setupLayout(R.layout.activity_about)
3336
if (BuildConfig.GIT_SHA.isNotEmpty()) {
3437
version.setText(R.string.appVersionExtendedWithHash)
3538
}
39+
3640
viewOpenSourceLicenses.setOnClickListener {
3741
Crashlytics.getInstance().crash()
3842
overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out)

app/src/main/kotlin/com/njlabs/showjava/activities/apps/AppsHandler.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ import io.reactivex.ObservableEmitter
2828

2929
class AppsHandler(private var context: Context) {
3030

31+
/**
32+
* Load all installed applications.
33+
*
34+
* @return [Observable] which can be used to track the loading progress and completion state.
35+
*/
3136
fun loadApps(withSystemApps: Boolean): Observable<ProcessStatus<ArrayList<PackageInfo>>> {
3237
return Observable.create { emitter: ObservableEmitter<ProcessStatus<ArrayList<PackageInfo>>> ->
3338
val installedApps = ArrayList<PackageInfo>()

app/src/main/kotlin/com/njlabs/showjava/activities/decompiler/LowMemoryActivity.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ import io.reactivex.schedulers.Schedulers
2828
import kotlinx.android.synthetic.main.activity_low_memory.*
2929
import timber.log.Timber
3030

31+
/**
32+
* If an app's decompilation was stopped due to low memory, explain what happened to the user
33+
* And also provide user a way to report the app that failed to decompile. This can then
34+
* be investigated later on to see what can be done to reduce the memory usage.
35+
*/
3136
class LowMemoryActivity : BaseActivity() {
3237

3338
override fun init(savedInstanceState: Bundle?) {

app/src/main/kotlin/com/njlabs/showjava/activities/explorer/navigator/NavigatorActivity.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,11 +219,10 @@ class NavigatorActivity : BaseActivity() {
219219
}
220220
}
221221

222+
/**
223+
* Check if the current folder the user is in, is the root
224+
*/
222225
private fun isAtRoot(): Boolean {
223-
224-
Timber.d("[isAtRoot] currentDirectory: ${currentDirectory?.canonicalPath}")
225-
Timber.d("[isAtRoot] sourceDirectory: ${selectedApp?.sourceDirectory?.canonicalPath}")
226-
227226
return currentDirectory?.canonicalPath == selectedApp?.sourceDirectory?.canonicalPath
228227
}
229228

app/src/main/kotlin/com/njlabs/showjava/activities/explorer/navigator/NavigatorHandler.kt

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,14 @@ import kotlin.collections.sortBy
3434

3535
class NavigatorHandler(private var context: Context) {
3636

37-
fun loadFiles(currentFile: File): Observable<ArrayList<FileItem>> {
37+
/**
38+
* Load all files in the given directory
39+
*/
40+
fun loadFiles(currentDirectory: File): Observable<ArrayList<FileItem>> {
3841
return Observable.fromCallable {
3942
val directories = ArrayList<FileItem>()
4043
val files = ArrayList<FileItem>()
41-
val items = currentFile.listFiles()
44+
val items = currentDirectory.listFiles()
4245
if (items.isNullOrEmpty()) {
4346
return@fromCallable directories
4447
}
@@ -66,13 +69,19 @@ class NavigatorHandler(private var context: Context) {
6669
}
6770
}
6871

72+
/**
73+
* Package an entire directory containing the source code into a .zip archive.
74+
*/
6975
fun archiveDirectory(sourceDirectory: File, packageName: String): Observable<File> {
7076
return Observable.fromCallable {
7177
ZipUtils.zipDir(sourceDirectory, packageName)
7278
}
7379
}
7480

75-
fun deleteDirectory(sourceDirectory: File): Observable<Any> {
81+
/**
82+
* Delete the source directory
83+
*/
84+
fun deleteDirectory(sourceDirectory: File): Observable<Unit> {
7685
return Observable.fromCallable {
7786
try {
7887
if (sourceDirectory.exists()) {

app/src/main/kotlin/com/njlabs/showjava/activities/explorer/navigator/adapters/FilesListAdapter.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ import com.njlabs.showjava.R
2525
import com.njlabs.showjava.data.FileItem
2626
import kotlinx.android.synthetic.main.layout_app_list_item.view.*
2727

28+
/**
29+
* List adapter for the code navigator
30+
*/
2831
class FilesListAdapter(
2932
private var fileItems: List<FileItem>,
3033
private val itemClick: (FileItem) -> Unit

app/src/main/kotlin/com/njlabs/showjava/activities/settings/SettingsHandler.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ import com.njlabs.showjava.utils.appStorage
2323
import io.reactivex.Observable
2424

2525
class SettingsHandler(private var context: Context) {
26+
27+
/**
28+
* Delete all decompiled sources recursively
29+
*/
2630
fun deleteHistory(): Observable<Any> {
2731
return Observable.fromCallable {
2832
appStorage.resolve("sources")

app/src/main/kotlin/com/njlabs/showjava/data/SourceInfo.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ import timber.log.Timber
2929
import java.io.File
3030
import java.io.IOException
3131

32+
/**
33+
* [SourceInfo] holds information about a specific decompiled source on the app storage.
34+
* The source info is persisted to disk as a simple json file at the root of each package's
35+
* decompiled source folder.
36+
*/
3237
class SourceInfo() : Parcelable {
3338

3439
lateinit var packageLabel: String

app/src/main/kotlin/com/njlabs/showjava/decompilers/BaseDecompiler.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ import java.io.File
4141
import java.io.PrintStream
4242
import java.util.concurrent.TimeUnit
4343

44+
/**
45+
* The base decompiler. This reads the input [Data] into easy to use properties of the class.
46+
* All other components of the decompiler will extend this one.
47+
*/
4448
abstract class BaseDecompiler(val context: Context, val data: Data) {
4549
var printStream: PrintStream? = null
4650

@@ -149,6 +153,9 @@ abstract class BaseDecompiler(val context: Context, val data: Data) {
149153
this.broadcastStatus(null, message)
150154
}
151155

156+
/**
157+
* Set the current decompilation step
158+
*/
152159
fun setStep(title: String) {
153160
sendStatus(title, context.getString(R.string.initializing), true)
154161
}
@@ -166,6 +173,9 @@ abstract class BaseDecompiler(val context: Context, val data: Data) {
166173
ListenableWorker.Result.RETRY
167174
}
168175

176+
/**
177+
* Return a success only if the conditions is true. Else exit with an exception.
178+
*/
169179
protected fun successIf(condition: Boolean): ListenableWorker.Result {
170180
disposables.clear()
171181
return if (condition)
@@ -202,6 +212,9 @@ abstract class BaseDecompiler(val context: Context, val data: Data) {
202212
)
203213
}
204214

215+
/**
216+
* Clear notifications and show a success notification.
217+
*/
205218
fun onCompleted() {
206219
processNotifier?.success()
207220
broadcastStatus(
@@ -224,6 +237,9 @@ abstract class BaseDecompiler(val context: Context, val data: Data) {
224237

225238
companion object {
226239

240+
/**
241+
* Check if the specified decompiler is available on the device based on the android version
242+
*/
227243
fun isAvailable(decompiler: String): Boolean {
228244
return when (decompiler) {
229245
"cfr" -> true

app/src/main/kotlin/com/njlabs/showjava/decompilers/JarExtractionWorker.kt

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,22 @@ import java.io.BufferedInputStream
4444
import java.io.InputStream
4545
import java.util.zip.ZipFile
4646

47-
47+
/**
48+
* The [JarExtractionWorker] worker handles optimization and extraction of the jar/dex file from the source
49+
*
50+
* a. For APKs & Dex files:
51+
* 1. All the classes within the input are read
52+
* 2. Classes are checked against the ignore list.
53+
* 3. Multiple dex files are created with the classes that are not ignored.
54+
* 4. For inputs with a large number of classes, creating a single dex file causes devices to
55+
* run out of memory. So, we chunk them to smaller dex files containing lesser number
56+
* of classes.
57+
* 5. The dex files are then converted to jar. (With the exception of JaDX which prefers dex files)
58+
*
59+
* b. For Jar files:
60+
* 1. They are directly passed to the next step. (With the exception of JaDX where the jar is
61+
* read and converted into dex chunks and then passed on to JaDX)
62+
*/
4863
class JarExtractionWorker(context: Context, data: Data) : BaseDecompiler(context, data) {
4964

5065
private var ignoredLibs: ArrayList<String> = ArrayList()

0 commit comments

Comments
 (0)