Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Consolidate JSON Info output into a single object #149

Merged
merged 2 commits into from
Nov 29, 2024

Conversation

AbhiTheModder
Copy link
Contributor

Refactored InfoWriterJson to produce a single JSON object containing all information. This addresses the issue of fragmented JSON output (#147). The writeStringPool method now correctly adds its data to the main JSON object.

Refactored `InfoWriterJson` to produce a single JSON object containing all information. This addresses the issue of fragmented JSON output (REAndroid#147). The `writeStringPool` method now correctly adds its data to the main JSON object.

public InfoWriterJson(Writer writer) {
super(writer);
JSONWriter jsonWriter = new JSONWriter(writer);
jsonWriter = jsonWriter.array();
JSONObject jsonObject = new JSONObject();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tried to keep the base structure same, however, for this line, I'm uncertain if it should be placed immediately after the JSONWriter initialization or in this manner. Please let me know if this is not acceptable. :)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you,

  • When JSONObject used all values will be hold on memory until flushed, but JSONWriter transfers all objects to stream instantly. May have impact when dealing with huge resources.
  • There is mis structure and duplicates, please run your tests with verbose -v flag.

Copy link
Contributor Author

@AbhiTheModder AbhiTheModder Nov 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • There is mis structure and duplicates, please run your tests with verbose -v flag.

I ensured that I tested with all available flags; however, I might be missing something (please point it out if you notice), here are my test results on two different APKs:

1:

$ java -jar build/libs/APKEditor-1.4.1.jar info -i test.apk -v -t json
[
 {
  "resource-packages":
  [
   {
    "id":127,
    "name":"you.in.spark.access.dots"
   }
  ]
 },
 {
  "id":2131689509,
  "type":"string",
  "name":"app_name",
  "entries":
  [
   {
    "qualifiers":"",
    "value":"Access Dots"
   }
  ]
 },
 {
  "id":2131558400,
  "type":"mipmap",
  "name":"access_dots_logo",
  "entries":
  [
   {
    "qualifiers":"-mdpi",
    "value":"res/mipmap-mdpi-v4/access_dots_logo.png"
   },
   {
    "qualifiers":"-hdpi",
    "value":"res/mipmap-hdpi-v4/access_dots_logo.png"
   },
   {
    "qualifiers":"-xhdpi",
    "value":"res/mipmap-xhdpi-v4/access_dots_logo.png"
   },
   {
    "qualifiers":"-xxhdpi",
    "value":"res/mipmap-xxhdpi-v4/access_dots_logo.png"
   },
   {
    "qualifiers":"-xxxhdpi",
    "value":"res/mipmap-xxxhdpi-v4/access_dots_logo.png"
   }
  ]
 },
 {
  "activities":
  [
   "you.in.spark.access.dots.AccessDotsHome",
   "you.in.spark.access.dots.InformationDialog",
   "com.google.android.gms.ads.AdActivity",
   "com.google.firebase.auth.internal.GenericIdpActivity",
   "com.google.firebase.auth.internal.RecaptchaActivity",
   "com.google.android.gms.common.api.GoogleApiActivity",
   "com.android.billingclient.api.ProxyBillingActivity"
  ]
 },
 {
  "uses-permission":
  [
   "android.permission.ACCESS_FINE_LOCATION",
   "android.permission.ACCESS_NETWORK_STATE",
   "android.permission.INTERNET",
   "android.permission.RECEIVE_BOOT_COMPLETED",
   "android.permission.SYSTEM_ALERT_WINDOW",
   "android.permission.WAKE_LOCK",
   "com.android.vending.BILLING"
  ]
 },
 {
  "package":"you.in.spark.access.dots",
  "VersionCode":11,
  "VersionName":"AD_3.6_BETA",
  "application-class":"you.in.spark.access.dots.MyApplication",
  "activity-main":"you.in.spark.access.dots.AccessDotsHome"
 }
]

2: Second one is tested on a large app so it's bit lengthy uploading as file here: out.json

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wrong about duplicates on my last comment, but seems like we need to do massive rework on "InfoWriterJson".

  • The main objective of info in json format is to provide universally parse-able information for secondary applications/services (e.g python scripts, web services, docker ...), for further processing.
  • As pointed by Enhancement Request: Nicer Json output for info command #147 , for example if you want to pick "application-class" you still have to iterate all objects on root json. On future we might need to replace root json-array by json-object.

Just a suggestion:

{
"app": {
  "package":"com.example",
  "versionCode":123,
  "versionName":"1.2.3"
 },
"uses-permission":
  [
   "android.permission.READ_MEDIA_VIDEO",
   "android.permission.READ_PHONE_STATE"
  ],
"activities":
  [
   "com.Activity1",
   "com.Activity2"
  ]
}

For now I am going to merge this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m also using it in my project and initially came to create an issue, but seeing there was already one and knowing you’re busy, I tried addressing it myself. However, regarding the "massive work," I’m not confident I can write it the way you do with how badly I write my projects 🙈, as I’ve seen how much consideration you put into your code structure.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow @AbhiTheModder thanks so much for doing this!

@REAndroid REAndroid merged commit a00ec09 into REAndroid:master Nov 29, 2024
1 check passed
@AbhiTheModder AbhiTheModder deleted the patch-1 branch November 30, 2024 03:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants