mirror of
https://github.com/revanced/revanced-patches.git
synced 2025-04-30 14:44:33 +02:00
Compare commits
No commits in common. "main" and "v1.0.0-dev.6" have entirely different histories.
main
...
v1.0.0-dev
@ -1,3 +0,0 @@
|
|||||||
[*.{kt,kts}]
|
|
||||||
ktlint_code_style = intellij_idea
|
|
||||||
ktlint_standard_no-wildcard-imports = disabled
|
|
9
.gitattributes
vendored
9
.gitattributes
vendored
@ -1,9 +0,0 @@
|
|||||||
#
|
|
||||||
# https://help.github.com/articles/dealing-with-line-endings/
|
|
||||||
#
|
|
||||||
# Linux start script should use lf
|
|
||||||
/gradlew text eol=lf
|
|
||||||
|
|
||||||
# These are Windows script files and should use crlf
|
|
||||||
*.bat text eol=crlf
|
|
||||||
|
|
110
.github/ISSUE_TEMPLATE/bug_report.yml
vendored
110
.github/ISSUE_TEMPLATE/bug_report.yml
vendored
@ -1,110 +0,0 @@
|
|||||||
name: 🐞 Bug report
|
|
||||||
description: Report a bug or an issue.
|
|
||||||
title: 'bug: '
|
|
||||||
labels: ['Bug report']
|
|
||||||
body:
|
|
||||||
- type: markdown
|
|
||||||
attributes:
|
|
||||||
value: |
|
|
||||||
<p align="center">
|
|
||||||
<picture>
|
|
||||||
<source
|
|
||||||
width="256px"
|
|
||||||
media="(prefers-color-scheme: dark)"
|
|
||||||
srcset="https://raw.githubusercontent.com/revanced/revanced-patches/main/assets/revanced-headline/revanced-headline-vertical-dark.svg"
|
|
||||||
>
|
|
||||||
<img
|
|
||||||
width="256px"
|
|
||||||
src="https://raw.githubusercontent.com/revanced/revanced-patches/main/assets/revanced-headline/revanced-headline-vertical-light.svg"
|
|
||||||
>
|
|
||||||
</picture>
|
|
||||||
<br>
|
|
||||||
<a href="https://revanced.app/">
|
|
||||||
<picture>
|
|
||||||
<source height="24px" media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/revanced/revanced-patches/main/assets/revanced-logo/revanced-logo.svg" />
|
|
||||||
<img height="24px" src="https://raw.githubusercontent.com/revanced/revanced-patches/main/assets/revanced-logo/revanced-logo.svg" />
|
|
||||||
</picture>
|
|
||||||
</a>
|
|
||||||
<a href="https://github.com/ReVanced">
|
|
||||||
<picture>
|
|
||||||
<source height="24px" media="(prefers-color-scheme: dark)" srcset="https://i.ibb.co/dMMmCrW/Git-Hub-Mark.png" />
|
|
||||||
<img height="24px" src="https://i.ibb.co/9wV3HGF/Git-Hub-Mark-Light.png" />
|
|
||||||
</picture>
|
|
||||||
</a>
|
|
||||||
<a href="http://revanced.app/discord">
|
|
||||||
<picture>
|
|
||||||
<source height="24px" media="(prefers-color-scheme: dark)" srcset="https://user-images.githubusercontent.com/13122796/178032563-d4e084b7-244e-4358-af50-26bde6dd4996.png" />
|
|
||||||
<img height="24px" src="https://user-images.githubusercontent.com/13122796/178032563-d4e084b7-244e-4358-af50-26bde6dd4996.png" />
|
|
||||||
</picture>
|
|
||||||
</a>
|
|
||||||
<a href="https://reddit.com/r/revancedapp">
|
|
||||||
<picture>
|
|
||||||
<source height="24px" media="(prefers-color-scheme: dark)" srcset="https://user-images.githubusercontent.com/13122796/178032351-9d9d5619-8ef7-470a-9eec-2744ece54553.png" />
|
|
||||||
<img height="24px" src="https://user-images.githubusercontent.com/13122796/178032351-9d9d5619-8ef7-470a-9eec-2744ece54553.png" />
|
|
||||||
</picture>
|
|
||||||
</a>
|
|
||||||
<a href="https://t.me/app_revanced">
|
|
||||||
<picture>
|
|
||||||
<source height="24px" media="(prefers-color-scheme: dark)" srcset="https://user-images.githubusercontent.com/13122796/178032213-faf25ab8-0bc3-4a94-a730-b524c96df124.png" />
|
|
||||||
<img height="24px" src="https://user-images.githubusercontent.com/13122796/178032213-faf25ab8-0bc3-4a94-a730-b524c96df124.png" />
|
|
||||||
</picture>
|
|
||||||
</a>
|
|
||||||
<a href="https://x.com/revancedapp">
|
|
||||||
<picture>
|
|
||||||
<source media="(prefers-color-scheme: dark)" srcset="https://user-images.githubusercontent.com/93124920/270180600-7c1b38bf-889b-4d68-bd5e-b9d86f91421a.png">
|
|
||||||
<img height="24px" src="https://user-images.githubusercontent.com/93124920/270108715-d80743fa-b330-4809-b1e6-79fbdc60d09c.png" />
|
|
||||||
</picture>
|
|
||||||
</a>
|
|
||||||
<a href="https://www.youtube.com/@ReVanced">
|
|
||||||
<picture>
|
|
||||||
<source height="24px" media="(prefers-color-scheme: dark)" srcset="https://user-images.githubusercontent.com/13122796/178032714-c51c7492-0666-44ac-99c2-f003a695ab50.png" />
|
|
||||||
<img height="24px" src="https://user-images.githubusercontent.com/13122796/178032714-c51c7492-0666-44ac-99c2-f003a695ab50.png" />
|
|
||||||
</picture>
|
|
||||||
</a>
|
|
||||||
<br>
|
|
||||||
<br>
|
|
||||||
Continuing the legacy of Vanced
|
|
||||||
</p>
|
|
||||||
|
|
||||||
# ReVanced Patches bug report
|
|
||||||
|
|
||||||
Before creating a new bug report, please keep the following in mind:
|
|
||||||
|
|
||||||
- **Do not submit a duplicate bug report**: Search for existing bug reports [here](https://github.com/ReVanced/revanced-patches/issues?q=label%3A%22Bug+report%22).
|
|
||||||
- **Review the contribution guidelines**: Make sure your bug report adheres to it. You can find the guidelines [here](https://github.com/ReVanced/revanced-patches/blob/main/CONTRIBUTING.md).
|
|
||||||
- **Do not use the issue page for support**: If you need help or have questions, check out other platforms on [revanced.app](https://revanced.app).
|
|
||||||
- type: textarea
|
|
||||||
attributes:
|
|
||||||
label: Bug description
|
|
||||||
description: |
|
|
||||||
- Describe your bug in detail
|
|
||||||
- Add steps to reproduce the bug if possible (Step 1. ... Step 2. ...)
|
|
||||||
- Add images and videos if possible
|
|
||||||
- List used patches if applicable
|
|
||||||
validations:
|
|
||||||
required: true
|
|
||||||
- type: textarea
|
|
||||||
attributes:
|
|
||||||
label: Error logs
|
|
||||||
description: Exceptions can be captured by running `logcat | grep AndroidRuntime` in a shell.
|
|
||||||
render: shell
|
|
||||||
- type: textarea
|
|
||||||
attributes:
|
|
||||||
label: Solution
|
|
||||||
description: If applicable, add a possible solution to the bug.
|
|
||||||
- type: textarea
|
|
||||||
attributes:
|
|
||||||
label: Additional context
|
|
||||||
description: Add additional context here.
|
|
||||||
- type: checkboxes
|
|
||||||
id: acknowledgements
|
|
||||||
attributes:
|
|
||||||
label: Acknowledgements
|
|
||||||
description: Your bug report will be closed if you don't follow the checklist below.
|
|
||||||
options:
|
|
||||||
- label: I have checked all open and closed bug reports and this is not a duplicate.
|
|
||||||
required: true
|
|
||||||
- label: I have chosen an appropriate title.
|
|
||||||
required: true
|
|
||||||
- label: All requested information has been provided properly.
|
|
||||||
required: true
|
|
5
.github/ISSUE_TEMPLATE/config.yml
vendored
5
.github/ISSUE_TEMPLATE/config.yml
vendored
@ -1,5 +0,0 @@
|
|||||||
blank_issues_enabled: false
|
|
||||||
contact_links:
|
|
||||||
- name: 🗨 Discussions
|
|
||||||
url: https://github.com/revanced/revanced-suggestions/discussions
|
|
||||||
about: Have something unspecific to ReVanced Patches in mind? Search for or start a new discussion!
|
|
106
.github/ISSUE_TEMPLATE/feature_request.yml
vendored
106
.github/ISSUE_TEMPLATE/feature_request.yml
vendored
@ -1,106 +0,0 @@
|
|||||||
name: ⭐ Feature request
|
|
||||||
description: Create a detailed request for a new feature.
|
|
||||||
title: 'feat: '
|
|
||||||
labels: ['Feature request']
|
|
||||||
body:
|
|
||||||
- type: markdown
|
|
||||||
attributes:
|
|
||||||
value: |
|
|
||||||
<p align="center">
|
|
||||||
<picture>
|
|
||||||
<source
|
|
||||||
width="256px"
|
|
||||||
media="(prefers-color-scheme: dark)"
|
|
||||||
srcset="https://raw.githubusercontent.com/revanced/revanced-patches/main/assets/revanced-headline/revanced-headline-vertical-dark.svg"
|
|
||||||
>
|
|
||||||
<img
|
|
||||||
width="256px"
|
|
||||||
src="https://raw.githubusercontent.com/revanced/revanced-patches/main/assets/revanced-headline/revanced-headline-vertical-light.svg"
|
|
||||||
>
|
|
||||||
</picture>
|
|
||||||
<br>
|
|
||||||
<a href="https://revanced.app/">
|
|
||||||
<picture>
|
|
||||||
<source height="24px" media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/revanced/revanced-patches/main/assets/revanced-logo/revanced-logo.svg" />
|
|
||||||
<img height="24px" src="https://raw.githubusercontent.com/revanced/revanced-patches/main/assets/revanced-logo/revanced-logo.svg" />
|
|
||||||
</picture>
|
|
||||||
</a>
|
|
||||||
<a href="https://github.com/ReVanced">
|
|
||||||
<picture>
|
|
||||||
<source height="24px" media="(prefers-color-scheme: dark)" srcset="https://i.ibb.co/dMMmCrW/Git-Hub-Mark.png" />
|
|
||||||
<img height="24px" src="https://i.ibb.co/9wV3HGF/Git-Hub-Mark-Light.png" />
|
|
||||||
</picture>
|
|
||||||
</a>
|
|
||||||
<a href="http://revanced.app/discord">
|
|
||||||
<picture>
|
|
||||||
<source height="24px" media="(prefers-color-scheme: dark)" srcset="https://user-images.githubusercontent.com/13122796/178032563-d4e084b7-244e-4358-af50-26bde6dd4996.png" />
|
|
||||||
<img height="24px" src="https://user-images.githubusercontent.com/13122796/178032563-d4e084b7-244e-4358-af50-26bde6dd4996.png" />
|
|
||||||
</picture>
|
|
||||||
</a>
|
|
||||||
<a href="https://reddit.com/r/revancedapp">
|
|
||||||
<picture>
|
|
||||||
<source height="24px" media="(prefers-color-scheme: dark)" srcset="https://user-images.githubusercontent.com/13122796/178032351-9d9d5619-8ef7-470a-9eec-2744ece54553.png" />
|
|
||||||
<img height="24px" src="https://user-images.githubusercontent.com/13122796/178032351-9d9d5619-8ef7-470a-9eec-2744ece54553.png" />
|
|
||||||
</picture>
|
|
||||||
</a>
|
|
||||||
<a href="https://t.me/app_revanced">
|
|
||||||
<picture>
|
|
||||||
<source height="24px" media="(prefers-color-scheme: dark)" srcset="https://user-images.githubusercontent.com/13122796/178032213-faf25ab8-0bc3-4a94-a730-b524c96df124.png" />
|
|
||||||
<img height="24px" src="https://user-images.githubusercontent.com/13122796/178032213-faf25ab8-0bc3-4a94-a730-b524c96df124.png" />
|
|
||||||
</picture>
|
|
||||||
</a>
|
|
||||||
<a href="https://x.com/revancedapp">
|
|
||||||
<picture>
|
|
||||||
<source media="(prefers-color-scheme: dark)" srcset="https://user-images.githubusercontent.com/93124920/270180600-7c1b38bf-889b-4d68-bd5e-b9d86f91421a.png">
|
|
||||||
<img height="24px" src="https://user-images.githubusercontent.com/93124920/270108715-d80743fa-b330-4809-b1e6-79fbdc60d09c.png" />
|
|
||||||
</picture>
|
|
||||||
</a>
|
|
||||||
<a href="https://www.youtube.com/@ReVanced">
|
|
||||||
<picture>
|
|
||||||
<source height="24px" media="(prefers-color-scheme: dark)" srcset="https://user-images.githubusercontent.com/13122796/178032714-c51c7492-0666-44ac-99c2-f003a695ab50.png" />
|
|
||||||
<img height="24px" src="https://user-images.githubusercontent.com/13122796/178032714-c51c7492-0666-44ac-99c2-f003a695ab50.png" />
|
|
||||||
</picture>
|
|
||||||
</a>
|
|
||||||
<br>
|
|
||||||
<br>
|
|
||||||
Continuing the legacy of Vanced
|
|
||||||
</p>
|
|
||||||
|
|
||||||
# ReVanced Patches feature request
|
|
||||||
|
|
||||||
Before creating a new feature request, please keep the following in mind:
|
|
||||||
|
|
||||||
- **Do not submit a duplicate feature request**: Search for existing feature requests [here](https://github.com/ReVanced/revanced-patches/issues?q=label%3A%22Feature+request%22).
|
|
||||||
- **Review the contribution guidelines**: Make sure your feature request adheres to it. You can find the guidelines [here](https://github.com/ReVanced/revanced-patches/blob/main/CONTRIBUTING.md).
|
|
||||||
- **Do not use the issue page for support**: If you need help or have questions, check out other platforms on [revanced.app](https://revanced.app).
|
|
||||||
- type: textarea
|
|
||||||
attributes:
|
|
||||||
label: Feature description
|
|
||||||
description: |
|
|
||||||
- Describe your feature in detail
|
|
||||||
- Add images, videos, links, examples, references, etc. if possible
|
|
||||||
- Add the target application name in case you request a new patch
|
|
||||||
- type: textarea
|
|
||||||
attributes:
|
|
||||||
label: Motivation
|
|
||||||
description: |
|
|
||||||
A strong motivation is necessary for a feature request to be considered.
|
|
||||||
|
|
||||||
- Why should this feature be implemented?
|
|
||||||
- What is the explicit use case?
|
|
||||||
- What are the benefits?
|
|
||||||
- What makes this feature important?
|
|
||||||
validations:
|
|
||||||
required: true
|
|
||||||
- type: checkboxes
|
|
||||||
id: acknowledgements
|
|
||||||
attributes:
|
|
||||||
label: Acknowledgements
|
|
||||||
description: Your feature request will be closed if you don't follow the checklist below.
|
|
||||||
options:
|
|
||||||
- label: I have checked all open and closed feature requests and this is not a duplicate
|
|
||||||
required: true
|
|
||||||
- label: I have chosen an appropriate title.
|
|
||||||
required: true
|
|
||||||
- label: All requested information has been provided properly.
|
|
||||||
required: true
|
|
2
.github/config.yml
vendored
2
.github/config.yml
vendored
@ -1,2 +0,0 @@
|
|||||||
firstPRMergeComment: >
|
|
||||||
Thank you for contributing to ReVanced. Join us on [Discord](https://revanced.app/discord) to receive a role for your contribution.
|
|
22
.github/dependabot.yml
vendored
22
.github/dependabot.yml
vendored
@ -1,22 +0,0 @@
|
|||||||
version: 2
|
|
||||||
updates:
|
|
||||||
- package-ecosystem: github-actions
|
|
||||||
labels: []
|
|
||||||
directory: /
|
|
||||||
target-branch: dev
|
|
||||||
schedule:
|
|
||||||
interval: monthly
|
|
||||||
|
|
||||||
- package-ecosystem: npm
|
|
||||||
labels: []
|
|
||||||
directory: /
|
|
||||||
target-branch: dev
|
|
||||||
schedule:
|
|
||||||
interval: monthly
|
|
||||||
|
|
||||||
- package-ecosystem: gradle
|
|
||||||
labels: []
|
|
||||||
directory: /
|
|
||||||
target-branch: dev
|
|
||||||
schedule:
|
|
||||||
interval: monthly
|
|
37
.github/workflows/build_pull_request.yml
vendored
37
.github/workflows/build_pull_request.yml
vendored
@ -1,37 +0,0 @@
|
|||||||
name: Build pull request
|
|
||||||
|
|
||||||
on:
|
|
||||||
workflow_dispatch:
|
|
||||||
pull_request:
|
|
||||||
branches:
|
|
||||||
- dev
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
release:
|
|
||||||
name: Build
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
with:
|
|
||||||
fetch-depth: 0
|
|
||||||
|
|
||||||
- name: Setup Java
|
|
||||||
uses: actions/setup-java@v4
|
|
||||||
with:
|
|
||||||
distribution: "temurin"
|
|
||||||
java-version: "17"
|
|
||||||
|
|
||||||
- name: Cache Gradle
|
|
||||||
uses: burrunan/gradle-cache-action@v1
|
|
||||||
|
|
||||||
- name: Build
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
run: ./gradlew :patches:buildAndroid --no-daemon
|
|
||||||
|
|
||||||
- name: Upload artifacts
|
|
||||||
uses: actions/upload-artifact@v4
|
|
||||||
with:
|
|
||||||
name: revanced-patches
|
|
||||||
path: patches/build/libs
|
|
31
.github/workflows/open_pull_request.yml
vendored
31
.github/workflows/open_pull_request.yml
vendored
@ -1,31 +0,0 @@
|
|||||||
name: Open a PR to main
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- dev
|
|
||||||
workflow_dispatch:
|
|
||||||
|
|
||||||
env:
|
|
||||||
MESSAGE: Merge branch `${{ github.head_ref || github.ref_name }}` to `main`
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
pull-request:
|
|
||||||
name: Open pull request
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Open pull request
|
|
||||||
uses: repo-sync/pull-request@v2
|
|
||||||
with:
|
|
||||||
destination_branch: main
|
|
||||||
pr_title: 'chore: ${{ env.MESSAGE }}'
|
|
||||||
pr_body: |
|
|
||||||
This pull request will ${{ env.MESSAGE }}.
|
|
||||||
|
|
||||||
## Before merging this PR
|
|
||||||
|
|
||||||
- [ ] Pull translations from Crowdin
|
|
||||||
pr_draft: true
|
|
44
.github/workflows/pull_strings.yml
vendored
44
.github/workflows/pull_strings.yml
vendored
@ -1,44 +0,0 @@
|
|||||||
name: Pull strings
|
|
||||||
|
|
||||||
on:
|
|
||||||
schedule:
|
|
||||||
- cron: "0 */12 * * *"
|
|
||||||
workflow_dispatch:
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
pull:
|
|
||||||
name: Pull strings
|
|
||||||
permissions:
|
|
||||||
contents: write
|
|
||||||
pull-requests: write
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
with:
|
|
||||||
ref: dev
|
|
||||||
fetch-depth: 0
|
|
||||||
clean: true
|
|
||||||
|
|
||||||
- name: Pull strings
|
|
||||||
uses: crowdin/github-action@v2
|
|
||||||
with:
|
|
||||||
config: crowdin.yml
|
|
||||||
upload_sources: false
|
|
||||||
download_translations: true
|
|
||||||
skip_ref_checkout: true
|
|
||||||
localization_branch_name: feat/translations
|
|
||||||
create_pull_request: false
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
CROWDIN_PROJECT_ID: ${{ secrets.CROWDIN_PROJECT_ID }}
|
|
||||||
CROWDIN_PERSONAL_TOKEN: ${{ secrets.CROWDIN_PERSONAL_TOKEN }}
|
|
||||||
|
|
||||||
- name: Open pull request
|
|
||||||
if: github.event_name == 'workflow_dispatch'
|
|
||||||
uses: repo-sync/pull-request@v2
|
|
||||||
with:
|
|
||||||
source_branch: feat/translations
|
|
||||||
destination_branch: dev
|
|
||||||
pr_title: "chore: Sync translations"
|
|
||||||
pr_body: "Sync translations from [crowdin.com/project/revanced](https://crowdin.com/project/revanced)"
|
|
33
.github/workflows/push_strings.yml
vendored
33
.github/workflows/push_strings.yml
vendored
@ -1,33 +0,0 @@
|
|||||||
name: Push strings
|
|
||||||
|
|
||||||
on:
|
|
||||||
workflow_dispatch:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- dev
|
|
||||||
paths:
|
|
||||||
- patches/src/main/resources/addresources/values/strings.xml
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
push:
|
|
||||||
name: Push strings
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
with:
|
|
||||||
fetch-depth: 0
|
|
||||||
|
|
||||||
- name: Preprocess strings
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
run: ./gradlew clean preprocessCrowdinStrings
|
|
||||||
|
|
||||||
- name: Push strings
|
|
||||||
uses: crowdin/github-action@v2
|
|
||||||
with:
|
|
||||||
config: crowdin.yml
|
|
||||||
upload_sources: true
|
|
||||||
env:
|
|
||||||
CROWDIN_PROJECT_ID: ${{ secrets.CROWDIN_PROJECT_ID }}
|
|
||||||
CROWDIN_PERSONAL_TOKEN: ${{ secrets.CROWDIN_PERSONAL_TOKEN }}
|
|
58
.github/workflows/release.yml
vendored
58
.github/workflows/release.yml
vendored
@ -1,59 +1,41 @@
|
|||||||
name: Release
|
name: Release
|
||||||
|
|
||||||
on:
|
on:
|
||||||
workflow_dispatch:
|
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
- dev
|
- dev
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
- dev
|
||||||
jobs:
|
jobs:
|
||||||
release:
|
release:
|
||||||
name: Release
|
name: Release
|
||||||
permissions:
|
|
||||||
contents: write
|
|
||||||
packages: write
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v2
|
||||||
with:
|
with:
|
||||||
# Make sure the release step uses its own credentials:
|
|
||||||
# https://github.com/cycjimmy/semantic-release-action#private-packages
|
|
||||||
persist-credentials: false
|
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
|
- name: Setup JDK
|
||||||
- name: Setup Java
|
uses: actions/setup-java@v2
|
||||||
uses: actions/setup-java@v4
|
|
||||||
with:
|
with:
|
||||||
distribution: "temurin"
|
java-version: '8'
|
||||||
java-version: "17"
|
distribution: 'adopt'
|
||||||
|
cache: gradle
|
||||||
- name: Cache Gradle
|
|
||||||
uses: burrunan/gradle-cache-action@v1
|
|
||||||
|
|
||||||
- name: Build
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
run: ./gradlew :patches:buildAndroid clean
|
|
||||||
|
|
||||||
- name: Setup Node.js
|
- name: Setup Node.js
|
||||||
uses: actions/setup-node@v4
|
uses: actions/setup-node@v2
|
||||||
with:
|
with:
|
||||||
node-version: "lts/*"
|
node-version: "lts/*"
|
||||||
cache: 'npm'
|
- name: Make gradlew executable
|
||||||
|
run: chmod +x gradlew
|
||||||
- name: Install dependencies
|
- name: Build with Gradle
|
||||||
run: npm install
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
- name: Import GPG key
|
run: ./gradlew build
|
||||||
uses: crazy-max/ghaction-import-gpg@v6
|
- name: Setup semantic-release
|
||||||
with:
|
run: npm install -g semantic-release @semantic-release/git @semantic-release/changelog gradle-semantic-release-plugin -D
|
||||||
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
|
|
||||||
passphrase: ${{ secrets.GPG_PASSPHRASE }}
|
|
||||||
fingerprint: ${{ vars.GPG_FINGERPRINT }}
|
|
||||||
|
|
||||||
- name: Release
|
- name: Release
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
run: npm exec semantic-release
|
run: npx semantic-release
|
||||||
|
18
.github/workflows/update-gradle-wrapper.yml
vendored
18
.github/workflows/update-gradle-wrapper.yml
vendored
@ -1,18 +0,0 @@
|
|||||||
name: Update Gradle wrapper
|
|
||||||
|
|
||||||
on:
|
|
||||||
schedule:
|
|
||||||
- cron: "0 0 1 * *"
|
|
||||||
workflow_dispatch:
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
update:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Update Gradle Wrapper
|
|
||||||
uses: gradle-update/update-gradle-wrapper-action@v1
|
|
||||||
with:
|
|
||||||
target-branch: dev
|
|
12
.gitignore
vendored
12
.gitignore
vendored
@ -115,15 +115,3 @@ gradle-app.setting
|
|||||||
|
|
||||||
# Potentially copyrighted test APK
|
# Potentially copyrighted test APK
|
||||||
*.apk
|
*.apk
|
||||||
|
|
||||||
# Ignore vscode config
|
|
||||||
.vscode/
|
|
||||||
|
|
||||||
# Dependency directories
|
|
||||||
node_modules/
|
|
||||||
|
|
||||||
# Gradle properties, due to Github token
|
|
||||||
./gradle.properties
|
|
||||||
|
|
||||||
# One package is called the same as the Gradle build folder
|
|
||||||
!**/src/**/build/
|
|
1
.idea/.gitignore
generated
vendored
1
.idea/.gitignore
generated
vendored
@ -6,4 +6,3 @@
|
|||||||
/dataSources.local.xml
|
/dataSources.local.xml
|
||||||
# Editor-based HTTP Client requests
|
# Editor-based HTTP Client requests
|
||||||
/httpRequests/
|
/httpRequests/
|
||||||
/kotlinc.xml
|
|
||||||
|
2
.idea/misc.xml
generated
2
.idea/misc.xml
generated
@ -4,5 +4,5 @@
|
|||||||
<component name="FrameworkDetectionExcludesConfiguration">
|
<component name="FrameworkDetectionExcludesConfiguration">
|
||||||
<file type="web" url="file://$PROJECT_DIR$" />
|
<file type="web" url="file://$PROJECT_DIR$" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="azul-17" project-jdk-type="JavaSDK" />
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK" />
|
||||||
</project>
|
</project>
|
32
.releaserc
32
.releaserc
@ -7,13 +7,7 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"plugins": [
|
"plugins": [
|
||||||
[
|
"@semantic-release/commit-analyzer",
|
||||||
"@semantic-release/commit-analyzer", {
|
|
||||||
"releaseRules": [
|
|
||||||
{ "type": "build", "scope": "Needs bump", "release": "patch" }
|
|
||||||
]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"@semantic-release/release-notes-generator",
|
"@semantic-release/release-notes-generator",
|
||||||
"@semantic-release/changelog",
|
"@semantic-release/changelog",
|
||||||
"gradle-semantic-release-plugin",
|
"gradle-semantic-release-plugin",
|
||||||
@ -22,28 +16,10 @@
|
|||||||
{
|
{
|
||||||
"assets": [
|
"assets": [
|
||||||
"CHANGELOG.md",
|
"CHANGELOG.md",
|
||||||
"gradle.properties",
|
"gradle.properties"
|
||||||
],
|
]
|
||||||
"message": "chore: Release v${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
[
|
"@semantic-release/github"
|
||||||
"@semantic-release/github",
|
|
||||||
{
|
|
||||||
"assets": [
|
|
||||||
{
|
|
||||||
"path": "patches/build/libs/patches-!(*sources*|*javadoc*).rvp?(.asc)"
|
|
||||||
},
|
|
||||||
],
|
|
||||||
successComment: false
|
|
||||||
}
|
|
||||||
],
|
|
||||||
[
|
|
||||||
"@saithodev/semantic-release-backmerge",
|
|
||||||
{
|
|
||||||
backmergeBranches: [{"from": "main", "to": "dev"}],
|
|
||||||
clearWorkspace: true
|
|
||||||
}
|
|
||||||
]
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
11071
CHANGELOG.md
11071
CHANGELOG.md
File diff suppressed because it is too large
Load Diff
128
CONTRIBUTING.md
128
CONTRIBUTING.md
@ -1,128 +0,0 @@
|
|||||||
<p align="center">
|
|
||||||
<picture>
|
|
||||||
<source
|
|
||||||
width="256px"
|
|
||||||
media="(prefers-color-scheme: dark)"
|
|
||||||
srcset="assets/revanced-headline/revanced-headline-vertical-dark.svg"
|
|
||||||
>
|
|
||||||
<img
|
|
||||||
width="256px"
|
|
||||||
src="assets/revanced-headline/revanced-headline-vertical-light.svg"
|
|
||||||
>
|
|
||||||
</picture>
|
|
||||||
<br>
|
|
||||||
<a href="https://revanced.app/">
|
|
||||||
<picture>
|
|
||||||
<source height="24px" media="(prefers-color-scheme: dark)" srcset="assets/revanced-logo/revanced-logo.svg" />
|
|
||||||
<img height="24px" src="assets/revanced-logo/revanced-logo.svg" />
|
|
||||||
</picture>
|
|
||||||
</a>
|
|
||||||
<a href="https://github.com/ReVanced">
|
|
||||||
<picture>
|
|
||||||
<source height="24px" media="(prefers-color-scheme: dark)" srcset="https://i.ibb.co/dMMmCrW/Git-Hub-Mark.png" />
|
|
||||||
<img height="24px" src="https://i.ibb.co/9wV3HGF/Git-Hub-Mark-Light.png" />
|
|
||||||
</picture>
|
|
||||||
</a>
|
|
||||||
<a href="http://revanced.app/discord">
|
|
||||||
<picture>
|
|
||||||
<source height="24px" media="(prefers-color-scheme: dark)" srcset="https://user-images.githubusercontent.com/13122796/178032563-d4e084b7-244e-4358-af50-26bde6dd4996.png" />
|
|
||||||
<img height="24px" src="https://user-images.githubusercontent.com/13122796/178032563-d4e084b7-244e-4358-af50-26bde6dd4996.png" />
|
|
||||||
</picture>
|
|
||||||
</a>
|
|
||||||
<a href="https://reddit.com/r/revancedapp">
|
|
||||||
<picture>
|
|
||||||
<source height="24px" media="(prefers-color-scheme: dark)" srcset="https://user-images.githubusercontent.com/13122796/178032351-9d9d5619-8ef7-470a-9eec-2744ece54553.png" />
|
|
||||||
<img height="24px" src="https://user-images.githubusercontent.com/13122796/178032351-9d9d5619-8ef7-470a-9eec-2744ece54553.png" />
|
|
||||||
</picture>
|
|
||||||
</a>
|
|
||||||
<a href="https://t.me/app_revanced">
|
|
||||||
<picture>
|
|
||||||
<source height="24px" media="(prefers-color-scheme: dark)" srcset="https://user-images.githubusercontent.com/13122796/178032213-faf25ab8-0bc3-4a94-a730-b524c96df124.png" />
|
|
||||||
<img height="24px" src="https://user-images.githubusercontent.com/13122796/178032213-faf25ab8-0bc3-4a94-a730-b524c96df124.png" />
|
|
||||||
</picture>
|
|
||||||
</a>
|
|
||||||
<a href="https://x.com/revancedapp">
|
|
||||||
<picture>
|
|
||||||
<source media="(prefers-color-scheme: dark)" srcset="https://user-images.githubusercontent.com/93124920/270180600-7c1b38bf-889b-4d68-bd5e-b9d86f91421a.png">
|
|
||||||
<img height="24px" src="https://user-images.githubusercontent.com/93124920/270108715-d80743fa-b330-4809-b1e6-79fbdc60d09c.png" />
|
|
||||||
</picture>
|
|
||||||
</a>
|
|
||||||
<a href="https://www.youtube.com/@ReVanced">
|
|
||||||
<picture>
|
|
||||||
<source height="24px" media="(prefers-color-scheme: dark)" srcset="https://user-images.githubusercontent.com/13122796/178032714-c51c7492-0666-44ac-99c2-f003a695ab50.png" />
|
|
||||||
<img height="24px" src="https://user-images.githubusercontent.com/13122796/178032714-c51c7492-0666-44ac-99c2-f003a695ab50.png" />
|
|
||||||
</picture>
|
|
||||||
</a>
|
|
||||||
<br>
|
|
||||||
<br>
|
|
||||||
Continuing the legacy of Vanced
|
|
||||||
</p>
|
|
||||||
|
|
||||||
# 👋 Contribution guidelines
|
|
||||||
|
|
||||||
This document describes how to contribute to ReVanced Patches.
|
|
||||||
|
|
||||||
## 📖 Resources to help you get started
|
|
||||||
|
|
||||||
* The [documentation](https://github.com/ReVanced/revanced-patcher/tree/main/docs) contains the fundamentals
|
|
||||||
of ReVanced Patcher and how to use ReVanced Patcher to create patches
|
|
||||||
* [Our backlog](https://github.com/orgs/ReVanced/projects/12) is where we keep track of what we're working on
|
|
||||||
* [Issues](https://github.com/ReVanced/revanced-patches/issues) are where we keep track of bugs and feature requests
|
|
||||||
|
|
||||||
## 🙏 Submitting a feature request
|
|
||||||
|
|
||||||
Features can be requested by opening an issue using the
|
|
||||||
[Feature request issue template](https://github.com/ReVanced/revanced-patches/issues/new?assignees=&labels=Feature+request&projects=&template=feature_request.yml&title=feat%3A+).
|
|
||||||
|
|
||||||
> **Note**
|
|
||||||
> Requests can be accepted or rejected at the discretion of maintainers of ReVanced Patches.
|
|
||||||
> Good motivation has to be provided for a request to be accepted.
|
|
||||||
|
|
||||||
## 🐞 Submitting a bug report
|
|
||||||
|
|
||||||
If you encounter a bug while using ReVanced Patches, open an issue using the
|
|
||||||
[Bug report issue template](https://github.com/ReVanced/revanced-patches/issues/new?assignees=&labels=Bug+report&projects=&template=bug_report.yml&title=bug%3A+).
|
|
||||||
|
|
||||||
## 🌐 Submitting translations
|
|
||||||
|
|
||||||
You can contribute translations at [translate.revanced.app](https://translate.revanced.app).
|
|
||||||
|
|
||||||
## 🧑⚖️ Guidelines for requesting or contributing patches
|
|
||||||
|
|
||||||
To maintain a high-quality and ethical collection of patches, the following guidelines for requesting
|
|
||||||
or contributing patches are effective as of September 14, 2023. Any patches present prior to this date
|
|
||||||
are unaffected by this change.
|
|
||||||
|
|
||||||
> **Note**
|
|
||||||
> We generally adhere to the guidelines outlined below. However, we may make exceptions
|
|
||||||
> in specific cases based on our discretion. Pull requests for patches that deviate from the guidelines
|
|
||||||
> will be evaluated individually. While a patch may not align with our general guidelines,
|
|
||||||
> we will consider its acceptance on a case-by-case basis, taking into account its impact on user experience
|
|
||||||
> and ethical considerations. We reserve the right to make exceptions for patches that provide significant value.
|
|
||||||
|
|
||||||
✅ Examples for acceptable patches include:
|
|
||||||
|
|
||||||
* Customizations: Feel free to contribute patches that allow users to personalize their experience
|
|
||||||
* Ad-Blocking: Patches aimed at enhancing user privacy and blocking intrusive advertisements are appreciated
|
|
||||||
* Feature additions: Patches that add new features or change behaviour to the app are welcome
|
|
||||||
|
|
||||||
❌ Examples for unacceptable patches include:
|
|
||||||
|
|
||||||
* Payment circumvention: We do not accept patches that exist solely to bypass payment for the app or any of its features
|
|
||||||
* Malicious patches: Patches that are malicious in nature are not allowed
|
|
||||||
|
|
||||||
## 📝 How to contribute
|
|
||||||
|
|
||||||
1. Before contributing, it is recommended to open an issue to discuss your change
|
|
||||||
with the maintainers of ReVanced Patches. This will help you determine whether your change is acceptable
|
|
||||||
and whether it is worth your time to implement it
|
|
||||||
2. Development happens on the `dev` branch. Fork the repository and create your branch from `dev`
|
|
||||||
3. Commit your changes. In case you are contributing a new patch, make sure to follow the conventions for patches
|
|
||||||
described in the [ReVanced Patcher documentation](https://github.com/ReVanced/revanced-patcher/tree/main/docs)
|
|
||||||
4. Submit a pull request to the `dev` branch of the repository and reference issues
|
|
||||||
that your pull request closes in the description of your pull request
|
|
||||||
5. Our team will review your pull request and provide feedback. Once your pull request is approved,
|
|
||||||
it will be merged into the `dev` branch and will be included in the next release of ReVanced Patches
|
|
||||||
|
|
||||||
❤️ Thank you for considering contributing to ReVanced Patches,
|
|
||||||
ReVanced
|
|
107
README.md
107
README.md
@ -1,105 +1,2 @@
|
|||||||
<p align="center">
|
# revanced-patches
|
||||||
<picture>
|
Repo for all ReVanced patches
|
||||||
<source
|
|
||||||
width="256px"
|
|
||||||
media="(prefers-color-scheme: dark)"
|
|
||||||
srcset="assets/revanced-headline/revanced-headline-vertical-dark.svg"
|
|
||||||
>
|
|
||||||
<img
|
|
||||||
width="256px"
|
|
||||||
src="assets/revanced-headline/revanced-headline-vertical-light.svg"
|
|
||||||
>
|
|
||||||
</picture>
|
|
||||||
<br>
|
|
||||||
<a href="https://revanced.app/">
|
|
||||||
<picture>
|
|
||||||
<source height="24px" media="(prefers-color-scheme: dark)" srcset="assets/revanced-logo/revanced-logo.svg" />
|
|
||||||
<img height="24px" src="assets/revanced-logo/revanced-logo.svg" />
|
|
||||||
</picture>
|
|
||||||
</a>
|
|
||||||
<a href="https://github.com/ReVanced">
|
|
||||||
<picture>
|
|
||||||
<source height="24px" media="(prefers-color-scheme: dark)" srcset="https://i.ibb.co/dMMmCrW/Git-Hub-Mark.png" />
|
|
||||||
<img height="24px" src="https://i.ibb.co/9wV3HGF/Git-Hub-Mark-Light.png" />
|
|
||||||
</picture>
|
|
||||||
</a>
|
|
||||||
<a href="http://revanced.app/discord">
|
|
||||||
<picture>
|
|
||||||
<source height="24px" media="(prefers-color-scheme: dark)" srcset="https://user-images.githubusercontent.com/13122796/178032563-d4e084b7-244e-4358-af50-26bde6dd4996.png" />
|
|
||||||
<img height="24px" src="https://user-images.githubusercontent.com/13122796/178032563-d4e084b7-244e-4358-af50-26bde6dd4996.png" />
|
|
||||||
</picture>
|
|
||||||
</a>
|
|
||||||
<a href="https://reddit.com/r/revancedapp">
|
|
||||||
<picture>
|
|
||||||
<source height="24px" media="(prefers-color-scheme: dark)" srcset="https://user-images.githubusercontent.com/13122796/178032351-9d9d5619-8ef7-470a-9eec-2744ece54553.png" />
|
|
||||||
<img height="24px" src="https://user-images.githubusercontent.com/13122796/178032351-9d9d5619-8ef7-470a-9eec-2744ece54553.png" />
|
|
||||||
</picture>
|
|
||||||
</a>
|
|
||||||
<a href="https://t.me/app_revanced">
|
|
||||||
<picture>
|
|
||||||
<source height="24px" media="(prefers-color-scheme: dark)" srcset="https://user-images.githubusercontent.com/13122796/178032213-faf25ab8-0bc3-4a94-a730-b524c96df124.png" />
|
|
||||||
<img height="24px" src="https://user-images.githubusercontent.com/13122796/178032213-faf25ab8-0bc3-4a94-a730-b524c96df124.png" />
|
|
||||||
</picture>
|
|
||||||
</a>
|
|
||||||
<a href="https://x.com/revancedapp">
|
|
||||||
<picture>
|
|
||||||
<source media="(prefers-color-scheme: dark)" srcset="https://user-images.githubusercontent.com/93124920/270180600-7c1b38bf-889b-4d68-bd5e-b9d86f91421a.png">
|
|
||||||
<img height="24px" src="https://user-images.githubusercontent.com/93124920/270108715-d80743fa-b330-4809-b1e6-79fbdc60d09c.png" />
|
|
||||||
</picture>
|
|
||||||
</a>
|
|
||||||
<a href="https://www.youtube.com/@ReVanced">
|
|
||||||
<picture>
|
|
||||||
<source height="24px" media="(prefers-color-scheme: dark)" srcset="https://user-images.githubusercontent.com/13122796/178032714-c51c7492-0666-44ac-99c2-f003a695ab50.png" />
|
|
||||||
<img height="24px" src="https://user-images.githubusercontent.com/13122796/178032714-c51c7492-0666-44ac-99c2-f003a695ab50.png" />
|
|
||||||
</picture>
|
|
||||||
</a>
|
|
||||||
<br>
|
|
||||||
<br>
|
|
||||||
Continuing the legacy of Vanced
|
|
||||||
</p>
|
|
||||||
|
|
||||||
# 🧩 ReVanced Patches
|
|
||||||
|
|
||||||

|
|
||||||

|
|
||||||
|
|
||||||
This repository contains a collection of ReVanced Patches.
|
|
||||||
|
|
||||||
## ❓ About
|
|
||||||
|
|
||||||
Patches are small modifications to Android apps that allow you to change the behavior of or add new features,
|
|
||||||
block ads, customize the appearance, and much more.
|
|
||||||
|
|
||||||
## 💪 Features
|
|
||||||
|
|
||||||
Some of the features the patches provide are:
|
|
||||||
|
|
||||||
* 🚫 **Block ads**: Say goodbye to ads
|
|
||||||
* ⭐ **Customize your app**: Personalize the appearance of apps with various layouts and themes
|
|
||||||
* 🪄 **Add new features**: Extend the functionality of apps with lots of new features
|
|
||||||
* ⚙️ **Miscellaneous and general purpose**: Rename packages, enable debugging, disable screen capture restrictions,
|
|
||||||
export activities, etc.
|
|
||||||
* ✨ **And much more!**
|
|
||||||
|
|
||||||
For a complete list of all available patches, visit [revanced.app/patches](https://revanced.app/patches).
|
|
||||||
|
|
||||||
## 🚀 How to get started
|
|
||||||
|
|
||||||
You can use [ReVanced CLI](https://github.com/ReVanced/revanced-cli) or [ReVanced Manager](https://github.com/ReVanced/revanced-manager) to use ReVanced Patches.
|
|
||||||
|
|
||||||
## 📚 Everything else
|
|
||||||
|
|
||||||
### 📙 Contributing
|
|
||||||
|
|
||||||
Thank you for considering contributing to ReVanced Patches. You can find the contribution guidelines [here](CONTRIBUTING.md).
|
|
||||||
|
|
||||||
### 🛠️ Building
|
|
||||||
|
|
||||||
To build ReVanced Patches, you can follow the [ReVanced documentation](https://github.com/ReVanced/revanced-documentation).
|
|
||||||
|
|
||||||
## 📜 Licence
|
|
||||||
|
|
||||||
ReVanced Patches is licensed under the GPLv3 license. Please see the [license file](LICENSE) for more information.
|
|
||||||
[tl;dr](https://www.tldrlegal.com/license/gnu-general-public-license-v3-gpl-3) you may copy, distribute and modify ReVanced Patches as long as you track changes/dates in source files.
|
|
||||||
Any modifications to ReVanced Patches must also be made available under the GPL,
|
|
||||||
along with build & install instructions.
|
|
||||||
|
File diff suppressed because one or more lines are too long
Before Width: | Height: | Size: 11 KiB |
File diff suppressed because one or more lines are too long
Before Width: | Height: | Size: 11 KiB |
@ -1 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg width="100%" height="100%" viewBox="0 0 800 800" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" xmlns:serif="http://www.serif.com/" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2;"><g id="Logo"><g id="Ring"><circle id="Ring-Background" serif:id="Ring Background" cx="400" cy="400" r="400" style="fill:#1b1b1b;"/><path id="Ring1" serif:id="Ring" d="M400,0c220.766,0 400,179.234 400,400c-0,220.766 -179.234,400 -400,400c-220.766,-0 -400,-179.234 -400,-400c0,-220.766 179.234,-400 400,-400Zm-0,36c200.897,-0 364,163.103 364,364c0,200.897 -163.103,364 -364,364c-200.897,0 -364,-163.103 -364,-364c-0,-200.897 163.103,-364 364,-364Z" style="fill:url(#_Linear1);"/></g><g id="Shape"><path id="V-Shape" serif:id="V Shape" d="M538.74,269.872c1.481,-3.382 1.157,-7.283 -0.863,-10.373c-2.021,-3.091 -5.464,-4.954 -9.156,-4.954c-5.148,0 -10.435,0 -14.165,0c-3.1,0 -5.907,1.834 -7.153,4.672c-12.468,28.396 -78.273,178.273 -100.25,228.328c-1.246,2.838 -4.053,4.671 -7.154,4.671c-3.1,0 -5.907,-1.833 -7.153,-4.671c-21.977,-50.055 -87.782,-199.932 -100.25,-228.328c-1.246,-2.838 -4.053,-4.672 -7.153,-4.672c-3.73,0 -9.017,0 -14.164,0c-3.693,0 -7.135,1.863 -9.156,4.954c-2.02,3.09 -2.344,6.991 -0.863,10.373c23.557,53.766 101.872,232.519 117.871,269.034c1.743,3.979 5.674,6.549 10.018,6.549c6.293,-0 15.408,-0 21.701,-0c4.344,-0 8.275,-2.57 10.018,-6.549c15.999,-36.515 94.315,-215.268 117.872,-269.034Z" style="fill:#fff;"/><path id="Diamond" d="M408.119,395.312c-1.675,2.901 -4.77,4.688 -8.119,4.688c-3.349,-0 -6.444,-1.787 -8.119,-4.688c-16.997,-29.44 -56.156,-97.264 -73.153,-126.704c-1.675,-2.901 -1.675,-6.474 0,-9.375c1.675,-2.901 4.77,-4.688 8.119,-4.688c33.995,0 112.311,0 146.306,0c3.349,0 6.444,1.787 8.119,4.688c1.675,2.901 1.675,6.474 -0,9.375c-16.997,29.44 -56.156,97.264 -73.153,126.704Z" style="fill:url(#_Linear2);"/></g></g><defs><linearGradient id="_Linear1" x1="0" y1="0" x2="1" y2="0" gradientUnits="userSpaceOnUse" gradientTransform="matrix(4.89859e-14,800,-800,4.89859e-14,400.001,3.31681e-10)"><stop offset="0" style="stop-color:#f04e98;stop-opacity:1"/><stop offset="0.5" style="stop-color:#5f65d4;stop-opacity:1"/><stop offset="1" style="stop-color:#4e98f0;stop-opacity:1"/></linearGradient><linearGradient id="_Linear2" x1="0" y1="0" x2="1" y2="0" gradientUnits="userSpaceOnUse" gradientTransform="matrix(1.77155e-14,289.317,-282.535,1.73003e-14,400,254.545)"><stop offset="0" style="stop-color:#f04e98;stop-opacity:1"/><stop offset="0.5" style="stop-color:#5f65d4;stop-opacity:1"/><stop offset="1" style="stop-color:#4e98f0;stop-opacity:1"/></linearGradient></defs></svg>
|
|
Before Width: | Height: | Size: 2.8 KiB |
59
build.gradle.kts
Normal file
59
build.gradle.kts
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
plugins {
|
||||||
|
kotlin("jvm") version "1.6.20"
|
||||||
|
java
|
||||||
|
`maven-publish`
|
||||||
|
}
|
||||||
|
|
||||||
|
group = "app.revanced"
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
mavenCentral()
|
||||||
|
mavenLocal()
|
||||||
|
maven {
|
||||||
|
url = uri("https://maven.pkg.github.com/revanced/revanced-patcher") // note the "r"!
|
||||||
|
credentials {
|
||||||
|
// DO NOT set these variables in the project's gradle.properties.
|
||||||
|
// Instead, you should set them in:
|
||||||
|
// Windows: %homepath%\.gradle\gradle.properties
|
||||||
|
// Linux: ~/.gradle/gradle.properties
|
||||||
|
username = project.findProperty("gpr.user") as String? ?: System.getenv("GITHUB_ACTOR") // DO NOT CHANGE!
|
||||||
|
password = project.findProperty("gpr.key") as String? ?: System.getenv("GITHUB_TOKEN") // DO NOT CHANGE!
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation(kotlin("stdlib"))
|
||||||
|
testImplementation(kotlin("test"))
|
||||||
|
|
||||||
|
implementation("app.revanced:revanced-patcher:1.0.0-dev.9")
|
||||||
|
}
|
||||||
|
|
||||||
|
java {
|
||||||
|
withSourcesJar()
|
||||||
|
withJavadocJar()
|
||||||
|
}
|
||||||
|
|
||||||
|
val isGitHubCI = System.getenv("GITHUB_ACTOR") != null
|
||||||
|
|
||||||
|
publishing {
|
||||||
|
repositories {
|
||||||
|
if (isGitHubCI) {
|
||||||
|
maven {
|
||||||
|
name = "GitHubPackages"
|
||||||
|
url = uri("https://maven.pkg.github.com/revanced/revanced-patches") // note the "s"!
|
||||||
|
credentials {
|
||||||
|
username = System.getenv("GITHUB_ACTOR")
|
||||||
|
password = System.getenv("GITHUB_TOKEN")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
mavenLocal()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
publications {
|
||||||
|
register<MavenPublication>("gpr") {
|
||||||
|
from(components["java"])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,8 +0,0 @@
|
|||||||
project_id_env: "CROWDIN_PROJECT_ID"
|
|
||||||
api_token_env: "CROWDIN_PERSONAL_TOKEN"
|
|
||||||
|
|
||||||
preserve_hierarchy: false
|
|
||||||
files:
|
|
||||||
- source: patches/src/main/resources/addresources/values/strings.xml
|
|
||||||
translation: patches/src/main/resources/addresources/values-%android_code%/strings.xml
|
|
||||||
skip_untranslated_strings: true
|
|
@ -1,16 +0,0 @@
|
|||||||
android {
|
|
||||||
namespace = "app.revanced.extension"
|
|
||||||
|
|
||||||
defaultConfig {
|
|
||||||
minSdk = 21
|
|
||||||
}
|
|
||||||
|
|
||||||
compileOptions {
|
|
||||||
sourceCompatibility = JavaVersion.VERSION_11
|
|
||||||
targetCompatibility = JavaVersion.VERSION_11
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
compileOnly(libs.annotation)
|
|
||||||
}
|
|
@ -1 +0,0 @@
|
|||||||
<manifest/>
|
|
@ -1,28 +0,0 @@
|
|||||||
package app.revanced.extension.all.misc.hide.adb;
|
|
||||||
|
|
||||||
import android.content.ContentResolver;
|
|
||||||
import android.provider.Settings;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
public final class HideAdbPatch {
|
|
||||||
private static final List<String> SPOOF_SETTINGS = Arrays.asList("adb_enabled", "adb_wifi_enabled", "development_settings_enabled");
|
|
||||||
|
|
||||||
public static int getInt(ContentResolver cr, String name) throws Settings.SettingNotFoundException {
|
|
||||||
if (SPOOF_SETTINGS.contains(name)) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return Settings.Global.getInt(cr, name);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int getInt(ContentResolver cr, String name, int def) {
|
|
||||||
if (SPOOF_SETTINGS.contains(name)) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return Settings.Global.getInt(cr, name, def);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,12 +0,0 @@
|
|||||||
android {
|
|
||||||
namespace = "app.revanced.extension"
|
|
||||||
|
|
||||||
compileOptions {
|
|
||||||
sourceCompatibility = JavaVersion.VERSION_11
|
|
||||||
targetCompatibility = JavaVersion.VERSION_11
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
compileOnly(libs.annotation)
|
|
||||||
}
|
|
@ -1,3 +0,0 @@
|
|||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
|
||||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
|
|
||||||
</manifest>
|
|
@ -1,424 +0,0 @@
|
|||||||
package app.revanced.extension.all.misc.connectivity.wifi.spoof;
|
|
||||||
|
|
||||||
import android.app.PendingIntent;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.net.ConnectivityManager;
|
|
||||||
import android.net.Network;
|
|
||||||
import android.net.NetworkCapabilities;
|
|
||||||
import android.net.NetworkInfo;
|
|
||||||
import android.net.NetworkRequest;
|
|
||||||
import android.os.Build;
|
|
||||||
import android.os.Handler;
|
|
||||||
|
|
||||||
import androidx.annotation.RequiresApi;
|
|
||||||
|
|
||||||
@SuppressWarnings({"deprecation", "unused"})
|
|
||||||
public class SpoofWifiPatch {
|
|
||||||
|
|
||||||
// Used to check what the (real or fake) active network is (take a look at `hasTransport`).
|
|
||||||
private static ConnectivityManager CONNECTIVITY_MANAGER;
|
|
||||||
|
|
||||||
// If Wifi is not enabled, these are types that would pretend to be Wifi for android.net.Network (lower index = higher priority).
|
|
||||||
// This does not apply to android.net.NetworkInfo, because we can pretend that Wifi is always active there.
|
|
||||||
//
|
|
||||||
// VPN should be a fallback, because Reverse Tethering uses VPN.
|
|
||||||
private static final int[] FAKE_FALLBACK_NETWORKS = { NetworkCapabilities.TRANSPORT_ETHERNET, NetworkCapabilities.TRANSPORT_VPN };
|
|
||||||
|
|
||||||
// In order to initialize our own ConnectivityManager, if it isn't initialized yet.
|
|
||||||
public static Object getSystemService(Context context, String name) {
|
|
||||||
Object result = context.getSystemService(name);
|
|
||||||
if (CONNECTIVITY_MANAGER == null) {
|
|
||||||
if (Context.CONNECTIVITY_SERVICE.equals(name)) {
|
|
||||||
CONNECTIVITY_MANAGER = (ConnectivityManager) result;
|
|
||||||
} else {
|
|
||||||
CONNECTIVITY_MANAGER = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
// In order to initialize our own ConnectivityManager, if it isn't initialized yet.
|
|
||||||
public static Object getSystemService(Context context, Class<?> serviceClass) {
|
|
||||||
Object result = context.getSystemService(serviceClass);
|
|
||||||
if (CONNECTIVITY_MANAGER == null) {
|
|
||||||
if (serviceClass == ConnectivityManager.class) {
|
|
||||||
CONNECTIVITY_MANAGER = (ConnectivityManager) result;
|
|
||||||
} else {
|
|
||||||
CONNECTIVITY_MANAGER = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Simply always return Wifi as active network.
|
|
||||||
public static NetworkInfo getActiveNetworkInfo(ConnectivityManager connectivityManager) {
|
|
||||||
for (NetworkInfo networkInfo : connectivityManager.getAllNetworkInfo()) {
|
|
||||||
if (networkInfo.getType() == ConnectivityManager.TYPE_WIFI) {
|
|
||||||
return networkInfo;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return connectivityManager.getActiveNetworkInfo();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Pretend Wifi is always connected.
|
|
||||||
public static boolean isConnected(NetworkInfo networkInfo) {
|
|
||||||
if (networkInfo.getType() == ConnectivityManager.TYPE_WIFI) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return networkInfo.isConnected();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Pretend Wifi is always connected.
|
|
||||||
public static boolean isConnectedOrConnecting(NetworkInfo networkInfo) {
|
|
||||||
if (networkInfo.getType() == ConnectivityManager.TYPE_WIFI) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return networkInfo.isConnectedOrConnecting();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Pretend Wifi is always available.
|
|
||||||
public static boolean isAvailable(NetworkInfo networkInfo) {
|
|
||||||
if (networkInfo.getType() == ConnectivityManager.TYPE_WIFI) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return networkInfo.isAvailable();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Pretend Wifi is always connected.
|
|
||||||
public static NetworkInfo.State getState(NetworkInfo networkInfo) {
|
|
||||||
if (networkInfo.getType() == ConnectivityManager.TYPE_WIFI) {
|
|
||||||
return NetworkInfo.State.CONNECTED;
|
|
||||||
}
|
|
||||||
return networkInfo.getState();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Pretend Wifi is always connected.
|
|
||||||
public static NetworkInfo.DetailedState getDetailedState(NetworkInfo networkInfo) {
|
|
||||||
if (networkInfo.getType() == ConnectivityManager.TYPE_WIFI) {
|
|
||||||
return NetworkInfo.DetailedState.CONNECTED;
|
|
||||||
}
|
|
||||||
return networkInfo.getDetailedState();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Pretend Wifi is enabled, so connection isn't metered.
|
|
||||||
public static boolean isActiveNetworkMetered(ConnectivityManager connectivityManager) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns the Wifi network, if Wifi is enabled.
|
|
||||||
// Otherwise if one of our fallbacks has a connection, return them.
|
|
||||||
// And as a last resort, return the default active network.
|
|
||||||
public static Network getActiveNetwork(ConnectivityManager connectivityManager) {
|
|
||||||
Network[] prioritizedNetworks = new Network[FAKE_FALLBACK_NETWORKS.length];
|
|
||||||
for (Network network : connectivityManager.getAllNetworks()) {
|
|
||||||
NetworkCapabilities networkCapabilities = connectivityManager.getNetworkCapabilities(network);
|
|
||||||
if (networkCapabilities == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (networkCapabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI)) {
|
|
||||||
return network;
|
|
||||||
}
|
|
||||||
if (networkCapabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)) {
|
|
||||||
for (int i = 0; i < FAKE_FALLBACK_NETWORKS.length; i++) {
|
|
||||||
int transportType = FAKE_FALLBACK_NETWORKS[i];
|
|
||||||
if (networkCapabilities.hasTransport(transportType)) {
|
|
||||||
prioritizedNetworks[i] = network;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (Network network : prioritizedNetworks) {
|
|
||||||
if (network != null) {
|
|
||||||
return network;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return connectivityManager.getActiveNetwork();
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the given network is a real or fake Wifi connection, return a Wifi network.
|
|
||||||
// Otherwise fallback to default implementation.
|
|
||||||
public static NetworkInfo getNetworkInfo(ConnectivityManager connectivityManager, Network network) {
|
|
||||||
NetworkCapabilities networkCapabilities = connectivityManager.getNetworkCapabilities(network);
|
|
||||||
if (networkCapabilities != null && hasTransport(networkCapabilities, NetworkCapabilities.TRANSPORT_WIFI)) {
|
|
||||||
for (NetworkInfo networkInfo : connectivityManager.getAllNetworkInfo()) {
|
|
||||||
if (networkInfo.getType() == ConnectivityManager.TYPE_WIFI) {
|
|
||||||
return networkInfo;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return connectivityManager.getNetworkInfo(network);
|
|
||||||
}
|
|
||||||
|
|
||||||
// If we are checking if the NetworkCapabilities use Wifi, return yes if
|
|
||||||
// - it is a real Wifi connection,
|
|
||||||
// - or the NetworkCapabilities are from a network pretending being a Wifi network.
|
|
||||||
// Otherwise fallback to default implementation.
|
|
||||||
public static boolean hasTransport(NetworkCapabilities networkCapabilities, int transportType) {
|
|
||||||
if (transportType == NetworkCapabilities.TRANSPORT_WIFI) {
|
|
||||||
if (networkCapabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (CONNECTIVITY_MANAGER != null) {
|
|
||||||
Network activeNetwork = getActiveNetwork(CONNECTIVITY_MANAGER);
|
|
||||||
NetworkCapabilities activeNetworkCapabilities = CONNECTIVITY_MANAGER.getNetworkCapabilities(activeNetwork);
|
|
||||||
if (activeNetworkCapabilities != null) {
|
|
||||||
for (int fallbackTransportType : FAKE_FALLBACK_NETWORKS) {
|
|
||||||
if (activeNetworkCapabilities.hasTransport(fallbackTransportType) && networkCapabilities.hasTransport(fallbackTransportType)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return networkCapabilities.hasTransport(transportType);
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the given network is a real or fake Wifi connection, pretend it has a connection (and some other things).
|
|
||||||
public static boolean hasCapability(NetworkCapabilities networkCapabilities, int capability) {
|
|
||||||
if (hasTransport(networkCapabilities, NetworkCapabilities.TRANSPORT_WIFI) && (
|
|
||||||
capability == NetworkCapabilities.NET_CAPABILITY_INTERNET
|
|
||||||
|| capability == NetworkCapabilities.NET_CAPABILITY_FOREGROUND
|
|
||||||
|| capability == NetworkCapabilities.NET_CAPABILITY_NOT_CONGESTED
|
|
||||||
|| capability == NetworkCapabilities.NET_CAPABILITY_NOT_METERED
|
|
||||||
|| capability == NetworkCapabilities.NET_CAPABILITY_NOT_RESTRICTED
|
|
||||||
|| capability == NetworkCapabilities.NET_CAPABILITY_NOT_ROAMING
|
|
||||||
|| capability == NetworkCapabilities.NET_CAPABILITY_NOT_SUSPENDED
|
|
||||||
|| capability == NetworkCapabilities.NET_CAPABILITY_NOT_VPN
|
|
||||||
|| capability == NetworkCapabilities.NET_CAPABILITY_TRUSTED
|
|
||||||
|| capability == NetworkCapabilities.NET_CAPABILITY_VALIDATED)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return networkCapabilities.hasCapability(capability);
|
|
||||||
}
|
|
||||||
|
|
||||||
// If it waits for Wifi connectivity, pretend it is fulfilled immediately if we have an active network.
|
|
||||||
@RequiresApi(api = Build.VERSION_CODES.S)
|
|
||||||
public static void registerBestMatchingNetworkCallback(ConnectivityManager connectivityManager, NetworkRequest request, ConnectivityManager.NetworkCallback networkCallback, Handler handler) {
|
|
||||||
Utils.networkCallback(
|
|
||||||
connectivityManager,
|
|
||||||
Utils.Option.of(request),
|
|
||||||
Utils.Option.of(networkCallback),
|
|
||||||
Utils.Option.empty(),
|
|
||||||
Utils.Option.of(handler),
|
|
||||||
() -> connectivityManager.registerBestMatchingNetworkCallback(request, networkCallback, handler)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// If it waits for Wifi connectivity, pretend it is fulfilled immediately if we have an active network.
|
|
||||||
@RequiresApi(api = Build.VERSION_CODES.N)
|
|
||||||
public static void registerDefaultNetworkCallback(ConnectivityManager connectivityManager, ConnectivityManager.NetworkCallback networkCallback) {
|
|
||||||
Utils.networkCallback(
|
|
||||||
connectivityManager,
|
|
||||||
Utils.Option.empty(),
|
|
||||||
Utils.Option.of(networkCallback),
|
|
||||||
Utils.Option.empty(),
|
|
||||||
Utils.Option.empty(),
|
|
||||||
() -> connectivityManager.registerDefaultNetworkCallback(networkCallback)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// If it waits for Wifi connectivity, pretend it is fulfilled immediately if we have an active network.
|
|
||||||
@RequiresApi(api = Build.VERSION_CODES.O)
|
|
||||||
public static void registerDefaultNetworkCallback(ConnectivityManager connectivityManager, ConnectivityManager.NetworkCallback networkCallback, Handler handler) {
|
|
||||||
Utils.networkCallback(
|
|
||||||
connectivityManager,
|
|
||||||
Utils.Option.empty(),
|
|
||||||
Utils.Option.of(networkCallback),
|
|
||||||
Utils.Option.empty(),
|
|
||||||
Utils.Option.of(handler),
|
|
||||||
() -> connectivityManager.registerDefaultNetworkCallback(networkCallback, handler)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// If it waits for Wifi connectivity, pretend it is fulfilled immediately if we have an active network.
|
|
||||||
public static void registerNetworkCallback(ConnectivityManager connectivityManager, NetworkRequest request, ConnectivityManager.NetworkCallback networkCallback) {
|
|
||||||
Utils.networkCallback(
|
|
||||||
connectivityManager,
|
|
||||||
Utils.Option.of(request),
|
|
||||||
Utils.Option.of(networkCallback),
|
|
||||||
Utils.Option.empty(),
|
|
||||||
Utils.Option.empty(),
|
|
||||||
() -> connectivityManager.registerNetworkCallback(request, networkCallback)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// If it waits for Wifi connectivity, pretend it is fulfilled immediately.
|
|
||||||
public static void registerNetworkCallback(ConnectivityManager connectivityManager, NetworkRequest request, PendingIntent operation) {
|
|
||||||
Utils.networkCallback(
|
|
||||||
connectivityManager,
|
|
||||||
Utils.Option.of(request),
|
|
||||||
Utils.Option.empty(),
|
|
||||||
Utils.Option.of(operation),
|
|
||||||
Utils.Option.empty(),
|
|
||||||
() -> connectivityManager.registerNetworkCallback(request, operation)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// If it waits for Wifi connectivity, pretend it is fulfilled immediately if we have an active network.
|
|
||||||
@RequiresApi(api = Build.VERSION_CODES.O)
|
|
||||||
public static void registerNetworkCallback(ConnectivityManager connectivityManager, NetworkRequest request, ConnectivityManager.NetworkCallback networkCallback, Handler handler) {
|
|
||||||
Utils.networkCallback(
|
|
||||||
connectivityManager,
|
|
||||||
Utils.Option.of(request),
|
|
||||||
Utils.Option.of(networkCallback),
|
|
||||||
Utils.Option.empty(),
|
|
||||||
Utils.Option.of(handler),
|
|
||||||
() -> connectivityManager.registerNetworkCallback(request, networkCallback, handler)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// If it requests Wifi connectivity, pretend it is fulfilled immediately if we have an active network.
|
|
||||||
public static void requestNetwork(ConnectivityManager connectivityManager, NetworkRequest request, ConnectivityManager.NetworkCallback networkCallback) {
|
|
||||||
Utils.networkCallback(
|
|
||||||
connectivityManager,
|
|
||||||
Utils.Option.of(request),
|
|
||||||
Utils.Option.of(networkCallback),
|
|
||||||
Utils.Option.empty(),
|
|
||||||
Utils.Option.empty(),
|
|
||||||
() -> connectivityManager.requestNetwork(request, networkCallback)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// If it requests Wifi connectivity, pretend it is fulfilled immediately if we have an active network.
|
|
||||||
@RequiresApi(api = Build.VERSION_CODES.O)
|
|
||||||
public static void requestNetwork(ConnectivityManager connectivityManager, NetworkRequest request, ConnectivityManager.NetworkCallback networkCallback, int timeoutMs) {
|
|
||||||
Utils.networkCallback(
|
|
||||||
connectivityManager,
|
|
||||||
Utils.Option.of(request),
|
|
||||||
Utils.Option.of(networkCallback),
|
|
||||||
Utils.Option.empty(),
|
|
||||||
Utils.Option.empty(),
|
|
||||||
() -> connectivityManager.requestNetwork(request, networkCallback, timeoutMs)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// If it requests Wifi connectivity, pretend it is fulfilled immediately if we have an active network.
|
|
||||||
@RequiresApi(api = Build.VERSION_CODES.O)
|
|
||||||
public static void requestNetwork(ConnectivityManager connectivityManager, NetworkRequest request, ConnectivityManager.NetworkCallback networkCallback, Handler handler) {
|
|
||||||
Utils.networkCallback(
|
|
||||||
connectivityManager,
|
|
||||||
Utils.Option.of(request),
|
|
||||||
Utils.Option.of(networkCallback),
|
|
||||||
Utils.Option.empty(),
|
|
||||||
Utils.Option.of(handler),
|
|
||||||
() -> connectivityManager.requestNetwork(request, networkCallback, handler)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// If it requests Wifi connectivity, pretend it is fulfilled immediately.
|
|
||||||
public static void requestNetwork(ConnectivityManager connectivityManager, NetworkRequest request, PendingIntent operation) {
|
|
||||||
Utils.networkCallback(
|
|
||||||
connectivityManager,
|
|
||||||
Utils.Option.of(request),
|
|
||||||
Utils.Option.empty(),
|
|
||||||
Utils.Option.of(operation),
|
|
||||||
Utils.Option.empty(),
|
|
||||||
() -> connectivityManager.requestNetwork(request, operation)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// If it requests Wifi connectivity, pretend it is fulfilled immediately if we have an active network.
|
|
||||||
@RequiresApi(api = Build.VERSION_CODES.O)
|
|
||||||
public static void requestNetwork(ConnectivityManager connectivityManager, NetworkRequest request, ConnectivityManager.NetworkCallback networkCallback, Handler handler, int timeoutMs) {
|
|
||||||
Utils.networkCallback(
|
|
||||||
connectivityManager,
|
|
||||||
Utils.Option.of(request),
|
|
||||||
Utils.Option.of(networkCallback),
|
|
||||||
Utils.Option.empty(),
|
|
||||||
Utils.Option.of(handler),
|
|
||||||
() -> connectivityManager.requestNetwork(request, networkCallback, handler, timeoutMs)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void unregisterNetworkCallback(ConnectivityManager connectivityManager, ConnectivityManager.NetworkCallback networkCallback) {
|
|
||||||
try {
|
|
||||||
connectivityManager.unregisterNetworkCallback(networkCallback);
|
|
||||||
} catch (IllegalArgumentException ignore) {
|
|
||||||
// ignore: NetworkCallback was not registered
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void unregisterNetworkCallback(ConnectivityManager connectivityManager, PendingIntent operation) {
|
|
||||||
try {
|
|
||||||
connectivityManager.unregisterNetworkCallback(operation);
|
|
||||||
} catch (IllegalArgumentException ignore) {
|
|
||||||
// ignore: PendingIntent was not registered
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class Utils {
|
|
||||||
private static class Option<T> {
|
|
||||||
private final T value;
|
|
||||||
private final boolean isPresent;
|
|
||||||
|
|
||||||
private Option(T value, boolean isPresent) {
|
|
||||||
this.value = value;
|
|
||||||
this.isPresent = isPresent;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static <T> Option<T> of(T value) {
|
|
||||||
return new Option<>(value, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static <T> Option<T> empty() {
|
|
||||||
return new Option<>(null, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void networkCallback(
|
|
||||||
ConnectivityManager connectivityManager,
|
|
||||||
Option<NetworkRequest> request,
|
|
||||||
Option<ConnectivityManager.NetworkCallback> networkCallback,
|
|
||||||
Option<PendingIntent> operation,
|
|
||||||
Option<Handler> handler,
|
|
||||||
Runnable fallback
|
|
||||||
) {
|
|
||||||
if(!request.isPresent || (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P && request.value != null && requestsWifiNetwork(request.value))) {
|
|
||||||
Runnable runnable = null;
|
|
||||||
if (networkCallback.isPresent && networkCallback.value != null) {
|
|
||||||
Network network = activeWifiNetwork(connectivityManager);
|
|
||||||
if (network != null) {
|
|
||||||
runnable = () -> networkCallback.value.onAvailable(network);
|
|
||||||
}
|
|
||||||
} else if (operation.isPresent && operation.value != null) {
|
|
||||||
runnable = () -> {
|
|
||||||
try {
|
|
||||||
operation.value.send();
|
|
||||||
} catch (PendingIntent.CanceledException ignore) {}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
if (runnable != null) {
|
|
||||||
if (handler.isPresent) {
|
|
||||||
if (handler.value != null) {
|
|
||||||
handler.value.post(runnable);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
runnable.run();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fallback.run();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns an active (maybe fake) Wifi network if there is one, otherwise null.
|
|
||||||
private static Network activeWifiNetwork(ConnectivityManager connectivityManager) {
|
|
||||||
Network network = getActiveNetwork(connectivityManager);
|
|
||||||
NetworkCapabilities networkCapabilities = connectivityManager.getNetworkCapabilities(network);
|
|
||||||
if (networkCapabilities != null && hasTransport(networkCapabilities, NetworkCapabilities.TRANSPORT_WIFI)) {
|
|
||||||
return network;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Whether a Wifi network with connection is requested.
|
|
||||||
@RequiresApi(api = Build.VERSION_CODES.P)
|
|
||||||
private static boolean requestsWifiNetwork(NetworkRequest request) {
|
|
||||||
return request.hasTransport(NetworkCapabilities.TRANSPORT_WIFI)
|
|
||||||
&& (request.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
|
|
||||||
|| request.hasCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,16 +0,0 @@
|
|||||||
android {
|
|
||||||
namespace = "app.revanced.extension"
|
|
||||||
|
|
||||||
defaultConfig {
|
|
||||||
minSdk = 21
|
|
||||||
}
|
|
||||||
|
|
||||||
compileOptions {
|
|
||||||
sourceCompatibility = JavaVersion.VERSION_11
|
|
||||||
targetCompatibility = JavaVersion.VERSION_11
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
compileOnly(libs.annotation)
|
|
||||||
}
|
|
@ -1 +0,0 @@
|
|||||||
<manifest/>
|
|
@ -1,336 +0,0 @@
|
|||||||
package app.revanced.extension.all.misc.directory.documentsprovider;
|
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.pm.ApplicationInfo;
|
|
||||||
import android.content.pm.ProviderInfo;
|
|
||||||
import android.database.Cursor;
|
|
||||||
import android.database.MatrixCursor;
|
|
||||||
import android.os.CancellationSignal;
|
|
||||||
import android.os.ParcelFileDescriptor;
|
|
||||||
import android.provider.DocumentsContract;
|
|
||||||
import android.provider.DocumentsProvider;
|
|
||||||
import android.system.ErrnoException;
|
|
||||||
import android.system.Os;
|
|
||||||
import android.system.StructStat;
|
|
||||||
import android.util.Log;
|
|
||||||
import android.webkit.MimeTypeMap;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A DocumentsProvider that allows access to the app's internal data directory.
|
|
||||||
*/
|
|
||||||
@SuppressLint("LongLogTag")
|
|
||||||
public class InternalDataDocumentsProvider extends DocumentsProvider {
|
|
||||||
private static final String[] rootColumns =
|
|
||||||
{"root_id", "mime_types", "flags", "icon", "title", "summary", "document_id"};
|
|
||||||
private static final String[] directoryColumns =
|
|
||||||
{"document_id", "mime_type", "_display_name", "last_modified", "flags",
|
|
||||||
"_size", "full_path", "lstat_info"};
|
|
||||||
private static final int S_IFLNK = 0x8000;
|
|
||||||
|
|
||||||
private String packageName;
|
|
||||||
private File dataDirectory;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Recursively delete a file or directory and all its children.
|
|
||||||
*
|
|
||||||
* @param root The file or directory to delete.
|
|
||||||
* @return True if the file or directory and all its children were successfully deleted.
|
|
||||||
*/
|
|
||||||
private static boolean deleteRecursively(File root) {
|
|
||||||
// If root is a directory, delete all children first
|
|
||||||
if (root.isDirectory()) {
|
|
||||||
try {
|
|
||||||
// Only delete recursively if the directory is not a symlink
|
|
||||||
if ((Os.lstat(root.getPath()).st_mode & S_IFLNK) != S_IFLNK) {
|
|
||||||
File[] files = root.listFiles();
|
|
||||||
if (files != null) {
|
|
||||||
for (File file : files) {
|
|
||||||
if (!deleteRecursively(file)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (ErrnoException e) {
|
|
||||||
Log.e("InternalDocumentsProvider", "Failed to lstat " + root.getPath(), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Delete file or empty directory
|
|
||||||
return root.delete();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Resolve the MIME type of a file based on its extension.
|
|
||||||
*
|
|
||||||
* @param file The file to resolve the MIME type for.
|
|
||||||
* @return The MIME type of the file.
|
|
||||||
*/
|
|
||||||
private static String resolveMimeType(File file) {
|
|
||||||
if (file.isDirectory()) {
|
|
||||||
return DocumentsContract.Document.MIME_TYPE_DIR;
|
|
||||||
}
|
|
||||||
|
|
||||||
String name = file.getName();
|
|
||||||
int indexOfExtDot = name.lastIndexOf('.');
|
|
||||||
if (indexOfExtDot < 0) {
|
|
||||||
// No extension
|
|
||||||
return "application/octet-stream";
|
|
||||||
}
|
|
||||||
|
|
||||||
String extension = name.substring(indexOfExtDot + 1).toLowerCase();
|
|
||||||
String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
|
|
||||||
return mimeType != null ? mimeType : "application/octet-stream";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final boolean onCreate() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final void attachInfo(Context context, ProviderInfo providerInfo) {
|
|
||||||
super.attachInfo(context, providerInfo);
|
|
||||||
|
|
||||||
this.packageName = context.getPackageName();
|
|
||||||
this.dataDirectory = context.getFilesDir().getParentFile();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final String createDocument(String parentDocumentId, String mimeType, String displayName) throws FileNotFoundException {
|
|
||||||
File directory = resolveDocumentId(parentDocumentId);
|
|
||||||
File file = new File(directory, displayName);
|
|
||||||
|
|
||||||
// If file already exists, append a number to the name
|
|
||||||
int i = 2;
|
|
||||||
while (file.exists()) {
|
|
||||||
file = new File(directory, displayName + " (" + i + ")");
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
// Create the file or directory
|
|
||||||
if (mimeType.equals(DocumentsContract.Document.MIME_TYPE_DIR) ? file.mkdir() : file.createNewFile()) {
|
|
||||||
// Return the document ID of the new entity
|
|
||||||
if (!parentDocumentId.endsWith("/")) {
|
|
||||||
parentDocumentId = parentDocumentId + "/";
|
|
||||||
}
|
|
||||||
return parentDocumentId + file.getName();
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
// Do nothing. We are throwing a FileNotFoundException later if the file could not be created.
|
|
||||||
}
|
|
||||||
throw new FileNotFoundException("Failed to create document in " + parentDocumentId + " with name " + displayName);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final void deleteDocument(String documentId) throws FileNotFoundException {
|
|
||||||
File file = resolveDocumentId(documentId);
|
|
||||||
if (!deleteRecursively(file)) {
|
|
||||||
throw new FileNotFoundException("Failed to delete document " + documentId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final String getDocumentType(String documentId) throws FileNotFoundException {
|
|
||||||
return resolveMimeType(resolveDocumentId(documentId));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final boolean isChildDocument(String parentDocumentId, String documentId) {
|
|
||||||
return documentId.startsWith(parentDocumentId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final String moveDocument(String sourceDocumentId, String sourceParentDocumentId, String targetParentDocumentId) throws FileNotFoundException {
|
|
||||||
File source = resolveDocumentId(sourceDocumentId);
|
|
||||||
File dest = resolveDocumentId(targetParentDocumentId);
|
|
||||||
|
|
||||||
File file = new File(dest, source.getName());
|
|
||||||
if (!file.exists() && source.renameTo(file)) {
|
|
||||||
// Return the new document ID
|
|
||||||
if (targetParentDocumentId.endsWith("/")) {
|
|
||||||
return targetParentDocumentId + file.getName();
|
|
||||||
}
|
|
||||||
return targetParentDocumentId + "/" + file.getName();
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new FileNotFoundException("Failed to move document from " + sourceDocumentId + " to " + targetParentDocumentId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final ParcelFileDescriptor openDocument(String documentId, String mode, CancellationSignal signal) throws FileNotFoundException {
|
|
||||||
File file = resolveDocumentId(documentId);
|
|
||||||
return ParcelFileDescriptor.open(file, ParcelFileDescriptor.parseMode(mode));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final Cursor queryChildDocuments(String parentDocumentId, String[] projection, String sortOrder) throws FileNotFoundException {
|
|
||||||
if (parentDocumentId.endsWith("/")) {
|
|
||||||
parentDocumentId = parentDocumentId.substring(0, parentDocumentId.length() - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (projection == null) {
|
|
||||||
projection = directoryColumns;
|
|
||||||
}
|
|
||||||
|
|
||||||
MatrixCursor cursor = new MatrixCursor(projection);
|
|
||||||
File children = resolveDocumentId(parentDocumentId);
|
|
||||||
|
|
||||||
// Collect all children
|
|
||||||
File[] files = children.listFiles();
|
|
||||||
if (files != null) {
|
|
||||||
for (File file : files) {
|
|
||||||
addRowForDocument(cursor, parentDocumentId + "/" + file.getName(), file);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return cursor;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final Cursor queryDocument(String documentId, String[] projection) throws FileNotFoundException {
|
|
||||||
if (projection == null) {
|
|
||||||
projection = directoryColumns;
|
|
||||||
}
|
|
||||||
|
|
||||||
MatrixCursor cursor = new MatrixCursor(projection);
|
|
||||||
addRowForDocument(cursor, documentId, null);
|
|
||||||
return cursor;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final Cursor queryRoots(String[] projection) {
|
|
||||||
ApplicationInfo info = Objects.requireNonNull(getContext()).getApplicationInfo();
|
|
||||||
String appName = info.loadLabel(getContext().getPackageManager()).toString();
|
|
||||||
|
|
||||||
if (projection == null) {
|
|
||||||
projection = rootColumns;
|
|
||||||
}
|
|
||||||
|
|
||||||
MatrixCursor cursor = new MatrixCursor(projection);
|
|
||||||
MatrixCursor.RowBuilder row = cursor.newRow();
|
|
||||||
row.add(DocumentsContract.Root.COLUMN_ROOT_ID, this.packageName);
|
|
||||||
row.add(DocumentsContract.Root.COLUMN_DOCUMENT_ID, this.packageName);
|
|
||||||
row.add(DocumentsContract.Root.COLUMN_SUMMARY, this.packageName);
|
|
||||||
row.add(DocumentsContract.Root.COLUMN_FLAGS,
|
|
||||||
DocumentsContract.Root.FLAG_LOCAL_ONLY |
|
|
||||||
DocumentsContract.Root.FLAG_SUPPORTS_IS_CHILD);
|
|
||||||
row.add(DocumentsContract.Root.COLUMN_TITLE, appName);
|
|
||||||
row.add(DocumentsContract.Root.COLUMN_MIME_TYPES, "*/*");
|
|
||||||
row.add(DocumentsContract.Root.COLUMN_ICON, info.icon);
|
|
||||||
return cursor;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final void removeDocument(String documentId, String parentDocumentId) throws FileNotFoundException {
|
|
||||||
deleteDocument(documentId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final String renameDocument(String documentId, String displayName) throws FileNotFoundException {
|
|
||||||
File file = resolveDocumentId(documentId);
|
|
||||||
if (!file.renameTo(new File(file.getParentFile(), displayName))) {
|
|
||||||
throw new FileNotFoundException("Failed to rename document from " + documentId + " to " + displayName);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return the new document ID
|
|
||||||
return documentId.substring(0, documentId.lastIndexOf('/', documentId.length() - 2)) + "/" + displayName;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Resolve a file instance for a given document ID.
|
|
||||||
*
|
|
||||||
* @param fullContentPath The document ID to resolve.
|
|
||||||
* @return File object for the given document ID.
|
|
||||||
* @throws FileNotFoundException If the document ID is invalid or the file does not exist.
|
|
||||||
*/
|
|
||||||
private File resolveDocumentId(String fullContentPath) throws FileNotFoundException {
|
|
||||||
if (!fullContentPath.startsWith(this.packageName)) {
|
|
||||||
throw new FileNotFoundException(fullContentPath + " not found");
|
|
||||||
}
|
|
||||||
String path = fullContentPath.substring(this.packageName.length());
|
|
||||||
|
|
||||||
// Resolve the relative path within /data/data/{PKG}
|
|
||||||
File file;
|
|
||||||
if (path.equals("/") || path.isEmpty()) {
|
|
||||||
file = this.dataDirectory;
|
|
||||||
} else {
|
|
||||||
// Remove leading slash
|
|
||||||
String relativePath = path.substring(1);
|
|
||||||
file = new File(this.dataDirectory, relativePath);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!file.exists()) {
|
|
||||||
throw new FileNotFoundException(fullContentPath + " not found");
|
|
||||||
}
|
|
||||||
return file;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add a row containing all file properties to a MatrixCursor for a given document ID.
|
|
||||||
*
|
|
||||||
* @param cursor The cursor to add the row to.
|
|
||||||
* @param documentId The document ID to add the row for.
|
|
||||||
* @param file The file to add the row for. If null, the file will be resolved from the document ID.
|
|
||||||
* @throws FileNotFoundException If the file does not exist.
|
|
||||||
*/
|
|
||||||
private void addRowForDocument(MatrixCursor cursor, String documentId, File file) throws FileNotFoundException {
|
|
||||||
if (file == null) {
|
|
||||||
file = resolveDocumentId(documentId);
|
|
||||||
}
|
|
||||||
|
|
||||||
int flags = 0;
|
|
||||||
if (file.isDirectory()) {
|
|
||||||
// Prefer list view for directories
|
|
||||||
flags = flags | DocumentsContract.Document.FLAG_DIR_PREFERS_LAST_MODIFIED;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (file.canWrite()) {
|
|
||||||
if (file.isDirectory()) {
|
|
||||||
flags = flags | DocumentsContract.Document.FLAG_DIR_SUPPORTS_CREATE;
|
|
||||||
}
|
|
||||||
|
|
||||||
flags = flags | DocumentsContract.Document.FLAG_SUPPORTS_WRITE |
|
|
||||||
DocumentsContract.Document.FLAG_SUPPORTS_DELETE |
|
|
||||||
DocumentsContract.Document.FLAG_SUPPORTS_RENAME |
|
|
||||||
DocumentsContract.Document.FLAG_SUPPORTS_MOVE;
|
|
||||||
}
|
|
||||||
|
|
||||||
MatrixCursor.RowBuilder row = cursor.newRow();
|
|
||||||
row.add(DocumentsContract.Document.COLUMN_DOCUMENT_ID, documentId);
|
|
||||||
row.add(DocumentsContract.Document.COLUMN_DISPLAY_NAME, file.getName());
|
|
||||||
row.add(DocumentsContract.Document.COLUMN_SIZE, file.length());
|
|
||||||
row.add(DocumentsContract.Document.COLUMN_MIME_TYPE, resolveMimeType(file));
|
|
||||||
row.add(DocumentsContract.Document.COLUMN_LAST_MODIFIED, file.lastModified());
|
|
||||||
row.add(DocumentsContract.Document.COLUMN_FLAGS, flags);
|
|
||||||
|
|
||||||
// Custom columns
|
|
||||||
row.add("full_path", file.getAbsolutePath());
|
|
||||||
|
|
||||||
// Add lstat column
|
|
||||||
String path = file.getPath();
|
|
||||||
try {
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
StructStat lstat = Os.lstat(path);
|
|
||||||
sb.append(lstat.st_mode);
|
|
||||||
sb.append(";");
|
|
||||||
sb.append(lstat.st_uid);
|
|
||||||
sb.append(";");
|
|
||||||
sb.append(lstat.st_gid);
|
|
||||||
// Append symlink target if it is a symlink
|
|
||||||
if ((lstat.st_mode & S_IFLNK) == S_IFLNK) {
|
|
||||||
sb.append(";");
|
|
||||||
sb.append(Os.readlink(path));
|
|
||||||
}
|
|
||||||
row.add("lstat_info", sb.toString());
|
|
||||||
} catch (Exception ex) {
|
|
||||||
Log.e("InternalDocumentsProvider", "Failed to get lstat info for " + path, ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,16 +0,0 @@
|
|||||||
android {
|
|
||||||
namespace = "app.revanced.extension"
|
|
||||||
|
|
||||||
defaultConfig {
|
|
||||||
minSdk = 21
|
|
||||||
}
|
|
||||||
|
|
||||||
compileOptions {
|
|
||||||
sourceCompatibility = JavaVersion.VERSION_11
|
|
||||||
targetCompatibility = JavaVersion.VERSION_11
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
compileOnly(libs.annotation)
|
|
||||||
}
|
|
@ -1 +0,0 @@
|
|||||||
<manifest/>
|
|
@ -1,22 +0,0 @@
|
|||||||
package app.revanced.extension.all.misc.screencapture.removerestriction;
|
|
||||||
|
|
||||||
import android.media.AudioAttributes;
|
|
||||||
import android.os.Build;
|
|
||||||
|
|
||||||
import androidx.annotation.RequiresApi;
|
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
public final class RemoveScreenCaptureRestrictionPatch {
|
|
||||||
// Member of AudioAttributes.Builder
|
|
||||||
@RequiresApi(api = Build.VERSION_CODES.Q)
|
|
||||||
public static AudioAttributes.Builder setAllowedCapturePolicy(final AudioAttributes.Builder builder, final int capturePolicy) {
|
|
||||||
builder.setAllowedCapturePolicy(AudioAttributes.ALLOW_CAPTURE_BY_ALL);
|
|
||||||
|
|
||||||
return builder;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Member of AudioManager static class
|
|
||||||
public static void setAllowedCapturePolicy(final int capturePolicy) {
|
|
||||||
// Ignore request
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,16 +0,0 @@
|
|||||||
android {
|
|
||||||
namespace = "app.revanced.extension"
|
|
||||||
|
|
||||||
defaultConfig {
|
|
||||||
minSdk = 21
|
|
||||||
}
|
|
||||||
|
|
||||||
compileOptions {
|
|
||||||
sourceCompatibility = JavaVersion.VERSION_11
|
|
||||||
targetCompatibility = JavaVersion.VERSION_11
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
compileOnly(libs.annotation)
|
|
||||||
}
|
|
@ -1 +0,0 @@
|
|||||||
<manifest/>
|
|
@ -1,16 +0,0 @@
|
|||||||
package app.revanced.extension.all.misc.screenshot.removerestriction;
|
|
||||||
|
|
||||||
import android.view.Window;
|
|
||||||
import android.view.WindowManager;
|
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
public class RemoveScreenshotRestrictionPatch {
|
|
||||||
|
|
||||||
public static void addFlags(Window window, int flags) {
|
|
||||||
window.addFlags(flags & ~WindowManager.LayoutParams.FLAG_SECURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setFlags(Window window, int flags, int mask) {
|
|
||||||
window.setFlags(flags & ~WindowManager.LayoutParams.FLAG_SECURE, mask & ~WindowManager.LayoutParams.FLAG_SECURE);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,4 +0,0 @@
|
|||||||
dependencies {
|
|
||||||
compileOnly(project(":extensions:shared:library"))
|
|
||||||
compileOnly(project(":extensions:boostforreddit:stub"))
|
|
||||||
}
|
|
@ -1 +0,0 @@
|
|||||||
<manifest/>
|
|
@ -1,26 +0,0 @@
|
|||||||
package app.revanced.extension.boostforreddit;
|
|
||||||
|
|
||||||
import com.rubenmayayo.reddit.ui.activities.WebViewActivity;
|
|
||||||
|
|
||||||
import app.revanced.extension.shared.fixes.slink.BaseFixSLinksPatch;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @noinspection unused
|
|
||||||
*/
|
|
||||||
public class FixSLinksPatch extends BaseFixSLinksPatch {
|
|
||||||
static {
|
|
||||||
INSTANCE = new FixSLinksPatch();
|
|
||||||
}
|
|
||||||
|
|
||||||
private FixSLinksPatch() {
|
|
||||||
webViewActivityClass = WebViewActivity.class;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean patchResolveSLink(String link) {
|
|
||||||
return INSTANCE.resolveSLink(link);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void patchSetAccessToken(String accessToken) {
|
|
||||||
INSTANCE.setAccessToken(accessToken);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,17 +0,0 @@
|
|||||||
plugins {
|
|
||||||
id(libs.plugins.android.library.get().pluginId)
|
|
||||||
}
|
|
||||||
|
|
||||||
android {
|
|
||||||
namespace = "app.revanced.extension"
|
|
||||||
compileSdk = 34
|
|
||||||
|
|
||||||
defaultConfig {
|
|
||||||
minSdk = 24
|
|
||||||
}
|
|
||||||
|
|
||||||
compileOptions {
|
|
||||||
sourceCompatibility = JavaVersion.VERSION_11
|
|
||||||
targetCompatibility = JavaVersion.VERSION_11
|
|
||||||
}
|
|
||||||
}
|
|
@ -1 +0,0 @@
|
|||||||
<manifest/>
|
|
@ -1,6 +0,0 @@
|
|||||||
package com.rubenmayayo.reddit.ui.activities;
|
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
|
|
||||||
public class WebViewActivity extends Activity {
|
|
||||||
}
|
|
@ -1,5 +0,0 @@
|
|||||||
android {
|
|
||||||
defaultConfig {
|
|
||||||
minSdk = 26
|
|
||||||
}
|
|
||||||
}
|
|
@ -1 +0,0 @@
|
|||||||
<manifest/>
|
|
@ -1,27 +0,0 @@
|
|||||||
package app.revanced.extension.music.spoof;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @noinspection unused
|
|
||||||
*/
|
|
||||||
public class SpoofClientPatch {
|
|
||||||
private static final int CLIENT_TYPE_ID = 26;
|
|
||||||
private static final String CLIENT_VERSION = "6.21";
|
|
||||||
private static final String DEVICE_MODEL = "iPhone16,2";
|
|
||||||
private static final String OS_VERSION = "17.7.2.21H221";
|
|
||||||
|
|
||||||
public static int getClientId() {
|
|
||||||
return CLIENT_TYPE_ID;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getClientVersion() {
|
|
||||||
return CLIENT_VERSION;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getClientModel() {
|
|
||||||
return DEVICE_MODEL;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getOsVersion() {
|
|
||||||
return OS_VERSION;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,4 +0,0 @@
|
|||||||
dependencies {
|
|
||||||
compileOnly(project(":extensions:shared:library"))
|
|
||||||
compileOnly(project(":extensions:nunl:stub"))
|
|
||||||
}
|
|
@ -1 +0,0 @@
|
|||||||
<manifest/>
|
|
@ -1,114 +0,0 @@
|
|||||||
package app.revanced.extension.nunl.ads;
|
|
||||||
|
|
||||||
import nl.nu.performance.api.client.interfaces.Block;
|
|
||||||
import nl.nu.performance.api.client.unions.SmallArticleLinkFlavor;
|
|
||||||
import nl.nu.performance.api.client.objects.*;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import app.revanced.extension.shared.Logger;
|
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
public class HideAdsPatch {
|
|
||||||
private static final String[] blockedHeaderBlocks = {
|
|
||||||
"Aanbiedingen (Adverteerders)",
|
|
||||||
"Aangeboden door NUshop"
|
|
||||||
};
|
|
||||||
|
|
||||||
// "Rubrieken" menu links to ads.
|
|
||||||
private static final String[] blockedLinkBlocks = {
|
|
||||||
"Van onze adverteerders"
|
|
||||||
};
|
|
||||||
|
|
||||||
public static void filterAds(List<Block> blocks) {
|
|
||||||
try {
|
|
||||||
ArrayList<Block> cleanedList = new ArrayList<>();
|
|
||||||
|
|
||||||
boolean skipFullHeader = false;
|
|
||||||
boolean skipUntilDivider = false;
|
|
||||||
|
|
||||||
int index = 0;
|
|
||||||
while (index < blocks.size()) {
|
|
||||||
Block currentBlock = blocks.get(index);
|
|
||||||
|
|
||||||
// Because of pagination, we might not see the Divider in front of it.
|
|
||||||
// Just remove it as is and leave potential extra spacing visible on the screen.
|
|
||||||
if (currentBlock instanceof DpgBannerBlock) {
|
|
||||||
index++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (index + 1 < blocks.size()) {
|
|
||||||
// Filter Divider -> DpgMediaBanner -> Divider.
|
|
||||||
if (currentBlock instanceof DividerBlock
|
|
||||||
&& blocks.get(index + 1) instanceof DpgBannerBlock) {
|
|
||||||
index += 2;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Filter Divider -> LinkBlock (... -> LinkBlock -> LinkBlock-> LinkBlock -> Divider).
|
|
||||||
if (currentBlock instanceof DividerBlock
|
|
||||||
&& blocks.get(index + 1) instanceof LinkBlock linkBlock) {
|
|
||||||
Link link = linkBlock.getLink();
|
|
||||||
if (link != null && link.getTitle() != null) {
|
|
||||||
for (String blockedLinkBlock : blockedLinkBlocks) {
|
|
||||||
if (blockedLinkBlock.equals(link.getTitle().getText())) {
|
|
||||||
skipUntilDivider = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (skipUntilDivider) {
|
|
||||||
index++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Skip LinkBlocks with a "flavor" claiming to be "isPartner" (sponsored inline ads).
|
|
||||||
if (currentBlock instanceof LinkBlock linkBlock
|
|
||||||
&& linkBlock.getLink() != null
|
|
||||||
&& linkBlock.getLink().getLinkFlavor() instanceof SmallArticleLinkFlavor smallArticleLinkFlavor
|
|
||||||
&& smallArticleLinkFlavor.isPartner() != null
|
|
||||||
&& smallArticleLinkFlavor.isPartner()) {
|
|
||||||
index++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (currentBlock instanceof DividerBlock) {
|
|
||||||
skipUntilDivider = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Filter HeaderBlock with known ads until next HeaderBlock.
|
|
||||||
if (currentBlock instanceof HeaderBlock headerBlock) {
|
|
||||||
StyledText headerText = headerBlock.component20();
|
|
||||||
if (headerText != null) {
|
|
||||||
skipFullHeader = false;
|
|
||||||
for (String blockedHeaderBlock : blockedHeaderBlocks) {
|
|
||||||
if (blockedHeaderBlock.equals(headerText.getText())) {
|
|
||||||
skipFullHeader = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (skipFullHeader) {
|
|
||||||
index++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!skipFullHeader && !skipUntilDivider) {
|
|
||||||
cleanedList.add(currentBlock);
|
|
||||||
}
|
|
||||||
index++;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Replace list in-place to not deal with moving the result to the correct register in smali.
|
|
||||||
blocks.clear();
|
|
||||||
blocks.addAll(cleanedList);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
Logger.printException(() -> "filterAds failure", ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,17 +0,0 @@
|
|||||||
plugins {
|
|
||||||
id(libs.plugins.android.library.get().pluginId)
|
|
||||||
}
|
|
||||||
|
|
||||||
android {
|
|
||||||
namespace = "app.revanced.extension"
|
|
||||||
compileSdk = 34
|
|
||||||
|
|
||||||
defaultConfig {
|
|
||||||
minSdk = 26
|
|
||||||
}
|
|
||||||
|
|
||||||
compileOptions {
|
|
||||||
sourceCompatibility = JavaVersion.VERSION_17
|
|
||||||
targetCompatibility = JavaVersion.VERSION_17
|
|
||||||
}
|
|
||||||
}
|
|
@ -1 +0,0 @@
|
|||||||
<manifest/>
|
|
@ -1,5 +0,0 @@
|
|||||||
package nl.nu.performance.api.client.interfaces;
|
|
||||||
|
|
||||||
public class Block {
|
|
||||||
|
|
||||||
}
|
|
@ -1,7 +0,0 @@
|
|||||||
package nl.nu.performance.api.client.objects;
|
|
||||||
|
|
||||||
import nl.nu.performance.api.client.interfaces.Block;
|
|
||||||
|
|
||||||
public class DividerBlock extends Block {
|
|
||||||
|
|
||||||
}
|
|
@ -1,7 +0,0 @@
|
|||||||
package nl.nu.performance.api.client.objects;
|
|
||||||
|
|
||||||
import nl.nu.performance.api.client.interfaces.Block;
|
|
||||||
|
|
||||||
public class DpgBannerBlock extends Block {
|
|
||||||
|
|
||||||
}
|
|
@ -1,10 +0,0 @@
|
|||||||
package nl.nu.performance.api.client.objects;
|
|
||||||
|
|
||||||
import nl.nu.performance.api.client.interfaces.Block;
|
|
||||||
|
|
||||||
public class HeaderBlock extends Block {
|
|
||||||
// returns title
|
|
||||||
public final StyledText component20() {
|
|
||||||
throw new UnsupportedOperationException("Stub");
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,13 +0,0 @@
|
|||||||
package nl.nu.performance.api.client.objects;
|
|
||||||
|
|
||||||
import nl.nu.performance.api.client.unions.LinkFlavor;
|
|
||||||
|
|
||||||
public class Link {
|
|
||||||
public final StyledText getTitle() {
|
|
||||||
throw new UnsupportedOperationException("Stub");
|
|
||||||
}
|
|
||||||
|
|
||||||
public final LinkFlavor getLinkFlavor() {
|
|
||||||
throw new UnsupportedOperationException("Stub");
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,10 +0,0 @@
|
|||||||
package nl.nu.performance.api.client.objects;
|
|
||||||
|
|
||||||
import android.os.Parcelable;
|
|
||||||
import nl.nu.performance.api.client.interfaces.Block;
|
|
||||||
|
|
||||||
public abstract class LinkBlock extends Block implements Parcelable {
|
|
||||||
public final Link getLink() {
|
|
||||||
throw new UnsupportedOperationException("Stub");
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,7 +0,0 @@
|
|||||||
package nl.nu.performance.api.client.objects;
|
|
||||||
|
|
||||||
public class StyledText {
|
|
||||||
public final String getText() {
|
|
||||||
throw new UnsupportedOperationException("Stub");
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,4 +0,0 @@
|
|||||||
package nl.nu.performance.api.client.unions;
|
|
||||||
|
|
||||||
public interface LinkFlavor {
|
|
||||||
}
|
|
@ -1,7 +0,0 @@
|
|||||||
package nl.nu.performance.api.client.unions;
|
|
||||||
|
|
||||||
public class SmallArticleLinkFlavor implements LinkFlavor {
|
|
||||||
public final Boolean isPartner() {
|
|
||||||
throw new UnsupportedOperationException("Stub");
|
|
||||||
}
|
|
||||||
}
|
|
9
extensions/proguard-rules.pro
vendored
9
extensions/proguard-rules.pro
vendored
@ -1,9 +0,0 @@
|
|||||||
-dontobfuscate
|
|
||||||
-dontoptimize
|
|
||||||
-keepattributes *
|
|
||||||
-keep class app.revanced.** {
|
|
||||||
*;
|
|
||||||
}
|
|
||||||
-keep class com.google.** {
|
|
||||||
*;
|
|
||||||
}
|
|
@ -1,3 +0,0 @@
|
|||||||
dependencies {
|
|
||||||
compileOnly(project(":extensions:reddit:stub"))
|
|
||||||
}
|
|
@ -1 +0,0 @@
|
|||||||
<manifest/>
|
|
@ -1,27 +0,0 @@
|
|||||||
package app.revanced.extension.reddit.patches;
|
|
||||||
|
|
||||||
import com.reddit.domain.model.ILink;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
public final class FilterPromotedLinksPatch {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Injection point.
|
|
||||||
*
|
|
||||||
* Filters list from promoted links.
|
|
||||||
**/
|
|
||||||
public static List<?> filterChildren(final Iterable<?> links) {
|
|
||||||
final List<Object> filteredList = new ArrayList<>();
|
|
||||||
|
|
||||||
for (Object item : links) {
|
|
||||||
if (item instanceof ILink && ((ILink) item).getPromoted()) continue;
|
|
||||||
|
|
||||||
filteredList.add(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
return filteredList;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,17 +0,0 @@
|
|||||||
plugins {
|
|
||||||
id(libs.plugins.android.library.get().pluginId)
|
|
||||||
}
|
|
||||||
|
|
||||||
android {
|
|
||||||
namespace = "app.revanced.extension"
|
|
||||||
compileSdk = 34
|
|
||||||
|
|
||||||
defaultConfig {
|
|
||||||
minSdk = 24
|
|
||||||
}
|
|
||||||
|
|
||||||
compileOptions {
|
|
||||||
sourceCompatibility = JavaVersion.VERSION_11
|
|
||||||
targetCompatibility = JavaVersion.VERSION_11
|
|
||||||
}
|
|
||||||
}
|
|
@ -1 +0,0 @@
|
|||||||
<manifest/>
|
|
@ -1,7 +0,0 @@
|
|||||||
package com.reddit.domain.model;
|
|
||||||
|
|
||||||
public class ILink {
|
|
||||||
public boolean getPromoted() {
|
|
||||||
throw new UnsupportedOperationException("Stub");
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,3 +0,0 @@
|
|||||||
dependencies {
|
|
||||||
implementation(project(":extensions:shared:library"))
|
|
||||||
}
|
|
@ -1,21 +0,0 @@
|
|||||||
plugins {
|
|
||||||
id("com.android.library")
|
|
||||||
}
|
|
||||||
|
|
||||||
android {
|
|
||||||
namespace = "app.revanced.extension"
|
|
||||||
compileSdk = 34
|
|
||||||
|
|
||||||
defaultConfig {
|
|
||||||
minSdk = 23
|
|
||||||
}
|
|
||||||
|
|
||||||
compileOptions {
|
|
||||||
sourceCompatibility = JavaVersion.VERSION_17
|
|
||||||
targetCompatibility = JavaVersion.VERSION_17
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
compileOnly(libs.annotation)
|
|
||||||
}
|
|
@ -1,171 +0,0 @@
|
|||||||
package app.revanced.extension.shared;
|
|
||||||
|
|
||||||
import static app.revanced.extension.shared.StringRef.str;
|
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.app.AlertDialog;
|
|
||||||
import android.app.SearchManager;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.DialogInterface;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.content.pm.PackageManager;
|
|
||||||
import android.net.Uri;
|
|
||||||
import android.os.Build;
|
|
||||||
import android.os.PowerManager;
|
|
||||||
import android.provider.Settings;
|
|
||||||
|
|
||||||
import androidx.annotation.RequiresApi;
|
|
||||||
|
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.URL;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @noinspection unused
|
|
||||||
*/
|
|
||||||
public class GmsCoreSupport {
|
|
||||||
private static final String PACKAGE_NAME_YOUTUBE = "com.google.android.youtube";
|
|
||||||
private static final String PACKAGE_NAME_YOUTUBE_MUSIC = "com.google.android.apps.youtube.music";
|
|
||||||
|
|
||||||
private static final String GMS_CORE_PACKAGE_NAME
|
|
||||||
= getGmsCoreVendorGroupId() + ".android.gms";
|
|
||||||
private static final Uri GMS_CORE_PROVIDER
|
|
||||||
= Uri.parse("content://" + getGmsCoreVendorGroupId() + ".android.gsf.gservices/prefix");
|
|
||||||
private static final String DONT_KILL_MY_APP_LINK
|
|
||||||
= "https://dontkillmyapp.com";
|
|
||||||
|
|
||||||
private static void open(String queryOrLink) {
|
|
||||||
Intent intent;
|
|
||||||
try {
|
|
||||||
// Check if queryOrLink is a valid URL.
|
|
||||||
new URL(queryOrLink);
|
|
||||||
|
|
||||||
intent = new Intent(Intent.ACTION_VIEW, Uri.parse(queryOrLink));
|
|
||||||
} catch (MalformedURLException e) {
|
|
||||||
intent = new Intent(Intent.ACTION_WEB_SEARCH);
|
|
||||||
intent.putExtra(SearchManager.QUERY, queryOrLink);
|
|
||||||
}
|
|
||||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
||||||
Utils.getContext().startActivity(intent);
|
|
||||||
|
|
||||||
// Gracefully exit, otherwise the broken app will continue to run.
|
|
||||||
System.exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void showBatteryOptimizationDialog(Activity context,
|
|
||||||
String dialogMessageRef,
|
|
||||||
String positiveButtonTextRef,
|
|
||||||
DialogInterface.OnClickListener onPositiveClickListener) {
|
|
||||||
// Use a delay to allow the activity to finish initializing.
|
|
||||||
// Otherwise, if device is in dark mode the dialog is shown with wrong color scheme.
|
|
||||||
Utils.runOnMainThreadDelayed(() -> {
|
|
||||||
// Do not set cancelable to false, to allow using back button to skip the action,
|
|
||||||
// just in case the battery change can never be satisfied.
|
|
||||||
var dialog = new AlertDialog.Builder(context)
|
|
||||||
.setTitle(str("gms_core_dialog_title"))
|
|
||||||
.setMessage(str(dialogMessageRef))
|
|
||||||
.setPositiveButton(str(positiveButtonTextRef), onPositiveClickListener)
|
|
||||||
.create();
|
|
||||||
Utils.showDialog(context, dialog);
|
|
||||||
}, 100);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Injection point.
|
|
||||||
*/
|
|
||||||
@RequiresApi(api = Build.VERSION_CODES.N)
|
|
||||||
public static void checkGmsCore(Activity context) {
|
|
||||||
try {
|
|
||||||
// Verify the user has not included GmsCore for a root installation.
|
|
||||||
// GmsCore Support changes the package name, but with a mounted installation
|
|
||||||
// all manifest changes are ignored and the original package name is used.
|
|
||||||
String packageName = context.getPackageName();
|
|
||||||
if (packageName.equals(PACKAGE_NAME_YOUTUBE) || packageName.equals(PACKAGE_NAME_YOUTUBE_MUSIC)) {
|
|
||||||
Logger.printInfo(() -> "App is mounted with root, but GmsCore patch was included");
|
|
||||||
// Cannot use localize text here, since the app will load
|
|
||||||
// resources from the unpatched app and all patch strings are missing.
|
|
||||||
Utils.showToastLong("The 'GmsCore support' patch breaks mount installations");
|
|
||||||
|
|
||||||
// Do not exit. If the app exits before launch completes (and without
|
|
||||||
// opening another activity), then on some devices such as Pixel phone Android 10
|
|
||||||
// no toast will be shown and the app will continually be relaunched
|
|
||||||
// with the appearance of a hung app.
|
|
||||||
}
|
|
||||||
|
|
||||||
// Verify GmsCore is installed.
|
|
||||||
try {
|
|
||||||
PackageManager manager = context.getPackageManager();
|
|
||||||
manager.getPackageInfo(GMS_CORE_PACKAGE_NAME, PackageManager.GET_ACTIVITIES);
|
|
||||||
} catch (PackageManager.NameNotFoundException exception) {
|
|
||||||
Logger.printInfo(() -> "GmsCore was not found");
|
|
||||||
// Cannot show a dialog and must show a toast,
|
|
||||||
// because on some installations the app crashes before a dialog can be displayed.
|
|
||||||
Utils.showToastLong(str("gms_core_toast_not_installed_message"));
|
|
||||||
open(getGmsCoreDownload());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if GmsCore is whitelisted from battery optimizations.
|
|
||||||
if (isAndroidAutomotive(context)) {
|
|
||||||
// Ignore Android Automotive devices (Google built-in),
|
|
||||||
// as there is no way to disable battery optimizations.
|
|
||||||
Logger.printDebug(() -> "Device is Android Automotive");
|
|
||||||
} else if (batteryOptimizationsEnabled(context)) {
|
|
||||||
Logger.printInfo(() -> "GmsCore is not whitelisted from battery optimizations");
|
|
||||||
|
|
||||||
showBatteryOptimizationDialog(context,
|
|
||||||
"gms_core_dialog_not_whitelisted_using_battery_optimizations_message",
|
|
||||||
"gms_core_dialog_continue_text",
|
|
||||||
(dialog, id) -> openGmsCoreDisableBatteryOptimizationsIntent(context));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if GmsCore is currently running in the background.
|
|
||||||
try (var client = context.getContentResolver().acquireContentProviderClient(GMS_CORE_PROVIDER)) {
|
|
||||||
if (client == null) {
|
|
||||||
Logger.printInfo(() -> "GmsCore is not running in the background");
|
|
||||||
|
|
||||||
showBatteryOptimizationDialog(context,
|
|
||||||
"gms_core_dialog_not_whitelisted_not_allowed_in_background_message",
|
|
||||||
"gms_core_dialog_open_website_text",
|
|
||||||
(dialog, id) -> open(DONT_KILL_MY_APP_LINK));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (Exception ex) {
|
|
||||||
Logger.printException(() -> "checkGmsCore failure", ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressLint("BatteryLife") // Permission is part of GmsCore
|
|
||||||
private static void openGmsCoreDisableBatteryOptimizationsIntent(Activity activity) {
|
|
||||||
Intent intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
|
|
||||||
intent.setData(Uri.fromParts("package", GMS_CORE_PACKAGE_NAME, null));
|
|
||||||
activity.startActivityForResult(intent, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return If GmsCore is not whitelisted from battery optimizations.
|
|
||||||
*/
|
|
||||||
private static boolean batteryOptimizationsEnabled(Context context) {
|
|
||||||
var powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
|
|
||||||
return !powerManager.isIgnoringBatteryOptimizations(GMS_CORE_PACKAGE_NAME);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean isAndroidAutomotive(Context context) {
|
|
||||||
return context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_AUTOMOTIVE);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String getGmsCoreDownload() {
|
|
||||||
final var vendorGroupId = getGmsCoreVendorGroupId();
|
|
||||||
//noinspection SwitchStatementWithTooFewBranches
|
|
||||||
return switch (vendorGroupId) {
|
|
||||||
case "app.revanced" -> "https://github.com/revanced/gmscore/releases/latest";
|
|
||||||
default -> vendorGroupId + ".android.gms";
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// Modified by a patch. Do not touch.
|
|
||||||
private static String getGmsCoreVendorGroupId() {
|
|
||||||
return "app.revanced";
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,156 +0,0 @@
|
|||||||
package app.revanced.extension.shared;
|
|
||||||
|
|
||||||
import android.util.Log;
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
import app.revanced.extension.shared.settings.BaseSettings;
|
|
||||||
|
|
||||||
import java.io.PrintWriter;
|
|
||||||
import java.io.StringWriter;
|
|
||||||
|
|
||||||
import static app.revanced.extension.shared.settings.BaseSettings.*;
|
|
||||||
|
|
||||||
public class Logger {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Log messages using lambdas.
|
|
||||||
*/
|
|
||||||
@FunctionalInterface
|
|
||||||
public interface LogMessage {
|
|
||||||
@NonNull
|
|
||||||
String buildMessageString();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return For outer classes, this returns {@link Class#getSimpleName()}.
|
|
||||||
* For static, inner, or anonymous classes, this returns the simple name of the enclosing class.
|
|
||||||
* <br>
|
|
||||||
* For example, each of these classes return 'SomethingView':
|
|
||||||
* <code>
|
|
||||||
* com.company.SomethingView
|
|
||||||
* com.company.SomethingView$StaticClass
|
|
||||||
* com.company.SomethingView$1
|
|
||||||
* </code>
|
|
||||||
*/
|
|
||||||
private String findOuterClassSimpleName() {
|
|
||||||
var selfClass = this.getClass();
|
|
||||||
|
|
||||||
String fullClassName = selfClass.getName();
|
|
||||||
final int dollarSignIndex = fullClassName.indexOf('$');
|
|
||||||
if (dollarSignIndex < 0) {
|
|
||||||
return selfClass.getSimpleName(); // Already an outer class.
|
|
||||||
}
|
|
||||||
|
|
||||||
// Class is inner, static, or anonymous.
|
|
||||||
// Parse the simple name full name.
|
|
||||||
// A class with no package returns index of -1, but incrementing gives index zero which is correct.
|
|
||||||
final int simpleClassNameStartIndex = fullClassName.lastIndexOf('.') + 1;
|
|
||||||
return fullClassName.substring(simpleClassNameStartIndex, dollarSignIndex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final String REVANCED_LOG_PREFIX = "revanced: ";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Logs debug messages under the outer class name of the code calling this method.
|
|
||||||
* Whenever possible, the log string should be constructed entirely inside {@link LogMessage#buildMessageString()}
|
|
||||||
* so the performance cost of building strings is paid only if {@link BaseSettings#DEBUG} is enabled.
|
|
||||||
*/
|
|
||||||
public static void printDebug(@NonNull LogMessage message) {
|
|
||||||
printDebug(message, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Logs debug messages under the outer class name of the code calling this method.
|
|
||||||
* Whenever possible, the log string should be constructed entirely inside {@link LogMessage#buildMessageString()}
|
|
||||||
* so the performance cost of building strings is paid only if {@link BaseSettings#DEBUG} is enabled.
|
|
||||||
*/
|
|
||||||
public static void printDebug(@NonNull LogMessage message, @Nullable Exception ex) {
|
|
||||||
if (DEBUG.get()) {
|
|
||||||
String logMessage = message.buildMessageString();
|
|
||||||
String logTag = REVANCED_LOG_PREFIX + message.findOuterClassSimpleName();
|
|
||||||
|
|
||||||
if (DEBUG_STACKTRACE.get()) {
|
|
||||||
var builder = new StringBuilder(logMessage);
|
|
||||||
var sw = new StringWriter();
|
|
||||||
new Throwable().printStackTrace(new PrintWriter(sw));
|
|
||||||
|
|
||||||
builder.append('\n').append(sw);
|
|
||||||
logMessage = builder.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ex == null) {
|
|
||||||
Log.d(logTag, logMessage);
|
|
||||||
} else {
|
|
||||||
Log.d(logTag, logMessage, ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Logs information messages using the outer class name of the code calling this method.
|
|
||||||
*/
|
|
||||||
public static void printInfo(@NonNull LogMessage message) {
|
|
||||||
printInfo(message, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Logs information messages using the outer class name of the code calling this method.
|
|
||||||
*/
|
|
||||||
public static void printInfo(@NonNull LogMessage message, @Nullable Exception ex) {
|
|
||||||
String logTag = REVANCED_LOG_PREFIX + message.findOuterClassSimpleName();
|
|
||||||
String logMessage = message.buildMessageString();
|
|
||||||
if (ex == null) {
|
|
||||||
Log.i(logTag, logMessage);
|
|
||||||
} else {
|
|
||||||
Log.i(logTag, logMessage, ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Logs exceptions under the outer class name of the code calling this method.
|
|
||||||
*/
|
|
||||||
public static void printException(@NonNull LogMessage message) {
|
|
||||||
printException(message, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Logs exceptions under the outer class name of the code calling this method.
|
|
||||||
* <p>
|
|
||||||
* If the calling code is showing it's own error toast,
|
|
||||||
* instead use {@link #printInfo(LogMessage, Exception)}
|
|
||||||
*
|
|
||||||
* @param message log message
|
|
||||||
* @param ex exception (optional)
|
|
||||||
*/
|
|
||||||
public static void printException(@NonNull LogMessage message, @Nullable Throwable ex) {
|
|
||||||
String messageString = message.buildMessageString();
|
|
||||||
String outerClassSimpleName = message.findOuterClassSimpleName();
|
|
||||||
String logMessage = REVANCED_LOG_PREFIX + outerClassSimpleName;
|
|
||||||
if (ex == null) {
|
|
||||||
Log.e(logMessage, messageString);
|
|
||||||
} else {
|
|
||||||
Log.e(logMessage, messageString, ex);
|
|
||||||
}
|
|
||||||
if (DEBUG_TOAST_ON_ERROR.get()) {
|
|
||||||
Utils.showToastLong(outerClassSimpleName + ": " + messageString);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Logging to use if {@link BaseSettings#DEBUG} or {@link Utils#getContext()} may not be initialized.
|
|
||||||
* Normally this method should not be used.
|
|
||||||
*/
|
|
||||||
public static void initializationInfo(@NonNull Class<?> callingClass, @NonNull String message) {
|
|
||||||
Log.i(REVANCED_LOG_PREFIX + callingClass.getSimpleName(), message);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Logging to use if {@link BaseSettings#DEBUG} or {@link Utils#getContext()} may not be initialized.
|
|
||||||
* Normally this method should not be used.
|
|
||||||
*/
|
|
||||||
public static void initializationException(@NonNull Class<?> callingClass, @NonNull String message,
|
|
||||||
@Nullable Exception ex) {
|
|
||||||
Log.e(REVANCED_LOG_PREFIX + callingClass.getSimpleName(), message, ex);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,122 +0,0 @@
|
|||||||
package app.revanced.extension.shared;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.res.Resources;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class StringRef {
|
|
||||||
private static Resources resources;
|
|
||||||
private static String packageName;
|
|
||||||
|
|
||||||
// must use a thread safe map, as this class is used both on and off the main thread
|
|
||||||
private static final Map<String, StringRef> strings = Collections.synchronizedMap(new HashMap<>());
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a cached instance.
|
|
||||||
* Should be used if the same String could be loaded more than once.
|
|
||||||
*
|
|
||||||
* @param id string resource name/id
|
|
||||||
* @see #sf(String)
|
|
||||||
*/
|
|
||||||
@NonNull
|
|
||||||
public static StringRef sfc(@NonNull String id) {
|
|
||||||
StringRef ref = strings.get(id);
|
|
||||||
if (ref == null) {
|
|
||||||
ref = new StringRef(id);
|
|
||||||
strings.put(id, ref);
|
|
||||||
}
|
|
||||||
return ref;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new instance, but does not cache the value.
|
|
||||||
* Should be used for Strings that are loaded exactly once.
|
|
||||||
*
|
|
||||||
* @param id string resource name/id
|
|
||||||
* @see #sfc(String)
|
|
||||||
*/
|
|
||||||
@NonNull
|
|
||||||
public static StringRef sf(@NonNull String id) {
|
|
||||||
return new StringRef(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets string value by string id, shorthand for <code>sfc(id).toString()</code>
|
|
||||||
*
|
|
||||||
* @param id string resource name/id
|
|
||||||
* @return String value from string.xml
|
|
||||||
*/
|
|
||||||
@NonNull
|
|
||||||
public static String str(@NonNull String id) {
|
|
||||||
return sfc(id).toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets string value by string id, shorthand for <code>sfc(id).toString()</code> and formats the string
|
|
||||||
* with given args.
|
|
||||||
*
|
|
||||||
* @param id string resource name/id
|
|
||||||
* @param args the args to format the string with
|
|
||||||
* @return String value from string.xml formatted with given args
|
|
||||||
*/
|
|
||||||
@NonNull
|
|
||||||
public static String str(@NonNull String id, Object... args) {
|
|
||||||
return String.format(str(id), args);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a StringRef object that'll not change it's value
|
|
||||||
*
|
|
||||||
* @param value value which toString() method returns when invoked on returned object
|
|
||||||
* @return Unique StringRef instance, its value will never change
|
|
||||||
*/
|
|
||||||
@NonNull
|
|
||||||
public static StringRef constant(@NonNull String value) {
|
|
||||||
final StringRef ref = new StringRef(value);
|
|
||||||
ref.resolved = true;
|
|
||||||
return ref;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Shorthand for <code>constant("")</code>
|
|
||||||
* Its value always resolves to empty string
|
|
||||||
*/
|
|
||||||
@NonNull
|
|
||||||
public static final StringRef empty = constant("");
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
private String value;
|
|
||||||
private boolean resolved;
|
|
||||||
|
|
||||||
public StringRef(@NonNull String resName) {
|
|
||||||
this.value = resName;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@NonNull
|
|
||||||
public String toString() {
|
|
||||||
if (!resolved) {
|
|
||||||
if (resources == null || packageName == null) {
|
|
||||||
Context context = Utils.getContext();
|
|
||||||
resources = context.getResources();
|
|
||||||
packageName = context.getPackageName();
|
|
||||||
}
|
|
||||||
resolved = true;
|
|
||||||
if (resources != null) {
|
|
||||||
final int identifier = resources.getIdentifier(value, "string", packageName);
|
|
||||||
if (identifier == 0)
|
|
||||||
Logger.printException(() -> "Resource not found: " + value);
|
|
||||||
else
|
|
||||||
value = resources.getString(identifier);
|
|
||||||
} else {
|
|
||||||
Logger.printException(() -> "Could not resolve resources!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,813 +0,0 @@
|
|||||||
package app.revanced.extension.shared;
|
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
|
||||||
import android.app.*;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.content.pm.ApplicationInfo;
|
|
||||||
import android.content.pm.PackageInfo;
|
|
||||||
import android.content.pm.PackageManager;
|
|
||||||
import android.content.res.Configuration;
|
|
||||||
import android.content.res.Resources;
|
|
||||||
import android.graphics.Color;
|
|
||||||
import android.net.ConnectivityManager;
|
|
||||||
import android.os.Build;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.os.Handler;
|
|
||||||
import android.os.Looper;
|
|
||||||
import android.preference.Preference;
|
|
||||||
import android.preference.PreferenceGroup;
|
|
||||||
import android.preference.PreferenceScreen;
|
|
||||||
import android.view.View;
|
|
||||||
import android.view.ViewGroup;
|
|
||||||
import android.view.ViewParent;
|
|
||||||
import android.view.animation.Animation;
|
|
||||||
import android.view.animation.AnimationUtils;
|
|
||||||
import android.widget.FrameLayout;
|
|
||||||
import android.widget.LinearLayout;
|
|
||||||
import android.widget.RelativeLayout;
|
|
||||||
import android.widget.Toast;
|
|
||||||
import android.widget.Toolbar;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
|
|
||||||
import java.text.Bidi;
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
import java.util.concurrent.Callable;
|
|
||||||
import java.util.concurrent.Future;
|
|
||||||
import java.util.concurrent.SynchronousQueue;
|
|
||||||
import java.util.concurrent.ThreadPoolExecutor;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
import app.revanced.extension.shared.settings.AppLanguage;
|
|
||||||
import app.revanced.extension.shared.settings.BaseSettings;
|
|
||||||
import app.revanced.extension.shared.settings.BooleanSetting;
|
|
||||||
import app.revanced.extension.shared.settings.preference.ReVancedAboutPreference;
|
|
||||||
|
|
||||||
public class Utils {
|
|
||||||
|
|
||||||
@SuppressLint("StaticFieldLeak")
|
|
||||||
private static volatile Context context;
|
|
||||||
|
|
||||||
private static String versionName;
|
|
||||||
private static String applicationLabel;
|
|
||||||
|
|
||||||
private Utils() {
|
|
||||||
} // utility class
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Injection point.
|
|
||||||
*
|
|
||||||
* @return The manifest 'Version' entry of the patches.jar used during patching.
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("SameReturnValue")
|
|
||||||
public static String getPatchesReleaseVersion() {
|
|
||||||
return ""; // Value is replaced during patching.
|
|
||||||
}
|
|
||||||
|
|
||||||
private static PackageInfo getPackageInfo() throws PackageManager.NameNotFoundException {
|
|
||||||
final var packageName = Objects.requireNonNull(getContext()).getPackageName();
|
|
||||||
|
|
||||||
PackageManager packageManager = context.getPackageManager();
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
|
||||||
return packageManager.getPackageInfo(
|
|
||||||
packageName,
|
|
||||||
PackageManager.PackageInfoFlags.of(0)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return packageManager.getPackageInfo(
|
|
||||||
packageName,
|
|
||||||
0
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return The version name of the app, such as 19.11.43
|
|
||||||
*/
|
|
||||||
public static String getAppVersionName() {
|
|
||||||
if (versionName == null) {
|
|
||||||
try {
|
|
||||||
versionName = getPackageInfo().versionName;
|
|
||||||
} catch (Exception ex) {
|
|
||||||
Logger.printException(() -> "Failed to get package info", ex);
|
|
||||||
versionName = "Unknown";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return versionName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getApplicationName() {
|
|
||||||
if (applicationLabel == null) {
|
|
||||||
try {
|
|
||||||
ApplicationInfo applicationInfo = getPackageInfo().applicationInfo;
|
|
||||||
applicationLabel = (String) applicationInfo.loadLabel(context.getPackageManager());
|
|
||||||
} catch (Exception ex) {
|
|
||||||
Logger.printException(() -> "Failed to get application name", ex);
|
|
||||||
applicationLabel = "Unknown";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return applicationLabel;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Hide a view by setting its layout height and width to 1dp.
|
|
||||||
*
|
|
||||||
* @param condition The setting to check for hiding the view.
|
|
||||||
* @param view The view to hide.
|
|
||||||
*/
|
|
||||||
public static void hideViewBy0dpUnderCondition(BooleanSetting condition, View view) {
|
|
||||||
if (hideViewBy0dpUnderCondition(condition.get(), view)) {
|
|
||||||
Logger.printDebug(() -> "View hidden by setting: " + condition);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Hide a view by setting its layout height and width to 0dp.
|
|
||||||
*
|
|
||||||
* @param condition The setting to check for hiding the view.
|
|
||||||
* @param view The view to hide.
|
|
||||||
*/
|
|
||||||
public static boolean hideViewBy0dpUnderCondition(boolean condition, View view) {
|
|
||||||
if (condition) {
|
|
||||||
hideViewByLayoutParams(view);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Hide a view by setting its visibility to GONE.
|
|
||||||
*
|
|
||||||
* @param condition The setting to check for hiding the view.
|
|
||||||
* @param view The view to hide.
|
|
||||||
*/
|
|
||||||
public static void hideViewUnderCondition(BooleanSetting condition, View view) {
|
|
||||||
if (hideViewUnderCondition(condition.get(), view)) {
|
|
||||||
Logger.printDebug(() -> "View hidden by setting: " + condition);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Hide a view by setting its visibility to GONE.
|
|
||||||
*
|
|
||||||
* @param condition The setting to check for hiding the view.
|
|
||||||
* @param view The view to hide.
|
|
||||||
*/
|
|
||||||
public static boolean hideViewUnderCondition(boolean condition, View view) {
|
|
||||||
if (condition) {
|
|
||||||
view.setVisibility(View.GONE);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void hideViewByRemovingFromParentUnderCondition(BooleanSetting condition, View view) {
|
|
||||||
if (hideViewByRemovingFromParentUnderCondition(condition.get(), view)) {
|
|
||||||
Logger.printDebug(() -> "View hidden by setting: " + condition);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean hideViewByRemovingFromParentUnderCondition(boolean setting, View view) {
|
|
||||||
if (setting) {
|
|
||||||
ViewParent parent = view.getParent();
|
|
||||||
if (parent instanceof ViewGroup) {
|
|
||||||
((ViewGroup) parent).removeView(view);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* General purpose pool for network calls and other background tasks.
|
|
||||||
* All tasks run at max thread priority.
|
|
||||||
*/
|
|
||||||
private static final ThreadPoolExecutor backgroundThreadPool = new ThreadPoolExecutor(
|
|
||||||
3, // 3 threads always ready to go
|
|
||||||
Integer.MAX_VALUE,
|
|
||||||
10, // For any threads over the minimum, keep them alive 10 seconds after they go idle
|
|
||||||
TimeUnit.SECONDS,
|
|
||||||
new SynchronousQueue<>(),
|
|
||||||
r -> { // ThreadFactory
|
|
||||||
Thread t = new Thread(r);
|
|
||||||
t.setPriority(Thread.MAX_PRIORITY); // run at max priority
|
|
||||||
return t;
|
|
||||||
});
|
|
||||||
|
|
||||||
public static void runOnBackgroundThread(@NonNull Runnable task) {
|
|
||||||
backgroundThreadPool.execute(task);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
public static <T> Future<T> submitOnBackgroundThread(@NonNull Callable<T> call) {
|
|
||||||
return backgroundThreadPool.submit(call);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Simulates a delay by doing meaningless calculations.
|
|
||||||
* Used for debugging to verify UI timeout logic.
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("UnusedReturnValue")
|
|
||||||
public static long doNothingForDuration(long amountOfTimeToWaste) {
|
|
||||||
final long timeCalculationStarted = System.currentTimeMillis();
|
|
||||||
Logger.printDebug(() -> "Artificially creating delay of: " + amountOfTimeToWaste + "ms");
|
|
||||||
|
|
||||||
long meaninglessValue = 0;
|
|
||||||
while (System.currentTimeMillis() - timeCalculationStarted < amountOfTimeToWaste) {
|
|
||||||
// could do a thread sleep, but that will trigger an exception if the thread is interrupted
|
|
||||||
meaninglessValue += Long.numberOfLeadingZeros((long) Math.exp(Math.random()));
|
|
||||||
}
|
|
||||||
// return the value, otherwise the compiler or VM might optimize and remove the meaningless time wasting work,
|
|
||||||
// leaving an empty loop that hammers on the System.currentTimeMillis native call
|
|
||||||
return meaninglessValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static boolean containsAny(@NonNull String value, @NonNull String... targets) {
|
|
||||||
return indexOfFirstFound(value, targets) >= 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int indexOfFirstFound(@NonNull String value, @NonNull String... targets) {
|
|
||||||
for (String string : targets) {
|
|
||||||
if (!string.isEmpty()) {
|
|
||||||
final int indexOf = value.indexOf(string);
|
|
||||||
if (indexOf >= 0) return indexOf;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return zero, if the resource is not found
|
|
||||||
*/
|
|
||||||
@SuppressLint("DiscouragedApi")
|
|
||||||
public static int getResourceIdentifier(@NonNull Context context, @NonNull String resourceIdentifierName, @NonNull String type) {
|
|
||||||
return context.getResources().getIdentifier(resourceIdentifierName, type, context.getPackageName());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return zero, if the resource is not found
|
|
||||||
*/
|
|
||||||
public static int getResourceIdentifier(@NonNull String resourceIdentifierName, @NonNull String type) {
|
|
||||||
return getResourceIdentifier(getContext(), resourceIdentifierName, type);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int getResourceInteger(@NonNull String resourceIdentifierName) throws Resources.NotFoundException {
|
|
||||||
return getContext().getResources().getInteger(getResourceIdentifier(resourceIdentifierName, "integer"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
public static Animation getResourceAnimation(@NonNull String resourceIdentifierName) throws Resources.NotFoundException {
|
|
||||||
return AnimationUtils.loadAnimation(getContext(), getResourceIdentifier(resourceIdentifierName, "anim"));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int getResourceColor(@NonNull String resourceIdentifierName) throws Resources.NotFoundException {
|
|
||||||
//noinspection deprecation
|
|
||||||
return getContext().getResources().getColor(getResourceIdentifier(resourceIdentifierName, "color"));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int getResourceDimensionPixelSize(@NonNull String resourceIdentifierName) throws Resources.NotFoundException {
|
|
||||||
return getContext().getResources().getDimensionPixelSize(getResourceIdentifier(resourceIdentifierName, "dimen"));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static float getResourceDimension(@NonNull String resourceIdentifierName) throws Resources.NotFoundException {
|
|
||||||
return getContext().getResources().getDimension(getResourceIdentifier(resourceIdentifierName, "dimen"));
|
|
||||||
}
|
|
||||||
|
|
||||||
public interface MatchFilter<T> {
|
|
||||||
boolean matches(T object);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Includes sub children.
|
|
||||||
*
|
|
||||||
* @noinspection unchecked
|
|
||||||
*/
|
|
||||||
public static <R extends View> R getChildViewByResourceName(@NonNull View view, @NonNull String str) {
|
|
||||||
var child = view.findViewById(Utils.getResourceIdentifier(str, "id"));
|
|
||||||
if (child != null) {
|
|
||||||
return (R) child;
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new IllegalArgumentException("View with resource name '" + str + "' not found");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param searchRecursively If children ViewGroups should also be
|
|
||||||
* recursively searched using depth first search.
|
|
||||||
* @return The first child view that matches the filter.
|
|
||||||
*/
|
|
||||||
@Nullable
|
|
||||||
public static <T extends View> T getChildView(@NonNull ViewGroup viewGroup, boolean searchRecursively,
|
|
||||||
@NonNull MatchFilter<View> filter) {
|
|
||||||
for (int i = 0, childCount = viewGroup.getChildCount(); i < childCount; i++) {
|
|
||||||
View childAt = viewGroup.getChildAt(i);
|
|
||||||
|
|
||||||
if (filter.matches(childAt)) {
|
|
||||||
//noinspection unchecked
|
|
||||||
return (T) childAt;
|
|
||||||
}
|
|
||||||
// Must do recursive after filter check, in case the filter is looking for a ViewGroup.
|
|
||||||
if (searchRecursively && childAt instanceof ViewGroup) {
|
|
||||||
T match = getChildView((ViewGroup) childAt, true, filter);
|
|
||||||
if (match != null) return match;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public static ViewParent getParentView(@NonNull View view, int nthParent) {
|
|
||||||
ViewParent parent = view.getParent();
|
|
||||||
|
|
||||||
int currentDepth = 0;
|
|
||||||
while (++currentDepth < nthParent && parent != null) {
|
|
||||||
parent = parent.getParent();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (currentDepth == nthParent) {
|
|
||||||
return parent;
|
|
||||||
}
|
|
||||||
|
|
||||||
final int currentDepthLog = currentDepth;
|
|
||||||
Logger.printDebug(() -> "Could not find parent view of depth: " + nthParent
|
|
||||||
+ " and instead found at: " + currentDepthLog + " view: " + view);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void restartApp(@NonNull Context context) {
|
|
||||||
String packageName = context.getPackageName();
|
|
||||||
Intent intent = Objects.requireNonNull(context.getPackageManager().getLaunchIntentForPackage(packageName));
|
|
||||||
Intent mainIntent = Intent.makeRestartActivityTask(intent.getComponent());
|
|
||||||
// Required for API 34 and later
|
|
||||||
// Ref: https://developer.android.com/about/versions/14/behavior-changes-14#safer-intents
|
|
||||||
mainIntent.setPackage(packageName);
|
|
||||||
context.startActivity(mainIntent);
|
|
||||||
System.exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Context getContext() {
|
|
||||||
if (context == null) {
|
|
||||||
Logger.initializationException(Utils.class, "Context is not set by extension hook, returning null", null);
|
|
||||||
}
|
|
||||||
return context;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setContext(Context appContext) {
|
|
||||||
// Must initially set context to check the app language.
|
|
||||||
context = appContext;
|
|
||||||
Logger.initializationInfo(Utils.class, "Set context: " + appContext);
|
|
||||||
|
|
||||||
AppLanguage language = BaseSettings.REVANCED_LANGUAGE.get();
|
|
||||||
if (language != AppLanguage.DEFAULT) {
|
|
||||||
// Create a new context with the desired language.
|
|
||||||
Logger.printDebug(() -> "Using app language: " + language);
|
|
||||||
Configuration config = appContext.getResources().getConfiguration();
|
|
||||||
config.setLocale(language.getLocale());
|
|
||||||
context = appContext.createConfigurationContext(config);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setClipboard(@NonNull String text) {
|
|
||||||
android.content.ClipboardManager clipboard = (android.content.ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
|
|
||||||
android.content.ClipData clip = android.content.ClipData.newPlainText("ReVanced", text);
|
|
||||||
clipboard.setPrimaryClip(clip);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isTablet() {
|
|
||||||
return context.getResources().getConfiguration().smallestScreenWidthDp >= 600;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
private static Boolean isRightToLeftTextLayout;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* If the device language uses right to left text layout (hebrew, arabic, etc)
|
|
||||||
*/
|
|
||||||
public static boolean isRightToLeftTextLayout() {
|
|
||||||
if (isRightToLeftTextLayout == null) {
|
|
||||||
String displayLanguage = Locale.getDefault().getDisplayLanguage();
|
|
||||||
isRightToLeftTextLayout = new Bidi(displayLanguage, Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT).isRightToLeft();
|
|
||||||
}
|
|
||||||
return isRightToLeftTextLayout;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return if the text contains at least 1 number character,
|
|
||||||
* including any unicode numbers such as Arabic.
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
|
|
||||||
public static boolean containsNumber(@NonNull CharSequence text) {
|
|
||||||
for (int index = 0, length = text.length(); index < length;) {
|
|
||||||
final int codePoint = Character.codePointAt(text, index);
|
|
||||||
if (Character.isDigit(codePoint)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
index += Character.charCount(codePoint);
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Ignore this class. It must be public to satisfy Android requirements.
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
public static final class DialogFragmentWrapper extends DialogFragment {
|
|
||||||
|
|
||||||
private Dialog dialog;
|
|
||||||
@Nullable
|
|
||||||
private DialogFragmentOnStartAction onStartAction;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onSaveInstanceState(Bundle outState) {
|
|
||||||
// Do not call super method to prevent state saving.
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
|
||||||
return dialog;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onStart() {
|
|
||||||
try {
|
|
||||||
super.onStart();
|
|
||||||
|
|
||||||
if (onStartAction != null) {
|
|
||||||
onStartAction.onStart((AlertDialog) getDialog());
|
|
||||||
}
|
|
||||||
} catch (Exception ex) {
|
|
||||||
Logger.printException(() -> "onStart failure: " + dialog.getClass().getSimpleName(), ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Interface for {@link #showDialog(Activity, AlertDialog, boolean, DialogFragmentOnStartAction)}.
|
|
||||||
*/
|
|
||||||
@FunctionalInterface
|
|
||||||
public interface DialogFragmentOnStartAction {
|
|
||||||
void onStart(AlertDialog dialog);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void showDialog(Activity activity, AlertDialog dialog) {
|
|
||||||
showDialog(activity, dialog, true, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Utility method to allow showing an AlertDialog on top of other alert dialogs.
|
|
||||||
* Calling this will always display the dialog on top of all other dialogs
|
|
||||||
* previously called using this method.
|
|
||||||
* <br>
|
|
||||||
* Be aware the on start action can be called multiple times for some situations,
|
|
||||||
* such as the user switching apps without dismissing the dialog then switching back to this app.
|
|
||||||
*<br>
|
|
||||||
* This method is only useful during app startup and multiple patches may show their own dialog,
|
|
||||||
* and the most important dialog can be called last (using a delay) so it's always on top.
|
|
||||||
*<br>
|
|
||||||
* For all other situations it's better to not use this method and
|
|
||||||
* call {@link AlertDialog#show()} on the dialog.
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
public static void showDialog(Activity activity,
|
|
||||||
AlertDialog dialog,
|
|
||||||
boolean isCancelable,
|
|
||||||
@Nullable DialogFragmentOnStartAction onStartAction) {
|
|
||||||
verifyOnMainThread();
|
|
||||||
|
|
||||||
DialogFragmentWrapper fragment = new DialogFragmentWrapper();
|
|
||||||
fragment.dialog = dialog;
|
|
||||||
fragment.onStartAction = onStartAction;
|
|
||||||
fragment.setCancelable(isCancelable);
|
|
||||||
|
|
||||||
fragment.show(activity.getFragmentManager(), null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Safe to call from any thread
|
|
||||||
*/
|
|
||||||
public static void showToastShort(@NonNull String messageToToast) {
|
|
||||||
showToast(messageToToast, Toast.LENGTH_SHORT);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Safe to call from any thread
|
|
||||||
*/
|
|
||||||
public static void showToastLong(@NonNull String messageToToast) {
|
|
||||||
showToast(messageToToast, Toast.LENGTH_LONG);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void showToast(@NonNull String messageToToast, int toastDuration) {
|
|
||||||
Objects.requireNonNull(messageToToast);
|
|
||||||
runOnMainThreadNowOrLater(() -> {
|
|
||||||
if (context == null) {
|
|
||||||
Logger.initializationException(Utils.class, "Cannot show toast (context is null): " + messageToToast, null);
|
|
||||||
} else {
|
|
||||||
Logger.printDebug(() -> "Showing toast: " + messageToToast);
|
|
||||||
Toast.makeText(context, messageToToast, toastDuration).show();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isDarkModeEnabled(Context context) {
|
|
||||||
Configuration config = context.getResources().getConfiguration();
|
|
||||||
final int currentNightMode = config.uiMode & Configuration.UI_MODE_NIGHT_MASK;
|
|
||||||
return currentNightMode == Configuration.UI_MODE_NIGHT_YES;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isLandscapeOrientation() {
|
|
||||||
final int orientation = context.getResources().getConfiguration().orientation;
|
|
||||||
return orientation == Configuration.ORIENTATION_LANDSCAPE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Automatically logs any exceptions the runnable throws.
|
|
||||||
*
|
|
||||||
* @see #runOnMainThreadNowOrLater(Runnable)
|
|
||||||
*/
|
|
||||||
public static void runOnMainThread(@NonNull Runnable runnable) {
|
|
||||||
runOnMainThreadDelayed(runnable, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Automatically logs any exceptions the runnable throws
|
|
||||||
*/
|
|
||||||
public static void runOnMainThreadDelayed(@NonNull Runnable runnable, long delayMillis) {
|
|
||||||
Runnable loggingRunnable = () -> {
|
|
||||||
try {
|
|
||||||
runnable.run();
|
|
||||||
} catch (Exception ex) {
|
|
||||||
Logger.printException(() -> runnable.getClass().getSimpleName() + ": " + ex.getMessage(), ex);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
new Handler(Looper.getMainLooper()).postDelayed(loggingRunnable, delayMillis);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* If called from the main thread, the code is run immediately.<p>
|
|
||||||
* If called off the main thread, this is the same as {@link #runOnMainThread(Runnable)}.
|
|
||||||
*/
|
|
||||||
public static void runOnMainThreadNowOrLater(@NonNull Runnable runnable) {
|
|
||||||
if (isCurrentlyOnMainThread()) {
|
|
||||||
runnable.run();
|
|
||||||
} else {
|
|
||||||
runOnMainThread(runnable);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return if the calling thread is on the main thread
|
|
||||||
*/
|
|
||||||
public static boolean isCurrentlyOnMainThread() {
|
|
||||||
return Looper.getMainLooper().isCurrentThread();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws IllegalStateException if the calling thread is _off_ the main thread
|
|
||||||
*/
|
|
||||||
public static void verifyOnMainThread() throws IllegalStateException {
|
|
||||||
if (!isCurrentlyOnMainThread()) {
|
|
||||||
throw new IllegalStateException("Must call _on_ the main thread");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws IllegalStateException if the calling thread is _on_ the main thread
|
|
||||||
*/
|
|
||||||
public static void verifyOffMainThread() throws IllegalStateException {
|
|
||||||
if (isCurrentlyOnMainThread()) {
|
|
||||||
throw new IllegalStateException("Must call _off_ the main thread");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum NetworkType {
|
|
||||||
NONE,
|
|
||||||
MOBILE,
|
|
||||||
OTHER,
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isNetworkConnected() {
|
|
||||||
NetworkType networkType = getNetworkType();
|
|
||||||
return networkType == NetworkType.MOBILE
|
|
||||||
|| networkType == NetworkType.OTHER;
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressLint({"MissingPermission", "deprecation"}) // Permission already included in YouTube.
|
|
||||||
public static NetworkType getNetworkType() {
|
|
||||||
Context networkContext = getContext();
|
|
||||||
if (networkContext == null) {
|
|
||||||
return NetworkType.NONE;
|
|
||||||
}
|
|
||||||
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
|
||||||
var networkInfo = cm.getActiveNetworkInfo();
|
|
||||||
|
|
||||||
if (networkInfo == null || !networkInfo.isConnected()) {
|
|
||||||
return NetworkType.NONE;
|
|
||||||
}
|
|
||||||
var type = networkInfo.getType();
|
|
||||||
return (type == ConnectivityManager.TYPE_MOBILE)
|
|
||||||
|| (type == ConnectivityManager.TYPE_BLUETOOTH) ? NetworkType.MOBILE : NetworkType.OTHER;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Hide a view by setting its layout params to 0x0
|
|
||||||
* @param view The view to hide.
|
|
||||||
*/
|
|
||||||
public static void hideViewByLayoutParams(View view) {
|
|
||||||
if (view instanceof LinearLayout) {
|
|
||||||
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(0, 0);
|
|
||||||
view.setLayoutParams(layoutParams);
|
|
||||||
} else if (view instanceof FrameLayout) {
|
|
||||||
FrameLayout.LayoutParams layoutParams2 = new FrameLayout.LayoutParams(0, 0);
|
|
||||||
view.setLayoutParams(layoutParams2);
|
|
||||||
} else if (view instanceof RelativeLayout) {
|
|
||||||
RelativeLayout.LayoutParams layoutParams3 = new RelativeLayout.LayoutParams(0, 0);
|
|
||||||
view.setLayoutParams(layoutParams3);
|
|
||||||
} else if (view instanceof Toolbar) {
|
|
||||||
Toolbar.LayoutParams layoutParams4 = new Toolbar.LayoutParams(0, 0);
|
|
||||||
view.setLayoutParams(layoutParams4);
|
|
||||||
} else if (view instanceof ViewGroup) {
|
|
||||||
ViewGroup.LayoutParams layoutParams5 = new ViewGroup.LayoutParams(0, 0);
|
|
||||||
view.setLayoutParams(layoutParams5);
|
|
||||||
} else {
|
|
||||||
ViewGroup.LayoutParams params = view.getLayoutParams();
|
|
||||||
params.width = 0;
|
|
||||||
params.height = 0;
|
|
||||||
view.setLayoutParams(params);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@link PreferenceScreen} and {@link PreferenceGroup} sorting styles.
|
|
||||||
*/
|
|
||||||
private enum Sort {
|
|
||||||
/**
|
|
||||||
* Sort by the localized preference title.
|
|
||||||
*/
|
|
||||||
BY_TITLE("_sort_by_title"),
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sort by the preference keys.
|
|
||||||
*/
|
|
||||||
BY_KEY("_sort_by_key"),
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Unspecified sorting.
|
|
||||||
*/
|
|
||||||
UNSORTED("_sort_by_unsorted");
|
|
||||||
|
|
||||||
final String keySuffix;
|
|
||||||
|
|
||||||
Sort(String keySuffix) {
|
|
||||||
this.keySuffix = keySuffix;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
static Sort fromKey(@Nullable String key, @NonNull Sort defaultSort) {
|
|
||||||
if (key != null) {
|
|
||||||
for (Sort sort : values()) {
|
|
||||||
if (key.endsWith(sort.keySuffix)) {
|
|
||||||
return sort;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return defaultSort;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final Pattern punctuationPattern = Pattern.compile("\\p{P}+");
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Strips all punctuation and converts to lower case. A null parameter returns an empty string.
|
|
||||||
*/
|
|
||||||
public static String removePunctuationConvertToLowercase(@Nullable CharSequence original) {
|
|
||||||
if (original == null) return "";
|
|
||||||
return punctuationPattern.matcher(original).replaceAll("").toLowerCase();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sort a PreferenceGroup and all it's sub groups by title or key.
|
|
||||||
*
|
|
||||||
* Sort order is determined by the preferences key {@link Sort} suffix.
|
|
||||||
*
|
|
||||||
* If a preference has no key or no {@link Sort} suffix,
|
|
||||||
* then the preferences are left unsorted.
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
public static void sortPreferenceGroups(@NonNull PreferenceGroup group) {
|
|
||||||
Sort groupSort = Sort.fromKey(group.getKey(), Sort.UNSORTED);
|
|
||||||
SortedMap<String, Preference> preferences = new TreeMap<>();
|
|
||||||
|
|
||||||
for (int i = 0, prefCount = group.getPreferenceCount(); i < prefCount; i++) {
|
|
||||||
Preference preference = group.getPreference(i);
|
|
||||||
|
|
||||||
final Sort preferenceSort;
|
|
||||||
if (preference instanceof PreferenceGroup subGroup) {
|
|
||||||
sortPreferenceGroups(subGroup);
|
|
||||||
preferenceSort = groupSort; // Sort value for groups is for it's content, not itself.
|
|
||||||
} else {
|
|
||||||
// Allow individual preferences to set a key sorting.
|
|
||||||
// Used to force a preference to the top or bottom of a group.
|
|
||||||
preferenceSort = Sort.fromKey(preference.getKey(), groupSort);
|
|
||||||
}
|
|
||||||
|
|
||||||
final String sortValue;
|
|
||||||
switch (preferenceSort) {
|
|
||||||
case BY_TITLE:
|
|
||||||
sortValue = removePunctuationConvertToLowercase(preference.getTitle());
|
|
||||||
break;
|
|
||||||
case BY_KEY:
|
|
||||||
sortValue = preference.getKey();
|
|
||||||
break;
|
|
||||||
case UNSORTED:
|
|
||||||
continue; // Keep original sorting.
|
|
||||||
default:
|
|
||||||
throw new IllegalStateException();
|
|
||||||
}
|
|
||||||
|
|
||||||
preferences.put(sortValue, preference);
|
|
||||||
}
|
|
||||||
|
|
||||||
int index = 0;
|
|
||||||
for (Preference pref : preferences.values()) {
|
|
||||||
int order = index++;
|
|
||||||
|
|
||||||
// Move any screens, intents, and the one off About preference to the top.
|
|
||||||
if (pref instanceof PreferenceScreen || pref instanceof ReVancedAboutPreference
|
|
||||||
|| pref.getIntent() != null) {
|
|
||||||
// Arbitrary high number.
|
|
||||||
order -= 1000;
|
|
||||||
}
|
|
||||||
|
|
||||||
pref.setOrder(order);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set all preferences to multiline titles if the device is not using an English variant.
|
|
||||||
* The English strings are heavily scrutinized and all titles fit on screen
|
|
||||||
* except 2 or 3 preference strings and those do not affect readability.
|
|
||||||
*
|
|
||||||
* Allowing multiline for those 2 or 3 English preferences looks weird and out of place,
|
|
||||||
* and visually it looks better to clip the text and keep all titles 1 line.
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
public static void setPreferenceTitlesToMultiLineIfNeeded(PreferenceGroup group) {
|
|
||||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
String revancedLocale = Utils.getContext().getResources().getConfiguration().locale.getLanguage();
|
|
||||||
if (revancedLocale.equals(Locale.ENGLISH.getLanguage())) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0, prefCount = group.getPreferenceCount(); i < prefCount; i++) {
|
|
||||||
Preference pref = group.getPreference(i);
|
|
||||||
pref.setSingleLineTitle(false);
|
|
||||||
|
|
||||||
if (pref instanceof PreferenceGroup subGroup) {
|
|
||||||
setPreferenceTitlesToMultiLineIfNeeded(subGroup);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* If {@link Fragment} uses [Android library] rather than [AndroidX library],
|
|
||||||
* the Dialog theme corresponding to [Android library] should be used.
|
|
||||||
* <p>
|
|
||||||
* If not, the following issues will occur:
|
|
||||||
* <a href="https://github.com/ReVanced/revanced-patches/issues/3061">ReVanced/revanced-patches#3061</a>
|
|
||||||
* <p>
|
|
||||||
* To prevent these issues, apply the Dialog theme corresponding to [Android library].
|
|
||||||
*/
|
|
||||||
public static void setEditTextDialogTheme(AlertDialog.Builder builder) {
|
|
||||||
final int editTextDialogStyle = getResourceIdentifier(
|
|
||||||
"revanced_edit_text_dialog_style", "style");
|
|
||||||
if (editTextDialogStyle != 0) {
|
|
||||||
builder.getContext().setTheme(editTextDialogStyle);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parse a color resource or hex code to an int representation of the color.
|
|
||||||
*/
|
|
||||||
public static int getColorFromString(String colorString) throws IllegalArgumentException, Resources.NotFoundException {
|
|
||||||
if (colorString.startsWith("#")) {
|
|
||||||
return Color.parseColor(colorString);
|
|
||||||
}
|
|
||||||
return getResourceColor(colorString);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,164 +0,0 @@
|
|||||||
package app.revanced.extension.shared.checks;
|
|
||||||
|
|
||||||
import static android.text.Html.FROM_HTML_MODE_COMPACT;
|
|
||||||
import static app.revanced.extension.shared.StringRef.str;
|
|
||||||
import static app.revanced.extension.shared.Utils.DialogFragmentOnStartAction;
|
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.app.AlertDialog;
|
|
||||||
import android.content.DialogInterface;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.net.Uri;
|
|
||||||
import android.text.Html;
|
|
||||||
import android.widget.Button;
|
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
|
|
||||||
import app.revanced.extension.shared.Logger;
|
|
||||||
import app.revanced.extension.shared.Utils;
|
|
||||||
import app.revanced.extension.shared.settings.BaseSettings;
|
|
||||||
|
|
||||||
abstract class Check {
|
|
||||||
private static final int NUMBER_OF_TIMES_TO_IGNORE_WARNING_BEFORE_DISABLING = 2;
|
|
||||||
|
|
||||||
private static final int SECONDS_BEFORE_SHOWING_IGNORE_BUTTON = 15;
|
|
||||||
private static final int SECONDS_BEFORE_SHOWING_WEBSITE_BUTTON = 10;
|
|
||||||
|
|
||||||
private static final Uri GOOD_SOURCE = Uri.parse("https://revanced.app");
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return If the check conclusively passed or failed. A null value indicates it neither passed nor failed.
|
|
||||||
*/
|
|
||||||
@Nullable
|
|
||||||
protected abstract Boolean check();
|
|
||||||
|
|
||||||
protected abstract String failureReason();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Specifies a sorting order for displaying the checks that failed.
|
|
||||||
* A lower value indicates to show first before other checks.
|
|
||||||
*/
|
|
||||||
public abstract int uiSortingValue();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* For debugging and development only.
|
|
||||||
* Forces all checks to be performed and the check failed dialog to be shown.
|
|
||||||
* Can be enabled by importing settings text with {@link BaseSettings#CHECK_ENVIRONMENT_WARNINGS_ISSUED}
|
|
||||||
* set to -1.
|
|
||||||
*/
|
|
||||||
static boolean debugAlwaysShowWarning() {
|
|
||||||
final boolean alwaysShowWarning = BaseSettings.CHECK_ENVIRONMENT_WARNINGS_ISSUED.get() < 0;
|
|
||||||
if (alwaysShowWarning) {
|
|
||||||
Logger.printInfo(() -> "Debug forcing environment check warning to show");
|
|
||||||
}
|
|
||||||
|
|
||||||
return alwaysShowWarning;
|
|
||||||
}
|
|
||||||
|
|
||||||
static boolean shouldRun() {
|
|
||||||
return BaseSettings.CHECK_ENVIRONMENT_WARNINGS_ISSUED.get()
|
|
||||||
< NUMBER_OF_TIMES_TO_IGNORE_WARNING_BEFORE_DISABLING;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void disableForever() {
|
|
||||||
Logger.printInfo(() -> "Environment checks disabled forever");
|
|
||||||
|
|
||||||
BaseSettings.CHECK_ENVIRONMENT_WARNINGS_ISSUED.save(Integer.MAX_VALUE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressLint("NewApi")
|
|
||||||
static void issueWarning(Activity activity, Collection<Check> failedChecks) {
|
|
||||||
final var reasons = new StringBuilder();
|
|
||||||
|
|
||||||
reasons.append("<ul>");
|
|
||||||
for (var check : failedChecks) {
|
|
||||||
// Add a non breaking space to fix bullet points spacing issue.
|
|
||||||
reasons.append("<li> ").append(check.failureReason());
|
|
||||||
}
|
|
||||||
reasons.append("</ul>");
|
|
||||||
|
|
||||||
var message = Html.fromHtml(
|
|
||||||
str("revanced_check_environment_failed_message", reasons.toString()),
|
|
||||||
FROM_HTML_MODE_COMPACT
|
|
||||||
);
|
|
||||||
|
|
||||||
Utils.runOnMainThreadDelayed(() -> {
|
|
||||||
AlertDialog alert = new AlertDialog.Builder(activity)
|
|
||||||
.setCancelable(false)
|
|
||||||
.setIconAttribute(android.R.attr.alertDialogIcon)
|
|
||||||
.setTitle(str("revanced_check_environment_failed_title"))
|
|
||||||
.setMessage(message)
|
|
||||||
.setPositiveButton(
|
|
||||||
" ",
|
|
||||||
(dialog, which) -> {
|
|
||||||
final var intent = new Intent(Intent.ACTION_VIEW, GOOD_SOURCE);
|
|
||||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
||||||
activity.startActivity(intent);
|
|
||||||
|
|
||||||
// Shutdown to prevent the user from navigating back to this app,
|
|
||||||
// which is no longer showing a warning dialog.
|
|
||||||
activity.finishAffinity();
|
|
||||||
System.exit(0);
|
|
||||||
}
|
|
||||||
).setNegativeButton(
|
|
||||||
" ",
|
|
||||||
(dialog, which) -> {
|
|
||||||
// Cleanup data if the user incorrectly imported a huge negative number.
|
|
||||||
final int current = Math.max(0, BaseSettings.CHECK_ENVIRONMENT_WARNINGS_ISSUED.get());
|
|
||||||
BaseSettings.CHECK_ENVIRONMENT_WARNINGS_ISSUED.save(current + 1);
|
|
||||||
|
|
||||||
dialog.dismiss();
|
|
||||||
}
|
|
||||||
).create();
|
|
||||||
|
|
||||||
Utils.showDialog(activity, alert, false, new DialogFragmentOnStartAction() {
|
|
||||||
boolean hasRun;
|
|
||||||
@Override
|
|
||||||
public void onStart(AlertDialog dialog) {
|
|
||||||
// Only run this once, otherwise if the user changes to a different app
|
|
||||||
// then changes back, this handler will run again and disable the buttons.
|
|
||||||
if (hasRun) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
hasRun = true;
|
|
||||||
|
|
||||||
var openWebsiteButton = dialog.getButton(DialogInterface.BUTTON_POSITIVE);
|
|
||||||
openWebsiteButton.setEnabled(false);
|
|
||||||
|
|
||||||
var dismissButton = dialog.getButton(DialogInterface.BUTTON_NEGATIVE);
|
|
||||||
dismissButton.setEnabled(false);
|
|
||||||
|
|
||||||
getCountdownRunnable(dismissButton, openWebsiteButton).run();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}, 1000); // Use a delay, so this dialog is shown on top of any other startup dialogs.
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Runnable getCountdownRunnable(Button dismissButton, Button openWebsiteButton) {
|
|
||||||
return new Runnable() {
|
|
||||||
private int secondsRemaining = SECONDS_BEFORE_SHOWING_IGNORE_BUTTON;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
Utils.verifyOnMainThread();
|
|
||||||
|
|
||||||
if (secondsRemaining > 0) {
|
|
||||||
if (secondsRemaining - SECONDS_BEFORE_SHOWING_WEBSITE_BUTTON == 0) {
|
|
||||||
openWebsiteButton.setText(str("revanced_check_environment_dialog_open_official_source_button"));
|
|
||||||
openWebsiteButton.setEnabled(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
secondsRemaining--;
|
|
||||||
|
|
||||||
Utils.runOnMainThreadDelayed(this, 1000);
|
|
||||||
} else {
|
|
||||||
dismissButton.setText(str("revanced_check_environment_dialog_ignore_button"));
|
|
||||||
dismissButton.setEnabled(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,341 +0,0 @@
|
|||||||
package app.revanced.extension.shared.checks;
|
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.pm.PackageInfo;
|
|
||||||
import android.content.pm.PackageManager;
|
|
||||||
import android.os.Build;
|
|
||||||
import android.util.Base64;
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
import app.revanced.extension.shared.Logger;
|
|
||||||
import app.revanced.extension.shared.Utils;
|
|
||||||
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.security.MessageDigest;
|
|
||||||
import java.security.NoSuchAlgorithmException;
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
import static app.revanced.extension.shared.StringRef.str;
|
|
||||||
import static app.revanced.extension.shared.checks.Check.debugAlwaysShowWarning;
|
|
||||||
import static app.revanced.extension.shared.checks.PatchInfo.Build.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This class is used to check if the app was patched by the user
|
|
||||||
* and not downloaded pre-patched, because pre-patched apps are difficult to trust.
|
|
||||||
* <br>
|
|
||||||
* Various indicators help to detect if the app was patched by the user.
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
public final class CheckEnvironmentPatch {
|
|
||||||
private static final boolean DEBUG_ALWAYS_SHOW_CHECK_FAILED_DIALOG = debugAlwaysShowWarning();
|
|
||||||
|
|
||||||
private enum InstallationType {
|
|
||||||
/**
|
|
||||||
* CLI patching, manual installation of a previously patched using adb,
|
|
||||||
* or root installation if stock app is first installed using adb.
|
|
||||||
*/
|
|
||||||
ADB((String) null),
|
|
||||||
ROOT_MOUNT_ON_APP_STORE("com.android.vending"),
|
|
||||||
MANAGER("app.revanced.manager.flutter",
|
|
||||||
"app.revanced.manager",
|
|
||||||
"app.revanced.manager.debug");
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
static InstallationType installTypeFromPackageName(@Nullable String packageName) {
|
|
||||||
for (InstallationType type : values()) {
|
|
||||||
for (String installPackageName : type.packageNames) {
|
|
||||||
if (Objects.equals(installPackageName, packageName)) {
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Array elements can be null.
|
|
||||||
*/
|
|
||||||
final String[] packageNames;
|
|
||||||
|
|
||||||
InstallationType(String... packageNames) {
|
|
||||||
this.packageNames = packageNames;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if the app is installed by the manager, the app store, or through adb/CLI.
|
|
||||||
* <br>
|
|
||||||
* Does not conclusively
|
|
||||||
* If the app is installed by the manager or the app store, it is likely, the app was patched using the manager,
|
|
||||||
* or installed manually via ADB (in the case of ReVanced CLI for example).
|
|
||||||
* <br>
|
|
||||||
* If the app is not installed by the manager or the app store, then the app was likely downloaded pre-patched
|
|
||||||
* and installed by the browser or another unknown app.
|
|
||||||
*/
|
|
||||||
private static class CheckExpectedInstaller extends Check {
|
|
||||||
@Nullable
|
|
||||||
InstallationType installerFound;
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
protected Boolean check() {
|
|
||||||
final var context = Utils.getContext();
|
|
||||||
|
|
||||||
final var installerPackageName =
|
|
||||||
context.getPackageManager().getInstallerPackageName(context.getPackageName());
|
|
||||||
|
|
||||||
Logger.printInfo(() -> "Installed by: " + installerPackageName);
|
|
||||||
|
|
||||||
installerFound = InstallationType.installTypeFromPackageName(installerPackageName);
|
|
||||||
final boolean passed = (installerFound != null);
|
|
||||||
|
|
||||||
Logger.printInfo(() -> passed
|
|
||||||
? "Apk was not installed from an unknown source"
|
|
||||||
: "Apk was installed from an unknown source");
|
|
||||||
|
|
||||||
return passed;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected String failureReason() {
|
|
||||||
return str("revanced_check_environment_manager_not_expected_installer");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int uiSortingValue() {
|
|
||||||
return -100; // Show first.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if the build properties are the same as during the patch.
|
|
||||||
* <br>
|
|
||||||
* If the build properties are the same as during the patch, it is likely, the app was patched on the same device.
|
|
||||||
* <br>
|
|
||||||
* If the build properties are different, the app was likely downloaded pre-patched or patched on another device.
|
|
||||||
*/
|
|
||||||
private static class CheckWasPatchedOnSameDevice extends Check {
|
|
||||||
@SuppressLint({"NewApi", "HardwareIds"})
|
|
||||||
@Override
|
|
||||||
protected Boolean check() {
|
|
||||||
if (PATCH_BOARD.isEmpty()) {
|
|
||||||
// Did not patch with Manager, and cannot conclusively say where this was from.
|
|
||||||
Logger.printInfo(() -> "APK does not contain a hardware signature and cannot compare to current device");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
//noinspection deprecation
|
|
||||||
final var passed = buildFieldEqualsHash("BOARD", Build.BOARD, PATCH_BOARD) &
|
|
||||||
buildFieldEqualsHash("BOOTLOADER", Build.BOOTLOADER, PATCH_BOOTLOADER) &
|
|
||||||
buildFieldEqualsHash("BRAND", Build.BRAND, PATCH_BRAND) &
|
|
||||||
buildFieldEqualsHash("CPU_ABI", Build.CPU_ABI, PATCH_CPU_ABI) &
|
|
||||||
buildFieldEqualsHash("CPU_ABI2", Build.CPU_ABI2, PATCH_CPU_ABI2) &
|
|
||||||
buildFieldEqualsHash("DEVICE", Build.DEVICE, PATCH_DEVICE) &
|
|
||||||
buildFieldEqualsHash("DISPLAY", Build.DISPLAY, PATCH_DISPLAY) &
|
|
||||||
buildFieldEqualsHash("FINGERPRINT", Build.FINGERPRINT, PATCH_FINGERPRINT) &
|
|
||||||
buildFieldEqualsHash("HARDWARE", Build.HARDWARE, PATCH_HARDWARE) &
|
|
||||||
buildFieldEqualsHash("HOST", Build.HOST, PATCH_HOST) &
|
|
||||||
buildFieldEqualsHash("ID", Build.ID, PATCH_ID) &
|
|
||||||
buildFieldEqualsHash("MANUFACTURER", Build.MANUFACTURER, PATCH_MANUFACTURER) &
|
|
||||||
buildFieldEqualsHash("MODEL", Build.MODEL, PATCH_MODEL) &
|
|
||||||
buildFieldEqualsHash("PRODUCT", Build.PRODUCT, PATCH_PRODUCT) &
|
|
||||||
buildFieldEqualsHash("RADIO", Build.RADIO, PATCH_RADIO) &
|
|
||||||
buildFieldEqualsHash("TAGS", Build.TAGS, PATCH_TAGS) &
|
|
||||||
buildFieldEqualsHash("TYPE", Build.TYPE, PATCH_TYPE) &
|
|
||||||
buildFieldEqualsHash("USER", Build.USER, PATCH_USER);
|
|
||||||
|
|
||||||
Logger.printInfo(() -> passed
|
|
||||||
? "Device hardware signature matches current device"
|
|
||||||
: "Device hardware signature does not match current device");
|
|
||||||
|
|
||||||
return passed;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected String failureReason() {
|
|
||||||
return str("revanced_check_environment_not_same_patching_device");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int uiSortingValue() {
|
|
||||||
return 0; // Show in the middle.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if the app was installed within the last 30 minutes after being patched.
|
|
||||||
* <br>
|
|
||||||
* If the app was installed within the last 30 minutes, it is likely, the app was patched by the user.
|
|
||||||
* <br>
|
|
||||||
* If the app was installed much later than the patch time, it is likely the app was
|
|
||||||
* downloaded pre-patched or the user waited too long to install the app.
|
|
||||||
*/
|
|
||||||
private static class CheckIsNearPatchTime extends Check {
|
|
||||||
/**
|
|
||||||
* How soon after patching the app must be installed to pass.
|
|
||||||
*/
|
|
||||||
static final int INSTALL_AFTER_PATCHING_DURATION_THRESHOLD = 30 * 60 * 1000; // 30 minutes.
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Milliseconds between the time the app was patched, and when it was installed/updated.
|
|
||||||
*/
|
|
||||||
long durationBetweenPatchingAndInstallation;
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
protected Boolean check() {
|
|
||||||
try {
|
|
||||||
Context context = Utils.getContext();
|
|
||||||
PackageManager packageManager = context.getPackageManager();
|
|
||||||
PackageInfo packageInfo = packageManager.getPackageInfo(context.getPackageName(), 0);
|
|
||||||
|
|
||||||
// Duration since initial install or last update, which ever is sooner.
|
|
||||||
durationBetweenPatchingAndInstallation = packageInfo.lastUpdateTime - PatchInfo.PATCH_TIME;
|
|
||||||
Logger.printInfo(() -> "App was installed/updated: "
|
|
||||||
+ (durationBetweenPatchingAndInstallation / (60 * 1000) + " minutes after patching"));
|
|
||||||
|
|
||||||
if (durationBetweenPatchingAndInstallation < 0) {
|
|
||||||
// Patch time is in the future and clearly wrong.
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (durationBetweenPatchingAndInstallation < INSTALL_AFTER_PATCHING_DURATION_THRESHOLD) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
} catch (PackageManager.NameNotFoundException ex) {
|
|
||||||
Logger.printException(() -> "Package name not found exception", ex); // Will never happen.
|
|
||||||
}
|
|
||||||
|
|
||||||
// User installed more than 30 minutes after patching.
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected String failureReason() {
|
|
||||||
if (durationBetweenPatchingAndInstallation < 0) {
|
|
||||||
// Could happen if the user has their device clock incorrectly set in the past,
|
|
||||||
// but assume that isn't the case and the apk was patched on a device with the wrong system time.
|
|
||||||
return str("revanced_check_environment_not_near_patch_time_invalid");
|
|
||||||
}
|
|
||||||
|
|
||||||
// If patched over 1 day ago, show how old this pre-patched apk is.
|
|
||||||
// Showing the age can help convey it's better to patch yourself and know it's the latest.
|
|
||||||
final long oneDay = 24 * 60 * 60 * 1000;
|
|
||||||
final long daysSincePatching = durationBetweenPatchingAndInstallation / oneDay;
|
|
||||||
if (daysSincePatching > 1) { // Use over 1 day to avoid singular vs plural strings.
|
|
||||||
return str("revanced_check_environment_not_near_patch_time_days", daysSincePatching);
|
|
||||||
}
|
|
||||||
|
|
||||||
return str("revanced_check_environment_not_near_patch_time");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int uiSortingValue() {
|
|
||||||
return 100; // Show last.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Injection point.
|
|
||||||
*/
|
|
||||||
public static void check(Activity context) {
|
|
||||||
// If the warning was already issued twice, or if the check was successful in the past,
|
|
||||||
// do not run the checks again.
|
|
||||||
if (!Check.shouldRun() && !DEBUG_ALWAYS_SHOW_CHECK_FAILED_DIALOG) {
|
|
||||||
Logger.printDebug(() -> "Environment checks are disabled");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Utils.runOnBackgroundThread(() -> {
|
|
||||||
try {
|
|
||||||
Logger.printInfo(() -> "Running environment checks");
|
|
||||||
List<Check> failedChecks = new ArrayList<>();
|
|
||||||
|
|
||||||
CheckWasPatchedOnSameDevice sameHardware = new CheckWasPatchedOnSameDevice();
|
|
||||||
Boolean hardwareCheckPassed = sameHardware.check();
|
|
||||||
if (hardwareCheckPassed != null) {
|
|
||||||
if (hardwareCheckPassed && !DEBUG_ALWAYS_SHOW_CHECK_FAILED_DIALOG) {
|
|
||||||
// Patched on the same device using Manager,
|
|
||||||
// and no further checks are needed.
|
|
||||||
Check.disableForever();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
failedChecks.add(sameHardware);
|
|
||||||
}
|
|
||||||
|
|
||||||
CheckExpectedInstaller installerCheck = new CheckExpectedInstaller();
|
|
||||||
if (installerCheck.check() && !DEBUG_ALWAYS_SHOW_CHECK_FAILED_DIALOG) {
|
|
||||||
// If the installer package is Manager but this code is reached,
|
|
||||||
// that means it must not be the right Manager otherwise the hardware hash
|
|
||||||
// signatures would be present and this check would not have run.
|
|
||||||
if (installerCheck.installerFound == InstallationType.MANAGER) {
|
|
||||||
failedChecks.add(installerCheck);
|
|
||||||
// Also could not have been patched on this device.
|
|
||||||
failedChecks.add(sameHardware);
|
|
||||||
} else if (failedChecks.isEmpty()) {
|
|
||||||
// ADB install of CLI build. Allow even if patched a long time ago.
|
|
||||||
Check.disableForever();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
failedChecks.add(installerCheck);
|
|
||||||
}
|
|
||||||
|
|
||||||
CheckIsNearPatchTime nearPatchTime = new CheckIsNearPatchTime();
|
|
||||||
Boolean timeCheckPassed = nearPatchTime.check();
|
|
||||||
if (timeCheckPassed && !DEBUG_ALWAYS_SHOW_CHECK_FAILED_DIALOG) {
|
|
||||||
// Allow installing recently patched apks,
|
|
||||||
// even if the install source is not Manager or ADB.
|
|
||||||
Check.disableForever();
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
failedChecks.add(nearPatchTime);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (DEBUG_ALWAYS_SHOW_CHECK_FAILED_DIALOG) {
|
|
||||||
// Show all failures for debugging layout.
|
|
||||||
failedChecks = Arrays.asList(
|
|
||||||
sameHardware,
|
|
||||||
nearPatchTime,
|
|
||||||
installerCheck
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
//noinspection ComparatorCombinators
|
|
||||||
Collections.sort(failedChecks, (o1, o2) -> o1.uiSortingValue() - o2.uiSortingValue());
|
|
||||||
|
|
||||||
Check.issueWarning(
|
|
||||||
context,
|
|
||||||
failedChecks
|
|
||||||
);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
Logger.printException(() -> "check failure", ex);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean buildFieldEqualsHash(String buildFieldName, String buildFieldValue, @Nullable String hash) {
|
|
||||||
try {
|
|
||||||
final var sha1 = MessageDigest.getInstance("SHA-1")
|
|
||||||
.digest(buildFieldValue.getBytes(StandardCharsets.UTF_8));
|
|
||||||
|
|
||||||
// Must be careful to use same base64 encoding Kotlin uses.
|
|
||||||
String runtimeHash = new String(Base64.encode(sha1, Base64.NO_WRAP), StandardCharsets.ISO_8859_1);
|
|
||||||
final boolean equals = runtimeHash.equals(hash);
|
|
||||||
if (!equals) {
|
|
||||||
Logger.printInfo(() -> "Hashes do not match. " + buildFieldName + ": '" + buildFieldValue
|
|
||||||
+ "' runtimeHash: '" + runtimeHash + "' patchTimeHash: '" + hash + "'");
|
|
||||||
}
|
|
||||||
|
|
||||||
return equals;
|
|
||||||
} catch (NoSuchAlgorithmException ex) {
|
|
||||||
Logger.printException(() -> "buildFieldEqualsHash failure", ex); // Will never happen.
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,32 +0,0 @@
|
|||||||
package app.revanced.extension.shared.checks;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fields are set by the patch. Do not modify.
|
|
||||||
* Fields are not final, because the compiler is inlining them.
|
|
||||||
*
|
|
||||||
* @noinspection CanBeFinal
|
|
||||||
*/
|
|
||||||
final class PatchInfo {
|
|
||||||
static long PATCH_TIME = 0L;
|
|
||||||
|
|
||||||
final static class Build {
|
|
||||||
static String PATCH_BOARD = "";
|
|
||||||
static String PATCH_BOOTLOADER = "";
|
|
||||||
static String PATCH_BRAND = "";
|
|
||||||
static String PATCH_CPU_ABI = "";
|
|
||||||
static String PATCH_CPU_ABI2 = "";
|
|
||||||
static String PATCH_DEVICE = "";
|
|
||||||
static String PATCH_DISPLAY = "";
|
|
||||||
static String PATCH_FINGERPRINT = "";
|
|
||||||
static String PATCH_HARDWARE = "";
|
|
||||||
static String PATCH_HOST = "";
|
|
||||||
static String PATCH_ID = "";
|
|
||||||
static String PATCH_MANUFACTURER = "";
|
|
||||||
static String PATCH_MODEL = "";
|
|
||||||
static String PATCH_PRODUCT = "";
|
|
||||||
static String PATCH_RADIO = "";
|
|
||||||
static String PATCH_TAGS = "";
|
|
||||||
static String PATCH_TYPE = "";
|
|
||||||
static String PATCH_USER = "";
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,208 +0,0 @@
|
|||||||
package app.revanced.extension.shared.fixes.slink;
|
|
||||||
|
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.net.Uri;
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import app.revanced.extension.shared.Logger;
|
|
||||||
import app.revanced.extension.shared.Utils;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.HttpURLConnection;
|
|
||||||
import java.net.SocketTimeoutException;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
import static app.revanced.extension.shared.Utils.getContext;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Base class to implement /s/ link resolution in 3rd party Reddit apps.
|
|
||||||
* <br>
|
|
||||||
* <br>
|
|
||||||
* Usage:
|
|
||||||
* <br>
|
|
||||||
* <br>
|
|
||||||
* An implementation of this class must have two static methods that are called by the app:
|
|
||||||
* <ul>
|
|
||||||
* <li>public static boolean patchResolveSLink(String link)</li>
|
|
||||||
* <li>public static void patchSetAccessToken(String accessToken)</li>
|
|
||||||
* </ul>
|
|
||||||
* The static methods must call the instance methods of the base class.
|
|
||||||
* <br>
|
|
||||||
* The singleton pattern can be used to access the instance of the class:
|
|
||||||
* <pre>
|
|
||||||
* {@code
|
|
||||||
* {
|
|
||||||
* INSTANCE = new FixSLinksPatch();
|
|
||||||
* }
|
|
||||||
* }
|
|
||||||
* </pre>
|
|
||||||
* Set the app's web view activity class as a fallback to open /s/ links if the resolution fails:
|
|
||||||
* <pre>
|
|
||||||
* {@code
|
|
||||||
* private FixSLinksPatch() {
|
|
||||||
* webViewActivityClass = WebViewActivity.class;
|
|
||||||
* }
|
|
||||||
* }
|
|
||||||
* </pre>
|
|
||||||
* Hook the app's navigation handler to call this method before doing any of its own resolution:
|
|
||||||
* <pre>
|
|
||||||
* {@code
|
|
||||||
* public static boolean patchResolveSLink(Context context, String link) {
|
|
||||||
* return INSTANCE.resolveSLink(context, link);
|
|
||||||
* }
|
|
||||||
* }
|
|
||||||
* </pre>
|
|
||||||
* If this method returns true, the app should early return and not do any of its own resolution.
|
|
||||||
* <br>
|
|
||||||
* <br>
|
|
||||||
* Hook the app's access token so that this class can use it to resolve /s/ links:
|
|
||||||
* <pre>
|
|
||||||
* {@code
|
|
||||||
* public static void patchSetAccessToken(String accessToken) {
|
|
||||||
* INSTANCE.setAccessToken(access_token);
|
|
||||||
* }
|
|
||||||
* }
|
|
||||||
* </pre>
|
|
||||||
*/
|
|
||||||
public abstract class BaseFixSLinksPatch {
|
|
||||||
/**
|
|
||||||
* The class of the activity used to open links in a web view if resolving them fails.
|
|
||||||
*/
|
|
||||||
protected Class<? extends Activity> webViewActivityClass;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The access token used to resolve the /s/ link.
|
|
||||||
*/
|
|
||||||
protected String accessToken;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The URL that was trying to be resolved before the access token was set.
|
|
||||||
* If this is not null, the URL will be resolved right after the access token is set.
|
|
||||||
*/
|
|
||||||
protected String pendingUrl;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The singleton instance of the class.
|
|
||||||
*/
|
|
||||||
protected static BaseFixSLinksPatch INSTANCE;
|
|
||||||
|
|
||||||
public boolean resolveSLink(String link) {
|
|
||||||
switch (resolveLink(link)) {
|
|
||||||
case ACCESS_TOKEN_START: {
|
|
||||||
pendingUrl = link;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
case DO_NOTHING:
|
|
||||||
return true;
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private ResolveResult resolveLink(String link) {
|
|
||||||
Context context = getContext();
|
|
||||||
if (link.matches(".*reddit\\.com/r/[^/]+/s/[^/]+")) {
|
|
||||||
// A link ends with #bypass if it failed to resolve below.
|
|
||||||
// resolveLink is called with the same link again but this time with #bypass
|
|
||||||
// so that the link is opened in the app browser instead of trying to resolve it again.
|
|
||||||
if (link.endsWith("#bypass")) {
|
|
||||||
openInAppBrowser(context, link);
|
|
||||||
|
|
||||||
return ResolveResult.DO_NOTHING;
|
|
||||||
}
|
|
||||||
|
|
||||||
Logger.printDebug(() -> "Resolving " + link);
|
|
||||||
|
|
||||||
if (accessToken == null) {
|
|
||||||
// This is not optimal.
|
|
||||||
// However, an accessToken is necessary to make an authenticated request to Reddit.
|
|
||||||
// in case Reddit has banned the IP - e.g. VPN.
|
|
||||||
Intent startIntent = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
|
|
||||||
context.startActivity(startIntent);
|
|
||||||
|
|
||||||
return ResolveResult.ACCESS_TOKEN_START;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Utils.runOnBackgroundThread(() -> {
|
|
||||||
String bypassLink = link + "#bypass";
|
|
||||||
|
|
||||||
String finalLocation = bypassLink;
|
|
||||||
try {
|
|
||||||
HttpURLConnection connection = getHttpURLConnection(link, accessToken);
|
|
||||||
connection.connect();
|
|
||||||
String location = connection.getHeaderField("location");
|
|
||||||
connection.disconnect();
|
|
||||||
|
|
||||||
Objects.requireNonNull(location, "Location is null");
|
|
||||||
|
|
||||||
finalLocation = location;
|
|
||||||
Logger.printDebug(() -> "Resolved " + link + " to " + location);
|
|
||||||
} catch (SocketTimeoutException e) {
|
|
||||||
Logger.printException(() -> "Timeout when trying to resolve " + link, e);
|
|
||||||
finalLocation = bypassLink;
|
|
||||||
} catch (Exception e) {
|
|
||||||
Logger.printException(() -> "Failed to resolve " + link, e);
|
|
||||||
finalLocation = bypassLink;
|
|
||||||
} finally {
|
|
||||||
Intent startIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(finalLocation));
|
|
||||||
startIntent.setPackage(context.getPackageName());
|
|
||||||
startIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
||||||
context.startActivity(startIntent);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return ResolveResult.DO_NOTHING;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ResolveResult.CONTINUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAccessToken(String accessToken) {
|
|
||||||
Logger.printDebug(() -> "Setting access token");
|
|
||||||
|
|
||||||
this.accessToken = accessToken;
|
|
||||||
|
|
||||||
// In case a link was trying to be resolved before access token was set.
|
|
||||||
// The link is resolved now, after the access token is set.
|
|
||||||
if (pendingUrl != null) {
|
|
||||||
String link = pendingUrl;
|
|
||||||
pendingUrl = null;
|
|
||||||
|
|
||||||
Logger.printDebug(() -> "Opening pending URL");
|
|
||||||
|
|
||||||
resolveLink(link);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void openInAppBrowser(Context context, String link) {
|
|
||||||
Intent intent = new Intent(context, webViewActivityClass);
|
|
||||||
intent.putExtra("url", link);
|
|
||||||
context.startActivity(intent);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
private HttpURLConnection getHttpURLConnection(String link, String accessToken) throws IOException {
|
|
||||||
URL url = new URL(link);
|
|
||||||
|
|
||||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
|
||||||
connection.setInstanceFollowRedirects(false);
|
|
||||||
connection.setRequestMethod("HEAD");
|
|
||||||
connection.setConnectTimeout(2000);
|
|
||||||
connection.setReadTimeout(2000);
|
|
||||||
|
|
||||||
if (accessToken != null) {
|
|
||||||
Logger.printDebug(() -> "Setting access token to make /s/ request");
|
|
||||||
|
|
||||||
connection.setRequestProperty("Authorization", "Bearer " + accessToken);
|
|
||||||
} else {
|
|
||||||
Logger.printDebug(() -> "Not setting access token to make /s/ request, because it is null");
|
|
||||||
}
|
|
||||||
|
|
||||||
return connection;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,10 +0,0 @@
|
|||||||
package app.revanced.extension.shared.fixes.slink;
|
|
||||||
|
|
||||||
public enum ResolveResult {
|
|
||||||
// Let app handle rest of stuff
|
|
||||||
CONTINUE,
|
|
||||||
// Start app, to make it cache its access_token
|
|
||||||
ACCESS_TOKEN_START,
|
|
||||||
// Don't do anything - we started resolving
|
|
||||||
DO_NOTHING
|
|
||||||
}
|
|
@ -1,145 +0,0 @@
|
|||||||
package app.revanced.extension.shared.requests;
|
|
||||||
|
|
||||||
import app.revanced.extension.shared.Utils;
|
|
||||||
import org.json.JSONArray;
|
|
||||||
import org.json.JSONException;
|
|
||||||
import org.json.JSONObject;
|
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.net.HttpURLConnection;
|
|
||||||
import java.net.URL;
|
|
||||||
|
|
||||||
public class Requester {
|
|
||||||
private Requester() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public static HttpURLConnection getConnectionFromRoute(String apiUrl, Route route, String... params) throws IOException {
|
|
||||||
return getConnectionFromCompiledRoute(apiUrl, route.compile(params));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static HttpURLConnection getConnectionFromCompiledRoute(String apiUrl, Route.CompiledRoute route) throws IOException {
|
|
||||||
String url = apiUrl + route.getCompiledRoute();
|
|
||||||
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
|
|
||||||
// Request data is in the URL parameters and no body is sent.
|
|
||||||
// The calling code must set a length if using a request body.
|
|
||||||
connection.setFixedLengthStreamingMode(0);
|
|
||||||
connection.setRequestMethod(route.getMethod().name());
|
|
||||||
String agentString = System.getProperty("http.agent")
|
|
||||||
+ "; ReVanced/" + Utils.getAppVersionName()
|
|
||||||
+ " (" + Utils.getPatchesReleaseVersion() + ")";
|
|
||||||
connection.setRequestProperty("User-Agent", agentString);
|
|
||||||
|
|
||||||
return connection;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parse the {@link HttpURLConnection}, and closes the underlying InputStream.
|
|
||||||
*/
|
|
||||||
private static String parseInputStreamAndClose(InputStream inputStream) throws IOException {
|
|
||||||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
|
|
||||||
StringBuilder jsonBuilder = new StringBuilder();
|
|
||||||
String line;
|
|
||||||
while ((line = reader.readLine()) != null) {
|
|
||||||
jsonBuilder.append(line);
|
|
||||||
jsonBuilder.append('\n');
|
|
||||||
}
|
|
||||||
return jsonBuilder.toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parse the {@link HttpURLConnection} response as a String.
|
|
||||||
* This does not close the url connection. If further requests to this host are unlikely
|
|
||||||
* in the near future, then instead use {@link #parseStringAndDisconnect(HttpURLConnection)}.
|
|
||||||
*/
|
|
||||||
public static String parseString(HttpURLConnection connection) throws IOException {
|
|
||||||
return parseInputStreamAndClose(connection.getInputStream());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parse the {@link HttpURLConnection} response as a String, and disconnect.
|
|
||||||
*
|
|
||||||
* <b>Should only be used if other requests to the server in the near future are unlikely</b>
|
|
||||||
*
|
|
||||||
* @see #parseString(HttpURLConnection)
|
|
||||||
*/
|
|
||||||
public static String parseStringAndDisconnect(HttpURLConnection connection) throws IOException {
|
|
||||||
String result = parseString(connection);
|
|
||||||
connection.disconnect();
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parse the {@link HttpURLConnection} error stream as a String.
|
|
||||||
* If the server sent no error response data, this returns an empty string.
|
|
||||||
*/
|
|
||||||
public static String parseErrorString(HttpURLConnection connection) throws IOException {
|
|
||||||
InputStream errorStream = connection.getErrorStream();
|
|
||||||
if (errorStream == null) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
return parseInputStreamAndClose(errorStream);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parse the {@link HttpURLConnection} error stream as a String, and disconnect.
|
|
||||||
* If the server sent no error response data, this returns an empty string.
|
|
||||||
*
|
|
||||||
* Should only be used if other requests to the server are unlikely in the near future.
|
|
||||||
*
|
|
||||||
* @see #parseErrorString(HttpURLConnection)
|
|
||||||
*/
|
|
||||||
public static String parseErrorStringAndDisconnect(HttpURLConnection connection) throws IOException {
|
|
||||||
String result = parseErrorString(connection);
|
|
||||||
connection.disconnect();
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parse the {@link HttpURLConnection} response into a JSONObject.
|
|
||||||
* This does not close the url connection. If further requests to this host are unlikely
|
|
||||||
* in the near future, then instead use {@link #parseJSONObjectAndDisconnect(HttpURLConnection)}.
|
|
||||||
*/
|
|
||||||
public static JSONObject parseJSONObject(HttpURLConnection connection) throws JSONException, IOException {
|
|
||||||
return new JSONObject(parseString(connection));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parse the {@link HttpURLConnection}, close the underlying InputStream, and disconnect.
|
|
||||||
*
|
|
||||||
* <b>Should only be used if other requests to the server in the near future are unlikely</b>
|
|
||||||
*
|
|
||||||
* @see #parseJSONObject(HttpURLConnection)
|
|
||||||
*/
|
|
||||||
public static JSONObject parseJSONObjectAndDisconnect(HttpURLConnection connection) throws JSONException, IOException {
|
|
||||||
JSONObject object = parseJSONObject(connection);
|
|
||||||
connection.disconnect();
|
|
||||||
return object;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parse the {@link HttpURLConnection}, and closes the underlying InputStream.
|
|
||||||
* This does not close the url connection. If further requests to this host are unlikely
|
|
||||||
* in the near future, then instead use {@link #parseJSONArrayAndDisconnect(HttpURLConnection)}.
|
|
||||||
*/
|
|
||||||
public static JSONArray parseJSONArray(HttpURLConnection connection) throws JSONException, IOException {
|
|
||||||
return new JSONArray(parseString(connection));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parse the {@link HttpURLConnection}, close the underlying InputStream, and disconnect.
|
|
||||||
*
|
|
||||||
* <b>Should only be used if other requests to the server in the near future are unlikely</b>
|
|
||||||
*
|
|
||||||
* @see #parseJSONArray(HttpURLConnection)
|
|
||||||
*/
|
|
||||||
public static JSONArray parseJSONArrayAndDisconnect(HttpURLConnection connection) throws JSONException, IOException {
|
|
||||||
JSONArray array = parseJSONArray(connection);
|
|
||||||
connection.disconnect();
|
|
||||||
return array;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,66 +0,0 @@
|
|||||||
package app.revanced.extension.shared.requests;
|
|
||||||
|
|
||||||
public class Route {
|
|
||||||
private final String route;
|
|
||||||
private final Method method;
|
|
||||||
private final int paramCount;
|
|
||||||
|
|
||||||
public Route(Method method, String route) {
|
|
||||||
this.method = method;
|
|
||||||
this.route = route;
|
|
||||||
this.paramCount = countMatches(route, '{');
|
|
||||||
|
|
||||||
if (paramCount != countMatches(route, '}'))
|
|
||||||
throw new IllegalArgumentException("Not enough parameters");
|
|
||||||
}
|
|
||||||
|
|
||||||
public Method getMethod() {
|
|
||||||
return method;
|
|
||||||
}
|
|
||||||
|
|
||||||
public CompiledRoute compile(String... params) {
|
|
||||||
if (params.length != paramCount)
|
|
||||||
throw new IllegalArgumentException("Error compiling route [" + route + "], incorrect amount of parameters provided. " +
|
|
||||||
"Expected: " + paramCount + ", provided: " + params.length);
|
|
||||||
|
|
||||||
StringBuilder compiledRoute = new StringBuilder(route);
|
|
||||||
for (int i = 0; i < paramCount; i++) {
|
|
||||||
int paramStart = compiledRoute.indexOf("{");
|
|
||||||
int paramEnd = compiledRoute.indexOf("}");
|
|
||||||
compiledRoute.replace(paramStart, paramEnd + 1, params[i]);
|
|
||||||
}
|
|
||||||
return new CompiledRoute(this, compiledRoute.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class CompiledRoute {
|
|
||||||
private final Route baseRoute;
|
|
||||||
private final String compiledRoute;
|
|
||||||
|
|
||||||
private CompiledRoute(Route baseRoute, String compiledRoute) {
|
|
||||||
this.baseRoute = baseRoute;
|
|
||||||
this.compiledRoute = compiledRoute;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getCompiledRoute() {
|
|
||||||
return compiledRoute;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Method getMethod() {
|
|
||||||
return baseRoute.method;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private int countMatches(CharSequence seq, char c) {
|
|
||||||
int count = 0;
|
|
||||||
for (int i = 0; i < seq.length(); i++) {
|
|
||||||
if (seq.charAt(i) == c)
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
return count;
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum Method {
|
|
||||||
GET,
|
|
||||||
POST
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,117 +0,0 @@
|
|||||||
package app.revanced.extension.shared.settings;
|
|
||||||
|
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
public enum AppLanguage {
|
|
||||||
/**
|
|
||||||
* The current app language.
|
|
||||||
*/
|
|
||||||
DEFAULT,
|
|
||||||
|
|
||||||
// Languages codes not included with YouTube, but are translated on Crowdin
|
|
||||||
GA,
|
|
||||||
|
|
||||||
// Language codes found in locale_config.xml
|
|
||||||
// All region specific variants have been removed.
|
|
||||||
AF,
|
|
||||||
AM,
|
|
||||||
AR,
|
|
||||||
AS,
|
|
||||||
AZ,
|
|
||||||
BE,
|
|
||||||
BG,
|
|
||||||
BN,
|
|
||||||
BS,
|
|
||||||
CA,
|
|
||||||
CS,
|
|
||||||
DA,
|
|
||||||
DE,
|
|
||||||
EL,
|
|
||||||
EN,
|
|
||||||
ES,
|
|
||||||
ET,
|
|
||||||
EU,
|
|
||||||
FA,
|
|
||||||
FI,
|
|
||||||
FR,
|
|
||||||
GL,
|
|
||||||
GU,
|
|
||||||
HI,
|
|
||||||
HE, // App uses obsolete 'IW' and not the modern 'HE' ISO code.
|
|
||||||
HR,
|
|
||||||
HU,
|
|
||||||
HY,
|
|
||||||
ID,
|
|
||||||
IS,
|
|
||||||
IT,
|
|
||||||
JA,
|
|
||||||
KA,
|
|
||||||
KK,
|
|
||||||
KM,
|
|
||||||
KN,
|
|
||||||
KO,
|
|
||||||
KY,
|
|
||||||
LO,
|
|
||||||
LT,
|
|
||||||
LV,
|
|
||||||
MK,
|
|
||||||
ML,
|
|
||||||
MN,
|
|
||||||
MR,
|
|
||||||
MS,
|
|
||||||
MY,
|
|
||||||
NE,
|
|
||||||
NL,
|
|
||||||
NB,
|
|
||||||
OR,
|
|
||||||
PA,
|
|
||||||
PL,
|
|
||||||
PT,
|
|
||||||
RO,
|
|
||||||
RU,
|
|
||||||
SI,
|
|
||||||
SK,
|
|
||||||
SL,
|
|
||||||
SQ,
|
|
||||||
SR,
|
|
||||||
SV,
|
|
||||||
SW,
|
|
||||||
TA,
|
|
||||||
TE,
|
|
||||||
TH,
|
|
||||||
TL,
|
|
||||||
TR,
|
|
||||||
UK,
|
|
||||||
UR,
|
|
||||||
UZ,
|
|
||||||
VI,
|
|
||||||
ZH,
|
|
||||||
ZU;
|
|
||||||
|
|
||||||
private final String language;
|
|
||||||
|
|
||||||
AppLanguage() {
|
|
||||||
language = name().toLowerCase(Locale.US);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return The 2 letter ISO 639_1 language code.
|
|
||||||
*/
|
|
||||||
public String getLanguage() {
|
|
||||||
// Changing the app language does not force the app to completely restart,
|
|
||||||
// so the default needs to be the current language and not a static field.
|
|
||||||
if (this == DEFAULT) {
|
|
||||||
return Locale.getDefault().getLanguage();
|
|
||||||
}
|
|
||||||
|
|
||||||
return language;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Locale getLocale() {
|
|
||||||
if (this == DEFAULT) {
|
|
||||||
return Locale.getDefault();
|
|
||||||
}
|
|
||||||
|
|
||||||
return Locale.forLanguageTag(language);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,39 +0,0 @@
|
|||||||
package app.revanced.extension.shared.settings;
|
|
||||||
|
|
||||||
import static java.lang.Boolean.FALSE;
|
|
||||||
import static java.lang.Boolean.TRUE;
|
|
||||||
import static app.revanced.extension.shared.settings.Setting.parent;
|
|
||||||
import static app.revanced.extension.shared.spoof.SpoofVideoStreamsPatch.AudioStreamLanguageOverrideAvailability;
|
|
||||||
import static app.revanced.extension.shared.spoof.SpoofVideoStreamsPatch.SpoofiOSAvailability;
|
|
||||||
|
|
||||||
import app.revanced.extension.shared.spoof.ClientType;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Settings shared across multiple apps.
|
|
||||||
* <p>
|
|
||||||
* To ensure this class is loaded when the UI is created, app specific setting bundles should extend
|
|
||||||
* or reference this class.
|
|
||||||
*/
|
|
||||||
public class BaseSettings {
|
|
||||||
public static final BooleanSetting DEBUG = new BooleanSetting("revanced_debug", FALSE);
|
|
||||||
public static final BooleanSetting DEBUG_STACKTRACE = new BooleanSetting("revanced_debug_stacktrace", FALSE, parent(DEBUG));
|
|
||||||
public static final BooleanSetting DEBUG_TOAST_ON_ERROR = new BooleanSetting("revanced_debug_toast_on_error", TRUE, "revanced_debug_toast_on_error_user_dialog_message");
|
|
||||||
|
|
||||||
public static final IntegerSetting CHECK_ENVIRONMENT_WARNINGS_ISSUED = new IntegerSetting("revanced_check_environment_warnings_issued", 0, true, false);
|
|
||||||
|
|
||||||
public static final EnumSetting<AppLanguage> REVANCED_LANGUAGE = new EnumSetting<>("revanced_language", AppLanguage.DEFAULT, true, "revanced_language_user_dialog_message");
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Use the icons declared in the preferences created during patching. If no icons or styles are declared then this setting does nothing.
|
|
||||||
*/
|
|
||||||
public static final BooleanSetting SHOW_MENU_ICONS = new BooleanSetting("revanced_show_menu_icons", TRUE, true);
|
|
||||||
|
|
||||||
public static final BooleanSetting SPOOF_VIDEO_STREAMS = new BooleanSetting("revanced_spoof_video_streams", TRUE, true, "revanced_spoof_video_streams_user_dialog_message");
|
|
||||||
public static final EnumSetting<AppLanguage> SPOOF_VIDEO_STREAMS_LANGUAGE = new EnumSetting<>("revanced_spoof_video_streams_language", AppLanguage.DEFAULT, new AudioStreamLanguageOverrideAvailability());
|
|
||||||
public static final BooleanSetting SPOOF_STREAMING_DATA_STATS_FOR_NERDS = new BooleanSetting("revanced_spoof_streaming_data_stats_for_nerds", TRUE, parent(SPOOF_VIDEO_STREAMS));
|
|
||||||
public static final BooleanSetting SPOOF_VIDEO_STREAMS_IOS_FORCE_AVC = new BooleanSetting("revanced_spoof_video_streams_ios_force_avc", FALSE, true,
|
|
||||||
"revanced_spoof_video_streams_ios_force_avc_user_dialog_message", new SpoofiOSAvailability());
|
|
||||||
// Client type must be last spoof setting due to cyclic references.
|
|
||||||
public static final EnumSetting<ClientType> SPOOF_VIDEO_STREAMS_CLIENT_TYPE = new EnumSetting<>("revanced_spoof_video_streams_client_type", ClientType.ANDROID_UNPLUGGED, true, parent(SPOOF_VIDEO_STREAMS));
|
|
||||||
|
|
||||||
}
|
|
@ -1,81 +0,0 @@
|
|||||||
package app.revanced.extension.shared.settings;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
|
|
||||||
import org.json.JSONException;
|
|
||||||
import org.json.JSONObject;
|
|
||||||
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
public class BooleanSetting extends Setting<Boolean> {
|
|
||||||
public BooleanSetting(String key, Boolean defaultValue) {
|
|
||||||
super(key, defaultValue);
|
|
||||||
}
|
|
||||||
public BooleanSetting(String key, Boolean defaultValue, boolean rebootApp) {
|
|
||||||
super(key, defaultValue, rebootApp);
|
|
||||||
}
|
|
||||||
public BooleanSetting(String key, Boolean defaultValue, boolean rebootApp, boolean includeWithImportExport) {
|
|
||||||
super(key, defaultValue, rebootApp, includeWithImportExport);
|
|
||||||
}
|
|
||||||
public BooleanSetting(String key, Boolean defaultValue, String userDialogMessage) {
|
|
||||||
super(key, defaultValue, userDialogMessage);
|
|
||||||
}
|
|
||||||
public BooleanSetting(String key, Boolean defaultValue, Availability availability) {
|
|
||||||
super(key, defaultValue, availability);
|
|
||||||
}
|
|
||||||
public BooleanSetting(String key, Boolean defaultValue, boolean rebootApp, String userDialogMessage) {
|
|
||||||
super(key, defaultValue, rebootApp, userDialogMessage);
|
|
||||||
}
|
|
||||||
public BooleanSetting(String key, Boolean defaultValue, boolean rebootApp, Availability availability) {
|
|
||||||
super(key, defaultValue, rebootApp, availability);
|
|
||||||
}
|
|
||||||
public BooleanSetting(String key, Boolean defaultValue, boolean rebootApp, String userDialogMessage, Availability availability) {
|
|
||||||
super(key, defaultValue, rebootApp, userDialogMessage, availability);
|
|
||||||
}
|
|
||||||
public BooleanSetting(@NonNull String key, @NonNull Boolean defaultValue, boolean rebootApp, boolean includeWithImportExport, @Nullable String userDialogMessage, @Nullable Availability availability) {
|
|
||||||
super(key, defaultValue, rebootApp, includeWithImportExport, userDialogMessage, availability);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets, but does _not_ persistently save the value.
|
|
||||||
* This method is only to be used by the Settings preference code.
|
|
||||||
*
|
|
||||||
* This intentionally is a static method to deter
|
|
||||||
* accidental usage when {@link #save(Boolean)} was intnded.
|
|
||||||
*/
|
|
||||||
public static void privateSetValue(@NonNull BooleanSetting setting, @NonNull Boolean newValue) {
|
|
||||||
setting.value = Objects.requireNonNull(newValue);
|
|
||||||
|
|
||||||
if (setting.isSetToDefault()) {
|
|
||||||
setting.removeFromPreferences();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void load() {
|
|
||||||
value = preferences.getBoolean(key, defaultValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Boolean readFromJSON(JSONObject json, String importExportKey) throws JSONException {
|
|
||||||
return json.getBoolean(importExportKey);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void setValueFromString(@NonNull String newValue) {
|
|
||||||
value = Boolean.valueOf(Objects.requireNonNull(newValue));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void saveToPreferences() {
|
|
||||||
preferences.saveBoolean(key, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
public Boolean get() {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,115 +0,0 @@
|
|||||||
package app.revanced.extension.shared.settings;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
|
|
||||||
import org.json.JSONException;
|
|
||||||
import org.json.JSONObject;
|
|
||||||
|
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
import app.revanced.extension.shared.Logger;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* If an Enum value is removed or changed, any saved or imported data using the
|
|
||||||
* non-existent value will be reverted to the default value
|
|
||||||
* (the event is logged, but no user error is displayed).
|
|
||||||
*
|
|
||||||
* All saved JSON text is converted to lowercase to keep the output less obnoxious.
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
public class EnumSetting<T extends Enum<?>> extends Setting<T> {
|
|
||||||
public EnumSetting(String key, T defaultValue) {
|
|
||||||
super(key, defaultValue);
|
|
||||||
}
|
|
||||||
public EnumSetting(String key, T defaultValue, boolean rebootApp) {
|
|
||||||
super(key, defaultValue, rebootApp);
|
|
||||||
}
|
|
||||||
public EnumSetting(String key, T defaultValue, boolean rebootApp, boolean includeWithImportExport) {
|
|
||||||
super(key, defaultValue, rebootApp, includeWithImportExport);
|
|
||||||
}
|
|
||||||
public EnumSetting(String key, T defaultValue, String userDialogMessage) {
|
|
||||||
super(key, defaultValue, userDialogMessage);
|
|
||||||
}
|
|
||||||
public EnumSetting(String key, T defaultValue, Availability availability) {
|
|
||||||
super(key, defaultValue, availability);
|
|
||||||
}
|
|
||||||
public EnumSetting(String key, T defaultValue, boolean rebootApp, String userDialogMessage) {
|
|
||||||
super(key, defaultValue, rebootApp, userDialogMessage);
|
|
||||||
}
|
|
||||||
public EnumSetting(String key, T defaultValue, boolean rebootApp, Availability availability) {
|
|
||||||
super(key, defaultValue, rebootApp, availability);
|
|
||||||
}
|
|
||||||
public EnumSetting(String key, T defaultValue, boolean rebootApp, String userDialogMessage, Availability availability) {
|
|
||||||
super(key, defaultValue, rebootApp, userDialogMessage, availability);
|
|
||||||
}
|
|
||||||
public EnumSetting(@NonNull String key, @NonNull T defaultValue, boolean rebootApp, boolean includeWithImportExport, @Nullable String userDialogMessage, @Nullable Availability availability) {
|
|
||||||
super(key, defaultValue, rebootApp, includeWithImportExport, userDialogMessage, availability);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void load() {
|
|
||||||
value = preferences.getEnum(key, defaultValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected T readFromJSON(JSONObject json, String importExportKey) throws JSONException {
|
|
||||||
String enumName = json.getString(importExportKey);
|
|
||||||
try {
|
|
||||||
return getEnumFromString(enumName);
|
|
||||||
} catch (IllegalArgumentException ex) {
|
|
||||||
// Info level to allow removing enum values in the future without showing any user errors.
|
|
||||||
Logger.printInfo(() -> "Using default, and ignoring unknown enum value: " + enumName, ex);
|
|
||||||
return defaultValue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void writeToJSON(JSONObject json, String importExportKey) throws JSONException {
|
|
||||||
// Use lowercase to keep the output less ugly.
|
|
||||||
json.put(importExportKey, value.name().toLowerCase(Locale.ENGLISH));
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
private T getEnumFromString(String enumName) {
|
|
||||||
//noinspection ConstantConditions
|
|
||||||
for (Enum<?> value : defaultValue.getClass().getEnumConstants()) {
|
|
||||||
if (value.name().equalsIgnoreCase(enumName)) {
|
|
||||||
// noinspection unchecked
|
|
||||||
return (T) value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw new IllegalArgumentException("Unknown enum value: " + enumName);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void setValueFromString(@NonNull String newValue) {
|
|
||||||
value = getEnumFromString(Objects.requireNonNull(newValue));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void saveToPreferences() {
|
|
||||||
preferences.saveEnumAsString(key, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
public T get() {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Availability based on if this setting is currently set to any of the provided types.
|
|
||||||
*/
|
|
||||||
@SafeVarargs
|
|
||||||
public final Setting.Availability availability(@NonNull T... types) {
|
|
||||||
return () -> {
|
|
||||||
T currentEnumType = get();
|
|
||||||
for (T enumType : types) {
|
|
||||||
if (currentEnumType == enumType) return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,67 +0,0 @@
|
|||||||
package app.revanced.extension.shared.settings;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
|
|
||||||
import org.json.JSONException;
|
|
||||||
import org.json.JSONObject;
|
|
||||||
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
public class FloatSetting extends Setting<Float> {
|
|
||||||
|
|
||||||
public FloatSetting(String key, Float defaultValue) {
|
|
||||||
super(key, defaultValue);
|
|
||||||
}
|
|
||||||
public FloatSetting(String key, Float defaultValue, boolean rebootApp) {
|
|
||||||
super(key, defaultValue, rebootApp);
|
|
||||||
}
|
|
||||||
public FloatSetting(String key, Float defaultValue, boolean rebootApp, boolean includeWithImportExport) {
|
|
||||||
super(key, defaultValue, rebootApp, includeWithImportExport);
|
|
||||||
}
|
|
||||||
public FloatSetting(String key, Float defaultValue, String userDialogMessage) {
|
|
||||||
super(key, defaultValue, userDialogMessage);
|
|
||||||
}
|
|
||||||
public FloatSetting(String key, Float defaultValue, Availability availability) {
|
|
||||||
super(key, defaultValue, availability);
|
|
||||||
}
|
|
||||||
public FloatSetting(String key, Float defaultValue, boolean rebootApp, String userDialogMessage) {
|
|
||||||
super(key, defaultValue, rebootApp, userDialogMessage);
|
|
||||||
}
|
|
||||||
public FloatSetting(String key, Float defaultValue, boolean rebootApp, Availability availability) {
|
|
||||||
super(key, defaultValue, rebootApp, availability);
|
|
||||||
}
|
|
||||||
public FloatSetting(String key, Float defaultValue, boolean rebootApp, String userDialogMessage, Availability availability) {
|
|
||||||
super(key, defaultValue, rebootApp, userDialogMessage, availability);
|
|
||||||
}
|
|
||||||
public FloatSetting(@NonNull String key, @NonNull Float defaultValue, boolean rebootApp, boolean includeWithImportExport, @Nullable String userDialogMessage, @Nullable Availability availability) {
|
|
||||||
super(key, defaultValue, rebootApp, includeWithImportExport, userDialogMessage, availability);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void load() {
|
|
||||||
value = preferences.getFloatString(key, defaultValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Float readFromJSON(JSONObject json, String importExportKey) throws JSONException {
|
|
||||||
return (float) json.getDouble(importExportKey);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void setValueFromString(@NonNull String newValue) {
|
|
||||||
value = Float.valueOf(Objects.requireNonNull(newValue));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void saveToPreferences() {
|
|
||||||
preferences.saveFloatString(key, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
public Float get() {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,67 +0,0 @@
|
|||||||
package app.revanced.extension.shared.settings;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
|
|
||||||
import org.json.JSONException;
|
|
||||||
import org.json.JSONObject;
|
|
||||||
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
public class IntegerSetting extends Setting<Integer> {
|
|
||||||
|
|
||||||
public IntegerSetting(String key, Integer defaultValue) {
|
|
||||||
super(key, defaultValue);
|
|
||||||
}
|
|
||||||
public IntegerSetting(String key, Integer defaultValue, boolean rebootApp) {
|
|
||||||
super(key, defaultValue, rebootApp);
|
|
||||||
}
|
|
||||||
public IntegerSetting(String key, Integer defaultValue, boolean rebootApp, boolean includeWithImportExport) {
|
|
||||||
super(key, defaultValue, rebootApp, includeWithImportExport);
|
|
||||||
}
|
|
||||||
public IntegerSetting(String key, Integer defaultValue, String userDialogMessage) {
|
|
||||||
super(key, defaultValue, userDialogMessage);
|
|
||||||
}
|
|
||||||
public IntegerSetting(String key, Integer defaultValue, Availability availability) {
|
|
||||||
super(key, defaultValue, availability);
|
|
||||||
}
|
|
||||||
public IntegerSetting(String key, Integer defaultValue, boolean rebootApp, String userDialogMessage) {
|
|
||||||
super(key, defaultValue, rebootApp, userDialogMessage);
|
|
||||||
}
|
|
||||||
public IntegerSetting(String key, Integer defaultValue, boolean rebootApp, Availability availability) {
|
|
||||||
super(key, defaultValue, rebootApp, availability);
|
|
||||||
}
|
|
||||||
public IntegerSetting(String key, Integer defaultValue, boolean rebootApp, String userDialogMessage, Availability availability) {
|
|
||||||
super(key, defaultValue, rebootApp, userDialogMessage, availability);
|
|
||||||
}
|
|
||||||
public IntegerSetting(@NonNull String key, @NonNull Integer defaultValue, boolean rebootApp, boolean includeWithImportExport, @Nullable String userDialogMessage, @Nullable Availability availability) {
|
|
||||||
super(key, defaultValue, rebootApp, includeWithImportExport, userDialogMessage, availability);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void load() {
|
|
||||||
value = preferences.getIntegerString(key, defaultValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Integer readFromJSON(JSONObject json, String importExportKey) throws JSONException {
|
|
||||||
return json.getInt(importExportKey);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void setValueFromString(@NonNull String newValue) {
|
|
||||||
value = Integer.valueOf(Objects.requireNonNull(newValue));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void saveToPreferences() {
|
|
||||||
preferences.saveIntegerString(key, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
public Integer get() {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,67 +0,0 @@
|
|||||||
package app.revanced.extension.shared.settings;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
|
|
||||||
import org.json.JSONException;
|
|
||||||
import org.json.JSONObject;
|
|
||||||
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
public class LongSetting extends Setting<Long> {
|
|
||||||
|
|
||||||
public LongSetting(String key, Long defaultValue) {
|
|
||||||
super(key, defaultValue);
|
|
||||||
}
|
|
||||||
public LongSetting(String key, Long defaultValue, boolean rebootApp) {
|
|
||||||
super(key, defaultValue, rebootApp);
|
|
||||||
}
|
|
||||||
public LongSetting(String key, Long defaultValue, boolean rebootApp, boolean includeWithImportExport) {
|
|
||||||
super(key, defaultValue, rebootApp, includeWithImportExport);
|
|
||||||
}
|
|
||||||
public LongSetting(String key, Long defaultValue, String userDialogMessage) {
|
|
||||||
super(key, defaultValue, userDialogMessage);
|
|
||||||
}
|
|
||||||
public LongSetting(String key, Long defaultValue, Availability availability) {
|
|
||||||
super(key, defaultValue, availability);
|
|
||||||
}
|
|
||||||
public LongSetting(String key, Long defaultValue, boolean rebootApp, String userDialogMessage) {
|
|
||||||
super(key, defaultValue, rebootApp, userDialogMessage);
|
|
||||||
}
|
|
||||||
public LongSetting(String key, Long defaultValue, boolean rebootApp, Availability availability) {
|
|
||||||
super(key, defaultValue, rebootApp, availability);
|
|
||||||
}
|
|
||||||
public LongSetting(String key, Long defaultValue, boolean rebootApp, String userDialogMessage, Availability availability) {
|
|
||||||
super(key, defaultValue, rebootApp, userDialogMessage, availability);
|
|
||||||
}
|
|
||||||
public LongSetting(@NonNull String key, @NonNull Long defaultValue, boolean rebootApp, boolean includeWithImportExport, @Nullable String userDialogMessage, @Nullable Availability availability) {
|
|
||||||
super(key, defaultValue, rebootApp, includeWithImportExport, userDialogMessage, availability);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void load() {
|
|
||||||
value = preferences.getLongString(key, defaultValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Long readFromJSON(JSONObject json, String importExportKey) throws JSONException {
|
|
||||||
return json.getLong(importExportKey);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void setValueFromString(@NonNull String newValue) {
|
|
||||||
value = Long.valueOf(Objects.requireNonNull(newValue));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void saveToPreferences() {
|
|
||||||
preferences.saveLongString(key, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
public Long get() {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,495 +0,0 @@
|
|||||||
package app.revanced.extension.shared.settings;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
import app.revanced.extension.shared.Logger;
|
|
||||||
import app.revanced.extension.shared.StringRef;
|
|
||||||
import app.revanced.extension.shared.Utils;
|
|
||||||
import app.revanced.extension.shared.settings.preference.SharedPrefCategory;
|
|
||||||
import org.json.JSONException;
|
|
||||||
import org.json.JSONObject;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
import static app.revanced.extension.shared.StringRef.str;
|
|
||||||
|
|
||||||
public abstract class Setting<T> {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Indicates if a {@link Setting} is available to edit and use.
|
|
||||||
* Typically this is dependent upon other BooleanSetting(s) set to 'true',
|
|
||||||
* but this can be used to call into extension code and check other conditions.
|
|
||||||
*/
|
|
||||||
public interface Availability {
|
|
||||||
boolean isAvailable();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Availability based on a single parent setting being enabled.
|
|
||||||
*/
|
|
||||||
@NonNull
|
|
||||||
public static Availability parent(@NonNull BooleanSetting parent) {
|
|
||||||
return parent::get;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Availability based on all parents being enabled.
|
|
||||||
*/
|
|
||||||
@NonNull
|
|
||||||
public static Availability parentsAll(@NonNull BooleanSetting... parents) {
|
|
||||||
return () -> {
|
|
||||||
for (BooleanSetting parent : parents) {
|
|
||||||
if (!parent.get()) return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Availability based on any parent being enabled.
|
|
||||||
*/
|
|
||||||
@NonNull
|
|
||||||
public static Availability parentsAny(@NonNull BooleanSetting... parents) {
|
|
||||||
return () -> {
|
|
||||||
for (BooleanSetting parent : parents) {
|
|
||||||
if (parent.get()) return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Callback for importing/exporting settings.
|
|
||||||
*/
|
|
||||||
public interface ImportExportCallback {
|
|
||||||
/**
|
|
||||||
* Called after all settings have been imported.
|
|
||||||
*/
|
|
||||||
void settingsImported(@Nullable Context context);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Called after all settings have been exported.
|
|
||||||
*/
|
|
||||||
void settingsExported(@Nullable Context context);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final List<ImportExportCallback> importExportCallbacks = new ArrayList<>();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds a callback for {@link #importFromJSON(Context, String)} and {@link #exportToJson(Context)}.
|
|
||||||
*/
|
|
||||||
public static void addImportExportCallback(@NonNull ImportExportCallback callback) {
|
|
||||||
importExportCallbacks.add(Objects.requireNonNull(callback));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* All settings that were instantiated.
|
|
||||||
* When a new setting is created, it is automatically added to this list.
|
|
||||||
*/
|
|
||||||
private static final List<Setting<?>> SETTINGS = new ArrayList<>();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Map of setting path to setting object.
|
|
||||||
*/
|
|
||||||
private static final Map<String, Setting<?>> PATH_TO_SETTINGS = new HashMap<>();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Preference all instances are saved to.
|
|
||||||
*/
|
|
||||||
public static final SharedPrefCategory preferences = new SharedPrefCategory("revanced_prefs");
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public static Setting<?> getSettingFromPath(@NonNull String str) {
|
|
||||||
return PATH_TO_SETTINGS.get(str);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return All settings that have been created.
|
|
||||||
*/
|
|
||||||
@NonNull
|
|
||||||
public static List<Setting<?>> allLoadedSettings() {
|
|
||||||
return Collections.unmodifiableList(SETTINGS);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return All settings that have been created, sorted by keys.
|
|
||||||
*/
|
|
||||||
@NonNull
|
|
||||||
private static List<Setting<?>> allLoadedSettingsSorted() {
|
|
||||||
Collections.sort(SETTINGS, (Setting<?> o1, Setting<?> o2) -> o1.key.compareTo(o2.key));
|
|
||||||
return allLoadedSettings();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The key used to store the value in the shared preferences.
|
|
||||||
*/
|
|
||||||
@NonNull
|
|
||||||
public final String key;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The default value of the setting.
|
|
||||||
*/
|
|
||||||
@NonNull
|
|
||||||
public final T defaultValue;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* If the app should be rebooted, if this setting is changed
|
|
||||||
*/
|
|
||||||
public final boolean rebootApp;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* If this setting should be included when importing/exporting settings.
|
|
||||||
*/
|
|
||||||
public final boolean includeWithImportExport;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* If this setting is available to edit and use.
|
|
||||||
* Not to be confused with it's status returned from {@link #get()}.
|
|
||||||
*/
|
|
||||||
@Nullable
|
|
||||||
private final Availability availability;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Confirmation message to display, if the user tries to change the setting from the default value.
|
|
||||||
*/
|
|
||||||
@Nullable
|
|
||||||
public final StringRef userDialogMessage;
|
|
||||||
|
|
||||||
// Must be volatile, as some settings are read/write from different threads.
|
|
||||||
// Of note, the object value is persistently stored using SharedPreferences (which is thread safe).
|
|
||||||
/**
|
|
||||||
* The value of the setting.
|
|
||||||
*/
|
|
||||||
@NonNull
|
|
||||||
protected volatile T value;
|
|
||||||
|
|
||||||
public Setting(String key, T defaultValue) {
|
|
||||||
this(key, defaultValue, false, true, null, null);
|
|
||||||
}
|
|
||||||
public Setting(String key, T defaultValue, boolean rebootApp) {
|
|
||||||
this(key, defaultValue, rebootApp, true, null, null);
|
|
||||||
}
|
|
||||||
public Setting(String key, T defaultValue, boolean rebootApp, boolean includeWithImportExport) {
|
|
||||||
this(key, defaultValue, rebootApp, includeWithImportExport, null, null);
|
|
||||||
}
|
|
||||||
public Setting(String key, T defaultValue, String userDialogMessage) {
|
|
||||||
this(key, defaultValue, false, true, userDialogMessage, null);
|
|
||||||
}
|
|
||||||
public Setting(String key, T defaultValue, Availability availability) {
|
|
||||||
this(key, defaultValue, false, true, null, availability);
|
|
||||||
}
|
|
||||||
public Setting(String key, T defaultValue, boolean rebootApp, String userDialogMessage) {
|
|
||||||
this(key, defaultValue, rebootApp, true, userDialogMessage, null);
|
|
||||||
}
|
|
||||||
public Setting(String key, T defaultValue, boolean rebootApp, Availability availability) {
|
|
||||||
this(key, defaultValue, rebootApp, true, null, availability);
|
|
||||||
}
|
|
||||||
public Setting(String key, T defaultValue, boolean rebootApp, String userDialogMessage, Availability availability) {
|
|
||||||
this(key, defaultValue, rebootApp, true, userDialogMessage, availability);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A setting backed by a shared preference.
|
|
||||||
*
|
|
||||||
* @param key The key used to store the value in the shared preferences.
|
|
||||||
* @param defaultValue The default value of the setting.
|
|
||||||
* @param rebootApp If the app should be rebooted, if this setting is changed.
|
|
||||||
* @param includeWithImportExport If this setting should be shown in the import/export dialog.
|
|
||||||
* @param userDialogMessage Confirmation message to display, if the user tries to change the setting from the default value.
|
|
||||||
* @param availability Condition that must be true, for this setting to be available to configure.
|
|
||||||
*/
|
|
||||||
public Setting(@NonNull String key,
|
|
||||||
@NonNull T defaultValue,
|
|
||||||
boolean rebootApp,
|
|
||||||
boolean includeWithImportExport,
|
|
||||||
@Nullable String userDialogMessage,
|
|
||||||
@Nullable Availability availability
|
|
||||||
) {
|
|
||||||
this.key = Objects.requireNonNull(key);
|
|
||||||
this.value = this.defaultValue = Objects.requireNonNull(defaultValue);
|
|
||||||
this.rebootApp = rebootApp;
|
|
||||||
this.includeWithImportExport = includeWithImportExport;
|
|
||||||
this.userDialogMessage = (userDialogMessage == null) ? null : new StringRef(userDialogMessage);
|
|
||||||
this.availability = availability;
|
|
||||||
|
|
||||||
SETTINGS.add(this);
|
|
||||||
if (PATH_TO_SETTINGS.put(key, this) != null) {
|
|
||||||
// Debug setting may not be created yet so using Logger may cause an initialization crash.
|
|
||||||
// Show a toast instead.
|
|
||||||
Utils.showToastLong(this.getClass().getSimpleName()
|
|
||||||
+ " error: Duplicate Setting key found: " + key);
|
|
||||||
}
|
|
||||||
|
|
||||||
load();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Migrate a setting value if the path is renamed but otherwise the old and new settings are identical.
|
|
||||||
*/
|
|
||||||
public static <T> void migrateOldSettingToNew(@NonNull Setting<T> oldSetting, @NonNull Setting<T> newSetting) {
|
|
||||||
if (oldSetting == newSetting) throw new IllegalArgumentException();
|
|
||||||
|
|
||||||
if (!oldSetting.isSetToDefault()) {
|
|
||||||
Logger.printInfo(() -> "Migrating old setting value: " + oldSetting + " into replacement setting: " + newSetting);
|
|
||||||
newSetting.save(oldSetting.value);
|
|
||||||
oldSetting.resetToDefault();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Migrate an old Setting value previously stored in a different SharedPreference.
|
|
||||||
*
|
|
||||||
* This method will be deleted in the future.
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("rawtypes")
|
|
||||||
public static void migrateFromOldPreferences(@NonNull SharedPrefCategory oldPrefs, @NonNull Setting setting, String settingKey) {
|
|
||||||
if (!oldPrefs.preferences.contains(settingKey)) {
|
|
||||||
return; // Nothing to do.
|
|
||||||
}
|
|
||||||
|
|
||||||
Object newValue = setting.get();
|
|
||||||
final Object migratedValue;
|
|
||||||
if (setting instanceof BooleanSetting) {
|
|
||||||
migratedValue = oldPrefs.getBoolean(settingKey, (Boolean) newValue);
|
|
||||||
} else if (setting instanceof IntegerSetting) {
|
|
||||||
migratedValue = oldPrefs.getIntegerString(settingKey, (Integer) newValue);
|
|
||||||
} else if (setting instanceof LongSetting) {
|
|
||||||
migratedValue = oldPrefs.getLongString(settingKey, (Long) newValue);
|
|
||||||
} else if (setting instanceof FloatSetting) {
|
|
||||||
migratedValue = oldPrefs.getFloatString(settingKey, (Float) newValue);
|
|
||||||
} else if (setting instanceof StringSetting) {
|
|
||||||
migratedValue = oldPrefs.getString(settingKey, (String) newValue);
|
|
||||||
} else {
|
|
||||||
Logger.printException(() -> "Unknown setting: " + setting);
|
|
||||||
// Remove otherwise it'll show a toast on every launch
|
|
||||||
oldPrefs.preferences.edit().remove(settingKey).apply();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
oldPrefs.preferences.edit().remove(settingKey).apply(); // Remove the old setting.
|
|
||||||
if (migratedValue.equals(newValue)) {
|
|
||||||
Logger.printDebug(() -> "Value does not need migrating: " + settingKey);
|
|
||||||
return; // Old value is already equal to the new setting value.
|
|
||||||
}
|
|
||||||
|
|
||||||
Logger.printDebug(() -> "Migrating old preference value into current preference: " + settingKey);
|
|
||||||
//noinspection unchecked
|
|
||||||
setting.save(migratedValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets, but does _not_ persistently save the value.
|
|
||||||
* This method is only to be used by the Settings preference code.
|
|
||||||
*
|
|
||||||
* This intentionally is a static method to deter
|
|
||||||
* accidental usage when {@link #save(Object)} was intended.
|
|
||||||
*/
|
|
||||||
public static void privateSetValueFromString(@NonNull Setting<?> setting, @NonNull String newValue) {
|
|
||||||
setting.setValueFromString(newValue);
|
|
||||||
|
|
||||||
// Clear the preference value since default is used, to allow changing
|
|
||||||
// the changing the default for a future release. Without this after upgrading
|
|
||||||
// the saved value will be whatever was the default when the app was first installed.
|
|
||||||
if (setting.isSetToDefault()) {
|
|
||||||
setting.removeFromPreferences();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the value of {@link #value}, but do not save to {@link #preferences}.
|
|
||||||
*/
|
|
||||||
protected abstract void setValueFromString(@NonNull String newValue);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Load and set the value of {@link #value}.
|
|
||||||
*/
|
|
||||||
protected abstract void load();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Persistently saves the value.
|
|
||||||
*/
|
|
||||||
public final void save(@NonNull T newValue) {
|
|
||||||
if (value.equals(newValue)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Must set before saving to preferences (otherwise importing fails to update UI correctly).
|
|
||||||
value = Objects.requireNonNull(newValue);
|
|
||||||
|
|
||||||
if (defaultValue.equals(newValue)) {
|
|
||||||
removeFromPreferences();
|
|
||||||
} else {
|
|
||||||
saveToPreferences();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Save {@link #value} to {@link #preferences}.
|
|
||||||
*/
|
|
||||||
protected abstract void saveToPreferences();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Remove {@link #value} from {@link #preferences}.
|
|
||||||
*/
|
|
||||||
protected final void removeFromPreferences() {
|
|
||||||
Logger.printDebug(() -> "Clearing stored preference value (reset to default): " + key);
|
|
||||||
preferences.removeKey(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
public abstract T get();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Identical to calling {@link #save(Object)} using {@link #defaultValue}.
|
|
||||||
*
|
|
||||||
* @return The newly saved default value.
|
|
||||||
*/
|
|
||||||
public T resetToDefault() {
|
|
||||||
save(defaultValue);
|
|
||||||
return defaultValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return if this setting can be configured and used.
|
|
||||||
*/
|
|
||||||
public boolean isAvailable() {
|
|
||||||
return availability == null || availability.isAvailable();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return if the currently set value is the same as {@link #defaultValue}
|
|
||||||
*/
|
|
||||||
public boolean isSetToDefault() {
|
|
||||||
return value.equals(defaultValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return key + "=" + get();
|
|
||||||
}
|
|
||||||
|
|
||||||
// region Import / export
|
|
||||||
|
|
||||||
/**
|
|
||||||
* If a setting path has this prefix, then remove it before importing/exporting.
|
|
||||||
*/
|
|
||||||
private static final String OPTIONAL_REVANCED_SETTINGS_PREFIX = "revanced_";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The path, minus any 'revanced' prefix to keep json concise.
|
|
||||||
*/
|
|
||||||
private String getImportExportKey() {
|
|
||||||
if (key.startsWith(OPTIONAL_REVANCED_SETTINGS_PREFIX)) {
|
|
||||||
return key.substring(OPTIONAL_REVANCED_SETTINGS_PREFIX.length());
|
|
||||||
}
|
|
||||||
return key;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param importExportKey The JSON key. The JSONObject parameter will contain data for this key.
|
|
||||||
* @return the value stored using the import/export key. Do not set any values in this method.
|
|
||||||
*/
|
|
||||||
protected abstract T readFromJSON(JSONObject json, String importExportKey) throws JSONException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Saves this instance to JSON.
|
|
||||||
* <p>
|
|
||||||
* To keep the JSON simple and readable,
|
|
||||||
* subclasses should not write out any embedded types (such as JSON Array or Dictionaries).
|
|
||||||
* <p>
|
|
||||||
* If this instance is not a type supported natively by JSON (ie: it's not a String/Integer/Float/Long),
|
|
||||||
* then subclasses can override this method and write out a String value representing the value.
|
|
||||||
*/
|
|
||||||
protected void writeToJSON(JSONObject json, String importExportKey) throws JSONException {
|
|
||||||
json.put(importExportKey, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
public static String exportToJson(@Nullable Context alertDialogContext) {
|
|
||||||
try {
|
|
||||||
JSONObject json = new JSONObject();
|
|
||||||
for (Setting<?> setting : allLoadedSettingsSorted()) {
|
|
||||||
String importExportKey = setting.getImportExportKey();
|
|
||||||
if (json.has(importExportKey)) {
|
|
||||||
throw new IllegalArgumentException("duplicate key found: " + importExportKey);
|
|
||||||
}
|
|
||||||
|
|
||||||
final boolean exportDefaultValues = false; // Enable to see what all settings looks like in the UI.
|
|
||||||
//noinspection ConstantValue
|
|
||||||
if (setting.includeWithImportExport && (!setting.isSetToDefault() || exportDefaultValues)) {
|
|
||||||
setting.writeToJSON(json, importExportKey);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (ImportExportCallback callback : importExportCallbacks) {
|
|
||||||
callback.settingsExported(alertDialogContext);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (json.length() == 0) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
String export = json.toString(0);
|
|
||||||
|
|
||||||
// Remove the outer JSON braces to make the output more compact,
|
|
||||||
// and leave less chance of the user forgetting to copy it
|
|
||||||
return export.substring(2, export.length() - 2);
|
|
||||||
} catch (JSONException e) {
|
|
||||||
Logger.printException(() -> "Export failure", e); // should never happen
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return if any settings that require a reboot were changed.
|
|
||||||
*/
|
|
||||||
public static boolean importFromJSON(@NonNull Context alertDialogContext, @NonNull String settingsJsonString) {
|
|
||||||
try {
|
|
||||||
if (!settingsJsonString.matches("[\\s\\S]*\\{")) {
|
|
||||||
settingsJsonString = '{' + settingsJsonString + '}'; // Restore outer JSON braces
|
|
||||||
}
|
|
||||||
JSONObject json = new JSONObject(settingsJsonString);
|
|
||||||
|
|
||||||
boolean rebootSettingChanged = false;
|
|
||||||
int numberOfSettingsImported = 0;
|
|
||||||
//noinspection rawtypes
|
|
||||||
for (Setting setting : SETTINGS) {
|
|
||||||
String key = setting.getImportExportKey();
|
|
||||||
if (json.has(key)) {
|
|
||||||
Object value = setting.readFromJSON(json, key);
|
|
||||||
if (!setting.get().equals(value)) {
|
|
||||||
rebootSettingChanged |= setting.rebootApp;
|
|
||||||
//noinspection unchecked
|
|
||||||
setting.save(value);
|
|
||||||
}
|
|
||||||
numberOfSettingsImported++;
|
|
||||||
} else if (setting.includeWithImportExport && !setting.isSetToDefault()) {
|
|
||||||
Logger.printDebug(() -> "Resetting to default: " + setting);
|
|
||||||
rebootSettingChanged |= setting.rebootApp;
|
|
||||||
setting.resetToDefault();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (ImportExportCallback callback : importExportCallbacks) {
|
|
||||||
callback.settingsImported(alertDialogContext);
|
|
||||||
}
|
|
||||||
|
|
||||||
Utils.showToastLong(numberOfSettingsImported == 0
|
|
||||||
? str("revanced_settings_import_reset")
|
|
||||||
: str("revanced_settings_import_success", numberOfSettingsImported));
|
|
||||||
|
|
||||||
return rebootSettingChanged;
|
|
||||||
} catch (JSONException | IllegalArgumentException ex) {
|
|
||||||
Utils.showToastLong(str("revanced_settings_import_failure_parse", ex.getMessage()));
|
|
||||||
Logger.printInfo(() -> "", ex);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
Logger.printException(() -> "Import failure: " + ex.getMessage(), ex); // should never happen
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// End import / export
|
|
||||||
|
|
||||||
}
|
|
@ -1,67 +0,0 @@
|
|||||||
package app.revanced.extension.shared.settings;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
|
|
||||||
import org.json.JSONException;
|
|
||||||
import org.json.JSONObject;
|
|
||||||
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
public class StringSetting extends Setting<String> {
|
|
||||||
|
|
||||||
public StringSetting(String key, String defaultValue) {
|
|
||||||
super(key, defaultValue);
|
|
||||||
}
|
|
||||||
public StringSetting(String key, String defaultValue, boolean rebootApp) {
|
|
||||||
super(key, defaultValue, rebootApp);
|
|
||||||
}
|
|
||||||
public StringSetting(String key, String defaultValue, boolean rebootApp, boolean includeWithImportExport) {
|
|
||||||
super(key, defaultValue, rebootApp, includeWithImportExport);
|
|
||||||
}
|
|
||||||
public StringSetting(String key, String defaultValue, String userDialogMessage) {
|
|
||||||
super(key, defaultValue, userDialogMessage);
|
|
||||||
}
|
|
||||||
public StringSetting(String key, String defaultValue, Availability availability) {
|
|
||||||
super(key, defaultValue, availability);
|
|
||||||
}
|
|
||||||
public StringSetting(String key, String defaultValue, boolean rebootApp, String userDialogMessage) {
|
|
||||||
super(key, defaultValue, rebootApp, userDialogMessage);
|
|
||||||
}
|
|
||||||
public StringSetting(String key, String defaultValue, boolean rebootApp, Availability availability) {
|
|
||||||
super(key, defaultValue, rebootApp, availability);
|
|
||||||
}
|
|
||||||
public StringSetting(String key, String defaultValue, boolean rebootApp, String userDialogMessage, Availability availability) {
|
|
||||||
super(key, defaultValue, rebootApp, userDialogMessage, availability);
|
|
||||||
}
|
|
||||||
public StringSetting(@NonNull String key, @NonNull String defaultValue, boolean rebootApp, boolean includeWithImportExport, @Nullable String userDialogMessage, @Nullable Availability availability) {
|
|
||||||
super(key, defaultValue, rebootApp, includeWithImportExport, userDialogMessage, availability);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void load() {
|
|
||||||
value = preferences.getString(key, defaultValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected String readFromJSON(JSONObject json, String importExportKey) throws JSONException {
|
|
||||||
return json.getString(importExportKey);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void setValueFromString(@NonNull String newValue) {
|
|
||||||
value = Objects.requireNonNull(newValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void saveToPreferences() {
|
|
||||||
preferences.saveString(key, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
public String get() {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,321 +0,0 @@
|
|||||||
package app.revanced.extension.shared.settings.preference;
|
|
||||||
|
|
||||||
import static app.revanced.extension.shared.StringRef.str;
|
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
|
||||||
import android.app.AlertDialog;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.preference.*;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
import app.revanced.extension.shared.Logger;
|
|
||||||
import app.revanced.extension.shared.Utils;
|
|
||||||
import app.revanced.extension.shared.settings.BaseSettings;
|
|
||||||
import app.revanced.extension.shared.settings.BooleanSetting;
|
|
||||||
import app.revanced.extension.shared.settings.Setting;
|
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
public abstract class AbstractPreferenceFragment extends PreferenceFragment {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Indicates that if a preference changes,
|
|
||||||
* to apply the change from the Setting to the UI component.
|
|
||||||
*/
|
|
||||||
public static boolean settingImportInProgress;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Prevents recursive calls during preference <-> UI syncing from showing extra dialogs.
|
|
||||||
*/
|
|
||||||
private static boolean updatingPreference;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Used to prevent showing reboot dialog, if user cancels a setting user dialog.
|
|
||||||
*/
|
|
||||||
private static boolean showingUserDialogMessage;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Confirm and restart dialog button text and title.
|
|
||||||
* Set by subclasses if Strings cannot be added as a resource.
|
|
||||||
*/
|
|
||||||
@Nullable
|
|
||||||
protected static String restartDialogButtonText, restartDialogTitle, confirmDialogTitle;
|
|
||||||
|
|
||||||
private final SharedPreferences.OnSharedPreferenceChangeListener listener = (sharedPreferences, str) -> {
|
|
||||||
try {
|
|
||||||
if (updatingPreference) {
|
|
||||||
Logger.printDebug(() -> "Ignoring preference change as sync is in progress");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Setting<?> setting = Setting.getSettingFromPath(Objects.requireNonNull(str));
|
|
||||||
if (setting == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Preference pref = findPreference(str);
|
|
||||||
if (pref == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Logger.printDebug(() -> "Preference changed: " + setting.key);
|
|
||||||
|
|
||||||
if (!settingImportInProgress && !showingUserDialogMessage) {
|
|
||||||
if (setting.userDialogMessage != null && !prefIsSetToDefault(pref, setting)) {
|
|
||||||
// Do not change the setting yet, to allow preserving whatever
|
|
||||||
// list/text value was previously set if it needs to be reverted.
|
|
||||||
showSettingUserDialogConfirmation(pref, setting);
|
|
||||||
return;
|
|
||||||
} else if (setting.rebootApp) {
|
|
||||||
showRestartDialog(getContext());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
updatingPreference = true;
|
|
||||||
// Apply 'Setting <- Preference', unless during importing when it needs to be 'Setting -> Preference'.
|
|
||||||
// Updating here can can cause a recursive call back into this same method.
|
|
||||||
updatePreference(pref, setting, true, settingImportInProgress);
|
|
||||||
// Update any other preference availability that may now be different.
|
|
||||||
updateUIAvailability();
|
|
||||||
updatingPreference = false;
|
|
||||||
} catch (Exception ex) {
|
|
||||||
Logger.printException(() -> "OnSharedPreferenceChangeListener failure", ex);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Initialize this instance, and do any custom behavior.
|
|
||||||
* <p>
|
|
||||||
* To ensure all {@link Setting} instances are correctly synced to the UI,
|
|
||||||
* it is important that subclasses make a call or otherwise reference their Settings class bundle
|
|
||||||
* so all app specific {@link Setting} instances are loaded before this method returns.
|
|
||||||
*/
|
|
||||||
protected void initialize() {
|
|
||||||
String preferenceResourceName = BaseSettings.SHOW_MENU_ICONS.get()
|
|
||||||
? "revanced_prefs_icons"
|
|
||||||
: "revanced_prefs";
|
|
||||||
final var identifier = Utils.getResourceIdentifier(preferenceResourceName, "xml");
|
|
||||||
if (identifier == 0) return;
|
|
||||||
addPreferencesFromResource(identifier);
|
|
||||||
|
|
||||||
PreferenceScreen screen = getPreferenceScreen();
|
|
||||||
Utils.sortPreferenceGroups(screen);
|
|
||||||
Utils.setPreferenceTitlesToMultiLineIfNeeded(screen);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void showSettingUserDialogConfirmation(Preference pref, Setting<?> setting) {
|
|
||||||
Utils.verifyOnMainThread();
|
|
||||||
|
|
||||||
final var context = getContext();
|
|
||||||
if (confirmDialogTitle == null) {
|
|
||||||
confirmDialogTitle = str("revanced_settings_confirm_user_dialog_title");
|
|
||||||
}
|
|
||||||
|
|
||||||
showingUserDialogMessage = true;
|
|
||||||
|
|
||||||
new AlertDialog.Builder(context)
|
|
||||||
.setTitle(confirmDialogTitle)
|
|
||||||
.setMessage(Objects.requireNonNull(setting.userDialogMessage).toString())
|
|
||||||
.setPositiveButton(android.R.string.ok, (dialog, id) -> {
|
|
||||||
// User confirmed, save to the Setting.
|
|
||||||
updatePreference(pref, setting, true, false);
|
|
||||||
|
|
||||||
// Update availability of other preferences that may be changed.
|
|
||||||
updateUIAvailability();
|
|
||||||
|
|
||||||
if (setting.rebootApp) {
|
|
||||||
showRestartDialog(context);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.setNegativeButton(android.R.string.cancel, (dialog, id) -> {
|
|
||||||
// Restore whatever the setting was before the change.
|
|
||||||
updatePreference(pref, setting, true, true);
|
|
||||||
})
|
|
||||||
.setOnDismissListener(dialog -> {
|
|
||||||
showingUserDialogMessage = false;
|
|
||||||
})
|
|
||||||
.setCancelable(false)
|
|
||||||
.show();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Updates all Preferences values and their availability using the current values in {@link Setting}.
|
|
||||||
*/
|
|
||||||
protected void updateUIToSettingValues() {
|
|
||||||
updatePreferenceScreen(getPreferenceScreen(), true,true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Updates Preferences availability only using the status of {@link Setting}.
|
|
||||||
*/
|
|
||||||
protected void updateUIAvailability() {
|
|
||||||
updatePreferenceScreen(getPreferenceScreen(), false, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return If the preference is currently set to the default value of the Setting.
|
|
||||||
*/
|
|
||||||
protected boolean prefIsSetToDefault(Preference pref, Setting<?> setting) {
|
|
||||||
Object defaultValue = setting.defaultValue;
|
|
||||||
if (pref instanceof SwitchPreference switchPref) {
|
|
||||||
return switchPref.isChecked() == (Boolean) defaultValue;
|
|
||||||
}
|
|
||||||
String defaultValueString = defaultValue.toString();
|
|
||||||
if (pref instanceof EditTextPreference editPreference) {
|
|
||||||
return editPreference.getText().equals(defaultValueString);
|
|
||||||
}
|
|
||||||
if (pref instanceof ListPreference listPref) {
|
|
||||||
return listPref.getValue().equals(defaultValueString);
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new IllegalStateException("Must override method to handle "
|
|
||||||
+ "preference type: " + pref.getClass());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Syncs all UI Preferences to any {@link Setting} they represent.
|
|
||||||
*/
|
|
||||||
private void updatePreferenceScreen(@NonNull PreferenceGroup group,
|
|
||||||
boolean syncSettingValue,
|
|
||||||
boolean applySettingToPreference) {
|
|
||||||
// Alternatively this could iterate thru all Settings and check for any matching Preferences,
|
|
||||||
// but there are many more Settings than UI preferences so it's more efficient to only check
|
|
||||||
// the Preferences.
|
|
||||||
for (int i = 0, prefCount = group.getPreferenceCount(); i < prefCount; i++) {
|
|
||||||
Preference pref = group.getPreference(i);
|
|
||||||
if (pref instanceof PreferenceGroup subGroup) {
|
|
||||||
updatePreferenceScreen(subGroup, syncSettingValue, applySettingToPreference);
|
|
||||||
} else if (pref.hasKey()) {
|
|
||||||
String key = pref.getKey();
|
|
||||||
Setting<?> setting = Setting.getSettingFromPath(key);
|
|
||||||
|
|
||||||
if (setting != null) {
|
|
||||||
updatePreference(pref, setting, syncSettingValue, applySettingToPreference);
|
|
||||||
} else if (BaseSettings.DEBUG.get() && (pref instanceof SwitchPreference
|
|
||||||
|| pref instanceof EditTextPreference || pref instanceof ListPreference)) {
|
|
||||||
// Probably a typo in the patches preference declaration.
|
|
||||||
Logger.printException(() -> "Preference key has no setting: " + key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handles syncing a UI Preference with the {@link Setting} that backs it.
|
|
||||||
* If needed, subclasses can override this to handle additional UI Preference types.
|
|
||||||
*
|
|
||||||
* @param applySettingToPreference If true, then apply {@link Setting} -> Preference.
|
|
||||||
* If false, then apply {@link Setting} <- Preference.
|
|
||||||
*/
|
|
||||||
protected void syncSettingWithPreference(@NonNull Preference pref,
|
|
||||||
@NonNull Setting<?> setting,
|
|
||||||
boolean applySettingToPreference) {
|
|
||||||
if (pref instanceof SwitchPreference switchPref) {
|
|
||||||
BooleanSetting boolSetting = (BooleanSetting) setting;
|
|
||||||
if (applySettingToPreference) {
|
|
||||||
switchPref.setChecked(boolSetting.get());
|
|
||||||
} else {
|
|
||||||
BooleanSetting.privateSetValue(boolSetting, switchPref.isChecked());
|
|
||||||
}
|
|
||||||
} else if (pref instanceof EditTextPreference editPreference) {
|
|
||||||
if (applySettingToPreference) {
|
|
||||||
editPreference.setText(setting.get().toString());
|
|
||||||
} else {
|
|
||||||
Setting.privateSetValueFromString(setting, editPreference.getText());
|
|
||||||
}
|
|
||||||
} else if (pref instanceof ListPreference listPref) {
|
|
||||||
if (applySettingToPreference) {
|
|
||||||
listPref.setValue(setting.get().toString());
|
|
||||||
} else {
|
|
||||||
Setting.privateSetValueFromString(setting, listPref.getValue());
|
|
||||||
}
|
|
||||||
updateListPreferenceSummary(listPref, setting);
|
|
||||||
} else {
|
|
||||||
Logger.printException(() -> "Setting cannot be handled: " + pref.getClass() + ": " + pref);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Updates a UI Preference with the {@link Setting} that backs it.
|
|
||||||
*
|
|
||||||
* @param syncSetting If the UI should be synced {@link Setting} <-> Preference
|
|
||||||
* @param applySettingToPreference If true, then apply {@link Setting} -> Preference.
|
|
||||||
* If false, then apply {@link Setting} <- Preference.
|
|
||||||
*/
|
|
||||||
private void updatePreference(@NonNull Preference pref, @NonNull Setting<?> setting,
|
|
||||||
boolean syncSetting, boolean applySettingToPreference) {
|
|
||||||
if (!syncSetting && applySettingToPreference) {
|
|
||||||
throw new IllegalArgumentException();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (syncSetting) {
|
|
||||||
syncSettingWithPreference(pref, setting, applySettingToPreference);
|
|
||||||
}
|
|
||||||
|
|
||||||
updatePreferenceAvailability(pref, setting);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void updatePreferenceAvailability(@NonNull Preference pref, @NonNull Setting<?> setting) {
|
|
||||||
pref.setEnabled(setting.isAvailable());
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void updateListPreferenceSummary(ListPreference listPreference, Setting<?> setting) {
|
|
||||||
String objectStringValue = setting.get().toString();
|
|
||||||
final int entryIndex = listPreference.findIndexOfValue(objectStringValue);
|
|
||||||
if (entryIndex >= 0) {
|
|
||||||
listPreference.setSummary(listPreference.getEntries()[entryIndex]);
|
|
||||||
} else {
|
|
||||||
// Value is not an available option.
|
|
||||||
// User manually edited import data, or options changed and current selection is no longer available.
|
|
||||||
// Still show the value in the summary, so it's clear that something is selected.
|
|
||||||
listPreference.setSummary(objectStringValue);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void showRestartDialog(Context context) {
|
|
||||||
Utils.verifyOnMainThread();
|
|
||||||
if (restartDialogTitle == null) {
|
|
||||||
restartDialogTitle = str("revanced_settings_restart_title");
|
|
||||||
}
|
|
||||||
if (restartDialogButtonText == null) {
|
|
||||||
restartDialogButtonText = str("revanced_settings_restart");
|
|
||||||
}
|
|
||||||
|
|
||||||
new AlertDialog.Builder(context)
|
|
||||||
.setMessage(restartDialogTitle)
|
|
||||||
.setPositiveButton(restartDialogButtonText, (dialog, id)
|
|
||||||
-> Utils.restartApp(context))
|
|
||||||
.setNegativeButton(android.R.string.cancel, null)
|
|
||||||
.setCancelable(false)
|
|
||||||
.show();
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressLint("ResourceType")
|
|
||||||
@Override
|
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
try {
|
|
||||||
PreferenceManager preferenceManager = getPreferenceManager();
|
|
||||||
preferenceManager.setSharedPreferencesName(Setting.preferences.name);
|
|
||||||
|
|
||||||
// Must initialize before adding change listener,
|
|
||||||
// otherwise the syncing of Setting -> UI
|
|
||||||
// causes a callback to the listener even though nothing changed.
|
|
||||||
initialize();
|
|
||||||
updateUIToSettingValues();
|
|
||||||
|
|
||||||
preferenceManager.getSharedPreferences().registerOnSharedPreferenceChangeListener(listener);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
Logger.printException(() -> "onCreate() failure", ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDestroy() {
|
|
||||||
getPreferenceManager().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(listener);
|
|
||||||
super.onDestroy();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,100 +0,0 @@
|
|||||||
package app.revanced.extension.shared.settings.preference;
|
|
||||||
|
|
||||||
import android.app.AlertDialog;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.os.Build;
|
|
||||||
import android.preference.EditTextPreference;
|
|
||||||
import android.preference.Preference;
|
|
||||||
import android.text.InputType;
|
|
||||||
import android.util.AttributeSet;
|
|
||||||
import android.util.TypedValue;
|
|
||||||
import android.widget.EditText;
|
|
||||||
import app.revanced.extension.shared.settings.Setting;
|
|
||||||
import app.revanced.extension.shared.Logger;
|
|
||||||
import app.revanced.extension.shared.Utils;
|
|
||||||
|
|
||||||
import static app.revanced.extension.shared.StringRef.str;
|
|
||||||
|
|
||||||
@SuppressWarnings({"unused", "deprecation"})
|
|
||||||
public class ImportExportPreference extends EditTextPreference implements Preference.OnPreferenceClickListener {
|
|
||||||
|
|
||||||
private String existingSettings;
|
|
||||||
|
|
||||||
private void init() {
|
|
||||||
setSelectable(true);
|
|
||||||
|
|
||||||
EditText editText = getEditText();
|
|
||||||
editText.setTextIsSelectable(true);
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
||||||
editText.setAutofillHints((String) null);
|
|
||||||
}
|
|
||||||
editText.setInputType(editText.getInputType() | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
|
|
||||||
editText.setTextSize(TypedValue.COMPLEX_UNIT_PT, 7); // Use a smaller font to reduce text wrap.
|
|
||||||
|
|
||||||
setOnPreferenceClickListener(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ImportExportPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
|
||||||
super(context, attrs, defStyleAttr, defStyleRes);
|
|
||||||
init();
|
|
||||||
}
|
|
||||||
public ImportExportPreference(Context context, AttributeSet attrs, int defStyleAttr) {
|
|
||||||
super(context, attrs, defStyleAttr);
|
|
||||||
init();
|
|
||||||
}
|
|
||||||
public ImportExportPreference(Context context, AttributeSet attrs) {
|
|
||||||
super(context, attrs);
|
|
||||||
init();
|
|
||||||
}
|
|
||||||
public ImportExportPreference(Context context) {
|
|
||||||
super(context);
|
|
||||||
init();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onPreferenceClick(Preference preference) {
|
|
||||||
try {
|
|
||||||
// Must set text before preparing dialog, otherwise text is non selectable if this preference is later reopened.
|
|
||||||
existingSettings = Setting.exportToJson(getContext());
|
|
||||||
getEditText().setText(existingSettings);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
Logger.printException(() -> "showDialog failure", ex);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onPrepareDialogBuilder(AlertDialog.Builder builder) {
|
|
||||||
try {
|
|
||||||
Utils.setEditTextDialogTheme(builder);
|
|
||||||
|
|
||||||
// Show the user the settings in JSON format.
|
|
||||||
builder.setNeutralButton(str("revanced_settings_import_copy"), (dialog, which) -> {
|
|
||||||
Utils.setClipboard(getEditText().getText().toString());
|
|
||||||
}).setPositiveButton(str("revanced_settings_import"), (dialog, which) -> {
|
|
||||||
importSettings(builder.getContext(), getEditText().getText().toString());
|
|
||||||
});
|
|
||||||
} catch (Exception ex) {
|
|
||||||
Logger.printException(() -> "onPrepareDialogBuilder failure", ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void importSettings(Context context, String replacementSettings) {
|
|
||||||
try {
|
|
||||||
if (replacementSettings.equals(existingSettings)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
AbstractPreferenceFragment.settingImportInProgress = true;
|
|
||||||
|
|
||||||
final boolean rebootNeeded = Setting.importFromJSON(context, replacementSettings);
|
|
||||||
if (rebootNeeded) {
|
|
||||||
AbstractPreferenceFragment.showRestartDialog(getContext());
|
|
||||||
}
|
|
||||||
} catch (Exception ex) {
|
|
||||||
Logger.printException(() -> "importSettings failure", ex);
|
|
||||||
} finally {
|
|
||||||
AbstractPreferenceFragment.settingImportInProgress = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,54 +0,0 @@
|
|||||||
package app.revanced.extension.shared.settings.preference;
|
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.preference.PreferenceCategory;
|
|
||||||
import android.util.AttributeSet;
|
|
||||||
import android.view.View;
|
|
||||||
import android.view.ViewGroup;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Empty preference category with no title, used to organize and group related preferences together.
|
|
||||||
*/
|
|
||||||
@SuppressWarnings({"unused", "deprecation"})
|
|
||||||
public class NoTitlePreferenceCategory extends PreferenceCategory {
|
|
||||||
|
|
||||||
public NoTitlePreferenceCategory(Context context, AttributeSet attrs) {
|
|
||||||
super(context, attrs);
|
|
||||||
}
|
|
||||||
|
|
||||||
public NoTitlePreferenceCategory(Context context, AttributeSet attrs, int defStyleAttr) {
|
|
||||||
super(context, attrs, defStyleAttr);
|
|
||||||
}
|
|
||||||
|
|
||||||
public NoTitlePreferenceCategory(Context context) {
|
|
||||||
super(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@SuppressLint("MissingSuperCall")
|
|
||||||
protected View onCreateView(ViewGroup parent) {
|
|
||||||
// Return an zero-height view to eliminate empty title space.
|
|
||||||
return new View(getContext());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CharSequence getTitle() {
|
|
||||||
// Title can be used for sorting. Return the first sub preference title.
|
|
||||||
if (getPreferenceCount() > 0) {
|
|
||||||
return getPreference(0).getTitle();
|
|
||||||
}
|
|
||||||
|
|
||||||
return super.getTitle();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getTitleRes() {
|
|
||||||
if (getPreferenceCount() > 0) {
|
|
||||||
return getPreference(0).getTitleRes();
|
|
||||||
}
|
|
||||||
|
|
||||||
return super.getTitleRes();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,359 +0,0 @@
|
|||||||
package app.revanced.extension.shared.settings.preference;
|
|
||||||
|
|
||||||
import static app.revanced.extension.shared.StringRef.str;
|
|
||||||
import static app.revanced.extension.shared.requests.Route.Method.GET;
|
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
|
||||||
import android.app.Dialog;
|
|
||||||
import android.app.ProgressDialog;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.content.res.Configuration;
|
|
||||||
import android.graphics.Color;
|
|
||||||
import android.net.Uri;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.os.Handler;
|
|
||||||
import android.os.Looper;
|
|
||||||
import android.preference.Preference;
|
|
||||||
import android.util.AttributeSet;
|
|
||||||
import android.view.Window;
|
|
||||||
import android.webkit.WebView;
|
|
||||||
import android.webkit.WebViewClient;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
|
|
||||||
import org.json.JSONArray;
|
|
||||||
import org.json.JSONException;
|
|
||||||
import org.json.JSONObject;
|
|
||||||
|
|
||||||
import java.net.HttpURLConnection;
|
|
||||||
import java.net.SocketTimeoutException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import app.revanced.extension.shared.Logger;
|
|
||||||
import app.revanced.extension.shared.Utils;
|
|
||||||
import app.revanced.extension.shared.requests.Requester;
|
|
||||||
import app.revanced.extension.shared.requests.Route;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Opens a dialog showing official links.
|
|
||||||
*/
|
|
||||||
@SuppressWarnings({"unused", "deprecation"})
|
|
||||||
public class ReVancedAboutPreference extends Preference {
|
|
||||||
|
|
||||||
private static String useNonBreakingHyphens(String text) {
|
|
||||||
// Replace any dashes with non breaking dashes, so the English text 'pre-release'
|
|
||||||
// and the dev release number does not break and cover two lines.
|
|
||||||
return text.replace("-", "‑"); // #8209 = non breaking hyphen.
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String getColorHexString(int color) {
|
|
||||||
return String.format("#%06X", (0x00FFFFFF & color));
|
|
||||||
}
|
|
||||||
|
|
||||||
protected boolean isDarkModeEnabled() {
|
|
||||||
return Utils.isDarkModeEnabled(getContext());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Subclasses can override this and provide a themed color.
|
|
||||||
*/
|
|
||||||
protected int getLightColor() {
|
|
||||||
return Color.WHITE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Subclasses can override this and provide a themed color.
|
|
||||||
*/
|
|
||||||
protected int getDarkColor() {
|
|
||||||
return Color.BLACK;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Apps that do not support bundling resources must override this.
|
|
||||||
*
|
|
||||||
* @return A localized string to display for the key.
|
|
||||||
*/
|
|
||||||
protected String getString(String key, Object ... args) {
|
|
||||||
return str(key, args);
|
|
||||||
}
|
|
||||||
|
|
||||||
private String createDialogHtml(WebLink[] aboutLinks) {
|
|
||||||
final boolean isNetworkConnected = Utils.isNetworkConnected();
|
|
||||||
|
|
||||||
StringBuilder builder = new StringBuilder();
|
|
||||||
builder.append("<html>");
|
|
||||||
builder.append("<body style=\"text-align: center; padding: 10px;\">");
|
|
||||||
|
|
||||||
final boolean isDarkMode = isDarkModeEnabled();
|
|
||||||
String backgroundColorHex = getColorHexString(isDarkMode ? getDarkColor() : getLightColor());
|
|
||||||
String foregroundColorHex = getColorHexString(isDarkMode ? getLightColor() : getDarkColor());
|
|
||||||
// Apply light/dark mode colors.
|
|
||||||
builder.append(String.format(
|
|
||||||
"<style> body { background-color: %s; color: %s; } a { color: %s; } </style>",
|
|
||||||
backgroundColorHex, foregroundColorHex, foregroundColorHex));
|
|
||||||
|
|
||||||
if (isNetworkConnected) {
|
|
||||||
builder.append("<img style=\"width: 100px; height: 100px;\" "
|
|
||||||
// Hide the image if it does not load.
|
|
||||||
+ "onerror=\"this.style.display='none';\" "
|
|
||||||
+ "src=\"").append(AboutLinksRoutes.aboutLogoUrl).append("\" />");
|
|
||||||
}
|
|
||||||
|
|
||||||
String patchesVersion = Utils.getPatchesReleaseVersion();
|
|
||||||
|
|
||||||
// Add the title.
|
|
||||||
builder.append("<h1>")
|
|
||||||
.append("ReVanced")
|
|
||||||
.append("</h1>");
|
|
||||||
|
|
||||||
builder.append("<p>")
|
|
||||||
// Replace hyphens with non breaking dashes so the version number does not break lines.
|
|
||||||
.append(useNonBreakingHyphens(getString("revanced_settings_about_links_body", patchesVersion)))
|
|
||||||
.append("</p>");
|
|
||||||
|
|
||||||
// Add a disclaimer if using a dev release.
|
|
||||||
if (patchesVersion.contains("dev")) {
|
|
||||||
builder.append("<h3>")
|
|
||||||
// English text 'Pre-release' can break lines.
|
|
||||||
.append(useNonBreakingHyphens(getString("revanced_settings_about_links_dev_header")))
|
|
||||||
.append("</h3>");
|
|
||||||
|
|
||||||
builder.append("<p>")
|
|
||||||
.append(getString("revanced_settings_about_links_dev_body"))
|
|
||||||
.append("</p>");
|
|
||||||
}
|
|
||||||
|
|
||||||
builder.append("<h2 style=\"margin-top: 30px;\">")
|
|
||||||
.append(getString("revanced_settings_about_links_header"))
|
|
||||||
.append("</h2>");
|
|
||||||
|
|
||||||
builder.append("<div>");
|
|
||||||
for (WebLink link : aboutLinks) {
|
|
||||||
builder.append("<div style=\"margin-bottom: 20px;\">");
|
|
||||||
builder.append(String.format("<a href=\"%s\">%s</a>", link.url, link.name));
|
|
||||||
builder.append("</div>");
|
|
||||||
}
|
|
||||||
builder.append("</div>");
|
|
||||||
|
|
||||||
builder.append("</body></html>");
|
|
||||||
return builder.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
setOnPreferenceClickListener(pref -> {
|
|
||||||
// Show a progress spinner if the social links are not fetched yet.
|
|
||||||
if (!AboutLinksRoutes.hasFetchedLinks() && Utils.isNetworkConnected()) {
|
|
||||||
// Show a progress spinner, but only if the api fetch takes more than a half a second.
|
|
||||||
final long delayToShowProgressSpinner = 500;
|
|
||||||
ProgressDialog progress = new ProgressDialog(getContext());
|
|
||||||
progress.setProgressStyle(ProgressDialog.STYLE_SPINNER);
|
|
||||||
|
|
||||||
Handler handler = new Handler(Looper.getMainLooper());
|
|
||||||
Runnable showDialogRunnable = progress::show;
|
|
||||||
handler.postDelayed(showDialogRunnable, delayToShowProgressSpinner);
|
|
||||||
|
|
||||||
Utils.runOnBackgroundThread(() ->
|
|
||||||
fetchLinksAndShowDialog(handler, showDialogRunnable, progress));
|
|
||||||
} else {
|
|
||||||
// No network call required and can run now.
|
|
||||||
fetchLinksAndShowDialog(null, null, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void fetchLinksAndShowDialog(@Nullable Handler handler,
|
|
||||||
Runnable showDialogRunnable,
|
|
||||||
@Nullable ProgressDialog progress) {
|
|
||||||
WebLink[] links = AboutLinksRoutes.fetchAboutLinks();
|
|
||||||
String htmlDialog = createDialogHtml(links);
|
|
||||||
|
|
||||||
// Enable to randomly force a delay to debug the spinner logic.
|
|
||||||
final boolean debugSpinnerDelayLogic = false;
|
|
||||||
//noinspection ConstantConditions
|
|
||||||
if (debugSpinnerDelayLogic && handler != null && Math.random() < 0.5f) {
|
|
||||||
Utils.doNothingForDuration((long) (Math.random() * 4000));
|
|
||||||
}
|
|
||||||
|
|
||||||
Utils.runOnMainThreadNowOrLater(() -> {
|
|
||||||
if (handler != null) {
|
|
||||||
handler.removeCallbacks(showDialogRunnable);
|
|
||||||
}
|
|
||||||
if (progress != null) {
|
|
||||||
progress.dismiss();
|
|
||||||
}
|
|
||||||
new WebViewDialog(getContext(), htmlDialog).show();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public ReVancedAboutPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
|
||||||
super(context, attrs, defStyleAttr, defStyleRes);
|
|
||||||
}
|
|
||||||
public ReVancedAboutPreference(Context context, AttributeSet attrs, int defStyleAttr) {
|
|
||||||
super(context, attrs, defStyleAttr);
|
|
||||||
}
|
|
||||||
public ReVancedAboutPreference(Context context, AttributeSet attrs) {
|
|
||||||
super(context, attrs);
|
|
||||||
}
|
|
||||||
public ReVancedAboutPreference(Context context) {
|
|
||||||
super(context);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Displays html content as a dialog. Any links a user taps on are opened in an external browser.
|
|
||||||
*/
|
|
||||||
class WebViewDialog extends Dialog {
|
|
||||||
|
|
||||||
private final String htmlContent;
|
|
||||||
|
|
||||||
public WebViewDialog(@NonNull Context context, @NonNull String htmlContent) {
|
|
||||||
super(context);
|
|
||||||
this.htmlContent = htmlContent;
|
|
||||||
}
|
|
||||||
|
|
||||||
// JS required to hide any broken images. No remote javascript is ever loaded.
|
|
||||||
@SuppressLint("SetJavaScriptEnabled")
|
|
||||||
@Override
|
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
|
||||||
|
|
||||||
WebView webView = new WebView(getContext());
|
|
||||||
webView.getSettings().setJavaScriptEnabled(true);
|
|
||||||
webView.setWebViewClient(new OpenLinksExternallyWebClient());
|
|
||||||
webView.loadDataWithBaseURL(null, htmlContent, "text/html", "utf-8", null);
|
|
||||||
|
|
||||||
setContentView(webView);
|
|
||||||
}
|
|
||||||
|
|
||||||
private class OpenLinksExternallyWebClient extends WebViewClient {
|
|
||||||
@Override
|
|
||||||
public boolean shouldOverrideUrlLoading(WebView view, String url) {
|
|
||||||
try {
|
|
||||||
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
|
|
||||||
getContext().startActivity(intent);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
Logger.printException(() -> "Open link failure", ex);
|
|
||||||
}
|
|
||||||
// Dismiss the about dialog using a delay,
|
|
||||||
// otherwise without a delay the UI looks hectic with the dialog dismissing
|
|
||||||
// to show the settings while simultaneously a web browser is opening.
|
|
||||||
Utils.runOnMainThreadDelayed(WebViewDialog.this::dismiss, 500);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class WebLink {
|
|
||||||
final boolean preferred;
|
|
||||||
String name;
|
|
||||||
final String url;
|
|
||||||
|
|
||||||
WebLink(JSONObject json) throws JSONException {
|
|
||||||
this(json.getBoolean("preferred"),
|
|
||||||
json.getString("name"),
|
|
||||||
json.getString("url")
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
WebLink(boolean preferred, String name, String url) {
|
|
||||||
this.preferred = preferred;
|
|
||||||
this.name = name;
|
|
||||||
this.url = url;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "WebLink{" +
|
|
||||||
"preferred=" + preferred +
|
|
||||||
", name='" + name + '\'' +
|
|
||||||
", url='" + url + '\'' +
|
|
||||||
'}';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class AboutLinksRoutes {
|
|
||||||
/**
|
|
||||||
* Backup icon url if the API call fails.
|
|
||||||
*/
|
|
||||||
public static volatile String aboutLogoUrl = "https://revanced.app/favicon.ico";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Links to use if fetch links api call fails.
|
|
||||||
*/
|
|
||||||
private static final WebLink[] NO_CONNECTION_STATIC_LINKS = {
|
|
||||||
new WebLink(true, "ReVanced.app", "https://revanced.app")
|
|
||||||
};
|
|
||||||
|
|
||||||
private static final String SOCIAL_LINKS_PROVIDER = "https://api.revanced.app/v4";
|
|
||||||
private static final Route.CompiledRoute GET_SOCIAL = new Route(GET, "/about").compile();
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
private static volatile WebLink[] fetchedLinks;
|
|
||||||
|
|
||||||
static boolean hasFetchedLinks() {
|
|
||||||
return fetchedLinks != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
static WebLink[] fetchAboutLinks() {
|
|
||||||
try {
|
|
||||||
if (hasFetchedLinks()) return fetchedLinks;
|
|
||||||
|
|
||||||
// Check if there is no internet connection.
|
|
||||||
if (!Utils.isNetworkConnected()) return NO_CONNECTION_STATIC_LINKS;
|
|
||||||
|
|
||||||
HttpURLConnection connection = Requester.getConnectionFromCompiledRoute(SOCIAL_LINKS_PROVIDER, GET_SOCIAL);
|
|
||||||
connection.setConnectTimeout(5000);
|
|
||||||
connection.setReadTimeout(5000);
|
|
||||||
Logger.printDebug(() -> "Fetching social links from: " + connection.getURL());
|
|
||||||
|
|
||||||
// Do not show an exception toast if the server is down
|
|
||||||
final int responseCode = connection.getResponseCode();
|
|
||||||
if (responseCode != 200) {
|
|
||||||
Logger.printDebug(() -> "Failed to get social links. Response code: " + responseCode);
|
|
||||||
return NO_CONNECTION_STATIC_LINKS;
|
|
||||||
}
|
|
||||||
|
|
||||||
JSONObject json = Requester.parseJSONObjectAndDisconnect(connection);
|
|
||||||
aboutLogoUrl = json.getJSONObject("branding").getString("logo");
|
|
||||||
|
|
||||||
List<WebLink> links = new ArrayList<>();
|
|
||||||
|
|
||||||
JSONArray donations = json.getJSONObject("donations").getJSONArray("links");
|
|
||||||
for (int i = 0, length = donations.length(); i < length; i++) {
|
|
||||||
WebLink link = new WebLink(donations.getJSONObject(i));
|
|
||||||
if (link.preferred) {
|
|
||||||
// This could be localized, but TikTok does not support localized resources.
|
|
||||||
// All link names returned by the api are also non localized.
|
|
||||||
link.name = "Donate";
|
|
||||||
links.add(link);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
JSONArray socials = json.getJSONArray("socials");
|
|
||||||
for (int i = 0, length = socials.length(); i < length; i++) {
|
|
||||||
WebLink link = new WebLink(socials.getJSONObject(i));
|
|
||||||
links.add(link);
|
|
||||||
}
|
|
||||||
|
|
||||||
Logger.printDebug(() -> "links: " + links);
|
|
||||||
|
|
||||||
return fetchedLinks = links.toArray(new WebLink[0]);
|
|
||||||
|
|
||||||
} catch (SocketTimeoutException ex) {
|
|
||||||
Logger.printInfo(() -> "Could not fetch social links", ex); // No toast.
|
|
||||||
} catch (JSONException ex) {
|
|
||||||
Logger.printException(() -> "Could not parse about information", ex);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
Logger.printException(() -> "Failed to get about information", ex);
|
|
||||||
}
|
|
||||||
|
|
||||||
return NO_CONNECTION_STATIC_LINKS;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,84 +0,0 @@
|
|||||||
package app.revanced.extension.shared.settings.preference;
|
|
||||||
|
|
||||||
import static app.revanced.extension.shared.StringRef.str;
|
|
||||||
|
|
||||||
import android.app.AlertDialog;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.preference.EditTextPreference;
|
|
||||||
import android.util.AttributeSet;
|
|
||||||
import android.widget.Button;
|
|
||||||
import android.widget.EditText;
|
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
import app.revanced.extension.shared.Logger;
|
|
||||||
import app.revanced.extension.shared.Utils;
|
|
||||||
import app.revanced.extension.shared.settings.Setting;
|
|
||||||
|
|
||||||
@SuppressWarnings({"unused", "deprecation"})
|
|
||||||
public class ResettableEditTextPreference extends EditTextPreference {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Setting to reset.
|
|
||||||
*/
|
|
||||||
@Nullable
|
|
||||||
private Setting<?> setting;
|
|
||||||
|
|
||||||
public ResettableEditTextPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
|
||||||
super(context, attrs, defStyleAttr, defStyleRes);
|
|
||||||
}
|
|
||||||
public ResettableEditTextPreference(Context context, AttributeSet attrs, int defStyleAttr) {
|
|
||||||
super(context, attrs, defStyleAttr);
|
|
||||||
}
|
|
||||||
public ResettableEditTextPreference(Context context, AttributeSet attrs) {
|
|
||||||
super(context, attrs);
|
|
||||||
}
|
|
||||||
public ResettableEditTextPreference(Context context) {
|
|
||||||
super(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSetting(@Nullable Setting<?> setting) {
|
|
||||||
this.setting = setting;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onPrepareDialogBuilder(AlertDialog.Builder builder) {
|
|
||||||
super.onPrepareDialogBuilder(builder);
|
|
||||||
Utils.setEditTextDialogTheme(builder);
|
|
||||||
|
|
||||||
if (setting == null) {
|
|
||||||
String key = getKey();
|
|
||||||
if (key != null) {
|
|
||||||
setting = Setting.getSettingFromPath(key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (setting != null) {
|
|
||||||
builder.setNeutralButton(str("revanced_settings_reset"), null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void showDialog(Bundle state) {
|
|
||||||
super.showDialog(state);
|
|
||||||
|
|
||||||
// Override the button click listener to prevent dismissing the dialog.
|
|
||||||
Button button = ((AlertDialog) getDialog()).getButton(AlertDialog.BUTTON_NEUTRAL);
|
|
||||||
if (button == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
button.setOnClickListener(v -> {
|
|
||||||
try {
|
|
||||||
String defaultStringValue = Objects.requireNonNull(setting).defaultValue.toString();
|
|
||||||
EditText editText = getEditText();
|
|
||||||
editText.setText(defaultStringValue);
|
|
||||||
editText.setSelection(defaultStringValue.length()); // move cursor to end of text
|
|
||||||
} catch (Exception ex) {
|
|
||||||
Logger.printException(() -> "reset failure", ex);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,190 +0,0 @@
|
|||||||
package app.revanced.extension.shared.settings.preference;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.preference.PreferenceFragment;
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
import app.revanced.extension.shared.Logger;
|
|
||||||
import app.revanced.extension.shared.Utils;
|
|
||||||
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Shared categories, and helper methods.
|
|
||||||
*
|
|
||||||
* The various save methods store numbers as Strings,
|
|
||||||
* which is required if using {@link PreferenceFragment}.
|
|
||||||
*
|
|
||||||
* If saved numbers will not be used with a preference fragment,
|
|
||||||
* then store the primitive numbers using the {@link #preferences} itself.
|
|
||||||
*/
|
|
||||||
public class SharedPrefCategory {
|
|
||||||
@NonNull
|
|
||||||
public final String name;
|
|
||||||
@NonNull
|
|
||||||
public final SharedPreferences preferences;
|
|
||||||
|
|
||||||
public SharedPrefCategory(@NonNull String name) {
|
|
||||||
this.name = Objects.requireNonNull(name);
|
|
||||||
preferences = Objects.requireNonNull(Utils.getContext()).getSharedPreferences(name, Context.MODE_PRIVATE);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void removeConflictingPreferenceKeyValue(@NonNull String key) {
|
|
||||||
Logger.printException(() -> "Found conflicting preference: " + key);
|
|
||||||
removeKey(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void saveObjectAsString(@NonNull String key, @Nullable Object value) {
|
|
||||||
preferences.edit().putString(key, (value == null ? null : value.toString())).apply();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Removes any preference data type that has the specified key.
|
|
||||||
*/
|
|
||||||
public void removeKey(@NonNull String key) {
|
|
||||||
preferences.edit().remove(Objects.requireNonNull(key)).apply();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void saveBoolean(@NonNull String key, boolean value) {
|
|
||||||
preferences.edit().putBoolean(key, value).apply();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param value a NULL parameter removes the value from the preferences
|
|
||||||
*/
|
|
||||||
public void saveEnumAsString(@NonNull String key, @Nullable Enum<?> value) {
|
|
||||||
saveObjectAsString(key, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param value a NULL parameter removes the value from the preferences
|
|
||||||
*/
|
|
||||||
public void saveIntegerString(@NonNull String key, @Nullable Integer value) {
|
|
||||||
saveObjectAsString(key, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param value a NULL parameter removes the value from the preferences
|
|
||||||
*/
|
|
||||||
public void saveLongString(@NonNull String key, @Nullable Long value) {
|
|
||||||
saveObjectAsString(key, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param value a NULL parameter removes the value from the preferences
|
|
||||||
*/
|
|
||||||
public void saveFloatString(@NonNull String key, @Nullable Float value) {
|
|
||||||
saveObjectAsString(key, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param value a NULL parameter removes the value from the preferences
|
|
||||||
*/
|
|
||||||
public void saveString(@NonNull String key, @Nullable String value) {
|
|
||||||
saveObjectAsString(key, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
public String getString(@NonNull String key, @NonNull String _default) {
|
|
||||||
Objects.requireNonNull(_default);
|
|
||||||
try {
|
|
||||||
return preferences.getString(key, _default);
|
|
||||||
} catch (ClassCastException ex) {
|
|
||||||
// Value stored is a completely different type (should never happen).
|
|
||||||
removeConflictingPreferenceKeyValue(key);
|
|
||||||
return _default;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
public <T extends Enum<?>> T getEnum(@NonNull String key, @NonNull T _default) {
|
|
||||||
Objects.requireNonNull(_default);
|
|
||||||
try {
|
|
||||||
String enumName = preferences.getString(key, null);
|
|
||||||
if (enumName != null) {
|
|
||||||
try {
|
|
||||||
// noinspection unchecked
|
|
||||||
return (T) Enum.valueOf(_default.getClass(), enumName);
|
|
||||||
} catch (IllegalArgumentException ex) {
|
|
||||||
// Info level to allow removing enum values in the future without showing any user errors.
|
|
||||||
Logger.printInfo(() -> "Using default, and ignoring unknown enum value: " + enumName);
|
|
||||||
removeKey(key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (ClassCastException ex) {
|
|
||||||
// Value stored is a completely different type (should never happen).
|
|
||||||
removeConflictingPreferenceKeyValue(key);
|
|
||||||
}
|
|
||||||
return _default;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean getBoolean(@NonNull String key, boolean _default) {
|
|
||||||
try {
|
|
||||||
return preferences.getBoolean(key, _default);
|
|
||||||
} catch (ClassCastException ex) {
|
|
||||||
// Value stored is a completely different type (should never happen).
|
|
||||||
removeConflictingPreferenceKeyValue(key);
|
|
||||||
return _default;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
public Integer getIntegerString(@NonNull String key, @NonNull Integer _default) {
|
|
||||||
try {
|
|
||||||
String value = preferences.getString(key, null);
|
|
||||||
if (value != null) {
|
|
||||||
return Integer.valueOf(value);
|
|
||||||
}
|
|
||||||
} catch (ClassCastException | NumberFormatException ex) {
|
|
||||||
try {
|
|
||||||
// Old data previously stored as primitive.
|
|
||||||
return preferences.getInt(key, _default);
|
|
||||||
} catch (ClassCastException ex2) {
|
|
||||||
// Value stored is a completely different type (should never happen).
|
|
||||||
removeConflictingPreferenceKeyValue(key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return _default;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
public Long getLongString(@NonNull String key, @NonNull Long _default) {
|
|
||||||
try {
|
|
||||||
String value = preferences.getString(key, null);
|
|
||||||
if (value != null) {
|
|
||||||
return Long.valueOf(value);
|
|
||||||
}
|
|
||||||
} catch (ClassCastException | NumberFormatException ex) {
|
|
||||||
try {
|
|
||||||
return preferences.getLong(key, _default);
|
|
||||||
} catch (ClassCastException ex2) {
|
|
||||||
removeConflictingPreferenceKeyValue(key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return _default;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
public Float getFloatString(@NonNull String key, @NonNull Float _default) {
|
|
||||||
try {
|
|
||||||
String value = preferences.getString(key, null);
|
|
||||||
if (value != null) {
|
|
||||||
return Float.valueOf(value);
|
|
||||||
}
|
|
||||||
} catch (ClassCastException | NumberFormatException ex) {
|
|
||||||
try {
|
|
||||||
return preferences.getFloat(key, _default);
|
|
||||||
} catch (ClassCastException ex2) {
|
|
||||||
removeConflictingPreferenceKeyValue(key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return _default;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,259 +0,0 @@
|
|||||||
package app.revanced.extension.shared.spoof;
|
|
||||||
|
|
||||||
import android.os.Build;
|
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
|
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
import app.revanced.extension.shared.Logger;
|
|
||||||
import app.revanced.extension.shared.settings.BaseSettings;
|
|
||||||
|
|
||||||
public enum ClientType {
|
|
||||||
// https://dumps.tadiphone.dev/dumps/oculus/eureka
|
|
||||||
ANDROID_VR_NO_AUTH(
|
|
||||||
28,
|
|
||||||
"ANDROID_VR",
|
|
||||||
"com.google.android.apps.youtube.vr.oculus",
|
|
||||||
"Oculus",
|
|
||||||
"Quest 3",
|
|
||||||
"Android",
|
|
||||||
"12",
|
|
||||||
// Android 12.1
|
|
||||||
"32",
|
|
||||||
"SQ3A.220605.009.A1",
|
|
||||||
"132.0.6808.3",
|
|
||||||
"1.61.48",
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
"Android VR No auth"
|
|
||||||
),
|
|
||||||
// Chromecast with Google TV 4K.
|
|
||||||
// https://dumps.tadiphone.dev/dumps/google/kirkwood
|
|
||||||
ANDROID_UNPLUGGED(
|
|
||||||
29,
|
|
||||||
"ANDROID_UNPLUGGED",
|
|
||||||
"com.google.android.apps.youtube.unplugged",
|
|
||||||
"Google",
|
|
||||||
"Google TV Streamer",
|
|
||||||
"Android",
|
|
||||||
"14",
|
|
||||||
"34",
|
|
||||||
"UTT3.240625.001.K5",
|
|
||||||
"132.0.6808.3",
|
|
||||||
"8.49.0",
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
"Android TV"
|
|
||||||
),
|
|
||||||
// Cannot play livestreams and lacks HDR, but can play videos with music and labeled "for children".
|
|
||||||
// Google Pixel 9 Pro Fold
|
|
||||||
// https://dumps.tadiphone.dev/dumps/google/barbet
|
|
||||||
ANDROID_CREATOR(
|
|
||||||
14,
|
|
||||||
"ANDROID_CREATOR",
|
|
||||||
"com.google.android.apps.youtube.creator",
|
|
||||||
"Google",
|
|
||||||
"Pixel 9 Pro Fold",
|
|
||||||
"Android",
|
|
||||||
"15",
|
|
||||||
"35",
|
|
||||||
"AP3A.241005.015.A2",
|
|
||||||
"132.0.6779.0",
|
|
||||||
"23.47.101",
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
"Android Creator"
|
|
||||||
),
|
|
||||||
IOS_UNPLUGGED(
|
|
||||||
33,
|
|
||||||
"IOS_UNPLUGGED",
|
|
||||||
"com.google.ios.youtubeunplugged",
|
|
||||||
"Apple",
|
|
||||||
forceAVC()
|
|
||||||
// 11 Pro Max (last device with iOS 13)
|
|
||||||
? "iPhone12,5"
|
|
||||||
// 15 Pro Max
|
|
||||||
: "iPhone16,2",
|
|
||||||
"iOS",
|
|
||||||
forceAVC()
|
|
||||||
// iOS 13 and earlier uses only AVC. 14+ adds VP9 and AV1.
|
|
||||||
? "13.7.17H35"
|
|
||||||
: "18.2.22C152",
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
// Version number should be a valid iOS release.
|
|
||||||
// https://www.ipa4fun.com/history/152043/
|
|
||||||
forceAVC()
|
|
||||||
// Some newer versions can also force AVC,
|
|
||||||
// but 6.45 is the last version that supports iOS 13.
|
|
||||||
? "6.45"
|
|
||||||
: "8.49",
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
forceAVC()
|
|
||||||
? "iOS TV Force AVC"
|
|
||||||
: "iOS TV"
|
|
||||||
),
|
|
||||||
ANDROID_VR_AUTH(
|
|
||||||
ANDROID_VR_NO_AUTH.id,
|
|
||||||
ANDROID_VR_NO_AUTH.clientName,
|
|
||||||
ANDROID_VR_NO_AUTH.packageName,
|
|
||||||
ANDROID_VR_NO_AUTH.deviceMake,
|
|
||||||
ANDROID_VR_NO_AUTH.deviceModel,
|
|
||||||
ANDROID_VR_NO_AUTH.osName,
|
|
||||||
ANDROID_VR_NO_AUTH.osVersion,
|
|
||||||
ANDROID_VR_NO_AUTH.androidSdkVersion,
|
|
||||||
ANDROID_VR_NO_AUTH.buildId,
|
|
||||||
ANDROID_VR_NO_AUTH.cronetVersion,
|
|
||||||
ANDROID_VR_NO_AUTH.clientVersion,
|
|
||||||
ANDROID_VR_NO_AUTH.requiresAuth,
|
|
||||||
true,
|
|
||||||
"Android VR Auth"
|
|
||||||
);
|
|
||||||
|
|
||||||
private static boolean forceAVC() {
|
|
||||||
return BaseSettings.SPOOF_VIDEO_STREAMS_IOS_FORCE_AVC.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* YouTube
|
|
||||||
* <a href="https://github.com/zerodytrash/YouTube-Internal-Clients?tab=readme-ov-file#clients">client type</a>
|
|
||||||
*/
|
|
||||||
public final int id;
|
|
||||||
|
|
||||||
public final String clientName;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* App package name.
|
|
||||||
*/
|
|
||||||
private final String packageName;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Player user-agent.
|
|
||||||
*/
|
|
||||||
public final String userAgent;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Device model, equivalent to {@link Build#MANUFACTURER} (System property: ro.product.vendor.manufacturer)
|
|
||||||
*/
|
|
||||||
public final String deviceMake;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Device model, equivalent to {@link Build#MODEL} (System property: ro.product.vendor.model)
|
|
||||||
*/
|
|
||||||
public final String deviceModel;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Device OS name.
|
|
||||||
*/
|
|
||||||
public final String osName;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Device OS version.
|
|
||||||
*/
|
|
||||||
public final String osVersion;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Android SDK version, equivalent to {@link Build.VERSION#SDK} (System property: ro.build.version.sdk)
|
|
||||||
* Field is null if not applicable.
|
|
||||||
*/
|
|
||||||
@Nullable
|
|
||||||
public final String androidSdkVersion;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Android build id, equivalent to {@link Build#ID}.
|
|
||||||
* Field is null if not applicable.
|
|
||||||
*/
|
|
||||||
@Nullable
|
|
||||||
private final String buildId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Cronet release version, as found in decompiled client apk.
|
|
||||||
* Field is null if not applicable.
|
|
||||||
*/
|
|
||||||
@Nullable
|
|
||||||
private final String cronetVersion;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* App version.
|
|
||||||
*/
|
|
||||||
public final String clientVersion;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* If this client requires authentication and does not work
|
|
||||||
* if logged out or in incognito mode.
|
|
||||||
*/
|
|
||||||
public final boolean requiresAuth;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* If the client should use authentication if available.
|
|
||||||
*/
|
|
||||||
public final boolean useAuth;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Friendly name displayed in stats for nerds.
|
|
||||||
*/
|
|
||||||
public final String friendlyName;
|
|
||||||
|
|
||||||
@SuppressWarnings("ConstantLocale")
|
|
||||||
ClientType(int id,
|
|
||||||
String clientName,
|
|
||||||
String packageName,
|
|
||||||
String deviceMake,
|
|
||||||
String deviceModel,
|
|
||||||
String osName,
|
|
||||||
String osVersion,
|
|
||||||
@Nullable String androidSdkVersion,
|
|
||||||
@Nullable String buildId,
|
|
||||||
@Nullable String cronetVersion,
|
|
||||||
String clientVersion,
|
|
||||||
boolean requiresAuth,
|
|
||||||
boolean useAuth,
|
|
||||||
String friendlyName) {
|
|
||||||
this.id = id;
|
|
||||||
this.clientName = clientName;
|
|
||||||
this.packageName = packageName;
|
|
||||||
this.deviceMake = deviceMake;
|
|
||||||
this.deviceModel = deviceModel;
|
|
||||||
this.osName = osName;
|
|
||||||
this.osVersion = osVersion;
|
|
||||||
this.androidSdkVersion = androidSdkVersion;
|
|
||||||
this.buildId = buildId;
|
|
||||||
this.cronetVersion = cronetVersion;
|
|
||||||
this.clientVersion = clientVersion;
|
|
||||||
this.requiresAuth = requiresAuth;
|
|
||||||
this.useAuth = useAuth;
|
|
||||||
this.friendlyName = friendlyName;
|
|
||||||
|
|
||||||
Locale defaultLocale = Locale.getDefault();
|
|
||||||
if (androidSdkVersion == null) {
|
|
||||||
// Convert version from '18.2.22C152' into '18_2_22'
|
|
||||||
String userAgentOsVersion = osVersion
|
|
||||||
.replaceAll("(\\d+\\.\\d+\\.\\d+).*", "$1")
|
|
||||||
.replace(".", "_");
|
|
||||||
// https://github.com/mitmproxy/mitmproxy/issues/4836
|
|
||||||
this.userAgent = String.format("%s/%s (%s; U; CPU iOS %s like Mac OS X; %s)",
|
|
||||||
packageName,
|
|
||||||
clientVersion,
|
|
||||||
deviceModel,
|
|
||||||
userAgentOsVersion,
|
|
||||||
defaultLocale
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
this.userAgent = String.format("%s/%s (Linux; U; Android %s; %s; %s; Build/%s; Cronet/%s)",
|
|
||||||
packageName,
|
|
||||||
clientVersion,
|
|
||||||
osVersion,
|
|
||||||
defaultLocale,
|
|
||||||
deviceModel,
|
|
||||||
Objects.requireNonNull(buildId),
|
|
||||||
Objects.requireNonNull(cronetVersion)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
Logger.printDebug(() -> "userAgent: " + this.userAgent);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,267 +0,0 @@
|
|||||||
package app.revanced.extension.shared.spoof;
|
|
||||||
|
|
||||||
import android.net.Uri;
|
|
||||||
import android.text.TextUtils;
|
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import app.revanced.extension.shared.Logger;
|
|
||||||
import app.revanced.extension.shared.Utils;
|
|
||||||
import app.revanced.extension.shared.settings.BaseSettings;
|
|
||||||
import app.revanced.extension.shared.settings.Setting;
|
|
||||||
import app.revanced.extension.shared.spoof.requests.StreamingDataRequest;
|
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
public class SpoofVideoStreamsPatch {
|
|
||||||
private static final boolean SPOOF_STREAMING_DATA = BaseSettings.SPOOF_VIDEO_STREAMS.get();
|
|
||||||
|
|
||||||
private static final boolean FIX_HLS_CURRENT_TIME = SPOOF_STREAMING_DATA
|
|
||||||
&& BaseSettings.SPOOF_VIDEO_STREAMS_CLIENT_TYPE.get() == ClientType.IOS_UNPLUGGED;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Any unreachable ip address. Used to intentionally fail requests.
|
|
||||||
*/
|
|
||||||
private static final String UNREACHABLE_HOST_URI_STRING = "https://127.0.0.0";
|
|
||||||
private static final Uri UNREACHABLE_HOST_URI = Uri.parse(UNREACHABLE_HOST_URI_STRING);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return If this patch was included during patching.
|
|
||||||
*/
|
|
||||||
private static boolean isPatchIncluded() {
|
|
||||||
return false; // Modified during patching.
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean notSpoofingToAndroid() {
|
|
||||||
return !isPatchIncluded()
|
|
||||||
|| !BaseSettings.SPOOF_VIDEO_STREAMS.get()
|
|
||||||
|| BaseSettings.SPOOF_VIDEO_STREAMS_CLIENT_TYPE.get() == ClientType.IOS_UNPLUGGED;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Injection point.
|
|
||||||
* Blocks /get_watch requests by returning an unreachable URI.
|
|
||||||
*
|
|
||||||
* @param playerRequestUri The URI of the player request.
|
|
||||||
* @return An unreachable URI if the request is a /get_watch request, otherwise the original URI.
|
|
||||||
*/
|
|
||||||
public static Uri blockGetWatchRequest(Uri playerRequestUri) {
|
|
||||||
if (SPOOF_STREAMING_DATA) {
|
|
||||||
try {
|
|
||||||
String path = playerRequestUri.getPath();
|
|
||||||
|
|
||||||
if (path != null && path.contains("get_watch")) {
|
|
||||||
Logger.printDebug(() -> "Blocking 'get_watch' by returning unreachable uri");
|
|
||||||
|
|
||||||
return UNREACHABLE_HOST_URI;
|
|
||||||
}
|
|
||||||
} catch (Exception ex) {
|
|
||||||
Logger.printException(() -> "blockGetWatchRequest failure", ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return playerRequestUri;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Injection point.
|
|
||||||
* <p>
|
|
||||||
* Blocks /initplayback requests.
|
|
||||||
*/
|
|
||||||
public static String blockInitPlaybackRequest(String originalUrlString) {
|
|
||||||
if (SPOOF_STREAMING_DATA) {
|
|
||||||
try {
|
|
||||||
var originalUri = Uri.parse(originalUrlString);
|
|
||||||
String path = originalUri.getPath();
|
|
||||||
|
|
||||||
if (path != null && path.contains("initplayback")) {
|
|
||||||
Logger.printDebug(() -> "Blocking 'initplayback' by clearing query");
|
|
||||||
|
|
||||||
return originalUri.buildUpon().clearQuery().build().toString();
|
|
||||||
}
|
|
||||||
} catch (Exception ex) {
|
|
||||||
Logger.printException(() -> "blockInitPlaybackRequest failure", ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return originalUrlString;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Injection point.
|
|
||||||
*/
|
|
||||||
public static boolean isSpoofingEnabled() {
|
|
||||||
return SPOOF_STREAMING_DATA;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Injection point.
|
|
||||||
* Only invoked when playing a livestream on an iOS client.
|
|
||||||
*/
|
|
||||||
public static boolean fixHLSCurrentTime(boolean original) {
|
|
||||||
if (!SPOOF_STREAMING_DATA) {
|
|
||||||
return original;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Injection point.
|
|
||||||
* Turns off a feature flag that interferes with spoofing.
|
|
||||||
*/
|
|
||||||
public static boolean useMediaFetchHotConfigReplacement(boolean original) {
|
|
||||||
if (original) {
|
|
||||||
Logger.printDebug(() -> "useMediaFetchHotConfigReplacement is set on");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!SPOOF_STREAMING_DATA) {
|
|
||||||
return original;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Injection point.
|
|
||||||
* Turns off a feature flag that interferes with video playback.
|
|
||||||
*/
|
|
||||||
public static boolean usePlaybackStartFeatureFlag(boolean original) {
|
|
||||||
if (original) {
|
|
||||||
Logger.printDebug(() -> "usePlaybackStartFeatureFlag is set on");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!SPOOF_STREAMING_DATA) {
|
|
||||||
return original;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Injection point.
|
|
||||||
*/
|
|
||||||
public static void fetchStreams(String url, Map<String, String> requestHeaders) {
|
|
||||||
if (SPOOF_STREAMING_DATA) {
|
|
||||||
try {
|
|
||||||
Uri uri = Uri.parse(url);
|
|
||||||
String path = uri.getPath();
|
|
||||||
if (path == null || !path.contains("player")) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 'get_drm_license' has no video id and appears to happen when waiting for a paid video to start.
|
|
||||||
// 'heartbeat' has no video id and appears to be only after playback has started.
|
|
||||||
// 'refresh' has no video id and appears to happen when waiting for a livestream to start.
|
|
||||||
// 'ad_break' has no video id.
|
|
||||||
if (path.contains("get_drm_license") || path.contains("heartbeat")
|
|
||||||
|| path.contains("refresh") || path.contains("ad_break")) {
|
|
||||||
Logger.printDebug(() -> "Ignoring path: " + path);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
String id = uri.getQueryParameter("id");
|
|
||||||
if (id == null) {
|
|
||||||
Logger.printException(() -> "Ignoring request with no id: " + url);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
StreamingDataRequest.fetchRequest(id, requestHeaders);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
Logger.printException(() -> "buildRequest failure", ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Injection point.
|
|
||||||
* Fix playback by replace the streaming data.
|
|
||||||
* Called after {@link #fetchStreams(String, Map)}.
|
|
||||||
*/
|
|
||||||
@Nullable
|
|
||||||
public static ByteBuffer getStreamingData(String videoId) {
|
|
||||||
if (SPOOF_STREAMING_DATA) {
|
|
||||||
try {
|
|
||||||
StreamingDataRequest request = StreamingDataRequest.getRequestForVideoId(videoId);
|
|
||||||
if (request != null) {
|
|
||||||
// This hook is always called off the main thread,
|
|
||||||
// but this can later be called for the same video id from the main thread.
|
|
||||||
// This is not a concern, since the fetch will always be finished
|
|
||||||
// and never block the main thread.
|
|
||||||
// But if debugging, then still verify this is the situation.
|
|
||||||
if (BaseSettings.DEBUG.get() && !request.fetchCompleted() && Utils.isCurrentlyOnMainThread()) {
|
|
||||||
Logger.printException(() -> "Error: Blocking main thread");
|
|
||||||
}
|
|
||||||
|
|
||||||
var stream = request.getStream();
|
|
||||||
if (stream != null) {
|
|
||||||
Logger.printDebug(() -> "Overriding video stream: " + videoId);
|
|
||||||
return stream;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Logger.printDebug(() -> "Not overriding streaming data (video stream is null): " + videoId);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
Logger.printException(() -> "getStreamingData failure", ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Injection point.
|
|
||||||
* Called after {@link #getStreamingData(String)}.
|
|
||||||
*/
|
|
||||||
@Nullable
|
|
||||||
public static byte[] removeVideoPlaybackPostBody(Uri uri, int method, byte[] postData) {
|
|
||||||
if (SPOOF_STREAMING_DATA) {
|
|
||||||
try {
|
|
||||||
final int methodPost = 2;
|
|
||||||
if (method == methodPost) {
|
|
||||||
String path = uri.getPath();
|
|
||||||
if (path != null && path.contains("videoplayback")) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (Exception ex) {
|
|
||||||
Logger.printException(() -> "removeVideoPlaybackPostBody failure", ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return postData;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Injection point.
|
|
||||||
*/
|
|
||||||
public static String appendSpoofedClient(String videoFormat) {
|
|
||||||
try {
|
|
||||||
if (SPOOF_STREAMING_DATA && BaseSettings.SPOOF_STREAMING_DATA_STATS_FOR_NERDS.get()
|
|
||||||
&& !TextUtils.isEmpty(videoFormat)) {
|
|
||||||
// Force LTR layout, to match the same LTR video time/length layout YouTube uses for all languages.
|
|
||||||
return "\u202D" + videoFormat + "\u2009(" // u202D = left to right override
|
|
||||||
+ StreamingDataRequest.getLastSpoofedClientName() + ")";
|
|
||||||
}
|
|
||||||
} catch (Exception ex) {
|
|
||||||
Logger.printException(() -> "appendSpoofedClient failure", ex);
|
|
||||||
}
|
|
||||||
|
|
||||||
return videoFormat;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final class AudioStreamLanguageOverrideAvailability implements Setting.Availability {
|
|
||||||
@Override
|
|
||||||
public boolean isAvailable() {
|
|
||||||
return BaseSettings.SPOOF_VIDEO_STREAMS.get()
|
|
||||||
&& BaseSettings.SPOOF_VIDEO_STREAMS_CLIENT_TYPE.get() == ClientType.ANDROID_VR_NO_AUTH;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final class SpoofiOSAvailability implements Setting.Availability {
|
|
||||||
@Override
|
|
||||||
public boolean isAvailable() {
|
|
||||||
return BaseSettings.SPOOF_VIDEO_STREAMS.get()
|
|
||||||
&& BaseSettings.SPOOF_VIDEO_STREAMS_CLIENT_TYPE.get() == ClientType.IOS_UNPLUGGED;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user