Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # MAY TOGGLE THE FEATURE OFF SYSTEM-WIDE:
- # adb shell device_config put app_hibernation app_hibernation_enabled false
- # adb shell device_config set_sync_disabled_for_tests persistent
- # adb shell settings put global auto_revoke_permissions_if_unused 0
- # 2nd script
- # TOGGLES 'MANAGE APP IF UNUSED' OPTION OFF FOR EVERY APP:
- # (PowerShell)
- $packages = adb shell "pm list packages -3" | ForEach-Object { $_.Trim() }
- foreach ($pkg in $packages) {
- if ($pkg -match "package:(.+)") {
- $packageName = $Matches[1]
- adb shell "appops set $packageName AUTO_REVOKE_PERMISSIONS_IF_UNUSED ignore"
- }
- }
- # 3rd script
- # RESTORATION OF LOST PRIVILEGES - CAUTION: THIS PROGRAMATICALLY GIVES AN APP EVERY PRIVILEGE IT IS ASKING FOR:
- # (also PowerShell)
- # Function to get an app's requested permissions
- function Get-AppPermissions {
- param (
- [string]$packageName
- )
- # Get the runtime permissions for the app - focus on permissions with granted=false
- $permissions = adb shell dumpsys package $packageName |
- Select-String -Pattern "android\.permission\.[A-Z_]+:.*granted=(false|true)" -AllMatches |
- ForEach-Object { $_.Matches } |
- ForEach-Object {
- if ($_.Value -match "(android\.permission\.[A-Z_]+)") {
- $Matches[1]
- }
- } |
- Sort-Object -Unique
- return $permissions
- }
- # List of permissions to exclude (non-changeable or not relevant for granting)
- $excludedPermissions = @(
- "android.permission.FOREGROUND_SERVICE",
- "android.permission.INTERNET",
- "android.permission.ACCESS_NETWORK_STATE",
- "android.permission.WAKE_LOCK",
- "android.permission.RECEIVE_BOOT_COMPLETED",
- "android.permission.VIBRATE",
- "android.permission.BLUETOOTH",
- "android.permission.READ_APP_BADGE"
- )
- # Get all third-party packages
- $packages = adb shell "pm list packages -3" | ForEach-Object {
- if ($_ -match "package:(.+)") {
- $Matches[1]
- }
- }
- $successCount = 0
- $failCount = 0
- # For each package, get its permissions and try to grant them
- foreach ($package in $packages) {
- Write-Host "Processing package: $package" -ForegroundColor Cyan
- # Get permissions for this package
- $permissions = Get-AppPermissions -packageName $package
- if ($permissions.Count -eq 0) {
- Write-Host " No permissions found for $package" -ForegroundColor Yellow
- continue
- }
- # Filter out excluded permissions
- $filteredPermissions = $permissions | Where-Object { $excludedPermissions -notcontains $_ }
- Write-Host " Found $($filteredPermissions.Count) grantable permissions"
- # Try to grant each permission
- foreach ($permission in $filteredPermissions) {
- # Try to grant the permission, but don't display errors
- $result = adb shell "pm grant $package $permission 2>&1"
- # Check if the grant was successful
- if ($result -match "Exception") {
- # Do nothing for failures - they're too common and noisy
- $failCount++
- } else {
- Write-Host " Granted: $permission" -ForegroundColor Green
- $successCount++
- }
- }
- # Set AUTO_REVOKE_PERMISSIONS_IF_UNUSED to ignore
- adb shell "appops set $package AUTO_REVOKE_PERMISSIONS_IF_UNUSED ignore" | Out-Null
- }
- Write-Host "`nPermissions Summary:" -ForegroundColor Cyan
- Write-Host " Successfully granted: $successCount" -ForegroundColor Green
- Write-Host " Failed to grant: $failCount" -ForegroundColor Yellow
- Write-Host "All packages processed." -ForegroundColor Cyan
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement