MuntashirAkon / AppManager

A full-featured package manager and viewer for Android
https://muntashirakon.github.io/AppManager/
Other
5.02k stars 282 forks source link

Allow disabling components of test-only apps on ADB mode #511

Closed MuntashirAkon closed 2 years ago

MuntashirAkon commented 3 years ago

Is it possible to check a package is testOnly then add a option to disable its component? I think it is useful for "adb user" when they have to use some app with tracker because sometime make app testOnly and reinstall it is possible.

Originally posted by @d4rkk3y in https://github.com/MuntashirAkon/AppManager/discussions/510#discussioncomment-985418

SNNafi commented 3 years ago

Yes, this is possible to check whether is it testOnly on not. From Android Studio 3.0, it sets android:testOnly="true" on APKs that are run from the IDE.

BUT, it does not exist in these cases

  1. Built the app using the Build APK(s) menu option

  2. Built the app using the assembleDebug or assembleRelease Gradle tasks

  3. Built the app using something else that might use those tasks, such as a CI server

AND, we can check it by the following code,

if(applicationInfo.flags and ApplicationInfo.FLAG_TEST_ONLY) == 256) {
    // testOnly=true
} else {
    // testOnly=false
}

I want to work on this feature. But as I am new to this repo, I can't understand, "then add an option to disable its component" Can you please give me some insights in this regard ? :)

MuntashirAkon commented 3 years ago

Thanks for your interest!

App Manager currently offers a feature called “block components” for root users only because components can be disabled/blocked only with root. However, if the app is a test-only app, components of the app can be disabled with ADB. The task here is to allow disabling components for the test-only apps if the user has enabled ADB mode of operation.

That being said, your tasks are as follows:

  1. In the components tabs of the app details page, if the app is set to test-only and ADB is enabled, reveal the block/unblock button.
  2. In the 1-click ops page, enable “block/unblock trackers” and “block components...” for ADB users too, and filter the list with test-only the apps (for ADB users only, others should be the same as it is).
  3. In the ComponentsBlocker class, disable applying Intent Firewall (IFW) rules for ADB users.

You can check if ADB is enabled anywhere in the app via AppPref#isAdbEnabled(). You do not have to worry about enabling/disabling components as they are already present in the ComponentsBlocker class.

While the tasks are very easy, you might have to analyse the code and read the docs in order to understand the tasks a bit better. You can always ask me here if you have any queries. Good luck!

SNNafi commented 3 years ago

Thanks for your detailed reply. I will check it very soon 😀

SNNafi commented 3 years ago

I have completed task 2 i.e. In the 1-click ops page, enable “block/unblock trackers” and “block components...” for ADB users too, and filter the list with test-only the apps (for ADB users only, others should be the same as it is).

But when I want to build it by Make Project, I am getting this error. I am using M1 macbook with Android Studio arm64 build.

Screenshot 2021-10-18 at 8 17 54 PM
MuntashirAkon commented 3 years ago

I have completed task 2 i.e. In the 1-click ops page, enable “block/unblock trackers” and “block components...” for ADB users too, and filter the list with test-only the apps (for ADB users only, others should be the same as it is).

You need to have latex and tex4ht installed in order to build the docs. You can disable it for now by commenting the following line:

https://github.com/MuntashirAkon/AppManager/blob/afd7d88e23f16ebcc35489bf1bf39cf56b32395f/docs/build.gradle#L59

SNNafi commented 3 years ago

Thanks for your quick reply. But another error occurred. :( Didn't find anything useful on the internet.

No matching variant of dev.rikka.tools.refine:gradle-plugin:3.0.3 was found. The consumer was configured to find a runtime of a library compatible with Java 8, packaged as a jar, and its dependencies declared externally, as well as attribute 'org.gradle.plugin.api-version' with value '7.1.1' but:
MuntashirAkon commented 3 years ago

Make sure JDK version is 11 or later (14 recommended). Android Studio or IntelliJ uses Java 8.1 by default which wouldn't work with App Manager.

SNNafi commented 3 years ago

Sorry for the late update. I have checked task no 2., and it is working fine.

For task 3, I think changing this code,

 private void retrieveDisabledComponents() {
        if (!AppPref.isRootEnabled()) return;
                           --------
}

to

 private void retrieveDisabledComponents() {
        if (!AppPref.isRootOrAdbEnabled()) return;
                             ----------------------
}

do the work? Is it ok?

MuntashirAkon commented 3 years ago

Just make a PR with your changes and link this issue there. I'll review and add comments there as necessary. You don't have to post here for the verification of your logic. Only post when you get stuck somewhere.

MuntashirAkon commented 2 years ago

Implemented in e9da575b

sobaee commented 2 years ago

Since this mod has implemented in the latest version

Where can I found the test-only version of app manager which I can install it by: adb install -t package-name?