Advertisement
MollyRealized

Untitled

Apr 26th, 2025 (edited)
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # MAY TOGGLE THE FEATURE OFF SYSTEM-WIDE:
  2.  
  3. # adb shell device_config put app_hibernation app_hibernation_enabled false
  4. # adb shell device_config set_sync_disabled_for_tests persistent
  5. # adb shell settings put global auto_revoke_permissions_if_unused 0
  6.  
  7. # 2nd script
  8. # TOGGLES 'MANAGE APP IF UNUSED' OPTION OFF FOR EVERY APP:
  9. # (PowerShell)
  10.  
  11. $packages = adb shell "pm list packages -3" | ForEach-Object { $_.Trim() }
  12. foreach ($pkg in $packages) {
  13.     if ($pkg -match "package:(.+)") {
  14.         $packageName = $Matches[1]
  15.         adb shell "appops set $packageName AUTO_REVOKE_PERMISSIONS_IF_UNUSED ignore"
  16.     }
  17. }
  18.  
  19. # 3rd script
  20. # RESTORATION OF LOST PRIVILEGES - CAUTION: THIS PROGRAMATICALLY GIVES AN APP EVERY PRIVILEGE IT IS ASKING FOR:
  21. # (also PowerShell)
  22. # Function to get an app's requested permissions
  23.  
  24. function Get-AppPermissions {
  25.     param (
  26.         [string]$packageName
  27.     )
  28.  
  29.     # Get the runtime permissions for the app - focus on permissions with granted=false
  30.     $permissions = adb shell dumpsys package $packageName |
  31.                   Select-String -Pattern "android\.permission\.[A-Z_]+:.*granted=(false|true)" -AllMatches |
  32.                   ForEach-Object { $_.Matches } |
  33.                   ForEach-Object {
  34.                       if ($_.Value -match "(android\.permission\.[A-Z_]+)") {
  35.                           $Matches[1]
  36.                       }
  37.                   } |
  38.                   Sort-Object -Unique
  39.  
  40.     return $permissions
  41. }
  42.  
  43. # List of permissions to exclude (non-changeable or not relevant for granting)
  44. $excludedPermissions = @(
  45.     "android.permission.FOREGROUND_SERVICE",
  46.     "android.permission.INTERNET",
  47.     "android.permission.ACCESS_NETWORK_STATE",
  48.     "android.permission.WAKE_LOCK",
  49.     "android.permission.RECEIVE_BOOT_COMPLETED",
  50.     "android.permission.VIBRATE",
  51.     "android.permission.BLUETOOTH",
  52.     "android.permission.READ_APP_BADGE"
  53. )
  54.  
  55. # Get all third-party packages
  56. $packages = adb shell "pm list packages -3" | ForEach-Object {
  57.     if ($_ -match "package:(.+)") {
  58.         $Matches[1]
  59.     }
  60. }
  61.  
  62. $successCount = 0
  63. $failCount = 0
  64.  
  65. # For each package, get its permissions and try to grant them
  66. foreach ($package in $packages) {
  67.     Write-Host "Processing package: $package" -ForegroundColor Cyan
  68.  
  69.     # Get permissions for this package
  70.     $permissions = Get-AppPermissions -packageName $package
  71.  
  72.     if ($permissions.Count -eq 0) {
  73.         Write-Host "  No permissions found for $package" -ForegroundColor Yellow
  74.         continue
  75.     }
  76.  
  77.     # Filter out excluded permissions
  78.     $filteredPermissions = $permissions | Where-Object { $excludedPermissions -notcontains $_ }
  79.  
  80.     Write-Host "  Found $($filteredPermissions.Count) grantable permissions"
  81.  
  82.     # Try to grant each permission
  83.     foreach ($permission in $filteredPermissions) {
  84.         # Try to grant the permission, but don't display errors
  85.         $result = adb shell "pm grant $package $permission 2>&1"
  86.  
  87.         # Check if the grant was successful
  88.         if ($result -match "Exception") {
  89.             # Do nothing for failures - they're too common and noisy
  90.             $failCount++
  91.         } else {
  92.             Write-Host "  Granted: $permission" -ForegroundColor Green
  93.             $successCount++
  94.         }
  95.     }
  96.  
  97.     # Set AUTO_REVOKE_PERMISSIONS_IF_UNUSED to ignore
  98.     adb shell "appops set $package AUTO_REVOKE_PERMISSIONS_IF_UNUSED ignore" | Out-Null
  99. }
  100.  
  101. Write-Host "`nPermissions Summary:" -ForegroundColor Cyan
  102. Write-Host "  Successfully granted: $successCount" -ForegroundColor Green
  103. Write-Host "  Failed to grant: $failCount" -ForegroundColor Yellow
  104. Write-Host "All packages processed." -ForegroundColor Cyan
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement