├── .cargo └── config ├── .github ├── ISSUE_TEMPLATE │ ├── add-new-package-s-.md │ ├── bug_report.md │ ├── debloat-issue-report.md │ ├── feature_request.md │ └── update-apps-description-or-recommendation.md ├── release.yml └── workflows │ ├── build_artifacts.yml │ ├── ci.yml │ └── release.yml ├── .gitignore ├── CHANGELOG.md ├── Cargo.lock ├── Cargo.toml ├── LICENSE ├── README.md ├── resources ├── assets │ ├── icons.json │ ├── icons.ttf │ └── uad_lists.json └── screenshots │ └── v0.5.0.png └── src ├── core ├── config.rs ├── mod.rs ├── save.rs ├── sync.rs ├── theme.rs ├── uad_lists.rs ├── update.rs └── utils.rs ├── gui ├── mod.rs ├── style.rs ├── views │ ├── about.rs │ ├── list.rs │ ├── mod.rs │ └── settings.rs └── widgets │ ├── mod.rs │ ├── modal.rs │ ├── navigation_menu.rs │ └── package_row.rs └── main.rs /.cargo/config: -------------------------------------------------------------------------------- 1 | [target.x86_64-pc-windows-msvc] 2 | rustflags = ["-C", "target-feature=+crt-static"] 3 | 4 | [target.x86_64-unknown-linux-gnu] 5 | linker = "clang" 6 | rustflags = ["-C", "link-arg=-fuse-ld=mold"] 7 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/add-new-package-s-.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Add new package(s) 3 | about: You want to add new apps in the debloat list 4 | title: "" 5 | labels: package::addition 6 | assignees: "" 7 | --- 8 | 9 | **Your phone model:** 10 | 11 | **Packages:** 12 | 13 | ``` 14 | com.this.is.a.bad.application 15 | com.this.is.another.bad.application 16 | ... 17 | ``` 18 | 19 | - [ ] **I removed all those packages on my phone** 20 | If not why. Leave the brackets blank and explain why. 21 | 22 | ## Document each package the best you can 23 | 24 | **List**: `Google`|`Misc`|`OEM` (manufacturer)|`AOSP`|`Pending`|`Carrier` (isp). 25 | 26 | **Removal**: `Recommended`, `Advanced`, `Expert` (this can break important features), 27 | or `Unsafe` (this can bootloop the phone or break extremely important features). 28 | 29 | ### \ 30 | 31 | **List**: \ 32 | **Removal**: \ 33 | 34 | > Description. Link to its Playstore page if it exists. 35 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: You have an issue with the UAD software itself 4 | title: "" 5 | labels: bug 6 | assignees: "" 7 | --- 8 | 9 | **Describe the bug** 10 | A clear and concise description of what the bug is. 11 | 12 | **Expected behavior** 13 | A clear and concise description of what you expected to happen. 14 | 15 | **You have a solution?** 16 | What to do to fix the issue. 17 | 18 | **UAD log** 19 | Upload the logfile generated by UAD. 20 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/debloat-issue-report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Debloat issue report 3 | about: Your phone has unexpected issues after debloating 4 | title: "" 5 | labels: package::breakage 6 | assignees: "" 7 | --- 8 | 9 | **Your phone model**: 10 | 11 | **Describe the issue** 12 | A clear and concise description of what the problem is. 13 | 14 | **You have a solution?** 15 | What to do to fix the issue. 16 | 17 | **UAD log** 18 | Upload the logfile generated by UAD. It would be difficult to help you without it. 19 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: You want a new feature 4 | title: "" 5 | labels: enhancement 6 | assignees: "" 7 | --- 8 | 9 | **Describe the feature you want** 10 | A clear description of what you want to happen. 11 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/update-apps-description-or-recommendation.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Update apps description or recommendation 3 | about: You want to improve/update a description/recommendation 4 | title: "" 5 | labels: package::documentation 6 | assignees: "" 7 | --- 8 | 9 | **Your phone model**: 10 | 11 | **Packages documentation to update:** 12 | 13 | ``` 14 | com.this.is.a.application 15 | com.this.is.another.application 16 | ... 17 | ``` 18 | 19 | ## Documentation Change 20 | 21 | **List**: `Google`|`Misc`|`OEM` (manufacturer)|`AOSP`|`Pending`|`Carrier` (isp). 22 | **Removal**: `Recommended`, `Advanced`, `Expert` (this can break important features), 23 | or `Unsafe` (this can bootloop the phone or break extremely important features). 24 | 25 | ### \ 26 | 27 | **List**: \ :arrow_right: \ 28 | **Removal**: \ 29 | :arrow_right: \ 30 | 31 | ### Current description 32 | 33 | > Current description 34 | 35 | ### Proposed description 36 | 37 | > Proposed description 38 | -------------------------------------------------------------------------------- /.github/release.yml: -------------------------------------------------------------------------------- 1 | changelog: 2 | exclude: 3 | labels: 4 | - package::documentation 5 | - package::addition 6 | - package::breakage 7 | - package::bootloop 8 | categories: 9 | - title: Added 10 | labels: 11 | - feature 12 | - title: Changed 13 | labels: 14 | - enhancement 15 | - title: Fixed 16 | labels: 17 | - bug 18 | -------------------------------------------------------------------------------- /.github/workflows/build_artifacts.yml: -------------------------------------------------------------------------------- 1 | name: Build artifacts 2 | on: 3 | workflow_dispatch: 4 | workflow_call: 5 | 6 | jobs: 7 | build: 8 | name: Building ${{ matrix.build_target }} [${{ matrix.graphics }}] [${{ matrix.update_feature }}] 9 | runs-on: ${{ matrix.os }} 10 | strategy: 11 | matrix: 12 | build_target: [linux, macos, windows] 13 | graphics: [glow, wgpu] 14 | update_feature: [self-update, no-self-update] 15 | exclude: 16 | - build_target: windows 17 | update_feature: no-self-update 18 | include: 19 | - build_target: linux 20 | os: ubuntu-latest 21 | - build_target: macos 22 | os: macos-latest 23 | - build_target: windows 24 | os: windows-latest 25 | - graphics: glow 26 | renderer: "-opengl" 27 | - graphics: wgpu 28 | renderer: "" # Vulkan but we don't want this in the binary filename 29 | - update_feature: self-update 30 | update_name: "" # we don't want this in the binary filename 31 | - update_feature: no-self-update 32 | update_name: "-noseflupdate" 33 | steps: 34 | - uses: actions/checkout@v3 35 | - uses: dtolnay/rust-toolchain@stable 36 | - uses: rui314/setup-mold@v1 # faster linker 37 | - uses: actions/cache@v3 38 | with: 39 | path: | 40 | ~/.cargo/bin/ 41 | ~/.cargo/registry/index/ 42 | ~/.cargo/registry/cache/ 43 | ~/.cargo/git/db/ 44 | target 45 | key: ${{ runner.os }}-release-${{ hashFiles('**/Cargo.lock') }} 46 | restore-keys: ${{ runner.OS }}-release- 47 | if: matrix.os == 'ubuntu-latest' 48 | - name: Building 49 | run: cargo build --release --no-default-features --features ${{ matrix.graphics }},${{ matrix.update_feature }} 50 | - name: Creating ./bin directory 51 | run: mkdir -p bin 52 | - name: Renaming binaries [Windows] 53 | if: matrix.os == 'windows-latest' 54 | run: mv target/release/uad_gui.exe bin/uad_gui-${{ matrix.build_target }}${{ matrix.renderer }}.exe 55 | - name: Renaming binaries [Others] 56 | if: matrix.os != 'windows-latest' 57 | run: mv target/release/uad_gui bin/uad_gui${{ matrix.update_name }}-${{ matrix.build_target }}${{ matrix.renderer }} 58 | - name: Tarball Linux/MacOS binary 59 | if: matrix.os != 'windows-latest' 60 | run: tar -czf bin/uad_gui${{ matrix.update_name }}-${{ matrix.build_target }}${{ matrix.renderer }}{.tar.gz,} 61 | - name: Upload artifacts 62 | uses: actions/upload-artifact@v3 63 | with: 64 | name: uad_gui${{ matrix.update_name }}-${{ matrix.build_target }}${{ matrix.renderer }} 65 | path: bin/uad_gui-* 66 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: Continuous Integration 2 | on: 3 | push: 4 | paths: 5 | - "**.rs" 6 | - "Cargo.lock" 7 | - "Cargo.toml" 8 | - "**.json" 9 | pull_request: 10 | paths: 11 | - "**.rs" 12 | - "Cargo.lock" 13 | - "Cargo.toml" 14 | - "**.json" 15 | 16 | jobs: 17 | lint: 18 | runs-on: ${{ matrix.os }} 19 | strategy: 20 | matrix: 21 | os: [ubuntu-latest, windows-latest, macOS-latest] 22 | lint: [check, test, clippy, fmt] 23 | exclude: # https://github.com/community/community/discussions/7835 24 | - os: windows-latest 25 | lint: clippy 26 | - os: windows-latest 27 | lint: fmt 28 | - os: macOS-latest 29 | lint: clippy 30 | - os: macOS-latest 31 | lint: fmt 32 | include: 33 | - lint: check 34 | args: " --all-features" 35 | - lint: test 36 | args: "" 37 | - lint: clippy 38 | args: " --all --all-features -- -D warnings" 39 | - lint: fmt 40 | args: " --all -- --check" 41 | steps: 42 | - uses: actions/checkout@v3 43 | - uses: rui314/setup-mold@v1 # faster linker 44 | - uses: actions/cache@v3 45 | with: 46 | path: | 47 | ~/.cargo/bin/ 48 | ~/.cargo/registry/index/ 49 | ~/.cargo/registry/cache/ 50 | ~/.cargo/git/db/ 51 | target 52 | key: ${{ runner.os }}-${{ matrix.lint }}-${{ hashFiles('**/Cargo.lock') }} 53 | restore-keys: ${{ runner.OS }}-${{ matrix.lint }}- 54 | - uses: dtolnay/rust-toolchain@stable 55 | with: 56 | components: clippy,rustfmt 57 | - run: cargo ${{ matrix.lint }}${{ matrix.args }} 58 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: Build and release 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | paths: 8 | - "**.rs" 9 | - "Cargo.lock" 10 | - "Cargo.toml" 11 | tags-ignore: 12 | - dev-build 13 | 14 | env: 15 | dev_tag: dev-build 16 | 17 | jobs: 18 | build: 19 | uses: ./.github/workflows/build_artifacts.yml 20 | release: 21 | runs-on: ubuntu-latest 22 | needs: build 23 | steps: 24 | - uses: actions/checkout@v3 25 | - name: Downloads artifacts 26 | uses: actions/download-artifact@v3 27 | with: 28 | path: bin 29 | - name: Create pre-release 30 | if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') 31 | uses: softprops/action-gh-release@v1 32 | with: 33 | body_path: ${{ github.workspace }}/CHANGELOG.md 34 | files: bin/*/uad_gui-* 35 | prerelease: true 36 | # - name: Update dev-build tag 37 | # if: ${{ github.event_name == 'push' }} 38 | # run: | 39 | # git tag -d ${{ env.dev_tag }} || true 40 | # git push origin :refs/tags/${{ env.dev_tag }} || true 41 | # git tag ${{ env.dev_tag }} 42 | # git push origin ${{ env.dev_tag }} 43 | # - name: Create dev-build release 44 | # if: ${{ github.event_name == 'push' }} 45 | # uses: softprops/action-gh-release@v1 46 | # with: 47 | # generate_release_notes: true 48 | # files: bin/*/uad_gui-* 49 | # prerelease: true 50 | # tag_name: ${{ env.dev_tag }} 51 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | debug/ 2 | target/ 3 | *.log 4 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to this project will be documented in this file. 4 | 5 | The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), 6 | and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). 7 | 8 | The sections should follow the order `Apps`, `Added`, `Changed`, `Fixed`, `Packaging` 9 | and `Removed`. 10 | 11 | ## [0.6] - Unreleased 12 | 13 | **WARNING: Settings specification has changed. Previous user settings will be erased**. 14 | 15 | ### Added 16 | - [[#374](https://github.com/0x192/universal-android-debloater/pull/374)] **Device-specific persistent configuration:** Some settings are now device-specific which means you can maintain different settings across several devices. 17 | 18 | - [[#447](https://github.com/0x192/universal-android-debloater/pull/447)] **Backup/Restore the state of a device:** Quick and easy way to save the state of all the system apps on a device and restore it. 19 | 20 | - [[#450](https://github.com/0x192/universal-android-debloater/pull/450)] **Warn the user when a work profile is detected:** Displays a warning message when switching to a work profile user and displays unavailable work profile users in the settings. 21 | 22 | ### Changed 23 | - [[#374](https://github.com/0x192/universal-android-debloater/pull/374)] ALL settings are now persistent. 24 | 25 | ### Fixed 26 | - [[#448](https://github.com/0x192/universal-android-debloater/pull/448)] UAD crash when interacting with work profiles on recent phones. 27 | 28 | ### Removed 29 | - The `Export current selection` button and the unintuitive auto import selection (see https://github.com/0x192/universal-android-debloater/issues/192) have been replaced by the new backup/restore system. 30 | 31 | ## [0.5.1] - 2022-07-03 32 | 33 | Since `0.5.0`, all changes related to apps are available to users without downloading a new version of UAD as the software directly download the json debloat list from Github. These changes can be tracked in commits with `[Pkg]` in their name. [See the commits](https://github.com/0x192/universal-android-debloater/commits/main) 34 | 35 | ### Added 36 | - [[#209](https://github.com/0x192/universal-android-debloater/issues/209)] Persistent highlighting when you click on a package 37 | 38 | ### Changed 39 | - `neededBy` and `dependencies` field can now list multiple packages (feature not visible in the UI yet) 40 | 41 | ### Fixed 42 | - [[#286](https://github.com/0x192/universal-android-debloater/issues/286)] UAD stuck on "Downloading UAD lists. Please wait" screen 43 | 44 | ## Packaging 45 | - [[#256](https://github.com/0x192/universal-android-debloater/issues/256)] Fixed typo in the release name of the noseflupdate variation 46 | - Bump dependencies 47 | 48 | ## [0.5.0] - 2022-04-03 49 | 50 | ### Apps 51 | 52 | - [[#115](https://github.com/0x192/universal-android-debloater/issues/115)] Added `com.tblenovo.lenovotips` to the recommended list. 53 | - [[#120](https://github.com/0x192/universal-android-debloater/pull/120)] Move Google keyboard to `Advanced` list (Default keyboards should not be in the `Recommended` list) 54 | - [[#169](https://github.com/0x192/universal-android-debloater/issues/154) Move `com.android.htmlviewer` to the `Expert` list. Removing it bootloop the device on MIUI 12.5.4+. 55 | 56 | Huge thanks to [@KarlRamstedt](https://github.com/KarlRamstedt) for their help in this major debloat list update: 57 | - [[#122](https://github.com/0x192/universal-android-debloater/pull/122)] Added a bunch of new packages 58 | - [[#122](https://github.com/0x192/universal-android-debloater/pull/122)] A lot of description updates and fixes 59 | - [[#122](https://github.com/0x192/universal-android-debloater/pull/122) | [#138](https://github.com/0x192/universal-android-debloater/pull/138)] Big revision of the recommendations according to more consistent criteria ([see the wiki](https://github.com/0x192/universal-android-debloater/wiki/FAQ#how-are-the-recommendations-chosen)) 60 | 61 | ### Added 62 | - [[#68](https://github.com/0x192/universal-android-debloater/issue/68)] **Unselect all button**: Let's you unselect all the packages you see on screen (i.e in the current filtered list). 63 | - [[#119](https://github.com/0x192/universal-android-debloater/issue/119)] **Reboot button**: Let's you quickly reboot the currently selected device. 64 | - [[#110](https://github.com/0x192/universal-android-debloater/pull/110)] **Remote `uad_lists.json` download**: The debloat list is now directly fetched from the main branch of this repo when you launch UAD. This means there is no longer the need to release a new version of UAD for updating the debloat lists! :rocket: 65 | - [[#121](https://github.com/0x192/universal-android-debloater/pull/121)] :arrows_counterclockwise: **UAD self-update**: UAD will now check at launch if there is a new version of itself and enable you to perform the update directly from the app! :rocket: 66 | 67 | ### Changed 68 | - [[#165](https://github.com/0x192/universal-android-debloater/issues/165)] UAD now tries every 500ms (for 1min) to initiate an ADB connection until a device is found during the `FindingPhones` loading state. 69 | - All the init process was reworked and a status message is displayed at each stage (`DownloadingList`, `FindingPhones`,`LoadingPackages`,`UpdatingUad` `Ready`) so you know what is happening. 70 | - Minor UI changes 71 | 72 | ### Packaging 73 | - Add a `no-self-update` build for MacOS and Linux. Useful if UAD is distributed into repositories. The update process will then be managed by a package manager. 74 | - MacOS builds are now also be released as a compressed tarball (like for Linux). You won't need to manually add the executable permission anymore. ([more info](https://github.com/actions/upload-artifact/issues/38)) 75 | - Bump dependencies 76 | 77 | 78 | ## [0.4.1] - 2022-01-31 79 | 80 | ### Fixed 81 | - Selection counter never decreasing. 82 | 83 | ## [0.4] - 2022-01-30 84 | 85 | ### Apps 86 | - [[#92](https://github.com/0x192/universal-android-debloater/pull/92)] Added 3 Fairphone packages + 7 Qualcomm packages (thanks [@VeH-c](https://github.com/VeH-c)) 87 | - [[#87](https://github.com/0x192/universal-android-debloater/pull/87)] Added 2 Unihertz packages (thanks [@rar0ch](https://github.com/rar0ch)) 88 | - [[#52](https://github.com/0x192/universal-android-debloater/issues/52)] Added `uk.co.ee.myee` to the debloat lists (thanks [@lawson58](https://github.com/lawson85)). 89 | - [[#58](https://github.com/0x192/universal-android-debloater/issues/52)] Added `android` to the debloat lists with the tag `Unsafe`. 90 | - Added 2 new Xiaomi packages to the `Recommended` list. 91 | - Multiple package description improvement (thanks [@jonas-ott](https://github.com/jonas-ott) and [@felurx](https://github.com/felurx) for the help) 92 | - Review of the package lists recommendations. The `Recommended` debloat list is now safer (less likely to remove something you'd want to keep). 93 | 94 | ### Added 95 | - [[#49](https://github.com/0x192/universal-android-debloater/issues/49)] Multi-device support: You are now able to select a device among the list of all ADB connected devices/emulators. 96 | - [[#44](https://github.com/0x192/universal-android-debloater/issues/44)] Persistent settings: Settings (only `theme` for now) are saved to a config file. Its location follows [the standards of the different OS](https://github.com/dirs-dev/dirs-rs#example). 97 | - Links to the Github page, wiki, github issues and logfiles in the `About` page. 98 | 99 | ### Changed 100 | - [[#65](https://github.com/0x192/universal-android-debloater/issues/65)] ADB commands now run in parallel and asynchronously! This means no more UI freeze when performing long/many actions! :rocket: 101 | - UI now updates itself in real time when performing ADB actions (thanks to async & multithreading). Before, it waited for the end of all actions. 102 | - Logfiles are now located in a more conventional place: [cache_dir](https://docs.rs/dirs/latest/dirs/). 103 | - Previous logs are no longer overwritten. The logger now only appends to the current logfile of the day (UAD_%Y%m%d.log). 104 | - Each new day the logger will create a new file on UAD launch. 105 | - [[#78](https://github.com/0x192/universal-android-debloater/issues/78)] Disable mode is now only available on Android 6+ because the disable ADB commands do not work without root on older devices. The setting will be greyed-out for those devices. 106 | - Minor light theme update 107 | 108 | 109 | ### Fixed 110 | - [[#50](https://github.com/0x192/universal-android-debloater/issues/50)] Resync button flipping theme back to `Lupin`. 111 | - [Regression ([048e7f](https://github.com/0x192/universal-android-debloater/commit/048e7fc8fd6d44b0e8ba933c289249366254a9cc))] Weird disabled/greyed action button with older devices (< Android 8.0). Package could be selected but no action was performed. 112 | - [[#78](https://github.com/0x192/universal-android-debloater/issues/78)] Packages not being actually uninstalled on older devices (< Android 6.0). Without root we can only use `pm block`/`pm unblock` for Android KitKit (4.4) and `pm hide`/`pm unhide` on Android Lollipop (5.x). 113 | 114 | ### Packaging 115 | - For Arch-based users, UAD is now available in the AUR: `universal-android-debloater-bin` (binary) and `universal-android-debloater` (from source) 116 | - Bump dependencies 117 | 118 | 119 | ## [0.3] - 2021-10-10 120 | 121 | ### Added 122 | - [[#16](https://github.com/0x192/universal-android-debloater/issues/16)] Multi-user support: You can now debloat/restore apps for any user of the phone (not only the primary user 0). 123 | - `Multi user mode` setting (default to `on` for Android 5+) allowing to remove packages for all users ([a work profile is another user](https://developer.android.com/work/managed-profiles)) instead of only the selected user. 124 | - User switcher (picklist). 125 | - [[#11](https://github.com/0x192/universal-android-debloater/issues/11)] New themes: light, dark and lupin. Lupin theme is now the new default theme. Themes can be changed from the settings. 126 | - [[#40](https://github.com/0x192/universal-android-debloater/issues/40)] Description field scrollbar: you can now scroll long descriptions. 127 | 128 | ### Fixed 129 | - [Regression] Unsafe packages can be deleted without enabling `expert mode`. 130 | - The refresh button doesn't update settings when a (new) phone is connected. 131 | - [Regression] Restore buttons are disabled when connecting an Android 8.0 phone. 132 | - [[#17](https://github.com/0x192/universal-android-debloater/issues/17)] Refresh icon does not appear. 133 | 134 | ## [0.2.2] - 2021-09-30 135 | 136 | ### Fixed 137 | - Crash when connecting a LG device (#33) 138 | 139 | ## [0.2.1] - 2021-09-28 140 | 141 | ### Added 142 | - Software version in the navigation panel 143 | 144 | ### Packaging 145 | - `wgpu` renderer is not the default renderer (you don't need to add `--features wgpu` if you want to build UAD with `wgpu`) 146 | 147 | ### Fixed 148 | - [[#35](https://github.com/0x192/universal-android-debloater/issues/35)] Exported selection not found 149 | 150 | ## [0.2] - 2021-09-26 151 | 152 | ### Added 153 | - [[#2](https://github.com/0x192/universal-android-debloater/issues/2)] UAD now comes with a logger. Debug information will be written to a `uad.log` file (Warning level log in *stdout*) 154 | - [[#15](https://github.com/0x192/universal-android-debloater/issues/15)] Support for older phone (< Android 8.0): 155 | - Disable mode in settings: clear and disable packages instead of uninstalling them (default for old phones because you can't restore uninstalled packages) 156 | - [[#8](https://github.com/0x192/universal-android-debloater/issues/8)] Export your selection in the `uad_exported_selection.txt` file. Packages from this file (if found in the current directory) will be automatically selected upon the start of UAD (or after a refresh). 157 | 158 | ### Changed 159 | - [[#25](https://github.com/0x192/universal-android-debloater/issues/25)] UAD will no longer crash at start if it doesn't find ADB but will display a useful error message 160 | - [[#3](https://github.com/0x192/universal-android-debloater/issues/3)] Better handling of ADB errors 161 | - Updated dependencies (compatibility with [Iced](https://github.com/iced-rs/iced) main branch latest commit) 162 | - Cleanup and refactoring of the code 163 | - Performance improvement 164 | - Various UI/UX improvement 165 | - The `Debloat/Restore selection` button has been split in 2 buttons: `removing` and `restoring` 166 | 167 | ### Packaging 168 | - Added an alternative build that uses [OpenGL](https://fr.wikipedia.org/wiki/OpenGL) (instead of [Vulkan](https://fr.wikipedia.org/wiki/Vulkan_(API))) for compatibility with older computers. If you encouter some visual glitches with the default Vulkan build you should try the OpenGL build. 169 | 170 | ### Fixed 171 | - Spelling mistake 172 | - Failed build with MSVC toolchain 173 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "uad_gui" 3 | description = "A cross-platform GUI debloater for android devices" 4 | version = "0.5.1" 5 | authors = ["w1nst0n"] 6 | license = "GPL-3.0" 7 | homepage = "https://github.com/0x192/universal-android-debloater" 8 | repository = "https://github.com/0x192/universal-android-debloater" 9 | readme = "README.md" 10 | keywords = ["debloater", "android", "adb", "privacy", "bloatware"] 11 | categories = ["gui"] 12 | edition = "2021" 13 | 14 | [features] 15 | default = ["wgpu", "self-update"] 16 | wgpu = [] # Iced/wgpu is default 17 | glow = ["iced/glow"] # OpenGL support 18 | self-update = ["flate2", "tar"] 19 | no-self-update = [] 20 | 21 | [dependencies] 22 | iced = { git = "https://github.com/iced-rs/iced.git" } 23 | iced_native = { git = "https://github.com/iced-rs/iced.git" } 24 | serde = { version = "^1.0", features = ["derive"] } 25 | serde_json = "^1.0" 26 | static_init = "^1.0" 27 | fern = { version = "^0", features = ["colored"] } 28 | chrono = { version = "^0.4", default-features = false, features = ["std", "clock"] } 29 | log = "^0.4" 30 | regex = "^1.5" 31 | toml = "^0" 32 | dirs = "^5.0.0" 33 | ureq = { version = "*", features = ["json"] } 34 | retry = { version = "^2.0.0" } 35 | 36 | [target.'cfg(not(target_os = "windows"))'.dependencies] 37 | flate2 = { version = "^1", optional = true } 38 | tar = { version = "^0.4", optional = true } 39 | 40 | [profile.release] 41 | opt-level = "s" 42 | lto = true 43 | strip = "symbols" 44 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | Universal Android Debloater GUI 635 | Copyright (C) 2021 W1nst0n 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Universal Android Debloater GUI Copyright (C) 2021 W1nst0n 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Universal Android Debloater GUI 2 | 3 | **DISCLAIMER**: Use at your own risk. I am not responsible for anything that 4 | could happen to your phone. 5 | 6 | uad_screenshot 7 | 8 | **This software is still in an early stage of development. Check out the issues, and feel free to contribute!** 9 | 10 | ## Summary 11 | 12 | This is a complete rewrite in Rust of the [UAD project](https://gitlab.com/W1nst0n/universal-android-debloater), 13 | which aims to improve privacy and battery performance by removing unnecessary 14 | and obscure system apps. 15 | This can also contribute to improve security by reducing [the attack surface](https://en.wikipedia.org/wiki/Attack_surface). 16 | 17 | Packages are as well documented as possible in order to provide a better 18 | understanding of what you can delete or not. The worst issue that could happen 19 | is removing an essential system package needed during boot causing then an unfortunate 20 | bootloop. After about 5 failed system boots, the phone will automatically reboot 21 | in recovery mode, and you'll have to perform a FACTORY RESET. Make a backup first! 22 | 23 | In any case, you **CANNOT** brick your device with this software! 24 | That's the main point, right? 25 | 26 | ## Features 27 | 28 | - [x] Uninstall/Disable and Restore/Enable system packages 29 | - [x] Multi-user support (e.g. apps in work profiles) 30 | - [x] Export/Import your selection in `uad_exported_selection.txt` 31 | - [x] Multi-device support: you can connect multiple phones at the same time 32 | - [x] All your actions are logged, so you never forget what you've done 33 | 34 | NB : System apps cannot truly be uninstalled without root (see the [FAQ](https://github.com/0x192/universal-android-debloater/wiki/FAQ)) 35 | 36 | ## Universal Debloat Lists 37 | 38 | - [x] GFAM (Google/Facebook/Amazon/Microsoft) 39 | - [x] AOSP 40 | - [x] Manufacturers (OEM) 41 | - [x] Mobile carriers 42 | - [x] Qualcomm / Mediatek / Miscellaneous 43 | 44 | ## Manufacturers debloat lists 45 | 46 | - [ ] Archos 47 | - [x] Asus 48 | - [ ] Blackberry 49 | - [ ] Gionee 50 | - [x] LG 51 | - [x] Google 52 | - [ ] iQOO 53 | - [x] Fairphone 54 | - [ ] HTC 55 | - [x] Huawei 56 | - [x] Motorola 57 | - [x] Nokia 58 | - [x] OnePlus 59 | - [x] Oppo 60 | - [x] Realme 61 | - [x] Samsung 62 | - [x] Sony 63 | - [x] Tecno 64 | - [ ] TCL 65 | - [x] Unihertz 66 | - [x] Vivo/iQOO 67 | - [ ] Wiko 68 | - [x] Xiaomi 69 | - [x] ZTE 70 | 71 | ## Mobile carriers debloat lists 72 | 73 | | Country | Carriers | 74 | | ------- | ------------------------------- | 75 | | France | Orange, SFR, Free, Bouygues | 76 | | USA | T-Mobile, Verizon, Sprint, AT&T | 77 | | Germany | Telekom | 78 | | UK | EE | 79 | 80 | ## How to use it 81 | 82 | - **Read the [FAQ](https://github.com/0x192/universal-android-debloater/wiki/FAQ)!** 83 | - **Do a proper backup of your data! You can never be too careful!** 84 | - Enable _Developer Options_ on your smartphone. 85 | - Turn on _USB Debugging_ from the developer panel. 86 | - From the settings, disconnect from any OEM accounts (when you delete an OEM 87 | account package it could lock you on the lockscreen because the phone can't 88 | associate your identity anymore) 89 | - Install ADB (see the intructions by clicking on your OS below): 90 |

91 |

92 | LINUX 93 | 94 | - Install _Android platform tools_ on your PC : 95 | 96 | Debian Base: 97 | 98 | ```bash 99 | sudo apt install android-sdk-platform-tools 100 | ``` 101 | 102 | Arch-Linux Base: 103 | 104 | ```bash 105 | sudo pacman -S android-tools 106 | ``` 107 | 108 | Red Hat Base: 109 | 110 | ```bash 111 | sudo yum install android-tools 112 | ``` 113 | 114 | OpenSUSE Base: 115 | 116 | ```bash 117 | sudo zypper install android-tools 118 | ``` 119 | 120 |
121 |

122 | 123 |

124 |

125 | MAC OS 126 | 127 | - Install [Homebrew](https://brew.sh/) 128 | - Install _Android platform tools_ 129 | 130 | ```bash 131 | brew install android-platform-tools 132 | ``` 133 | 134 |
135 |

136 | 137 |

138 |

139 | WINDOWS 140 | 141 | - Download [android platform tools](https://dl.google.com/android/repository/platform-tools-latest-windows.zip) 142 | and unzip it somewhere. 143 | - [Add the android platform tools to your PATH](https://www.architectryan.com/2018/03/17/add-to-the-path-on-windows-10/) 144 | **OR** make sure to launch UAD from the same directory. 145 | 146 | - [Install USB drivers for your device](https://developer.android.com/studio/run/oem-usb#Drivers) 147 | - Check your device is detected: 148 | 149 | ```bash 150 | adb devices 151 | ``` 152 | 153 |
154 |

155 | 156 | - Download the latest release of UAD GUI for your Operating System [here](https://github.com/0x192/universal-android-debloater/releases). 157 | Take the `opengl` version only if the default version (with a Vulkan backend) 158 | doesn't launch. 159 | 160 | **NOTE:** Chinese phones users may need to use the AOSP list for removing some stock 161 | apps because those Chinese manufacturers (especially Xiaomi and Huawei) have been 162 | using the name of AOSP packages for their own (modified & closed-source) apps. 163 | 164 | **IMPORTANT NOTE:** You will have to run this software whenever your OEM pushes 165 | an update to your phone as some _uninstalled_ system apps could be reinstalled. 166 | 167 | ## How to contribute 168 | 169 | Hey-hey-hey! Don't go away so fast! This is a community project. 170 | That means I need you! I'm sure you want to make this project better anyway. 171 | 172 | ==> [How to contribute](https://github.com/0x192/universal-android-debloater/wiki) 173 | 174 | ## Special thanks 175 | 176 | - [@mawilms](https://github.com/mawilms) for his LotRO plugin manager ([Lembas](https://github.com/mawilms/lembas)) 177 | which helped me a lot to understand how to use the [Iced](https://github.com/hecrj/iced) 178 | GUI library. 179 | - [@casperstorm](https://github.com/casperstorm) for the UI/UX inspiration. 180 | -------------------------------------------------------------------------------- /resources/assets/icons.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0x192/universal-android-debloater/11f27c671cba278d71296cdef4c5a5dba06add5e/resources/assets/icons.ttf -------------------------------------------------------------------------------- /resources/screenshots/v0.5.0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0x192/universal-android-debloater/11f27c671cba278d71296cdef4c5a5dba06add5e/resources/screenshots/v0.5.0.png -------------------------------------------------------------------------------- /src/core/config.rs: -------------------------------------------------------------------------------- 1 | use crate::core::sync::{get_android_sdk, User}; 2 | use crate::core::utils::DisplayablePath; 3 | use crate::gui::views::settings::Settings; 4 | use crate::CONFIG_DIR; 5 | use serde::{Deserialize, Serialize}; 6 | use static_init::dynamic; 7 | use std::fs; 8 | use std::path::PathBuf; 9 | 10 | #[derive(Default, Debug, Serialize, Deserialize, Clone)] 11 | pub struct Config { 12 | pub general: GeneralSettings, 13 | #[serde(skip_serializing_if = "Vec::is_empty", default = "Vec::new")] 14 | pub devices: Vec, 15 | } 16 | 17 | #[derive(Default, Debug, Serialize, Deserialize, Clone)] 18 | pub struct GeneralSettings { 19 | pub theme: String, 20 | pub expert_mode: bool, 21 | } 22 | 23 | #[derive(Default, Debug, Clone)] 24 | pub struct BackupSettings { 25 | pub backups: Vec, 26 | pub selected: Option, 27 | pub users: Vec, 28 | pub selected_user: Option, 29 | pub backup_state: String, 30 | } 31 | 32 | #[derive(Debug, Serialize, Deserialize, Clone)] 33 | pub struct DeviceSettings { 34 | pub device_id: String, 35 | pub disable_mode: bool, 36 | pub multi_user_mode: bool, 37 | #[serde(skip)] 38 | pub backup: BackupSettings, 39 | } 40 | 41 | impl Default for DeviceSettings { 42 | fn default() -> Self { 43 | Self { 44 | device_id: String::new(), 45 | multi_user_mode: get_android_sdk() > 21, 46 | disable_mode: false, 47 | backup: BackupSettings::default(), 48 | } 49 | } 50 | } 51 | 52 | #[dynamic] 53 | static CONFIG_FILE: PathBuf = CONFIG_DIR.join("config.toml"); 54 | 55 | impl Config { 56 | pub fn save_changes(settings: &Settings, device_id: &String) { 57 | let mut config = Self::load_configuration_file(); 58 | if let Some(device) = config 59 | .devices 60 | .iter_mut() 61 | .find(|x| x.device_id == *device_id) 62 | { 63 | *device = settings.device.clone(); 64 | } else { 65 | debug!("config: New device settings saved"); 66 | config.devices.push(settings.device.clone()); 67 | } 68 | config.general = settings.general.clone(); 69 | let toml = toml::to_string(&config).unwrap(); 70 | fs::write(&*CONFIG_FILE, toml).expect("Could not write config file to disk!"); 71 | } 72 | 73 | pub fn load_configuration_file() -> Self { 74 | match fs::read_to_string(&*CONFIG_FILE) { 75 | Ok(s) => match toml::from_str(&s) { 76 | Ok(config) => return config, 77 | Err(e) => error!("Invalid config file: `{}`", e), 78 | }, 79 | Err(e) => error!("Failed to read config file: `{}`", e), 80 | } 81 | error!("Restoring default config file"); 82 | let toml = toml::to_string(&Self::default()).unwrap(); 83 | fs::write(&*CONFIG_FILE, toml).expect("Could not write config file to disk!"); 84 | Self::default() 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /src/core/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod config; 2 | pub mod save; 3 | pub mod sync; 4 | pub mod theme; 5 | pub mod uad_lists; 6 | pub mod update; 7 | pub mod utils; 8 | -------------------------------------------------------------------------------- /src/core/save.rs: -------------------------------------------------------------------------------- 1 | use crate::core::config::DeviceSettings; 2 | use crate::core::sync::{apply_pkg_state_commands, CorePackage, Phone, User}; 3 | use crate::core::utils::DisplayablePath; 4 | use crate::gui::widgets::package_row::PackageRow; 5 | use crate::CACHE_DIR; 6 | use serde::{Deserialize, Serialize}; 7 | use static_init::dynamic; 8 | use std::fs; 9 | use std::path::{Path, PathBuf}; 10 | 11 | #[dynamic] 12 | pub static BACKUP_DIR: PathBuf = CACHE_DIR.join("backups"); 13 | 14 | #[derive(Default, Deserialize, Serialize, Debug, Clone, PartialEq, Eq)] 15 | struct PhoneBackup { 16 | device_id: String, 17 | users: Vec, 18 | } 19 | 20 | #[derive(Default, Deserialize, Serialize, Debug, Clone, PartialEq, Eq)] 21 | struct UserBackup { 22 | id: u16, 23 | packages: Vec, 24 | } 25 | 26 | // Backup all `Uninstalled` and `Disabled` packages 27 | pub async fn backup_phone( 28 | users: Vec, 29 | device_id: String, 30 | phone_packages: Vec>, 31 | ) -> Result<(), String> { 32 | let mut backup = PhoneBackup { 33 | device_id: device_id.clone(), 34 | ..PhoneBackup::default() 35 | }; 36 | 37 | for u in users { 38 | let mut user_backup = UserBackup { 39 | id: u.id, 40 | ..UserBackup::default() 41 | }; 42 | 43 | for p in phone_packages[u.index].clone() { 44 | user_backup.packages.push(CorePackage { 45 | name: p.name.clone(), 46 | state: p.state, 47 | }); 48 | } 49 | backup.users.push(user_backup); 50 | } 51 | 52 | match serde_json::to_string_pretty(&backup) { 53 | Ok(json) => { 54 | let backup_path = &*BACKUP_DIR.join(device_id); 55 | 56 | if let Err(e) = fs::create_dir_all(backup_path) { 57 | error!("BACKUP: could not create backup dir: {}", e); 58 | return Err(e.to_string()); 59 | }; 60 | 61 | let backup_filename = 62 | format!("{}.json", chrono::Local::now().format("%Y-%m-%d_%H-%M-%S")); 63 | 64 | match fs::write(backup_path.join(backup_filename), json) { 65 | Ok(_) => Ok(()), 66 | Err(err) => Err(err.to_string()), 67 | } 68 | } 69 | Err(err) => Err(err.to_string()), 70 | } 71 | } 72 | 73 | pub fn list_available_backups(dir: &Path) -> Vec { 74 | #[allow(clippy::option_if_let_else)] 75 | match fs::read_dir(dir) { 76 | Ok(files) => files 77 | .filter_map(|e| e.ok()) 78 | .map(|e| DisplayablePath { path: e.path() }) 79 | .collect::>(), 80 | Err(_) => vec![], 81 | } 82 | } 83 | 84 | pub fn list_available_backup_user(backup: DisplayablePath) -> Vec { 85 | match fs::read_to_string(backup.path) { 86 | Ok(data) => { 87 | let phone_backup: PhoneBackup = 88 | serde_json::from_str(&data).expect("Unable to parse backup file"); 89 | 90 | let mut users = vec![]; 91 | for u in phone_backup.users { 92 | users.push(User { 93 | id: u.id, 94 | index: 0, 95 | protected: false, 96 | }); 97 | } 98 | users 99 | } 100 | Err(e) => { 101 | error!("[BACKUP]: Selected backup file not found: {}", e); 102 | vec![] 103 | } 104 | } 105 | } 106 | 107 | #[derive(Debug)] 108 | pub struct BackupPackage { 109 | pub index: usize, 110 | pub commands: Vec, 111 | } 112 | 113 | pub fn restore_backup( 114 | selected_device: &Phone, 115 | packages: &[Vec], 116 | settings: &DeviceSettings, 117 | ) -> Result, String> { 118 | match fs::read_to_string( 119 | settings 120 | .backup 121 | .selected 122 | .as_ref() 123 | .ok_or("field should be Some type")? 124 | .path 125 | .clone(), 126 | ) { 127 | Ok(data) => { 128 | let phone_backup: PhoneBackup = 129 | serde_json::from_str(&data).expect("Unable to parse backup file"); 130 | 131 | let mut commands = vec![]; 132 | for u in phone_backup.users { 133 | let index = match selected_device.user_list.iter().find(|x| x.id == u.id) { 134 | Some(i) => i.index, 135 | None => return Err(format!("user {} doesn't exist", u.id)), 136 | }; 137 | 138 | for (i, backup_package) in u.packages.iter().enumerate() { 139 | let package: CorePackage; 140 | match packages[index] 141 | .iter() 142 | .find(|x| x.name == backup_package.name) 143 | { 144 | Some(p) => package = p.into(), 145 | None => { 146 | return Err(format!( 147 | "{} not found for user {}", 148 | backup_package.name, u.id 149 | )) 150 | } 151 | } 152 | let p_commands = apply_pkg_state_commands( 153 | &package, 154 | backup_package.state, 155 | &settings 156 | .backup 157 | .selected_user 158 | .ok_or("field should be Some type")?, 159 | selected_device, 160 | ); 161 | if !p_commands.is_empty() { 162 | commands.push(BackupPackage { 163 | index: i, 164 | commands: p_commands, 165 | }); 166 | } 167 | } 168 | } 169 | if !commands.is_empty() { 170 | commands.push(BackupPackage { 171 | index: 0, 172 | commands: vec![], 173 | }); 174 | } 175 | Ok(commands) 176 | } 177 | Err(e) => Err(e.to_string()), 178 | } 179 | } 180 | -------------------------------------------------------------------------------- /src/core/sync.rs: -------------------------------------------------------------------------------- 1 | use crate::core::uad_lists::PackageState; 2 | use crate::gui::views::list::PackageInfo; 3 | use crate::gui::widgets::package_row::PackageRow; 4 | use regex::Regex; 5 | use retry::{delay::Fixed, retry, OperationResult}; 6 | use serde::{Deserialize, Serialize}; 7 | use static_init::dynamic; 8 | use std::collections::HashSet; 9 | use std::env; 10 | use std::process::Command; 11 | 12 | #[cfg(target_os = "windows")] 13 | use std::os::windows::process::CommandExt; 14 | 15 | #[dynamic] 16 | static RE: Regex = Regex::new(r"\n(\S+)\s+device").unwrap(); 17 | 18 | #[derive(Debug, Clone, PartialEq, Eq)] 19 | pub struct Phone { 20 | pub model: String, 21 | pub android_sdk: u8, 22 | pub user_list: Vec, 23 | pub adb_id: String, 24 | } 25 | 26 | impl Default for Phone { 27 | fn default() -> Self { 28 | Self { 29 | model: "fetching devices...".to_string(), 30 | android_sdk: 0, 31 | user_list: vec![], 32 | adb_id: String::new(), 33 | } 34 | } 35 | } 36 | 37 | impl std::fmt::Display for Phone { 38 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 39 | write!(f, "{}", self.model) 40 | } 41 | } 42 | 43 | #[derive(Default, Debug, Clone, PartialEq, Eq, Copy)] 44 | pub struct User { 45 | pub id: u16, 46 | pub index: usize, 47 | pub protected: bool, 48 | } 49 | 50 | impl std::fmt::Display for User { 51 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 52 | write!(f, "user {}", self.id) 53 | } 54 | } 55 | 56 | pub fn adb_shell_command(shell: bool, args: &str) -> Result { 57 | let adb_command = if shell { 58 | vec!["shell", args] 59 | } else { 60 | vec![args] 61 | }; 62 | 63 | let mut command = Command::new("adb"); 64 | command.args(adb_command); 65 | 66 | #[cfg(target_os = "windows")] 67 | let command = command.creation_flags(0x08000000); // do not open a cmd window 68 | 69 | match command.output() { 70 | Err(e) => { 71 | error!("ADB: {}", e); 72 | Err("ADB was not found".to_string()) 73 | } 74 | Ok(o) => { 75 | if o.status.success() { 76 | Ok(String::from_utf8(o.stdout) 77 | .map_err(|e| e.to_string())? 78 | .trim_end() 79 | .to_string()) 80 | } else { 81 | let stdout = String::from_utf8(o.stdout) 82 | .map_err(|e| e.to_string())? 83 | .trim_end() 84 | .to_string(); 85 | let stderr = String::from_utf8(o.stderr) 86 | .map_err(|e| e.to_string())? 87 | .trim_end() 88 | .to_string(); 89 | 90 | // ADB does really weird things. Some errors are not redirected to stderr 91 | let err = if stdout.is_empty() { stderr } else { stdout }; 92 | Err(err) 93 | } 94 | } 95 | } 96 | } 97 | 98 | #[derive(Debug, Clone)] 99 | pub enum CommandType { 100 | PackageManager(PackageInfo), 101 | Shell, 102 | } 103 | pub async fn perform_adb_commands( 104 | action: String, 105 | command_type: CommandType, 106 | ) -> Result { 107 | let label = match command_type { 108 | CommandType::PackageManager(ref p) => p.removal.to_string(), 109 | CommandType::Shell => "Shell".to_string(), 110 | }; 111 | 112 | match adb_shell_command(true, &action) { 113 | Ok(o) => { 114 | // On old devices, adb commands can return the '0' exit code even if there 115 | // is an error. On Android 4.4, ADB doesn't check if the package exists. 116 | // It does not return any error if you try to `pm block` a non-existent package. 117 | // Some commands are even killed by ADB before finishing and UAD can't catch 118 | // the output. 119 | if ["Error", "Failure"].iter().any(|&e| o.contains(e)) { 120 | error!("[{}] {} -> {}", label, action, o); 121 | Err(()) 122 | } else { 123 | info!("[{}] {} -> {}", label, action, o); 124 | Ok(command_type) 125 | } 126 | } 127 | Err(err) => { 128 | if !err.contains("[not installed for") { 129 | error!("[{}] {} -> {}", label, action, err); 130 | } 131 | Err(()) 132 | } 133 | } 134 | } 135 | 136 | #[allow(clippy::option_if_let_else)] 137 | pub fn user_flag(user_id: Option<&User>) -> String { 138 | match user_id { 139 | Some(user_id) => format!(" --user {}", user_id.id), 140 | None => "".to_string(), 141 | } 142 | } 143 | 144 | pub fn list_all_system_packages(user_id: Option<&User>) -> String { 145 | let action = format!("pm list packages -s -u{}", user_flag(user_id)); 146 | 147 | adb_shell_command(true, &action) 148 | .unwrap_or_else(|_| String::new()) 149 | .replace("package:", "") 150 | } 151 | 152 | pub fn hashset_system_packages(state: PackageState, user_id: Option<&User>) -> HashSet { 153 | let user = user_flag(user_id); 154 | let action = match state { 155 | PackageState::Enabled => format!("pm list packages -s -e{user}"), 156 | PackageState::Disabled => format!("pm list package -s -d{user}"), 157 | _ => String::new(), // You probably don't need to use this function for anything else 158 | }; 159 | 160 | adb_shell_command(true, &action) 161 | .unwrap_or_default() 162 | .replace("package:", "") 163 | .lines() 164 | .map(String::from) 165 | .collect() 166 | } 167 | 168 | // Minimum information for processing adb commands 169 | #[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq)] 170 | pub struct CorePackage { 171 | pub name: String, 172 | pub state: PackageState, 173 | } 174 | 175 | impl From<&mut PackageRow> for CorePackage { 176 | fn from(pr: &mut PackageRow) -> Self { 177 | Self { 178 | name: pr.name.clone(), 179 | state: pr.state, 180 | } 181 | } 182 | } 183 | impl From for CorePackage { 184 | fn from(pr: PackageRow) -> Self { 185 | Self { 186 | name: pr.name.clone(), 187 | state: pr.state, 188 | } 189 | } 190 | } 191 | 192 | impl From<&PackageRow> for CorePackage { 193 | fn from(pr: &PackageRow) -> Self { 194 | Self { 195 | name: pr.name.clone(), 196 | state: pr.state, 197 | } 198 | } 199 | } 200 | 201 | pub fn apply_pkg_state_commands( 202 | package: &CorePackage, 203 | wanted_state: PackageState, 204 | selected_user: &User, 205 | phone: &Phone, 206 | ) -> Vec { 207 | // https://github.com/0x192/universal-android-debloater/wiki/ADB-reference 208 | // ALWAYS PUT THE COMMAND THAT CHANGES THE PACKAGE STATE FIRST! 209 | let commands = match wanted_state { 210 | PackageState::Enabled => { 211 | match package.state { 212 | PackageState::Disabled => match phone.android_sdk { 213 | i if i >= 23 => vec!["pm enable"], 214 | _ => vec!["pm enable"], 215 | }, 216 | PackageState::Uninstalled => match phone.android_sdk { 217 | i if i >= 23 => vec!["cmd package install-existing"], 218 | 21 | 22 => vec!["pm unhide"], 219 | 19 | 20 => vec!["pm unblock", "pm clear"], 220 | _ => vec![], // Impossible action already prevented by the GUI 221 | }, 222 | _ => vec![], 223 | } 224 | } 225 | PackageState::Disabled => match package.state { 226 | PackageState::Uninstalled | PackageState::Enabled => match phone.android_sdk { 227 | sdk if sdk >= 23 => vec!["pm disable-user", "am force-stop", "pm clear"], 228 | _ => vec![], 229 | }, 230 | _ => vec![], 231 | }, 232 | PackageState::Uninstalled => match package.state { 233 | PackageState::Enabled | PackageState::Disabled => match phone.android_sdk { 234 | sdk if sdk >= 23 => vec!["pm uninstall"], // > Android Marshmallow (6.0) 235 | 21 | 22 => vec!["pm hide", "pm clear"], // Android Lollipop (5.x) 236 | 19 | 20 => vec!["pm block", "pm clear"], // Android KitKat (4.4/4.4W) 237 | _ => vec!["pm uninstall"], // Disable mode is unavailable on older devices because the specific ADB commands need root 238 | }, 239 | _ => vec![], 240 | }, 241 | PackageState::All => vec![], 242 | }; 243 | if phone.android_sdk < 21 { 244 | request_builder(&commands, &package.name, None) 245 | } else { 246 | request_builder(&commands, &package.name, Some(selected_user)) 247 | } 248 | } 249 | 250 | pub fn request_builder(commands: &[&str], package: &str, user: Option<&User>) -> Vec { 251 | #[allow(clippy::option_if_let_else)] 252 | match user { 253 | Some(u) => commands 254 | .iter() 255 | .map(|c| format!("{} --user {} {}", c, u.id, package)) 256 | .collect(), 257 | None => commands.iter().map(|c| format!("{c} {package}")).collect(), 258 | } 259 | } 260 | 261 | pub fn get_phone_model() -> String { 262 | adb_shell_command(true, "getprop ro.product.model").unwrap_or_else(|err| { 263 | println!("ERROR: {err}"); 264 | if err.contains("adb: no devices/emulators found") { 265 | "no devices/emulators found".to_string() 266 | } else { 267 | err 268 | } 269 | }) 270 | } 271 | 272 | pub fn get_android_sdk() -> u8 { 273 | adb_shell_command(true, "getprop ro.build.version.sdk").map_or(0, |sdk| sdk.parse().unwrap()) 274 | } 275 | 276 | pub fn get_phone_brand() -> String { 277 | format!( 278 | "{} {}", 279 | adb_shell_command(true, "getprop ro.product.brand") 280 | .map(|s| s.trim().to_string()) 281 | .unwrap_or_default(), 282 | get_phone_model() 283 | ) 284 | } 285 | 286 | pub fn is_protected_user(user_id: &str) -> bool { 287 | adb_shell_command(true, &format!("pm list packages --user {user_id}")).is_err() 288 | } 289 | 290 | pub fn get_user_list() -> Vec { 291 | #[dynamic] 292 | static RE: Regex = Regex::new(r"\{([0-9]+)").unwrap(); 293 | adb_shell_command(true, "pm list users") 294 | .map(|users| { 295 | RE.find_iter(&users) 296 | .enumerate() 297 | .map(|(i, u)| User { 298 | id: u.as_str()[1..].parse().unwrap(), 299 | index: i, 300 | protected: is_protected_user(&u.as_str()[1..]), 301 | }) 302 | .collect() 303 | }) 304 | .unwrap_or_default() 305 | } 306 | 307 | // getprop ro.serialno 308 | pub async fn get_devices_list() -> Vec { 309 | retry( 310 | Fixed::from_millis(500).take(120), 311 | || match adb_shell_command(false, "devices") { 312 | Ok(devices) => { 313 | let mut device_list: Vec = vec![]; 314 | if !RE.is_match(&devices) { 315 | return OperationResult::Retry(vec![]); 316 | } 317 | for device in RE.captures_iter(&devices) { 318 | env::set_var("ANDROID_SERIAL", &device[1]); 319 | device_list.push(Phone { 320 | model: get_phone_brand(), 321 | android_sdk: get_android_sdk(), 322 | user_list: get_user_list(), 323 | adb_id: device[1].to_string(), 324 | }); 325 | } 326 | OperationResult::Ok(device_list) 327 | } 328 | Err(err) => { 329 | error!("get_device_list() -> {}", err); 330 | let test: Vec = vec![]; 331 | OperationResult::Retry(test) 332 | } 333 | }, 334 | ) 335 | .unwrap_or_default() 336 | } 337 | -------------------------------------------------------------------------------- /src/core/theme.rs: -------------------------------------------------------------------------------- 1 | use iced::{color, Color}; 2 | 3 | #[derive(Default, Debug, PartialEq, Eq, Copy, Clone)] 4 | pub enum Theme { 5 | #[default] 6 | Lupin, 7 | Dark, 8 | Light, 9 | } 10 | 11 | #[derive(Debug, Clone, Copy)] 12 | pub struct BaseColors { 13 | pub background: Color, 14 | pub foreground: Color, 15 | } 16 | 17 | #[derive(Debug, Clone, Copy)] 18 | pub struct NormalColors { 19 | pub primary: Color, 20 | pub secondary: Color, 21 | pub surface: Color, 22 | pub error: Color, 23 | } 24 | 25 | #[derive(Debug, Clone, Copy)] 26 | pub struct BrightColors { 27 | pub primary: Color, 28 | pub secondary: Color, 29 | pub surface: Color, 30 | pub error: Color, 31 | } 32 | 33 | #[derive(Debug, Clone, Copy)] 34 | pub struct ColorPalette { 35 | pub base: BaseColors, 36 | pub normal: NormalColors, 37 | pub bright: BrightColors, 38 | } 39 | 40 | impl Theme { 41 | pub const ALL: [Self; 3] = [Self::Lupin, Self::Dark, Self::Light]; 42 | pub fn palette(self) -> ColorPalette { 43 | match self { 44 | Self::Dark => ColorPalette { 45 | base: BaseColors { 46 | background: color!(0x111111), 47 | foreground: color!(0x1C1C1C), 48 | }, 49 | normal: NormalColors { 50 | primary: color!(0x5E4266), 51 | secondary: color!(0x386e50), 52 | surface: color!(0x828282), 53 | error: color!(0x992B2B), 54 | }, 55 | bright: BrightColors { 56 | primary: color!(0xBA84FC), 57 | secondary: color!(0x49eb7a), 58 | surface: color!(0xE0E0E0), 59 | error: color!(0xC13047), 60 | }, 61 | }, 62 | Self::Light => ColorPalette { 63 | base: BaseColors { 64 | background: color!(0xEEEEEE), 65 | foreground: color!(0xE0E0E0), 66 | }, 67 | normal: NormalColors { 68 | primary: color!(0x230F08), 69 | secondary: color!(0xF9D659), 70 | surface: color!(0x818181), 71 | error: color!(0x992B2B), 72 | }, 73 | bright: BrightColors { 74 | primary: color!(0x673AB7), 75 | secondary: color!(0x3797A4), 76 | surface: color!(0x000000), 77 | error: color!(0xC13047), 78 | }, 79 | }, 80 | Self::Lupin => ColorPalette { 81 | base: BaseColors { 82 | background: color!(0x282a36), 83 | foreground: color!(0x353746), 84 | }, 85 | normal: NormalColors { 86 | primary: color!(0x58406F), 87 | secondary: color!(0x386e50), 88 | surface: color!(0xa2a4a3), 89 | error: color!(0xA13034), 90 | }, 91 | bright: BrightColors { 92 | primary: color!(0xbd94f9), 93 | secondary: color!(0x49eb7a), 94 | surface: color!(0xf4f8f3), 95 | error: color!(0xE63E6D), 96 | }, 97 | }, 98 | } 99 | } 100 | } 101 | 102 | impl std::fmt::Display for Theme { 103 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 104 | write!( 105 | f, 106 | "{}", 107 | match self { 108 | Self::Dark => "Dark", 109 | Self::Light => "Light", 110 | Self::Lupin => "Lupin", 111 | } 112 | ) 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /src/core/uad_lists.rs: -------------------------------------------------------------------------------- 1 | use crate::core::utils::{format_diff_time_from_now, last_modified_date}; 2 | use crate::CACHE_DIR; 3 | use retry::{delay::Fixed, retry, OperationResult}; 4 | use serde::{Deserialize, Serialize}; 5 | use serde_json; 6 | use std::collections::HashMap; 7 | use std::fs; 8 | use std::path::{Path, PathBuf}; 9 | 10 | #[derive(Deserialize, Debug, Clone, PartialEq, Hash, Eq)] 11 | #[serde(rename_all = "camelCase")] 12 | pub struct Package { 13 | id: String, 14 | pub list: UadList, 15 | pub description: String, 16 | dependencies: Vec, 17 | needed_by: Vec, 18 | labels: Vec, 19 | pub removal: Removal, 20 | } 21 | 22 | #[derive(Default, Deserialize, Debug, Clone, Copy, PartialEq, Eq, Hash)] 23 | pub enum UadList { 24 | #[default] 25 | All, 26 | Aosp, 27 | Carrier, 28 | Google, 29 | Misc, 30 | Oem, 31 | Pending, 32 | Unlisted, 33 | } 34 | 35 | #[derive(Default, Debug, Clone, Copy, PartialEq, Eq)] 36 | pub enum UadListState { 37 | #[default] 38 | Downloading, 39 | Done, 40 | Failed, 41 | } 42 | 43 | impl std::fmt::Display for UadListState { 44 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 45 | let date = last_modified_date(CACHE_DIR.join("uad_lists.json")); 46 | let s = match self { 47 | Self::Downloading => "Checking updates...".to_string(), 48 | Self::Done => format!("Done (last was {})", format_diff_time_from_now(date)), 49 | Self::Failed => "Failed to check update!".to_string(), 50 | }; 51 | write!(f, "{s}") 52 | } 53 | } 54 | 55 | impl UadList { 56 | pub const ALL: [Self; 8] = [ 57 | Self::All, 58 | Self::Aosp, 59 | Self::Carrier, 60 | Self::Google, 61 | Self::Misc, 62 | Self::Oem, 63 | Self::Pending, 64 | Self::Unlisted, 65 | ]; 66 | } 67 | 68 | impl std::fmt::Display for UadList { 69 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 70 | write!( 71 | f, 72 | "{}", 73 | match self { 74 | Self::All => "All lists", 75 | Self::Aosp => "aosp", 76 | Self::Carrier => "carrier", 77 | Self::Google => "google", 78 | Self::Misc => "misc", 79 | Self::Oem => "oem", 80 | Self::Pending => "pending", 81 | Self::Unlisted => "unlisted", 82 | } 83 | ) 84 | } 85 | } 86 | 87 | #[derive(Default, Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] 88 | pub enum PackageState { 89 | All, 90 | #[default] 91 | Enabled, 92 | Uninstalled, 93 | Disabled, 94 | } 95 | 96 | impl PackageState { 97 | pub const ALL: [Self; 4] = [Self::All, Self::Enabled, Self::Uninstalled, Self::Disabled]; 98 | } 99 | 100 | impl std::fmt::Display for PackageState { 101 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 102 | write!( 103 | f, 104 | "{}", 105 | match self { 106 | Self::All => "All packages", 107 | Self::Enabled => "Enabled", 108 | Self::Uninstalled => "Uninstalled", 109 | Self::Disabled => "Disabled", 110 | } 111 | ) 112 | } 113 | } 114 | 115 | pub trait Opposite { 116 | fn opposite(&self, disable: bool) -> PackageState; 117 | } 118 | 119 | impl Opposite for PackageState { 120 | fn opposite(&self, disable: bool) -> Self { 121 | match self { 122 | Self::Enabled => { 123 | if disable { 124 | Self::Disabled 125 | } else { 126 | Self::Uninstalled 127 | } 128 | } 129 | Self::Uninstalled | Self::Disabled => Self::Enabled, 130 | Self::All => Self::All, 131 | } 132 | } 133 | } 134 | 135 | // Bad names. To be changed! 136 | #[derive(Default, Debug, Deserialize, Clone, Copy, PartialEq, Eq, Hash)] 137 | pub enum Removal { 138 | All, 139 | #[default] 140 | Recommended, 141 | Advanced, 142 | Expert, 143 | Unsafe, 144 | Unlisted, 145 | } 146 | 147 | impl Removal { 148 | pub const ALL: [Self; 6] = [ 149 | Self::All, 150 | Self::Recommended, 151 | Self::Advanced, 152 | Self::Expert, 153 | Self::Unsafe, 154 | Self::Unlisted, 155 | ]; 156 | } 157 | 158 | impl std::fmt::Display for Removal { 159 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 160 | write!( 161 | f, 162 | "{}", 163 | match self { 164 | Self::All => "All", 165 | Self::Recommended => "Recommended", 166 | Self::Advanced => "Advanced", 167 | Self::Expert => "Expert", 168 | Self::Unsafe => "Unsafe", 169 | Self::Unlisted => "Unlisted", 170 | } 171 | ) 172 | } 173 | } 174 | 175 | type PackageHashMap = HashMap; 176 | pub fn load_debloat_lists(remote: bool) -> (Result, bool) { 177 | let cached_uad_lists: PathBuf = CACHE_DIR.join("uad_lists.json"); 178 | let mut error = false; 179 | let list: Vec = if remote { 180 | retry(Fixed::from_millis(1000).take(60), || { 181 | match ureq::get( 182 | "https://raw.githubusercontent.com/0x192/universal-android-debloater/\ 183 | main/resources/assets/uad_lists.json", 184 | ) 185 | .call() 186 | { 187 | Ok(data) => { 188 | let text = data.into_string().expect("response should be Ok type"); 189 | fs::write(cached_uad_lists.clone(), &text).expect("Unable to write file"); 190 | let list = serde_json::from_str(&text).expect("Unable to parse"); 191 | OperationResult::Ok(list) 192 | } 193 | Err(e) => { 194 | warn!("Could not load remote debloat list: {}", e); 195 | error = true; 196 | OperationResult::Retry(Vec::::new()) 197 | } 198 | } 199 | }) 200 | .map_or_else(|_| get_local_lists(), |list| list) 201 | } else { 202 | warn!("Could not load remote debloat list"); 203 | get_local_lists() 204 | }; 205 | 206 | // TODO: Do it without intermediary Vec? 207 | let mut package_lists = HashMap::new(); 208 | for p in list { 209 | let name = p.id.clone(); 210 | package_lists.insert(name, p); 211 | } 212 | if error { 213 | (Err(package_lists), remote) 214 | } else { 215 | (Ok(package_lists), remote) 216 | } 217 | } 218 | 219 | fn get_local_lists() -> Vec { 220 | const DATA: &str = include_str!("../../resources/assets/uad_lists.json"); 221 | let cached_uad_lists = CACHE_DIR.join("uad_lists.json"); 222 | 223 | if Path::new(&cached_uad_lists).exists() { 224 | let data = fs::read_to_string(cached_uad_lists).unwrap(); 225 | serde_json::from_str(&data).expect("Unable to parse") 226 | } else { 227 | serde_json::from_str(DATA).expect("Unable to parse") 228 | } 229 | } 230 | 231 | #[cfg(test)] 232 | mod tests { 233 | use super::*; 234 | #[test] 235 | fn test_parse_json() { 236 | const DATA: &str = include_str!("../../resources/assets/uad_lists.json"); 237 | let _: Vec = serde_json::from_str(DATA).expect("Unable to parse"); 238 | } 239 | } 240 | -------------------------------------------------------------------------------- /src/core/update.rs: -------------------------------------------------------------------------------- 1 | use serde::Deserialize; 2 | 3 | #[cfg(feature = "self-update")] 4 | use { 5 | retry::{delay::Fibonacci, retry, OperationResult}, 6 | std::fs, 7 | std::io, 8 | std::io::copy, 9 | std::path::Path, 10 | std::path::PathBuf, 11 | }; 12 | 13 | #[derive(Debug, Deserialize, Clone)] 14 | pub struct Release { 15 | pub tag_name: String, 16 | pub assets: Vec, 17 | } 18 | 19 | #[derive(Debug, Deserialize, Clone)] 20 | pub struct ReleaseAsset { 21 | pub name: String, 22 | #[serde(rename = "browser_download_url")] 23 | pub download_url: String, 24 | } 25 | 26 | #[derive(Default, Debug, Clone)] 27 | pub struct SelfUpdateState { 28 | pub latest_release: Option, 29 | pub status: SelfUpdateStatus, 30 | } 31 | 32 | #[derive(Default, Debug, PartialEq, Eq, Clone)] 33 | pub enum SelfUpdateStatus { 34 | Updating, 35 | #[default] 36 | Checking, 37 | Done, 38 | Failed, 39 | } 40 | 41 | impl std::fmt::Display for SelfUpdateStatus { 42 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 43 | let s = match self { 44 | Self::Checking => "Checking updates...", 45 | Self::Updating => "Updating...", 46 | Self::Failed => "Failed to check update!", 47 | Self::Done => "Done", 48 | }; 49 | write!(f, "{s}") 50 | } 51 | } 52 | 53 | /// Download a file from the internet 54 | #[cfg(feature = "self-update")] 55 | pub async fn download_file(url: T, dest_file: PathBuf) -> Result<(), String> { 56 | let url = url.to_string(); 57 | debug!("downloading file from {}", &url); 58 | 59 | match ureq::get(&url).call() { 60 | Ok(res) => { 61 | let mut file = fs::File::create(dest_file).map_err(|e| e.to_string())?; 62 | 63 | if let Err(e) = copy(&mut res.into_reader(), &mut file) { 64 | return Err(e.to_string()); 65 | } 66 | } 67 | Err(e) => return Err(e.to_string()), 68 | } 69 | Ok(()) 70 | } 71 | 72 | /// Downloads the latest release file that matches `bin_name`, renames the current 73 | /// executable to a temp path, renames the new version as the original file name, 74 | /// then returns both the original file name (new version) and temp path (old version) 75 | #[cfg(feature = "self-update")] 76 | pub async fn download_update_to_temp_file( 77 | bin_name: String, 78 | release: Release, 79 | ) -> Result<(PathBuf, PathBuf), ()> { 80 | let current_bin_path = std::env::current_exe().map_err(|_| ())?; 81 | 82 | // Path to download the new version to 83 | let download_path = current_bin_path 84 | .parent() 85 | .ok_or(())? 86 | .join(format!("tmp_{bin_name}")); 87 | 88 | // Path to temporarily force rename current process to, se we can then 89 | // rename `download_path` to `current_bin_path` and then launch new version 90 | // cleanly as `current_bin_path` 91 | let tmp_path = current_bin_path 92 | .parent() 93 | .ok_or(())? 94 | .join(format!("tmp2_{bin_name}")); 95 | 96 | // MacOS and Linux release are gziped tarball 97 | #[cfg(not(target_os = "windows"))] 98 | { 99 | let asset_name = format!("{bin_name}.tar.gz"); 100 | 101 | let asset = release 102 | .assets 103 | .iter() 104 | .find(|a| a.name == asset_name) 105 | .cloned() 106 | .ok_or(())?; 107 | 108 | let archive_path = current_bin_path.parent().ok_or(())?.join(&asset_name); 109 | 110 | if let Err(e) = download_file(asset.download_url, archive_path.clone()).await { 111 | error!("Couldn't download UAD update: {}", e); 112 | return Err(()); 113 | } 114 | 115 | if extract_binary_from_tar(&archive_path, &download_path).is_err() { 116 | error!("Couldn't extract UAD release tarball"); 117 | return Err(()); 118 | } 119 | 120 | std::fs::remove_file(&archive_path).map_err(|_| ())?; 121 | } 122 | 123 | // For Windows we download the new binary directly 124 | #[cfg(target_os = "windows")] 125 | { 126 | let asset = release 127 | .assets 128 | .iter() 129 | .find(|a| a.name == bin_name) 130 | .cloned() 131 | .ok_or(())?; 132 | 133 | if let Err(e) = download_file(asset.download_url, download_path.clone()).await { 134 | error!("Couldn't download UAD update: {}", e); 135 | return Err(()); 136 | } 137 | } 138 | 139 | // Make the file executable 140 | #[cfg(not(target_os = "windows"))] 141 | { 142 | use std::os::unix::fs::PermissionsExt; 143 | 144 | let mut permissions = fs::metadata(&download_path).map_err(|_| ())?.permissions(); 145 | permissions.set_mode(0o755); 146 | if let Err(e) = fs::set_permissions(&download_path, permissions) { 147 | error!("[SelfUpdate] Couldn't set permission to temp file: {}", e); 148 | return Err(()); 149 | } 150 | } 151 | 152 | if let Err(e) = rename(¤t_bin_path, &tmp_path) { 153 | error!("[SelfUpdate] Couldn't rename binary path: {}", e); 154 | return Err(()); 155 | } 156 | if let Err(e) = rename(&download_path, ¤t_bin_path) { 157 | error!("[SelfUpdate] Couldn't rename binary path: {}", e); 158 | return Err(()); 159 | } 160 | 161 | Ok((current_bin_path, tmp_path)) 162 | } 163 | 164 | #[cfg(not(feature = "self-update"))] 165 | pub fn get_latest_release() -> Result, ()> { 166 | Ok(None) 167 | } 168 | 169 | // UAD only has pre-releases so we can't use 170 | // https://api.github.com/repos/0x192/universal-android-debloater/releases/latest 171 | // to only get the latest release 172 | #[cfg(feature = "self-update")] 173 | pub fn get_latest_release() -> Result, ()> { 174 | debug!("Checking for UAD update"); 175 | 176 | match ureq::get("https://api.github.com/repos/0x192/universal-android-debloater/releases") 177 | .call() 178 | { 179 | Ok(res) => { 180 | let release: Release = serde_json::from_value( 181 | res.into_json::() 182 | .map_err(|_| ())? 183 | .get(0) 184 | .ok_or(())? 185 | .clone(), 186 | ) 187 | .map_err(|_| ())?; 188 | if release.tag_name.as_str() != "dev-build" 189 | && release.tag_name.as_str() > env!("CARGO_PKG_VERSION") 190 | { 191 | Ok(Some(release)) 192 | } else { 193 | Ok(None) 194 | } 195 | } 196 | Err(_) => { 197 | debug!("Failed to check UAD update"); 198 | Err(()) 199 | } 200 | } 201 | } 202 | 203 | /// Extracts the binary from a `tar.gz` archive to `temp_file` path 204 | #[cfg(feature = "self-update")] 205 | #[cfg(not(target_os = "windows"))] 206 | pub fn extract_binary_from_tar(archive_path: &Path, temp_file: &Path) -> io::Result<()> { 207 | use flate2::read::GzDecoder; 208 | use std::fs::File; 209 | use tar::Archive; 210 | let mut archive = Archive::new(GzDecoder::new(File::open(archive_path)?)); 211 | 212 | let mut temp_file = File::create(temp_file)?; 213 | 214 | for file in archive.entries()? { 215 | let mut file = file?; 216 | 217 | let path = file.path()?; 218 | if path.to_str().is_some() { 219 | io::copy(&mut file, &mut temp_file)?; 220 | return Ok(()); 221 | } 222 | } 223 | Err(io::ErrorKind::NotFound.into()) 224 | } 225 | 226 | /// Hardcoded binary names for each compilation target 227 | /// that gets published to the Github Release 228 | #[cfg(feature = "self-update")] 229 | pub const fn bin_name() -> &'static str { 230 | #[cfg(target_os = "windows")] 231 | { 232 | "uad_gui.exe" 233 | } 234 | 235 | #[cfg(target_os = "macos")] 236 | { 237 | "uad_gui-macos" 238 | } 239 | 240 | #[cfg(not(any(target_os = "macos", target_os = "windows")))] 241 | { 242 | "uad_gui-linux" 243 | } 244 | } 245 | 246 | /// Rename a file or directory to a new name, retrying if the operation fails because of permissions 247 | /// 248 | /// Will retry for ~30 seconds with longer and longer delays between each, to allow for virus scan 249 | /// and other automated operations to complete. 250 | #[cfg(feature = "self-update")] 251 | pub fn rename(from: F, to: T) -> Result<(), String> 252 | where 253 | F: AsRef, 254 | T: AsRef, 255 | { 256 | // 21 Fibonacci steps starting at 1 ms is ~28 seconds total 257 | // See https://github.com/rust-lang/rustup/pull/1873 where this was used by Rustup to work around 258 | // virus scanning file locks 259 | let from = from.as_ref(); 260 | let to = to.as_ref(); 261 | 262 | retry(Fibonacci::from_millis(1).take(21), || { 263 | match fs::rename(from, to) { 264 | Ok(_) => OperationResult::Ok(()), 265 | Err(e) => match e.kind() { 266 | io::ErrorKind::PermissionDenied => OperationResult::Retry(e), 267 | _ => OperationResult::Err(e), 268 | }, 269 | } 270 | }) 271 | .map_err(|e| e.to_string()) 272 | } 273 | 274 | /// Remove a file, retrying if the operation fails because of permissions 275 | /// 276 | /// Will retry for ~30 seconds with longer and longer delays between each, to allow for virus scan 277 | /// and other automated operations to complete. 278 | #[cfg(feature = "self-update")] 279 | pub fn remove_file

(path: P) -> Result<(), String> 280 | where 281 | P: AsRef, 282 | { 283 | // 21 Fibonacci steps starting at 1 ms is ~28 seconds total 284 | // See https://github.com/rust-lang/rustup/pull/1873 where this was used by Rustup to work around 285 | // virus scanning file locks 286 | let path = path.as_ref(); 287 | 288 | retry( 289 | Fibonacci::from_millis(1).take(21), 290 | || match fs::remove_file(path) { 291 | Ok(_) => OperationResult::Ok(()), 292 | Err(e) => match e.kind() { 293 | io::ErrorKind::PermissionDenied => OperationResult::Retry(e), 294 | _ => OperationResult::Err(e), 295 | }, 296 | }, 297 | ) 298 | .map_err(|e| e.to_string()) 299 | } 300 | -------------------------------------------------------------------------------- /src/core/utils.rs: -------------------------------------------------------------------------------- 1 | use crate::core::sync::{hashset_system_packages, list_all_system_packages, User}; 2 | use crate::core::theme::Theme; 3 | use crate::core::uad_lists::{Package, PackageState, Removal, UadList}; 4 | use crate::gui::widgets::package_row::PackageRow; 5 | use chrono::offset::Utc; 6 | use chrono::DateTime; 7 | use std::collections::HashMap; 8 | use std::path::PathBuf; 9 | use std::process::Command; 10 | use std::{fmt, fs}; 11 | 12 | pub fn fetch_packages( 13 | uad_lists: &HashMap, 14 | user_id: Option<&User>, 15 | ) -> Vec { 16 | let all_system_packages = list_all_system_packages(user_id); // installed and uninstalled packages 17 | let enabled_system_packages = hashset_system_packages(PackageState::Enabled, user_id); 18 | let disabled_system_packages = hashset_system_packages(PackageState::Disabled, user_id); 19 | let mut description; 20 | let mut uad_list; 21 | let mut state; 22 | let mut removal; 23 | let mut user_package: Vec = Vec::new(); 24 | 25 | for p_name in all_system_packages.lines() { 26 | state = PackageState::Uninstalled; 27 | description = "[No description] : CONTRIBUTION WELCOMED"; 28 | uad_list = UadList::Unlisted; 29 | removal = Removal::Unlisted; 30 | 31 | if uad_lists.contains_key(p_name) { 32 | description = &uad_lists.get(p_name).unwrap().description; 33 | if description.is_empty() { 34 | description = "[No description] : CONTRIBUTION WELCOMED"; 35 | }; 36 | uad_list = uad_lists.get(p_name).unwrap().list; 37 | removal = uad_lists.get(p_name).unwrap().removal; 38 | } 39 | 40 | if enabled_system_packages.contains(p_name) { 41 | state = PackageState::Enabled; 42 | } else if disabled_system_packages.contains(p_name) { 43 | state = PackageState::Disabled; 44 | } 45 | 46 | let package_row = 47 | PackageRow::new(p_name, state, description, uad_list, removal, false, false); 48 | user_package.push(package_row); 49 | } 50 | user_package.sort_by(|a, b| a.name.to_lowercase().cmp(&b.name.to_lowercase())); 51 | user_package 52 | } 53 | 54 | pub fn string_to_theme(theme: &str) -> Theme { 55 | match theme { 56 | "Dark" => Theme::Dark, 57 | "Light" => Theme::Light, 58 | "Lupin" => Theme::Lupin, 59 | _ => Theme::Lupin, 60 | } 61 | } 62 | 63 | pub fn setup_uad_dir(dir: Option) -> PathBuf { 64 | let dir = dir.unwrap().join("uad"); 65 | fs::create_dir_all(&dir).expect("Can't create cache directory"); 66 | dir 67 | } 68 | 69 | pub fn open_url(dir: PathBuf) { 70 | #[cfg(target_os = "windows")] 71 | let output = Command::new("explorer").args([dir]).output(); 72 | 73 | #[cfg(target_os = "macos")] 74 | let output = Command::new("open").args([dir]).output(); 75 | 76 | #[cfg(not(any(target_os = "macos", target_os = "windows")))] 77 | let output = Command::new("xdg-open").args([dir]).output(); 78 | 79 | match output { 80 | Ok(o) => { 81 | if !o.status.success() { 82 | let stderr = String::from_utf8(o.stderr).unwrap().trim_end().to_string(); 83 | error!("Can't open the following URL: {}", stderr); 84 | } 85 | } 86 | Err(e) => error!("Failed to run command to open the file explorer: {}", e), 87 | } 88 | } 89 | 90 | #[rustfmt::skip] 91 | #[allow(clippy::option_if_let_else)] 92 | pub fn last_modified_date(file: PathBuf) -> DateTime { 93 | fs::metadata(file).map_or_else(|_| Utc::now(), |metadata| match metadata.modified() { 94 | Ok(time) => time.into(), 95 | Err(_) => Utc::now(), 96 | }) 97 | } 98 | 99 | pub fn format_diff_time_from_now(date: DateTime) -> String { 100 | let now: DateTime = Utc::now(); 101 | let last_update = now - date; 102 | if last_update.num_days() == 0 { 103 | if last_update.num_hours() == 0 { 104 | last_update.num_minutes().to_string() + " min(s) ago" 105 | } else { 106 | last_update.num_hours().to_string() + " hour(s) ago" 107 | } 108 | } else { 109 | last_update.num_days().to_string() + " day(s) ago" 110 | } 111 | } 112 | 113 | #[derive(Debug, Clone, PartialEq, Eq)] 114 | pub struct DisplayablePath { 115 | pub path: PathBuf, 116 | } 117 | 118 | impl fmt::Display for DisplayablePath { 119 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { 120 | let stem = self.path.file_stem().map_or_else( 121 | || { 122 | error!("[PATH STEM]: No file stem found"); 123 | "[File steam not found]".to_string() 124 | }, 125 | |p| match p.to_os_string().into_string() { 126 | Ok(stem) => stem, 127 | Err(e) => { 128 | error!("[PATH ENCODING]: {:?}", e); 129 | "[PATH ENCODING ERROR]".to_string() 130 | } 131 | }, 132 | ); 133 | 134 | write!(f, "{stem}") 135 | } 136 | } 137 | -------------------------------------------------------------------------------- /src/gui/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod style; 2 | pub mod views; 3 | pub mod widgets; 4 | 5 | use crate::core::sync::{get_devices_list, perform_adb_commands, CommandType, Phone}; 6 | use crate::core::theme::Theme; 7 | use crate::core::uad_lists::UadListState; 8 | use crate::core::update::{get_latest_release, Release, SelfUpdateState, SelfUpdateStatus}; 9 | use crate::core::utils::string_to_theme; 10 | 11 | use views::about::{About as AboutView, Message as AboutMessage}; 12 | use views::list::{List as AppsView, LoadingState as ListLoadingState, Message as AppsMessage}; 13 | use views::settings::{Message as SettingsMessage, Settings as SettingsView}; 14 | use widgets::navigation_menu::nav_menu; 15 | 16 | use iced::widget::column; 17 | use iced::{ 18 | window::Settings as Window, Alignment, Application, Command, Element, Length, Renderer, 19 | Settings, 20 | }; 21 | use std::{env, path::PathBuf}; 22 | 23 | #[cfg(feature = "self-update")] 24 | use crate::core::update::{bin_name, download_update_to_temp_file, remove_file}; 25 | 26 | #[derive(Default, Debug, Clone)] 27 | enum View { 28 | #[default] 29 | List, 30 | About, 31 | Settings, 32 | } 33 | 34 | #[derive(Default, Clone)] 35 | pub struct UpdateState { 36 | self_update: SelfUpdateState, 37 | uad_list: UadListState, 38 | } 39 | 40 | #[derive(Default, Clone)] 41 | pub struct UadGui { 42 | view: View, 43 | apps_view: AppsView, 44 | about_view: AboutView, 45 | settings_view: SettingsView, 46 | devices_list: Vec, 47 | selected_device: Option, // index of devices_list 48 | update_state: UpdateState, 49 | nb_running_async_adb_commands: u32, 50 | } 51 | 52 | #[derive(Debug, Clone)] 53 | pub enum Message { 54 | // Navigation Panel 55 | AboutPressed, 56 | SettingsPressed, 57 | AppsPress, 58 | DeviceSelected(Phone), 59 | AboutAction(AboutMessage), 60 | AppsAction(AppsMessage), 61 | SettingsAction(SettingsMessage), 62 | RefreshButtonPressed, 63 | RebootButtonPressed, 64 | LoadDevices(Vec), 65 | _NewReleaseDownloaded(Result<(PathBuf, PathBuf), ()>), 66 | GetLatestRelease(Result, ()>), 67 | Nothing, 68 | } 69 | 70 | impl Application for UadGui { 71 | type Theme = Theme; 72 | type Executor = iced::executor::Default; 73 | type Message = Message; 74 | type Flags = (); 75 | 76 | fn new(_flags: ()) -> (Self, Command) { 77 | ( 78 | Self::default(), 79 | Command::batch([ 80 | Command::perform(get_devices_list(), Message::LoadDevices), 81 | Command::perform( 82 | async move { get_latest_release() }, 83 | Message::GetLatestRelease, 84 | ), 85 | ]), 86 | ) 87 | } 88 | 89 | fn theme(&self) -> Theme { 90 | string_to_theme(&self.settings_view.general.theme) 91 | } 92 | 93 | fn title(&self) -> String { 94 | String::from("Universal Android Debloater") 95 | } 96 | fn update(&mut self, msg: Message) -> Command { 97 | match msg { 98 | #[allow(clippy::option_if_let_else)] 99 | Message::LoadDevices(devices_list) => { 100 | self.selected_device = match &self.selected_device { 101 | Some(s_device) => { 102 | // Try to reload last selected phone 103 | devices_list 104 | .iter() 105 | .find(|phone| phone.adb_id == s_device.adb_id) 106 | .cloned() 107 | } 108 | None => devices_list.first().cloned(), 109 | }; 110 | self.devices_list = devices_list; 111 | 112 | #[allow(unused_must_use)] 113 | { 114 | self.update(Message::SettingsAction(SettingsMessage::LoadDeviceSettings)); 115 | } 116 | 117 | self.update(Message::AppsAction(AppsMessage::LoadUadList(true))) 118 | } 119 | Message::AppsPress => { 120 | self.view = View::List; 121 | Command::none() 122 | } 123 | Message::AboutPressed => { 124 | self.view = View::About; 125 | self.update_state.self_update = SelfUpdateState::default(); 126 | Command::perform( 127 | async move { get_latest_release() }, 128 | Message::GetLatestRelease, 129 | ) 130 | } 131 | Message::SettingsPressed => { 132 | self.view = View::Settings; 133 | Command::none() 134 | } 135 | Message::RefreshButtonPressed => { 136 | self.apps_view = AppsView::default(); 137 | Command::perform(get_devices_list(), Message::LoadDevices) 138 | } 139 | Message::RebootButtonPressed => { 140 | self.apps_view = AppsView::default(); 141 | self.selected_device = None; 142 | self.devices_list = vec![]; 143 | Command::perform( 144 | perform_adb_commands("reboot".to_string(), CommandType::Shell), 145 | |_| Message::Nothing, 146 | ) 147 | } 148 | Message::AppsAction(msg) => self 149 | .apps_view 150 | .update( 151 | &mut self.settings_view, 152 | &mut self.selected_device.clone().unwrap_or_default(), 153 | &mut self.update_state.uad_list, 154 | msg, 155 | ) 156 | .map(Message::AppsAction), 157 | Message::SettingsAction(msg) => { 158 | match msg { 159 | SettingsMessage::RestoringDevice(ref output) => { 160 | self.nb_running_async_adb_commands -= 1; 161 | self.view = View::List; 162 | 163 | #[allow(unused_must_use)] 164 | { 165 | self.apps_view.update( 166 | &mut self.settings_view, 167 | &mut self.selected_device.clone().unwrap_or_default(), 168 | &mut self.update_state.uad_list, 169 | AppsMessage::RestoringDevice(output.clone()), 170 | ); 171 | } 172 | if self.nb_running_async_adb_commands == 0 { 173 | return self.update(Message::RefreshButtonPressed); 174 | } 175 | } 176 | SettingsMessage::MultiUserMode(toggled) => { 177 | if toggled { 178 | for user in self.apps_view.phone_packages.clone() { 179 | for (i, _) in 180 | user.iter().enumerate().filter(|&(_, pkg)| pkg.selected) 181 | { 182 | for u in self 183 | .selected_device 184 | .as_ref() 185 | .unwrap() 186 | .user_list 187 | .iter() 188 | .filter(|&u| !u.protected) 189 | { 190 | self.apps_view.phone_packages[u.index][i].selected = true; 191 | } 192 | } 193 | } 194 | } 195 | } 196 | _ => (), 197 | } 198 | self.settings_view 199 | .update( 200 | &self.selected_device.clone().unwrap_or_default(), 201 | &self.apps_view.phone_packages, 202 | &mut self.nb_running_async_adb_commands, 203 | msg, 204 | ) 205 | .map(Message::SettingsAction) 206 | } 207 | Message::AboutAction(msg) => { 208 | self.about_view.update(msg.clone()); 209 | 210 | match msg { 211 | AboutMessage::UpdateUadLists => { 212 | self.update_state.uad_list = UadListState::Downloading; 213 | self.apps_view.loading_state = 214 | ListLoadingState::DownloadingList(String::new()); 215 | self.update(Message::AppsAction(AppsMessage::LoadUadList(true))) 216 | } 217 | AboutMessage::DoSelfUpdate => { 218 | #[cfg(feature = "self-update")] 219 | if self.update_state.self_update.latest_release.is_some() { 220 | self.update_state.self_update.status = SelfUpdateStatus::Updating; 221 | self.apps_view.loading_state = 222 | ListLoadingState::_UpdatingUad(String::new()); 223 | let bin_name = bin_name().to_owned(); 224 | let release = self 225 | .update_state 226 | .self_update 227 | .latest_release 228 | .as_ref() 229 | .unwrap() 230 | .clone(); 231 | Command::perform( 232 | download_update_to_temp_file(bin_name, release), 233 | Message::_NewReleaseDownloaded, 234 | ) 235 | } else { 236 | Command::none() 237 | } 238 | #[cfg(not(feature = "self-update"))] 239 | Command::none() 240 | } 241 | AboutMessage::UrlPressed(_) => Command::none(), 242 | } 243 | } 244 | Message::DeviceSelected(s_device) => { 245 | self.selected_device = Some(s_device.clone()); 246 | self.view = View::List; 247 | env::set_var("ANDROID_SERIAL", s_device.adb_id); 248 | info!("{:-^65}", "-"); 249 | info!( 250 | "ANDROID_SDK: {} | DEVICE: {}", 251 | s_device.android_sdk, s_device.model 252 | ); 253 | info!("{:-^65}", "-"); 254 | self.apps_view.loading_state = ListLoadingState::FindingPhones(String::new()); 255 | 256 | #[allow(unused_must_use)] 257 | { 258 | self.update(Message::SettingsAction(SettingsMessage::LoadDeviceSettings)); 259 | } 260 | self.update(Message::AppsAction(AppsMessage::LoadPhonePackages(( 261 | self.apps_view.uad_lists.clone(), 262 | UadListState::Done, 263 | )))) 264 | } 265 | Message::_NewReleaseDownloaded(res) => { 266 | debug!("UAD update has been download!"); 267 | 268 | #[cfg(feature = "self-update")] 269 | if let Ok((relaunch_path, cleanup_path)) = res { 270 | // Remove first arg, which is path to binary. We don't use this first 271 | // arg as binary path because it's not reliable, per the docs. 272 | let mut args = std::env::args(); 273 | args.next(); 274 | let mut args: Vec<_> = args.collect(); 275 | 276 | // Remove the `--self-update-temp` arg from args if it exists, 277 | // since we need to pass it cleanly. Otherwise new process will 278 | // fail during arg parsing. 279 | if let Some(idx) = args.iter().position(|a| a == "--self-update-temp") { 280 | args.remove(idx); 281 | // Remove path passed after this arg 282 | args.remove(idx); 283 | } 284 | 285 | match std::process::Command::new(relaunch_path) 286 | .args(args) 287 | .arg("--self-update-temp") 288 | .arg(&cleanup_path) 289 | .spawn() 290 | { 291 | Ok(_) => { 292 | if let Err(e) = remove_file(cleanup_path) { 293 | error!("Could not remove temp update file: {}", e); 294 | } 295 | std::process::exit(0) 296 | } 297 | Err(error) => { 298 | if let Err(e) = remove_file(cleanup_path) { 299 | error!("Could not remove temp update file: {}", e); 300 | } 301 | error!("Failed to update UAD: {}", error); 302 | } 303 | } 304 | } else { 305 | error!("Failed to update UAD!"); 306 | } 307 | Command::none() 308 | } 309 | Message::GetLatestRelease(release) => { 310 | match release { 311 | Ok(r) => { 312 | self.update_state.self_update.status = SelfUpdateStatus::Done; 313 | self.update_state.self_update.latest_release = r; 314 | } 315 | Err(_) => self.update_state.self_update.status = SelfUpdateStatus::Failed, 316 | }; 317 | Command::none() 318 | } 319 | Message::Nothing => Command::none(), 320 | } 321 | } 322 | 323 | fn view(&self) -> Element> { 324 | let navigation_container = nav_menu( 325 | &self.devices_list, 326 | self.selected_device.clone(), 327 | &self.apps_view, 328 | &self.update_state.self_update, 329 | ); 330 | 331 | let selected_device = self.selected_device.clone().unwrap_or_default(); 332 | let main_container = match self.view { 333 | View::List => self 334 | .apps_view 335 | .view(&self.settings_view, &selected_device) 336 | .map(Message::AppsAction), 337 | View::About => self 338 | .about_view 339 | .view(&self.update_state) 340 | .map(Message::AboutAction), 341 | View::Settings => self 342 | .settings_view 343 | .view(&selected_device) 344 | .map(Message::SettingsAction), 345 | }; 346 | 347 | column![navigation_container, main_container] 348 | .width(Length::Fill) 349 | .align_items(Alignment::Center) 350 | .into() 351 | } 352 | } 353 | 354 | impl UadGui { 355 | pub fn start() -> iced::Result { 356 | Self::run(Settings { 357 | window: Window { 358 | size: (1050, 800), 359 | resizable: true, 360 | decorations: true, 361 | ..iced::window::Settings::default() 362 | }, 363 | default_text_size: 17.0, 364 | ..Settings::default() 365 | }) 366 | } 367 | } 368 | -------------------------------------------------------------------------------- /src/gui/style.rs: -------------------------------------------------------------------------------- 1 | use crate::core::theme::Theme; 2 | use iced::overlay::menu; 3 | use iced::widget::{ 4 | button, checkbox, container, pick_list, radio, rule, scrollable, text, text_input, 5 | }; 6 | use iced::{application, Background, Color}; 7 | 8 | #[derive(Default, Debug, Clone, Copy)] 9 | pub enum Application { 10 | #[default] 11 | Default, 12 | } 13 | 14 | impl application::StyleSheet for Theme { 15 | type Style = Application; 16 | 17 | fn appearance(&self, _style: &Self::Style) -> application::Appearance { 18 | application::Appearance { 19 | background_color: self.palette().base.background, 20 | text_color: self.palette().bright.surface, 21 | } 22 | } 23 | } 24 | 25 | #[derive(Default, Debug, Clone, Copy)] 26 | pub enum Container { 27 | #[default] 28 | Invisible, 29 | Frame, 30 | BorderedFrame, 31 | Tooltip, 32 | Background, 33 | } 34 | 35 | impl container::StyleSheet for Theme { 36 | type Style = Container; 37 | 38 | fn appearance(&self, style: &Self::Style) -> container::Appearance { 39 | match style { 40 | Container::Invisible => container::Appearance::default(), 41 | Container::Frame => container::Appearance { 42 | background: Some(Background::Color(self.palette().base.foreground)), 43 | text_color: Some(self.palette().bright.surface), 44 | border_radius: 5.0, 45 | ..container::Appearance::default() 46 | }, 47 | Container::BorderedFrame => container::Appearance { 48 | background: Some(Background::Color(self.palette().base.foreground)), 49 | text_color: Some(self.palette().bright.surface), 50 | border_radius: 5.0, 51 | border_width: 1.0, 52 | border_color: self.palette().normal.error, 53 | }, 54 | Container::Tooltip => container::Appearance { 55 | background: Some(Background::Color(self.palette().base.foreground)), 56 | text_color: Some(self.palette().bright.surface), 57 | border_radius: 8.0, 58 | border_width: 1.0, 59 | border_color: self.palette().normal.primary, 60 | }, 61 | 62 | Container::Background => container::Appearance { 63 | background: Some(Background::Color(self.palette().base.background)), 64 | text_color: Some(self.palette().bright.surface), 65 | border_radius: 5.0, 66 | ..container::Appearance::default() 67 | }, 68 | } 69 | } 70 | } 71 | 72 | #[derive(Default, Debug, Clone, Copy, PartialEq, Eq)] 73 | pub enum Button { 74 | #[default] 75 | Primary, 76 | Unavailable, 77 | SelfUpdate, 78 | Refresh, 79 | UninstallPackage, 80 | RestorePackage, 81 | NormalPackage, 82 | SelectedPackage, 83 | } 84 | 85 | impl button::StyleSheet for Theme { 86 | type Style = Button; 87 | 88 | fn active(&self, style: &Self::Style) -> button::Appearance { 89 | let p = self.palette(); 90 | 91 | let appearance = button::Appearance { 92 | border_width: 1.0, 93 | border_radius: 2.0, 94 | ..button::Appearance::default() 95 | }; 96 | 97 | let active_appearance = |bg: Option, mc| button::Appearance { 98 | background: Some(Background::Color(bg.unwrap_or(p.base.foreground))), 99 | border_color: Color { a: 0.5, ..mc }, 100 | text_color: mc, 101 | ..appearance 102 | }; 103 | 104 | match style { 105 | Button::Primary | Button::SelfUpdate | Button::Refresh => { 106 | active_appearance(None, p.bright.primary) 107 | } 108 | Button::RestorePackage => active_appearance(None, p.bright.secondary), 109 | Button::NormalPackage => button::Appearance { 110 | background: Some(Background::Color(p.base.foreground)), 111 | text_color: p.bright.surface, 112 | border_radius: 5.0, 113 | border_width: 0.0, 114 | border_color: p.base.background, 115 | ..appearance 116 | }, 117 | Button::SelectedPackage => button::Appearance { 118 | background: Some(Background::Color(Color { 119 | a: 0.25, 120 | ..p.normal.primary 121 | })), 122 | text_color: p.bright.primary, 123 | border_radius: 5.0, 124 | border_width: 0.0, 125 | border_color: p.normal.primary, 126 | ..appearance 127 | }, 128 | Button::Unavailable | Button::UninstallPackage => { 129 | active_appearance(None, p.bright.error) 130 | } 131 | } 132 | } 133 | 134 | fn hovered(&self, style: &Self::Style) -> button::Appearance { 135 | let active = self.active(style); 136 | let p = self.palette(); 137 | 138 | let hover_appearance = |bg, tc: Option| button::Appearance { 139 | background: Some(Background::Color(Color { a: 0.25, ..bg })), 140 | text_color: tc.unwrap_or(bg), 141 | ..active 142 | }; 143 | 144 | match style { 145 | Button::Primary | Button::SelfUpdate | Button::Refresh => { 146 | hover_appearance(p.bright.primary, None) 147 | } 148 | Button::NormalPackage => hover_appearance(p.normal.primary, Some(p.bright.surface)), 149 | Button::SelectedPackage => hover_appearance(p.normal.primary, None), 150 | Button::RestorePackage => hover_appearance(p.bright.secondary, None), 151 | Button::Unavailable | Button::UninstallPackage => { 152 | hover_appearance(p.bright.error, None) 153 | } 154 | } 155 | } 156 | 157 | fn pressed(&self, style: &Self::Style) -> button::Appearance { 158 | self.active(style) 159 | } 160 | 161 | fn disabled(&self, style: &Self::Style) -> button::Appearance { 162 | let active = self.active(style); 163 | let p = self.palette(); 164 | 165 | let disabled_appearance = |bg, tc: Option| button::Appearance { 166 | background: Some(Background::Color(Color { a: 0.05, ..bg })), 167 | text_color: Color { 168 | a: 0.50, 169 | ..tc.unwrap_or(bg) 170 | }, 171 | ..active 172 | }; 173 | 174 | match style { 175 | Button::RestorePackage => disabled_appearance(p.normal.primary, Some(p.bright.primary)), 176 | Button::UninstallPackage => disabled_appearance(p.bright.error, None), 177 | Button::Primary => disabled_appearance(p.bright.primary, Some(p.bright.primary)), 178 | _ => active, 179 | } 180 | } 181 | } 182 | 183 | #[derive(Default, Debug, Clone, Copy)] 184 | pub enum Scrollable { 185 | #[default] 186 | Description, 187 | Packages, 188 | } 189 | 190 | impl scrollable::StyleSheet for Theme { 191 | type Style = Scrollable; 192 | 193 | fn active(&self, style: &Self::Style) -> scrollable::Scrollbar { 194 | let from_appearance = |c: Color| scrollable::Scrollbar { 195 | background: Some(Background::Color(Color::TRANSPARENT)), 196 | border_radius: 5.0, 197 | border_width: 0.0, 198 | border_color: Color::TRANSPARENT, 199 | scroller: scrollable::Scroller { 200 | color: c, 201 | border_radius: 5.0, 202 | border_width: 1.0, 203 | border_color: Color::TRANSPARENT, 204 | }, 205 | }; 206 | 207 | match style { 208 | Scrollable::Description => from_appearance(self.palette().normal.surface), 209 | Scrollable::Packages => from_appearance(self.palette().base.foreground), 210 | } 211 | } 212 | 213 | fn hovered(&self, style: &Self::Style, _mouse_over_scrollbar: bool) -> scrollable::Scrollbar { 214 | scrollable::Scrollbar { 215 | scroller: self.active(style).scroller, 216 | ..self.active(style) 217 | } 218 | } 219 | 220 | fn dragging(&self, style: &Self::Style) -> scrollable::Scrollbar { 221 | let hovered = self.hovered(style, true); 222 | scrollable::Scrollbar { 223 | scroller: hovered.scroller, 224 | ..hovered 225 | } 226 | } 227 | } 228 | 229 | #[derive(Default, Debug, Clone, Copy)] 230 | pub enum CheckBox { 231 | #[default] 232 | PackageEnabled, 233 | PackageDisabled, 234 | SettingsEnabled, 235 | SettingsDisabled, 236 | } 237 | 238 | impl checkbox::StyleSheet for Theme { 239 | type Style = CheckBox; 240 | 241 | fn active(&self, style: &Self::Style, _is_checked: bool) -> checkbox::Appearance { 242 | match style { 243 | CheckBox::PackageEnabled => checkbox::Appearance { 244 | background: Background::Color(self.palette().base.background), 245 | icon_color: self.palette().bright.primary, 246 | border_radius: 5.0, 247 | border_width: 1.0, 248 | border_color: self.palette().base.background, 249 | text_color: Some(self.palette().bright.surface), 250 | }, 251 | CheckBox::PackageDisabled => checkbox::Appearance { 252 | background: Background::Color(Color { 253 | a: 0.55, 254 | ..self.palette().base.background 255 | }), 256 | icon_color: self.palette().bright.primary, 257 | border_radius: 5.0, 258 | border_width: 1.0, 259 | border_color: self.palette().normal.primary, 260 | text_color: Some(self.palette().normal.primary), 261 | }, 262 | CheckBox::SettingsEnabled => checkbox::Appearance { 263 | background: Background::Color(self.palette().base.background), 264 | icon_color: self.palette().bright.primary, 265 | border_radius: 5.0, 266 | border_width: 1.0, 267 | border_color: self.palette().bright.primary, 268 | text_color: Some(self.palette().bright.surface), 269 | }, 270 | CheckBox::SettingsDisabled => checkbox::Appearance { 271 | background: Background::Color(self.palette().base.foreground), 272 | icon_color: self.palette().bright.primary, 273 | border_radius: 5.0, 274 | border_width: 1.0, 275 | border_color: self.palette().normal.primary, 276 | text_color: Some(self.palette().bright.surface), 277 | }, 278 | } 279 | } 280 | 281 | fn hovered(&self, style: &Self::Style, is_checked: bool) -> checkbox::Appearance { 282 | let from_appearance = || checkbox::Appearance { 283 | background: Background::Color(self.palette().base.foreground), 284 | icon_color: self.palette().bright.primary, 285 | border_radius: 5.0, 286 | border_width: 2.0, 287 | border_color: self.palette().bright.primary, 288 | text_color: Some(self.palette().bright.surface), 289 | }; 290 | 291 | match style { 292 | CheckBox::PackageEnabled | CheckBox::SettingsEnabled => from_appearance(), 293 | CheckBox::PackageDisabled | CheckBox::SettingsDisabled => { 294 | self.active(style, is_checked) 295 | } 296 | } 297 | } 298 | } 299 | 300 | #[derive(Default, Debug, Clone, Copy)] 301 | pub enum TextInput { 302 | #[default] 303 | Default, 304 | } 305 | 306 | impl text_input::StyleSheet for Theme { 307 | type Style = TextInput; 308 | 309 | fn active(&self, _style: &Self::Style) -> text_input::Appearance { 310 | text_input::Appearance { 311 | background: Background::Color(self.palette().base.foreground), 312 | border_radius: 5.0, 313 | border_width: 0.0, 314 | border_color: self.palette().base.foreground, 315 | } 316 | } 317 | 318 | fn focused(&self, _style: &Self::Style) -> text_input::Appearance { 319 | text_input::Appearance { 320 | background: Background::Color(self.palette().base.foreground), 321 | border_radius: 2.0, 322 | border_width: 1.0, 323 | border_color: Color { 324 | a: 0.5, 325 | ..self.palette().normal.primary 326 | }, 327 | } 328 | } 329 | 330 | fn placeholder_color(&self, _style: &Self::Style) -> Color { 331 | self.palette().normal.surface 332 | } 333 | 334 | fn value_color(&self, _style: &Self::Style) -> Color { 335 | self.palette().bright.primary 336 | } 337 | 338 | fn selection_color(&self, _style: &Self::Style) -> Color { 339 | self.palette().normal.primary 340 | } 341 | 342 | /// Produces the style of an hovered text input. 343 | fn hovered(&self, style: &Self::Style) -> text_input::Appearance { 344 | self.focused(style) 345 | } 346 | } 347 | 348 | #[derive(Default, Debug, Clone, Copy)] 349 | pub enum PickList { 350 | #[default] 351 | Default, 352 | } 353 | 354 | impl menu::StyleSheet for Theme { 355 | type Style = (); 356 | 357 | fn appearance(&self, _style: &Self::Style) -> menu::Appearance { 358 | let p = self.palette(); 359 | 360 | menu::Appearance { 361 | text_color: p.bright.surface, 362 | background: p.base.background.into(), 363 | border_width: 1.0, 364 | border_radius: 2.0, 365 | border_color: p.base.background, 366 | selected_text_color: p.bright.surface, 367 | selected_background: p.normal.primary.into(), 368 | } 369 | } 370 | } 371 | 372 | impl pick_list::StyleSheet for Theme { 373 | type Style = (); 374 | 375 | fn active(&self, _style: &()) -> pick_list::Appearance { 376 | pick_list::Appearance { 377 | text_color: self.palette().bright.surface, 378 | background: self.palette().base.background.into(), 379 | border_width: 1.0, 380 | border_color: Color { 381 | a: 0.5, 382 | ..self.palette().normal.primary 383 | }, 384 | border_radius: 2.0, 385 | handle_color: self.palette().bright.surface, 386 | placeholder_color: self.palette().bright.surface, 387 | } 388 | } 389 | 390 | fn hovered(&self, style: &()) -> pick_list::Appearance { 391 | let active = self.active(style); 392 | pick_list::Appearance { 393 | border_color: self.palette().normal.primary, 394 | ..active 395 | } 396 | } 397 | } 398 | 399 | #[derive(Default, Clone, Copy)] 400 | pub enum Text { 401 | #[default] 402 | Default, 403 | Ok, 404 | Danger, 405 | Commentary, 406 | Color(Color), 407 | } 408 | 409 | impl From for Text { 410 | fn from(color: Color) -> Self { 411 | Self::Color(color) 412 | } 413 | } 414 | 415 | impl text::StyleSheet for Theme { 416 | type Style = Text; 417 | 418 | fn appearance(&self, style: Self::Style) -> text::Appearance { 419 | match style { 420 | Text::Default => text::Appearance::default(), 421 | Text::Ok => text::Appearance { 422 | color: Some(self.palette().bright.secondary), 423 | }, 424 | Text::Danger => text::Appearance { 425 | color: Some(self.palette().bright.error), 426 | }, 427 | Text::Commentary => text::Appearance { 428 | color: Some(self.palette().normal.surface), 429 | }, 430 | Text::Color(c) => text::Appearance { color: Some(c) }, 431 | } 432 | } 433 | } 434 | 435 | impl radio::StyleSheet for Theme { 436 | type Style = (); 437 | 438 | fn active(&self, _style: &Self::Style, _is_selected: bool) -> radio::Appearance { 439 | radio::Appearance { 440 | background: Color::TRANSPARENT.into(), 441 | dot_color: self.palette().bright.primary, 442 | border_width: 1.0, 443 | border_color: self.palette().bright.primary, 444 | text_color: None, 445 | } 446 | } 447 | 448 | fn hovered(&self, style: &Self::Style, _is_selected: bool) -> radio::Appearance { 449 | let active = self.active(style, true); 450 | 451 | radio::Appearance { 452 | dot_color: self.palette().bright.primary, 453 | border_color: self.palette().bright.primary, 454 | border_width: 2.0, 455 | ..active 456 | } 457 | } 458 | } 459 | 460 | #[derive(Default, Clone, Copy)] 461 | pub enum Rule { 462 | #[default] 463 | Default, 464 | } 465 | 466 | impl rule::StyleSheet for Theme { 467 | type Style = Rule; 468 | 469 | fn appearance(&self, style: &Self::Style) -> rule::Appearance { 470 | match style { 471 | Rule::Default => rule::Appearance { 472 | color: self.palette().bright.surface, 473 | width: 2, 474 | radius: 2.0, 475 | fill_mode: rule::FillMode::Full, 476 | }, 477 | } 478 | } 479 | } 480 | -------------------------------------------------------------------------------- /src/gui/views/about.rs: -------------------------------------------------------------------------------- 1 | use crate::core::theme::Theme; 2 | use crate::core::utils::{last_modified_date, open_url}; 3 | use crate::gui::{style, UpdateState}; 4 | use crate::CACHE_DIR; 5 | use iced::widget::{button, column, container, row, text, Space}; 6 | use iced::{Alignment, Element, Length, Renderer}; 7 | use std::path::PathBuf; 8 | 9 | #[cfg(feature = "self-update")] 10 | use crate::core::update::SelfUpdateStatus; 11 | 12 | #[derive(Default, Debug, Clone)] 13 | pub struct About {} 14 | 15 | #[derive(Debug, Clone)] 16 | pub enum Message { 17 | UrlPressed(PathBuf), 18 | UpdateUadLists, 19 | DoSelfUpdate, 20 | } 21 | 22 | impl About { 23 | pub fn update(&mut self, msg: Message) { 24 | if let Message::UrlPressed(url) = msg { 25 | open_url(url); 26 | } 27 | // other events are handled by UadGui update() 28 | } 29 | pub fn view(&self, update_state: &UpdateState) -> Element> { 30 | let about_text = text( 31 | "Universal Android Debloater (UAD) is a Free and Open-Source community project aiming at simplifying \ 32 | the removal of pre-installed apps on any Android device.", 33 | ); 34 | 35 | let descr_container = container(about_text) 36 | .width(Length::Fill) 37 | .padding(25) 38 | .style(style::Container::Frame); 39 | 40 | let date = last_modified_date(CACHE_DIR.join("uad_lists.json")); 41 | let uad_list_text = text(format!("Documentation: v{}", date.format("%Y%m%d"))).width(250); 42 | let last_update_text = text(update_state.uad_list.to_string()); 43 | let uad_lists_btn = button("Update") 44 | .on_press(Message::UpdateUadLists) 45 | .padding(5) 46 | .style(style::Button::Primary); 47 | 48 | #[cfg(feature = "self-update")] 49 | let self_update_btn = button("Update") 50 | .on_press(Message::DoSelfUpdate) 51 | .padding(5) 52 | .style(style::Button::Primary); 53 | 54 | #[cfg(feature = "self-update")] 55 | let uad_version_text = 56 | text(format!("UAD version: v{}", env!("CARGO_PKG_VERSION"))).width(250); 57 | 58 | #[cfg(feature = "self-update")] 59 | #[rustfmt::skip] 60 | let self_update_text = update_state.self_update.latest_release.as_ref().map_or_else(|| 61 | if update_state.self_update.status == SelfUpdateStatus::Done { 62 | "(No update available)".to_string() 63 | } else { 64 | update_state.self_update.status.to_string() 65 | }, |r| if update_state.self_update.status == SelfUpdateStatus::Updating { 66 | update_state.self_update.status.to_string() 67 | } else { 68 | format!("(v{} available)", r.tag_name) 69 | }); 70 | 71 | #[cfg(feature = "self-update")] 72 | let last_self_update_text = text(self_update_text).style(style::Text::Default); 73 | 74 | #[cfg(feature = "self-update")] 75 | let self_update_row = row![uad_version_text, self_update_btn, last_self_update_text,] 76 | .align_items(Alignment::Center) 77 | .spacing(10) 78 | .width(550); 79 | 80 | let uad_list_row = row![uad_list_text, uad_lists_btn, last_update_text,] 81 | .align_items(Alignment::Center) 82 | .spacing(10) 83 | .width(550); 84 | 85 | #[cfg(feature = "self-update")] 86 | let update_column = column![uad_list_row, self_update_row] 87 | .align_items(Alignment::Center) 88 | .spacing(10); 89 | 90 | #[cfg(not(feature = "self-update"))] 91 | let update_column = column![uad_list_row] 92 | .align_items(Alignment::Center) 93 | .spacing(10); 94 | 95 | let update_container = container(update_column) 96 | .width(Length::Fill) 97 | .center_x() 98 | .padding(10) 99 | .style(style::Container::Frame); 100 | 101 | let website_btn = button("Github page") 102 | .on_press(Message::UrlPressed(PathBuf::from( 103 | "https://github.com/0x192/universal-android-debloater", 104 | ))) 105 | .padding(5) 106 | .style(style::Button::Primary); 107 | 108 | let issue_btn = button("Have an issue?") 109 | .on_press(Message::UrlPressed(PathBuf::from( 110 | "https://github.com/0x192/universal-android-debloater/issues", 111 | ))) 112 | .padding(5) 113 | .style(style::Button::Primary); 114 | 115 | let log_btn = button("Locate the logfiles") 116 | .on_press(Message::UrlPressed(CACHE_DIR.to_path_buf())) 117 | .padding(5) 118 | .style(style::Button::Primary); 119 | 120 | let wiki_btn = button("Wiki") 121 | .on_press(Message::UrlPressed(PathBuf::from( 122 | "https://github.com/0x192/universal-android-debloater/wiki", 123 | ))) 124 | .padding(5) 125 | .style(style::Button::Primary); 126 | 127 | let row = row![website_btn, wiki_btn, issue_btn, log_btn,].spacing(20); 128 | 129 | let content = column![ 130 | Space::new(Length::Fill, Length::Shrink), 131 | descr_container, 132 | update_container, 133 | row, 134 | ] 135 | .width(Length::Fill) 136 | .spacing(20) 137 | .align_items(Alignment::Center); 138 | 139 | container(content) 140 | .width(Length::Fill) 141 | .height(Length::Fill) 142 | .padding(10) 143 | .into() 144 | } 145 | } 146 | -------------------------------------------------------------------------------- /src/gui/views/list.rs: -------------------------------------------------------------------------------- 1 | use crate::core::config::DeviceSettings; 2 | use crate::core::sync::{apply_pkg_state_commands, perform_adb_commands, CommandType, Phone, User}; 3 | use crate::core::theme::Theme; 4 | use crate::core::uad_lists::{ 5 | load_debloat_lists, Opposite, Package, PackageState, Removal, UadList, UadListState, 6 | }; 7 | use crate::core::utils::fetch_packages; 8 | use crate::gui::style; 9 | use crate::gui::widgets::navigation_menu::ICONS; 10 | use std::collections::HashMap; 11 | use std::env; 12 | 13 | use crate::gui::views::settings::Settings; 14 | use crate::gui::widgets::modal::Modal; 15 | use crate::gui::widgets::package_row::{Message as RowMessage, PackageRow}; 16 | use iced::widget::{ 17 | button, column, container, horizontal_space, pick_list, radio, row, scrollable, text, 18 | text_input, tooltip, vertical_rule, Space, 19 | }; 20 | use iced::{alignment, Alignment, Command, Element, Length, Renderer}; 21 | 22 | #[derive(Debug, Default, Clone)] 23 | pub struct PackageInfo { 24 | pub i_user: usize, 25 | pub index: usize, 26 | pub removal: String, 27 | } 28 | 29 | #[derive(Debug, Clone)] 30 | pub enum LoadingState { 31 | DownloadingList(String), 32 | FindingPhones(String), 33 | LoadingPackages(String), 34 | _UpdatingUad(String), 35 | Ready(String), 36 | RestoringDevice(String), 37 | } 38 | 39 | impl Default for LoadingState { 40 | fn default() -> Self { 41 | Self::FindingPhones(String::new()) 42 | } 43 | } 44 | 45 | #[derive(Default, Debug, Clone)] 46 | pub struct List { 47 | pub loading_state: LoadingState, 48 | pub uad_lists: HashMap, 49 | pub phone_packages: Vec>, // packages of all users of the phone 50 | filtered_packages: Vec, // phone_packages indexes of the selected user (= what you see on screen) 51 | selected_packages: Vec<(usize, usize)>, // Vec of (user_index, pkg_index) 52 | selected_package_state: Option, 53 | selected_removal: Option, 54 | selected_list: Option, 55 | selected_user: Option, 56 | pub input_value: String, 57 | description: String, 58 | selection_modal: bool, 59 | current_package_index: usize, 60 | } 61 | 62 | #[derive(Debug, Clone)] 63 | pub enum Message { 64 | LoadUadList(bool), 65 | LoadPhonePackages((HashMap, UadListState)), 66 | RestoringDevice(Result), 67 | ApplyFilters(Vec>), 68 | SearchInputChanged(String), 69 | ToggleAllSelected(bool), 70 | ListSelected(UadList), 71 | UserSelected(User), 72 | PackageStateSelected(PackageState), 73 | RemovalSelected(Removal), 74 | ApplyActionOnSelection, 75 | List(usize, RowMessage), 76 | ChangePackageState(Result), 77 | Nothing, 78 | ModalHide, 79 | ModalUserSelected(User), 80 | ModalValidate, 81 | } 82 | 83 | impl List { 84 | pub fn update( 85 | &mut self, 86 | settings: &mut Settings, 87 | selected_device: &mut Phone, 88 | list_update_state: &mut UadListState, 89 | message: Message, 90 | ) -> Command { 91 | let i_user = self.selected_user.unwrap_or_default().index; 92 | match message { 93 | Message::ModalHide => { 94 | self.selection_modal = false; 95 | Command::none() 96 | } 97 | Message::ModalValidate => { 98 | let mut commands = vec![]; 99 | self.selected_packages.sort_unstable(); 100 | self.selected_packages.dedup(); 101 | for selection in &self.selected_packages { 102 | commands.append(&mut build_action_pkg_commands( 103 | &self.phone_packages, 104 | selected_device, 105 | &settings.device, 106 | *selection, 107 | )); 108 | } 109 | self.selection_modal = false; 110 | Command::batch(commands) 111 | } 112 | Message::RestoringDevice(output) => { 113 | if let Ok(res) = output { 114 | if let CommandType::PackageManager(p) = res { 115 | self.loading_state = LoadingState::RestoringDevice( 116 | self.phone_packages[i_user][p.index].name.clone(), 117 | ); 118 | } 119 | } else { 120 | self.loading_state = LoadingState::RestoringDevice("Error [TODO]".to_string()); 121 | } 122 | Command::none() 123 | } 124 | Message::LoadUadList(remote) => { 125 | info!("{:-^65}", "-"); 126 | info!( 127 | "ANDROID_SDK: {} | DEVICE: {}", 128 | selected_device.android_sdk, selected_device.model 129 | ); 130 | info!("{:-^65}", "-"); 131 | self.loading_state = LoadingState::DownloadingList(String::new()); 132 | Command::perform( 133 | Self::init_apps_view(remote, selected_device.clone()), 134 | Message::LoadPhonePackages, 135 | ) 136 | } 137 | Message::LoadPhonePackages(list_box) => { 138 | let (uad_list, list_state) = list_box; 139 | self.loading_state = LoadingState::LoadingPackages(String::new()); 140 | self.uad_lists = uad_list.clone(); 141 | *list_update_state = list_state; 142 | Command::perform( 143 | Self::load_packages(uad_list, selected_device.user_list.clone()), 144 | Message::ApplyFilters, 145 | ) 146 | } 147 | Message::ApplyFilters(packages) => { 148 | self.phone_packages = packages; 149 | self.filtered_packages = (0..self.phone_packages[i_user].len()).collect(); 150 | self.selected_package_state = Some(PackageState::Enabled); 151 | self.selected_removal = Some(Removal::Recommended); 152 | self.selected_list = Some(UadList::All); 153 | self.selected_user = Some(User::default()); 154 | Self::filter_package_lists(self); 155 | self.loading_state = LoadingState::Ready(String::new()); 156 | Command::none() 157 | } 158 | Message::ToggleAllSelected(selected) => { 159 | #[allow(unused_must_use)] 160 | for i in self.filtered_packages.clone() { 161 | if self.phone_packages[i_user][i].selected != selected { 162 | self.update( 163 | settings, 164 | selected_device, 165 | list_update_state, 166 | Message::List(i, RowMessage::ToggleSelection(selected)), 167 | ); 168 | } 169 | } 170 | Command::none() 171 | } 172 | Message::SearchInputChanged(letter) => { 173 | self.input_value = letter; 174 | Self::filter_package_lists(self); 175 | Command::none() 176 | } 177 | Message::ListSelected(list) => { 178 | self.selected_list = Some(list); 179 | Self::filter_package_lists(self); 180 | Command::none() 181 | } 182 | Message::PackageStateSelected(package_state) => { 183 | self.selected_package_state = Some(package_state); 184 | Self::filter_package_lists(self); 185 | Command::none() 186 | } 187 | Message::RemovalSelected(removal) => { 188 | self.selected_removal = Some(removal); 189 | Self::filter_package_lists(self); 190 | Command::none() 191 | } 192 | Message::List(i_package, row_message) => { 193 | #[allow(unused_must_use)] 194 | { 195 | self.phone_packages[i_user][i_package] 196 | .update(&row_message) 197 | .map(move |row_message| Message::List(i_package, row_message)); 198 | } 199 | 200 | let package = &mut self.phone_packages[i_user][i_package]; 201 | 202 | match row_message { 203 | RowMessage::ToggleSelection(toggle) => { 204 | if package.removal == Removal::Unsafe && !settings.general.expert_mode { 205 | package.selected = false; 206 | return Command::none(); 207 | } 208 | 209 | if settings.device.multi_user_mode { 210 | for u in selected_device.user_list.iter().filter(|&u| !u.protected) { 211 | self.phone_packages[u.index][i_package].selected = toggle; 212 | if toggle { 213 | self.selected_packages.push((u.index, i_package)); 214 | } 215 | } 216 | if !toggle { 217 | self.selected_packages.retain(|&x| x.1 != i_package); 218 | } 219 | } else { 220 | package.selected = toggle; 221 | if toggle { 222 | self.selected_packages.push((i_user, i_package)); 223 | } else { 224 | self.selected_packages 225 | .retain(|&x| x.1 != i_package || x.0 != i_user); 226 | } 227 | } 228 | Command::none() 229 | } 230 | RowMessage::ActionPressed => { 231 | self.phone_packages[i_user][i_package].selected = true; 232 | Command::batch(build_action_pkg_commands( 233 | &self.phone_packages, 234 | selected_device, 235 | &settings.device, 236 | (i_user, i_package), 237 | )) 238 | } 239 | RowMessage::PackagePressed => { 240 | self.description = package.clone().description; 241 | package.current = true; 242 | if self.current_package_index != i_package { 243 | self.phone_packages[i_user][self.current_package_index].current = false; 244 | } 245 | self.current_package_index = i_package; 246 | Command::none() 247 | } 248 | } 249 | } 250 | Message::ApplyActionOnSelection => { 251 | self.selection_modal = true; 252 | Command::none() 253 | } 254 | Message::UserSelected(user) => { 255 | self.selected_user = Some(user); 256 | self.filtered_packages = (0..self.phone_packages[user.index].len()).collect(); 257 | Self::filter_package_lists(self); 258 | Command::none() 259 | } 260 | Message::ChangePackageState(res) => { 261 | if let Ok(CommandType::PackageManager(p)) = res { 262 | let package = &mut self.phone_packages[p.i_user][p.index]; 263 | package.state = package.state.opposite(settings.device.disable_mode); 264 | package.selected = false; 265 | self.selected_packages 266 | .retain(|&x| x.1 != p.index && x.0 != p.i_user); 267 | Self::filter_package_lists(self); 268 | } 269 | Command::none() 270 | } 271 | Message::ModalUserSelected(user) => { 272 | self.selected_user = Some(user); 273 | self.update( 274 | settings, 275 | selected_device, 276 | list_update_state, 277 | Message::UserSelected(user), 278 | ) 279 | } 280 | Message::Nothing => Command::none(), 281 | } 282 | } 283 | 284 | pub fn view( 285 | &self, 286 | settings: &Settings, 287 | selected_device: &Phone, 288 | ) -> Element> { 289 | match &self.loading_state { 290 | LoadingState::DownloadingList(_) => { 291 | let text = "Downloading latest UAD lists from Github. Please wait..."; 292 | waiting_view(settings, text, true) 293 | } 294 | LoadingState::FindingPhones(_) => { 295 | let text = "Finding connected devices..."; 296 | waiting_view(settings, text, false) 297 | } 298 | LoadingState::LoadingPackages(_) => { 299 | let text = "Pulling packages from the device. Please wait..."; 300 | waiting_view(settings, text, false) 301 | } 302 | LoadingState::_UpdatingUad(_) => { 303 | let text = "Updating UAD. Please wait..."; 304 | waiting_view(settings, text, false) 305 | } 306 | LoadingState::RestoringDevice(output) => { 307 | let text = format!("Restoring device: {output}"); 308 | waiting_view(settings, &text, false) 309 | } 310 | LoadingState::Ready(_) => { 311 | let search_packages = text_input( 312 | "Search packages...", 313 | &self.input_value, 314 | Message::SearchInputChanged, 315 | ) 316 | .padding(5); 317 | 318 | let user_picklist = pick_list( 319 | selected_device.user_list.clone(), 320 | self.selected_user, 321 | Message::UserSelected, 322 | ) 323 | .width(85); 324 | 325 | let divider = Space::new(Length::Fill, Length::Shrink); 326 | 327 | let list_picklist = 328 | pick_list(&UadList::ALL[..], self.selected_list, Message::ListSelected); 329 | let package_state_picklist = pick_list( 330 | &PackageState::ALL[..], 331 | self.selected_package_state, 332 | Message::PackageStateSelected, 333 | ); 334 | 335 | let removal_picklist = pick_list( 336 | &Removal::ALL[..], 337 | self.selected_removal, 338 | Message::RemovalSelected, 339 | ); 340 | 341 | let control_panel = row![ 342 | search_packages, 343 | user_picklist, 344 | divider, 345 | removal_picklist, 346 | package_state_picklist, 347 | list_picklist, 348 | ] 349 | .width(Length::Fill) 350 | .align_items(Alignment::Center) 351 | .spacing(10) 352 | .padding([0, 16, 0, 0]); 353 | 354 | let packages = 355 | self.filtered_packages 356 | .iter() 357 | .fold(column![].spacing(6), |col, i| { 358 | col.push( 359 | self.phone_packages[self.selected_user.unwrap().index][*i] 360 | .view(settings, selected_device) 361 | .map(move |msg| Message::List(*i, msg)), 362 | ) 363 | }); 364 | 365 | let packages_scrollable = scrollable(packages) 366 | .height(Length::FillPortion(6)) 367 | .style(style::Scrollable::Packages); 368 | 369 | let description_scroll = scrollable(text(&self.description).width(Length::Fill)) 370 | .style(style::Scrollable::Description); 371 | 372 | let description_panel = container(description_scroll) 373 | .padding(6) 374 | .height(Length::FillPortion(2)) 375 | .width(Length::Fill) 376 | .style(style::Container::Frame); 377 | 378 | let review_selection = if !self.selected_packages.is_empty() { 379 | button(text(format!( 380 | "Review selection ({})", 381 | self.selected_packages.len() 382 | ))) 383 | .on_press(Message::ApplyActionOnSelection) 384 | .padding(5) 385 | .style(style::Button::Primary) 386 | } else { 387 | button(text(format!( 388 | "Review selection ({})", 389 | self.selected_packages.len() 390 | ))) 391 | .padding(5) 392 | }; 393 | 394 | let select_all_btn = button("Select all") 395 | .padding(5) 396 | .on_press(Message::ToggleAllSelected(true)) 397 | .style(style::Button::Primary); 398 | 399 | let unselect_all_btn = button("Unselect all") 400 | .padding(5) 401 | .on_press(Message::ToggleAllSelected(false)) 402 | .style(style::Button::Primary); 403 | 404 | let action_row = row![ 405 | select_all_btn, 406 | unselect_all_btn, 407 | Space::new(Length::Fill, Length::Shrink), 408 | review_selection, 409 | ] 410 | .width(Length::Fill) 411 | .spacing(10) 412 | .align_items(Alignment::Center); 413 | 414 | let unavailable = container( 415 | column![ 416 | text("ADB is not authorized to access this user!").size(22) 417 | .style(style::Text::Danger), 418 | text("The most likely reason is that it is the user of your work profile (also called Secure Folder on Samsung devices). There's really no solution, other than completely disabling your work profile in your device settings.") 419 | .style(style::Text::Commentary) 420 | .horizontal_alignment(alignment::Horizontal::Center), 421 | ] 422 | .spacing(6) 423 | .align_items(Alignment::Center) 424 | ) 425 | .padding(10) 426 | .center_x() 427 | .style(style::Container::BorderedFrame); 428 | 429 | let content = if selected_device.user_list.is_empty() 430 | || !self.phone_packages[self.selected_user.unwrap().index].is_empty() 431 | { 432 | column![ 433 | control_panel, 434 | packages_scrollable, 435 | description_panel, 436 | action_row, 437 | ] 438 | .width(Length::Fill) 439 | .spacing(10) 440 | .align_items(Alignment::Center) 441 | } else { 442 | column![ 443 | control_panel, 444 | container(unavailable).height(Length::Fill).center_y(), 445 | ] 446 | .width(Length::Fill) 447 | .spacing(10) 448 | .align_items(Alignment::Center) 449 | }; 450 | if self.selection_modal { 451 | Modal::new( 452 | content.padding(10), 453 | self.apply_selection_modal( 454 | selected_device, 455 | settings, 456 | &self.phone_packages[self.selected_user.unwrap().index], 457 | ), 458 | ) 459 | .on_blur(Message::ModalHide) 460 | .into() 461 | } else { 462 | container(content).height(Length::Fill).padding(10).into() 463 | } 464 | } 465 | } 466 | } 467 | 468 | fn apply_selection_modal( 469 | &self, 470 | device: &Phone, 471 | settings: &Settings, 472 | packages: &[PackageRow], 473 | ) -> Element> { 474 | // (nb_to_restore, nb_to_remove) 475 | let mut h_recap: HashMap = HashMap::new(); 476 | for p in packages.iter().filter(|p| p.selected) { 477 | if p.state == PackageState::Uninstalled || p.state == PackageState::Disabled { 478 | h_recap.entry(p.removal).or_insert((0, 0)).1 += 1; 479 | } else { 480 | h_recap.entry(p.removal).or_insert((0, 0)).0 += 1; 481 | } 482 | } 483 | 484 | let radio_btn_users = device.user_list.iter().filter(|&u| !u.protected).fold( 485 | row![].spacing(10), 486 | |row, user| { 487 | row.push( 488 | radio( 489 | format!("{}", user.clone()), 490 | *user, 491 | self.selected_user, 492 | Message::ModalUserSelected, 493 | ) 494 | .size(23), 495 | ) 496 | }, 497 | ); 498 | 499 | let title_ctn = 500 | container(row![text("Review your selection").size(25)].align_items(Alignment::Center)) 501 | .width(Length::Fill) 502 | .style(style::Container::Frame) 503 | .padding([10, 0, 10, 0]) 504 | .center_y() 505 | .center_x(); 506 | 507 | let users_ctn = container(radio_btn_users) 508 | .padding(10) 509 | .center_x() 510 | .style(style::Container::Frame); 511 | 512 | let explaination_ctn = container( 513 | row![ 514 | text("The action for the selected user will be applied to all other users") 515 | .style(style::Text::Danger), 516 | tooltip( 517 | text("\u{EA0C}") 518 | .font(ICONS) 519 | .width(17) 520 | .horizontal_alignment(alignment::Horizontal::Center) 521 | .style(style::Text::Commentary) 522 | .size(17), 523 | "Let's say you choose user 0. If a selected package on user 0\n\ 524 | is set to be uninstalled and if this same package is disabled on user 10,\n\ 525 | then the package on both users will be uninstalled.", 526 | tooltip::Position::Top, 527 | ) 528 | .gap(20) 529 | .padding(10) 530 | .size(17) 531 | .style(style::Container::Tooltip) 532 | ] 533 | .spacing(10), 534 | ) 535 | .center_x() 536 | .padding(10) 537 | .style(style::Container::BorderedFrame); 538 | 539 | let modal_btn_row = row![ 540 | button(text("Cancel")).on_press(Message::ModalHide), 541 | horizontal_space(Length::Fill), 542 | button(text("Apply")).on_press(Message::ModalValidate), 543 | ] 544 | .padding([0, 15, 10, 10]); 545 | 546 | let recap_view = Removal::ALL 547 | .iter() 548 | .filter(|&&r| r != Removal::All) 549 | .fold(column![].spacing(6).width(Length::Fill), |col, r| { 550 | col.push(recap(settings, &mut h_recap, *r)) 551 | }); 552 | 553 | let selected_pkgs_ctn = container( 554 | container( 555 | scrollable( 556 | container( 557 | if !self 558 | .selected_packages 559 | .iter() 560 | .any(|s| s.0 == self.selected_user.unwrap().index) 561 | { 562 | column![text("No packages selected for this user")] 563 | .align_items(Alignment::Center) 564 | .width(Length::Fill) 565 | } else { 566 | self.selected_packages 567 | .iter() 568 | .filter(|s| s.0 == self.selected_user.unwrap().index) 569 | .fold( 570 | column![].spacing(6).width(Length::Fill), 571 | |col, selection| { 572 | col.push( 573 | row![ 574 | row![text( 575 | self.phone_packages[selection.0][selection.1] 576 | .removal 577 | )] 578 | .width(100), 579 | row![text( 580 | self.phone_packages[selection.0][selection.1] 581 | .uad_list 582 | )] 583 | .width(60), 584 | row![text( 585 | self.phone_packages[selection.0][selection.1] 586 | .name 587 | .clone() 588 | ),], 589 | horizontal_space(Length::Fill), 590 | row![match self.phone_packages[selection.0] 591 | [selection.1] 592 | .state 593 | { 594 | PackageState::Enabled => 595 | if settings.device.disable_mode { 596 | text("Disable") 597 | .style(style::Text::Danger) 598 | } else { 599 | text("Uninstall") 600 | .style(style::Text::Danger) 601 | }, 602 | PackageState::Disabled => 603 | text("Enable").style(style::Text::Ok), 604 | PackageState::Uninstalled => 605 | text("Restore").style(style::Text::Ok), 606 | PackageState::All => text("Impossible") 607 | .style(style::Text::Danger), 608 | },] 609 | .width(60), 610 | ] 611 | .width(Length::Fill) 612 | .spacing(20), 613 | ) 614 | }, 615 | ) 616 | }, 617 | ) 618 | .padding(10) 619 | .width(Length::Fill), 620 | ) 621 | .style(style::Scrollable::Description), 622 | ) 623 | .width(Length::Fill) 624 | .style(style::Container::Frame), 625 | ) 626 | .width(Length::Fill) 627 | .max_height(150) 628 | .padding([0, 10, 0, 10]); 629 | 630 | container( 631 | if device.user_list.iter().filter(|&u| !u.protected).count() > 1 632 | && settings.device.multi_user_mode 633 | { 634 | column![ 635 | title_ctn, 636 | users_ctn, 637 | row![explaination_ctn].padding([0, 10, 0, 10]), 638 | container(recap_view).padding(10), 639 | selected_pkgs_ctn, 640 | modal_btn_row, 641 | ] 642 | .spacing(10) 643 | .align_items(Alignment::Center) 644 | } else if !settings.device.multi_user_mode { 645 | column![ 646 | title_ctn, 647 | users_ctn, 648 | container(recap_view).padding(10), 649 | selected_pkgs_ctn, 650 | modal_btn_row, 651 | ] 652 | .spacing(10) 653 | .align_items(Alignment::Center) 654 | } else { 655 | column![ 656 | title_ctn, 657 | container(recap_view).padding(10), 658 | selected_pkgs_ctn, 659 | modal_btn_row, 660 | ] 661 | .spacing(10) 662 | .align_items(Alignment::Center) 663 | }, 664 | ) 665 | .width(800) 666 | .height(Length::Shrink) 667 | .max_height(700) 668 | .style(style::Container::Background) 669 | .into() 670 | } 671 | fn filter_package_lists(&mut self) { 672 | let list_filter: UadList = self.selected_list.unwrap(); 673 | let package_filter: PackageState = self.selected_package_state.unwrap(); 674 | let removal_filter: Removal = self.selected_removal.unwrap(); 675 | 676 | self.filtered_packages = self.phone_packages[self.selected_user.unwrap().index] 677 | .iter() 678 | .enumerate() 679 | .filter(|(_, p)| { 680 | (list_filter == UadList::All || p.uad_list == list_filter) 681 | && (package_filter == PackageState::All || p.state == package_filter) 682 | && (removal_filter == Removal::All || p.removal == removal_filter) 683 | && (self.input_value.is_empty() || p.name.contains(&self.input_value)) 684 | }) 685 | .map(|(i, _)| i) 686 | .collect(); 687 | } 688 | 689 | async fn load_packages( 690 | uad_list: HashMap, 691 | user_list: Vec, 692 | ) -> Vec> { 693 | let mut phone_packages = vec![]; 694 | 695 | if user_list.len() <= 1 { 696 | phone_packages.push(fetch_packages(&uad_list, None)); 697 | } else { 698 | phone_packages.extend( 699 | user_list 700 | .iter() 701 | .map(|user| fetch_packages(&uad_list, Some(user))), 702 | ); 703 | }; 704 | phone_packages 705 | } 706 | 707 | async fn init_apps_view( 708 | remote: bool, 709 | phone: Phone, 710 | ) -> (HashMap, UadListState) { 711 | let (uad_lists, _) = load_debloat_lists(remote); 712 | match uad_lists { 713 | Ok(list) => { 714 | env::set_var("ANDROID_SERIAL", phone.adb_id.clone()); 715 | if phone.adb_id.is_empty() { 716 | error!("AppsView ready but no phone found"); 717 | } 718 | (list, UadListState::Done) 719 | } 720 | Err(local_list) => { 721 | error!("Error loading remote debloat list for the phone. Fallback to embedded (and outdated) list"); 722 | (local_list, UadListState::Failed) 723 | } 724 | } 725 | } 726 | } 727 | 728 | fn waiting_view<'a>( 729 | _settings: &Settings, 730 | displayed_text: &str, 731 | btn: bool, 732 | ) -> Element<'a, Message, Renderer> { 733 | let col = if btn { 734 | let no_internet_btn = button("No internet?") 735 | .padding(5) 736 | .on_press(Message::LoadUadList(false)) 737 | .style(style::Button::Primary); 738 | 739 | column![] 740 | .spacing(10) 741 | .align_items(Alignment::Center) 742 | .push(text(displayed_text).size(20)) 743 | .push(no_internet_btn) 744 | } else { 745 | column![] 746 | .spacing(10) 747 | .align_items(Alignment::Center) 748 | .push(text(displayed_text).size(20)) 749 | }; 750 | 751 | container(col) 752 | .width(Length::Fill) 753 | .height(Length::Fill) 754 | .center_y() 755 | .center_x() 756 | .style(style::Container::default()) 757 | .into() 758 | } 759 | 760 | fn build_action_pkg_commands( 761 | packages: &[Vec], 762 | device: &Phone, 763 | settings: &DeviceSettings, 764 | selection: (usize, usize), 765 | ) -> Vec> { 766 | let pkg = &packages[selection.0][selection.1]; 767 | let wanted_state = pkg.state.opposite(settings.disable_mode); 768 | 769 | let mut commands = vec![]; 770 | for u in device.user_list.iter().filter(|&&u| { 771 | !u.protected && (packages[u.index][selection.1].selected || settings.multi_user_mode) 772 | }) { 773 | let u_pkg = packages[u.index][selection.1].clone(); 774 | let actions = if settings.multi_user_mode { 775 | apply_pkg_state_commands(&u_pkg.into(), wanted_state, u, device) 776 | } else { 777 | let wanted_state = u_pkg.state.opposite(settings.disable_mode); 778 | apply_pkg_state_commands(&u_pkg.into(), wanted_state, u, device) 779 | }; 780 | for (j, action) in actions.into_iter().enumerate() { 781 | let p_info = PackageInfo { 782 | i_user: u.index, 783 | index: selection.1, 784 | removal: pkg.removal.to_string(), 785 | }; 786 | // In the end there is only one package state change 787 | // even if we run multiple adb commands 788 | commands.push(Command::perform( 789 | perform_adb_commands(action, CommandType::PackageManager(p_info)), 790 | if j == 0 { 791 | Message::ChangePackageState 792 | } else { 793 | |_| Message::Nothing 794 | }, 795 | )); 796 | } 797 | } 798 | commands 799 | } 800 | 801 | fn recap<'a>( 802 | settings: &Settings, 803 | recap: &mut HashMap, 804 | removal: Removal, 805 | ) -> Element<'a, Message, Renderer> { 806 | container( 807 | row![ 808 | text(removal).size(25).width(Length::FillPortion(1)), 809 | vertical_rule(5), 810 | row![ 811 | if settings.device.disable_mode { 812 | text("Disable").style(style::Text::Danger) 813 | } else { 814 | text("Uninstall").style(style::Text::Danger) 815 | }, 816 | horizontal_space(Length::Fill), 817 | text(recap.entry(removal).or_insert((0, 0)).0.to_string()) 818 | .style(style::Text::Danger) 819 | ] 820 | .width(Length::FillPortion(1)), 821 | vertical_rule(5), 822 | row![ 823 | if settings.device.disable_mode { 824 | text("Enable").style(style::Text::Ok) 825 | } else { 826 | text("Restore").style(style::Text::Ok) 827 | }, 828 | horizontal_space(Length::Fill), 829 | text(recap.entry(removal).or_insert((0, 0)).1.to_string()).style(style::Text::Ok) 830 | ] 831 | .width(Length::FillPortion(1)) 832 | ] 833 | .spacing(20) 834 | .padding([0, 10, 0, 0]) 835 | .width(Length::Fill) 836 | .align_items(Alignment::Center), 837 | ) 838 | .padding(10) 839 | .width(Length::Fill) 840 | .height(45) 841 | .style(style::Container::Frame) 842 | .into() 843 | } 844 | -------------------------------------------------------------------------------- /src/gui/views/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod about; 2 | pub mod list; 3 | pub mod settings; 4 | -------------------------------------------------------------------------------- /src/gui/views/settings.rs: -------------------------------------------------------------------------------- 1 | use crate::core::config::{BackupSettings, Config, DeviceSettings, GeneralSettings}; 2 | use crate::core::save::{ 3 | backup_phone, list_available_backup_user, list_available_backups, restore_backup, BACKUP_DIR, 4 | }; 5 | use crate::core::sync::{get_android_sdk, perform_adb_commands, CommandType, Phone}; 6 | use crate::core::theme::Theme; 7 | use crate::core::utils::{open_url, string_to_theme, DisplayablePath}; 8 | use crate::gui::style; 9 | use crate::gui::views::list::PackageInfo; 10 | use crate::gui::widgets::package_row::PackageRow; 11 | 12 | use iced::widget::{button, checkbox, column, container, pick_list, radio, row, text, Space}; 13 | use iced::{alignment, Alignment, Command, Element, Length, Renderer}; 14 | use std::path::PathBuf; 15 | 16 | #[derive(Debug, Clone)] 17 | pub struct Settings { 18 | pub general: GeneralSettings, 19 | pub device: DeviceSettings, 20 | } 21 | 22 | impl Default for Settings { 23 | fn default() -> Self { 24 | Self { 25 | general: Config::load_configuration_file().general, 26 | device: DeviceSettings::default(), 27 | } 28 | } 29 | } 30 | 31 | #[derive(Debug, Clone)] 32 | pub enum Message { 33 | LoadDeviceSettings, 34 | ExpertMode(bool), 35 | DisableMode(bool), 36 | MultiUserMode(bool), 37 | ApplyTheme(Theme), 38 | UrlPressed(PathBuf), 39 | BackupSelected(DisplayablePath), 40 | BackupDevice, 41 | RestoreDevice, 42 | RestoringDevice(Result), 43 | DeviceBackedUp(Result<(), String>), 44 | } 45 | 46 | impl Settings { 47 | pub fn update( 48 | &mut self, 49 | phone: &Phone, 50 | packages: &[Vec], 51 | nb_running_async_adb_commands: &mut u32, 52 | msg: Message, 53 | ) -> Command { 54 | match msg { 55 | Message::ExpertMode(toggled) => { 56 | self.general.expert_mode = toggled; 57 | debug!("Config change: {:?}", self); 58 | Config::save_changes(self, &phone.adb_id); 59 | Command::none() 60 | } 61 | Message::DisableMode(toggled) => { 62 | if phone.android_sdk >= 23 { 63 | self.device.disable_mode = toggled; 64 | debug!("Config change: {:?}", self); 65 | Config::save_changes(self, &phone.adb_id); 66 | } 67 | Command::none() 68 | } 69 | Message::MultiUserMode(toggled) => { 70 | self.device.multi_user_mode = toggled; 71 | debug!("Config change: {:?}", self); 72 | Config::save_changes(self, &phone.adb_id); 73 | Command::none() 74 | } 75 | Message::ApplyTheme(theme) => { 76 | self.general.theme = theme.to_string(); 77 | debug!("Config change: {:?}", self); 78 | Config::save_changes(self, &phone.adb_id); 79 | Command::none() 80 | } 81 | Message::UrlPressed(url) => { 82 | open_url(url); 83 | Command::none() 84 | } 85 | Message::LoadDeviceSettings => { 86 | let backups = list_available_backups(&BACKUP_DIR.join(phone.adb_id.clone())); 87 | match Config::load_configuration_file() 88 | .devices 89 | .iter() 90 | .find(|d| d.device_id == phone.adb_id) 91 | { 92 | Some(device) => { 93 | self.device = device.clone(); 94 | self.device.backup = BackupSettings { 95 | backups: backups.clone(), 96 | selected: backups.first().cloned(), 97 | users: phone.user_list.clone(), 98 | selected_user: phone.user_list.first().copied(), 99 | backup_state: String::new(), 100 | }; 101 | } 102 | None => { 103 | self.device = DeviceSettings { 104 | device_id: phone.adb_id.clone(), 105 | multi_user_mode: phone.android_sdk > 21, 106 | disable_mode: false, 107 | backup: BackupSettings { 108 | backups: backups.clone(), 109 | selected: backups.first().cloned(), 110 | users: phone.user_list.clone(), 111 | selected_user: phone.user_list.first().copied(), 112 | backup_state: String::new(), 113 | }, 114 | } 115 | } 116 | }; 117 | Command::none() 118 | } 119 | Message::BackupSelected(d_path) => { 120 | self.device.backup.selected = Some(d_path.clone()); 121 | self.device.backup.users = list_available_backup_user(d_path); 122 | Command::none() 123 | } 124 | Message::BackupDevice => Command::perform( 125 | backup_phone( 126 | phone.user_list.clone(), 127 | self.device.device_id.clone(), 128 | packages.to_vec(), 129 | ), 130 | Message::DeviceBackedUp, 131 | ), 132 | Message::DeviceBackedUp(_) => { 133 | info!("[BACKUP] Backup successfully created"); 134 | self.device.backup.backups = 135 | list_available_backups(&BACKUP_DIR.join(phone.adb_id.clone())); 136 | self.device.backup.selected = self.device.backup.backups.first().cloned(); 137 | Command::none() 138 | } 139 | Message::RestoreDevice => match restore_backup(phone, packages, &self.device) { 140 | Ok(r_packages) => { 141 | let mut commands = vec![]; 142 | *nb_running_async_adb_commands = 0; 143 | for p in &r_packages { 144 | let p_info = PackageInfo { 145 | i_user: 0, 146 | index: p.index, 147 | removal: "RESTORE".to_string(), 148 | }; 149 | for command in p.commands.clone() { 150 | *nb_running_async_adb_commands += 1; 151 | commands.push(Command::perform( 152 | perform_adb_commands( 153 | command, 154 | CommandType::PackageManager(p_info.clone()), 155 | ), 156 | Message::RestoringDevice, 157 | )); 158 | } 159 | } 160 | if r_packages.is_empty() { 161 | if get_android_sdk() == 0 { 162 | self.device.backup.backup_state = "Device is not connected".to_string(); 163 | } else { 164 | self.device.backup.backup_state = 165 | "Device state is already restored".to_string(); 166 | } 167 | } 168 | info!( 169 | "[RESTORE] Restoring backup {}", 170 | self.device.backup.selected.as_ref().unwrap() 171 | ); 172 | Command::batch(commands) 173 | } 174 | Err(e) => { 175 | self.device.backup.backup_state = e.to_string(); 176 | error!("{} - {}", self.device.backup.selected.as_ref().unwrap(), e); 177 | Command::none() 178 | } 179 | }, 180 | // Trigger an action in mod.rs (Message::SettingsAction(msg)) 181 | Message::RestoringDevice(_) => Command::none(), 182 | } 183 | } 184 | 185 | pub fn view(&self, phone: &Phone) -> Element> { 186 | let radio_btn_theme = Theme::ALL 187 | .iter() 188 | .fold(row![].spacing(10), |column, option| { 189 | column.push( 190 | radio( 191 | format!("{}", option.clone()), 192 | *option, 193 | Some(string_to_theme(&self.general.theme)), 194 | Message::ApplyTheme, 195 | ) 196 | .size(23), 197 | ) 198 | }); 199 | let theme_ctn = container(radio_btn_theme) 200 | .padding(10) 201 | .width(Length::Fill) 202 | .height(Length::Shrink) 203 | .style(style::Container::Frame); 204 | 205 | let expert_mode_checkbox = checkbox( 206 | "Allow to uninstall packages marked as \"unsafe\" (I KNOW WHAT I AM DOING)", 207 | self.general.expert_mode, 208 | Message::ExpertMode, 209 | ) 210 | .style(style::CheckBox::SettingsEnabled); 211 | 212 | let expert_mode_descr = 213 | text("Most of unsafe packages are known to bootloop the device if removed.") 214 | .style(style::Text::Commentary) 215 | .size(15); 216 | 217 | let general_ctn = container(column![expert_mode_checkbox, expert_mode_descr].spacing(10)) 218 | .padding(10) 219 | .width(Length::Fill) 220 | .height(Length::Shrink) 221 | .style(style::Container::Frame); 222 | 223 | let warning_ctn = container( 224 | row![ 225 | text("The following settings only affect the currently selected device :") 226 | .style(style::Text::Danger), 227 | text(phone.model.clone()), 228 | Space::new(Length::Fill, Length::Shrink), 229 | text(phone.adb_id.clone()).style(style::Text::Commentary) 230 | ] 231 | .spacing(7), 232 | ) 233 | .padding(10) 234 | .width(Length::Fill) 235 | .style(style::Container::BorderedFrame); 236 | 237 | let multi_user_mode_descr = row![ 238 | text("This will not affect the following protected work profile users: ") 239 | .size(15) 240 | .style(style::Text::Commentary), 241 | text( 242 | phone 243 | .user_list 244 | .iter() 245 | .filter(|&u| u.protected) 246 | .map(|u| u.id.to_string()) 247 | .collect::>() 248 | .join(", ") 249 | ) 250 | .size(15) 251 | .style(style::Text::Danger) 252 | ]; 253 | 254 | let multi_user_mode_checkbox = checkbox( 255 | "Affect all the users of the device (not only the selected user)", 256 | self.device.multi_user_mode, 257 | Message::MultiUserMode, 258 | ) 259 | .style(style::CheckBox::SettingsEnabled); 260 | 261 | let disable_checkbox_style = if phone.android_sdk >= 23 { 262 | style::CheckBox::SettingsEnabled 263 | } else { 264 | style::CheckBox::SettingsDisabled 265 | }; 266 | 267 | let disable_mode_descr = 268 | text("In some cases, it can be better to disable a package instead of uninstalling it") 269 | .style(style::Text::Commentary) 270 | .size(15); 271 | 272 | let unavailable_btn = button(text("Unavailable").size(13)) 273 | .on_press(Message::UrlPressed(PathBuf::from( 274 | "https://github.com/0x192/universal-android-debloater/wiki/FAQ#\ 275 | why-is-the-disable-mode-setting-not-available-for-my-device", 276 | ))) 277 | .height(22) 278 | .style(style::Button::Unavailable); 279 | 280 | // Disabling package without root isn't really possible before Android Oreo (8.0) 281 | // see https://github.com/0x192/universal-android-debloater/wiki/ADB-reference 282 | let disable_mode_checkbox = checkbox( 283 | "Clear and disable packages instead of uninstalling them", 284 | self.device.disable_mode, 285 | Message::DisableMode, 286 | ) 287 | .style(disable_checkbox_style); 288 | 289 | let disable_setting_row = if phone.android_sdk >= 23 { 290 | row![ 291 | disable_mode_checkbox, 292 | Space::new(Length::Fill, Length::Shrink), 293 | ] 294 | .width(Length::Fill) 295 | } else { 296 | row![ 297 | disable_mode_checkbox, 298 | Space::new(Length::Fill, Length::Shrink), 299 | unavailable_btn, 300 | ] 301 | .width(Length::Fill) 302 | }; 303 | 304 | let device_specific_ctn = container( 305 | column![ 306 | multi_user_mode_checkbox, 307 | multi_user_mode_descr, 308 | disable_setting_row, 309 | disable_mode_descr, 310 | ] 311 | .spacing(10), 312 | ) 313 | .padding(10) 314 | .width(Length::Fill) 315 | .height(Length::Shrink) 316 | .style(style::Container::Frame); 317 | 318 | let backup_pick_list = pick_list( 319 | self.device.backup.backups.clone(), 320 | self.device.backup.selected.clone(), 321 | Message::BackupSelected, 322 | ) 323 | .padding(6); 324 | 325 | let backup_btn = button(text("Backup").horizontal_alignment(alignment::Horizontal::Center)) 326 | .padding(5) 327 | .on_press(Message::BackupDevice) 328 | .style(style::Button::Primary) 329 | .width(77); 330 | 331 | let restore_btn = |enabled| { 332 | if enabled { 333 | button(text("Restore").horizontal_alignment(alignment::Horizontal::Center)) 334 | .padding(5) 335 | .on_press(Message::RestoreDevice) 336 | .width(77) 337 | } else { 338 | button(text("No backup").horizontal_alignment(alignment::Horizontal::Center)) 339 | .padding(5) 340 | .width(77) 341 | } 342 | }; 343 | 344 | let locate_backup_btn = if self.device.backup.backups.is_empty() { 345 | button("Open backup directory") 346 | .padding(5) 347 | .style(style::Button::Primary) 348 | } else { 349 | button("Open backup directory") 350 | .on_press(Message::UrlPressed(BACKUP_DIR.join(phone.adb_id.clone()))) 351 | .padding(5) 352 | .style(style::Button::Primary) 353 | }; 354 | 355 | let backup_row = row![ 356 | backup_btn, 357 | "Backup the current state of the phone", 358 | Space::new(Length::Fill, Length::Shrink), 359 | locate_backup_btn, 360 | ] 361 | .spacing(10) 362 | .align_items(Alignment::Center); 363 | 364 | let restore_row = if self.device.backup.backups.is_empty() { 365 | row![restore_btn(false), "Restore the state of the device",] 366 | .spacing(10) 367 | .align_items(Alignment::Center) 368 | } else { 369 | row![ 370 | restore_btn(true), 371 | "Restore the state of the device", 372 | Space::new(Length::Fill, Length::Shrink), 373 | text(self.device.backup.backup_state.clone()).style(style::Text::Danger), 374 | backup_pick_list, 375 | ] 376 | .spacing(10) 377 | .align_items(Alignment::Center) 378 | }; 379 | 380 | let backup_restore_ctn = container(column![backup_row, restore_row].spacing(10)) 381 | .padding(10) 382 | .width(Length::Fill) 383 | .height(Length::Shrink) 384 | .style(style::Container::Frame); 385 | 386 | let no_device_ctn = || { 387 | container(text("No device detected").style(style::Text::Danger)) 388 | .padding(10) 389 | .width(Length::Fill) 390 | .style(style::Container::BorderedFrame) 391 | }; 392 | 393 | let content = if phone.adb_id.clone().is_empty() { 394 | column![ 395 | text("Theme").size(25), 396 | theme_ctn, 397 | text("General").size(25), 398 | general_ctn, 399 | text("Current device").size(25), 400 | no_device_ctn(), 401 | text("Backup / Restore").size(25), 402 | no_device_ctn(), 403 | ] 404 | .width(Length::Fill) 405 | .spacing(20) 406 | } else { 407 | column![ 408 | text("Theme").size(25), 409 | theme_ctn, 410 | text("General").size(25), 411 | general_ctn, 412 | text("Current device").size(25), 413 | warning_ctn, 414 | device_specific_ctn, 415 | backup_restore_ctn, 416 | ] 417 | .width(Length::Fill) 418 | .spacing(20) 419 | }; 420 | 421 | container(content) 422 | .padding(10) 423 | .width(Length::Fill) 424 | .height(Length::Fill) 425 | .into() 426 | } 427 | } 428 | -------------------------------------------------------------------------------- /src/gui/widgets/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod modal; 2 | pub mod navigation_menu; 3 | pub mod package_row; 4 | -------------------------------------------------------------------------------- /src/gui/widgets/modal.rs: -------------------------------------------------------------------------------- 1 | use iced_native::alignment::Alignment; 2 | use iced_native::widget::{self, Tree}; 3 | use iced_native::{ 4 | event, layout, mouse, overlay, renderer, Clipboard, Color, Element, Event, Layout, Length, 5 | Point, Rectangle, Shell, Size, Widget, 6 | }; 7 | 8 | /// A widget that centers a modal element over some base element 9 | pub struct Modal<'a, Message, Renderer> { 10 | base: Element<'a, Message, Renderer>, 11 | modal: Element<'a, Message, Renderer>, 12 | on_blur: Option, 13 | } 14 | 15 | impl<'a, Message, Renderer> Modal<'a, Message, Renderer> { 16 | /// Returns a new [`Modal`] 17 | pub fn new( 18 | base: impl Into>, 19 | modal: impl Into>, 20 | ) -> Self { 21 | Self { 22 | base: base.into(), 23 | modal: modal.into(), 24 | on_blur: None, 25 | } 26 | } 27 | 28 | #[allow(clippy::missing_const_for_fn)] 29 | /// Sets the message that will be produces when the background 30 | /// of the [`Modal`] is pressed 31 | pub fn on_blur(self, on_blur: Message) -> Self { 32 | Self { 33 | on_blur: Some(on_blur), 34 | ..self 35 | } 36 | } 37 | } 38 | 39 | impl<'a, Message, Renderer> Widget for Modal<'a, Message, Renderer> 40 | where 41 | Renderer: iced_native::Renderer, 42 | Message: Clone, 43 | { 44 | fn children(&self) -> Vec { 45 | vec![Tree::new(&self.base), Tree::new(&self.modal)] 46 | } 47 | 48 | fn diff(&self, tree: &mut Tree) { 49 | tree.diff_children(&[&self.base, &self.modal]); 50 | } 51 | 52 | fn width(&self) -> Length { 53 | self.base.as_widget().width() 54 | } 55 | 56 | fn height(&self) -> Length { 57 | self.base.as_widget().height() 58 | } 59 | 60 | fn layout(&self, renderer: &Renderer, limits: &layout::Limits) -> layout::Node { 61 | self.base.as_widget().layout(renderer, limits) 62 | } 63 | 64 | fn on_event( 65 | &mut self, 66 | state: &mut Tree, 67 | event: Event, 68 | layout: Layout<'_>, 69 | cursor_position: Point, 70 | renderer: &Renderer, 71 | clipboard: &mut dyn Clipboard, 72 | shell: &mut Shell<'_, Message>, 73 | ) -> event::Status { 74 | self.base.as_widget_mut().on_event( 75 | &mut state.children[0], 76 | event, 77 | layout, 78 | cursor_position, 79 | renderer, 80 | clipboard, 81 | shell, 82 | ) 83 | } 84 | 85 | fn draw( 86 | &self, 87 | state: &Tree, 88 | renderer: &mut Renderer, 89 | theme: &::Theme, 90 | style: &renderer::Style, 91 | layout: Layout<'_>, 92 | cursor_position: Point, 93 | viewport: &Rectangle, 94 | ) { 95 | self.base.as_widget().draw( 96 | &state.children[0], 97 | renderer, 98 | theme, 99 | style, 100 | layout, 101 | cursor_position, 102 | viewport, 103 | ); 104 | } 105 | 106 | fn overlay<'b>( 107 | &'b mut self, 108 | state: &'b mut Tree, 109 | layout: Layout<'_>, 110 | _renderer: &Renderer, 111 | ) -> Option> { 112 | Some(overlay::Element::new( 113 | layout.position(), 114 | Box::new(Overlay { 115 | content: &mut self.modal, 116 | tree: &mut state.children[1], 117 | size: layout.bounds().size(), 118 | on_blur: self.on_blur.clone(), 119 | }), 120 | )) 121 | } 122 | 123 | fn mouse_interaction( 124 | &self, 125 | state: &Tree, 126 | layout: Layout<'_>, 127 | cursor_position: Point, 128 | viewport: &Rectangle, 129 | renderer: &Renderer, 130 | ) -> mouse::Interaction { 131 | self.base.as_widget().mouse_interaction( 132 | &state.children[0], 133 | layout, 134 | cursor_position, 135 | viewport, 136 | renderer, 137 | ) 138 | } 139 | 140 | fn operate( 141 | &self, 142 | state: &mut Tree, 143 | layout: Layout<'_>, 144 | renderer: &Renderer, 145 | operation: &mut dyn widget::Operation, 146 | ) { 147 | self.base 148 | .as_widget() 149 | .operate(&mut state.children[0], layout, renderer, operation); 150 | } 151 | } 152 | 153 | struct Overlay<'a, 'b, Message, Renderer> { 154 | content: &'b mut Element<'a, Message, Renderer>, 155 | tree: &'b mut Tree, 156 | size: Size, 157 | on_blur: Option, 158 | } 159 | 160 | impl<'a, 'b, Message, Renderer> overlay::Overlay 161 | for Overlay<'a, 'b, Message, Renderer> 162 | where 163 | Renderer: iced_native::Renderer, 164 | Message: Clone, 165 | { 166 | fn layout(&self, renderer: &Renderer, _bounds: Size, position: Point) -> layout::Node { 167 | let limits = layout::Limits::new(Size::ZERO, self.size) 168 | .width(Length::Fill) 169 | .height(Length::Fill); 170 | 171 | let mut child = self.content.as_widget().layout(renderer, &limits); 172 | child.align(Alignment::Center, Alignment::Center, limits.max()); 173 | 174 | let mut node = layout::Node::with_children(self.size, vec![child]); 175 | node.move_to(position); 176 | 177 | node 178 | } 179 | 180 | fn on_event( 181 | &mut self, 182 | event: Event, 183 | layout: Layout<'_>, 184 | cursor_position: Point, 185 | renderer: &Renderer, 186 | clipboard: &mut dyn Clipboard, 187 | shell: &mut Shell<'_, Message>, 188 | ) -> event::Status { 189 | let content_bounds = layout.children().next().unwrap().bounds(); 190 | 191 | #[allow(clippy::equatable_if_let)] 192 | if let Some(message) = self.on_blur.as_ref() { 193 | if let Event::Mouse(mouse::Event::ButtonPressed(mouse::Button::Left)) = &event { 194 | if !content_bounds.contains(cursor_position) { 195 | shell.publish(message.clone()); 196 | return event::Status::Captured; 197 | } 198 | } 199 | } 200 | 201 | self.content.as_widget_mut().on_event( 202 | self.tree, 203 | event, 204 | layout.children().next().unwrap(), 205 | cursor_position, 206 | renderer, 207 | clipboard, 208 | shell, 209 | ) 210 | } 211 | 212 | fn draw( 213 | &self, 214 | renderer: &mut Renderer, 215 | theme: &Renderer::Theme, 216 | style: &renderer::Style, 217 | layout: Layout<'_>, 218 | cursor_position: Point, 219 | ) { 220 | renderer.fill_quad( 221 | renderer::Quad { 222 | bounds: layout.bounds(), 223 | border_radius: renderer::BorderRadius::from(0.0), 224 | border_width: 0.0, 225 | border_color: Color::TRANSPARENT, 226 | }, 227 | Color { 228 | a: 0.80, 229 | ..Color::BLACK 230 | }, 231 | ); 232 | 233 | self.content.as_widget().draw( 234 | self.tree, 235 | renderer, 236 | theme, 237 | style, 238 | layout.children().next().unwrap(), 239 | cursor_position, 240 | &layout.bounds(), 241 | ); 242 | } 243 | 244 | fn operate( 245 | &mut self, 246 | layout: Layout<'_>, 247 | renderer: &Renderer, 248 | operation: &mut dyn widget::Operation, 249 | ) { 250 | self.content.as_widget().operate( 251 | self.tree, 252 | layout.children().next().unwrap(), 253 | renderer, 254 | operation, 255 | ); 256 | } 257 | 258 | fn mouse_interaction( 259 | &self, 260 | layout: Layout<'_>, 261 | cursor_position: Point, 262 | viewport: &Rectangle, 263 | renderer: &Renderer, 264 | ) -> mouse::Interaction { 265 | self.content.as_widget().mouse_interaction( 266 | self.tree, 267 | layout.children().next().unwrap(), 268 | cursor_position, 269 | viewport, 270 | renderer, 271 | ) 272 | } 273 | } 274 | 275 | impl<'a, Message, Renderer> From> for Element<'a, Message, Renderer> 276 | where 277 | Renderer: 'a + iced_native::Renderer, 278 | Message: 'a + Clone, 279 | { 280 | fn from(modal: Modal<'a, Message, Renderer>) -> Self { 281 | Element::new(modal) 282 | } 283 | } 284 | -------------------------------------------------------------------------------- /src/gui/widgets/navigation_menu.rs: -------------------------------------------------------------------------------- 1 | pub use crate::core::sync::Phone; 2 | use crate::core::theme::Theme; 3 | use crate::core::update::{SelfUpdateState, SelfUpdateStatus}; 4 | pub use crate::gui::views::about::Message as AboutMessage; 5 | pub use crate::gui::views::list::{List as AppsView, LoadingState as ListLoadingState}; 6 | use crate::gui::{style, Message}; 7 | use iced::widget::{button, container, pick_list, row, text, Space, Text}; 8 | use iced::{alignment, Alignment, Element, Font, Length, Renderer}; 9 | 10 | pub const ICONS: Font = Font::External { 11 | name: "Icons", 12 | bytes: include_bytes!("../../../resources/assets/icons.ttf"), 13 | }; 14 | 15 | pub fn nav_menu<'a>( 16 | device_list: &'a Vec, 17 | selected_device: Option, 18 | apps_view: &AppsView, 19 | self_update_state: &SelfUpdateState, 20 | ) -> Element<'a, Message, Renderer> { 21 | let apps_refresh_btn = button( 22 | Text::new("\u{E900}") 23 | .font(ICONS) 24 | .width(17) 25 | .horizontal_alignment(alignment::Horizontal::Center) 26 | .size(17), 27 | ) 28 | .on_press(Message::RefreshButtonPressed) 29 | .padding(5) 30 | .style(style::Button::Refresh); 31 | 32 | let reboot_btn = button("Reboot") 33 | .on_press(Message::RebootButtonPressed) 34 | .padding(5) 35 | .style(style::Button::Refresh); 36 | 37 | #[allow(clippy::option_if_let_else)] 38 | let uad_version_text = if let Some(r) = &self_update_state.latest_release { 39 | if self_update_state.status == SelfUpdateStatus::Updating { 40 | Text::new("Updating please wait...") 41 | } else { 42 | Text::new(format!( 43 | "New UAD version available {} -> {}", 44 | env!("CARGO_PKG_VERSION"), 45 | r.tag_name 46 | )) 47 | } 48 | } else { 49 | Text::new(env!("CARGO_PKG_VERSION")) 50 | }; 51 | 52 | let apps_btn = if self_update_state.latest_release.is_some() { 53 | button("Update") 54 | .on_press(Message::AboutAction(AboutMessage::DoSelfUpdate)) 55 | .padding(5) 56 | .style(style::Button::SelfUpdate) 57 | } else { 58 | button("Apps") 59 | .on_press(Message::AppsPress) 60 | .padding(5) 61 | .style(style::Button::Primary) 62 | }; 63 | 64 | let about_btn = button("About") 65 | .on_press(Message::AboutPressed) 66 | .padding(5) 67 | .style(style::Button::Primary); 68 | 69 | let settings_btn = button("Settings") 70 | .on_press(Message::SettingsPressed) 71 | .padding(5) 72 | .style(style::Button::Primary); 73 | 74 | let device_list_text = match apps_view.loading_state { 75 | ListLoadingState::FindingPhones(_) => text("finding connected phone..."), 76 | _ => text("no devices/emulators found"), 77 | }; 78 | 79 | let row = match selected_device { 80 | Some(phone) => row![ 81 | apps_refresh_btn, 82 | reboot_btn, 83 | pick_list(device_list, Some(phone), Message::DeviceSelected,), 84 | Space::new(Length::Fill, Length::Shrink), 85 | uad_version_text, 86 | apps_btn, 87 | about_btn, 88 | settings_btn, 89 | ] 90 | .width(Length::Fill) 91 | .align_items(Alignment::Center) 92 | .spacing(10), 93 | None => row![ 94 | reboot_btn, 95 | apps_refresh_btn, 96 | device_list_text, 97 | Space::new(Length::Fill, Length::Shrink), 98 | uad_version_text, 99 | apps_btn, 100 | about_btn, 101 | settings_btn, 102 | ] 103 | .width(Length::Fill) 104 | .align_items(Alignment::Center) 105 | .spacing(10), 106 | }; 107 | 108 | container(row) 109 | .width(Length::Fill) 110 | .padding(10) 111 | .style(style::Container::Frame) 112 | .into() 113 | } 114 | -------------------------------------------------------------------------------- /src/gui/widgets/package_row.rs: -------------------------------------------------------------------------------- 1 | use crate::core::sync::Phone; 2 | use crate::core::theme::Theme; 3 | use crate::core::uad_lists::{PackageState, Removal, UadList}; 4 | use crate::gui::style; 5 | use crate::gui::views::settings::Settings; 6 | 7 | use iced::widget::{button, checkbox, row, text, Space}; 8 | use iced::{alignment, Alignment, Command, Element, Length, Renderer}; 9 | 10 | #[derive(Clone, Debug)] 11 | pub struct PackageRow { 12 | pub name: String, 13 | pub state: PackageState, 14 | pub description: String, 15 | pub uad_list: UadList, 16 | pub removal: Removal, 17 | pub selected: bool, 18 | pub current: bool, 19 | } 20 | 21 | #[derive(Clone, Debug)] 22 | pub enum Message { 23 | PackagePressed, 24 | ActionPressed, 25 | ToggleSelection(bool), 26 | } 27 | 28 | impl PackageRow { 29 | pub fn new( 30 | name: &str, 31 | state: PackageState, 32 | description: &str, 33 | uad_list: UadList, 34 | removal: Removal, 35 | selected: bool, 36 | current: bool, 37 | ) -> Self { 38 | Self { 39 | name: name.to_string(), 40 | state, 41 | description: description.to_string(), 42 | uad_list, 43 | removal, 44 | selected, 45 | current, 46 | } 47 | } 48 | 49 | pub fn update(&mut self, _message: &Message) -> Command { 50 | Command::none() 51 | } 52 | 53 | pub fn view(&self, settings: &Settings, _phone: &Phone) -> Element> { 54 | //let trash_svg = format!("{}/resources/assets/trash.svg", env!("CARGO_MANIFEST_DIR")); 55 | //let restore_svg = format!("{}/resources/assets/rotate.svg", env!("CARGO_MANIFEST_DIR")); 56 | let button_style; 57 | let action_text; 58 | let action_btn; 59 | let selection_checkbox; 60 | 61 | match self.state { 62 | PackageState::Enabled => { 63 | action_text = if settings.device.disable_mode { 64 | "Disable" 65 | } else { 66 | "Uninstall" 67 | }; 68 | button_style = style::Button::UninstallPackage; 69 | } 70 | PackageState::Disabled => { 71 | action_text = "Enable"; 72 | button_style = style::Button::RestorePackage; 73 | } 74 | PackageState::Uninstalled => { 75 | action_text = "Restore"; 76 | button_style = style::Button::RestorePackage; 77 | } 78 | PackageState::All => { 79 | action_text = "Error"; 80 | button_style = style::Button::RestorePackage; 81 | warn!("Incredible! Something impossible happened!"); 82 | } 83 | } 84 | // Disable any removal action for unsafe packages if expert_mode is disabled 85 | if self.removal != Removal::Unsafe 86 | || self.state != PackageState::Enabled 87 | || settings.general.expert_mode 88 | { 89 | selection_checkbox = checkbox("", self.selected, Message::ToggleSelection) 90 | .style(style::CheckBox::PackageEnabled); 91 | 92 | action_btn = button( 93 | text(action_text) 94 | .horizontal_alignment(alignment::Horizontal::Center) 95 | .width(100), 96 | ) 97 | .on_press(Message::ActionPressed); 98 | } else { 99 | selection_checkbox = checkbox("", self.selected, Message::ToggleSelection) 100 | .style(style::CheckBox::PackageDisabled); 101 | 102 | action_btn = button( 103 | text(action_text) 104 | .horizontal_alignment(alignment::Horizontal::Center) 105 | .width(100), 106 | ); 107 | } 108 | 109 | row![ 110 | button( 111 | row![ 112 | selection_checkbox, 113 | text(&self.name).width(Length::FillPortion(8)), 114 | action_btn.style(button_style) 115 | ] 116 | .align_items(Alignment::Center) 117 | ) 118 | .padding(8) 119 | .style(if self.current { 120 | style::Button::SelectedPackage 121 | } else { 122 | style::Button::NormalPackage 123 | }) 124 | .width(Length::Fill) 125 | .on_press(Message::PackagePressed), 126 | Space::with_width(15) 127 | ] 128 | .align_items(Alignment::Center) 129 | .into() 130 | } 131 | } 132 | -------------------------------------------------------------------------------- /src/main.rs: -------------------------------------------------------------------------------- 1 | #![windows_subsystem = "windows"] 2 | #[macro_use] 3 | extern crate log; 4 | 5 | use crate::core::utils::setup_uad_dir; 6 | use fern::{ 7 | colors::{Color, ColoredLevelConfig}, 8 | FormatCallback, 9 | }; 10 | use log::Record; 11 | use static_init::dynamic; 12 | use std::path::PathBuf; 13 | use std::{fmt::Arguments, fs::OpenOptions}; 14 | 15 | mod core; 16 | mod gui; 17 | 18 | #[dynamic] 19 | static CONFIG_DIR: PathBuf = setup_uad_dir(dirs::config_dir()); 20 | 21 | #[dynamic] 22 | static CACHE_DIR: PathBuf = setup_uad_dir(dirs::cache_dir()); 23 | 24 | fn main() -> iced::Result { 25 | setup_logger().expect("setup logging"); 26 | gui::UadGui::start() 27 | } 28 | 29 | pub fn setup_logger() -> Result<(), fern::InitError> { 30 | let colors = ColoredLevelConfig::new().info(Color::Green); 31 | 32 | let make_formatter = |use_colors: bool| { 33 | move |out: FormatCallback, message: &Arguments, record: &Record| { 34 | out.finish(format_args!( 35 | "{} {} [{}:{}] {}", 36 | chrono::Local::now().format("%Y-%m-%d %H:%M:%S"), 37 | if use_colors { 38 | format!("{:5}", colors.color(record.level())) 39 | } else { 40 | format!("{:5}", record.level().to_string()) 41 | }, 42 | record.file().unwrap_or("?"), 43 | record.line().map(|l| l.to_string()).unwrap_or_default(), 44 | message 45 | )); 46 | } 47 | }; 48 | 49 | let default_log_level = log::LevelFilter::Warn; 50 | let log_file = OpenOptions::new() 51 | .write(true) 52 | .create(true) 53 | .append(true) 54 | .truncate(false) 55 | .open(CACHE_DIR.join(format!("UAD_{}.log", chrono::Local::now().format("%Y%m%d"))))?; 56 | 57 | let file_dispatcher = fern::Dispatch::new() 58 | .format(make_formatter(false)) 59 | .level(default_log_level) 60 | .level_for("uad_gui", log::LevelFilter::Debug) 61 | .chain(log_file); 62 | 63 | let stdout_dispatcher = fern::Dispatch::new() 64 | .format(make_formatter(true)) 65 | .level(default_log_level) 66 | .level_for("uad_gui", log::LevelFilter::Warn) 67 | .chain(std::io::stdout()); 68 | 69 | fern::Dispatch::new() 70 | .chain(stdout_dispatcher) 71 | .chain(file_dispatcher) 72 | .apply()?; 73 | 74 | Ok(()) 75 | } 76 | --------------------------------------------------------------------------------