Compare commits
65 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8bd8c6642f | |||
| 83464df908 | |||
| bc76cfcd49 | |||
| 9078fe89de | |||
| 3eb36a9006 | |||
| 2a00670bbb | |||
| 7c5ad0a4c9 | |||
| 209a9a9ba1 | |||
| d04f04716c | |||
| 143a67e47b | |||
| 125bd31264 | |||
| 116c4c6377 | |||
| d5f910763f | |||
| f79996995e | |||
| 5b53b61416 | |||
| 2c7f515e3b | |||
| 97cfafd47e | |||
| 044f08bcd0 | |||
| d2b23833a3 | |||
| f200c2c0d0 | |||
| db740e4aaa | |||
| 74ac47f497 | |||
| 03d5e86006 | |||
| 9e352e366e | |||
| 0e8161f2fa | |||
| a2add4112e | |||
| 92d07fb47f | |||
| 7ac4df014c | |||
| 91848e5fea | |||
| 26e8129408 | |||
| a6ac97962e | |||
| d385d1c39c | |||
| 1d58d24006 | |||
| 5c8c1b2e77 | |||
| 21897c2be6 | |||
| f0224be20b | |||
| 9c7e37e6c7 | |||
| d23b64e5dd | |||
| daa3348ccf | |||
| 17682811ac | |||
| a67505217c | |||
| 11185406d9 | |||
| 7737b9d6df | |||
| 5c5b35f9e2 | |||
| 1cb31d1615 | |||
| fa6f7e0a21 | |||
| 391ba14ce8 | |||
| 1d6084148e | |||
| 88bc875055 | |||
| f780311b3e | |||
| 98db49ca24 | |||
| 63e6936f9b | |||
| a3285cc4a2 | |||
| 05efaf185c | |||
| 0f67dfd686 | |||
| a4a65f4214 | |||
| abaaedbf30 | |||
| ea44b0d15d | |||
| ed0047778d | |||
| f289bf210c | |||
| 407dc2f819 | |||
| 2417c6f576 | |||
| fff1fc2ab2 | |||
| a2f3eb9c96 | |||
| 71078fda14 |
@@ -0,0 +1,70 @@
|
|||||||
|
name: Build AAB — WhatSMS Gateway
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- feat/whatsms-branding-ptpt
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container:
|
||||||
|
image: mingc/android-build-box:latest
|
||||||
|
options: --network host
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Configurar JDK 17
|
||||||
|
run: |
|
||||||
|
export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64
|
||||||
|
echo "JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64" >> $GITHUB_ENV
|
||||||
|
echo "/usr/lib/jvm/java-17-openjdk-amd64/bin" >> $GITHUB_PATH
|
||||||
|
java -version
|
||||||
|
|
||||||
|
- name: Injectar google-services.json
|
||||||
|
run: echo '${{ secrets.GOOGLE_SERVICES_JSON }}' > app/google-services.json
|
||||||
|
|
||||||
|
- name: Decode keystore
|
||||||
|
run: echo '${{ secrets.KEYSTORE_BASE64 }}' | base64 -d > app/keystore.jks
|
||||||
|
|
||||||
|
- name: Build AAB release
|
||||||
|
env:
|
||||||
|
SIGNING_STORE_PASSWORD: ${{ secrets.SIGNING_STORE_PASSWORD }}
|
||||||
|
SIGNING_KEY_ALIAS: ${{ secrets.SIGNING_KEY_ALIAS }}
|
||||||
|
SIGNING_KEY_PASSWORD: ${{ secrets.SIGNING_KEY_PASSWORD }}
|
||||||
|
JAVA_HOME: /usr/lib/jvm/java-17-openjdk-amd64
|
||||||
|
run: |
|
||||||
|
chmod +x gradlew
|
||||||
|
./gradlew bundleRelease --no-daemon --stacktrace
|
||||||
|
|
||||||
|
- name: Publicar AAB como release Gitea
|
||||||
|
env:
|
||||||
|
GITEA_TOKEN: ${{ github.token }}
|
||||||
|
run: |
|
||||||
|
AAB=$(find app/build/outputs/bundle/release -name "*.aab" | head -1)
|
||||||
|
echo "AAB encontrado: $AAB"
|
||||||
|
# Criar release (ignora erro se tag ja existir)
|
||||||
|
RESP=$(curl -s -X POST \
|
||||||
|
-H "Authorization: token $GITEA_TOKEN" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
https://git.descomplicar.pt/api/v1/repos/ealmeida/whatsms-gateway-android/releases \
|
||||||
|
-d '{"tag_name":"v3.2.0-ci","name":"WhatSMS Gateway v3.2.0 CI","body":"Build automatico Gitea Actions","draft":false,"prerelease":true}')
|
||||||
|
RELEASE_ID=$(echo "$RESP" | grep -o '"id":[0-9]*' | head -1 | cut -d: -f2)
|
||||||
|
# Se release ja existe, obter ID por tag
|
||||||
|
if [ -z "$RELEASE_ID" ] || [ "$RELEASE_ID" = "null" ]; then
|
||||||
|
RELEASE_ID=$(curl -s \
|
||||||
|
-H "Authorization: token $GITEA_TOKEN" \
|
||||||
|
https://git.descomplicar.pt/api/v1/repos/ealmeida/whatsms-gateway-android/releases/tags/v3.2.0-ci \
|
||||||
|
| grep -o '"id":[0-9]*' | head -1 | cut -d: -f2)
|
||||||
|
fi
|
||||||
|
echo "Release ID: $RELEASE_ID"
|
||||||
|
# Upload AAB como asset da release
|
||||||
|
curl -s -X POST \
|
||||||
|
-H "Authorization: token $GITEA_TOKEN" \
|
||||||
|
-H "Content-Type: application/octet-stream" \
|
||||||
|
--data-binary "@$AAB" \
|
||||||
|
"https://git.descomplicar.pt/api/v1/repos/ealmeida/whatsms-gateway-android/releases/${RELEASE_ID}/assets?name=whatsms-gateway-v3.2.0.aab"
|
||||||
|
echo "Upload concluido!"
|
||||||
@@ -0,0 +1,94 @@
|
|||||||
|
name: Build APK
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_call:
|
||||||
|
inputs:
|
||||||
|
version-name:
|
||||||
|
required: true
|
||||||
|
type: string
|
||||||
|
build-type:
|
||||||
|
required: true
|
||||||
|
type: string
|
||||||
|
secrets:
|
||||||
|
google-services-json:
|
||||||
|
required: true
|
||||||
|
signing-key-store-base64:
|
||||||
|
required: true
|
||||||
|
signing-key-alias:
|
||||||
|
required: true
|
||||||
|
signing-key-password:
|
||||||
|
required: true
|
||||||
|
signing-store-password:
|
||||||
|
required: true
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-apk:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Setup JAVA 17
|
||||||
|
uses: actions/setup-java@v3
|
||||||
|
with:
|
||||||
|
distribution: "temurin"
|
||||||
|
java-version: 17
|
||||||
|
|
||||||
|
- name: Cache Gradle and wrapper
|
||||||
|
uses: actions/cache@v3
|
||||||
|
with:
|
||||||
|
path: |
|
||||||
|
~/.gradle/caches
|
||||||
|
~/.gradle/wrapper
|
||||||
|
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }}
|
||||||
|
|
||||||
|
- name: Setup Google Services
|
||||||
|
run: echo ${{ secrets.google-services-json }} | base64 --decode > ./app/google-services.json
|
||||||
|
|
||||||
|
- name: Set App Version
|
||||||
|
run: |
|
||||||
|
export VERSION_NAME='${{ inputs.version-name }}'
|
||||||
|
sed -i "s/versionName.*/versionName \"${VERSION_NAME#v}\"/" app/build.gradle
|
||||||
|
sed -i "s/versionCode.*/versionCode $(( ($(date +%s) - $(date -d "2022-06-15" +%s)) / 86400 ))/" app/build.gradle
|
||||||
|
|
||||||
|
- name: Test
|
||||||
|
run: ./gradlew test
|
||||||
|
|
||||||
|
#1
|
||||||
|
- name: Decode Keystore
|
||||||
|
env:
|
||||||
|
ENCODED_STRING: ${{ secrets.signing-key-store-base64 }}
|
||||||
|
SIGNING_KEY_STORE_PATH: app/keystore.jks
|
||||||
|
|
||||||
|
run: |
|
||||||
|
echo $ENCODED_STRING > keystore-b64.txt
|
||||||
|
base64 -d keystore-b64.txt > $SIGNING_KEY_STORE_PATH
|
||||||
|
|
||||||
|
#2
|
||||||
|
- name: Build ${{ inputs.build-type }} apk
|
||||||
|
env:
|
||||||
|
SIGNING_KEY_STORE_PATH: app/keystore.jks
|
||||||
|
SIGNING_KEY_ALIAS: ${{ secrets.signing-key-alias }}
|
||||||
|
SIGNING_KEY_PASSWORD: ${{ secrets.signing-key-password }}
|
||||||
|
SIGNING_STORE_PASSWORD: ${{ secrets.signing-store-password }}
|
||||||
|
TARGET: ${{ inputs.build-type }}
|
||||||
|
run: ./gradlew assemble${TARGET^}
|
||||||
|
|
||||||
|
- name: Build ${{ inputs.build-type }} bundle
|
||||||
|
env:
|
||||||
|
SIGNING_KEY_STORE_PATH: app/keystore.jks
|
||||||
|
SIGNING_KEY_ALIAS: ${{ secrets.signing-key-alias }}
|
||||||
|
SIGNING_KEY_PASSWORD: ${{ secrets.signing-key-password }}
|
||||||
|
SIGNING_STORE_PASSWORD: ${{ secrets.signing-store-password }}
|
||||||
|
TARGET: ${{ inputs.build-type }}
|
||||||
|
run: ./gradlew bundle${TARGET^}
|
||||||
|
#3
|
||||||
|
- name: Upload ${{ inputs.build-type }} Build to Artifacts
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: ${{ inputs.build-type }}-artifacts
|
||||||
|
path: |
|
||||||
|
app/build/outputs/apk/${{ inputs.build-type }}/
|
||||||
|
app/build/outputs/bundle/${{ inputs.build-type }}/
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
name: Close inactive issues and PRs
|
||||||
|
on:
|
||||||
|
schedule:
|
||||||
|
- cron: "30 1 * * *"
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
close-issues:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
issues: write
|
||||||
|
pull-requests: write
|
||||||
|
steps:
|
||||||
|
- uses: actions/stale@v10
|
||||||
|
with:
|
||||||
|
days-before-stale: 7
|
||||||
|
days-before-close: 7
|
||||||
|
exempt-all-assignees: true
|
||||||
|
|
||||||
|
stale-issue-message: "This issue is stale because it has been open for 7 days with no activity."
|
||||||
|
close-issue-message: "This issue was closed because it has been inactive for 7 days since being marked as stale."
|
||||||
|
stale-issue-label: "stale"
|
||||||
|
|
||||||
|
stale-pr-message: "This PR is stale because it has been open for 7 days with no activity."
|
||||||
|
close-pr-message: "This PR was closed because it has been inactive for 7 days since being marked as stale."
|
||||||
|
stale-pr-label: "stale"
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
name: Discord Release Notification
|
||||||
|
|
||||||
|
on:
|
||||||
|
release:
|
||||||
|
types: [released]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
notify-discord:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
if: github.event.release.prerelease == false
|
||||||
|
steps:
|
||||||
|
- name: Send Discord Notification
|
||||||
|
uses: capcom6/discord-webhook@3a447f4ed76c79ed32fb073d705bda1cd45119e6
|
||||||
|
with:
|
||||||
|
webhook-url: ${{ secrets.DISCORD_WEBHOOK }}
|
||||||
|
content: |
|
||||||
|
🎉 New Release of [${{ github.event.repository.name }}](${{ github.event.repository.html_url }}): **${{ github.event.release.name }}**
|
||||||
|
|
||||||
|
${{ github.event.release.body }}
|
||||||
|
|
||||||
|
📦 Download: ${{ github.event.release.html_url }}
|
||||||
|
flags: 4 # 4 = SUPPRESS_EMBEDS
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
name: Publish Docs
|
||||||
|
|
||||||
|
on:
|
||||||
|
release:
|
||||||
|
types: [ published ]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
- name: Set App Version
|
||||||
|
run: |
|
||||||
|
sed -i "s/{{VERSION}}/${GITHUB_REF_NAME#v}/" docs/api/swagger.json
|
||||||
|
- name: Deploy
|
||||||
|
uses: peaceiris/actions-gh-pages@v3
|
||||||
|
with:
|
||||||
|
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
publish_dir: ./docs/api
|
||||||
@@ -0,0 +1,78 @@
|
|||||||
|
name: Release
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request: { types: [opened, synchronize, ready_for_review] }
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
build-type: [release, insecure]
|
||||||
|
name: Build ${{ matrix.build-type }}
|
||||||
|
if: github.event.pull_request.draft == false
|
||||||
|
uses: ./.github/workflows/build-apk.yml
|
||||||
|
with:
|
||||||
|
version-name: ${{ github.sha }}
|
||||||
|
build-type: ${{ matrix.build-type }}
|
||||||
|
secrets:
|
||||||
|
google-services-json: ${{ secrets.GOOGLE_SERVICES_JSON }}
|
||||||
|
signing-key-store-base64: ${{ secrets.SIGNING_KEY_STORE_BASE64 }}
|
||||||
|
signing-key-alias: ${{ secrets.SIGNING_KEY_ALIAS }}
|
||||||
|
signing-key-password: ${{ secrets.SIGNING_KEY_PASSWORD }}
|
||||||
|
signing-store-password: ${{ secrets.SIGNING_STORE_PASSWORD }}
|
||||||
|
|
||||||
|
release:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
if: github.event.pull_request.draft == false
|
||||||
|
needs: [build]
|
||||||
|
steps:
|
||||||
|
- name: Download release artifacts
|
||||||
|
uses: actions/download-artifact@v4
|
||||||
|
with:
|
||||||
|
name: release-artifacts
|
||||||
|
|
||||||
|
- name: Download insecure artifacts
|
||||||
|
uses: actions/download-artifact@v4
|
||||||
|
with:
|
||||||
|
name: insecure-artifacts
|
||||||
|
|
||||||
|
- name: Upload to S3
|
||||||
|
uses: capcom6/upload-s3-action@master
|
||||||
|
env:
|
||||||
|
AWS_REGION: ${{ secrets.AWS_REGION }}
|
||||||
|
with:
|
||||||
|
aws_key_id: ${{ secrets.AWS_KEY_ID }}
|
||||||
|
aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY}}
|
||||||
|
aws_bucket: ${{ secrets.AWS_BUCKET }}
|
||||||
|
endpoint: ${{ secrets.AWS_ENDPOINT }}
|
||||||
|
source_files: |
|
||||||
|
./apk/release/app-release.apk
|
||||||
|
./bundle/release/app-release.aab
|
||||||
|
./apk/insecure/app-insecure.apk
|
||||||
|
./bundle/insecure/app-insecure.aab
|
||||||
|
destination_dir: apk/${{ github.event.pull_request.head.sha }}
|
||||||
|
|
||||||
|
- name: Find Comment
|
||||||
|
uses: peter-evans/find-comment@v3
|
||||||
|
id: fc
|
||||||
|
with:
|
||||||
|
issue-number: ${{ github.event.pull_request.number }}
|
||||||
|
comment-author: "github-actions[bot]"
|
||||||
|
body-includes: Pull request artifacts
|
||||||
|
|
||||||
|
- name: Create or update comment
|
||||||
|
uses: peter-evans/create-or-update-comment@v4
|
||||||
|
with:
|
||||||
|
comment-id: ${{ steps.fc.outputs.comment-id }}
|
||||||
|
issue-number: ${{ github.event.pull_request.number }}
|
||||||
|
body: |
|
||||||
|
## 🤖 Pull request artifacts
|
||||||
|
|
||||||
|
| file | commit |
|
||||||
|
| ---- | ------ |
|
||||||
|
| [`app-release.apk`](https://s3.sms-gate.app/apk/${{ github.event.pull_request.head.sha }}/app-release.apk) | ${{ github.event.pull_request.head.sha }} |
|
||||||
|
| [`app-release.aab`](https://s3.sms-gate.app/apk/${{ github.event.pull_request.head.sha }}/app-release.aab) | ${{ github.event.pull_request.head.sha }} |
|
||||||
|
| [`app-insecure.apk`](https://s3.sms-gate.app/apk/${{ github.event.pull_request.head.sha }}/app-insecure.apk) | ${{ github.event.pull_request.head.sha }} |
|
||||||
|
| [`app-insecure.aab`](https://s3.sms-gate.app/apk/${{ github.event.pull_request.head.sha }}/app-insecure.aab) | ${{ github.event.pull_request.head.sha }} |
|
||||||
|
|
||||||
|
edit-mode: replace
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
name: Remove Labels on New Push
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request_target:
|
||||||
|
types: [opened, synchronize] # Trigger on PR opened or new commits pushed
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
remove_labels:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
pull-requests: write # Grant permission to modify labels
|
||||||
|
steps:
|
||||||
|
# step 1: checkout repository code
|
||||||
|
- name: Checkout code into workspace directory
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
# step 2: remove specific labels
|
||||||
|
- name: Remove specific labels
|
||||||
|
run: |
|
||||||
|
gh pr edit ${{ github.event.pull_request.number }} --remove-label "ready" || true
|
||||||
|
gh pr edit ${{ github.event.pull_request.number }} --remove-label "deployed" || true
|
||||||
|
env:
|
||||||
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
name: Release
|
||||||
|
|
||||||
|
on:
|
||||||
|
release:
|
||||||
|
types: [published]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
build-type: [release, insecure]
|
||||||
|
name: Build ${{ matrix.build-type }}
|
||||||
|
uses: ./.github/workflows/build-apk.yml
|
||||||
|
with:
|
||||||
|
version-name: ${{ github.ref_name }}
|
||||||
|
build-type: ${{ matrix.build-type }}
|
||||||
|
secrets:
|
||||||
|
google-services-json: ${{ secrets.GOOGLE_SERVICES_JSON }}
|
||||||
|
signing-key-store-base64: ${{ secrets.SIGNING_KEY_STORE_BASE64 }}
|
||||||
|
signing-key-alias: ${{ secrets.SIGNING_KEY_ALIAS }}
|
||||||
|
signing-key-password: ${{ secrets.SIGNING_KEY_PASSWORD }}
|
||||||
|
signing-store-password: ${{ secrets.SIGNING_STORE_PASSWORD }}
|
||||||
|
|
||||||
|
release:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: [build]
|
||||||
|
steps:
|
||||||
|
- uses: actions/download-artifact@v4
|
||||||
|
with:
|
||||||
|
name: release-artifacts
|
||||||
|
- uses: actions/download-artifact@v4
|
||||||
|
with:
|
||||||
|
name: insecure-artifacts
|
||||||
|
- name: Create Github Release
|
||||||
|
uses: softprops/action-gh-release@v1
|
||||||
|
with:
|
||||||
|
generate_release_notes: true
|
||||||
|
prerelease: true
|
||||||
|
files: |
|
||||||
|
./apk/release/app-release.apk
|
||||||
|
./bundle/release/app-release.aab
|
||||||
|
./apk/insecure/app-insecure.apk
|
||||||
|
./bundle/insecure/app-insecure.aab
|
||||||
+371
@@ -0,0 +1,371 @@
|
|||||||
|
# File created using '.gitignore Generator' for Visual Studio Code: https://bit.ly/vscode-gig
|
||||||
|
# Created by https://www.toptal.com/developers/gitignore/api/windows,visualstudiocode,macos,linux,intellij,androidstudio,android,dotenv
|
||||||
|
# Edit at https://www.toptal.com/developers/gitignore?templates=windows,visualstudiocode,macos,linux,intellij,androidstudio,android,dotenv
|
||||||
|
|
||||||
|
### Android ###
|
||||||
|
# Gradle files
|
||||||
|
.gradle/
|
||||||
|
build/
|
||||||
|
|
||||||
|
# Local configuration file (sdk path, etc)
|
||||||
|
local.properties
|
||||||
|
|
||||||
|
# Log/OS Files
|
||||||
|
*.log
|
||||||
|
|
||||||
|
# Android Studio generated files and folders
|
||||||
|
captures/
|
||||||
|
.externalNativeBuild/
|
||||||
|
.cxx/
|
||||||
|
*.apk
|
||||||
|
output.json
|
||||||
|
|
||||||
|
# IntelliJ
|
||||||
|
*.iml
|
||||||
|
.idea/
|
||||||
|
misc.xml
|
||||||
|
deploymentTargetDropDown.xml
|
||||||
|
render.experimental.xml
|
||||||
|
|
||||||
|
# Keystore files
|
||||||
|
*.jks
|
||||||
|
*.keystore
|
||||||
|
|
||||||
|
# Google Services (e.g. APIs or Firebase)
|
||||||
|
google-services.json
|
||||||
|
|
||||||
|
# Android Profiling
|
||||||
|
*.hprof
|
||||||
|
|
||||||
|
### Android Patch ###
|
||||||
|
gen-external-apklibs
|
||||||
|
|
||||||
|
# Replacement of .externalNativeBuild directories introduced
|
||||||
|
# with Android Studio 3.5.
|
||||||
|
|
||||||
|
### dotenv ###
|
||||||
|
.env
|
||||||
|
|
||||||
|
### Intellij ###
|
||||||
|
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
|
||||||
|
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
||||||
|
|
||||||
|
# User-specific stuff
|
||||||
|
.idea/**/workspace.xml
|
||||||
|
.idea/**/tasks.xml
|
||||||
|
.idea/**/usage.statistics.xml
|
||||||
|
.idea/**/dictionaries
|
||||||
|
.idea/**/shelf
|
||||||
|
|
||||||
|
# AWS User-specific
|
||||||
|
.idea/**/aws.xml
|
||||||
|
|
||||||
|
# Generated files
|
||||||
|
.idea/**/contentModel.xml
|
||||||
|
|
||||||
|
# Sensitive or high-churn files
|
||||||
|
.idea/**/dataSources/
|
||||||
|
.idea/**/dataSources.ids
|
||||||
|
.idea/**/dataSources.local.xml
|
||||||
|
.idea/**/sqlDataSources.xml
|
||||||
|
.idea/**/dynamic.xml
|
||||||
|
.idea/**/uiDesigner.xml
|
||||||
|
.idea/**/dbnavigator.xml
|
||||||
|
|
||||||
|
# Gradle
|
||||||
|
.idea/**/gradle.xml
|
||||||
|
.idea/**/libraries
|
||||||
|
|
||||||
|
# Gradle and Maven with auto-import
|
||||||
|
# When using Gradle or Maven with auto-import, you should exclude module files,
|
||||||
|
# since they will be recreated, and may cause churn. Uncomment if using
|
||||||
|
# auto-import.
|
||||||
|
# .idea/artifacts
|
||||||
|
# .idea/compiler.xml
|
||||||
|
# .idea/jarRepositories.xml
|
||||||
|
# .idea/modules.xml
|
||||||
|
# .idea/*.iml
|
||||||
|
# .idea/modules
|
||||||
|
# *.iml
|
||||||
|
# *.ipr
|
||||||
|
|
||||||
|
# CMake
|
||||||
|
cmake-build-*/
|
||||||
|
|
||||||
|
# Mongo Explorer plugin
|
||||||
|
.idea/**/mongoSettings.xml
|
||||||
|
|
||||||
|
# File-based project format
|
||||||
|
*.iws
|
||||||
|
|
||||||
|
# IntelliJ
|
||||||
|
out/
|
||||||
|
|
||||||
|
# mpeltonen/sbt-idea plugin
|
||||||
|
.idea_modules/
|
||||||
|
|
||||||
|
# JIRA plugin
|
||||||
|
atlassian-ide-plugin.xml
|
||||||
|
|
||||||
|
# Cursive Clojure plugin
|
||||||
|
.idea/replstate.xml
|
||||||
|
|
||||||
|
# SonarLint plugin
|
||||||
|
.idea/sonarlint/
|
||||||
|
|
||||||
|
# Crashlytics plugin (for Android Studio and IntelliJ)
|
||||||
|
com_crashlytics_export_strings.xml
|
||||||
|
crashlytics.properties
|
||||||
|
crashlytics-build.properties
|
||||||
|
fabric.properties
|
||||||
|
|
||||||
|
# Editor-based Rest Client
|
||||||
|
.idea/httpRequests
|
||||||
|
|
||||||
|
# Android studio 3.1+ serialized cache file
|
||||||
|
.idea/caches/build_file_checksums.ser
|
||||||
|
|
||||||
|
### Intellij Patch ###
|
||||||
|
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
|
||||||
|
|
||||||
|
# *.iml
|
||||||
|
# modules.xml
|
||||||
|
# .idea/misc.xml
|
||||||
|
# *.ipr
|
||||||
|
|
||||||
|
# Sonarlint plugin
|
||||||
|
# https://plugins.jetbrains.com/plugin/7973-sonarlint
|
||||||
|
.idea/**/sonarlint/
|
||||||
|
|
||||||
|
# SonarQube Plugin
|
||||||
|
# https://plugins.jetbrains.com/plugin/7238-sonarqube-community-plugin
|
||||||
|
.idea/**/sonarIssues.xml
|
||||||
|
|
||||||
|
# Markdown Navigator plugin
|
||||||
|
# https://plugins.jetbrains.com/plugin/7896-markdown-navigator-enhanced
|
||||||
|
.idea/**/markdown-navigator.xml
|
||||||
|
.idea/**/markdown-navigator-enh.xml
|
||||||
|
.idea/**/markdown-navigator/
|
||||||
|
|
||||||
|
# Cache file creation bug
|
||||||
|
# See https://youtrack.jetbrains.com/issue/JBR-2257
|
||||||
|
.idea/$CACHE_FILE$
|
||||||
|
|
||||||
|
# CodeStream plugin
|
||||||
|
# https://plugins.jetbrains.com/plugin/12206-codestream
|
||||||
|
.idea/codestream.xml
|
||||||
|
|
||||||
|
# Azure Toolkit for IntelliJ plugin
|
||||||
|
# https://plugins.jetbrains.com/plugin/8053-azure-toolkit-for-intellij
|
||||||
|
.idea/**/azureSettings.xml
|
||||||
|
|
||||||
|
### Linux ###
|
||||||
|
*~
|
||||||
|
|
||||||
|
# temporary files which can be created if a process still has a handle open of a deleted file
|
||||||
|
.fuse_hidden*
|
||||||
|
|
||||||
|
# KDE directory preferences
|
||||||
|
.directory
|
||||||
|
|
||||||
|
# Linux trash folder which might appear on any partition or disk
|
||||||
|
.Trash-*
|
||||||
|
|
||||||
|
# .nfs files are created when an open file is removed but is still being accessed
|
||||||
|
.nfs*
|
||||||
|
|
||||||
|
### macOS ###
|
||||||
|
# General
|
||||||
|
.DS_Store
|
||||||
|
.AppleDouble
|
||||||
|
.LSOverride
|
||||||
|
|
||||||
|
# Icon must end with two \r
|
||||||
|
Icon
|
||||||
|
|
||||||
|
|
||||||
|
# Thumbnails
|
||||||
|
._*
|
||||||
|
|
||||||
|
# Files that might appear in the root of a volume
|
||||||
|
.DocumentRevisions-V100
|
||||||
|
.fseventsd
|
||||||
|
.Spotlight-V100
|
||||||
|
.TemporaryItems
|
||||||
|
.Trashes
|
||||||
|
.VolumeIcon.icns
|
||||||
|
.com.apple.timemachine.donotpresent
|
||||||
|
|
||||||
|
# Directories potentially created on remote AFP share
|
||||||
|
.AppleDB
|
||||||
|
.AppleDesktop
|
||||||
|
Network Trash Folder
|
||||||
|
Temporary Items
|
||||||
|
.apdisk
|
||||||
|
|
||||||
|
### macOS Patch ###
|
||||||
|
# iCloud generated files
|
||||||
|
*.icloud
|
||||||
|
|
||||||
|
### VisualStudioCode ###
|
||||||
|
.vscode/*
|
||||||
|
!.vscode/settings.json
|
||||||
|
!.vscode/tasks.json
|
||||||
|
!.vscode/launch.json
|
||||||
|
!.vscode/extensions.json
|
||||||
|
!.vscode/*.code-snippets
|
||||||
|
|
||||||
|
# Local History for Visual Studio Code
|
||||||
|
.history/
|
||||||
|
|
||||||
|
# Built Visual Studio Code Extensions
|
||||||
|
*.vsix
|
||||||
|
|
||||||
|
### VisualStudioCode Patch ###
|
||||||
|
# Ignore all local history of files
|
||||||
|
.history
|
||||||
|
.ionide
|
||||||
|
|
||||||
|
### Windows ###
|
||||||
|
# Windows thumbnail cache files
|
||||||
|
Thumbs.db
|
||||||
|
Thumbs.db:encryptable
|
||||||
|
ehthumbs.db
|
||||||
|
ehthumbs_vista.db
|
||||||
|
|
||||||
|
# Dump file
|
||||||
|
*.stackdump
|
||||||
|
|
||||||
|
# Folder config file
|
||||||
|
[Dd]esktop.ini
|
||||||
|
|
||||||
|
# Recycle Bin used on file shares
|
||||||
|
$RECYCLE.BIN/
|
||||||
|
|
||||||
|
# Windows Installer files
|
||||||
|
*.cab
|
||||||
|
*.msi
|
||||||
|
*.msix
|
||||||
|
*.msm
|
||||||
|
*.msp
|
||||||
|
|
||||||
|
# Windows shortcuts
|
||||||
|
*.lnk
|
||||||
|
|
||||||
|
### AndroidStudio ###
|
||||||
|
# Covers files to be ignored for android development using Android Studio.
|
||||||
|
|
||||||
|
# Built application files
|
||||||
|
*.ap_
|
||||||
|
*.aab
|
||||||
|
|
||||||
|
# Files for the ART/Dalvik VM
|
||||||
|
*.dex
|
||||||
|
|
||||||
|
# Java class files
|
||||||
|
*.class
|
||||||
|
|
||||||
|
# Generated files
|
||||||
|
bin/
|
||||||
|
gen/
|
||||||
|
|
||||||
|
# Gradle files
|
||||||
|
.gradle
|
||||||
|
|
||||||
|
# Signing files
|
||||||
|
.signing/
|
||||||
|
|
||||||
|
# Local configuration file (sdk path, etc)
|
||||||
|
|
||||||
|
# Proguard folder generated by Eclipse
|
||||||
|
proguard/
|
||||||
|
|
||||||
|
# Log Files
|
||||||
|
|
||||||
|
# Android Studio
|
||||||
|
/*/build/
|
||||||
|
/*/local.properties
|
||||||
|
/*/out
|
||||||
|
/*/*/build
|
||||||
|
/*/*/production
|
||||||
|
.navigation/
|
||||||
|
*.ipr
|
||||||
|
*.swp
|
||||||
|
|
||||||
|
# Keystore files
|
||||||
|
|
||||||
|
# Google Services (e.g. APIs or Firebase)
|
||||||
|
# google-services.json
|
||||||
|
|
||||||
|
# Android Patch
|
||||||
|
|
||||||
|
# External native build folder generated in Android Studio 2.2 and later
|
||||||
|
.externalNativeBuild
|
||||||
|
|
||||||
|
# NDK
|
||||||
|
obj/
|
||||||
|
|
||||||
|
# IntelliJ IDEA
|
||||||
|
/out/
|
||||||
|
|
||||||
|
# User-specific configurations
|
||||||
|
.idea/caches/
|
||||||
|
.idea/libraries/
|
||||||
|
.idea/shelf/
|
||||||
|
.idea/workspace.xml
|
||||||
|
.idea/tasks.xml
|
||||||
|
.idea/.name
|
||||||
|
.idea/compiler.xml
|
||||||
|
.idea/copyright/profiles_settings.xml
|
||||||
|
.idea/encodings.xml
|
||||||
|
.idea/misc.xml
|
||||||
|
.idea/modules.xml
|
||||||
|
.idea/scopes/scope_settings.xml
|
||||||
|
.idea/dictionaries
|
||||||
|
.idea/vcs.xml
|
||||||
|
.idea/jsLibraryMappings.xml
|
||||||
|
.idea/datasources.xml
|
||||||
|
.idea/dataSources.ids
|
||||||
|
.idea/sqlDataSources.xml
|
||||||
|
.idea/dynamic.xml
|
||||||
|
.idea/uiDesigner.xml
|
||||||
|
.idea/assetWizardSettings.xml
|
||||||
|
.idea/gradle.xml
|
||||||
|
.idea/jarRepositories.xml
|
||||||
|
.idea/navEditor.xml
|
||||||
|
|
||||||
|
# Legacy Eclipse project files
|
||||||
|
.classpath
|
||||||
|
.project
|
||||||
|
.cproject
|
||||||
|
.settings/
|
||||||
|
|
||||||
|
# Mobile Tools for Java (J2ME)
|
||||||
|
.mtj.tmp/
|
||||||
|
|
||||||
|
# Package Files #
|
||||||
|
*.war
|
||||||
|
*.ear
|
||||||
|
|
||||||
|
# virtual machine crash logs (Reference: http://www.java.com/en/download/help/error_hotspot.xml)
|
||||||
|
hs_err_pid*
|
||||||
|
|
||||||
|
## Plugin-specific files:
|
||||||
|
|
||||||
|
# mpeltonen/sbt-idea plugin
|
||||||
|
|
||||||
|
# JIRA plugin
|
||||||
|
|
||||||
|
# Mongo Explorer plugin
|
||||||
|
.idea/mongoSettings.xml
|
||||||
|
|
||||||
|
# Crashlytics plugin (for Android Studio and IntelliJ)
|
||||||
|
|
||||||
|
### AndroidStudio Patch ###
|
||||||
|
|
||||||
|
!/gradle/wrapper/gradle-wrapper.jar
|
||||||
|
|
||||||
|
# End of https://www.toptal.com/developers/gitignore/api/windows,visualstudiocode,macos,linux,intellij,androidstudio,android,dotenv
|
||||||
|
|
||||||
|
# Custom rules (everything added below won't be overriden by 'Generate .gitignore File' if you use 'Update' option)
|
||||||
|
|
||||||
@@ -0,0 +1,201 @@
|
|||||||
|
Apache License
|
||||||
|
Version 2.0, January 2004
|
||||||
|
http://www.apache.org/licenses/
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||||
|
|
||||||
|
1. Definitions.
|
||||||
|
|
||||||
|
"License" shall mean the terms and conditions for use, reproduction,
|
||||||
|
and distribution as defined by Sections 1 through 9 of this document.
|
||||||
|
|
||||||
|
"Licensor" shall mean the copyright owner or entity authorized by
|
||||||
|
the copyright owner that is granting the License.
|
||||||
|
|
||||||
|
"Legal Entity" shall mean the union of the acting entity and all
|
||||||
|
other entities that control, are controlled by, or are under common
|
||||||
|
control with that entity. For the purposes of this definition,
|
||||||
|
"control" means (i) the power, direct or indirect, to cause the
|
||||||
|
direction or management of such entity, whether by contract or
|
||||||
|
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||||
|
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||||
|
|
||||||
|
"You" (or "Your") shall mean an individual or Legal Entity
|
||||||
|
exercising permissions granted by this License.
|
||||||
|
|
||||||
|
"Source" form shall mean the preferred form for making modifications,
|
||||||
|
including but not limited to software source code, documentation
|
||||||
|
source, and configuration files.
|
||||||
|
|
||||||
|
"Object" form shall mean any form resulting from mechanical
|
||||||
|
transformation or translation of a Source form, including but
|
||||||
|
not limited to compiled object code, generated documentation,
|
||||||
|
and conversions to other media types.
|
||||||
|
|
||||||
|
"Work" shall mean the work of authorship, whether in Source or
|
||||||
|
Object form, made available under the License, as indicated by a
|
||||||
|
copyright notice that is included in or attached to the work
|
||||||
|
(an example is provided in the Appendix below).
|
||||||
|
|
||||||
|
"Derivative Works" shall mean any work, whether in Source or Object
|
||||||
|
form, that is based on (or derived from) the Work and for which the
|
||||||
|
editorial revisions, annotations, elaborations, or other modifications
|
||||||
|
represent, as a whole, an original work of authorship. For the purposes
|
||||||
|
of this License, Derivative Works shall not include works that remain
|
||||||
|
separable from, or merely link (or bind by name) to the interfaces of,
|
||||||
|
the Work and Derivative Works thereof.
|
||||||
|
|
||||||
|
"Contribution" shall mean any work of authorship, including
|
||||||
|
the original version of the Work and any modifications or additions
|
||||||
|
to that Work or Derivative Works thereof, that is intentionally
|
||||||
|
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||||
|
or by an individual or Legal Entity authorized to submit on behalf of
|
||||||
|
the copyright owner. For the purposes of this definition, "submitted"
|
||||||
|
means any form of electronic, verbal, or written communication sent
|
||||||
|
to the Licensor or its representatives, including but not limited to
|
||||||
|
communication on electronic mailing lists, source code control systems,
|
||||||
|
and issue tracking systems that are managed by, or on behalf of, the
|
||||||
|
Licensor for the purpose of discussing and improving the Work, but
|
||||||
|
excluding communication that is conspicuously marked or otherwise
|
||||||
|
designated in writing by the copyright owner as "Not a Contribution."
|
||||||
|
|
||||||
|
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||||
|
on behalf of whom a Contribution has been received by Licensor and
|
||||||
|
subsequently incorporated within the Work.
|
||||||
|
|
||||||
|
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
copyright license to reproduce, prepare Derivative Works of,
|
||||||
|
publicly display, publicly perform, sublicense, and distribute the
|
||||||
|
Work and such Derivative Works in Source or Object form.
|
||||||
|
|
||||||
|
3. Grant of Patent License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
(except as stated in this section) patent license to make, have made,
|
||||||
|
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||||
|
where such license applies only to those patent claims licensable
|
||||||
|
by such Contributor that are necessarily infringed by their
|
||||||
|
Contribution(s) alone or by combination of their Contribution(s)
|
||||||
|
with the Work to which such Contribution(s) was submitted. If You
|
||||||
|
institute patent litigation against any entity (including a
|
||||||
|
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||||
|
or a Contribution incorporated within the Work constitutes direct
|
||||||
|
or contributory patent infringement, then any patent licenses
|
||||||
|
granted to You under this License for that Work shall terminate
|
||||||
|
as of the date such litigation is filed.
|
||||||
|
|
||||||
|
4. Redistribution. You may reproduce and distribute copies of the
|
||||||
|
Work or Derivative Works thereof in any medium, with or without
|
||||||
|
modifications, and in Source or Object form, provided that You
|
||||||
|
meet the following conditions:
|
||||||
|
|
||||||
|
(a) You must give any other recipients of the Work or
|
||||||
|
Derivative Works a copy of this License; and
|
||||||
|
|
||||||
|
(b) You must cause any modified files to carry prominent notices
|
||||||
|
stating that You changed the files; and
|
||||||
|
|
||||||
|
(c) You must retain, in the Source form of any Derivative Works
|
||||||
|
that You distribute, all copyright, patent, trademark, and
|
||||||
|
attribution notices from the Source form of the Work,
|
||||||
|
excluding those notices that do not pertain to any part of
|
||||||
|
the Derivative Works; and
|
||||||
|
|
||||||
|
(d) If the Work includes a "NOTICE" text file as part of its
|
||||||
|
distribution, then any Derivative Works that You distribute must
|
||||||
|
include a readable copy of the attribution notices contained
|
||||||
|
within such NOTICE file, excluding those notices that do not
|
||||||
|
pertain to any part of the Derivative Works, in at least one
|
||||||
|
of the following places: within a NOTICE text file distributed
|
||||||
|
as part of the Derivative Works; within the Source form or
|
||||||
|
documentation, if provided along with the Derivative Works; or,
|
||||||
|
within a display generated by the Derivative Works, if and
|
||||||
|
wherever such third-party notices normally appear. The contents
|
||||||
|
of the NOTICE file are for informational purposes only and
|
||||||
|
do not modify the License. You may add Your own attribution
|
||||||
|
notices within Derivative Works that You distribute, alongside
|
||||||
|
or as an addendum to the NOTICE text from the Work, provided
|
||||||
|
that such additional attribution notices cannot be construed
|
||||||
|
as modifying the License.
|
||||||
|
|
||||||
|
You may add Your own copyright statement to Your modifications and
|
||||||
|
may provide additional or different license terms and conditions
|
||||||
|
for use, reproduction, or distribution of Your modifications, or
|
||||||
|
for any such Derivative Works as a whole, provided Your use,
|
||||||
|
reproduction, and distribution of the Work otherwise complies with
|
||||||
|
the conditions stated in this License.
|
||||||
|
|
||||||
|
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||||
|
any Contribution intentionally submitted for inclusion in the Work
|
||||||
|
by You to the Licensor shall be under the terms and conditions of
|
||||||
|
this License, without any additional terms or conditions.
|
||||||
|
Notwithstanding the above, nothing herein shall supersede or modify
|
||||||
|
the terms of any separate license agreement you may have executed
|
||||||
|
with Licensor regarding such Contributions.
|
||||||
|
|
||||||
|
6. Trademarks. This License does not grant permission to use the trade
|
||||||
|
names, trademarks, service marks, or product names of the Licensor,
|
||||||
|
except as required for reasonable and customary use in describing the
|
||||||
|
origin of the Work and reproducing the content of the NOTICE file.
|
||||||
|
|
||||||
|
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||||
|
agreed to in writing, Licensor provides the Work (and each
|
||||||
|
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||||
|
implied, including, without limitation, any warranties or conditions
|
||||||
|
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||||
|
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||||
|
appropriateness of using or redistributing the Work and assume any
|
||||||
|
risks associated with Your exercise of permissions under this License.
|
||||||
|
|
||||||
|
8. Limitation of Liability. In no event and under no legal theory,
|
||||||
|
whether in tort (including negligence), contract, or otherwise,
|
||||||
|
unless required by applicable law (such as deliberate and grossly
|
||||||
|
negligent acts) or agreed to in writing, shall any Contributor be
|
||||||
|
liable to You for damages, including any direct, indirect, special,
|
||||||
|
incidental, or consequential damages of any character arising as a
|
||||||
|
result of this License or out of the use or inability to use the
|
||||||
|
Work (including but not limited to damages for loss of goodwill,
|
||||||
|
work stoppage, computer failure or malfunction, or any and all
|
||||||
|
other commercial damages or losses), even if such Contributor
|
||||||
|
has been advised of the possibility of such damages.
|
||||||
|
|
||||||
|
9. Accepting Warranty or Additional Liability. While redistributing
|
||||||
|
the Work or Derivative Works thereof, You may choose to offer,
|
||||||
|
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||||
|
or other liability obligations and/or rights consistent with this
|
||||||
|
License. However, in accepting such obligations, You may act only
|
||||||
|
on Your own behalf and on Your sole responsibility, not on behalf
|
||||||
|
of any other Contributor, and only if You agree to indemnify,
|
||||||
|
defend, and hold each Contributor harmless for any liability
|
||||||
|
incurred by, or claims asserted against, such Contributor by reason
|
||||||
|
of your accepting any such warranty or additional liability.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
APPENDIX: How to apply the Apache License to your work.
|
||||||
|
|
||||||
|
To apply the Apache License to your work, attach the following
|
||||||
|
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||||
|
replaced with your own identifying information. (Don't include
|
||||||
|
the brackets!) The text should be enclosed in the appropriate
|
||||||
|
comment syntax for the file format. We also recommend that a
|
||||||
|
file or class name and description of purpose be included on the
|
||||||
|
same "printed page" as the copyright notice for easier
|
||||||
|
identification within third-party archives.
|
||||||
|
|
||||||
|
Copyright [yyyy] [name of copyright owner]
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
/build
|
||||||
@@ -0,0 +1,139 @@
|
|||||||
|
plugins {
|
||||||
|
id 'com.android.application'
|
||||||
|
id 'kotlin-android'
|
||||||
|
id 'kotlin-kapt'
|
||||||
|
id 'com.google.gms.google-services'
|
||||||
|
}
|
||||||
|
|
||||||
|
android {
|
||||||
|
compileSdk 34
|
||||||
|
|
||||||
|
defaultConfig {
|
||||||
|
applicationId "pt.whatsms.gateway"
|
||||||
|
minSdk 21
|
||||||
|
targetSdk 34
|
||||||
|
versionCode 11
|
||||||
|
versionName "3.2.0"
|
||||||
|
|
||||||
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
|
|
||||||
|
javaCompileOptions {
|
||||||
|
annotationProcessorOptions {
|
||||||
|
arguments += ["room.schemaLocation": "$projectDir/schemas".toString()]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
buildFeatures {
|
||||||
|
viewBinding true
|
||||||
|
}
|
||||||
|
signingConfigs {
|
||||||
|
release {
|
||||||
|
storeFile file("keystore.jks")
|
||||||
|
storePassword System.getenv("SIGNING_STORE_PASSWORD")
|
||||||
|
keyAlias System.getenv("SIGNING_KEY_ALIAS")
|
||||||
|
keyPassword System.getenv("SIGNING_KEY_PASSWORD")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
buildTypes {
|
||||||
|
debug {
|
||||||
|
debuggable true
|
||||||
|
manifestPlaceholders = [networkSecurityConfig: "@xml/network_security_config"]
|
||||||
|
}
|
||||||
|
debugInsecure {
|
||||||
|
debuggable true
|
||||||
|
manifestPlaceholders = [networkSecurityConfig: "@xml/network_security_config_insecure"]
|
||||||
|
signingConfig signingConfigs.debug
|
||||||
|
}
|
||||||
|
insecure {
|
||||||
|
initWith debug
|
||||||
|
debuggable true
|
||||||
|
signingConfig signingConfigs.release
|
||||||
|
manifestPlaceholders = [networkSecurityConfig: "@xml/network_security_config_insecure"]
|
||||||
|
}
|
||||||
|
release {
|
||||||
|
minifyEnabled false
|
||||||
|
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||||
|
signingConfig signingConfigs.release
|
||||||
|
manifestPlaceholders = [networkSecurityConfig: "@xml/network_security_config"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
compileOptions {
|
||||||
|
sourceCompatibility JavaVersion.VERSION_1_8
|
||||||
|
targetCompatibility JavaVersion.VERSION_1_8
|
||||||
|
}
|
||||||
|
kotlinOptions {
|
||||||
|
jvmTarget = '1.8'
|
||||||
|
}
|
||||||
|
packagingOptions {
|
||||||
|
exclude 'META-INF/INDEX.LIST'
|
||||||
|
exclude 'META-INF/io.netty.versions.properties'
|
||||||
|
}
|
||||||
|
namespace 'pt.whatsms.gateway'
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
def ktor_version = "2.2.4"
|
||||||
|
def okhttp_version = "4.10.0"
|
||||||
|
def room_version = "2.4.3"
|
||||||
|
def coroutines_version = "1.6.1"
|
||||||
|
def work_version = "2.7.1"
|
||||||
|
def koin_version = "3.4.0"
|
||||||
|
def lifecycle_version = "2.6.2"
|
||||||
|
|
||||||
|
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version")
|
||||||
|
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version")
|
||||||
|
|
||||||
|
implementation("io.ktor:ktor-serialization-gson:$ktor_version")
|
||||||
|
|
||||||
|
implementation("io.ktor:ktor-server-core:$ktor_version")
|
||||||
|
implementation("io.ktor:ktor-server-netty:$ktor_version")
|
||||||
|
implementation("io.ktor:ktor-server-compression:$ktor_version")
|
||||||
|
implementation("io.ktor:ktor-server-status-pages:$ktor_version")
|
||||||
|
implementation("io.ktor:ktor-server-content-negotiation:$ktor_version")
|
||||||
|
implementation("io.ktor:ktor-server-call-logging:$ktor_version")
|
||||||
|
implementation("io.ktor:ktor-server-auth:$ktor_version")
|
||||||
|
implementation("io.ktor:ktor-server-auth-jwt:$ktor_version")
|
||||||
|
|
||||||
|
implementation("io.ktor:ktor-client-core:$ktor_version")
|
||||||
|
implementation("io.ktor:ktor-client-content-negotiation:$ktor_version")
|
||||||
|
implementation("io.ktor:ktor-client-okhttp:$ktor_version")
|
||||||
|
|
||||||
|
implementation("com.squareup.okhttp3:okhttp:$okhttp_version")
|
||||||
|
implementation("com.squareup.okhttp3:okhttp-sse:$okhttp_version")
|
||||||
|
|
||||||
|
// Kotlin + coroutines
|
||||||
|
implementation "androidx.work:work-runtime-ktx:$work_version"
|
||||||
|
|
||||||
|
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version"
|
||||||
|
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
|
||||||
|
|
||||||
|
implementation("androidx.preference:preference-ktx:1.2.0")
|
||||||
|
|
||||||
|
implementation("androidx.core:core-ktx:1.8.0")
|
||||||
|
implementation("androidx.appcompat:appcompat:1.4.2")
|
||||||
|
implementation("com.google.android.material:material:1.6.1")
|
||||||
|
implementation("androidx.constraintlayout:constraintlayout:2.1.4")
|
||||||
|
implementation 'androidx.preference:preference-ktx:1.2.1'
|
||||||
|
|
||||||
|
implementation("com.aventrix.jnanoid:jnanoid:2.0.0")
|
||||||
|
|
||||||
|
implementation("androidx.room:room-ktx:$room_version")
|
||||||
|
annotationProcessor("androidx.room:room-compiler:$room_version")
|
||||||
|
kapt("androidx.room:room-compiler:$room_version")
|
||||||
|
|
||||||
|
// Import the Firebase BoM
|
||||||
|
implementation platform('com.google.firebase:firebase-bom:31.1.1')
|
||||||
|
implementation 'com.google.firebase:firebase-messaging-ktx'
|
||||||
|
|
||||||
|
implementation 'com.googlecode.libphonenumber:libphonenumber:9.0.22'
|
||||||
|
|
||||||
|
// Koin for Android
|
||||||
|
implementation "io.insert-koin:koin-android:$koin_version"
|
||||||
|
|
||||||
|
// QR code scanner para emparelhamento WhatSMS
|
||||||
|
implementation 'com.journeyapps:zxing-android-embedded:4.3.0'
|
||||||
|
|
||||||
|
testImplementation("junit:junit:4.13.2")
|
||||||
|
androidTestImplementation("androidx.test.ext:junit:1.1.3")
|
||||||
|
androidTestImplementation("androidx.test.espresso:espresso-core:3.4.0")
|
||||||
|
}
|
||||||
Vendored
+21
@@ -0,0 +1,21 @@
|
|||||||
|
# Add project specific ProGuard rules here.
|
||||||
|
# You can control the set of applied configuration files using the
|
||||||
|
# proguardFiles setting in build.gradle.
|
||||||
|
#
|
||||||
|
# For more details, see
|
||||||
|
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||||
|
|
||||||
|
# If your project uses WebView with JS, uncomment the following
|
||||||
|
# and specify the fully qualified class name to the JavaScript interface
|
||||||
|
# class:
|
||||||
|
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||||
|
# public *;
|
||||||
|
#}
|
||||||
|
|
||||||
|
# Uncomment this to preserve the line number information for
|
||||||
|
# debugging stack traces.
|
||||||
|
#-keepattributes SourceFile,LineNumberTable
|
||||||
|
|
||||||
|
# If you keep the line number information, uncomment this to
|
||||||
|
# hide the original source file name.
|
||||||
|
#-renamesourcefileattribute SourceFile
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
"version": 3,
|
||||||
|
"artifactType": {
|
||||||
|
"type": "APK",
|
||||||
|
"kind": "Directory"
|
||||||
|
},
|
||||||
|
"applicationId": "pt.whatsms.gateway",
|
||||||
|
"variantName": "release",
|
||||||
|
"elements": [
|
||||||
|
{
|
||||||
|
"type": "SINGLE",
|
||||||
|
"filters": [],
|
||||||
|
"attributes": [],
|
||||||
|
"versionCode": 1,
|
||||||
|
"versionName": "1.0.0",
|
||||||
|
"outputFile": "app-release.apk"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"elementType": "File"
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
ewogICJmb3JtYXRWZXJzaW9uIjogMSwKICAiZGF0YWJhc2UiOiB7CiAgICAidmVyc2lvbiI6IDEsCiAgICAiaWRlbnRpdHlIYXNoIjogIjY3ZmU0ODFiNDg1ZjRkMjcwNWFiNzQ2ODg0YWQ2OWIxIiwKICAgICJlbnRpdGllcyI6IFsKICAgICAgewogICAgICAgICJ0YWJsZU5hbWUiOiAiTWVzc2FnZSIsCiAgICAgICAgImNyZWF0ZVNxbCI6ICJDUkVBVEUgVEFCTEUgSUYgTk9UIEVYSVNUUyBgJHtUQUJMRV9OQU1FfWAgKGBpZGAgVEVYVCBOT1QgTlVMTCwgYHRleHRgIFRFWFQgTk9UIE5VTEwsIGBzdGF0ZWAgVEVYVCBOT1QgTlVMTCwgUFJJTUFSWSBLRVkoYGlkYCkpIiwKICAgICAgICAiZmllbGRzIjogWwogICAgICAgICAgewogICAgICAgICAgICAiZmllbGRQYXRoIjogImlkIiwKICAgICAgICAgICAgImNvbHVtbk5hbWUiOiAiaWQiLAogICAgICAgICAgICAiYWZmaW5pdHkiOiAiVEVYVCIsCiAgICAgICAgICAgICJub3ROdWxsIjogdHJ1ZQogICAgICAgICAgfSwKICAgICAgICAgIHsKICAgICAgICAgICAgImZpZWxkUGF0aCI6ICJ0ZXh0IiwKICAgICAgICAgICAgImNvbHVtbk5hbWUiOiAidGV4dCIsCiAgICAgICAgICAgICJhZmZpbml0eSI6ICJURVhUIiwKICAgICAgICAgICAgIm5vdE51bGwiOiB0cnVlCiAgICAgICAgICB9LAogICAgICAgICAgewogICAgICAgICAgICAiZmllbGRQYXRoIjogInN0YXRlIiwKICAgICAgICAgICAgImNvbHVtbk5hbWUiOiAic3RhdGUiLAogICAgICAgICAgICAiYWZmaW5pdHkiOiAiVEVYVCIsCiAgICAgICAgICAgICJub3ROdWxsIjogdHJ1ZQogICAgICAgICAgfQogICAgICAgIF0sCiAgICAgICAgInByaW1hcnlLZXkiOiB7CiAgICAgICAgICAiY29sdW1uTmFtZXMiOiBbCiAgICAgICAgICAgICJpZCIKICAgICAgICAgIF0sCiAgICAgICAgICAiYXV0b0dlbmVyYXRlIjogZmFsc2UKICAgICAgICB9LAogICAgICAgICJpbmRpY2VzIjogW10sCiAgICAgICAgImZvcmVpZ25LZXlzIjogW10KICAgICAgfSwKICAgICAgewogICAgICAgICJ0YWJsZU5hbWUiOiAiTWVzc2FnZVJlY2lwaWVudCIsCiAgICAgICAgImNyZWF0ZVNxbCI6ICJDUkVBVEUgVEFCTEUgSUYgTk9UIEVYSVNUUyBgJHtUQUJMRV9OQU1FfWAgKGBtZXNzYWdlSWRgIFRFWFQgTk9UIE5VTEwsIGBwaG9uZU51bWJlcmAgVEVYVCBOT1QgTlVMTCwgYHN0YXRlYCBURVhUIE5PVCBOVUxMLCBQUklNQVJZIEtFWShgbWVzc2FnZUlkYCwgYHBob25lTnVtYmVyYCksIEZPUkVJR04gS0VZKGBtZXNzYWdlSWRgKSBSRUZFUkVOQ0VTIGBNZXNzYWdlYChgaWRgKSBPTiBVUERBVEUgTk8gQUNUSU9OIE9OIERFTEVURSBDQVNDQURFICkiLAogICAgICAgICJmaWVsZHMiOiBbCiAgICAgICAgICB7CiAgICAgICAgICAgICJmaWVsZFBhdGgiOiAibWVzc2FnZUlkIiwKICAgICAgICAgICAgImNvbHVtbk5hbWUiOiAibWVzc2FnZUlkIiwKICAgICAgICAgICAgImFmZmluaXR5IjogIlRFWFQiLAogICAgICAgICAgICAibm90TnVsbCI6IHRydWUKICAgICAgICAgIH0sCiAgICAgICAgICB7CiAgICAgICAgICAgICJmaWVsZFBhdGgiOiAicGhvbmVOdW1iZXIiLAogICAgICAgICAgICAiY29sdW1uTmFtZSI6ICJwaG9uZU51bWJlciIsCiAgICAgICAgICAgICJhZmZpbml0eSI6ICJURVhUIiwKICAgICAgICAgICAgIm5vdE51bGwiOiB0cnVlCiAgICAgICAgICB9LAogICAgICAgICAgewogICAgICAgICAgICAiZmllbGRQYXRoIjogInN0YXRlIiwKICAgICAgICAgICAgImNvbHVtbk5hbWUiOiAic3RhdGUiLAogICAgICAgICAgICAiYWZmaW5pdHkiOiAiVEVYVCIsCiAgICAgICAgICAgICJub3ROdWxsIjogdHJ1ZQogICAgICAgICAgfQogICAgICAgIF0sCiAgICAgICAgInByaW1hcnlLZXkiOiB7CiAgICAgICAgICAiY29sdW1uTmFtZXMiOiBbCiAgICAgICAgICAgICJtZXNzYWdlSWQiLAogICAgICAgICAgICAicGhvbmVOdW1iZXIiCiAgICAgICAgICBdLAogICAgICAgICAgImF1dG9HZW5lcmF0ZSI6IGZhbHNlCiAgICAgICAgfSwKICAgICAgICAiaW5kaWNlcyI6IFtdLAogICAgICAgICJmb3JlaWduS2V5cyI6IFsKICAgICAgICAgIHsKICAgICAgICAgICAgInRhYmxlIjogIk1lc3NhZ2UiLAogICAgICAgICAgICAib25EZWxldGUiOiAiQ0FTQ0FERSIsCiAgICAgICAgICAgICJvblVwZGF0ZSI6ICJOTyBBQ1RJT04iLAogICAgICAgICAgICAiY29sdW1ucyI6IFsKICAgICAgICAgICAgICAibWVzc2FnZUlkIgogICAgICAgICAgICBdLAogICAgICAgICAgICAicmVmZXJlbmNlZENvbHVtbnMiOiBbCiAgICAgICAgICAgICAgImlkIgogICAgICAgICAgICBdCiAgICAgICAgICB9CiAgICAgICAgXQogICAgICB9CiAgICBdLAogICAgInZpZXdzIjogW10sCiAgICAic2V0dXBRdWVyaWVzIjogWwogICAgICAiQ1JFQVRFIFRBQkxFIElGIE5PVCBFWElTVFMgcm9vbV9tYXN0ZXJfdGFibGUgKGlkIElOVEVHRVIgUFJJTUFSWSBLRVksaWRlbnRpdHlfaGFzaCBURVhUKSIsCiAgICAgICJJTlNFUlQgT1IgUkVQTEFDRSBJTlRPIHJvb21fbWFzdGVyX3RhYmxlIChpZCxpZGVudGl0eV9oYXNoKSBWQUxVRVMoNDIsICc2N2ZlNDgxYjQ4NWY0ZDI3MDVhYjc0Njg4NGFkNjliMScpIgogICAgXQogIH0KfQ==
|
||||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -0,0 +1 @@
|
|||||||
|
ewogICJmb3JtYXRWZXJzaW9uIjogMSwKICAiZGF0YWJhc2UiOiB7CiAgICAidmVyc2lvbiI6IDIsCiAgICAiaWRlbnRpdHlIYXNoIjogIjFjM2MzMjQ2ZWEwZjM2OGVjOTViNzQwYjJmNTBlMThiIiwKICAgICJlbnRpdGllcyI6IFsKICAgICAgewogICAgICAgICJ0YWJsZU5hbWUiOiAiTWVzc2FnZSIsCiAgICAgICAgImNyZWF0ZVNxbCI6ICJDUkVBVEUgVEFCTEUgSUYgTk9UIEVYSVNUUyBgJHtUQUJMRV9OQU1FfWAgKGBpZGAgVEVYVCBOT1QgTlVMTCwgYHRleHRgIFRFWFQgTk9UIE5VTEwsIGBzb3VyY2VgIFRFWFQgTk9UIE5VTEwgREVGQVVMVCAnTG9jYWwnLCBgc3RhdGVgIFRFWFQgTk9UIE5VTEwsIFBSSU1BUlkgS0VZKGBpZGApKSIsCiAgICAgICAgImZpZWxkcyI6IFsKICAgICAgICAgIHsKICAgICAgICAgICAgImZpZWxkUGF0aCI6ICJpZCIsCiAgICAgICAgICAgICJjb2x1bW5OYW1lIjogImlkIiwKICAgICAgICAgICAgImFmZmluaXR5IjogIlRFWFQiLAogICAgICAgICAgICAibm90TnVsbCI6IHRydWUKICAgICAgICAgIH0sCiAgICAgICAgICB7CiAgICAgICAgICAgICJmaWVsZFBhdGgiOiAidGV4dCIsCiAgICAgICAgICAgICJjb2x1bW5OYW1lIjogInRleHQiLAogICAgICAgICAgICAiYWZmaW5pdHkiOiAiVEVYVCIsCiAgICAgICAgICAgICJub3ROdWxsIjogdHJ1ZQogICAgICAgICAgfSwKICAgICAgICAgIHsKICAgICAgICAgICAgImZpZWxkUGF0aCI6ICJzb3VyY2UiLAogICAgICAgICAgICAiY29sdW1uTmFtZSI6ICJzb3VyY2UiLAogICAgICAgICAgICAiYWZmaW5pdHkiOiAiVEVYVCIsCiAgICAgICAgICAgICJub3ROdWxsIjogdHJ1ZSwKICAgICAgICAgICAgImRlZmF1bHRWYWx1ZSI6ICInTG9jYWwnIgogICAgICAgICAgfSwKICAgICAgICAgIHsKICAgICAgICAgICAgImZpZWxkUGF0aCI6ICJzdGF0ZSIsCiAgICAgICAgICAgICJjb2x1bW5OYW1lIjogInN0YXRlIiwKICAgICAgICAgICAgImFmZmluaXR5IjogIlRFWFQiLAogICAgICAgICAgICAibm90TnVsbCI6IHRydWUKICAgICAgICAgIH0KICAgICAgICBdLAogICAgICAgICJwcmltYXJ5S2V5IjogewogICAgICAgICAgImNvbHVtbk5hbWVzIjogWwogICAgICAgICAgICAiaWQiCiAgICAgICAgICBdLAogICAgICAgICAgImF1dG9HZW5lcmF0ZSI6IGZhbHNlCiAgICAgICAgfSwKICAgICAgICAiaW5kaWNlcyI6IFtdLAogICAgICAgICJmb3JlaWduS2V5cyI6IFtdCiAgICAgIH0sCiAgICAgIHsKICAgICAgICAidGFibGVOYW1lIjogIk1lc3NhZ2VSZWNpcGllbnQiLAogICAgICAgICJjcmVhdGVTcWwiOiAiQ1JFQVRFIFRBQkxFIElGIE5PVCBFWElTVFMgYCR7VEFCTEVfTkFNRX1gIChgbWVzc2FnZUlkYCBURVhUIE5PVCBOVUxMLCBgcGhvbmVOdW1iZXJgIFRFWFQgTk9UIE5VTEwsIGBzdGF0ZWAgVEVYVCBOT1QgTlVMTCwgUFJJTUFSWSBLRVkoYG1lc3NhZ2VJZGAsIGBwaG9uZU51bWJlcmApLCBGT1JFSUdOIEtFWShgbWVzc2FnZUlkYCkgUkVGRVJFTkNFUyBgTWVzc2FnZWAoYGlkYCkgT04gVVBEQVRFIE5PIEFDVElPTiBPTiBERUxFVEUgQ0FTQ0FERSApIiwKICAgICAgICAiZmllbGRzIjogWwogICAgICAgICAgewogICAgICAgICAgICAiZmllbGRQYXRoIjogIm1lc3NhZ2VJZCIsCiAgICAgICAgICAgICJjb2x1bW5OYW1lIjogIm1lc3NhZ2VJZCIsCiAgICAgICAgICAgICJhZmZpbml0eSI6ICJURVhUIiwKICAgICAgICAgICAgIm5vdE51bGwiOiB0cnVlCiAgICAgICAgICB9LAogICAgICAgICAgewogICAgICAgICAgICAiZmllbGRQYXRoIjogInBob25lTnVtYmVyIiwKICAgICAgICAgICAgImNvbHVtbk5hbWUiOiAicGhvbmVOdW1iZXIiLAogICAgICAgICAgICAiYWZmaW5pdHkiOiAiVEVYVCIsCiAgICAgICAgICAgICJub3ROdWxsIjogdHJ1ZQogICAgICAgICAgfSwKICAgICAgICAgIHsKICAgICAgICAgICAgImZpZWxkUGF0aCI6ICJzdGF0ZSIsCiAgICAgICAgICAgICJjb2x1bW5OYW1lIjogInN0YXRlIiwKICAgICAgICAgICAgImFmZmluaXR5IjogIlRFWFQiLAogICAgICAgICAgICAibm90TnVsbCI6IHRydWUKICAgICAgICAgIH0KICAgICAgICBdLAogICAgICAgICJwcmltYXJ5S2V5IjogewogICAgICAgICAgImNvbHVtbk5hbWVzIjogWwogICAgICAgICAgICAibWVzc2FnZUlkIiwKICAgICAgICAgICAgInBob25lTnVtYmVyIgogICAgICAgICAgXSwKICAgICAgICAgICJhdXRvR2VuZXJhdGUiOiBmYWxzZQogICAgICAgIH0sCiAgICAgICAgImluZGljZXMiOiBbXSwKICAgICAgICAiZm9yZWlnbktleXMiOiBbCiAgICAgICAgICB7CiAgICAgICAgICAgICJ0YWJsZSI6ICJNZXNzYWdlIiwKICAgICAgICAgICAgIm9uRGVsZXRlIjogIkNBU0NBREUiLAogICAgICAgICAgICAib25VcGRhdGUiOiAiTk8gQUNUSU9OIiwKICAgICAgICAgICAgImNvbHVtbnMiOiBbCiAgICAgICAgICAgICAgIm1lc3NhZ2VJZCIKICAgICAgICAgICAgXSwKICAgICAgICAgICAgInJlZmVyZW5jZWRDb2x1bW5zIjogWwogICAgICAgICAgICAgICJpZCIKICAgICAgICAgICAgXQogICAgICAgICAgfQogICAgICAgIF0KICAgICAgfQogICAgXSwKICAgICJ2aWV3cyI6IFtdLAogICAgInNldHVwUXVlcmllcyI6IFsKICAgICAgIkNSRUFURSBUQUJMRSBJRiBOT1QgRVhJU1RTIHJvb21fbWFzdGVyX3RhYmxlIChpZCBJTlRFR0VSIFBSSU1BUlkgS0VZLGlkZW50aXR5X2hhc2ggVEVYVCkiLAogICAgICAiSU5TRVJUIE9SIFJFUExBQ0UgSU5UTyByb29tX21hc3Rlcl90YWJsZSAoaWQsaWRlbnRpdHlfaGFzaCkgVkFMVUVTKDQyLCAnMWMzYzMyNDZlYTBmMzY4ZWM5NWI3NDBiMmY1MGUxOGInKSIKICAgIF0KICB9Cn0=
|
||||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1 @@
|
|||||||
|
ewogICJmb3JtYXRWZXJzaW9uIjogMSwKICAiZGF0YWJhc2UiOiB7CiAgICAidmVyc2lvbiI6IDMsCiAgICAiaWRlbnRpdHlIYXNoIjogIjg5YjRkMTE0MmE5Yzc3ZWZmYmIyMzQ4NzlmNGI1NDBhIiwKICAgICJlbnRpdGllcyI6IFsKICAgICAgewogICAgICAgICJ0YWJsZU5hbWUiOiAiTWVzc2FnZSIsCiAgICAgICAgImNyZWF0ZVNxbCI6ICJDUkVBVEUgVEFCTEUgSUYgTk9UIEVYSVNUUyBgJHtUQUJMRV9OQU1FfWAgKGBpZGAgVEVYVCBOT1QgTlVMTCwgYHRleHRgIFRFWFQgTk9UIE5VTEwsIGBzb3VyY2VgIFRFWFQgTk9UIE5VTEwgREVGQVVMVCAnTG9jYWwnLCBgc3RhdGVgIFRFWFQgTk9UIE5VTEwsIGBjcmVhdGVkQXRgIElOVEVHRVIgTk9UIE5VTEwgREVGQVVMVCAwLCBQUklNQVJZIEtFWShgaWRgKSkiLAogICAgICAgICJmaWVsZHMiOiBbCiAgICAgICAgICB7CiAgICAgICAgICAgICJmaWVsZFBhdGgiOiAiaWQiLAogICAgICAgICAgICAiY29sdW1uTmFtZSI6ICJpZCIsCiAgICAgICAgICAgICJhZmZpbml0eSI6ICJURVhUIiwKICAgICAgICAgICAgIm5vdE51bGwiOiB0cnVlCiAgICAgICAgICB9LAogICAgICAgICAgewogICAgICAgICAgICAiZmllbGRQYXRoIjogInRleHQiLAogICAgICAgICAgICAiY29sdW1uTmFtZSI6ICJ0ZXh0IiwKICAgICAgICAgICAgImFmZmluaXR5IjogIlRFWFQiLAogICAgICAgICAgICAibm90TnVsbCI6IHRydWUKICAgICAgICAgIH0sCiAgICAgICAgICB7CiAgICAgICAgICAgICJmaWVsZFBhdGgiOiAic291cmNlIiwKICAgICAgICAgICAgImNvbHVtbk5hbWUiOiAic291cmNlIiwKICAgICAgICAgICAgImFmZmluaXR5IjogIlRFWFQiLAogICAgICAgICAgICAibm90TnVsbCI6IHRydWUsCiAgICAgICAgICAgICJkZWZhdWx0VmFsdWUiOiAiJ0xvY2FsJyIKICAgICAgICAgIH0sCiAgICAgICAgICB7CiAgICAgICAgICAgICJmaWVsZFBhdGgiOiAic3RhdGUiLAogICAgICAgICAgICAiY29sdW1uTmFtZSI6ICJzdGF0ZSIsCiAgICAgICAgICAgICJhZmZpbml0eSI6ICJURVhUIiwKICAgICAgICAgICAgIm5vdE51bGwiOiB0cnVlCiAgICAgICAgICB9LAogICAgICAgICAgewogICAgICAgICAgICAiZmllbGRQYXRoIjogImNyZWF0ZWRBdCIsCiAgICAgICAgICAgICJjb2x1bW5OYW1lIjogImNyZWF0ZWRBdCIsCiAgICAgICAgICAgICJhZmZpbml0eSI6ICJJTlRFR0VSIiwKICAgICAgICAgICAgIm5vdE51bGwiOiB0cnVlLAogICAgICAgICAgICAiZGVmYXVsdFZhbHVlIjogIjAiCiAgICAgICAgICB9CiAgICAgICAgXSwKICAgICAgICAicHJpbWFyeUtleSI6IHsKICAgICAgICAgICJjb2x1bW5OYW1lcyI6IFsKICAgICAgICAgICAgImlkIgogICAgICAgICAgXSwKICAgICAgICAgICJhdXRvR2VuZXJhdGUiOiBmYWxzZQogICAgICAgIH0sCiAgICAgICAgImluZGljZXMiOiBbXSwKICAgICAgICAiZm9yZWlnbktleXMiOiBbXQogICAgICB9LAogICAgICB7CiAgICAgICAgInRhYmxlTmFtZSI6ICJNZXNzYWdlUmVjaXBpZW50IiwKICAgICAgICAiY3JlYXRlU3FsIjogIkNSRUFURSBUQUJMRSBJRiBOT1QgRVhJU1RTIGAke1RBQkxFX05BTUV9YCAoYG1lc3NhZ2VJZGAgVEVYVCBOT1QgTlVMTCwgYHBob25lTnVtYmVyYCBURVhUIE5PVCBOVUxMLCBgc3RhdGVgIFRFWFQgTk9UIE5VTEwsIFBSSU1BUlkgS0VZKGBtZXNzYWdlSWRgLCBgcGhvbmVOdW1iZXJgKSwgRk9SRUlHTiBLRVkoYG1lc3NhZ2VJZGApIFJFRkVSRU5DRVMgYE1lc3NhZ2VgKGBpZGApIE9OIFVQREFURSBOTyBBQ1RJT04gT04gREVMRVRFIENBU0NBREUgKSIsCiAgICAgICAgImZpZWxkcyI6IFsKICAgICAgICAgIHsKICAgICAgICAgICAgImZpZWxkUGF0aCI6ICJtZXNzYWdlSWQiLAogICAgICAgICAgICAiY29sdW1uTmFtZSI6ICJtZXNzYWdlSWQiLAogICAgICAgICAgICAiYWZmaW5pdHkiOiAiVEVYVCIsCiAgICAgICAgICAgICJub3ROdWxsIjogdHJ1ZQogICAgICAgICAgfSwKICAgICAgICAgIHsKICAgICAgICAgICAgImZpZWxkUGF0aCI6ICJwaG9uZU51bWJlciIsCiAgICAgICAgICAgICJjb2x1bW5OYW1lIjogInBob25lTnVtYmVyIiwKICAgICAgICAgICAgImFmZmluaXR5IjogIlRFWFQiLAogICAgICAgICAgICAibm90TnVsbCI6IHRydWUKICAgICAgICAgIH0sCiAgICAgICAgICB7CiAgICAgICAgICAgICJmaWVsZFBhdGgiOiAic3RhdGUiLAogICAgICAgICAgICAiY29sdW1uTmFtZSI6ICJzdGF0ZSIsCiAgICAgICAgICAgICJhZmZpbml0eSI6ICJURVhUIiwKICAgICAgICAgICAgIm5vdE51bGwiOiB0cnVlCiAgICAgICAgICB9CiAgICAgICAgXSwKICAgICAgICAicHJpbWFyeUtleSI6IHsKICAgICAgICAgICJjb2x1bW5OYW1lcyI6IFsKICAgICAgICAgICAgIm1lc3NhZ2VJZCIsCiAgICAgICAgICAgICJwaG9uZU51bWJlciIKICAgICAgICAgIF0sCiAgICAgICAgICAiYXV0b0dlbmVyYXRlIjogZmFsc2UKICAgICAgICB9LAogICAgICAgICJpbmRpY2VzIjogW10sCiAgICAgICAgImZvcmVpZ25LZXlzIjogWwogICAgICAgICAgewogICAgICAgICAgICAidGFibGUiOiAiTWVzc2FnZSIsCiAgICAgICAgICAgICJvbkRlbGV0ZSI6ICJDQVNDQURFIiwKICAgICAgICAgICAgIm9uVXBkYXRlIjogIk5PIEFDVElPTiIsCiAgICAgICAgICAgICJjb2x1bW5zIjogWwogICAgICAgICAgICAgICJtZXNzYWdlSWQiCiAgICAgICAgICAgIF0sCiAgICAgICAgICAgICJyZWZlcmVuY2VkQ29sdW1ucyI6IFsKICAgICAgICAgICAgICAiaWQiCiAgICAgICAgICAgIF0KICAgICAgICAgIH0KICAgICAgICBdCiAgICAgIH0KICAgIF0sCiAgICAidmlld3MiOiBbXSwKICAgICJzZXR1cFF1ZXJpZXMiOiBbCiAgICAgICJDUkVBVEUgVEFCTEUgSUYgTk9UIEVYSVNUUyByb29tX21hc3Rlcl90YWJsZSAoaWQgSU5URUdFUiBQUklNQVJZIEtFWSxpZGVudGl0eV9oYXNoIFRFWFQpIiwKICAgICAgIklOU0VSVCBPUiBSRVBMQUNFIElOVE8gcm9vbV9tYXN0ZXJfdGFibGUgKGlkLGlkZW50aXR5X2hhc2gpIFZBTFVFUyg0MiwgJzg5YjRkMTE0MmE5Yzc3ZWZmYmIyMzQ4NzlmNGI1NDBhJykiCiAgICBdCiAgfQp9
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
ewogICJmb3JtYXRWZXJzaW9uIjogMSwKICAiZGF0YWJhc2UiOiB7CiAgICAidmVyc2lvbiI6IDQsCiAgICAiaWRlbnRpdHlIYXNoIjogImU0YTA0NTBhZTJiODA2YjUyYmZiY2QyNDU2NTAxYTFkIiwKICAgICJlbnRpdGllcyI6IFsKICAgICAgewogICAgICAgICJ0YWJsZU5hbWUiOiAiTWVzc2FnZSIsCiAgICAgICAgImNyZWF0ZVNxbCI6ICJDUkVBVEUgVEFCTEUgSUYgTk9UIEVYSVNUUyBgJHtUQUJMRV9OQU1FfWAgKGBpZGAgVEVYVCBOT1QgTlVMTCwgYHRleHRgIFRFWFQgTk9UIE5VTEwsIGBzb3VyY2VgIFRFWFQgTk9UIE5VTEwgREVGQVVMVCAnTG9jYWwnLCBgc3RhdGVgIFRFWFQgTk9UIE5VTEwsIGBjcmVhdGVkQXRgIElOVEVHRVIgTk9UIE5VTEwgREVGQVVMVCAwLCBQUklNQVJZIEtFWShgaWRgKSkiLAogICAgICAgICJmaWVsZHMiOiBbCiAgICAgICAgICB7CiAgICAgICAgICAgICJmaWVsZFBhdGgiOiAiaWQiLAogICAgICAgICAgICAiY29sdW1uTmFtZSI6ICJpZCIsCiAgICAgICAgICAgICJhZmZpbml0eSI6ICJURVhUIiwKICAgICAgICAgICAgIm5vdE51bGwiOiB0cnVlCiAgICAgICAgICB9LAogICAgICAgICAgewogICAgICAgICAgICAiZmllbGRQYXRoIjogInRleHQiLAogICAgICAgICAgICAiY29sdW1uTmFtZSI6ICJ0ZXh0IiwKICAgICAgICAgICAgImFmZmluaXR5IjogIlRFWFQiLAogICAgICAgICAgICAibm90TnVsbCI6IHRydWUKICAgICAgICAgIH0sCiAgICAgICAgICB7CiAgICAgICAgICAgICJmaWVsZFBhdGgiOiAic291cmNlIiwKICAgICAgICAgICAgImNvbHVtbk5hbWUiOiAic291cmNlIiwKICAgICAgICAgICAgImFmZmluaXR5IjogIlRFWFQiLAogICAgICAgICAgICAibm90TnVsbCI6IHRydWUsCiAgICAgICAgICAgICJkZWZhdWx0VmFsdWUiOiAiJ0xvY2FsJyIKICAgICAgICAgIH0sCiAgICAgICAgICB7CiAgICAgICAgICAgICJmaWVsZFBhdGgiOiAic3RhdGUiLAogICAgICAgICAgICAiY29sdW1uTmFtZSI6ICJzdGF0ZSIsCiAgICAgICAgICAgICJhZmZpbml0eSI6ICJURVhUIiwKICAgICAgICAgICAgIm5vdE51bGwiOiB0cnVlCiAgICAgICAgICB9LAogICAgICAgICAgewogICAgICAgICAgICAiZmllbGRQYXRoIjogImNyZWF0ZWRBdCIsCiAgICAgICAgICAgICJjb2x1bW5OYW1lIjogImNyZWF0ZWRBdCIsCiAgICAgICAgICAgICJhZmZpbml0eSI6ICJJTlRFR0VSIiwKICAgICAgICAgICAgIm5vdE51bGwiOiB0cnVlLAogICAgICAgICAgICAiZGVmYXVsdFZhbHVlIjogIjAiCiAgICAgICAgICB9CiAgICAgICAgXSwKICAgICAgICAicHJpbWFyeUtleSI6IHsKICAgICAgICAgICJjb2x1bW5OYW1lcyI6IFsKICAgICAgICAgICAgImlkIgogICAgICAgICAgXSwKICAgICAgICAgICJhdXRvR2VuZXJhdGUiOiBmYWxzZQogICAgICAgIH0sCiAgICAgICAgImluZGljZXMiOiBbXSwKICAgICAgICAiZm9yZWlnbktleXMiOiBbXQogICAgICB9LAogICAgICB7CiAgICAgICAgInRhYmxlTmFtZSI6ICJNZXNzYWdlUmVjaXBpZW50IiwKICAgICAgICAiY3JlYXRlU3FsIjogIkNSRUFURSBUQUJMRSBJRiBOT1QgRVhJU1RTIGAke1RBQkxFX05BTUV9YCAoYG1lc3NhZ2VJZGAgVEVYVCBOT1QgTlVMTCwgYHBob25lTnVtYmVyYCBURVhUIE5PVCBOVUxMLCBgc3RhdGVgIFRFWFQgTk9UIE5VTEwsIGBlcnJvcmAgVEVYVCwgUFJJTUFSWSBLRVkoYG1lc3NhZ2VJZGAsIGBwaG9uZU51bWJlcmApLCBGT1JFSUdOIEtFWShgbWVzc2FnZUlkYCkgUkVGRVJFTkNFUyBgTWVzc2FnZWAoYGlkYCkgT04gVVBEQVRFIE5PIEFDVElPTiBPTiBERUxFVEUgQ0FTQ0FERSApIiwKICAgICAgICAiZmllbGRzIjogWwogICAgICAgICAgewogICAgICAgICAgICAiZmllbGRQYXRoIjogIm1lc3NhZ2VJZCIsCiAgICAgICAgICAgICJjb2x1bW5OYW1lIjogIm1lc3NhZ2VJZCIsCiAgICAgICAgICAgICJhZmZpbml0eSI6ICJURVhUIiwKICAgICAgICAgICAgIm5vdE51bGwiOiB0cnVlCiAgICAgICAgICB9LAogICAgICAgICAgewogICAgICAgICAgICAiZmllbGRQYXRoIjogInBob25lTnVtYmVyIiwKICAgICAgICAgICAgImNvbHVtbk5hbWUiOiAicGhvbmVOdW1iZXIiLAogICAgICAgICAgICAiYWZmaW5pdHkiOiAiVEVYVCIsCiAgICAgICAgICAgICJub3ROdWxsIjogdHJ1ZQogICAgICAgICAgfSwKICAgICAgICAgIHsKICAgICAgICAgICAgImZpZWxkUGF0aCI6ICJzdGF0ZSIsCiAgICAgICAgICAgICJjb2x1bW5OYW1lIjogInN0YXRlIiwKICAgICAgICAgICAgImFmZmluaXR5IjogIlRFWFQiLAogICAgICAgICAgICAibm90TnVsbCI6IHRydWUKICAgICAgICAgIH0sCiAgICAgICAgICB7CiAgICAgICAgICAgICJmaWVsZFBhdGgiOiAiZXJyb3IiLAogICAgICAgICAgICAiY29sdW1uTmFtZSI6ICJlcnJvciIsCiAgICAgICAgICAgICJhZmZpbml0eSI6ICJURVhUIiwKICAgICAgICAgICAgIm5vdE51bGwiOiBmYWxzZQogICAgICAgICAgfQogICAgICAgIF0sCiAgICAgICAgInByaW1hcnlLZXkiOiB7CiAgICAgICAgICAiY29sdW1uTmFtZXMiOiBbCiAgICAgICAgICAgICJtZXNzYWdlSWQiLAogICAgICAgICAgICAicGhvbmVOdW1iZXIiCiAgICAgICAgICBdLAogICAgICAgICAgImF1dG9HZW5lcmF0ZSI6IGZhbHNlCiAgICAgICAgfSwKICAgICAgICAiaW5kaWNlcyI6IFtdLAogICAgICAgICJmb3JlaWduS2V5cyI6IFsKICAgICAgICAgIHsKICAgICAgICAgICAgInRhYmxlIjogIk1lc3NhZ2UiLAogICAgICAgICAgICAib25EZWxldGUiOiAiQ0FTQ0FERSIsCiAgICAgICAgICAgICJvblVwZGF0ZSI6ICJOTyBBQ1RJT04iLAogICAgICAgICAgICAiY29sdW1ucyI6IFsKICAgICAgICAgICAgICAibWVzc2FnZUlkIgogICAgICAgICAgICBdLAogICAgICAgICAgICAicmVmZXJlbmNlZENvbHVtbnMiOiBbCiAgICAgICAgICAgICAgImlkIgogICAgICAgICAgICBdCiAgICAgICAgICB9CiAgICAgICAgXQogICAgICB9CiAgICBdLAogICAgInZpZXdzIjogW10sCiAgICAic2V0dXBRdWVyaWVzIjogWwogICAgICAiQ1JFQVRFIFRBQkxFIElGIE5PVCBFWElTVFMgcm9vbV9tYXN0ZXJfdGFibGUgKGlkIElOVEVHRVIgUFJJTUFSWSBLRVksaWRlbnRpdHlfaGFzaCBURVhUKSIsCiAgICAgICJJTlNFUlQgT1IgUkVQTEFDRSBJTlRPIHJvb21fbWFzdGVyX3RhYmxlIChpZCxpZGVudGl0eV9oYXNoKSBWQUxVRVMoNDIsICdlNGEwNDUwYWUyYjgwNmI1MmJmYmNkMjQ1NjUwMWExZCcpIgogICAgXQogIH0KfQ==
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
ewogICJmb3JtYXRWZXJzaW9uIjogMSwKICAiZGF0YWJhc2UiOiB7CiAgICAidmVyc2lvbiI6IDUsCiAgICAiaWRlbnRpdHlIYXNoIjogIjRhODYyNjNiOWJiNmE3MzYyNzFjYzY2YzZmYWNhMjU0IiwKICAgICJlbnRpdGllcyI6IFsKICAgICAgewogICAgICAgICJ0YWJsZU5hbWUiOiAiTWVzc2FnZSIsCiAgICAgICAgImNyZWF0ZVNxbCI6ICJDUkVBVEUgVEFCTEUgSUYgTk9UIEVYSVNUUyBgJHtUQUJMRV9OQU1FfWAgKGBpZGAgVEVYVCBOT1QgTlVMTCwgYHRleHRgIFRFWFQgTk9UIE5VTEwsIGBzb3VyY2VgIFRFWFQgTk9UIE5VTEwgREVGQVVMVCAnTG9jYWwnLCBgc3RhdGVgIFRFWFQgTk9UIE5VTEwsIGBpc0VuY3J5cHRlZGAgSU5URUdFUiBOT1QgTlVMTCBERUZBVUxUIDAsIGBjcmVhdGVkQXRgIElOVEVHRVIgTk9UIE5VTEwgREVGQVVMVCAwLCBQUklNQVJZIEtFWShgaWRgKSkiLAogICAgICAgICJmaWVsZHMiOiBbCiAgICAgICAgICB7CiAgICAgICAgICAgICJmaWVsZFBhdGgiOiAiaWQiLAogICAgICAgICAgICAiY29sdW1uTmFtZSI6ICJpZCIsCiAgICAgICAgICAgICJhZmZpbml0eSI6ICJURVhUIiwKICAgICAgICAgICAgIm5vdE51bGwiOiB0cnVlCiAgICAgICAgICB9LAogICAgICAgICAgewogICAgICAgICAgICAiZmllbGRQYXRoIjogInRleHQiLAogICAgICAgICAgICAiY29sdW1uTmFtZSI6ICJ0ZXh0IiwKICAgICAgICAgICAgImFmZmluaXR5IjogIlRFWFQiLAogICAgICAgICAgICAibm90TnVsbCI6IHRydWUKICAgICAgICAgIH0sCiAgICAgICAgICB7CiAgICAgICAgICAgICJmaWVsZFBhdGgiOiAic291cmNlIiwKICAgICAgICAgICAgImNvbHVtbk5hbWUiOiAic291cmNlIiwKICAgICAgICAgICAgImFmZmluaXR5IjogIlRFWFQiLAogICAgICAgICAgICAibm90TnVsbCI6IHRydWUsCiAgICAgICAgICAgICJkZWZhdWx0VmFsdWUiOiAiJ0xvY2FsJyIKICAgICAgICAgIH0sCiAgICAgICAgICB7CiAgICAgICAgICAgICJmaWVsZFBhdGgiOiAic3RhdGUiLAogICAgICAgICAgICAiY29sdW1uTmFtZSI6ICJzdGF0ZSIsCiAgICAgICAgICAgICJhZmZpbml0eSI6ICJURVhUIiwKICAgICAgICAgICAgIm5vdE51bGwiOiB0cnVlCiAgICAgICAgICB9LAogICAgICAgICAgewogICAgICAgICAgICAiZmllbGRQYXRoIjogImlzRW5jcnlwdGVkIiwKICAgICAgICAgICAgImNvbHVtbk5hbWUiOiAiaXNFbmNyeXB0ZWQiLAogICAgICAgICAgICAiYWZmaW5pdHkiOiAiSU5URUdFUiIsCiAgICAgICAgICAgICJub3ROdWxsIjogdHJ1ZSwKICAgICAgICAgICAgImRlZmF1bHRWYWx1ZSI6ICIwIgogICAgICAgICAgfSwKICAgICAgICAgIHsKICAgICAgICAgICAgImZpZWxkUGF0aCI6ICJjcmVhdGVkQXQiLAogICAgICAgICAgICAiY29sdW1uTmFtZSI6ICJjcmVhdGVkQXQiLAogICAgICAgICAgICAiYWZmaW5pdHkiOiAiSU5URUdFUiIsCiAgICAgICAgICAgICJub3ROdWxsIjogdHJ1ZSwKICAgICAgICAgICAgImRlZmF1bHRWYWx1ZSI6ICIwIgogICAgICAgICAgfQogICAgICAgIF0sCiAgICAgICAgInByaW1hcnlLZXkiOiB7CiAgICAgICAgICAiY29sdW1uTmFtZXMiOiBbCiAgICAgICAgICAgICJpZCIKICAgICAgICAgIF0sCiAgICAgICAgICAiYXV0b0dlbmVyYXRlIjogZmFsc2UKICAgICAgICB9LAogICAgICAgICJpbmRpY2VzIjogW10sCiAgICAgICAgImZvcmVpZ25LZXlzIjogW10KICAgICAgfSwKICAgICAgewogICAgICAgICJ0YWJsZU5hbWUiOiAiTWVzc2FnZVJlY2lwaWVudCIsCiAgICAgICAgImNyZWF0ZVNxbCI6ICJDUkVBVEUgVEFCTEUgSUYgTk9UIEVYSVNUUyBgJHtUQUJMRV9OQU1FfWAgKGBtZXNzYWdlSWRgIFRFWFQgTk9UIE5VTEwsIGBwaG9uZU51bWJlcmAgVEVYVCBOT1QgTlVMTCwgYHN0YXRlYCBURVhUIE5PVCBOVUxMLCBgZXJyb3JgIFRFWFQsIFBSSU1BUlkgS0VZKGBtZXNzYWdlSWRgLCBgcGhvbmVOdW1iZXJgKSwgRk9SRUlHTiBLRVkoYG1lc3NhZ2VJZGApIFJFRkVSRU5DRVMgYE1lc3NhZ2VgKGBpZGApIE9OIFVQREFURSBOTyBBQ1RJT04gT04gREVMRVRFIENBU0NBREUgKSIsCiAgICAgICAgImZpZWxkcyI6IFsKICAgICAgICAgIHsKICAgICAgICAgICAgImZpZWxkUGF0aCI6ICJtZXNzYWdlSWQiLAogICAgICAgICAgICAiY29sdW1uTmFtZSI6ICJtZXNzYWdlSWQiLAogICAgICAgICAgICAiYWZmaW5pdHkiOiAiVEVYVCIsCiAgICAgICAgICAgICJub3ROdWxsIjogdHJ1ZQogICAgICAgICAgfSwKICAgICAgICAgIHsKICAgICAgICAgICAgImZpZWxkUGF0aCI6ICJwaG9uZU51bWJlciIsCiAgICAgICAgICAgICJjb2x1bW5OYW1lIjogInBob25lTnVtYmVyIiwKICAgICAgICAgICAgImFmZmluaXR5IjogIlRFWFQiLAogICAgICAgICAgICAibm90TnVsbCI6IHRydWUKICAgICAgICAgIH0sCiAgICAgICAgICB7CiAgICAgICAgICAgICJmaWVsZFBhdGgiOiAic3RhdGUiLAogICAgICAgICAgICAiY29sdW1uTmFtZSI6ICJzdGF0ZSIsCiAgICAgICAgICAgICJhZmZpbml0eSI6ICJURVhUIiwKICAgICAgICAgICAgIm5vdE51bGwiOiB0cnVlCiAgICAgICAgICB9LAogICAgICAgICAgewogICAgICAgICAgICAiZmllbGRQYXRoIjogImVycm9yIiwKICAgICAgICAgICAgImNvbHVtbk5hbWUiOiAiZXJyb3IiLAogICAgICAgICAgICAiYWZmaW5pdHkiOiAiVEVYVCIsCiAgICAgICAgICAgICJub3ROdWxsIjogZmFsc2UKICAgICAgICAgIH0KICAgICAgICBdLAogICAgICAgICJwcmltYXJ5S2V5IjogewogICAgICAgICAgImNvbHVtbk5hbWVzIjogWwogICAgICAgICAgICAibWVzc2FnZUlkIiwKICAgICAgICAgICAgInBob25lTnVtYmVyIgogICAgICAgICAgXSwKICAgICAgICAgICJhdXRvR2VuZXJhdGUiOiBmYWxzZQogICAgICAgIH0sCiAgICAgICAgImluZGljZXMiOiBbXSwKICAgICAgICAiZm9yZWlnbktleXMiOiBbCiAgICAgICAgICB7CiAgICAgICAgICAgICJ0YWJsZSI6ICJNZXNzYWdlIiwKICAgICAgICAgICAgIm9uRGVsZXRlIjogIkNBU0NBREUiLAogICAgICAgICAgICAib25VcGRhdGUiOiAiTk8gQUNUSU9OIiwKICAgICAgICAgICAgImNvbHVtbnMiOiBbCiAgICAgICAgICAgICAgIm1lc3NhZ2VJZCIKICAgICAgICAgICAgXSwKICAgICAgICAgICAgInJlZmVyZW5jZWRDb2x1bW5zIjogWwogICAgICAgICAgICAgICJpZCIKICAgICAgICAgICAgXQogICAgICAgICAgfQogICAgICAgIF0KICAgICAgfQogICAgXSwKICAgICJ2aWV3cyI6IFtdLAogICAgInNldHVwUXVlcmllcyI6IFsKICAgICAgIkNSRUFURSBUQUJMRSBJRiBOT1QgRVhJU1RTIHJvb21fbWFzdGVyX3RhYmxlIChpZCBJTlRFR0VSIFBSSU1BUlkgS0VZLGlkZW50aXR5X2hhc2ggVEVYVCkiLAogICAgICAiSU5TRVJUIE9SIFJFUExBQ0UgSU5UTyByb29tX21hc3Rlcl90YWJsZSAoaWQsaWRlbnRpdHlfaGFzaCkgVkFMVUVTKDQyLCAnNGE4NjI2M2I5YmI2YTczNjI3MWNjNjZjNmZhY2EyNTQnKSIKICAgIF0KICB9Cn0=
|
||||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -0,0 +1,22 @@
|
|||||||
|
package pt.whatsms.gateway
|
||||||
|
|
||||||
|
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||||
|
import androidx.test.platform.app.InstrumentationRegistry
|
||||||
|
import org.junit.Assert.assertEquals
|
||||||
|
import org.junit.Test
|
||||||
|
import org.junit.runner.RunWith
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instrumented test, which will execute on an Android device.
|
||||||
|
*
|
||||||
|
* See [testing documentation](http://d.android.com/tools/testing).
|
||||||
|
*/
|
||||||
|
@RunWith(AndroidJUnit4::class)
|
||||||
|
class ExampleInstrumentedTest {
|
||||||
|
@Test
|
||||||
|
fun useAppContext() {
|
||||||
|
// Context of the app under test.
|
||||||
|
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
|
||||||
|
assertEquals("pt.whatsms.gateway", appContext.packageName)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,103 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools">
|
||||||
|
|
||||||
|
<uses-feature
|
||||||
|
android:name="android.hardware.telephony"
|
||||||
|
android:required="false" />
|
||||||
|
|
||||||
|
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
||||||
|
<uses-permission android:name="android.permission.CAMERA" />
|
||||||
|
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
||||||
|
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />
|
||||||
|
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_CONNECTED_DEVICE" />
|
||||||
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
|
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
|
||||||
|
<uses-permission android:name="android.permission.READ_SMS" />
|
||||||
|
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
||||||
|
<uses-permission android:name="android.permission.RECEIVE_MMS" />
|
||||||
|
<uses-permission android:name="android.permission.RECEIVE_SMS" />
|
||||||
|
<uses-permission android:name="android.permission.RECEIVE_WAP_PUSH" />
|
||||||
|
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
|
||||||
|
<uses-permission android:name="android.permission.SEND_SMS" />
|
||||||
|
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
||||||
|
|
||||||
|
<application
|
||||||
|
android:name=".App"
|
||||||
|
android:allowBackup="true"
|
||||||
|
android:icon="@mipmap/ic_launcher"
|
||||||
|
android:label="@string/app_name"
|
||||||
|
android:networkSecurityConfig="${networkSecurityConfig}"
|
||||||
|
android:roundIcon="@mipmap/ic_launcher_round"
|
||||||
|
android:supportsRtl="true"
|
||||||
|
android:theme="@style/Theme.SmsGateway">
|
||||||
|
<service
|
||||||
|
android:name=".modules.gateway.services.SSEForegroundService"
|
||||||
|
android:enabled="true"
|
||||||
|
android:exported="false"
|
||||||
|
android:foregroundServiceType="dataSync" />
|
||||||
|
<service
|
||||||
|
android:name=".modules.ping.services.PingForegroundService"
|
||||||
|
android:enabled="true"
|
||||||
|
android:exported="false"
|
||||||
|
android:foregroundServiceType="dataSync" />
|
||||||
|
|
||||||
|
<service
|
||||||
|
android:name=".services.PushService"
|
||||||
|
android:enabled="true"
|
||||||
|
android:exported="false">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="com.google.firebase.MESSAGING_EVENT" />
|
||||||
|
</intent-filter>
|
||||||
|
</service>
|
||||||
|
|
||||||
|
<receiver
|
||||||
|
android:name=".receivers.EventsReceiver"
|
||||||
|
android:enabled="true"
|
||||||
|
android:exported="true">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="pt.whatsms.gateway.ACTION_SENT" />
|
||||||
|
<action android:name="pt.whatsms.gateway.ACTION_DELIVERED" />
|
||||||
|
</intent-filter>
|
||||||
|
</receiver>
|
||||||
|
<receiver
|
||||||
|
android:name=".receivers.BootReceiver"
|
||||||
|
android:enabled="true"
|
||||||
|
android:exported="true">
|
||||||
|
<intent-filter>
|
||||||
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
|
|
||||||
|
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
||||||
|
<action android:name="android.intent.action.ACTION_BOOT_COMPLETED" />
|
||||||
|
<action android:name="android.intent.action.REBOOT" />
|
||||||
|
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
|
||||||
|
<action android:name="com.htc.intent.action.QUICKBOOT_POWERON" />
|
||||||
|
<action android:name="android.intent.action.ACTION_SHUTDOWN" />
|
||||||
|
</intent-filter>
|
||||||
|
</receiver>
|
||||||
|
|
||||||
|
<service
|
||||||
|
android:name=".modules.localserver.WebService"
|
||||||
|
android:enabled="true"
|
||||||
|
android:foregroundServiceType="connectedDevice" />
|
||||||
|
<service
|
||||||
|
android:name="androidx.work.impl.foreground.SystemForegroundService"
|
||||||
|
android:foregroundServiceType="dataSync"
|
||||||
|
tools:node="merge" />
|
||||||
|
|
||||||
|
<activity
|
||||||
|
android:name=".ui.ScanPairingActivity"
|
||||||
|
android:exported="false" />
|
||||||
|
|
||||||
|
<activity
|
||||||
|
android:name=".MainActivity"
|
||||||
|
android:exported="true">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
|
||||||
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
|
</intent-filter>
|
||||||
|
</activity>
|
||||||
|
</application>
|
||||||
|
|
||||||
|
</manifest>
|
||||||
|
Before Width: | Height: | Size: 665 B After Width: | Height: | Size: 665 B |
|
Before Width: | Height: | Size: 628 B After Width: | Height: | Size: 628 B |
@@ -1394,7 +1394,7 @@
|
|||||||
"url": "https://www.apache.org/licenses/LICENSE-2.0"
|
"url": "https://www.apache.org/licenses/LICENSE-2.0"
|
||||||
},
|
},
|
||||||
"title": "SMSGate API",
|
"title": "SMSGate API",
|
||||||
"version": "3.1.0-hardcode"
|
"version": "{{VERSION}}"
|
||||||
},
|
},
|
||||||
"openapi": "3.0.1",
|
"openapi": "3.0.1",
|
||||||
"paths": {
|
"paths": {
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 141 KiB |
@@ -0,0 +1,75 @@
|
|||||||
|
package pt.whatsms.gateway
|
||||||
|
|
||||||
|
import android.app.Application
|
||||||
|
import healthModule
|
||||||
|
import pt.whatsms.gateway.data.dbModule
|
||||||
|
import pt.whatsms.gateway.modules.connection.connectionModule
|
||||||
|
import pt.whatsms.gateway.modules.encryption.encryptionModule
|
||||||
|
import pt.whatsms.gateway.modules.events.eventBusModule
|
||||||
|
import pt.whatsms.gateway.modules.gateway.GatewayService
|
||||||
|
import pt.whatsms.gateway.modules.incoming.incomingModule
|
||||||
|
import pt.whatsms.gateway.modules.localserver.localserverModule
|
||||||
|
import pt.whatsms.gateway.modules.logs.logsModule
|
||||||
|
import pt.whatsms.gateway.modules.messages.messagesModule
|
||||||
|
import pt.whatsms.gateway.modules.notifications.notificationsModule
|
||||||
|
import pt.whatsms.gateway.modules.orchestrator.OrchestratorService
|
||||||
|
import pt.whatsms.gateway.modules.orchestrator.orchestratorModule
|
||||||
|
import pt.whatsms.gateway.modules.ping.pingModule
|
||||||
|
import pt.whatsms.gateway.modules.receiver.receiverModule
|
||||||
|
import pt.whatsms.gateway.modules.settings.settingsModule
|
||||||
|
import pt.whatsms.gateway.modules.webhooks.webhooksModule
|
||||||
|
import pt.whatsms.gateway.receivers.EventsReceiver
|
||||||
|
import org.koin.android.ext.android.get
|
||||||
|
import org.koin.android.ext.android.inject
|
||||||
|
import org.koin.android.ext.koin.androidContext
|
||||||
|
import org.koin.android.ext.koin.androidLogger
|
||||||
|
import org.koin.core.context.startKoin
|
||||||
|
|
||||||
|
class App: Application() {
|
||||||
|
override fun onCreate() {
|
||||||
|
super.onCreate()
|
||||||
|
|
||||||
|
startKoin {
|
||||||
|
androidLogger()
|
||||||
|
androidContext(this@App)
|
||||||
|
modules(
|
||||||
|
eventBusModule,
|
||||||
|
settingsModule,
|
||||||
|
dbModule,
|
||||||
|
logsModule,
|
||||||
|
notificationsModule,
|
||||||
|
messagesModule,
|
||||||
|
incomingModule,
|
||||||
|
receiverModule,
|
||||||
|
encryptionModule,
|
||||||
|
pt.whatsms.gateway.modules.gateway.gatewayModule,
|
||||||
|
healthModule,
|
||||||
|
webhooksModule,
|
||||||
|
localserverModule,
|
||||||
|
pingModule,
|
||||||
|
connectionModule,
|
||||||
|
orchestratorModule,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
Thread.setDefaultUncaughtExceptionHandler(
|
||||||
|
GlobalExceptionHandler(
|
||||||
|
Thread.getDefaultUncaughtExceptionHandler()!!,
|
||||||
|
get()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
instance = this
|
||||||
|
|
||||||
|
EventsReceiver.register(this)
|
||||||
|
|
||||||
|
get<OrchestratorService>().start(this, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
val gatewayService: GatewayService by inject()
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
lateinit var instance: App
|
||||||
|
private set
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package pt.whatsms.gateway
|
||||||
|
|
||||||
|
import android.util.Log
|
||||||
|
import pt.whatsms.gateway.modules.logs.LogsService
|
||||||
|
import pt.whatsms.gateway.modules.logs.db.LogEntry
|
||||||
|
import org.koin.core.component.KoinComponent
|
||||||
|
import java.lang.Thread.UncaughtExceptionHandler
|
||||||
|
|
||||||
|
class GlobalExceptionHandler(
|
||||||
|
private val defaultHandler: UncaughtExceptionHandler,
|
||||||
|
private val logger: LogsService
|
||||||
|
) : UncaughtExceptionHandler, KoinComponent {
|
||||||
|
|
||||||
|
override fun uncaughtException(thread: Thread, throwable: Throwable) {
|
||||||
|
try {
|
||||||
|
logger.insert(
|
||||||
|
LogEntry.Priority.ERROR,
|
||||||
|
"GlobalExceptionHandler",
|
||||||
|
"Unhandled exception in ${thread.name}",
|
||||||
|
mapOf(
|
||||||
|
"message" to throwable.message,
|
||||||
|
"stackTrace" to throwable.stackTrace.joinToString("\n"),
|
||||||
|
"threadName" to thread.name,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.e("GlobalExceptionHandler", "Failed to log uncaught exception", e)
|
||||||
|
} finally {
|
||||||
|
defaultHandler.uncaughtException(thread, throwable)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,88 @@
|
|||||||
|
package pt.whatsms.gateway
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
|
import android.os.Bundle
|
||||||
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
|
import androidx.fragment.app.Fragment
|
||||||
|
import com.google.android.material.tabs.TabLayoutMediator
|
||||||
|
import pt.whatsms.gateway.databinding.ActivityMainBinding
|
||||||
|
import pt.whatsms.gateway.ui.HolderFragment
|
||||||
|
import pt.whatsms.gateway.ui.HomeFragment
|
||||||
|
import pt.whatsms.gateway.ui.SettingsFragment
|
||||||
|
|
||||||
|
class MainActivity : AppCompatActivity() {
|
||||||
|
|
||||||
|
private lateinit var binding: ActivityMainBinding
|
||||||
|
|
||||||
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
super.onCreate(savedInstanceState)
|
||||||
|
|
||||||
|
binding = ActivityMainBinding.inflate(layoutInflater)
|
||||||
|
setContentView(binding.root)
|
||||||
|
|
||||||
|
val adapter = FragmentsAdapter(this)
|
||||||
|
binding.viewPager.adapter = adapter
|
||||||
|
|
||||||
|
TabLayoutMediator(binding.tabLayout, binding.viewPager) { tab, position ->
|
||||||
|
when (position) {
|
||||||
|
0 -> tab.apply {
|
||||||
|
text = getString(R.string.tab_text_home)
|
||||||
|
setIcon(R.drawable.ic_home)
|
||||||
|
}
|
||||||
|
|
||||||
|
1 -> tab.apply {
|
||||||
|
text = getString(R.string.tab_text_messages)
|
||||||
|
setIcon(R.drawable.ic_sms)
|
||||||
|
}
|
||||||
|
|
||||||
|
2 -> tab.apply {
|
||||||
|
text = getString(R.string.tab_text_settings)
|
||||||
|
setIcon(R.drawable.ic_advanced)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.attach()
|
||||||
|
|
||||||
|
processIntent(intent)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onNewIntent(intent: Intent) {
|
||||||
|
super.onNewIntent(intent)
|
||||||
|
processIntent(intent)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun processIntent(intent: Intent) {
|
||||||
|
val tabIndex = intent.getIntExtra(EXTRA_TAB_INDEX, TAB_INDEX_HOME)
|
||||||
|
|
||||||
|
binding.viewPager.currentItem = tabIndex
|
||||||
|
}
|
||||||
|
|
||||||
|
class FragmentsAdapter(activity: AppCompatActivity) :
|
||||||
|
androidx.viewpager2.adapter.FragmentStateAdapter(activity) {
|
||||||
|
|
||||||
|
override fun getItemCount(): Int = 3
|
||||||
|
|
||||||
|
override fun createFragment(position: Int): Fragment {
|
||||||
|
return when (position) {
|
||||||
|
0 -> HomeFragment.newInstance()
|
||||||
|
1 -> HolderFragment.newInstance()
|
||||||
|
else -> SettingsFragment.newInstance()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
const val TAB_INDEX_HOME = 0
|
||||||
|
const val TAB_INDEX_MESSAGES = 1
|
||||||
|
const val TAB_INDEX_SETTINGS = 2
|
||||||
|
|
||||||
|
private const val EXTRA_TAB_INDEX = "tabIndex"
|
||||||
|
|
||||||
|
fun starter(context: Context, tabIndex: Int): Intent {
|
||||||
|
return Intent(context, MainActivity::class.java).apply {
|
||||||
|
putExtra(EXTRA_TAB_INDEX, tabIndex)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,83 @@
|
|||||||
|
package pt.whatsms.gateway.data
|
||||||
|
|
||||||
|
import androidx.room.AutoMigration
|
||||||
|
import androidx.room.Database
|
||||||
|
import androidx.room.Room
|
||||||
|
import androidx.room.RoomDatabase
|
||||||
|
import androidx.room.TypeConverters
|
||||||
|
import pt.whatsms.gateway.data.dao.MessagesDao
|
||||||
|
import pt.whatsms.gateway.data.dao.TokensDao
|
||||||
|
import pt.whatsms.gateway.data.entities.Message
|
||||||
|
import pt.whatsms.gateway.data.entities.MessageRecipient
|
||||||
|
import pt.whatsms.gateway.data.entities.MessageState
|
||||||
|
import pt.whatsms.gateway.data.entities.RecipientState
|
||||||
|
import pt.whatsms.gateway.data.entities.Token
|
||||||
|
import pt.whatsms.gateway.modules.incoming.db.IncomingMessage
|
||||||
|
import pt.whatsms.gateway.modules.incoming.db.IncomingMessagesDao
|
||||||
|
import pt.whatsms.gateway.modules.logs.db.LogEntriesDao
|
||||||
|
import pt.whatsms.gateway.modules.logs.db.LogEntry
|
||||||
|
import pt.whatsms.gateway.modules.webhooks.db.WebHook
|
||||||
|
import pt.whatsms.gateway.modules.webhooks.db.WebHooksDao
|
||||||
|
import pt.whatsms.gateway.modules.webhooks.db.WebhookQueueDao
|
||||||
|
import pt.whatsms.gateway.modules.webhooks.db.WebhookQueueEntity
|
||||||
|
|
||||||
|
@Database(
|
||||||
|
entities = [
|
||||||
|
Message::class,
|
||||||
|
MessageRecipient::class,
|
||||||
|
RecipientState::class,
|
||||||
|
MessageState::class,
|
||||||
|
WebHook::class,
|
||||||
|
WebhookQueueEntity::class,
|
||||||
|
LogEntry::class,
|
||||||
|
Token::class,
|
||||||
|
IncomingMessage::class,
|
||||||
|
],
|
||||||
|
version = 20,
|
||||||
|
autoMigrations = [
|
||||||
|
AutoMigration(from = 1, to = 2),
|
||||||
|
AutoMigration(from = 2, to = 3),
|
||||||
|
AutoMigration(from = 3, to = 4),
|
||||||
|
AutoMigration(from = 4, to = 5),
|
||||||
|
AutoMigration(from = 5, to = 6),
|
||||||
|
AutoMigration(from = 6, to = 7),
|
||||||
|
// AutoMigration(from = 7, to = 8), // manual migration
|
||||||
|
AutoMigration(from = 8, to = 9),
|
||||||
|
AutoMigration(from = 9, to = 10),
|
||||||
|
AutoMigration(from = 10, to = 11),
|
||||||
|
AutoMigration(from = 11, to = 12),
|
||||||
|
AutoMigration(from = 12, to = 13),
|
||||||
|
// AutoMigration(from = 13, to = 14), // manual migration
|
||||||
|
AutoMigration(from = 14, to = 15),
|
||||||
|
AutoMigration(from = 15, to = 16),
|
||||||
|
AutoMigration(from = 16, to = 17),
|
||||||
|
AutoMigration(from = 17, to = 18),
|
||||||
|
AutoMigration(from = 18, to = 19),
|
||||||
|
AutoMigration(from = 19, to = 20),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
@TypeConverters(Converters::class)
|
||||||
|
abstract class AppDatabase : RoomDatabase() {
|
||||||
|
abstract fun messagesDao(): MessagesDao
|
||||||
|
abstract fun webhooksDao(): WebHooksDao
|
||||||
|
abstract fun webhookQueueDao(): WebhookQueueDao
|
||||||
|
abstract fun logDao(): LogEntriesDao
|
||||||
|
abstract fun incomingMessagesDao(): IncomingMessagesDao
|
||||||
|
abstract fun tokensDao(): TokensDao
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
fun getDatabase(context: android.content.Context): AppDatabase {
|
||||||
|
return Room.databaseBuilder(
|
||||||
|
context,
|
||||||
|
AppDatabase::class.java,
|
||||||
|
"gateway"
|
||||||
|
)
|
||||||
|
.addMigrations(
|
||||||
|
MIGRATION_7_8,
|
||||||
|
MIGRATION_13_14,
|
||||||
|
)
|
||||||
|
.allowMainThreadQueries()
|
||||||
|
.build()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
package pt.whatsms.gateway.data
|
||||||
|
|
||||||
|
import androidx.room.TypeConverter
|
||||||
|
import com.google.gson.GsonBuilder
|
||||||
|
import com.google.gson.JsonElement
|
||||||
|
import java.text.SimpleDateFormat
|
||||||
|
import java.util.Date
|
||||||
|
import java.util.Locale
|
||||||
|
import java.util.TimeZone
|
||||||
|
|
||||||
|
class Converters {
|
||||||
|
private val gson = GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").create()
|
||||||
|
|
||||||
|
@TypeConverter
|
||||||
|
fun listToString(value: List<String>?): String? {
|
||||||
|
return value?.let { gson.toJson(it) }
|
||||||
|
}
|
||||||
|
|
||||||
|
@TypeConverter
|
||||||
|
fun listFromString(value: String?): List<String>? {
|
||||||
|
return value?.let { gson.fromJson(it, Array<String>::class.java).toList() }
|
||||||
|
}
|
||||||
|
|
||||||
|
@TypeConverter
|
||||||
|
fun dateToString(value: Date?): String? {
|
||||||
|
return value?.let { DATE_FORMAT.format(it) }
|
||||||
|
}
|
||||||
|
|
||||||
|
@TypeConverter
|
||||||
|
fun dateFromString(value: String?): Date? {
|
||||||
|
return value?.let { DATE_FORMAT.parse(it) }
|
||||||
|
}
|
||||||
|
|
||||||
|
@TypeConverter
|
||||||
|
fun jsonToString(value: JsonElement?): String? {
|
||||||
|
return value?.let { gson.toJson(it) }
|
||||||
|
}
|
||||||
|
|
||||||
|
@TypeConverter
|
||||||
|
fun stringToJson(value: String?): JsonElement? {
|
||||||
|
return value?.let { gson.fromJson(it, JsonElement::class.java) }
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private val DATE_FORMAT =
|
||||||
|
SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.US).apply {
|
||||||
|
timeZone = TimeZone.getTimeZone("GMT")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,86 @@
|
|||||||
|
package pt.whatsms.gateway.data
|
||||||
|
|
||||||
|
import androidx.room.migration.Migration
|
||||||
|
import androidx.sqlite.db.SupportSQLiteDatabase
|
||||||
|
|
||||||
|
val MIGRATION_7_8 = object : Migration(7, 8) {
|
||||||
|
override fun migrate(database: SupportSQLiteDatabase) {
|
||||||
|
database.execSQL(
|
||||||
|
"""
|
||||||
|
UPDATE message
|
||||||
|
SET validUntil = strftime('%FT%TZ', createdAt / 1000 + 86400, 'unixepoch')
|
||||||
|
WHERE validUntil IS NULL AND state = 'Pending'
|
||||||
|
""".trimIndent()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val MIGRATION_13_14 = object : Migration(13, 14) {
|
||||||
|
override fun migrate(database: SupportSQLiteDatabase) {
|
||||||
|
// Create a new table with the desired schema (without the text column)
|
||||||
|
database.execSQL(
|
||||||
|
"""
|
||||||
|
CREATE TABLE IF NOT EXISTS message_new (
|
||||||
|
`id` TEXT NOT NULL,
|
||||||
|
`withDeliveryReport` INTEGER NOT NULL DEFAULT 1,
|
||||||
|
`simNumber` INTEGER,
|
||||||
|
`validUntil` TEXT,
|
||||||
|
`isEncrypted` INTEGER NOT NULL DEFAULT 0,
|
||||||
|
`skipPhoneValidation` INTEGER NOT NULL DEFAULT 0,
|
||||||
|
`priority` INTEGER NOT NULL DEFAULT 0,
|
||||||
|
`type` TEXT NOT NULL DEFAULT 'Text',
|
||||||
|
`source` TEXT NOT NULL DEFAULT 'Local',
|
||||||
|
`content` TEXT NOT NULL,
|
||||||
|
`state` TEXT NOT NULL,
|
||||||
|
`createdAt` INTEGER NOT NULL DEFAULT 0,
|
||||||
|
`processedAt` INTEGER,
|
||||||
|
PRIMARY KEY(`id`)
|
||||||
|
)
|
||||||
|
""".trimIndent()
|
||||||
|
)
|
||||||
|
|
||||||
|
// Copy data from the old table to the new table
|
||||||
|
database.execSQL(
|
||||||
|
"""
|
||||||
|
INSERT INTO message_new (
|
||||||
|
id,
|
||||||
|
withDeliveryReport,
|
||||||
|
simNumber,
|
||||||
|
validUntil,
|
||||||
|
isEncrypted,
|
||||||
|
skipPhoneValidation,
|
||||||
|
priority,
|
||||||
|
source,
|
||||||
|
type,
|
||||||
|
content,
|
||||||
|
state,
|
||||||
|
createdAt,
|
||||||
|
processedAt
|
||||||
|
) SELECT
|
||||||
|
id,
|
||||||
|
withDeliveryReport,
|
||||||
|
simNumber,
|
||||||
|
validUntil,
|
||||||
|
isEncrypted,
|
||||||
|
skipPhoneValidation,
|
||||||
|
priority,
|
||||||
|
source,
|
||||||
|
'Text' AS type,
|
||||||
|
'{"text": "' || replace(replace(text, '\\', '\\\\'), '"', '\\"') || '"}' AS content,
|
||||||
|
state,
|
||||||
|
createdAt,
|
||||||
|
processedAt
|
||||||
|
FROM message
|
||||||
|
""".trimIndent()
|
||||||
|
)
|
||||||
|
|
||||||
|
// Drop the old table and rename the new table to the original name
|
||||||
|
database.execSQL("DROP TABLE IF EXISTS message")
|
||||||
|
database.execSQL("ALTER TABLE message_new RENAME TO message")
|
||||||
|
|
||||||
|
// Create indices
|
||||||
|
database.execSQL("CREATE INDEX IF NOT EXISTS index_Message_state ON message (state)")
|
||||||
|
database.execSQL("CREATE INDEX IF NOT EXISTS index_Message_createdAt ON message (createdAt)")
|
||||||
|
database.execSQL("CREATE INDEX IF NOT EXISTS index_Message_processedAt ON message (processedAt)")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package pt.whatsms.gateway.data
|
||||||
|
|
||||||
|
import org.koin.dsl.module
|
||||||
|
|
||||||
|
val dbModule = module {
|
||||||
|
single { AppDatabase.getDatabase(get()) }
|
||||||
|
single { get<AppDatabase>().messagesDao() }
|
||||||
|
single { get<AppDatabase>().incomingMessagesDao() }
|
||||||
|
single { get<AppDatabase>().webhooksDao() }
|
||||||
|
single { get<AppDatabase>().webhookQueueDao() }
|
||||||
|
single { get<AppDatabase>().logDao() }
|
||||||
|
single { get<AppDatabase>().tokensDao() }
|
||||||
|
}
|
||||||
@@ -0,0 +1,205 @@
|
|||||||
|
package pt.whatsms.gateway.data.dao
|
||||||
|
|
||||||
|
import androidx.lifecycle.LiveData
|
||||||
|
import androidx.room.Dao
|
||||||
|
import androidx.room.Insert
|
||||||
|
import androidx.room.OnConflictStrategy
|
||||||
|
import androidx.room.Query
|
||||||
|
import androidx.room.Transaction
|
||||||
|
import pt.whatsms.gateway.data.entities.Message
|
||||||
|
import pt.whatsms.gateway.data.entities.MessageRecipient
|
||||||
|
import pt.whatsms.gateway.data.entities.MessageState
|
||||||
|
import pt.whatsms.gateway.data.entities.MessageWithRecipients
|
||||||
|
import pt.whatsms.gateway.data.entities.MessagesStats
|
||||||
|
import pt.whatsms.gateway.data.entities.MessagesTotals
|
||||||
|
import pt.whatsms.gateway.data.entities.RecipientState
|
||||||
|
import pt.whatsms.gateway.domain.EntitySource
|
||||||
|
import pt.whatsms.gateway.domain.ProcessingState
|
||||||
|
|
||||||
|
@Dao
|
||||||
|
interface MessagesDao {
|
||||||
|
//#region Read
|
||||||
|
@Query("SELECT COUNT(*) as count, MAX(processedAt) as lastTimestamp FROM message WHERE state <> 'Pending' AND state <> 'Failed' AND processedAt >= :timestamp")
|
||||||
|
fun countProcessedFrom(timestamp: Long): MessagesStats
|
||||||
|
|
||||||
|
@Query("SELECT COUNT(*) as count, MAX(processedAt) as lastTimestamp FROM message WHERE state = 'Failed' AND processedAt >= :timestamp")
|
||||||
|
fun countFailedFrom(timestamp: Long): MessagesStats
|
||||||
|
|
||||||
|
@Query(
|
||||||
|
"""
|
||||||
|
SELECT
|
||||||
|
COUNT(*) as total,
|
||||||
|
COALESCE(SUM(CASE WHEN state = 'Pending' THEN 1 ELSE 0 END), 0) as pending,
|
||||||
|
COALESCE(SUM(CASE WHEN state = 'Sent' THEN 1 ELSE 0 END), 0) as sent,
|
||||||
|
COALESCE(SUM(CASE WHEN state = 'Delivered' THEN 1 ELSE 0 END), 0) as delivered,
|
||||||
|
COALESCE(SUM(CASE WHEN state = 'Failed' THEN 1 ELSE 0 END), 0) as failed
|
||||||
|
FROM message
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
fun getMessagesStats(): LiveData<MessagesTotals>
|
||||||
|
|
||||||
|
@Query("SELECT * FROM message ORDER BY createdAt DESC LIMIT :limit")
|
||||||
|
fun selectLast(limit: Int): LiveData<List<Message>>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* FIFO: oldest pending first (priority DESC, createdAt ASC)
|
||||||
|
*/
|
||||||
|
@Transaction
|
||||||
|
@Query("SELECT *, `rowid` FROM message WHERE state = 'Pending' ORDER BY priority DESC, createdAt ASC LIMIT 1")
|
||||||
|
fun getPendingFifo(): MessageWithRecipients?
|
||||||
|
|
||||||
|
/**
|
||||||
|
* LIFO: newest pending first (priority DESC, createdAt DESC)
|
||||||
|
*/
|
||||||
|
@Transaction
|
||||||
|
@Query("SELECT *, `rowid` FROM message WHERE state = 'Pending' ORDER BY priority DESC, createdAt DESC LIMIT 1")
|
||||||
|
fun getPendingLifo(): MessageWithRecipients?
|
||||||
|
|
||||||
|
@Transaction
|
||||||
|
@Query("SELECT *, `rowid` FROM message WHERE id = :id")
|
||||||
|
fun get(id: String): MessageWithRecipients?
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Count messages based on state and date range
|
||||||
|
*/
|
||||||
|
@Query("SELECT COUNT(*) as count FROM message WHERE source = :source AND (:state IS NULL OR state = :state) AND createdAt BETWEEN :start AND :end")
|
||||||
|
fun count(source: EntitySource, state: ProcessingState?, start: Long, end: Long): Int
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get messages with pagination and filtering
|
||||||
|
*/
|
||||||
|
@Transaction
|
||||||
|
@Query("SELECT *, `rowid` FROM message WHERE source = :source AND (:state IS NULL OR state = :state) AND createdAt BETWEEN :start AND :end ORDER BY createdAt DESC LIMIT :limit OFFSET :offset")
|
||||||
|
fun select(
|
||||||
|
source: EntitySource,
|
||||||
|
state: ProcessingState?,
|
||||||
|
start: Long,
|
||||||
|
end: Long,
|
||||||
|
limit: Int,
|
||||||
|
offset: Int
|
||||||
|
): List<MessageWithRecipients>
|
||||||
|
//#endregion
|
||||||
|
|
||||||
|
@Insert
|
||||||
|
fun _insert(message: Message)
|
||||||
|
|
||||||
|
@Insert
|
||||||
|
fun _insertRecipients(recipient: List<MessageRecipient>)
|
||||||
|
|
||||||
|
@Insert(onConflict = OnConflictStrategy.IGNORE)
|
||||||
|
fun _insertMessageState(state: MessageState)
|
||||||
|
|
||||||
|
@Insert(onConflict = OnConflictStrategy.IGNORE)
|
||||||
|
fun _insertRecipientStates(state: List<RecipientState>)
|
||||||
|
|
||||||
|
@Query(
|
||||||
|
"INSERT INTO recipientstate(messageId, phoneNumber, state, updatedAt) " +
|
||||||
|
"SELECT :messageId, phoneNumber, :state, strftime('%s', 'now') * 1000 " +
|
||||||
|
"FROM messagerecipient " +
|
||||||
|
"WHERE messageId = :messageId"
|
||||||
|
)
|
||||||
|
fun _insertRecipientStatesByMessage(
|
||||||
|
messageId: String,
|
||||||
|
state: pt.whatsms.gateway.domain.ProcessingState
|
||||||
|
)
|
||||||
|
|
||||||
|
@Transaction
|
||||||
|
fun insert(message: MessageWithRecipients) {
|
||||||
|
_insert(message.message)
|
||||||
|
_insertMessageState(
|
||||||
|
MessageState(
|
||||||
|
message.message.id,
|
||||||
|
message.message.state,
|
||||||
|
System.currentTimeMillis()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
_insertRecipients(message.recipients)
|
||||||
|
_insertRecipientStates(message.recipients.map {
|
||||||
|
RecipientState(
|
||||||
|
message.message.id,
|
||||||
|
it.phoneNumber,
|
||||||
|
it.state,
|
||||||
|
System.currentTimeMillis()
|
||||||
|
)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
@Query("UPDATE message SET state = :state WHERE id = :id AND state <> 'Failed'")
|
||||||
|
fun _updateMessageState(id: String, state: pt.whatsms.gateway.domain.ProcessingState)
|
||||||
|
|
||||||
|
fun updateMessageState(id: String, state: pt.whatsms.gateway.domain.ProcessingState) {
|
||||||
|
_updateMessageState(id, state)
|
||||||
|
_insertMessageState(
|
||||||
|
MessageState(
|
||||||
|
id,
|
||||||
|
state,
|
||||||
|
System.currentTimeMillis()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Query("UPDATE message SET state = 'Processed', processedAt = strftime('%s', 'now') * 1000 WHERE id = :id")
|
||||||
|
fun _setMessageProcessed(id: String)
|
||||||
|
fun setMessageProcessed(id: String) {
|
||||||
|
_setMessageProcessed(id)
|
||||||
|
_insertMessageState(
|
||||||
|
MessageState(
|
||||||
|
id,
|
||||||
|
pt.whatsms.gateway.domain.ProcessingState.Processed,
|
||||||
|
System.currentTimeMillis()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Query("UPDATE messagerecipient SET state = :state, error = :error WHERE messageId = :id AND phoneNumber = :phoneNumber AND state <> 'Failed'")
|
||||||
|
fun _updateRecipientState(
|
||||||
|
id: String,
|
||||||
|
phoneNumber: String,
|
||||||
|
state: pt.whatsms.gateway.domain.ProcessingState,
|
||||||
|
error: String?
|
||||||
|
)
|
||||||
|
|
||||||
|
@Transaction
|
||||||
|
fun updateRecipientState(
|
||||||
|
id: String,
|
||||||
|
phoneNumber: String,
|
||||||
|
state: pt.whatsms.gateway.domain.ProcessingState,
|
||||||
|
error: String?
|
||||||
|
) {
|
||||||
|
_updateRecipientState(id, phoneNumber, state, error)
|
||||||
|
_insertRecipientStates(
|
||||||
|
listOf(
|
||||||
|
RecipientState(id, phoneNumber, state, System.currentTimeMillis())
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Query("UPDATE messagerecipient SET state = :state, error = :error WHERE messageId = :id AND state <> 'Failed'")
|
||||||
|
fun _updateRecipientsState(
|
||||||
|
id: String,
|
||||||
|
state: pt.whatsms.gateway.domain.ProcessingState,
|
||||||
|
error: String?
|
||||||
|
)
|
||||||
|
|
||||||
|
@Transaction
|
||||||
|
fun updateRecipientsState(
|
||||||
|
id: String,
|
||||||
|
state: pt.whatsms.gateway.domain.ProcessingState,
|
||||||
|
error: String?
|
||||||
|
) {
|
||||||
|
_updateRecipientsState(id, state, error)
|
||||||
|
_insertRecipientStatesByMessage(id, state)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Query("UPDATE message SET simNumber = :simNumber WHERE id = :id")
|
||||||
|
fun updateSimNumber(
|
||||||
|
id: String,
|
||||||
|
simNumber: Int
|
||||||
|
)
|
||||||
|
|
||||||
|
@Query("UPDATE message SET partsCount = :partsCount WHERE id = :id")
|
||||||
|
fun updatePartsCount(id: String, partsCount: Int)
|
||||||
|
|
||||||
|
@Query("DELETE FROM message WHERE createdAt < :until AND state <> 'Pending'")
|
||||||
|
suspend fun truncateLog(until: Long)
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package pt.whatsms.gateway.data.dao
|
||||||
|
|
||||||
|
import androidx.room.Dao
|
||||||
|
import androidx.room.Insert
|
||||||
|
import androidx.room.OnConflictStrategy
|
||||||
|
import androidx.room.Query
|
||||||
|
import pt.whatsms.gateway.data.entities.Token
|
||||||
|
|
||||||
|
@Dao
|
||||||
|
interface TokensDao {
|
||||||
|
@Insert(onConflict = OnConflictStrategy.IGNORE)
|
||||||
|
suspend fun insert(token: Token): Long
|
||||||
|
|
||||||
|
@Query("UPDATE tokens SET revokedAt = strftime('%s', 'now') * 1000 WHERE id = :id")
|
||||||
|
suspend fun revoke(id: String)
|
||||||
|
|
||||||
|
@Query("SELECT EXISTS (SELECT 1 FROM tokens WHERE id = :id AND revokedAt IS NOT NULL)")
|
||||||
|
suspend fun isRevoked(id: String): Boolean
|
||||||
|
|
||||||
|
@Query("DELETE FROM tokens WHERE expiresAt < strftime('%s', 'now') * 1000")
|
||||||
|
suspend fun cleanup()
|
||||||
|
}
|
||||||
@@ -0,0 +1,102 @@
|
|||||||
|
package pt.whatsms.gateway.data.entities
|
||||||
|
|
||||||
|
import androidx.room.ColumnInfo
|
||||||
|
import androidx.room.Entity
|
||||||
|
import androidx.room.PrimaryKey
|
||||||
|
import com.google.gson.Gson
|
||||||
|
import pt.whatsms.gateway.domain.EntitySource
|
||||||
|
import pt.whatsms.gateway.domain.MessageContent
|
||||||
|
import pt.whatsms.gateway.domain.ProcessingState
|
||||||
|
import java.util.Date
|
||||||
|
|
||||||
|
enum class MessageType {
|
||||||
|
Text,
|
||||||
|
Data,
|
||||||
|
}
|
||||||
|
|
||||||
|
@Entity(
|
||||||
|
indices = [
|
||||||
|
androidx.room.Index(value = ["createdAt"]),
|
||||||
|
androidx.room.Index(value = ["state", "processedAt"]),
|
||||||
|
androidx.room.Index(value = ["state", "createdAt"]),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
data class Message constructor(
|
||||||
|
@PrimaryKey val id: String,
|
||||||
|
|
||||||
|
@ColumnInfo(defaultValue = "1")
|
||||||
|
val withDeliveryReport: Boolean,
|
||||||
|
val simNumber: Int?,
|
||||||
|
val validUntil: Date?,
|
||||||
|
@ColumnInfo(defaultValue = "0")
|
||||||
|
val isEncrypted: Boolean,
|
||||||
|
@ColumnInfo(defaultValue = "0")
|
||||||
|
val skipPhoneValidation: Boolean,
|
||||||
|
@ColumnInfo(defaultValue = "0")
|
||||||
|
val priority: Byte,
|
||||||
|
|
||||||
|
@ColumnInfo(defaultValue = "Local")
|
||||||
|
val source: EntitySource,
|
||||||
|
|
||||||
|
@ColumnInfo(defaultValue = "Text")
|
||||||
|
val type: MessageType = MessageType.Text,
|
||||||
|
|
||||||
|
val content: String,
|
||||||
|
|
||||||
|
val state: ProcessingState = ProcessingState.Pending,
|
||||||
|
val partsCount: Int? = null,
|
||||||
|
@ColumnInfo(defaultValue = "0")
|
||||||
|
val createdAt: Long = System.currentTimeMillis(),
|
||||||
|
val processedAt: Long? = null,
|
||||||
|
) {
|
||||||
|
constructor(
|
||||||
|
id: String,
|
||||||
|
withDeliveryReport: Boolean,
|
||||||
|
simNumber: Int?,
|
||||||
|
validUntil: Date?,
|
||||||
|
isEncrypted: Boolean,
|
||||||
|
skipPhoneValidation: Boolean,
|
||||||
|
priority: Byte,
|
||||||
|
source: EntitySource,
|
||||||
|
|
||||||
|
content: MessageContent,
|
||||||
|
|
||||||
|
createdAt: Long,
|
||||||
|
) : this(
|
||||||
|
id,
|
||||||
|
withDeliveryReport,
|
||||||
|
simNumber,
|
||||||
|
validUntil,
|
||||||
|
isEncrypted,
|
||||||
|
skipPhoneValidation,
|
||||||
|
priority,
|
||||||
|
source,
|
||||||
|
|
||||||
|
content = gson.toJson(content),
|
||||||
|
type = when (content) {
|
||||||
|
is MessageContent.Text -> MessageType.Text
|
||||||
|
is MessageContent.Data -> MessageType.Data
|
||||||
|
},
|
||||||
|
createdAt = createdAt,
|
||||||
|
)
|
||||||
|
|
||||||
|
val textContent: MessageContent.Text?
|
||||||
|
get() = when (type) {
|
||||||
|
MessageType.Text -> gson.fromJson(content, MessageContent.Text::class.java)
|
||||||
|
else -> null
|
||||||
|
}
|
||||||
|
|
||||||
|
val dataContent: MessageContent.Data?
|
||||||
|
get() = when (type) {
|
||||||
|
MessageType.Data -> gson.fromJson(content, MessageContent.Data::class.java)
|
||||||
|
else -> null
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
const val PRIORITY_MIN: Byte = Byte.MIN_VALUE
|
||||||
|
const val PRIORITY_DEFAULT: Byte = 0
|
||||||
|
const val PRIORITY_EXPEDITED: Byte = 100
|
||||||
|
|
||||||
|
private val gson = Gson()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package pt.whatsms.gateway.data.entities
|
||||||
|
|
||||||
|
import androidx.room.Entity
|
||||||
|
import androidx.room.ForeignKey
|
||||||
|
|
||||||
|
@Entity(
|
||||||
|
primaryKeys = ["messageId", "phoneNumber"],
|
||||||
|
foreignKeys = [
|
||||||
|
ForeignKey(entity = Message::class, parentColumns = ["id"], childColumns = ["messageId"], onDelete = ForeignKey.CASCADE)
|
||||||
|
]
|
||||||
|
)
|
||||||
|
data class MessageRecipient(
|
||||||
|
val messageId: String,
|
||||||
|
val phoneNumber: String,
|
||||||
|
val state: pt.whatsms.gateway.domain.ProcessingState = pt.whatsms.gateway.domain.ProcessingState.Pending,
|
||||||
|
val error: String? = null
|
||||||
|
)
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package pt.whatsms.gateway.data.entities
|
||||||
|
|
||||||
|
import androidx.room.Entity
|
||||||
|
import androidx.room.ForeignKey
|
||||||
|
|
||||||
|
@Entity(
|
||||||
|
primaryKeys = ["messageId", "state"],
|
||||||
|
foreignKeys = [
|
||||||
|
ForeignKey(
|
||||||
|
entity = Message::class,
|
||||||
|
parentColumns = ["id"],
|
||||||
|
childColumns = ["messageId"],
|
||||||
|
onDelete = ForeignKey.CASCADE
|
||||||
|
)
|
||||||
|
]
|
||||||
|
)
|
||||||
|
data class MessageState(
|
||||||
|
val messageId: String,
|
||||||
|
val state: pt.whatsms.gateway.domain.ProcessingState,
|
||||||
|
val updatedAt: Long
|
||||||
|
)
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package pt.whatsms.gateway.data.entities
|
||||||
|
|
||||||
|
import androidx.room.ColumnInfo
|
||||||
|
import androidx.room.Embedded
|
||||||
|
import androidx.room.Relation
|
||||||
|
|
||||||
|
data class MessageWithRecipients(
|
||||||
|
@Embedded val message: Message,
|
||||||
|
@Relation(
|
||||||
|
parentColumn = "id",
|
||||||
|
entityColumn = "messageId",
|
||||||
|
)
|
||||||
|
val recipients: List<MessageRecipient>,
|
||||||
|
@Relation(
|
||||||
|
parentColumn = "id",
|
||||||
|
entityColumn = "messageId",
|
||||||
|
)
|
||||||
|
val states: List<MessageState> = emptyList(),
|
||||||
|
@ColumnInfo(name = "rowid")
|
||||||
|
val rowId: Long = 0,
|
||||||
|
) {
|
||||||
|
val state: pt.whatsms.gateway.domain.ProcessingState
|
||||||
|
get() = when {
|
||||||
|
recipients.any { it.state == pt.whatsms.gateway.domain.ProcessingState.Pending } -> pt.whatsms.gateway.domain.ProcessingState.Pending
|
||||||
|
recipients.any { it.state == pt.whatsms.gateway.domain.ProcessingState.Processed } -> pt.whatsms.gateway.domain.ProcessingState.Processed
|
||||||
|
|
||||||
|
recipients.all { it.state == pt.whatsms.gateway.domain.ProcessingState.Failed } -> pt.whatsms.gateway.domain.ProcessingState.Failed
|
||||||
|
recipients.all { it.state == pt.whatsms.gateway.domain.ProcessingState.Delivered } -> pt.whatsms.gateway.domain.ProcessingState.Delivered
|
||||||
|
else -> pt.whatsms.gateway.domain.ProcessingState.Sent
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
package pt.whatsms.gateway.data.entities
|
||||||
|
|
||||||
|
data class MessagesStats(
|
||||||
|
val count: Int,
|
||||||
|
val lastTimestamp: Long
|
||||||
|
)
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package pt.whatsms.gateway.data.entities
|
||||||
|
|
||||||
|
data class MessagesTotals(
|
||||||
|
val total: Long,
|
||||||
|
val pending: Long,
|
||||||
|
val sent: Long,
|
||||||
|
val delivered: Long,
|
||||||
|
val failed: Long,
|
||||||
|
)
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package pt.whatsms.gateway.data.entities
|
||||||
|
|
||||||
|
import androidx.room.Entity
|
||||||
|
import androidx.room.ForeignKey
|
||||||
|
|
||||||
|
@Entity(
|
||||||
|
primaryKeys = ["messageId", "phoneNumber", "state"],
|
||||||
|
foreignKeys = [
|
||||||
|
ForeignKey(
|
||||||
|
entity = MessageRecipient::class,
|
||||||
|
parentColumns = ["messageId", "phoneNumber"],
|
||||||
|
childColumns = ["messageId", "phoneNumber"],
|
||||||
|
onDelete = ForeignKey.CASCADE
|
||||||
|
)
|
||||||
|
]
|
||||||
|
)
|
||||||
|
data class RecipientState(
|
||||||
|
val messageId: String,
|
||||||
|
val phoneNumber: String,
|
||||||
|
val state: pt.whatsms.gateway.domain.ProcessingState,
|
||||||
|
val updatedAt: Long
|
||||||
|
)
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package pt.whatsms.gateway.data.entities
|
||||||
|
|
||||||
|
import androidx.room.Entity
|
||||||
|
import androidx.room.Index
|
||||||
|
import androidx.room.PrimaryKey
|
||||||
|
|
||||||
|
@Entity(
|
||||||
|
tableName = "tokens",
|
||||||
|
indices = [
|
||||||
|
Index("expiresAt")
|
||||||
|
],
|
||||||
|
)
|
||||||
|
data class Token(
|
||||||
|
@PrimaryKey
|
||||||
|
val id: String,
|
||||||
|
val expiresAt: Long,
|
||||||
|
val revokedAt: Long? = null,
|
||||||
|
)
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package pt.whatsms.gateway.domain
|
||||||
|
|
||||||
|
enum class EntitySource {
|
||||||
|
Local,
|
||||||
|
Cloud,
|
||||||
|
|
||||||
|
@Deprecated("Not used anymore")
|
||||||
|
Gateway,
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package pt.whatsms.gateway.domain
|
||||||
|
|
||||||
|
import pt.whatsms.gateway.BuildConfig
|
||||||
|
import pt.whatsms.gateway.modules.health.domain.CheckResult
|
||||||
|
import pt.whatsms.gateway.modules.health.domain.HealthResult
|
||||||
|
import pt.whatsms.gateway.modules.health.domain.Status
|
||||||
|
|
||||||
|
class HealthResponse(
|
||||||
|
healthResult: HealthResult,
|
||||||
|
|
||||||
|
val version: String = BuildConfig.VERSION_NAME,
|
||||||
|
val releaseId: Int = BuildConfig.VERSION_CODE,
|
||||||
|
) {
|
||||||
|
val status: Status = healthResult.status
|
||||||
|
val checks: Map<String, CheckResult> = healthResult.checks
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package pt.whatsms.gateway.domain
|
||||||
|
|
||||||
|
sealed class MessageContent {
|
||||||
|
data class Text(val text: String) : MessageContent() {
|
||||||
|
override fun toString(): String {
|
||||||
|
return text
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
data class Data(val data: String, val port: UShort) : MessageContent() {
|
||||||
|
override fun toString(): String {
|
||||||
|
return "$data:$port"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package pt.whatsms.gateway.domain
|
||||||
|
|
||||||
|
enum class ProcessingState {
|
||||||
|
Pending,
|
||||||
|
Processed,
|
||||||
|
Sent,
|
||||||
|
Delivered,
|
||||||
|
Failed
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package pt.whatsms.gateway.extensions
|
||||||
|
|
||||||
|
import android.os.Build
|
||||||
|
import com.google.gson.GsonBuilder
|
||||||
|
import java.util.TimeZone
|
||||||
|
|
||||||
|
fun GsonBuilder.configure(): GsonBuilder {
|
||||||
|
return this.setDateFormatISO8601()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun GsonBuilder.setDateFormatISO8601(): GsonBuilder {
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||||
|
this.setDateFormat(
|
||||||
|
"yyyy-MM-dd'T'HH:mm:ss.SSSXXX"
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
//get device timezone
|
||||||
|
val timeZone = TimeZone.getDefault()
|
||||||
|
this.setDateFormat(
|
||||||
|
"yyyy-MM-dd'T'HH:mm:ss.SSS" + when (timeZone.rawOffset) {
|
||||||
|
0 -> "Z"
|
||||||
|
else -> "+" + (timeZone.rawOffset / 3600000).toString().padStart(
|
||||||
|
2,
|
||||||
|
'0'
|
||||||
|
) + ":" + ((timeZone.rawOffset % 3600000) / 60000).toString()
|
||||||
|
.padStart(2, '0')
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return this
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package pt.whatsms.gateway.helpers
|
||||||
|
|
||||||
|
import pt.whatsms.gateway.BuildConfig
|
||||||
|
|
||||||
|
object BuildHelper {
|
||||||
|
val isInsecureVersion =
|
||||||
|
BuildConfig.BUILD_TYPE == "insecure" || BuildConfig.BUILD_TYPE == "debugInsecure"
|
||||||
|
}
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
package pt.whatsms.gateway.helpers
|
||||||
|
|
||||||
|
import android.os.Build
|
||||||
|
import java.text.ParseException
|
||||||
|
import java.text.SimpleDateFormat
|
||||||
|
import java.util.Date
|
||||||
|
import java.util.Locale
|
||||||
|
import java.util.TimeZone
|
||||||
|
|
||||||
|
object DateTimeParser {
|
||||||
|
fun parseIsoDateTime(input: String): Date? {
|
||||||
|
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
|
parseModern(input)
|
||||||
|
} else {
|
||||||
|
parseLegacy(input)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Suppress("NewApi")
|
||||||
|
private fun parseModern(input: String): Date? {
|
||||||
|
return try {
|
||||||
|
// Pattern handles both with/without milliseconds
|
||||||
|
val formatter = java.time.format.DateTimeFormatter.ofPattern(
|
||||||
|
"yyyy-MM-dd'T'HH:mm:ss[.SSS]XXX"
|
||||||
|
)
|
||||||
|
val offsetDateTime = java.time.OffsetDateTime.parse(input, formatter)
|
||||||
|
Date.from(offsetDateTime.toInstant())
|
||||||
|
} catch (e: Exception) {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun parseLegacy(input: String): Date? {
|
||||||
|
// Try patterns in order of specificity
|
||||||
|
val patterns = arrayOf(
|
||||||
|
"yyyy-MM-dd'T'HH:mm:ss.SSSXXX", // With milliseconds
|
||||||
|
"yyyy-MM-dd'T'HH:mm:ssXXX" // Without milliseconds
|
||||||
|
)
|
||||||
|
|
||||||
|
for (pattern in patterns) {
|
||||||
|
try {
|
||||||
|
val sdf = SimpleDateFormat(pattern, Locale.US).apply {
|
||||||
|
timeZone = TimeZone.getTimeZone("UTC")
|
||||||
|
}
|
||||||
|
return sdf.parse(input)
|
||||||
|
} catch (e: ParseException) {
|
||||||
|
// Try next pattern
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package pt.whatsms.gateway.helpers
|
||||||
|
|
||||||
|
import com.google.i18n.phonenumbers.PhoneNumberUtil
|
||||||
|
|
||||||
|
object PhoneHelper {
|
||||||
|
fun filterPhoneNumber(phoneNumber: String, countryCode: String): String {
|
||||||
|
val phoneUtil = PhoneNumberUtil.getInstance()
|
||||||
|
val number = phoneUtil.parse(phoneNumber, countryCode.uppercase())
|
||||||
|
if (!phoneUtil.isValidNumber(number)) {
|
||||||
|
throw RuntimeException("Invalid phone number")
|
||||||
|
}
|
||||||
|
if (phoneUtil.getNumberType(number) != PhoneNumberUtil.PhoneNumberType.MOBILE
|
||||||
|
&& phoneUtil.getNumberType(number) != PhoneNumberUtil.PhoneNumberType.FIXED_LINE_OR_MOBILE
|
||||||
|
) {
|
||||||
|
throw RuntimeException("Invalid phone number type")
|
||||||
|
}
|
||||||
|
return phoneUtil.format(number, PhoneNumberUtil.PhoneNumberFormat.E164)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,123 @@
|
|||||||
|
package pt.whatsms.gateway.helpers
|
||||||
|
|
||||||
|
import android.util.Log
|
||||||
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.Job
|
||||||
|
import kotlinx.coroutines.cancelChildren
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import okhttp3.OkHttpClient
|
||||||
|
import okhttp3.Request
|
||||||
|
import okhttp3.Response
|
||||||
|
import okhttp3.sse.EventSource
|
||||||
|
import okhttp3.sse.EventSourceListener
|
||||||
|
import okhttp3.sse.EventSources
|
||||||
|
import java.util.concurrent.TimeUnit
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean
|
||||||
|
|
||||||
|
class SSEManager(
|
||||||
|
private val url: String,
|
||||||
|
private val authToken: String
|
||||||
|
) {
|
||||||
|
private val client = OkHttpClient.Builder()
|
||||||
|
.readTimeout(1, TimeUnit.HOURS)
|
||||||
|
.build()
|
||||||
|
private val scope = CoroutineScope(Dispatchers.IO + Job())
|
||||||
|
|
||||||
|
private var eventSource: EventSource? = null
|
||||||
|
private var reconnectAttempts = 0
|
||||||
|
private val isDisconnecting = AtomicBoolean(false)
|
||||||
|
|
||||||
|
// Event callbacks
|
||||||
|
var onEvent: ((type: String?, data: String) -> Unit)? = null
|
||||||
|
var onConnected: (() -> Unit)? = null
|
||||||
|
var onError: ((Throwable?) -> Unit)? = null
|
||||||
|
var onClosed: (() -> Unit)? = null
|
||||||
|
|
||||||
|
fun connect() {
|
||||||
|
isDisconnecting.set(false)
|
||||||
|
scope.launch {
|
||||||
|
try {
|
||||||
|
val request = Request.Builder()
|
||||||
|
.url(url)
|
||||||
|
.apply {
|
||||||
|
header("Authorization", "Bearer $authToken")
|
||||||
|
}
|
||||||
|
.build()
|
||||||
|
|
||||||
|
eventSource = EventSources.createFactory(client)
|
||||||
|
.newEventSource(request, object : EventSourceListener() {
|
||||||
|
override fun onOpen(eventSource: EventSource, response: Response) {
|
||||||
|
Log.d(TAG, "SSE connected")
|
||||||
|
reconnectAttempts = 0
|
||||||
|
onConnected?.invoke()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onEvent(
|
||||||
|
eventSource: EventSource,
|
||||||
|
id: String?,
|
||||||
|
type: String?,
|
||||||
|
data: String
|
||||||
|
) {
|
||||||
|
Log.d(TAG, "Event received: $type - $data")
|
||||||
|
onEvent?.invoke(type, data)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onClosed(eventSource: EventSource) {
|
||||||
|
Log.d(TAG, "SSE connection closed")
|
||||||
|
onClosed?.invoke()
|
||||||
|
scheduleReconnect()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onFailure(
|
||||||
|
eventSource: EventSource,
|
||||||
|
t: Throwable?,
|
||||||
|
response: Response?
|
||||||
|
) {
|
||||||
|
Log.e(TAG, "SSE error", t)
|
||||||
|
onError?.invoke(t)
|
||||||
|
scheduleReconnect()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.e(TAG, "Connection failed", e)
|
||||||
|
scheduleReconnect()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun disconnect() {
|
||||||
|
isDisconnecting.set(true)
|
||||||
|
scope.launch {
|
||||||
|
eventSource?.cancel()
|
||||||
|
eventSource = null
|
||||||
|
reconnectAttempts = 0
|
||||||
|
}
|
||||||
|
scope.coroutineContext.cancelChildren()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun scheduleReconnect() {
|
||||||
|
if (isDisconnecting.get()) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
reconnectAttempts++
|
||||||
|
val delay = when {
|
||||||
|
reconnectAttempts > 10 -> 60_000L // 1 minute
|
||||||
|
reconnectAttempts > 5 -> 30_000L // 30 seconds
|
||||||
|
else -> 5_000L // 5 seconds
|
||||||
|
}
|
||||||
|
|
||||||
|
scope.launch {
|
||||||
|
eventSource?.cancel()
|
||||||
|
eventSource = null
|
||||||
|
Log.d(TAG, "Reconnecting in ${delay}ms (attempt $reconnectAttempts)")
|
||||||
|
kotlinx.coroutines.delay(delay)
|
||||||
|
connect()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
const val TAG = "SSEManager"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
package pt.whatsms.gateway.helpers
|
||||||
|
|
||||||
|
import android.content.ComponentName
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.pm.PackageManager
|
||||||
|
import androidx.core.content.edit
|
||||||
|
import androidx.preference.PreferenceManager
|
||||||
|
import pt.whatsms.gateway.receivers.BootReceiver
|
||||||
|
|
||||||
|
class SettingsHelper(private val context: Context) {
|
||||||
|
private val settings = PreferenceManager.getDefaultSharedPreferences(context)
|
||||||
|
|
||||||
|
init {
|
||||||
|
migrate()
|
||||||
|
}
|
||||||
|
|
||||||
|
var autostart: Boolean
|
||||||
|
get() = settings.getBoolean(PREF_KEY_AUTOSTART, false)
|
||||||
|
set(value) {
|
||||||
|
// enable broadcast receiver
|
||||||
|
context.packageManager.setComponentEnabledSetting(
|
||||||
|
ComponentName(context, BootReceiver::class.java),
|
||||||
|
if (value) PackageManager.COMPONENT_ENABLED_STATE_ENABLED else PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
|
||||||
|
PackageManager.DONT_KILL_APP
|
||||||
|
)
|
||||||
|
|
||||||
|
settings.edit { putBoolean(PREF_KEY_AUTOSTART, value) }
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun migrate() {
|
||||||
|
// remove after 2025-11-28
|
||||||
|
val PREF_KEY_SERVER_TOKEN = "server_token"
|
||||||
|
if (settings.contains(PREF_KEY_SERVER_TOKEN)) {
|
||||||
|
settings.edit(true) {
|
||||||
|
putString("localserver.PASSWORD", settings.getString(PREF_KEY_SERVER_TOKEN, null))
|
||||||
|
remove(PREF_KEY_SERVER_TOKEN)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private const val PREF_KEY_AUTOSTART = "autostart"
|
||||||
|
|
||||||
|
private const val PREF_KEY_FCM_TOKEN = "fcm_token"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,105 @@
|
|||||||
|
package pt.whatsms.gateway.helpers
|
||||||
|
|
||||||
|
import android.Manifest
|
||||||
|
import android.annotation.SuppressLint
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
|
import android.content.pm.PackageManager
|
||||||
|
import android.os.Build
|
||||||
|
import android.telephony.SubscriptionManager
|
||||||
|
import androidx.core.app.ActivityCompat
|
||||||
|
|
||||||
|
object SubscriptionsHelper {
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
|
fun getSubscriptionsManager(context: Context): SubscriptionManager? = when {
|
||||||
|
Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1 -> null
|
||||||
|
Build.VERSION.SDK_INT < 31 -> SubscriptionManager.from(context)
|
||||||
|
else -> context.getSystemService(SubscriptionManager::class.java)
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressLint("MissingPermission")
|
||||||
|
fun selectAvailableSimSlots(context: Context): Set<Int>? {
|
||||||
|
if (!hasPhoneStatePermission(context)) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
val subscriptionManager = getSubscriptionsManager(context) ?: return null
|
||||||
|
return when {
|
||||||
|
Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1 -> subscriptionManager.activeSubscriptionInfoList.map { it.simSlotIndex }
|
||||||
|
.toSet()
|
||||||
|
else -> null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressLint("MissingPermission")
|
||||||
|
fun getSubscriptionId(context: Context, simSlotIndex: Int): Int? {
|
||||||
|
if (!hasPhoneStatePermission(context)) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
val subscriptionManager = getSubscriptionsManager(context) ?: return null
|
||||||
|
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
|
||||||
|
subscriptionManager.activeSubscriptionInfoList.find {
|
||||||
|
it.simSlotIndex == simSlotIndex
|
||||||
|
}?.subscriptionId
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressLint("MissingPermission")
|
||||||
|
fun getSimSlotIndex(context: Context, subscriptionId: Int): Int? {
|
||||||
|
if (!hasPhoneStatePermission(context)) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
val subscriptionManager = getSubscriptionsManager(context) ?: return null
|
||||||
|
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
|
||||||
|
subscriptionManager.activeSubscriptionInfoList.find {
|
||||||
|
it.subscriptionId == subscriptionId
|
||||||
|
}?.simSlotIndex
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun hasPhoneStatePermission(context: Context): Boolean {
|
||||||
|
return ActivityCompat.checkSelfPermission(
|
||||||
|
context,
|
||||||
|
Manifest.permission.READ_PHONE_STATE
|
||||||
|
) == PackageManager.PERMISSION_GRANTED
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressLint("InlinedApi")
|
||||||
|
fun extractSubscriptionId(context: Context, intent: Intent): Int? {
|
||||||
|
return when {
|
||||||
|
intent.extras?.containsKey(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX) == true -> intent.extras?.getInt(
|
||||||
|
SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX
|
||||||
|
)
|
||||||
|
|
||||||
|
intent.extras?.containsKey("subscription") == true -> intent.extras?.getInt("subscription")
|
||||||
|
intent.extras?.containsKey(SubscriptionManager.EXTRA_SLOT_INDEX) == true -> intent.extras?.getInt(
|
||||||
|
SubscriptionManager.EXTRA_SLOT_INDEX
|
||||||
|
)?.let { getSubscriptionId(context, it) }
|
||||||
|
|
||||||
|
else -> null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressLint("MissingPermission")
|
||||||
|
fun getPhoneNumber(context: Context, simSlotIndex: Int): String? {
|
||||||
|
if (!hasPhoneStatePermission(context)) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
val subscriptionManager = getSubscriptionsManager(context) ?: return null
|
||||||
|
|
||||||
|
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
|
||||||
|
subscriptionManager.activeSubscriptionInfoList?.find {
|
||||||
|
it.simSlotIndex == simSlotIndex
|
||||||
|
}?.number?.takeIf { it.isNotBlank() }
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package pt.whatsms.gateway.modules.connection
|
||||||
|
|
||||||
|
enum class CellularNetworkType {
|
||||||
|
None,
|
||||||
|
Unknown,
|
||||||
|
Mobile2G,
|
||||||
|
Mobile3G,
|
||||||
|
Mobile4G,
|
||||||
|
Mobile5G,
|
||||||
|
}
|
||||||
@@ -0,0 +1,186 @@
|
|||||||
|
package pt.whatsms.gateway.modules.connection
|
||||||
|
|
||||||
|
import android.Manifest
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.pm.PackageManager
|
||||||
|
import android.net.ConnectivityManager
|
||||||
|
import android.net.Network
|
||||||
|
import android.net.NetworkCapabilities
|
||||||
|
import android.os.Build
|
||||||
|
import android.telephony.TelephonyManager
|
||||||
|
import androidx.core.app.ActivityCompat
|
||||||
|
import androidx.lifecycle.LiveData
|
||||||
|
import androidx.lifecycle.MutableLiveData
|
||||||
|
import pt.whatsms.gateway.modules.health.domain.CheckResult
|
||||||
|
import pt.whatsms.gateway.modules.health.domain.Status
|
||||||
|
import pt.whatsms.gateway.modules.logs.LogsService
|
||||||
|
import pt.whatsms.gateway.modules.logs.db.LogEntry
|
||||||
|
import org.koin.core.component.KoinComponent
|
||||||
|
import org.koin.core.component.inject
|
||||||
|
|
||||||
|
class ConnectionService(
|
||||||
|
private val context: Context
|
||||||
|
) : KoinComponent {
|
||||||
|
private val _status = MutableLiveData(false)
|
||||||
|
val status: LiveData<Boolean> = _status
|
||||||
|
|
||||||
|
private val connectivityManager =
|
||||||
|
context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
|
||||||
|
private val logsService by inject<LogsService>()
|
||||||
|
|
||||||
|
private val networkCallback = object : ConnectivityManager.NetworkCallback() {
|
||||||
|
override fun onLost(network: Network) {
|
||||||
|
if (_status.value == false) return
|
||||||
|
|
||||||
|
logsService.insert(
|
||||||
|
LogEntry.Priority.WARN,
|
||||||
|
MODULE_NAME,
|
||||||
|
"Internet connection lost"
|
||||||
|
)
|
||||||
|
|
||||||
|
_status.postValue(false)
|
||||||
|
|
||||||
|
super.onLost(network)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onCapabilitiesChanged(
|
||||||
|
network: Network,
|
||||||
|
networkCapabilities: NetworkCapabilities
|
||||||
|
) {
|
||||||
|
val hasInternet =
|
||||||
|
networkCapabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
|
||||||
|
&& (Build.VERSION.SDK_INT < Build.VERSION_CODES.M || networkCapabilities.hasCapability(
|
||||||
|
NetworkCapabilities.NET_CAPABILITY_VALIDATED
|
||||||
|
))
|
||||||
|
|
||||||
|
if (_status.value == hasInternet) return
|
||||||
|
|
||||||
|
logsService.insert(
|
||||||
|
LogEntry.Priority.INFO,
|
||||||
|
MODULE_NAME,
|
||||||
|
"Internet connection status: $hasInternet"
|
||||||
|
)
|
||||||
|
|
||||||
|
_status.postValue(hasInternet)
|
||||||
|
|
||||||
|
super.onCapabilitiesChanged(network, networkCapabilities)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun healthCheck(): Map<String, CheckResult> {
|
||||||
|
val status = when (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||||
|
true -> when (_status.value) {
|
||||||
|
true -> Status.PASS
|
||||||
|
else -> Status.FAIL
|
||||||
|
}
|
||||||
|
|
||||||
|
false -> Status.PASS
|
||||||
|
}
|
||||||
|
val transport = transportType
|
||||||
|
val cellularType = cellularNetworkType
|
||||||
|
|
||||||
|
return mapOf(
|
||||||
|
"status" to CheckResult(
|
||||||
|
status,
|
||||||
|
when (status) {
|
||||||
|
Status.PASS -> 1L
|
||||||
|
else -> 0L
|
||||||
|
},
|
||||||
|
"boolean",
|
||||||
|
"Internet connection status"
|
||||||
|
),
|
||||||
|
"transport" to CheckResult(
|
||||||
|
when (transport.isEmpty()) {
|
||||||
|
true -> Status.FAIL
|
||||||
|
false -> Status.PASS
|
||||||
|
},
|
||||||
|
transport.sumOf { it.value }.toLong(),
|
||||||
|
"flags",
|
||||||
|
"Network transport type"
|
||||||
|
),
|
||||||
|
"cellular" to CheckResult(
|
||||||
|
Status.PASS,
|
||||||
|
cellularType.ordinal.toLong(),
|
||||||
|
"index",
|
||||||
|
"Cellular network type"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
val transportType: Set<TransportType>
|
||||||
|
get() {
|
||||||
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) return setOf(TransportType.Unknown)
|
||||||
|
|
||||||
|
val result = mutableSetOf<TransportType>()
|
||||||
|
|
||||||
|
val nw = connectivityManager.activeNetwork ?: return result
|
||||||
|
val actNw = connectivityManager.getNetworkCapabilities(nw) ?: return result
|
||||||
|
|
||||||
|
if (actNw.hasTransport(NetworkCapabilities.TRANSPORT_WIFI)) {
|
||||||
|
result.add(TransportType.WiFi)
|
||||||
|
}
|
||||||
|
if (actNw.hasTransport(NetworkCapabilities.TRANSPORT_ETHERNET)) {
|
||||||
|
result.add(TransportType.Ethernet)
|
||||||
|
}
|
||||||
|
if (actNw.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR)) {
|
||||||
|
result.add(TransportType.Cellular)
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
val cellularNetworkType: CellularNetworkType
|
||||||
|
get() {
|
||||||
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) return CellularNetworkType.Unknown
|
||||||
|
|
||||||
|
val transport = transportType
|
||||||
|
|
||||||
|
if (transport.contains(TransportType.Unknown)) {
|
||||||
|
return CellularNetworkType.Unknown
|
||||||
|
}
|
||||||
|
if (!transport.contains(TransportType.Cellular)) {
|
||||||
|
return CellularNetworkType.None
|
||||||
|
}
|
||||||
|
|
||||||
|
val tm = context.getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager
|
||||||
|
if (ActivityCompat.checkSelfPermission(
|
||||||
|
context,
|
||||||
|
Manifest.permission.READ_PHONE_STATE
|
||||||
|
) != PackageManager.PERMISSION_GRANTED
|
||||||
|
) {
|
||||||
|
return CellularNetworkType.Unknown
|
||||||
|
}
|
||||||
|
when (tm.dataNetworkType) {
|
||||||
|
TelephonyManager.NETWORK_TYPE_GPRS,
|
||||||
|
TelephonyManager.NETWORK_TYPE_EDGE,
|
||||||
|
TelephonyManager.NETWORK_TYPE_CDMA,
|
||||||
|
TelephonyManager.NETWORK_TYPE_1xRTT,
|
||||||
|
TelephonyManager.NETWORK_TYPE_IDEN,
|
||||||
|
TelephonyManager.NETWORK_TYPE_GSM -> return CellularNetworkType.Mobile2G
|
||||||
|
|
||||||
|
TelephonyManager.NETWORK_TYPE_UMTS,
|
||||||
|
TelephonyManager.NETWORK_TYPE_EVDO_0,
|
||||||
|
TelephonyManager.NETWORK_TYPE_EVDO_A,
|
||||||
|
TelephonyManager.NETWORK_TYPE_HSDPA,
|
||||||
|
TelephonyManager.NETWORK_TYPE_HSUPA,
|
||||||
|
TelephonyManager.NETWORK_TYPE_HSPA,
|
||||||
|
TelephonyManager.NETWORK_TYPE_EVDO_B,
|
||||||
|
TelephonyManager.NETWORK_TYPE_EHRPD,
|
||||||
|
TelephonyManager.NETWORK_TYPE_HSPAP,
|
||||||
|
TelephonyManager.NETWORK_TYPE_TD_SCDMA -> return CellularNetworkType.Mobile3G
|
||||||
|
|
||||||
|
TelephonyManager.NETWORK_TYPE_LTE,
|
||||||
|
TelephonyManager.NETWORK_TYPE_IWLAN, 19 -> return CellularNetworkType.Mobile4G
|
||||||
|
|
||||||
|
TelephonyManager.NETWORK_TYPE_NR -> return CellularNetworkType.Mobile5G
|
||||||
|
}
|
||||||
|
|
||||||
|
return CellularNetworkType.Unknown
|
||||||
|
}
|
||||||
|
|
||||||
|
init {
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||||
|
connectivityManager.registerDefaultNetworkCallback(networkCallback)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package pt.whatsms.gateway.modules.connection
|
||||||
|
|
||||||
|
import org.koin.core.module.dsl.singleOf
|
||||||
|
import org.koin.dsl.module
|
||||||
|
|
||||||
|
val connectionModule = module {
|
||||||
|
singleOf(::ConnectionService)
|
||||||
|
}
|
||||||
|
|
||||||
|
val MODULE_NAME = "connection"
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package pt.whatsms.gateway.modules.connection
|
||||||
|
|
||||||
|
enum class TransportType(
|
||||||
|
val value: Int
|
||||||
|
) {
|
||||||
|
Unknown(1),
|
||||||
|
Cellular(2),
|
||||||
|
WiFi(4),
|
||||||
|
Ethernet(8),
|
||||||
|
}
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
package pt.whatsms.gateway.modules.encryption
|
||||||
|
|
||||||
|
import android.util.Base64
|
||||||
|
import javax.crypto.Cipher
|
||||||
|
import javax.crypto.SecretKey
|
||||||
|
import javax.crypto.SecretKeyFactory
|
||||||
|
import javax.crypto.spec.IvParameterSpec
|
||||||
|
import javax.crypto.spec.PBEKeySpec
|
||||||
|
import javax.crypto.spec.SecretKeySpec
|
||||||
|
|
||||||
|
class EncryptionService(
|
||||||
|
private val settings: EncryptionSettings,
|
||||||
|
) {
|
||||||
|
fun decrypt(encryptedText: String): String {
|
||||||
|
val chunks = encryptedText.split('$')
|
||||||
|
if (chunks.size < 5)
|
||||||
|
throw RuntimeException("Invalid encrypted data format")
|
||||||
|
|
||||||
|
if (chunks[1] != "aes-256-cbc/pbkdf2-sha1") {
|
||||||
|
throw RuntimeException("Unsupported algorithm")
|
||||||
|
}
|
||||||
|
|
||||||
|
val params = parseParams(chunks[2])
|
||||||
|
if (!params.containsKey("i")) {
|
||||||
|
throw RuntimeException("Missing iteration count")
|
||||||
|
}
|
||||||
|
|
||||||
|
val salt = decode(chunks[3])
|
||||||
|
val text = chunks[4]
|
||||||
|
|
||||||
|
val passphrase = requireNotNull(settings.passphrase) { "Passphrase is not set" }
|
||||||
|
val secretKey = generateSecretKeyFromPassphrase(
|
||||||
|
passphrase.toCharArray(),
|
||||||
|
salt,
|
||||||
|
256,
|
||||||
|
params.getValue("i").toInt()
|
||||||
|
)
|
||||||
|
|
||||||
|
return decryptText(text, secretKey, salt)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun decryptText(encryptedText: String, secretKey: SecretKey, iv: ByteArray): String {
|
||||||
|
val ivSpec = IvParameterSpec(iv)
|
||||||
|
val cipher = Cipher.getInstance("AES/CBC/PKCS5Padding")
|
||||||
|
cipher.init(Cipher.DECRYPT_MODE, secretKey, ivSpec)
|
||||||
|
val encryptedBytes = decode(encryptedText)
|
||||||
|
val decryptedBytes = cipher.doFinal(encryptedBytes)
|
||||||
|
return String(decryptedBytes)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun decode(input: String): ByteArray {
|
||||||
|
return Base64.decode(input, Base64.DEFAULT)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun generateSecretKeyFromPassphrase(
|
||||||
|
passphrase: CharArray,
|
||||||
|
salt: ByteArray,
|
||||||
|
keyLength: Int = 256,
|
||||||
|
iterationCount: Int = 300_000
|
||||||
|
): SecretKey {
|
||||||
|
val keySpec = PBEKeySpec(passphrase, salt, iterationCount, keyLength)
|
||||||
|
val keyFactory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1")
|
||||||
|
val keyBytes = keyFactory.generateSecret(keySpec).encoded
|
||||||
|
return SecretKeySpec(keyBytes, "AES")
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun parseParams(params: String): Map<String, String> {
|
||||||
|
return params.split(',')
|
||||||
|
.map { it.split('=', limit = 2) }
|
||||||
|
.associate { it[0] to it[1] }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
package pt.whatsms.gateway.modules.encryption
|
||||||
|
|
||||||
|
import pt.whatsms.gateway.modules.settings.Importer
|
||||||
|
import pt.whatsms.gateway.modules.settings.KeyValueStorage
|
||||||
|
import pt.whatsms.gateway.modules.settings.get
|
||||||
|
|
||||||
|
class EncryptionSettings(
|
||||||
|
private val storage: KeyValueStorage,
|
||||||
|
) : Importer {
|
||||||
|
val passphrase: String?
|
||||||
|
get() = storage.get<String>(PASSPHRASE)
|
||||||
|
|
||||||
|
private var version: Int
|
||||||
|
get() = storage.get<Int>(VERSION) ?: 0
|
||||||
|
set(value) = storage.set(VERSION, value)
|
||||||
|
|
||||||
|
init {
|
||||||
|
migrate()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun migrate() {
|
||||||
|
if (version == VERSION_CODE) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (version < 1) {
|
||||||
|
passphrase?.let {
|
||||||
|
storage.set(PASSPHRASE, it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
version = VERSION_CODE
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private const val VERSION_CODE = 1
|
||||||
|
|
||||||
|
private const val PASSPHRASE = "passphrase"
|
||||||
|
|
||||||
|
private const val VERSION = "version"
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun import(data: Map<String, *>): Boolean {
|
||||||
|
return data.map {
|
||||||
|
when (it.key) {
|
||||||
|
PASSPHRASE -> {
|
||||||
|
val newValue = it.value?.toString()
|
||||||
|
val changed = passphrase != newValue
|
||||||
|
storage.set(it.key, newValue)
|
||||||
|
changed
|
||||||
|
}
|
||||||
|
|
||||||
|
else -> false
|
||||||
|
}
|
||||||
|
}.any { it }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package pt.whatsms.gateway.modules.encryption
|
||||||
|
|
||||||
|
import org.koin.dsl.module
|
||||||
|
|
||||||
|
val encryptionModule = module {
|
||||||
|
single {
|
||||||
|
EncryptionService(get())
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
package pt.whatsms.gateway.modules.events
|
||||||
|
|
||||||
|
open class AppEvent(
|
||||||
|
@Transient
|
||||||
|
val name: String,
|
||||||
|
)
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package pt.whatsms.gateway.modules.events
|
||||||
|
|
||||||
|
import android.util.Log
|
||||||
|
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||||
|
import kotlinx.coroutines.flow.asSharedFlow
|
||||||
|
import kotlinx.coroutines.flow.filter
|
||||||
|
|
||||||
|
class EventBus {
|
||||||
|
private val _events = MutableSharedFlow<AppEvent>()
|
||||||
|
val events = _events.asSharedFlow()
|
||||||
|
|
||||||
|
suspend fun emit(event: AppEvent) {
|
||||||
|
Log.d("EventBus", "${Thread.currentThread().name} emitted ${event.name}")
|
||||||
|
_events.emit(event)
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend inline fun <reified T : AppEvent> collect(crossinline block: suspend (T) -> Unit) {
|
||||||
|
events
|
||||||
|
.filter {
|
||||||
|
it is T
|
||||||
|
}
|
||||||
|
.collect { block(it as T) }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package pt.whatsms.gateway.modules.events
|
||||||
|
|
||||||
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.Job
|
||||||
|
import kotlinx.coroutines.SupervisorJob
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import org.koin.core.component.KoinComponent
|
||||||
|
import org.koin.core.component.get
|
||||||
|
|
||||||
|
abstract class EventsReceiver : KoinComponent {
|
||||||
|
private val scope = CoroutineScope(Dispatchers.IO + SupervisorJob())
|
||||||
|
private var job: Job? = null
|
||||||
|
|
||||||
|
private val eventBus = get<EventBus>()
|
||||||
|
|
||||||
|
fun start() {
|
||||||
|
stop()
|
||||||
|
|
||||||
|
this.job = scope.launch {
|
||||||
|
collect(eventBus)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract suspend fun collect(eventBus: EventBus)
|
||||||
|
|
||||||
|
fun stop() {
|
||||||
|
this.job?.cancel()
|
||||||
|
this.job = null
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
package pt.whatsms.gateway.modules.events
|
||||||
|
|
||||||
|
data class ExternalEvent(
|
||||||
|
val type: ExternalEventType,
|
||||||
|
val data: String?,
|
||||||
|
)
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package pt.whatsms.gateway.modules.events
|
||||||
|
|
||||||
|
import com.google.gson.annotations.SerializedName
|
||||||
|
|
||||||
|
enum class ExternalEventType {
|
||||||
|
@SerializedName("MessageEnqueued")
|
||||||
|
MessageEnqueued,
|
||||||
|
|
||||||
|
@SerializedName("WebhooksUpdated")
|
||||||
|
WebhooksUpdated,
|
||||||
|
|
||||||
|
@SerializedName("MessagesExportRequested")
|
||||||
|
MessagesExportRequested,
|
||||||
|
|
||||||
|
@SerializedName("SettingsUpdated")
|
||||||
|
SettingsUpdated,
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package pt.whatsms.gateway.modules.events
|
||||||
|
|
||||||
|
import org.koin.dsl.module
|
||||||
|
|
||||||
|
val eventBusModule = module {
|
||||||
|
single { EventBus() }
|
||||||
|
}
|
||||||
@@ -0,0 +1,99 @@
|
|||||||
|
package pt.whatsms.gateway.modules.gateway
|
||||||
|
|
||||||
|
import android.util.Log
|
||||||
|
import kotlinx.coroutines.coroutineScope
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import pt.whatsms.gateway.domain.EntitySource
|
||||||
|
import pt.whatsms.gateway.modules.events.EventBus
|
||||||
|
import pt.whatsms.gateway.modules.events.EventsReceiver
|
||||||
|
import pt.whatsms.gateway.modules.gateway.events.DeviceRegisteredEvent
|
||||||
|
import pt.whatsms.gateway.modules.gateway.events.MessageEnqueuedEvent
|
||||||
|
import pt.whatsms.gateway.modules.gateway.events.SettingsUpdatedEvent
|
||||||
|
import pt.whatsms.gateway.modules.gateway.events.WebhooksUpdatedEvent
|
||||||
|
import pt.whatsms.gateway.modules.gateway.services.SSEForegroundService
|
||||||
|
import pt.whatsms.gateway.modules.gateway.workers.PullMessagesWorker
|
||||||
|
import pt.whatsms.gateway.modules.gateway.workers.SendStateWorker
|
||||||
|
import pt.whatsms.gateway.modules.gateway.workers.SettingsUpdateWorker
|
||||||
|
import pt.whatsms.gateway.modules.gateway.workers.WebhooksUpdateWorker
|
||||||
|
import pt.whatsms.gateway.modules.messages.events.MessageStateChangedEvent
|
||||||
|
import pt.whatsms.gateway.modules.ping.events.PingEvent
|
||||||
|
import org.koin.core.component.get
|
||||||
|
|
||||||
|
class EventsReceiver : EventsReceiver() {
|
||||||
|
|
||||||
|
private val settings = get<GatewaySettings>()
|
||||||
|
|
||||||
|
override suspend fun collect(eventBus: EventBus) {
|
||||||
|
coroutineScope {
|
||||||
|
launch {
|
||||||
|
Log.d("EventsReceiver", "launched MessageEnqueuedEvent")
|
||||||
|
eventBus.collect<MessageEnqueuedEvent> { event ->
|
||||||
|
Log.d("EventsReceiver", "Event: $event")
|
||||||
|
|
||||||
|
if (!settings.enabled) return@collect
|
||||||
|
|
||||||
|
PullMessagesWorker.start(get())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
launch {
|
||||||
|
Log.d("EventsReceiver", "launched MessageStateChangedEvent")
|
||||||
|
val allowedSources = setOf(EntitySource.Cloud, EntitySource.Gateway)
|
||||||
|
eventBus.collect<MessageStateChangedEvent> { event ->
|
||||||
|
Log.d("EventsReceiver", "Event: $event")
|
||||||
|
|
||||||
|
if (!settings.enabled) return@collect
|
||||||
|
|
||||||
|
if (event.source !in allowedSources) return@collect
|
||||||
|
|
||||||
|
SendStateWorker.start(get(), event.id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
launch {
|
||||||
|
Log.d("EventsReceiver", "launched PingEvent")
|
||||||
|
eventBus.collect<PingEvent> {
|
||||||
|
Log.d("EventsReceiver", "Event: $it")
|
||||||
|
|
||||||
|
if (!settings.enabled) return@collect
|
||||||
|
|
||||||
|
PullMessagesWorker.start(get())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
launch {
|
||||||
|
Log.d("EventsReceiver", "launched WebhooksUpdatedEvent")
|
||||||
|
eventBus.collect<WebhooksUpdatedEvent> {
|
||||||
|
Log.d("EventsReceiver", "Event: $it")
|
||||||
|
|
||||||
|
if (!settings.enabled) return@collect
|
||||||
|
|
||||||
|
WebhooksUpdateWorker.start(get())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
launch {
|
||||||
|
Log.d("EventsReceiver", "launched SettingsUpdatedEvent")
|
||||||
|
eventBus.collect<SettingsUpdatedEvent> {
|
||||||
|
Log.d("EventsReceiver", "Event: $it")
|
||||||
|
|
||||||
|
if (!settings.enabled) return@collect
|
||||||
|
|
||||||
|
SettingsUpdateWorker.start(get())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
launch {
|
||||||
|
Log.d("EventsReceiver", "launched DeviceRegisteredEvent")
|
||||||
|
eventBus.collect<DeviceRegisteredEvent> {
|
||||||
|
Log.d("EventsReceiver", "Event: $it")
|
||||||
|
|
||||||
|
if (!settings.enabled) return@collect
|
||||||
|
if (settings.fcmToken != null) return@collect
|
||||||
|
|
||||||
|
SSEForegroundService.start(get())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,235 @@
|
|||||||
|
package pt.whatsms.gateway.modules.gateway
|
||||||
|
|
||||||
|
import com.google.gson.annotations.SerializedName
|
||||||
|
import io.ktor.client.HttpClient
|
||||||
|
import io.ktor.client.call.body
|
||||||
|
import io.ktor.client.engine.okhttp.OkHttp
|
||||||
|
import io.ktor.client.plugins.UserAgent
|
||||||
|
import io.ktor.client.plugins.contentnegotiation.ContentNegotiation
|
||||||
|
import io.ktor.client.request.HttpRequestBuilder
|
||||||
|
import io.ktor.client.request.get
|
||||||
|
import io.ktor.client.request.header
|
||||||
|
import io.ktor.client.request.parameter
|
||||||
|
import io.ktor.client.request.patch
|
||||||
|
import io.ktor.client.request.post
|
||||||
|
import io.ktor.client.request.setBody
|
||||||
|
import io.ktor.http.ContentType
|
||||||
|
import io.ktor.http.HttpHeaders
|
||||||
|
import io.ktor.http.Url
|
||||||
|
import io.ktor.http.contentType
|
||||||
|
import io.ktor.http.hostWithPort
|
||||||
|
import io.ktor.serialization.gson.gson
|
||||||
|
import io.ktor.util.encodeBase64
|
||||||
|
import pt.whatsms.gateway.BuildConfig
|
||||||
|
import pt.whatsms.gateway.domain.ProcessingState
|
||||||
|
import pt.whatsms.gateway.extensions.configure
|
||||||
|
import pt.whatsms.gateway.modules.webhooks.domain.WebHookEvent
|
||||||
|
import java.util.Date
|
||||||
|
|
||||||
|
class GatewayApi(
|
||||||
|
private val baseUrl: String,
|
||||||
|
private val privateToken: String?
|
||||||
|
) {
|
||||||
|
val hostname: String
|
||||||
|
get() = Url(baseUrl).hostWithPort
|
||||||
|
|
||||||
|
private val client = HttpClient(OkHttp) {
|
||||||
|
install(UserAgent) {
|
||||||
|
agent = "pt.whatsms.gateway/" + BuildConfig.VERSION_NAME
|
||||||
|
}
|
||||||
|
install(ContentNegotiation) {
|
||||||
|
gson {
|
||||||
|
configure()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expectSuccess = true
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun getDevice(token: String?): DeviceGetResponse {
|
||||||
|
return client.get("$baseUrl/device") {
|
||||||
|
token?.let { bearerAuth(it) }
|
||||||
|
}.body()
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun deviceRegister(
|
||||||
|
request: DeviceRegisterRequest,
|
||||||
|
credentials: Pair<String, String>?
|
||||||
|
): DeviceRegisterResponse {
|
||||||
|
return client.post("$baseUrl/device") {
|
||||||
|
when {
|
||||||
|
credentials != null -> basicAuth(credentials.first, credentials.second)
|
||||||
|
privateToken != null -> bearerAuth(privateToken)
|
||||||
|
}
|
||||||
|
contentType(ContentType.Application.Json)
|
||||||
|
setBody(request)
|
||||||
|
}.body()
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun deviceRegister(
|
||||||
|
request: DeviceRegisterRequest,
|
||||||
|
code: String
|
||||||
|
): DeviceRegisterResponse {
|
||||||
|
return client.post("$baseUrl/device") {
|
||||||
|
header("Authorization", "Code $code")
|
||||||
|
contentType(ContentType.Application.Json)
|
||||||
|
setBody(request)
|
||||||
|
}.body()
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun devicePatch(token: String, request: DevicePatchRequest) {
|
||||||
|
client.patch("$baseUrl/device") {
|
||||||
|
bearerAuth(token)
|
||||||
|
contentType(ContentType.Application.Json)
|
||||||
|
setBody(request)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun getMessages(token: String, processingOrder: ProcessingOrder): List<Message> {
|
||||||
|
return client.get("$baseUrl/message") {
|
||||||
|
parameter("order", processingOrder)
|
||||||
|
bearerAuth(token)
|
||||||
|
}.body()
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun patchMessages(token: String, request: List<MessagePatchRequest>) {
|
||||||
|
client.patch("$baseUrl/message") {
|
||||||
|
bearerAuth(token)
|
||||||
|
contentType(ContentType.Application.Json)
|
||||||
|
setBody(request)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun getWebHooks(token: String): List<WebHook> {
|
||||||
|
return client.get("$baseUrl/webhooks") {
|
||||||
|
bearerAuth(token)
|
||||||
|
}.body()
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun getUserCode(credentials: Pair<String, String>): GetUserCodeResponse {
|
||||||
|
return client.get("$baseUrl/user/code") {
|
||||||
|
basicAuth(credentials.first, credentials.second)
|
||||||
|
}.body()
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun changeUserPassword(token: String, request: PasswordChangeRequest) {
|
||||||
|
client.patch("$baseUrl/user/password") {
|
||||||
|
bearerAuth(token)
|
||||||
|
contentType(ContentType.Application.Json)
|
||||||
|
setBody(request)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun getSettings(token: String): Map<String, *> {
|
||||||
|
return client.get("$baseUrl/settings") {
|
||||||
|
bearerAuth(token)
|
||||||
|
}.body()
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
private fun HttpRequestBuilder.bearerAuth(token: String) {
|
||||||
|
header(HttpHeaders.Authorization, "Bearer $token")
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun HttpRequestBuilder.basicAuth(username: String, password: String) {
|
||||||
|
header(HttpHeaders.Authorization, "Basic ${"$username:$password".encodeBase64()}")
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
data class DeviceGetResponse(
|
||||||
|
val externalIp: String,
|
||||||
|
)
|
||||||
|
|
||||||
|
data class DeviceRegisterRequest(
|
||||||
|
val name: String,
|
||||||
|
val pushToken: String?,
|
||||||
|
)
|
||||||
|
|
||||||
|
data class DeviceRegisterResponse(
|
||||||
|
val id: String,
|
||||||
|
val token: String,
|
||||||
|
val login: String,
|
||||||
|
val password: String?,
|
||||||
|
)
|
||||||
|
|
||||||
|
data class DevicePatchRequest(
|
||||||
|
val id: String,
|
||||||
|
val pushToken: String?,
|
||||||
|
)
|
||||||
|
|
||||||
|
data class MessagePatchRequest(
|
||||||
|
val id: String,
|
||||||
|
val state: ProcessingState,
|
||||||
|
val recipients: List<RecipientState>,
|
||||||
|
val states: Map<ProcessingState, Date>
|
||||||
|
)
|
||||||
|
|
||||||
|
data class PasswordChangeRequest(
|
||||||
|
val currentPassword: String,
|
||||||
|
val newPassword: String
|
||||||
|
)
|
||||||
|
|
||||||
|
data class GetUserCodeResponse(
|
||||||
|
val code: String,
|
||||||
|
val validUntil: Date
|
||||||
|
)
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
sealed class MessageContent {
|
||||||
|
class Text(
|
||||||
|
val text: String,
|
||||||
|
) : MessageContent()
|
||||||
|
|
||||||
|
class Data(
|
||||||
|
val data: String,
|
||||||
|
val port: UShort,
|
||||||
|
) : MessageContent()
|
||||||
|
}
|
||||||
|
|
||||||
|
data class Message(
|
||||||
|
val id: String,
|
||||||
|
@SerializedName("textMessage")
|
||||||
|
val _textMessage: MessageContent.Text?,
|
||||||
|
@SerializedName("dataMessage")
|
||||||
|
val _dataMessage: MessageContent.Data?,
|
||||||
|
val phoneNumbers: List<String>,
|
||||||
|
val simNumber: Int?,
|
||||||
|
val withDeliveryReport: Boolean?,
|
||||||
|
val isEncrypted: Boolean?,
|
||||||
|
val validUntil: Date?,
|
||||||
|
val priority: Byte?,
|
||||||
|
val createdAt: Date?,
|
||||||
|
|
||||||
|
@SerializedName("message")
|
||||||
|
val _message: String?,
|
||||||
|
) {
|
||||||
|
val content: MessageContent
|
||||||
|
get() = this._dataMessage
|
||||||
|
?: this._textMessage
|
||||||
|
?: _message?.let { MessageContent.Text(it) }
|
||||||
|
?: throw RuntimeException("Invalid message content")
|
||||||
|
}
|
||||||
|
|
||||||
|
data class RecipientState(
|
||||||
|
val phoneNumber: String,
|
||||||
|
val state: ProcessingState,
|
||||||
|
val error: String?,
|
||||||
|
)
|
||||||
|
|
||||||
|
data class WebHook(
|
||||||
|
val id: String,
|
||||||
|
val url: String,
|
||||||
|
val event: WebHookEvent,
|
||||||
|
)
|
||||||
|
|
||||||
|
enum class ProcessingOrder {
|
||||||
|
@SerializedName("lifo")
|
||||||
|
LIFO,
|
||||||
|
|
||||||
|
@SerializedName("fifo")
|
||||||
|
FIFO;
|
||||||
|
|
||||||
|
override fun toString(): String {
|
||||||
|
return this.name.lowercase()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,305 @@
|
|||||||
|
package pt.whatsms.gateway.modules.gateway
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.os.Build
|
||||||
|
import io.ktor.client.plugins.ClientRequestException
|
||||||
|
import io.ktor.http.HttpStatusCode
|
||||||
|
import pt.whatsms.gateway.data.entities.MessageWithRecipients
|
||||||
|
import pt.whatsms.gateway.domain.EntitySource
|
||||||
|
import pt.whatsms.gateway.domain.MessageContent
|
||||||
|
import pt.whatsms.gateway.modules.events.EventBus
|
||||||
|
import pt.whatsms.gateway.modules.gateway.events.DeviceRegisteredEvent
|
||||||
|
import pt.whatsms.gateway.modules.gateway.services.SSEForegroundService
|
||||||
|
import pt.whatsms.gateway.modules.gateway.workers.PullMessagesWorker
|
||||||
|
import pt.whatsms.gateway.modules.gateway.workers.SendStateWorker
|
||||||
|
import pt.whatsms.gateway.modules.gateway.workers.SettingsUpdateWorker
|
||||||
|
import pt.whatsms.gateway.modules.gateway.workers.WebhooksUpdateWorker
|
||||||
|
import pt.whatsms.gateway.modules.logs.LogsService
|
||||||
|
import pt.whatsms.gateway.modules.logs.db.LogEntry
|
||||||
|
import pt.whatsms.gateway.modules.messages.MessagesService
|
||||||
|
import pt.whatsms.gateway.modules.messages.MessagesSettings
|
||||||
|
import pt.whatsms.gateway.modules.messages.data.SendParams
|
||||||
|
import pt.whatsms.gateway.modules.messages.data.SendRequest
|
||||||
|
import pt.whatsms.gateway.services.PushService
|
||||||
|
import java.util.Date
|
||||||
|
|
||||||
|
class GatewayService(
|
||||||
|
private val messagesService: MessagesService,
|
||||||
|
private val settings: GatewaySettings,
|
||||||
|
private val events: EventBus,
|
||||||
|
private val logsService: LogsService,
|
||||||
|
) {
|
||||||
|
private val eventsReceiver by lazy { EventsReceiver() }
|
||||||
|
|
||||||
|
private var _api: GatewayApi? = null
|
||||||
|
|
||||||
|
private val api
|
||||||
|
get() = _api ?: GatewayApi(
|
||||||
|
settings.serverUrl,
|
||||||
|
settings.privateToken
|
||||||
|
).also { _api = it }
|
||||||
|
|
||||||
|
//region Start, stop, etc...
|
||||||
|
fun start(context: Context) {
|
||||||
|
if (!settings.enabled) return
|
||||||
|
|
||||||
|
PushService.register(context)
|
||||||
|
PullMessagesWorker.start(context)
|
||||||
|
WebhooksUpdateWorker.start(context)
|
||||||
|
SettingsUpdateWorker.start(context)
|
||||||
|
|
||||||
|
eventsReceiver.start()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun stop(context: Context) {
|
||||||
|
eventsReceiver.stop()
|
||||||
|
|
||||||
|
SSEForegroundService.stop(context)
|
||||||
|
SettingsUpdateWorker.stop(context)
|
||||||
|
WebhooksUpdateWorker.stop(context)
|
||||||
|
PullMessagesWorker.stop(context)
|
||||||
|
|
||||||
|
this._api = null
|
||||||
|
}
|
||||||
|
|
||||||
|
fun isActiveLiveData(context: Context) = PullMessagesWorker.getStateLiveData(context)
|
||||||
|
//endregion
|
||||||
|
|
||||||
|
//region Account
|
||||||
|
suspend fun getLoginCode(): GatewayApi.GetUserCodeResponse {
|
||||||
|
val username = settings.username
|
||||||
|
?: throw IllegalStateException("Username is not set")
|
||||||
|
val password = settings.password
|
||||||
|
?: throw IllegalStateException("Password is not set")
|
||||||
|
|
||||||
|
return api.getUserCode(username to password)
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun changePassword(current: String, new: String) {
|
||||||
|
val info = settings.registrationInfo
|
||||||
|
?: throw IllegalStateException("The device is not registered on the server")
|
||||||
|
|
||||||
|
this.api.changeUserPassword(
|
||||||
|
info.token,
|
||||||
|
GatewayApi.PasswordChangeRequest(current, new)
|
||||||
|
)
|
||||||
|
|
||||||
|
settings.registrationInfo = info.copy(password = new)
|
||||||
|
|
||||||
|
events.emit(
|
||||||
|
DeviceRegisteredEvent.Success(
|
||||||
|
api.hostname,
|
||||||
|
info.login,
|
||||||
|
new,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
//endregion
|
||||||
|
|
||||||
|
//region Device
|
||||||
|
internal suspend fun registerDevice(
|
||||||
|
pushToken: String?,
|
||||||
|
registerMode: RegistrationMode
|
||||||
|
) {
|
||||||
|
if (!settings.enabled) return
|
||||||
|
|
||||||
|
val settings = settings.registrationInfo
|
||||||
|
val accessToken = settings?.token
|
||||||
|
|
||||||
|
if (accessToken != null) {
|
||||||
|
// if there's an access token, try to update push token
|
||||||
|
try {
|
||||||
|
updateDevice(pushToken)
|
||||||
|
return
|
||||||
|
} catch (e: ClientRequestException) {
|
||||||
|
// if token is invalid, try to register new one
|
||||||
|
if (e.response.status != HttpStatusCode.Unauthorized) {
|
||||||
|
throw e
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
val deviceName = "${Build.MANUFACTURER}/${Build.PRODUCT}"
|
||||||
|
val request = GatewayApi.DeviceRegisterRequest(
|
||||||
|
deviceName,
|
||||||
|
pushToken
|
||||||
|
)
|
||||||
|
val response = when (registerMode) {
|
||||||
|
RegistrationMode.Anonymous -> api.deviceRegister(request, null)
|
||||||
|
is RegistrationMode.WithCode -> api.deviceRegister(request, registerMode.code)
|
||||||
|
is RegistrationMode.WithCredentials -> api.deviceRegister(
|
||||||
|
request,
|
||||||
|
registerMode.login to registerMode.password
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
this.settings.fcmToken = pushToken
|
||||||
|
this.settings.registrationInfo = response
|
||||||
|
|
||||||
|
events.emit(
|
||||||
|
DeviceRegisteredEvent.Success(
|
||||||
|
api.hostname,
|
||||||
|
response.login,
|
||||||
|
response.password,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
} catch (th: Throwable) {
|
||||||
|
events.emit(
|
||||||
|
DeviceRegisteredEvent.Failure(
|
||||||
|
api.hostname,
|
||||||
|
th.localizedMessage ?: th.message ?: th.toString()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
throw th
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal suspend fun updateDevice(pushToken: String?) {
|
||||||
|
if (!settings.enabled) return
|
||||||
|
|
||||||
|
val settings = settings.registrationInfo ?: return
|
||||||
|
val accessToken = settings.token
|
||||||
|
|
||||||
|
api.devicePatch(
|
||||||
|
accessToken,
|
||||||
|
GatewayApi.DevicePatchRequest(
|
||||||
|
settings.id,
|
||||||
|
pushToken
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
this.settings.fcmToken = pushToken
|
||||||
|
|
||||||
|
events.emit(
|
||||||
|
DeviceRegisteredEvent.Success(
|
||||||
|
api.hostname,
|
||||||
|
settings.login,
|
||||||
|
settings.password,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
sealed class RegistrationMode {
|
||||||
|
object Anonymous : RegistrationMode()
|
||||||
|
class WithCredentials(val login: String, val password: String) : RegistrationMode()
|
||||||
|
class WithCode(val code: String) : RegistrationMode()
|
||||||
|
}
|
||||||
|
//endregion
|
||||||
|
|
||||||
|
//region Messages
|
||||||
|
internal suspend fun getNewMessages(context: Context) {
|
||||||
|
if (!settings.enabled) return
|
||||||
|
val settings = settings.registrationInfo ?: return
|
||||||
|
val processingOrder = when (messagesService.processingOrder) {
|
||||||
|
MessagesSettings.ProcessingOrder.LIFO -> GatewayApi.ProcessingOrder.LIFO
|
||||||
|
MessagesSettings.ProcessingOrder.FIFO -> GatewayApi.ProcessingOrder.FIFO
|
||||||
|
}
|
||||||
|
val messages = api.getMessages(settings.token, processingOrder)
|
||||||
|
for (message in messages) {
|
||||||
|
try {
|
||||||
|
processMessage(context, message)
|
||||||
|
} catch (th: Throwable) {
|
||||||
|
logsService.insert(
|
||||||
|
LogEntry.Priority.ERROR,
|
||||||
|
MODULE_NAME,
|
||||||
|
"Failed to process message",
|
||||||
|
mapOf(
|
||||||
|
"message" to message,
|
||||||
|
"exception" to th.stackTraceToString(),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
th.printStackTrace()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun processMessage(context: Context, message: GatewayApi.Message) {
|
||||||
|
val messageState = messagesService.getMessage(message.id)
|
||||||
|
if (messageState != null) {
|
||||||
|
SendStateWorker.start(context, message.id)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
val request = SendRequest(
|
||||||
|
EntitySource.Cloud,
|
||||||
|
pt.whatsms.gateway.modules.messages.data.Message(
|
||||||
|
message.id,
|
||||||
|
when (val content = message.content) {
|
||||||
|
is GatewayApi.MessageContent.Text -> MessageContent.Text(content.text)
|
||||||
|
is GatewayApi.MessageContent.Data -> MessageContent.Data(
|
||||||
|
content.data,
|
||||||
|
content.port
|
||||||
|
)
|
||||||
|
},
|
||||||
|
message.phoneNumbers,
|
||||||
|
message.isEncrypted ?: false,
|
||||||
|
message.createdAt ?: Date(),
|
||||||
|
),
|
||||||
|
SendParams(
|
||||||
|
message.withDeliveryReport ?: true,
|
||||||
|
skipPhoneValidation = true,
|
||||||
|
simNumber = message.simNumber,
|
||||||
|
validUntil = message.validUntil,
|
||||||
|
priority = message.priority,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
messagesService.enqueueMessage(request)
|
||||||
|
}
|
||||||
|
|
||||||
|
internal suspend fun sendState(
|
||||||
|
message: MessageWithRecipients
|
||||||
|
) {
|
||||||
|
val settings = settings.registrationInfo ?: return
|
||||||
|
|
||||||
|
api.patchMessages(
|
||||||
|
settings.token,
|
||||||
|
listOf(
|
||||||
|
GatewayApi.MessagePatchRequest(
|
||||||
|
message.message.id,
|
||||||
|
message.message.state,
|
||||||
|
message.recipients.map {
|
||||||
|
GatewayApi.RecipientState(
|
||||||
|
it.phoneNumber,
|
||||||
|
it.state,
|
||||||
|
it.error
|
||||||
|
)
|
||||||
|
},
|
||||||
|
message.states.associate { it.state to Date(it.updatedAt) }
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
//endregion
|
||||||
|
|
||||||
|
//region Webhooks
|
||||||
|
internal suspend fun getWebHooks(): List<GatewayApi.WebHook> {
|
||||||
|
val settings = settings.registrationInfo
|
||||||
|
return if (settings != null) {
|
||||||
|
api.getWebHooks(settings.token)
|
||||||
|
} else {
|
||||||
|
emptyList()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//endregion
|
||||||
|
|
||||||
|
//region Settings
|
||||||
|
internal suspend fun getSettings(): Map<String, *>? {
|
||||||
|
val settings = settings.registrationInfo ?: return null
|
||||||
|
|
||||||
|
return api.getSettings(settings.token)
|
||||||
|
}
|
||||||
|
//endregion
|
||||||
|
|
||||||
|
//region Utility
|
||||||
|
suspend fun getPublicIP(): String {
|
||||||
|
return GatewayApi(
|
||||||
|
settings.serverUrl,
|
||||||
|
settings.privateToken
|
||||||
|
)
|
||||||
|
.getDevice(settings.registrationInfo?.token)
|
||||||
|
.externalIp
|
||||||
|
}
|
||||||
|
//endregion
|
||||||
|
}
|
||||||
@@ -0,0 +1,112 @@
|
|||||||
|
package pt.whatsms.gateway.modules.gateway
|
||||||
|
|
||||||
|
import pt.whatsms.gateway.modules.settings.Exporter
|
||||||
|
import pt.whatsms.gateway.modules.settings.Importer
|
||||||
|
import pt.whatsms.gateway.modules.settings.KeyValueStorage
|
||||||
|
import pt.whatsms.gateway.modules.settings.get
|
||||||
|
|
||||||
|
class GatewaySettings(
|
||||||
|
private val storage: KeyValueStorage,
|
||||||
|
) : Exporter, Importer {
|
||||||
|
enum class NotificationChannel {
|
||||||
|
AUTO,
|
||||||
|
SSE_ONLY,
|
||||||
|
}
|
||||||
|
|
||||||
|
var enabled: Boolean
|
||||||
|
get() = storage.get<Boolean>(ENABLED) ?: false
|
||||||
|
set(value) = storage.set(ENABLED, value)
|
||||||
|
|
||||||
|
val deviceId: String?
|
||||||
|
get() = registrationInfo?.id
|
||||||
|
|
||||||
|
var registrationInfo: GatewayApi.DeviceRegisterResponse?
|
||||||
|
get() = storage.get(REGISTRATION_INFO)
|
||||||
|
set(value) = storage.set(REGISTRATION_INFO, value)
|
||||||
|
|
||||||
|
var fcmToken: String?
|
||||||
|
get() = storage.get(FCM_TOKEN)
|
||||||
|
set(value) = storage.set(FCM_TOKEN, value)
|
||||||
|
|
||||||
|
val username: String?
|
||||||
|
get() = registrationInfo?.login
|
||||||
|
val password: String?
|
||||||
|
get() = registrationInfo?.password
|
||||||
|
|
||||||
|
// WhatSMS fork: hardcoded server. Campo de URL removido do UI.
|
||||||
|
val serverUrl: String
|
||||||
|
get() = WHATSMS_SERVER_URL
|
||||||
|
|
||||||
|
// WhatSMS fork: private token hardcoded para auto-registo sem configuração.
|
||||||
|
// Token rotado periodicamente via rebuild do APK.
|
||||||
|
val privateToken: String?
|
||||||
|
get() = WHATSMS_PRIVATE_TOKEN
|
||||||
|
|
||||||
|
val notificationChannel: NotificationChannel
|
||||||
|
get() = storage.get<NotificationChannel>(NOTIFICATION_CHANNEL) ?: NotificationChannel.AUTO
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private const val REGISTRATION_INFO = "REGISTRATION_INFO"
|
||||||
|
private const val ENABLED = "ENABLED"
|
||||||
|
private const val FCM_TOKEN = "fcm_token"
|
||||||
|
|
||||||
|
private const val CLOUD_URL = "cloud_url"
|
||||||
|
private const val PRIVATE_TOKEN = "private_token"
|
||||||
|
private const val NOTIFICATION_CHANNEL = "notification_channel"
|
||||||
|
|
||||||
|
// WhatSMS fork: servidor da Descomplicar.
|
||||||
|
const val WHATSMS_SERVER_URL = "https://smsgw.whatsms.pt/api/mobile/v1"
|
||||||
|
|
||||||
|
// WhatSMS fork: private_token do GATEWAY_TOKEN config do server.
|
||||||
|
// Permite auto-registo silencioso de novos devices.
|
||||||
|
const val WHATSMS_PRIVATE_TOKEN =
|
||||||
|
"a6c877b0369bd68d77c1760a88ec1996c6b672353f4b6344"
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun export(): Map<String, *> {
|
||||||
|
return mapOf(
|
||||||
|
CLOUD_URL to serverUrl,
|
||||||
|
NOTIFICATION_CHANNEL to notificationChannel.name,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun import(data: Map<String, *>): Boolean {
|
||||||
|
return data.map {
|
||||||
|
when (it.key) {
|
||||||
|
CLOUD_URL -> {
|
||||||
|
val url = it.value?.toString() ?: WHATSMS_SERVER_URL
|
||||||
|
if (url != null && !url.startsWith("https://")) {
|
||||||
|
throw IllegalArgumentException("url must start with https://")
|
||||||
|
}
|
||||||
|
|
||||||
|
val changed = serverUrl != url
|
||||||
|
|
||||||
|
storage.set(it.key, url)
|
||||||
|
|
||||||
|
changed
|
||||||
|
}
|
||||||
|
|
||||||
|
PRIVATE_TOKEN -> {
|
||||||
|
val newValue = it.value?.toString()
|
||||||
|
val changed = privateToken != newValue
|
||||||
|
|
||||||
|
storage.set(it.key, newValue)
|
||||||
|
|
||||||
|
changed
|
||||||
|
}
|
||||||
|
|
||||||
|
NOTIFICATION_CHANNEL -> {
|
||||||
|
val newValue = it.value?.let { NotificationChannel.valueOf(it.toString()) }
|
||||||
|
?: NotificationChannel.AUTO
|
||||||
|
val changed = notificationChannel != newValue
|
||||||
|
|
||||||
|
storage.set(it.key, newValue.name)
|
||||||
|
|
||||||
|
changed
|
||||||
|
}
|
||||||
|
|
||||||
|
else -> false
|
||||||
|
}
|
||||||
|
}.any { it }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package pt.whatsms.gateway.modules.gateway
|
||||||
|
|
||||||
|
import org.koin.core.module.dsl.singleOf
|
||||||
|
import org.koin.dsl.module
|
||||||
|
|
||||||
|
val gatewayModule = module {
|
||||||
|
singleOf(::GatewayService)
|
||||||
|
}
|
||||||
|
|
||||||
|
val MODULE_NAME = "gateway"
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package pt.whatsms.gateway.modules.gateway.events
|
||||||
|
|
||||||
|
import pt.whatsms.gateway.modules.events.AppEvent
|
||||||
|
|
||||||
|
sealed class DeviceRegisteredEvent(
|
||||||
|
val server: String,
|
||||||
|
) : AppEvent(NAME) {
|
||||||
|
class Success(
|
||||||
|
server: String,
|
||||||
|
val login: String,
|
||||||
|
val password: String?,
|
||||||
|
) : DeviceRegisteredEvent(server)
|
||||||
|
|
||||||
|
class Failure(
|
||||||
|
server: String,
|
||||||
|
val reason: String,
|
||||||
|
) : DeviceRegisteredEvent(server)
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
const val NAME = "DeviceRegisteredEvent"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package pt.whatsms.gateway.modules.gateway.events
|
||||||
|
|
||||||
|
import pt.whatsms.gateway.modules.events.AppEvent
|
||||||
|
|
||||||
|
class MessageEnqueuedEvent : AppEvent(NAME) {
|
||||||
|
companion object {
|
||||||
|
const val NAME = "MessageEnqueuedEvent"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package pt.whatsms.gateway.modules.gateway.events
|
||||||
|
|
||||||
|
import pt.whatsms.gateway.modules.events.AppEvent
|
||||||
|
|
||||||
|
class SettingsUpdatedEvent : AppEvent(NAME) {
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
const val NAME = "SettingsUpdatedEvent"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package pt.whatsms.gateway.modules.gateway.events
|
||||||
|
|
||||||
|
import pt.whatsms.gateway.modules.events.AppEvent
|
||||||
|
|
||||||
|
class WebhooksUpdatedEvent : AppEvent(NAME) {
|
||||||
|
companion object {
|
||||||
|
const val NAME = "WebhooksUpdatedEvent"
|
||||||
|
}
|
||||||
|
}
|
||||||
+162
@@ -0,0 +1,162 @@
|
|||||||
|
package pt.whatsms.gateway.modules.gateway.services
|
||||||
|
|
||||||
|
import android.app.Service
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
|
import android.net.wifi.WifiManager
|
||||||
|
import android.os.Build
|
||||||
|
import android.os.IBinder
|
||||||
|
import android.os.PowerManager
|
||||||
|
import android.util.Log
|
||||||
|
import pt.whatsms.gateway.R
|
||||||
|
import pt.whatsms.gateway.helpers.SSEManager
|
||||||
|
import pt.whatsms.gateway.modules.events.ExternalEvent
|
||||||
|
import pt.whatsms.gateway.modules.events.ExternalEventType
|
||||||
|
import pt.whatsms.gateway.modules.gateway.GatewaySettings
|
||||||
|
import pt.whatsms.gateway.modules.gateway.workers.PullMessagesWorker
|
||||||
|
import pt.whatsms.gateway.modules.logs.LogsService
|
||||||
|
import pt.whatsms.gateway.modules.logs.db.LogEntry
|
||||||
|
import pt.whatsms.gateway.modules.notifications.NotificationsService
|
||||||
|
import pt.whatsms.gateway.modules.orchestrator.EventsRouter
|
||||||
|
import org.koin.android.ext.android.inject
|
||||||
|
|
||||||
|
class SSEForegroundService : Service() {
|
||||||
|
private val settings: GatewaySettings by inject()
|
||||||
|
|
||||||
|
private val eventsRouter by inject<EventsRouter>()
|
||||||
|
|
||||||
|
private val notificationsSvc: NotificationsService by inject()
|
||||||
|
private val logsService: LogsService by inject()
|
||||||
|
|
||||||
|
private val wakeLock: PowerManager.WakeLock by lazy {
|
||||||
|
(getSystemService(Context.POWER_SERVICE) as PowerManager).run {
|
||||||
|
newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, this.javaClass.name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private val wifiLock: WifiManager.WifiLock by lazy {
|
||||||
|
(getSystemService(Context.WIFI_SERVICE) as WifiManager).createWifiLock(
|
||||||
|
WifiManager.WIFI_MODE_FULL_HIGH_PERF,
|
||||||
|
this.javaClass.name
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
private val sseManager by lazy {
|
||||||
|
SSEManager(
|
||||||
|
"${settings.serverUrl}/events",
|
||||||
|
requireNotNull(
|
||||||
|
settings.registrationInfo?.token
|
||||||
|
) { "Authentication token is required for SSE connection" }
|
||||||
|
)
|
||||||
|
.apply {
|
||||||
|
onConnected = {
|
||||||
|
Log.d("SSEForegroundService", "SSE connected, pulling pending messages")
|
||||||
|
try {
|
||||||
|
PullMessagesWorker.start(this@SSEForegroundService)
|
||||||
|
} catch (e: Throwable) {
|
||||||
|
e.printStackTrace()
|
||||||
|
logsService.insert(
|
||||||
|
LogEntry.Priority.ERROR,
|
||||||
|
"SSEForegroundService",
|
||||||
|
"Failed to start PullMessagesWorker on connect",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
onEvent = { event, data ->
|
||||||
|
Log.d("SSEForegroundService", "$event: $data")
|
||||||
|
|
||||||
|
try {
|
||||||
|
processEvent(event, data)
|
||||||
|
} catch (e: Throwable) {
|
||||||
|
e.printStackTrace()
|
||||||
|
|
||||||
|
logsService.insert(
|
||||||
|
LogEntry.Priority.ERROR,
|
||||||
|
"SSEForegroundService",
|
||||||
|
"Failed to process event",
|
||||||
|
mapOf("event" to event, "data" to data)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onCreate() {
|
||||||
|
super.onCreate()
|
||||||
|
|
||||||
|
if (!wakeLock.isHeld) {
|
||||||
|
wakeLock.acquire()
|
||||||
|
}
|
||||||
|
if (!wifiLock.isHeld) {
|
||||||
|
wifiLock.acquire()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
||||||
|
val notification = notificationsSvc.makeNotification(
|
||||||
|
this,
|
||||||
|
NotificationsService.NOTIFICATION_ID_REALTIME_EVENTS,
|
||||||
|
getString(R.string.listening_to_the_server_events)
|
||||||
|
)
|
||||||
|
|
||||||
|
startForeground(NotificationsService.NOTIFICATION_ID_REALTIME_EVENTS, notification)
|
||||||
|
|
||||||
|
sseManager.connect()
|
||||||
|
|
||||||
|
return super.onStartCommand(intent, flags, startId)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onBind(intent: Intent): IBinder? {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun processEvent(event: String?, data: String) {
|
||||||
|
val type = try {
|
||||||
|
event?.let { ExternalEventType.valueOf(it) }
|
||||||
|
?: ExternalEventType.MessageEnqueued
|
||||||
|
} catch (e: Throwable) {
|
||||||
|
throw RuntimeException("Unknown event type: $event", e)
|
||||||
|
}
|
||||||
|
|
||||||
|
eventsRouter.route(
|
||||||
|
ExternalEvent(
|
||||||
|
type = type,
|
||||||
|
data = data
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onDestroy() {
|
||||||
|
sseManager.disconnect()
|
||||||
|
if (wifiLock.isHeld) {
|
||||||
|
wifiLock.release()
|
||||||
|
}
|
||||||
|
if (wakeLock.isHeld) {
|
||||||
|
wakeLock.release()
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||||
|
stopForeground(STOP_FOREGROUND_REMOVE)
|
||||||
|
} else {
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
|
stopForeground(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
super.onDestroy()
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
fun start(context: Context) {
|
||||||
|
val intent = Intent(context, SSEForegroundService::class.java)
|
||||||
|
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
|
context.startForegroundService(intent)
|
||||||
|
} else {
|
||||||
|
context.startService(intent)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun stop(context: Context) {
|
||||||
|
context.stopService(Intent(context, SSEForegroundService::class.java))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
package pt.whatsms.gateway.modules.gateway.workers
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import androidx.lifecycle.map
|
||||||
|
import androidx.work.BackoffPolicy
|
||||||
|
import androidx.work.Constraints
|
||||||
|
import androidx.work.CoroutineWorker
|
||||||
|
import androidx.work.ExistingPeriodicWorkPolicy
|
||||||
|
import androidx.work.NetworkType
|
||||||
|
import androidx.work.PeriodicWorkRequest
|
||||||
|
import androidx.work.PeriodicWorkRequestBuilder
|
||||||
|
import androidx.work.WorkInfo
|
||||||
|
import androidx.work.WorkManager
|
||||||
|
import androidx.work.WorkRequest
|
||||||
|
import androidx.work.WorkerParameters
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
import pt.whatsms.gateway.App
|
||||||
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
|
class PullMessagesWorker(
|
||||||
|
appContext: Context,
|
||||||
|
params: WorkerParameters
|
||||||
|
) : CoroutineWorker(appContext, params) {
|
||||||
|
override suspend fun doWork(): Result {
|
||||||
|
try {
|
||||||
|
withContext(Dispatchers.IO) {
|
||||||
|
App.instance.gatewayService.getNewMessages(
|
||||||
|
applicationContext
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return Result.success()
|
||||||
|
} catch (th: Throwable) {
|
||||||
|
th.printStackTrace()
|
||||||
|
return Result.retry()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
const val NAME = "PullMessagesWorker"
|
||||||
|
|
||||||
|
fun start(context: Context) {
|
||||||
|
val work = PeriodicWorkRequestBuilder<PullMessagesWorker>(PeriodicWorkRequest.MIN_PERIODIC_INTERVAL_MILLIS, TimeUnit.MILLISECONDS)
|
||||||
|
.setBackoffCriteria(BackoffPolicy.EXPONENTIAL, WorkRequest.MIN_BACKOFF_MILLIS, TimeUnit.MILLISECONDS)
|
||||||
|
.setConstraints(
|
||||||
|
Constraints.Builder()
|
||||||
|
.setRequiredNetworkType(NetworkType.CONNECTED)
|
||||||
|
.build()
|
||||||
|
)
|
||||||
|
.build()
|
||||||
|
WorkManager.getInstance(context)
|
||||||
|
.enqueueUniquePeriodicWork(
|
||||||
|
NAME,
|
||||||
|
ExistingPeriodicWorkPolicy.REPLACE,
|
||||||
|
work
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getStateLiveData(context: Context) = WorkManager.getInstance(context)
|
||||||
|
.getWorkInfosForUniqueWorkLiveData(NAME)
|
||||||
|
.map { infos -> infos.any { it.state == WorkInfo.State.RUNNING || it.state == WorkInfo.State.ENQUEUED } }
|
||||||
|
|
||||||
|
fun stop(context: Context) {
|
||||||
|
WorkManager.getInstance(context)
|
||||||
|
.cancelUniqueWork(NAME)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,89 @@
|
|||||||
|
package pt.whatsms.gateway.modules.gateway.workers
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import androidx.work.BackoffPolicy
|
||||||
|
import androidx.work.Constraints
|
||||||
|
import androidx.work.CoroutineWorker
|
||||||
|
import androidx.work.ExistingWorkPolicy
|
||||||
|
import androidx.work.NetworkType
|
||||||
|
import androidx.work.OneTimeWorkRequestBuilder
|
||||||
|
import androidx.work.WorkManager
|
||||||
|
import androidx.work.WorkRequest
|
||||||
|
import androidx.work.WorkerParameters
|
||||||
|
import androidx.work.workDataOf
|
||||||
|
import pt.whatsms.gateway.App
|
||||||
|
import pt.whatsms.gateway.modules.gateway.GatewayService
|
||||||
|
import pt.whatsms.gateway.modules.logs.LogsService
|
||||||
|
import pt.whatsms.gateway.modules.logs.db.LogEntry
|
||||||
|
import org.koin.core.component.KoinComponent
|
||||||
|
import org.koin.core.component.inject
|
||||||
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
|
class RegistrationWorker(
|
||||||
|
appContext: Context,
|
||||||
|
params: WorkerParameters
|
||||||
|
) : CoroutineWorker(appContext, params), KoinComponent {
|
||||||
|
private val logsSvc: LogsService by inject()
|
||||||
|
|
||||||
|
override suspend fun doWork(): Result {
|
||||||
|
try {
|
||||||
|
val token = inputData.getString(DATA_TOKEN)
|
||||||
|
val isUpdate = inputData.getBoolean(DATA_IS_UPDATE, false)
|
||||||
|
|
||||||
|
when (isUpdate) {
|
||||||
|
true -> App.instance.gatewayService.updateDevice(token ?: return Result.success())
|
||||||
|
false -> App.instance.gatewayService.registerDevice(
|
||||||
|
token,
|
||||||
|
GatewayService.RegistrationMode.Anonymous
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return Result.success()
|
||||||
|
} catch (e: Exception) {
|
||||||
|
logsSvc.insert(
|
||||||
|
priority = LogEntry.Priority.ERROR,
|
||||||
|
module = NAME,
|
||||||
|
message = "Registration failed: ${e.message}",
|
||||||
|
context = mapOf(
|
||||||
|
"token" to inputData.getString(DATA_TOKEN)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
e.printStackTrace()
|
||||||
|
return Result.retry()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private const val NAME = "RegistrationWorker"
|
||||||
|
|
||||||
|
private const val DATA_TOKEN = "token"
|
||||||
|
private const val DATA_IS_UPDATE = "isUpdate"
|
||||||
|
|
||||||
|
fun start(context: Context, token: String?, isUpdate: Boolean) {
|
||||||
|
val work = OneTimeWorkRequestBuilder<RegistrationWorker>()
|
||||||
|
.setConstraints(
|
||||||
|
Constraints.Builder()
|
||||||
|
.setRequiredNetworkType(NetworkType.CONNECTED)
|
||||||
|
.build()
|
||||||
|
)
|
||||||
|
.setBackoffCriteria(
|
||||||
|
BackoffPolicy.EXPONENTIAL,
|
||||||
|
WorkRequest.MIN_BACKOFF_MILLIS,
|
||||||
|
TimeUnit.MILLISECONDS
|
||||||
|
)
|
||||||
|
.setInputData(
|
||||||
|
workDataOf(
|
||||||
|
DATA_TOKEN to token,
|
||||||
|
DATA_IS_UPDATE to isUpdate,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.build()
|
||||||
|
WorkManager.getInstance(context)
|
||||||
|
.enqueueUniqueWork(
|
||||||
|
NAME,
|
||||||
|
ExistingWorkPolicy.REPLACE,
|
||||||
|
work
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
package pt.whatsms.gateway.modules.gateway.workers
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import androidx.work.BackoffPolicy
|
||||||
|
import androidx.work.Constraints
|
||||||
|
import androidx.work.CoroutineWorker
|
||||||
|
import androidx.work.NetworkType
|
||||||
|
import androidx.work.OneTimeWorkRequestBuilder
|
||||||
|
import androidx.work.WorkManager
|
||||||
|
import androidx.work.WorkRequest
|
||||||
|
import androidx.work.WorkerParameters
|
||||||
|
import androidx.work.workDataOf
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
import pt.whatsms.gateway.modules.gateway.GatewayService
|
||||||
|
import pt.whatsms.gateway.modules.messages.MessagesService
|
||||||
|
import org.koin.core.component.KoinComponent
|
||||||
|
import org.koin.core.component.inject
|
||||||
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
|
class SendStateWorker(appContext: Context, params: WorkerParameters) :
|
||||||
|
CoroutineWorker(appContext, params), KoinComponent {
|
||||||
|
private val messagesService: MessagesService by inject()
|
||||||
|
private val gatewayService: GatewayService by inject()
|
||||||
|
override suspend fun doWork(): Result {
|
||||||
|
try {
|
||||||
|
val messageId = inputData.getString(MESSAGE_ID) ?: return Result.failure()
|
||||||
|
val message = messagesService.getMessage(messageId) ?: return Result.failure()
|
||||||
|
|
||||||
|
withContext(Dispatchers.IO) {
|
||||||
|
gatewayService.sendState(message)
|
||||||
|
}
|
||||||
|
return Result.success()
|
||||||
|
} catch (th: Throwable) {
|
||||||
|
th.printStackTrace()
|
||||||
|
return when {
|
||||||
|
this.runAttemptCount < RETRY_COUNT -> Result.retry()
|
||||||
|
else -> Result.failure()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private const val RETRY_COUNT = 10
|
||||||
|
|
||||||
|
private const val MESSAGE_ID = "messageId"
|
||||||
|
|
||||||
|
fun start(context: Context, messageId: String) {
|
||||||
|
val work = OneTimeWorkRequestBuilder<SendStateWorker>()
|
||||||
|
.setInputData(workDataOf(MESSAGE_ID to messageId))
|
||||||
|
.setBackoffCriteria(
|
||||||
|
BackoffPolicy.EXPONENTIAL,
|
||||||
|
WorkRequest.MIN_BACKOFF_MILLIS,
|
||||||
|
TimeUnit.MILLISECONDS
|
||||||
|
)
|
||||||
|
.setConstraints(
|
||||||
|
Constraints.Builder()
|
||||||
|
.setRequiredNetworkType(NetworkType.CONNECTED)
|
||||||
|
.build()
|
||||||
|
)
|
||||||
|
.build()
|
||||||
|
|
||||||
|
WorkManager.getInstance(context)
|
||||||
|
.enqueue(work)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,71 @@
|
|||||||
|
package pt.whatsms.gateway.modules.gateway.workers
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import androidx.work.BackoffPolicy
|
||||||
|
import androidx.work.Constraints
|
||||||
|
import androidx.work.CoroutineWorker
|
||||||
|
import androidx.work.ExistingPeriodicWorkPolicy
|
||||||
|
import androidx.work.NetworkType
|
||||||
|
import androidx.work.PeriodicWorkRequestBuilder
|
||||||
|
import androidx.work.WorkManager
|
||||||
|
import androidx.work.WorkRequest
|
||||||
|
import androidx.work.WorkerParameters
|
||||||
|
import pt.whatsms.gateway.modules.gateway.GatewayService
|
||||||
|
import pt.whatsms.gateway.modules.settings.SettingsService
|
||||||
|
import org.koin.core.component.KoinComponent
|
||||||
|
import org.koin.core.component.get
|
||||||
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
|
class SettingsUpdateWorker(appContext: Context, params: WorkerParameters) :
|
||||||
|
CoroutineWorker(appContext, params), KoinComponent {
|
||||||
|
override suspend fun doWork(): Result {
|
||||||
|
val gatewaySvc: GatewayService = get()
|
||||||
|
val settingsSvc: SettingsService = get()
|
||||||
|
|
||||||
|
return try {
|
||||||
|
val settings = gatewaySvc.getSettings()
|
||||||
|
|
||||||
|
settings?.let {
|
||||||
|
settingsSvc.update(settings)
|
||||||
|
}
|
||||||
|
|
||||||
|
Result.success()
|
||||||
|
} catch (th: Throwable) {
|
||||||
|
th.printStackTrace()
|
||||||
|
Result.retry()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private const val NAME = "SettingsUpdateWorker"
|
||||||
|
|
||||||
|
fun start(context: Context) {
|
||||||
|
val work = PeriodicWorkRequestBuilder<SettingsUpdateWorker>(
|
||||||
|
24,
|
||||||
|
TimeUnit.HOURS
|
||||||
|
)
|
||||||
|
.setBackoffCriteria(
|
||||||
|
BackoffPolicy.EXPONENTIAL,
|
||||||
|
WorkRequest.MIN_BACKOFF_MILLIS,
|
||||||
|
TimeUnit.MILLISECONDS
|
||||||
|
)
|
||||||
|
.setConstraints(
|
||||||
|
Constraints.Builder()
|
||||||
|
.setRequiredNetworkType(NetworkType.CONNECTED)
|
||||||
|
.build()
|
||||||
|
)
|
||||||
|
.build()
|
||||||
|
WorkManager.getInstance(context)
|
||||||
|
.enqueueUniquePeriodicWork(
|
||||||
|
NAME,
|
||||||
|
ExistingPeriodicWorkPolicy.REPLACE,
|
||||||
|
work
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun stop(context: Context) {
|
||||||
|
WorkManager.getInstance(context)
|
||||||
|
.cancelUniqueWork(NAME)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user