ReVanced / revanced-manager

💊 Application to use ReVanced on Android
https://revanced.app
GNU General Public License v3.0
17.47k stars 723 forks source link

bug: After grant "install unknown apps" permission, patching starts again due to an issue of Android 11 #2138

Open kitadai31 opened 1 month ago

kitadai31 commented 1 month ago

Bug description

After patching is complete, if you press the "Install" button and allow the "Install unknown apps" permission, the patching will start again.

https://github.com/user-attachments/assets/9307078c-8d25-49ff-ab87-6c707f70c64a

This problem occurs only on Android 11. Android 11 has a issue that when user grant the "Install unknown apps" permission, the app will be force stopped, or the last Activity will be recreated.

Reference: https://issuetracker.google.com/issues/154157387 https://issuetracker.google.com/issues/168293637 https://www.androidpolice.com/2020/08/24/android-11-install-unknown-apps-more-cumbersome/ https://mobilesyrup.com/2020/06/03/android-11-change-apps-force-quite-install-apk/

This does not occur on Android 10 or earlier and Android 12 or later. (This is entirely an issue with Android 11 itself, and VendettaManager also have this issue that patching starts again, by the way.)

Possible solution

Ask the permission when the first launch, only on Android 11. (Like the Flutter Manager asks the install apps permission on the first launch)

Because the docs says that apps should request special permissions in-context when the user requests a specific action that requires the permission. https://developer.android.com/training/permissions/requesting-special#in-context For other versions of Android, you can continue to request the permission on the exact timing (when user pressed the "Install" button).

Version of ReVanced Manager and version & name of app you are patching

ReVanced Manager Compose, compose-dev branch e992a99

Installation method

None

ReVanced Manager logs

I picked up the logs near where the problem occurred.
It seems that the Manager's PID has also changed (from 17936 to 18861.)

08-13 21:06:26.596 17936 17952 I evanced.manage: Background concurrent copying GC freed 3045637(91MB) AllocSpace objects, 829(32MB) LOS objects, 32% free, 100MB/148MB, paused 44us total 243.293ms
08-13 21:06:27.901 17936 17981 I ReVanced Patcher: Aligning APK
08-13 21:06:28.237 17936 17952 I evanced.manage: Background concurrent copying GC freed 131353(47MB) AllocSpace objects, 97(18MB) LOS objects, 20% free, 185MB/233MB, paused 73us total 248.975ms
08-13 21:06:28.548 17936 17981 I ReVanced Patcher: Patched apk saved to /data/user/0/app.revanced.manager/app_ephemeral/patcher/result.apk
08-13 21:06:31.691 17936 18024 I ReVanced Patcher: Signing APK
08-13 21:06:32.243 17936 17952 I evanced.manage: Background concurrent copying GC freed 1261608(41MB) AllocSpace objects, 1062(131MB) LOS objects, 37% free, 79MB/127MB, paused 37us total 112.226ms
08-13 21:06:32.692 17936 18024 I ReVanced Manager: [Worker] Patching succeeded
08-13 21:06:32.708 17936 18680 I WM-WorkerWrapper: Worker result SUCCESS for Work [ id=e1b76616-78bd-4fa2-b8e6-b407d6819166, tags={ app.revanced.manager.patcher.worker.PatcherWorker } ]
08-13 21:06:32.715 17936 17936 I WM-SystemFgDispatcher: Stopping foreground service
08-13 21:06:36.235 17936 17965 D OpenGLRenderer: endAllActiveAnimators on 0x78741244a0 (UnprojectedRipple) with handle 0x7794153a20
08-13 21:06:36.672  1383  5698 I ActivityTaskManager: START u0 {act=android.content.pm.action.CONFIRM_INSTALL flg=0x10000000 pkg=com.android.packageinstaller cmp=com.android.packageinstaller/.InstallStart (has extras)} from uid 10345
08-13 21:06:36.679  1383  5698 W ActivityTaskManager: Tried to set launchTime (0) < mLastActivityLaunchTime (974162)
08-13 21:06:36.692  1383  5584 I ActivityTaskManager: START u0 {act=android.content.pm.action.CONFIRM_INSTALL flg=0x2000001 pkg=com.android.packageinstaller cmp=com.android.packageinstaller/.PackageInstallerActivity (has extras)} from uid 10099
08-13 21:06:36.698  1383  8194 W ActivityTaskManager: Tried to set launchTime (0) < mLastActivityLaunchTime (1417301)
08-13 21:06:36.711 15009 15009 W PackageParsing: Unknown element under <application>: property at /data/app/vmdl1013723930.tmp/base.apk Binary XML file line #307
08-13 21:06:36.774  1383  1525 I ActivityTaskManager: Displayed com.android.packageinstaller/.PackageInstallerActivity: +97ms
08-13 21:06:37.751  1383  2047 I ActivityTaskManager: START u0 {act=android.settings.MANAGE_UNKNOWN_APP_SOURCES dat=package:app.revanced.manager cmp=com.android.settings/.Settings$ManageAppExternalSourcesActivity} from uid 10099
08-13 21:06:37.880 18818 18818 D SettingsActivity: Starting onCreate
08-13 21:06:37.892 18818 18818 D SettingsActivity: Starting to set activity title
08-13 21:06:37.892 18818 18818 D SettingsActivity: Done setting title
08-13 21:06:37.892 18818 18818 D SettingsActivity: Switching to fragment com.android.settings.applications.appinfo.ExternalSourcesDetails
08-13 21:06:37.916  1383  2047 E UserRestrictionsUtils: Unknown restriction queried by uid 1000 (org.lineageos.lineageparts et al): null
08-13 21:06:37.917 18818 18818 D SettingsActivity: Executed frag manager pendingTransactions
08-13 21:06:37.933 18818 18847 W CategoryManager: Category is null, no tiles
08-13 21:06:37.937 18818 18818 W UnsafeUtil: platform method missing - proto runtime falling back to safer methods: java.lang.NoSuchMethodException: sun.misc.Unsafe.copyMemory [class java.lang.Object, long, class java.lang.Object, long, long]
08-13 21:06:37.947 18818 18848 D SettingsActivity: No enabled state changed, skipping updateCategory call
08-13 21:06:37.979 18818 18840 I AdrenoGLES-0: QUALCOMM build                   : 781e7d0, I46ff5fc46f
08-13 21:06:37.979 18818 18840 I AdrenoGLES-0: Build Date                       : 12/01/20
08-13 21:06:37.979 18818 18840 I AdrenoGLES-0: OpenGL ES Shader Compiler Version: EV031.31.04.01
08-13 21:06:37.979 18818 18840 I AdrenoGLES-0: Local Branch                     : QPR1
08-13 21:06:37.979 18818 18840 I AdrenoGLES-0: Remote Branch                    : 
08-13 21:06:37.979 18818 18840 I AdrenoGLES-0: Remote Branch                    : 
08-13 21:06:37.979 18818 18840 I AdrenoGLES-0: Reconstruct Branch               : 
08-13 21:06:37.979 18818 18840 I AdrenoGLES-0: Build Config                     : C P 11.0.1 AArch64
08-13 21:06:37.979 18818 18840 I AdrenoGLES-0: Driver Path                      : /vendor/lib64/egl/libGLESv2_adreno.so
08-13 21:06:37.982 18818 18840 I AdrenoGLES-0: PFP: 0x016ee189, ME: 0x00000000
08-13 21:06:37.983 18818 18840 W AdrenoUtils: <ReadGpuID_from_sysfs:197>: Failed to open /sys/class/kgsl/kgsl-3d0/gpu_model
08-13 21:06:37.983 18818 18840 W AdrenoUtils: <ReadGpuID:221>: Failed to read chip ID from gpu_model. Fallback to use the GSL path
vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
08-13 21:06:39.406  1383  5584 I ActivityManager: Killing 17936:app.revanced.manager/u0a345 (adj 900): REQUEST_INSTALL_PACKAGES changed.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
08-13 21:06:39.464  1383  3729 D ConnectivityService: ConnectivityService NetworkRequestInfo binderDied(NetworkRequest [ LISTEN id=178, [ Capabilities: INTERNET&NOT_RESTRICTED&TRUSTED&NOT_VPN&FOREGROUND Uid: 10345 AdministratorUids: [] RequestorUid: 10345 RequestorPackageName: app.revanced.manager] ], android.os.BinderProxy@ae33bca)
08-13 21:06:39.464  1383  5584 I WindowManager: WIN DEATH: Window{fb5d663 u0 app.revanced.manager/app.revanced.manager.MainActivity}
08-13 21:06:39.464  1383  5584 W InputDispatcher: Attempted to unregister already unregistered input channel 'fb5d663 app.revanced.manager/app.revanced.manager.MainActivity (server)'
08-13 21:06:39.466   847   847 I Zygote  : Process 17936 exited due to signal 9 (Killed)
08-13 21:06:39.467  1383  1520 W ActivityManager: setHasOverlayUi called on unknown pid: 17936
08-13 21:06:39.483  1383  1531 I libprocessgroup: Successfully killed process cgroup uid 10345 pid 17936 in 74ms
08-13 21:06:40.914  1902  1902 I KeyButtonView: Back button event: ACTION_DOWN
08-13 21:06:40.917  1383  1756 D InputDispatcher: Waiting to send key to Window{388083f u0 com.android.settings/com.android.settings.Settings$ManageAppExternalSourcesActivity} because there are unprocessed events that may cause focus to change
08-13 21:06:40.961  1902  1902 I KeyButtonView: Back button event: ACTION_UP
08-13 21:06:40.962  1383  1518 D AutofillManagerService: onBackKeyPressed()
08-13 21:06:40.963  1383  1756 D InputDispatcher: Waiting to send key to Window{388083f u0 com.android.settings/com.android.settings.Settings$ManageAppExternalSourcesActivity} because there are unprocessed events that may cause focus to change
08-13 21:06:40.995  1383  1520 D CompatibilityChangeReporter: Compat change id reported: 135634846; UID 10345; state: DISABLED
08-13 21:06:40.995  1383  1527 D CompatibilityChangeReporter: Compat change id reported: 143937733; UID 10345; state: ENABLED
08-13 21:06:41.003   847   847 D Zygote  : Forked child process 18861
08-13 21:06:41.005  1383  1527 I ActivityManager: Start proc 18861:app.revanced.manager/u0a345 for activity {app.revanced.manager/app.revanced.manager.MainActivity}
08-13 21:06:41.024  1209  1243 I adbd    : jdwp connection from 18861
08-13 21:06:41.071 18861 18861 D NetworkSecurityConfig: No Network Security Config specified, using platform default
08-13 21:06:41.072 18861 18861 D NetworkSecurityConfig: No Network Security Config specified, using platform default
08-13 21:06:41.088 18861 18861 I TetheringManager: registerTetheringEventCallback:app.revanced.manager
08-13 21:06:41.089 18861 18861 D WM-PackageManagerHelper: Skipping component enablement for androidx.work.impl.background.systemjob.SystemJobService
08-13 21:06:41.089 18861 18861 D WM-Schedulers: Created SystemJobScheduler and enabled SystemJobService
08-13 21:06:41.093 18861 18861 I [Koin]  : Started 42 definitions in 0.608229 ms
08-13 21:06:41.124 18861 18888 D ReVanced Manager: Bundle: PatchBundleEntity(uid=0, name=ReVanced Patches, versionInfo=VersionInfo(patches=v4.12.0, integrations=v1.12.0), source=api, autoUpdate=true)
08-13 21:06:41.125 18861 18888 D ReVanced Manager: Loaded patch bundle: /data/user/0/app.revanced.manager/app_patch_bundles/0/patches.jar
08-13 21:06:41.204 18861 18861 I [Koin]  : [Warning] - No Koin context defined in Compose, fallback to default Koin context.
08-13 21:06:41.204 18861 18861 I [Koin]  : Use KoinContext(), KoinAndroidContext() or KoinApplication() to setup or create Koin context with Compose and avoid such message.
08-13 21:06:41.345 18861 18891 I AdrenoGLES-0: QUALCOMM build                   : 781e7d0, I46ff5fc46f
08-13 21:06:41.345 18861 18891 I AdrenoGLES-0: Build Date                       : 12/01/20
08-13 21:06:41.345 18861 18891 I AdrenoGLES-0: OpenGL ES Shader Compiler Version: EV031.31.04.01
08-13 21:06:41.345 18861 18891 I AdrenoGLES-0: Local Branch                     : QPR1
08-13 21:06:41.345 18861 18891 I AdrenoGLES-0: Remote Branch                    : 
08-13 21:06:41.345 18861 18891 I AdrenoGLES-0: Remote Branch                    : 
08-13 21:06:41.345 18861 18891 I AdrenoGLES-0: Reconstruct Branch               : 
08-13 21:06:41.345 18861 18891 I AdrenoGLES-0: Build Config                     : C P 11.0.1 AArch64
08-13 21:06:41.345 18861 18891 I AdrenoGLES-0: Driver Path                      : /vendor/lib64/egl/libGLESv2_adreno.so
08-13 21:06:41.350 18861 18891 I AdrenoGLES-0: PFP: 0x016ee189, ME: 0x00000000
08-13 21:06:41.354 18861 18891 W AdrenoUtils: <ReadGpuID_from_sysfs:197>: Failed to open /sys/class/kgsl/kgsl-3d0/gpu_model
08-13 21:06:41.354 18861 18891 W AdrenoUtils: <ReadGpuID:221>: Failed to read chip ID from gpu_model. Fallback to use the GSL path
08-13 21:06:41.384   615   615 I hwservicemanager: getTransport: Cannot find entry android.hardware.graphics.mapper@4.0::IMapper/default in either framework or device manifest.
08-13 21:06:41.384 18861 18891 I Gralloc4: mapper 4.x is not supported
08-13 21:06:41.384   615   615 I hwservicemanager: getTransport: Cannot find entry android.hardware.graphics.mapper@3.0::IMapper/default in either framework or device manifest.
08-13 21:06:41.384 18861 18891 W Gralloc3: mapper 3.x is not supported
08-13 21:06:41.388 18861 18891 E libc    : Access denied finding property "vendor.gralloc.disable_ahardware_buffer"
08-13 21:06:42.462 18861 18886 I PatcherConfig: Deleting existing temporary files directory
08-13 21:06:42.465 18861 18886 I ResourceContext: Decoding app manifest

Patch logs

No response

Acknowledgements

Axelen123 commented 1 month ago

Thanks for finding this. The best way to solve this would probably be to ask the user to grant the permission before allowing the user to patch anything.

Ushie commented 1 month ago

That seems to be a weird fix, because it doesn't fix the problem, the patching process is unnecessarily triggered after the permission is granted, even though the out.apk is still available to use

oSumAtrIX commented 1 month ago

I am speculating it's caused by the activity being "restarted"

kitadai31 commented 1 month ago

It turned out that some devices force stop the app completely when asking the permission. This record is from OPPO A73 (Android 11).

https://github.com/user-attachments/assets/1c615718-88e4-4aa1-bda6-9054cfc4899f

When the first dialog (For your security, ...) appeared, the app was killed.

There is no other way than asking the install permission before starts patching.