mirror of
https://github.com/kavishdevar/librepods.git
synced 2026-05-16 05:26:04 +00:00
Compare commits
73 Commits
v0.2.0
...
nightly-04
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
044aff731f | ||
|
|
216c97f9ca | ||
|
|
fd3774b513 | ||
|
|
b7336940e6 | ||
|
|
b2ba830a80 | ||
|
|
f08769e62f | ||
|
|
d1933c3b67 | ||
|
|
fb44f01ac0 | ||
|
|
93a93cbe68 | ||
|
|
a4898293b8 | ||
|
|
845f26192c | ||
|
|
3321bb1c43 | ||
|
|
c7a5cb2d8c | ||
|
|
7b81411417 | ||
|
|
d80f2275a1 | ||
|
|
795bebc6ae | ||
|
|
4ef3e4d4da | ||
|
|
b88b14de15 | ||
|
|
7cd4dfa3e0 | ||
|
|
30d16e9977 | ||
|
|
ddcf15eefe | ||
|
|
3e89d7f41b | ||
|
|
9eb6010a25 | ||
|
|
60e865fc1f | ||
|
|
629b7b917e | ||
|
|
d4ee741224 | ||
|
|
4c8b0d720d | ||
|
|
e20b0f7fd7 | ||
|
|
b64ff1d09e | ||
|
|
37056c6de7 | ||
|
|
3a636e37a4 | ||
|
|
136e3e8995 | ||
|
|
e39c1cfeba | ||
|
|
b06d780eee | ||
|
|
70f420dedb | ||
|
|
23193ceb39 | ||
|
|
cb246d1287 | ||
|
|
95cd677da9 | ||
|
|
0d049d93fb | ||
|
|
469d948061 | ||
|
|
f5d92768e2 | ||
|
|
8cb2951bc6 | ||
|
|
bb578dab23 | ||
|
|
b1b47048a3 | ||
|
|
bf09300dfe | ||
|
|
70165232c0 | ||
|
|
aabbc902cb | ||
|
|
0ee7056600 | ||
|
|
8b24ac49e2 | ||
|
|
d2dd722bc7 | ||
|
|
67fc93bde5 | ||
|
|
0b578d62cf | ||
|
|
072b9b4dac | ||
|
|
0af60cd8a9 | ||
|
|
be29a46dab | ||
|
|
7461f7dfb7 | ||
|
|
904c00afce | ||
|
|
6272357d84 | ||
|
|
6ac6700be6 | ||
|
|
113ee0a966 | ||
|
|
d82e4e2427 | ||
|
|
481d5f13cf | ||
|
|
ef221af505 | ||
|
|
c19190f031 | ||
|
|
d0b8574c68 | ||
|
|
294d733e71 | ||
|
|
f6d7e97796 | ||
|
|
ae174bc9ea | ||
|
|
1804e80cba | ||
|
|
0b8bd5a5b8 | ||
|
|
d1d48562d7 | ||
|
|
c84e64e656 | ||
|
|
51739514fa |
227
.github/workflows/ci-android.yml
vendored
227
.github/workflows/ci-android.yml
vendored
@@ -1,4 +1,4 @@
|
||||
name: Build APK and root module (and create nightly release)
|
||||
name: Android CI
|
||||
|
||||
on:
|
||||
push:
|
||||
@@ -6,95 +6,188 @@ on:
|
||||
- '*'
|
||||
paths:
|
||||
- 'android/**'
|
||||
pull_request:
|
||||
paths:
|
||||
- 'android/**'
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
release:
|
||||
description: 'Create a nightly release'
|
||||
branch:
|
||||
description: Branch to build
|
||||
required: true
|
||||
type: boolean
|
||||
default: false
|
||||
custom_notes:
|
||||
description: 'Custom updates to add to What''s Changed section'
|
||||
required: false
|
||||
type: string
|
||||
default: main
|
||||
workflow_call:
|
||||
|
||||
jobs:
|
||||
build-debug-apk:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
outputs:
|
||||
short_sha: ${{ steps.vars.outputs.short_sha }}
|
||||
app_version: ${{ steps.version.outputs.app_version }}
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: true
|
||||
ref: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.branch || github.ref }}
|
||||
- uses: actions/setup-java@v4
|
||||
with:
|
||||
distribution: 'zulu'
|
||||
distribution: zulu
|
||||
java-version: 21
|
||||
- uses: gradle/actions/setup-gradle@v4
|
||||
- name: Build debug APK
|
||||
run: ./gradlew assembleDebug
|
||||
- name: Decode keystore
|
||||
run: echo "${{ secrets.RELEASE_KEYSTORE_FILE }}" | base64 --decode > android/release.keystore
|
||||
- name: Setup Android SDK
|
||||
uses: android-actions/setup-android@v3
|
||||
- name: Accept Licenses
|
||||
run: yes | sdkmanager --licenses
|
||||
- name: Install NDK
|
||||
run: sdkmanager "ndk;30.0.14904198"
|
||||
- name: Create local.properties
|
||||
run: |
|
||||
cat <<EOF > android/local.properties
|
||||
RELEASE_STORE_FILE=../release.keystore
|
||||
RELEASE_STORE_PASSWORD=${{ secrets.RELEASE_STORE_PASSWORD }}
|
||||
RELEASE_KEY_ALIAS=${{ secrets.RELEASE_KEY_ALIAS }}
|
||||
RELEASE_KEY_PASSWORD=${{ secrets.RELEASE_KEY_PASSWORD }}
|
||||
EOF
|
||||
- name: Build
|
||||
run: ./gradlew packageReleaseArtifacts
|
||||
working-directory: android
|
||||
- name: Upload artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
- name: Get app version
|
||||
id: version
|
||||
run: echo "app_version=$(grep 'appVersionName =' android/app/build.gradle.kts | sed 's/.*= "\(.*\)"/\1/')" >> $GITHUB_OUTPUT
|
||||
- id: vars
|
||||
run: echo "short_sha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: Debug APK
|
||||
path: android/app/build/outputs/apk/**/*.apk
|
||||
nightly-release:
|
||||
name: apk-release
|
||||
path: release/*release.apk
|
||||
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: apk-debug
|
||||
path: release/*debug.apk
|
||||
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: root-module-release
|
||||
path: release/*release.zip
|
||||
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: root-module-debug
|
||||
path: release/*debug.zip
|
||||
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: release-bundle
|
||||
path: release/*.aab
|
||||
|
||||
release:
|
||||
if: github.event_name == 'push'
|
||||
runs-on: ubuntu-latest
|
||||
if: github.event_name == 'push' && github.ref == 'refs/heads/release-nightly' || github.event_name == 'workflow_dispatch' && github.event.inputs.release == 'true'
|
||||
needs: build-debug-apk
|
||||
needs: build
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
fetch-tags: true
|
||||
- uses: actions/download-artifact@v4
|
||||
- name: Export APK_NAME for later use
|
||||
run: echo "APK_NAME=LibrePods-$(echo ${{ github.sha }} | cut -c1-7).apk" >> $GITHUB_ENV
|
||||
- name: Rename .apk file
|
||||
run: mv "./Debug APK/debug/"*.apk "./$APK_NAME"
|
||||
- name: Decode keystore file
|
||||
run: echo "${{ secrets.DEBUG_KEYSTORE_FILE }}" | base64 --decode > debug.keystore
|
||||
- name: Install apksigner
|
||||
run: sudo apt-get update && sudo apt-get install -y apksigner
|
||||
- name: Sign APK
|
||||
run: |
|
||||
apksigner sign --ks debug.keystore --ks-key-alias androiddebugkey --ks-pass pass:android --key-pass pass:android "./$APK_NAME"
|
||||
- name: Verify APK
|
||||
run: apksigner verify "./$APK_NAME"
|
||||
- name: Fetch the latest non-nightly release tag
|
||||
id: fetch-tag
|
||||
run: echo "::set-output name=tag::$(git describe --tags $(git rev-list --tags --max-count=1))"
|
||||
- name: Retrieve commits since the last release
|
||||
id: get-commits
|
||||
run: |
|
||||
COMMITS=$(git log ${{ steps.fetch-tag.outputs.tag }}..HEAD --pretty=format:"- %s (%h)" --abbrev-commit)
|
||||
echo "::set-output name=commits::${COMMITS}"
|
||||
- name: Prepare release notes
|
||||
id: release-notes
|
||||
run: |
|
||||
# Create a temporary file for release notes
|
||||
NOTES_FILE=$(mktemp)
|
||||
|
||||
# Process custom notes if they exist
|
||||
if [ "${{ github.event_name }}" == "workflow_dispatch" ] && [ -n "${{ github.event.inputs.custom_notes }}" ]; then
|
||||
CUSTOM_NOTES="${{ github.event.inputs.custom_notes }}"
|
||||
|
||||
# Check if custom notes already have bullet points or GitHub-style formatting
|
||||
if echo "$CUSTOM_NOTES" | grep -q "^\*\|^- \|http.*commit\|in #[0-9]\+"; then
|
||||
# Already formatted, use as is
|
||||
echo "$CUSTOM_NOTES" > "$NOTES_FILE"
|
||||
else
|
||||
# Add bullet point formatting
|
||||
echo "- $CUSTOM_NOTES" > "$NOTES_FILE"
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "notes_file=$NOTES_FILE" >> $GITHUB_OUTPUT
|
||||
- name: Zip root-module directory
|
||||
run: sh ./build-magisk-module.sh
|
||||
- name: Delete release if exist then create release
|
||||
with:
|
||||
name: apk-release
|
||||
path: artifacts/apk-release
|
||||
|
||||
- uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: apk-debug
|
||||
path: artifacts/apk-debug
|
||||
|
||||
- uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: root-module-release
|
||||
path: artifacts/root-module-release
|
||||
|
||||
- uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: root-module-debug
|
||||
path: artifacts/root-module-debug
|
||||
- id: prev
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
gh release view "nightly" && gh release delete "nightly" -y --cleanup-tag
|
||||
gh release create "nightly" "./$APK_NAME" "./btl2capfix.zip" -p -t "Nightly Release" --notes-file "${{ steps.release-notes.outputs.notes_file }}" --generate-notes
|
||||
TAG=$(gh release list \
|
||||
--limit 1 \
|
||||
--json tagName \
|
||||
--jq '.[0].tagName')
|
||||
|
||||
echo "tag=$TAG" >> $GITHUB_OUTPUT
|
||||
- id: changelog
|
||||
run: |
|
||||
if [ -z "${{ steps.prev.outputs.tag }}" ]; then
|
||||
NOTES=$(git log --pretty=format:"- %s ([%h](https://github.com/kavishdevar/librepods/commit/%H))")
|
||||
else
|
||||
NOTES=$(git log ${{ steps.prev.outputs.tag }}..HEAD --pretty=format:"- %s ([%h](https://github.com/kavishdevar/librepods/commit/%H))")
|
||||
fi
|
||||
echo "notes<<EOF" >> $GITHUB_OUTPUT
|
||||
echo "$NOTES" >> $GITHUB_OUTPUT
|
||||
echo "EOF" >> $GITHUB_OUTPUT
|
||||
|
||||
- id: tag
|
||||
run: echo "tag=nightly-${{ needs.build.outputs.short_sha }}" >> $GITHUB_OUTPUT
|
||||
|
||||
- env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
gh release create "${{ steps.tag.outputs.tag }}" \
|
||||
artifacts/**/* \
|
||||
-t "Nightly ${{ needs.build.outputs.short_sha }}" \
|
||||
--notes "${{ steps.changelog.outputs.notes }}" \
|
||||
--prerelease
|
||||
- name: Get timestamp
|
||||
id: timestamp
|
||||
run: echo "timestamp=$(date -u +%Y-%m-%dT%H:%M:%SZ)" >> $GITHUB_OUTPUT
|
||||
- name: Post to Discord
|
||||
run: |
|
||||
curl -X POST "${{ secrets.DISCORD_ANDROID_CI_URL }}?with_components=true" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"embeds": [
|
||||
{
|
||||
"title": "LibrePods Nightly Build",
|
||||
"description": "Download the latest debug and release APKs.",
|
||||
"color": 253060,
|
||||
"fields": [
|
||||
{
|
||||
"name": "Changelog",
|
||||
"value": "${{ steps.changelog.outputs.notes }}",
|
||||
"inline": false
|
||||
}
|
||||
],
|
||||
"timestamp": "${{ steps.timestamp.outputs.timestamp }}",
|
||||
"footer": {
|
||||
"text": "GitHub Actions"
|
||||
}
|
||||
}
|
||||
],
|
||||
"components": [
|
||||
{
|
||||
"type": 1,
|
||||
"components": [
|
||||
{
|
||||
"type": 2,
|
||||
"label": "Download Release APK",
|
||||
"style": 5,
|
||||
"url": "https://github.com/kavishdevar/librepods/releases/download/nightly-${{ needs.build.outputs.short_sha }}/LibrePods-FOSS-v${{ needs.build.outputs.app_version }}-release.apk"
|
||||
},
|
||||
{
|
||||
"type": 2,
|
||||
"label": "Download Debug APK",
|
||||
"style": 5,
|
||||
"url": "https://github.com/kavishdevar/librepods/releases/download/nightly-${{ needs.build.outputs.short_sha }}/LibrePods-FOSS-v${{ needs.build.outputs.app_version }}-debug.apk"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}'
|
||||
|
||||
7
.gitignore
vendored
7
.gitignore
vendored
@@ -1,10 +1,5 @@
|
||||
root-module/radare2-5.9.9-android-aarch64.tar.gz
|
||||
wak.toml
|
||||
log.txt
|
||||
btl2capfix.zip
|
||||
root-module-manual
|
||||
release
|
||||
.vscode
|
||||
testing.py
|
||||
.DS_Store
|
||||
CMakeLists.txt.user*
|
||||
|
||||
|
||||
@@ -1,164 +0,0 @@
|
||||
# Bluetooth Low Energy (BLE) - Apple Proximity Pairing Message
|
||||
|
||||
This document describes how the AirPods BLE "Proximity Pairing Message" is parsed and interpreted in the application. This message is broadcast by Apple devices (such as AirPods) and contains key information about the device's state, battery, and other properties.
|
||||
|
||||
## Overview
|
||||
|
||||
When scanning for BLE devices, the application looks for manufacturer data with Apple's ID (`0x004C`). If the data starts with `0x07`, it is identified as a Proximity Pairing Message. The message contains various fields, each representing a specific property of the AirPods.
|
||||
|
||||
## Proximity Pairing Message Structure
|
||||
|
||||
| Byte Index | Field Name | Description | Example Value(s) |
|
||||
|------------|-------------------------|---------------------------------------------------------|--------------------------|
|
||||
| 0 | Prefix | Message type (should be `0x07` for proximity pairing) | `0x07` |
|
||||
| 1 | Length | Length of the message | `0x12` |
|
||||
| 2 | Pairing Mode | `0x01` = Paired, `0x00` = Pairing mode | `0x01`, `0x00` |
|
||||
| 3-4 | Device Model | Big-endian: [3]=high, [4]=low | `0x0E20` (AirPods Pro) |
|
||||
| 5 | Status | Bitfield, see below | `0x62` |
|
||||
| 6 | Pods Battery Byte | Nibbles for left/right pod battery | `0xA7` |
|
||||
| 7 | Flags & Case Battery | Upper nibble: case battery, lower: flags | `0xB3` |
|
||||
| 8 | Lid Indicator | Bits for lid state and open counter | `0x09` |
|
||||
| 9 | Device Color | Color code | `0x02` |
|
||||
| 10 | Connection State | Enum, see below | `0x04` |
|
||||
| 11-26 | Encrypted Payload | 16 bytes, not parsed | |
|
||||
|
||||
## Field Details
|
||||
|
||||
### Device Model
|
||||
|
||||
| Value (hex) | Model Name |
|
||||
|-------------|--------------------------|
|
||||
| 0x0220 | AirPods 1st Gen |
|
||||
| 0x0F20 | AirPods 2nd Gen |
|
||||
| 0x1320 | AirPods 3rd Gen |
|
||||
| 0x1920 | AirPods 4th Gen |
|
||||
| 0x1B20 | AirPods 4th Gen (ANC) |
|
||||
| 0x0A20 | AirPods Max |
|
||||
| 0x1F20 | AirPods Max (USB-C) |
|
||||
| 0x0E20 | AirPods Pro |
|
||||
| 0x1420 | AirPods Pro 2nd Gen |
|
||||
| 0x2420 | AirPods Pro 2nd Gen (USB-C) |
|
||||
|
||||
### Status Byte (Bitfield)
|
||||
|
||||
| Bit | Meaning | Value if Set |
|
||||
|-----|--------------------------------|-------------|
|
||||
| 0 | Right Pod In Ear (XOR logic) | true |
|
||||
| 1 | Right Pod In Ear (XOR logic) | true |
|
||||
| 2 | Both Pods In Case | true |
|
||||
| 3 | Left Pod In Ear (XOR logic) | true |
|
||||
| 4 | One Pod In Case | true |
|
||||
| 5 | Primary Pod (1=Left, 0=Right) | true/false |
|
||||
| 6 | This Pod In Case | true |
|
||||
|
||||
### Ear Detection Logic
|
||||
|
||||
The in-ear detection uses XOR logic based on:
|
||||
- Whether the right pod is primary (`areValuesFlipped`)
|
||||
- Whether this pod is in the case (`isThisPodInTheCase`)
|
||||
|
||||
```cpp
|
||||
bool xorFactor = areValuesFlipped ^ deviceInfo.isThisPodInTheCase;
|
||||
deviceInfo.isLeftPodInEar = xorFactor ? (status & 0x08) != 0 : (status & 0x02) != 0; // Bit 3 or 1
|
||||
deviceInfo.isRightPodInEar = xorFactor ? (status & 0x02) != 0 : (status & 0x08) != 0; // Bit 1 or 3
|
||||
```
|
||||
|
||||
### Primary Pod
|
||||
|
||||
Determined by bit 5 of the status byte:
|
||||
- `1` = Left pod is primary
|
||||
- `0` = Right pod is primary
|
||||
|
||||
This affects:
|
||||
1. Battery level interpretation (which nibble corresponds to which pod)
|
||||
2. Microphone assignment
|
||||
3. Ear detection logic
|
||||
|
||||
### Microphone Status
|
||||
|
||||
The active microphone is determined by:
|
||||
```cpp
|
||||
deviceInfo.isLeftPodMicrophone = primaryLeft ^ deviceInfo.isThisPodInTheCase;
|
||||
deviceInfo.isRightPodMicrophone = !primaryLeft ^ deviceInfo.isThisPodInTheCase;
|
||||
```
|
||||
|
||||
### Pods Battery Byte
|
||||
|
||||
- Upper nibble: one pod battery (depends on primary)
|
||||
- Lower nibble: other pod battery
|
||||
|
||||
| Value | Meaning |
|
||||
|-------|----------------|
|
||||
| 0x0-0x9 | 0-90% (x10) |
|
||||
| 0xA-0xE | 100% |
|
||||
| 0xF | Not available|
|
||||
|
||||
### Flags & Case Battery Byte
|
||||
|
||||
- Upper nibble: case battery (same encoding as pods)
|
||||
- Lower nibble: flags
|
||||
|
||||
#### Flags (Lower Nibble)
|
||||
|
||||
| Bit | Meaning |
|
||||
|-----|--------------------------|
|
||||
| 0 | Right Pod Charging (XOR) |
|
||||
| 1 | Left Pod Charging (XOR) |
|
||||
| 2 | Case Charging |
|
||||
|
||||
### Lid Indicator
|
||||
|
||||
| Bits | Meaning |
|
||||
|------|------------------------|
|
||||
| 0-2 | Lid Open Counter |
|
||||
| 3 | Lid State (0=Open, 1=Closed) |
|
||||
|
||||
### Device Color
|
||||
|
||||
| Value | Color |
|
||||
|-------|-------------|
|
||||
| 0x00 | White |
|
||||
| 0x01 | Black |
|
||||
| 0x02 | Red |
|
||||
| 0x03 | Blue |
|
||||
| 0x04 | Pink |
|
||||
| 0x05 | Gray |
|
||||
| 0x06 | Silver |
|
||||
| 0x07 | Gold |
|
||||
| 0x08 | Rose Gold |
|
||||
| 0x09 | Space Gray |
|
||||
| 0x0A | Dark Blue |
|
||||
| 0x0B | Light Blue |
|
||||
| 0x0C | Yellow |
|
||||
| 0x0D+ | Unknown |
|
||||
|
||||
### Connection State
|
||||
|
||||
| Value | State |
|
||||
|-------|--------------|
|
||||
| 0x00 | Disconnected |
|
||||
| 0x04 | Idle |
|
||||
| 0x05 | Music |
|
||||
| 0x06 | Call |
|
||||
| 0x07 | Ringing |
|
||||
| 0x09 | Hanging Up |
|
||||
| 0xFF | Unknown |
|
||||
|
||||
## Example Message
|
||||
|
||||
| Byte Index | Example Value | Description |
|
||||
|------------|--------------|----------------------------|
|
||||
| 0 | 0x07 | Proximity Pairing Message |
|
||||
| 1 | 0x12 | Length |
|
||||
| 2 | 0x01 | Paired |
|
||||
| 3-4 | 0x0E 0x20 | AirPods Pro |
|
||||
| 5 | 0x62 | Status |
|
||||
| 6 | 0xA7 | Pods Battery |
|
||||
| 7 | 0xB3 | Flags & Case Battery |
|
||||
| 8 | 0x09 | Lid Indicator |
|
||||
| 9 | 0x02 | Device Color |
|
||||
| 10 | 0x04 | Connection State (Idle) |
|
||||
|
||||
---
|
||||
|
||||
For further details, see [`BleManager`](linux/ble/blemanager.cpp) and [`BleScanner`](linux/ble/blescanner.cpp).
|
||||
19
README.md
19
README.md
@@ -76,10 +76,19 @@ https://github.com/user-attachments/assets/43911243-0576-4093-8c55-89c1db5ea533
|
||||
|
||||
### Root Requirement
|
||||
|
||||
If you are using ColorOS/OxygenOS 16, Android 16 QPR3, Android 17 Beta 3 or higher, you don't need root except for customizing transparency mode, setting up hearing aid, and use Bluetooth Multipoint. Changing ANC, conversational awareness, ear detection, and other customizations will work without root.
|
||||
LibrePods **may** require root depending on your device/OS and what features you want access to:
|
||||
|
||||
For everyone else:
|
||||
**You must have a rooted device with Xposed to use LibrePods on Android.**
|
||||
- Features requiring the VendorID hook ([the features marked with an asterisk here](https://github.com/kavishdevar/librepods#key-features)) will always require root regardless of your device/OS.
|
||||
- On **ColorOS/OxygenOS 16** and **Pixel devices on Android 16 QPR3** (with the latest Google Play system update), LibrePods does not need root for most features (except those requiring the VendorID hook mentioned above).
|
||||
- On other devices, LibrePods needs root because of a bug in the Android Bluetooth stack Fluoride/non-compliance of Apple with Bluetooth standards. You must have Xposed installed for the app to workaround this bug and connect to AirPods. [This issue is being tracked here](https://issuetracker.google.com/issues/371713238). Please do not comment on the issue thread. The issue has already been resolved and should be available in **Android 17** for all devices.
|
||||
|
||||
> [!IMPORTANT]
|
||||
> This workaround with Xposed is not guaranteed to work on all devices.
|
||||
|
||||
### Troubleshooting steps for common errors
|
||||
- Ensure the correct scope is set in LSPosed/Vector.
|
||||
- Ensure there is no root-hiding module preventing the hook from loading on the Bluetooth app.
|
||||
- Restart your phone after confirming the scope.
|
||||
|
||||
### A few notes
|
||||
|
||||
@@ -129,7 +138,7 @@ A huge thank you to everyone supporting the project!
|
||||
- MagicPods for Steam Deck ([website](https://magicpods.app/steamdeck/))
|
||||
- MagicPods - if you're looking for "LibrePods for Windows" ([ms store](https://apps.microsoft.com/store/detail/9P6SKKFKSHKM) [installer](https://magicpods.app/installer/MagicPods.appinstaller) | [website](https://magicpods.app/))
|
||||
|
||||
# Nightly / Development Builds
|
||||
# Nightly/Development Builds
|
||||
|
||||
Want to try the latest features before they're officially released? You can grab nightly builds from GitHub Actions:
|
||||
|
||||
@@ -140,7 +149,7 @@ Want to try the latest features before they're officially released? You can grab
|
||||
4. Extract the zip and install the `.apk` on your device
|
||||
|
||||
> [!NOTE]
|
||||
> You need to be signed in to GitHub to download artifacts. Nightly builds are debug-signed and may not auto-update — you may need to uninstall the stable version first.
|
||||
> You need to be signed in to GitHub to download artifacts. Nightly builds are debug-signed and may not auto-update. You may need to uninstall the stable version first.
|
||||
|
||||
### Linux (Rust)
|
||||
1. Go to the [Actions tab](https://github.com/kavishdevar/librepods/actions/workflows/ci-linux-rust.yml)
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import java.util.Properties
|
||||
|
||||
val appVersionName = "0.2.9"
|
||||
|
||||
plugins {
|
||||
alias(libs.plugins.android.application)
|
||||
alias(libs.plugins.kotlin.compose)
|
||||
@@ -26,18 +28,16 @@ android {
|
||||
|
||||
defaultConfig {
|
||||
applicationId = "me.kavishdevar.librepods"
|
||||
minSdk = 33
|
||||
targetSdk = 37
|
||||
versionCode = 28
|
||||
versionName = "0.2.0"
|
||||
versionCode = 52
|
||||
versionName = appVersionName
|
||||
}
|
||||
buildTypes {
|
||||
release {
|
||||
isMinifyEnabled = true
|
||||
isShrinkResources = true
|
||||
proguardFiles(
|
||||
getDefaultProguardFile("proguard-android-optimize.txt"),
|
||||
"proguard-rules.pro"
|
||||
getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro"
|
||||
)
|
||||
externalNativeBuild {
|
||||
cmake {
|
||||
@@ -46,18 +46,29 @@ android {
|
||||
}
|
||||
buildConfigField("Boolean", "PLAY_BUILD", "false")
|
||||
signingConfig = signingConfigs.getByName("release")
|
||||
defaultConfig {
|
||||
minSdk = 33
|
||||
}
|
||||
}
|
||||
debug {
|
||||
buildConfigField("Boolean", "PLAY_BUILD", "false")
|
||||
signingConfig = signingConfigs.getByName("release")
|
||||
versionNameSuffix = "-debug"
|
||||
defaultConfig {
|
||||
minSdk = 33
|
||||
}
|
||||
}
|
||||
create("playRelease") {
|
||||
initWith(getByName("release"))
|
||||
buildConfigField("Boolean", "PLAY_BUILD", "true")
|
||||
}
|
||||
productFlavors {
|
||||
create("foss") {
|
||||
dimension = "env"
|
||||
buildConfigField("Boolean", "PLAY_BUILD", "false")
|
||||
}
|
||||
create("playDebug") {
|
||||
initWith(getByName("debug"))
|
||||
create("play") {
|
||||
dimension = "env"
|
||||
buildConfigField("Boolean", "PLAY_BUILD", "true")
|
||||
versionNameSuffix = "-play"
|
||||
minSdk = 36
|
||||
}
|
||||
}
|
||||
compileOptions {
|
||||
@@ -80,39 +91,20 @@ android {
|
||||
}
|
||||
sourceSets {
|
||||
getByName("main") {
|
||||
res.directories+="src/main/res-apple"
|
||||
res.directories += "src/main/res-apple"
|
||||
}
|
||||
}
|
||||
|
||||
ndkVersion = "30.0.14904198"
|
||||
|
||||
flavorDimensions += "env"
|
||||
|
||||
productFlavors {
|
||||
create("normal") {
|
||||
dimension = "env"
|
||||
externalNativeBuild {
|
||||
cmake {
|
||||
arguments += "-DIS_XPOSED=OFF"
|
||||
}
|
||||
}
|
||||
}
|
||||
create("xposed") {
|
||||
dimension = "env"
|
||||
externalNativeBuild {
|
||||
cmake {
|
||||
arguments += "-DIS_XPOSED=ON"
|
||||
}
|
||||
}
|
||||
versionNameSuffix = "-xposed"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(platform(libs.androidx.compose.bom))
|
||||
implementation(libs.accompanist.permissions)
|
||||
implementation(libs.androidx.core.ktx)
|
||||
implementation(libs.androidx.lifecycle.process)
|
||||
implementation(libs.androidx.lifecycle.runtime.ktx)
|
||||
implementation(libs.androidx.activity.compose)
|
||||
implementation(libs.androidx.ui)
|
||||
@@ -135,15 +127,92 @@ dependencies {
|
||||
implementation(libs.backdrop)
|
||||
// implementation(libs.hilt)
|
||||
// implementation(libs.hilt.compiler)
|
||||
add("xposedCompileOnly", libs.libxposed.api)
|
||||
add("xposedImplementation", libs.libxposed.service)
|
||||
add("playReleaseImplementation", libs.billing)
|
||||
compileOnly(libs.libxposed.api)
|
||||
implementation(libs.libxposed.service)
|
||||
implementation(libs.play.review)
|
||||
implementation(libs.play.review.ktx)
|
||||
}
|
||||
|
||||
aboutLibraries {
|
||||
export{
|
||||
export {
|
||||
prettyPrint = true
|
||||
excludeFields = listOf("generated")
|
||||
outputFile = file("src/main/res/raw/aboutlibraries.json")
|
||||
}
|
||||
}
|
||||
|
||||
val rootModuleDir = rootProject.file("../root-module-manual")
|
||||
val releaseDir = rootProject.file("../release")
|
||||
|
||||
fun cap(s: String) = s.replaceFirstChar { it.uppercase() }
|
||||
|
||||
fun registerRootModuleZipTask(
|
||||
name: String,
|
||||
flavor: String,
|
||||
buildType: String
|
||||
) = tasks.register<Zip>(name) {
|
||||
|
||||
val variantTask = "assemble${cap(flavor)}${cap(buildType)}"
|
||||
dependsOn(variantTask)
|
||||
|
||||
val apkPath = "outputs/apk/$flavor/$buildType/app-$flavor-$buildType.apk"
|
||||
|
||||
from(rootModuleDir)
|
||||
|
||||
duplicatesStrategy = DuplicatesStrategy.WARN
|
||||
|
||||
from(layout.buildDirectory.file(apkPath)) {
|
||||
into("system/priv-app/LibrePods")
|
||||
rename { "LibrePods.apk" }
|
||||
}
|
||||
|
||||
delete(layout.buildDirectory.dir("outputs/rootModuleZips"))
|
||||
|
||||
archiveFileName.set("LibrePods-FOSS-v$appVersionName-$buildType.zip")
|
||||
destinationDirectory.set(layout.buildDirectory.dir("outputs/rootModuleZips"))
|
||||
}
|
||||
|
||||
val zipRelease = registerRootModuleZipTask(
|
||||
"zipReleaseModule",
|
||||
"foss",
|
||||
"release"
|
||||
)
|
||||
|
||||
val zipDebug = registerRootModuleZipTask(
|
||||
"zipDebugModule",
|
||||
"foss",
|
||||
"debug"
|
||||
)
|
||||
|
||||
val collect = tasks.register<Copy>("collectReleaseArtifacts") {
|
||||
|
||||
dependsOn(
|
||||
zipRelease,
|
||||
zipDebug,
|
||||
"bundlePlayRelease"
|
||||
)
|
||||
|
||||
into(releaseDir)
|
||||
|
||||
from(layout.buildDirectory.dir("outputs/apk/foss/release")) {
|
||||
include("*.apk")
|
||||
rename(".*", "LibrePods-FOSS-v$appVersionName-release.apk")
|
||||
}
|
||||
|
||||
from(layout.buildDirectory.dir("outputs/apk/foss/debug")) {
|
||||
include("*.apk")
|
||||
rename(".*", "LibrePods-FOSS-v$appVersionName-debug.apk")
|
||||
}
|
||||
|
||||
from(layout.buildDirectory.dir("outputs/bundle/playRelease")) {
|
||||
include("*.aab")
|
||||
}
|
||||
|
||||
from(layout.buildDirectory.dir("outputs/rootModuleZips")) {
|
||||
include("*.zip")
|
||||
}
|
||||
}
|
||||
|
||||
tasks.register("packageReleaseArtifacts") {
|
||||
dependsOn(collect)
|
||||
}
|
||||
|
||||
Binary file not shown.
3
android/app/proguard-rules.pro
vendored
3
android/app/proguard-rules.pro
vendored
@@ -20,5 +20,4 @@
|
||||
# hide the original source file name.
|
||||
#-renamesourcefileattribute SourceFile
|
||||
|
||||
-keep class androidx.compose.** { *; }
|
||||
-dontwarn androidx.compose.**
|
||||
-keep class me.kavishdevar.librepods.utils.KotlinModule { *; }
|
||||
|
||||
@@ -14,9 +14,18 @@
|
||||
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
||||
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
|
||||
<!-- <uses-permission-->
|
||||
<!-- android:name="android.permission.BLUETOOTH_PRIVILEGED"-->
|
||||
<!-- tools:ignore="ProtectedPermissions" />-->
|
||||
<uses-permission
|
||||
android:name="android.permission.BLUETOOTH_PRIVILEGED"
|
||||
tools:ignore="ProtectedPermissions" />
|
||||
<uses-permission
|
||||
android:name="android.permission.MODIFY_PHONE_STATE"
|
||||
tools:ignore="ProtectedPermissions" />
|
||||
<uses-permission
|
||||
android:name="android.permission.LOCAL_MAC_ADDRESS"
|
||||
tools:ignore="ProtectedPermissions" />
|
||||
<uses-permission
|
||||
android:name="android.permission.INTERACT_ACROSS_USERS"
|
||||
tools:ignore="ProtectedPermissions" />
|
||||
<uses-permission android:name="android.permission.BLUETOOTH" />
|
||||
<uses-permission
|
||||
android:name="android.permission.BLUETOOTH_SCAN"
|
||||
@@ -27,8 +36,6 @@
|
||||
<uses-permission android:name="android.permission.ANSWER_PHONE_CALLS" />
|
||||
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
|
||||
<!-- <uses-permission android:name="android.permission.INTERNET" />-->
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
|
||||
tools:ignore="ScopedStorage" />
|
||||
<!-- <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"-->
|
||||
<!-- android:maxSdkVersion="30" />-->
|
||||
<!-- <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"-->
|
||||
|
||||
@@ -3,8 +3,6 @@ cmake_minimum_required(VERSION 3.22.1)
|
||||
project("l2c_fcr_hook")
|
||||
set(CMAKE_CXX_STANDARD 23)
|
||||
|
||||
option(IS_XPOSED "Build Xposed components" OFF)
|
||||
|
||||
add_library(bluetooth_socket SHARED
|
||||
bluetooth_socket.cpp
|
||||
)
|
||||
@@ -24,40 +22,36 @@ target_link_libraries(bluetooth_socket
|
||||
log
|
||||
)
|
||||
|
||||
if(IS_XPOSED)
|
||||
|
||||
set(XPOSED_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../xposed/cpp)
|
||||
set(XPOSED_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../xposed/cpp)
|
||||
|
||||
add_library(l2c_fcr_hook SHARED
|
||||
${XPOSED_SRC_DIR}/l2c_fcr_hook.cpp
|
||||
add_library(l2c_fcr_hook SHARED
|
||||
l2c_fcr_hook.cpp
|
||||
|
||||
${XPOSED_SRC_DIR}/xz/xz_crc32.c
|
||||
${XPOSED_SRC_DIR}/xz/xz_crc64.c
|
||||
${XPOSED_SRC_DIR}/xz/xz_sha256.c
|
||||
${XPOSED_SRC_DIR}/xz/xz_dec_stream.c
|
||||
${XPOSED_SRC_DIR}/xz/xz_dec_lzma2.c
|
||||
${XPOSED_SRC_DIR}/xz/xz_dec_bcj.c
|
||||
)
|
||||
xz/xz_crc32.c
|
||||
xz/xz_crc64.c
|
||||
xz/xz_sha256.c
|
||||
xz/xz_dec_stream.c
|
||||
xz/xz_dec_lzma2.c
|
||||
xz/xz_dec_bcj.c
|
||||
)
|
||||
|
||||
target_include_directories(l2c_fcr_hook PRIVATE
|
||||
${XPOSED_SRC_DIR}
|
||||
${XPOSED_SRC_DIR}/xz
|
||||
)
|
||||
target_include_directories(l2c_fcr_hook PRIVATE
|
||||
xz
|
||||
)
|
||||
|
||||
target_compile_definitions(l2c_fcr_hook PRIVATE
|
||||
XZ_DEC_X86
|
||||
XZ_DEC_ARM
|
||||
XZ_DEC_ARMTHUMB
|
||||
XZ_DEC_ARM64
|
||||
XZ_DEC_ANY_CHECK
|
||||
XZ_USE_CRC64
|
||||
XZ_USE_SHA256
|
||||
XZ_DEC_CONCATENATED
|
||||
)
|
||||
target_compile_definitions(l2c_fcr_hook PRIVATE
|
||||
XZ_DEC_X86
|
||||
XZ_DEC_ARM
|
||||
XZ_DEC_ARMTHUMB
|
||||
XZ_DEC_ARM64
|
||||
XZ_DEC_ANY_CHECK
|
||||
XZ_USE_CRC64
|
||||
XZ_USE_SHA256
|
||||
XZ_DEC_CONCATENATED
|
||||
)
|
||||
|
||||
target_link_libraries(l2c_fcr_hook
|
||||
android
|
||||
log
|
||||
)
|
||||
|
||||
endif()
|
||||
target_link_libraries(l2c_fcr_hook
|
||||
android
|
||||
log
|
||||
)
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
#include "l2c_fcr_hook.h"
|
||||
|
||||
extern "C" {
|
||||
#include "xz.h"
|
||||
#include "xz.h"
|
||||
}
|
||||
|
||||
#define LOG_TAG "LibrePodsHook"
|
||||
@@ -39,13 +39,13 @@ extern "C" {
|
||||
|
||||
static HookFunType hook_func = nullptr;
|
||||
|
||||
static uint8_t (*original_l2c_fcr_chk_chan_modes)(void*) = nullptr;
|
||||
static tBTA_STATUS (*original_BTA_DmSetLocalDiRecord)(
|
||||
tSDP_DI_RECORD*, uint32_t*) = nullptr;
|
||||
static uint8_t (*original_l2c_fcr_chk_chan_modes)(void *) = nullptr;
|
||||
|
||||
static tBTA_STATUS (*original_BTA_DmSetLocalDiRecord)(tSDP_DI_RECORD *, uint32_t *) = nullptr;
|
||||
|
||||
static std::atomic<bool> enableSdpHook(false);
|
||||
|
||||
uint8_t fake_l2c_fcr_chk_chan_modes(void* p_ccb) {
|
||||
uint8_t fake_l2c_fcr_chk_chan_modes(void *p_ccb) {
|
||||
LOGI("fake_l2c_fcr_chk_chan_modes called");
|
||||
uint8_t orig = 0;
|
||||
if (original_l2c_fcr_chk_chan_modes)
|
||||
@@ -55,13 +55,13 @@ uint8_t fake_l2c_fcr_chk_chan_modes(void* p_ccb) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
tBTA_STATUS fake_BTA_DmSetLocalDiRecord(
|
||||
tSDP_DI_RECORD* p_device_info,
|
||||
uint32_t* p_handle) {
|
||||
tBTA_STATUS fake_BTA_DmSetLocalDiRecord(tSDP_DI_RECORD *p_device_info, uint32_t *p_handle) {
|
||||
|
||||
LOGI("fake_BTA_DmSetLocalDiRecord called");
|
||||
|
||||
if (original_BTA_DmSetLocalDiRecord && enableSdpHook.load(std::memory_order_relaxed)) original_BTA_DmSetLocalDiRecord(p_device_info, p_handle);
|
||||
if (original_BTA_DmSetLocalDiRecord &&
|
||||
enableSdpHook.load(std::memory_order_relaxed))
|
||||
original_BTA_DmSetLocalDiRecord(p_device_info, p_handle);
|
||||
|
||||
LOGI("fake_BTA_DmSetLocalDiRecord: modifying vendor to 0x004C, vendor_id_source to 0x0001");
|
||||
|
||||
@@ -70,14 +70,15 @@ tBTA_STATUS fake_BTA_DmSetLocalDiRecord(
|
||||
p_device_info->vendor_id_source = 0x0001;
|
||||
}
|
||||
|
||||
LOGI("fake_BTA_DmSetLocalDiRecord: returning status %d", original_BTA_DmSetLocalDiRecord ? original_BTA_DmSetLocalDiRecord(p_device_info, p_handle) : BTA_FAILURE);
|
||||
return original_BTA_DmSetLocalDiRecord ? original_BTA_DmSetLocalDiRecord(p_device_info, p_handle) : BTA_FAILURE;
|
||||
LOGI("fake_BTA_DmSetLocalDiRecord: returning status %d",
|
||||
original_BTA_DmSetLocalDiRecord ? original_BTA_DmSetLocalDiRecord(p_device_info, p_handle)
|
||||
: BTA_FAILURE);
|
||||
return original_BTA_DmSetLocalDiRecord ? original_BTA_DmSetLocalDiRecord(p_device_info,
|
||||
p_handle)
|
||||
: BTA_FAILURE;
|
||||
}
|
||||
|
||||
static bool decompressXZ(
|
||||
const uint8_t* input,
|
||||
size_t input_size,
|
||||
std::vector<uint8_t>& output) {
|
||||
static bool decompressXZ(const uint8_t *input, size_t input_size, std::vector<uint8_t> &output) {
|
||||
|
||||
LOGI("decompressXZ called with input_size: %zu", input_size);
|
||||
|
||||
@@ -86,7 +87,7 @@ static bool decompressXZ(
|
||||
xz_crc64_init();
|
||||
#endif
|
||||
|
||||
struct xz_dec* dec = xz_dec_init(XZ_DYNALLOC, 64U << 20);
|
||||
struct xz_dec *dec = xz_dec_init(XZ_DYNALLOC, 64U << 20);
|
||||
if (!dec) {
|
||||
LOGE("decompressXZ: xz_dec_init failed");
|
||||
return false;
|
||||
@@ -106,7 +107,8 @@ static bool decompressXZ(
|
||||
|
||||
LOGI("decompressXZ: entering decompression loop");
|
||||
while (true) {
|
||||
LOGI("decompressXZ: xz_dec_run iteration, buf.in_pos: %zu, buf.out_pos: %zu", buf.in_pos, buf.out_pos);
|
||||
LOGI("decompressXZ: xz_dec_run iteration, buf.in_pos: %zu, buf.out_pos: %zu", buf.in_pos,
|
||||
buf.out_pos);
|
||||
enum xz_ret ret = xz_dec_run(dec, &buf);
|
||||
|
||||
LOGI("decompressXZ: xz_dec_run returned %d", ret);
|
||||
@@ -135,10 +137,10 @@ static bool decompressXZ(
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool getLibraryPath(const char* name, std::string& out) {
|
||||
static bool getLibraryPath(const char *name, std::string &out) {
|
||||
LOGI("getLibraryPath called with name: %s", name);
|
||||
|
||||
FILE* fp = fopen("/proc/self/maps", "r");
|
||||
FILE *fp = fopen("/proc/self/maps", "r");
|
||||
if (!fp) {
|
||||
LOGE("getLibraryPath: fopen failed");
|
||||
return false;
|
||||
@@ -150,7 +152,7 @@ static bool getLibraryPath(const char* name, std::string& out) {
|
||||
while (fgets(line, sizeof(line), fp)) {
|
||||
if (strstr(line, name)) {
|
||||
LOGI("getLibraryPath: found line containing %s", name);
|
||||
char* path = strchr(line, '/');
|
||||
char *path = strchr(line, '/');
|
||||
if (path) {
|
||||
out = path;
|
||||
out.erase(out.find('\n'));
|
||||
@@ -166,10 +168,10 @@ static bool getLibraryPath(const char* name, std::string& out) {
|
||||
return false;
|
||||
}
|
||||
|
||||
static uintptr_t getModuleBase(const char* name) {
|
||||
static uintptr_t getModuleBase(const char *name) {
|
||||
LOGI("getModuleBase called with name: %s", name);
|
||||
|
||||
FILE* fp = fopen("/proc/self/maps", "r");
|
||||
FILE *fp = fopen("/proc/self/maps", "r");
|
||||
if (!fp) {
|
||||
LOGE("getModuleBase: fopen failed");
|
||||
return 0;
|
||||
@@ -192,26 +194,78 @@ static uintptr_t getModuleBase(const char* name) {
|
||||
return base;
|
||||
}
|
||||
|
||||
static uint64_t findSymbolOffset(
|
||||
const std::vector<uint8_t>& elf,
|
||||
const char* symbol_substring) {
|
||||
static uint64_t
|
||||
findSymbolOffsetDynsym(const std::vector<uint8_t> &elf, const char *symbol_substring) {
|
||||
|
||||
LOGI("findSymbolOffsetDynsym called with %s", symbol_substring);
|
||||
|
||||
auto *eh = reinterpret_cast<const Elf64_Ehdr *>(elf.data());
|
||||
auto *shdr = reinterpret_cast<const Elf64_Shdr *>(
|
||||
elf.data() + eh->e_shoff);
|
||||
|
||||
const char *shstr = reinterpret_cast<const char *>(
|
||||
elf.data() + shdr[eh->e_shstrndx].sh_offset);
|
||||
|
||||
const Elf64_Shdr *dynsym = nullptr;
|
||||
const Elf64_Shdr *dynstr = nullptr;
|
||||
|
||||
for (int i = 0; i < eh->e_shnum; ++i) {
|
||||
const char *secname = shstr + shdr[i].sh_name;
|
||||
|
||||
if (!strcmp(secname, ".dynsym"))
|
||||
dynsym = &shdr[i];
|
||||
if (!strcmp(secname, ".dynstr"))
|
||||
dynstr = &shdr[i];
|
||||
}
|
||||
|
||||
if (!dynsym || !dynstr) {
|
||||
LOGE("findSymbolOffsetDynsym: dynsym or dynstr not found");
|
||||
return 0;
|
||||
}
|
||||
|
||||
auto *symbols = reinterpret_cast<const Elf64_Sym *>(
|
||||
elf.data() + dynsym->sh_offset);
|
||||
|
||||
const char *strings = reinterpret_cast<const char *>(
|
||||
elf.data() + dynstr->sh_offset);
|
||||
|
||||
size_t count = dynsym->sh_size / sizeof(Elf64_Sym);
|
||||
|
||||
LOGI("findSymbolOffsetDynsym: scanning %zu symbols", count);
|
||||
|
||||
for (size_t i = 0; i < count; ++i) {
|
||||
const char *name = strings + symbols[i].st_name;
|
||||
|
||||
if (strstr(name, symbol_substring) && ELF64_ST_TYPE(symbols[i].st_info) == STT_FUNC) {
|
||||
|
||||
LOGI("findSymbolOffsetDynsym: matched %s @ 0x%lx", name,
|
||||
(unsigned long) symbols[i].st_value);
|
||||
|
||||
return symbols[i].st_value;
|
||||
}
|
||||
}
|
||||
|
||||
LOGI("findSymbolOffsetDynsym: no match for %s", symbol_substring);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static uint64_t findSymbolOffset(const std::vector<uint8_t> &elf, const char *symbol_substring) {
|
||||
|
||||
LOGI("findSymbolOffset called with symbol_substring: %s", symbol_substring);
|
||||
|
||||
auto* eh = reinterpret_cast<const Elf64_Ehdr*>(elf.data());
|
||||
auto* shdr = reinterpret_cast<const Elf64_Shdr*>(
|
||||
auto *eh = reinterpret_cast<const Elf64_Ehdr *>(elf.data());
|
||||
auto *shdr = reinterpret_cast<const Elf64_Shdr *>(
|
||||
elf.data() + eh->e_shoff);
|
||||
|
||||
const char* shstr =
|
||||
reinterpret_cast<const char*>(
|
||||
elf.data() + shdr[eh->e_shstrndx].sh_offset);
|
||||
const char *shstr = reinterpret_cast<const char *>(
|
||||
elf.data() + shdr[eh->e_shstrndx].sh_offset);
|
||||
|
||||
const Elf64_Shdr* symtab = nullptr;
|
||||
const Elf64_Shdr* strtab = nullptr;
|
||||
const Elf64_Shdr *symtab = nullptr;
|
||||
const Elf64_Shdr *strtab = nullptr;
|
||||
|
||||
LOGI("findSymbolOffset: parsing ELF sections");
|
||||
for (int i = 0; i < eh->e_shnum; ++i) {
|
||||
const char* secname = shstr + shdr[i].sh_name;
|
||||
const char *secname = shstr + shdr[i].sh_name;
|
||||
if (!strcmp(secname, ".symtab"))
|
||||
symtab = &shdr[i];
|
||||
if (!strcmp(secname, ".strtab"))
|
||||
@@ -224,23 +278,22 @@ static uint64_t findSymbolOffset(
|
||||
}
|
||||
LOGI("findSymbolOffset: found symtab and strtab");
|
||||
|
||||
auto* symbols = reinterpret_cast<const Elf64_Sym*>(
|
||||
auto *symbols = reinterpret_cast<const Elf64_Sym *>(
|
||||
elf.data() + symtab->sh_offset);
|
||||
|
||||
const char* strings =
|
||||
reinterpret_cast<const char*>(
|
||||
elf.data() + strtab->sh_offset);
|
||||
const char *strings = reinterpret_cast<const char *>(
|
||||
elf.data() + strtab->sh_offset);
|
||||
|
||||
size_t count = symtab->sh_size / sizeof(Elf64_Sym);
|
||||
|
||||
LOGI("findSymbolOffset: scanning %zu symbols", count);
|
||||
for (size_t i = 0; i < count; ++i) {
|
||||
const char* name = strings + symbols[i].st_name;
|
||||
const char *name = strings + symbols[i].st_name;
|
||||
|
||||
if (strstr(name, symbol_substring) &&
|
||||
ELF64_ST_TYPE(symbols[i].st_info) == STT_FUNC) {
|
||||
if (strstr(name, symbol_substring) && ELF64_ST_TYPE(symbols[i].st_info) == STT_FUNC) {
|
||||
|
||||
LOGI("findSymbolOffset: matched symbol %s at 0x%lx", name, (unsigned long)symbols[i].st_value);
|
||||
LOGI("findSymbolOffset: matched symbol %s at 0x%lx", name,
|
||||
(unsigned long) symbols[i].st_value);
|
||||
|
||||
return symbols[i].st_value;
|
||||
}
|
||||
@@ -250,7 +303,7 @@ static uint64_t findSymbolOffset(
|
||||
return 0;
|
||||
}
|
||||
|
||||
static bool hookLibrary(const char* libname) {
|
||||
static bool hookLibrary(const char *libname) {
|
||||
LOGI("hookLibrary called with libname: %s", libname);
|
||||
|
||||
if (!hook_func) {
|
||||
@@ -277,89 +330,78 @@ static bool hookLibrary(const char* libname) {
|
||||
close(fd);
|
||||
return false;
|
||||
}
|
||||
LOGI("hookLibrary: opened file, size: %lld", (long long)st.st_size);
|
||||
LOGI("hookLibrary: opened file, size: %lld", (long long) st.st_size);
|
||||
|
||||
std::vector<uint8_t> file(st.st_size);
|
||||
read(fd, file.data(), st.st_size);
|
||||
close(fd);
|
||||
|
||||
auto* eh = reinterpret_cast<Elf64_Ehdr*>(file.data());
|
||||
auto* shdr = reinterpret_cast<Elf64_Shdr*>(
|
||||
auto *eh = reinterpret_cast<Elf64_Ehdr *>(file.data());
|
||||
auto *shdr = reinterpret_cast<Elf64_Shdr *>(
|
||||
file.data() + eh->e_shoff);
|
||||
|
||||
const char* shstr =
|
||||
reinterpret_cast<const char*>(
|
||||
file.data() + shdr[eh->e_shstrndx].sh_offset);
|
||||
const char *shstr = reinterpret_cast<const char *>(
|
||||
file.data() + shdr[eh->e_shstrndx].sh_offset);
|
||||
|
||||
uint64_t chk_offset = 0;
|
||||
uint64_t sdp_offset = 0;
|
||||
|
||||
LOGI("hookLibrary: parsing ELF header and sections");
|
||||
for (int i = 0; i < eh->e_shnum; ++i) {
|
||||
|
||||
if (!strcmp(shstr + shdr[i].sh_name, ".gnu_debugdata")) {
|
||||
LOGI("hookLibrary: found .gnu_debugdata section");
|
||||
|
||||
std::vector<uint8_t> compressed(
|
||||
file.begin() + shdr[i].sh_offset,
|
||||
file.begin() + shdr[i].sh_offset + shdr[i].sh_size);
|
||||
std::vector<uint8_t> compressed(file.begin() + shdr[i].sh_offset,
|
||||
file.begin() + shdr[i].sh_offset + shdr[i].sh_size);
|
||||
|
||||
std::vector<uint8_t> decompressed;
|
||||
|
||||
if (!decompressXZ(
|
||||
compressed.data(),
|
||||
compressed.size(),
|
||||
decompressed)) {
|
||||
LOGE("hookLibrary: decompressXZ failed");
|
||||
return false;
|
||||
}
|
||||
LOGI("hookLibrary: decompressed debug data, size: %zu", decompressed.size());
|
||||
if (decompressXZ(compressed.data(), compressed.size(), decompressed)) {
|
||||
|
||||
uintptr_t base = getModuleBase(libname);
|
||||
if (!base) {
|
||||
LOGE("hookLibrary: getModuleBase failed");
|
||||
return false;
|
||||
}
|
||||
LOGI("hookLibrary: module base: 0x%lx", base);
|
||||
chk_offset = findSymbolOffset(decompressed, "l2c_fcr_chk_chan_modes");
|
||||
|
||||
uint64_t chk_offset =
|
||||
findSymbolOffset(decompressed,
|
||||
"l2c_fcr_chk_chan_modes");
|
||||
|
||||
uint64_t sdp_offset =
|
||||
findSymbolOffset(decompressed,
|
||||
"BTA_DmSetLocalDiRecord");
|
||||
|
||||
LOGI("hookLibrary: chk_offset: 0x%lx, sdp_offset: 0x%lx", chk_offset, sdp_offset);
|
||||
|
||||
if (chk_offset) {
|
||||
void* target =
|
||||
reinterpret_cast<void*>(base + chk_offset);
|
||||
|
||||
hook_func(target,
|
||||
(void*)fake_l2c_fcr_chk_chan_modes,
|
||||
(void**)&original_l2c_fcr_chk_chan_modes);
|
||||
|
||||
LOGI("hookLibrary: hooked l2c_fcr_chk_chan_modes");
|
||||
sdp_offset = findSymbolOffset(decompressed, "BTA_DmSetLocalDiRecord");
|
||||
} else {
|
||||
LOGE("debugdata decompress failed");
|
||||
}
|
||||
|
||||
if (sdp_offset) {
|
||||
void* target =
|
||||
reinterpret_cast<void*>(base + sdp_offset);
|
||||
|
||||
hook_func(target,
|
||||
(void*)fake_BTA_DmSetLocalDiRecord,
|
||||
(void**)&original_BTA_DmSetLocalDiRecord);
|
||||
|
||||
LOGI("hookLibrary: hooked BTA_DmSetLocalDiRecord");
|
||||
}
|
||||
|
||||
return true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
LOGI("hookLibrary: failed for %s", libname);
|
||||
return false;
|
||||
if (!chk_offset) {
|
||||
LOGI("fallback dynsym chk");
|
||||
chk_offset = findSymbolOffsetDynsym(file, "l2c_fcr_chk_chan_modes");
|
||||
}
|
||||
|
||||
if (!sdp_offset) {
|
||||
LOGI("fallback dynsym sdp");
|
||||
sdp_offset = findSymbolOffsetDynsym(file, "BTA_DmSetLocalDiRecord");
|
||||
}
|
||||
|
||||
uintptr_t base = getModuleBase(libname);
|
||||
if (!base) {
|
||||
LOGE("hookLibrary: getModuleBase failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (chk_offset) {
|
||||
void *target = reinterpret_cast<void *>(base + chk_offset);
|
||||
hook_func(target, (void *) fake_l2c_fcr_chk_chan_modes,
|
||||
(void **) &original_l2c_fcr_chk_chan_modes);
|
||||
LOGI("hooked chk");
|
||||
}
|
||||
|
||||
if (sdp_offset) {
|
||||
void *target = reinterpret_cast<void *>(base + sdp_offset);
|
||||
hook_func(target, (void *) fake_BTA_DmSetLocalDiRecord,
|
||||
(void **) &original_BTA_DmSetLocalDiRecord);
|
||||
LOGI("hooked sdp");
|
||||
}
|
||||
|
||||
return chk_offset || sdp_offset;
|
||||
}
|
||||
|
||||
static void on_library_loaded(const char* name, void*) {
|
||||
static void on_library_loaded(const char *name, void *) {
|
||||
LOGI("on_library_loaded called with name: %s", name);
|
||||
|
||||
if (strstr(name, "libbluetooth_jni.so")) {
|
||||
@@ -373,20 +415,19 @@ static void on_library_loaded(const char* name, void*) {
|
||||
}
|
||||
}
|
||||
|
||||
extern "C"
|
||||
[[gnu::visibility("default")]]
|
||||
extern "C" [[gnu::visibility("default")]]
|
||||
[[gnu::used]]
|
||||
NativeOnModuleLoaded native_init(const NativeAPIEntries* entries) {
|
||||
NativeOnModuleLoaded native_init(const NativeAPIEntries *entries) {
|
||||
LOGI("native_init called with entries: %p", entries);
|
||||
hook_func = (HookFunType)entries->hook_func;
|
||||
LOGI("LibrePodsNativeHook initialized, sdp hook enabled: %d", enableSdpHook.load(std::memory_order_relaxed));
|
||||
hook_func = (HookFunType) entries->hook_func;
|
||||
LOGI("LibrePodsNativeHook initialized, sdp hook enabled: %d",
|
||||
enableSdpHook.load(std::memory_order_relaxed));
|
||||
return on_library_loaded;
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT void JNICALL
|
||||
Java_me_kavishdevar_librepods_utils_NativeBridge_setSdpHook(
|
||||
JNIEnv*, jobject thiz, jboolean enable) {
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_me_kavishdevar_librepods_utils_NativeBridge_setSdpHook(JNIEnv *, jobject thiz,
|
||||
jboolean enable) {
|
||||
LOGI("setSdpHook called with enable: %d", enable);
|
||||
enableSdpHook.store(enable, std::memory_order_relaxed);
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
package me.kavishdevar.librepods
|
||||
|
||||
import android.app.Application
|
||||
import androidx.lifecycle.DefaultLifecycleObserver
|
||||
import androidx.lifecycle.LifecycleOwner
|
||||
import androidx.lifecycle.ProcessLifecycleOwner
|
||||
import io.github.libxposed.service.XposedService
|
||||
import io.github.libxposed.service.XposedServiceHelper
|
||||
import me.kavishdevar.librepods.billing.BillingManager
|
||||
import me.kavishdevar.librepods.billing.BillingProviderFactory
|
||||
import me.kavishdevar.librepods.utils.XposedServiceHolder
|
||||
import me.kavishdevar.librepods.utils.XposedState
|
||||
|
||||
class LibrePodsApplication: Application(), XposedServiceHelper.OnServiceListener, DefaultLifecycleObserver {
|
||||
|
||||
override fun onCreate() {
|
||||
XposedServiceHelper.registerListener(this)
|
||||
BillingManager.provider = BillingProviderFactory.create(this)
|
||||
ProcessLifecycleOwner.get().lifecycle.addObserver(this)
|
||||
|
||||
super<Application>.onCreate()
|
||||
|
||||
}
|
||||
|
||||
override fun onResume(owner: LifecycleOwner) {
|
||||
BillingManager.provider.queryPurchases()
|
||||
XposedState.isAvailable = XposedServiceHolder.service != null
|
||||
XposedState.bluetoothScopeEnabled = XposedServiceHolder.service?.scope?.contains("com.google.android.bluetooth") == true || XposedServiceHolder.service?.scope?.contains("com.android.bluetooth") == true
|
||||
}
|
||||
|
||||
override fun onServiceBind(service: XposedService) {
|
||||
XposedServiceHolder.service = service
|
||||
XposedState.isAvailable = true
|
||||
XposedState.bluetoothScopeEnabled = XposedServiceHolder.service?.scope?.contains("com.google.android.bluetooth") == true || XposedServiceHolder.service?.scope?.contains("com.android.bluetooth") == true
|
||||
}
|
||||
|
||||
override fun onServiceDied(p0: XposedService) {
|
||||
XposedServiceHolder.service = null
|
||||
XposedState.isAvailable = false
|
||||
}
|
||||
}
|
||||
@@ -24,6 +24,7 @@ package me.kavishdevar.librepods
|
||||
// import me.kavishdevar.librepods.utils.RadareOffsetFinder
|
||||
//import dagger.hilt.android.AndroidEntryPoint
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.Activity
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.ComponentName
|
||||
import android.content.Context
|
||||
@@ -52,7 +53,6 @@ import androidx.compose.animation.slideInHorizontally
|
||||
import androidx.compose.animation.slideOutHorizontally
|
||||
import androidx.compose.foundation.Canvas
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.gestures.detectTapGestures
|
||||
import androidx.compose.foundation.isSystemInDarkTheme
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
@@ -64,7 +64,6 @@ import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
@@ -81,8 +80,6 @@ import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableIntStateOf
|
||||
import androidx.compose.runtime.mutableLongStateOf
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
@@ -94,8 +91,6 @@ import androidx.compose.ui.geometry.Offset
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.drawscope.rotate
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import androidx.compose.ui.input.pointer.PointerEventPass
|
||||
import androidx.compose.ui.input.pointer.pointerInput
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.platform.LocalWindowInfo
|
||||
import androidx.compose.ui.res.stringResource
|
||||
@@ -117,17 +112,16 @@ import com.google.accompanist.permissions.ExperimentalPermissionsApi
|
||||
import com.google.accompanist.permissions.MultiplePermissionsState
|
||||
import com.google.accompanist.permissions.isGranted
|
||||
import com.google.accompanist.permissions.rememberMultiplePermissionsState
|
||||
import com.google.android.play.core.review.ReviewManagerFactory
|
||||
import com.kyant.backdrop.backdrops.layerBackdrop
|
||||
import com.kyant.backdrop.backdrops.rememberLayerBackdrop
|
||||
import dev.chrisbanes.haze.hazeSource
|
||||
import dev.chrisbanes.haze.materials.ExperimentalHazeMaterialsApi
|
||||
import dev.chrisbanes.haze.rememberHazeState
|
||||
import kotlinx.coroutines.delay
|
||||
import me.kavishdevar.librepods.billing.BillingManager
|
||||
import me.kavishdevar.librepods.billing.BillingProviderFactory
|
||||
import me.kavishdevar.librepods.data.AirPodsNotifications
|
||||
import me.kavishdevar.librepods.data.ControlCommandRepository
|
||||
import me.kavishdevar.librepods.presentation.components.ConfirmationDialog
|
||||
import me.kavishdevar.librepods.presentation.components.AppInfoCard
|
||||
import me.kavishdevar.librepods.presentation.components.DeviceInfoCard
|
||||
import me.kavishdevar.librepods.presentation.components.StyledIconButton
|
||||
import me.kavishdevar.librepods.presentation.screens.AccessibilitySettingsScreen
|
||||
import me.kavishdevar.librepods.presentation.screens.AdaptiveStrengthScreen
|
||||
@@ -147,22 +141,25 @@ import me.kavishdevar.librepods.presentation.screens.TransparencySettingsScreen
|
||||
import me.kavishdevar.librepods.presentation.screens.TroubleshootingScreen
|
||||
import me.kavishdevar.librepods.presentation.screens.UpdateHearingTestScreen
|
||||
import me.kavishdevar.librepods.presentation.screens.VersionScreen
|
||||
import me.kavishdevar.librepods.presentation.theme.LibrePodsTheme
|
||||
import me.kavishdevar.librepods.presentation.viewmodel.AirPodsViewModel
|
||||
import me.kavishdevar.librepods.presentation.viewmodel.AppSettingsViewModel
|
||||
import me.kavishdevar.librepods.presentation.viewmodel.PurchaseViewModel
|
||||
import me.kavishdevar.librepods.services.AirPodsService
|
||||
import me.kavishdevar.librepods.utils.XposedState
|
||||
import me.kavishdevar.librepods.utils.isSupported
|
||||
import kotlin.io.encoding.ExperimentalEncodingApi
|
||||
|
||||
lateinit var serviceConnection: ServiceConnection
|
||||
lateinit var connectionStatusReceiver: BroadcastReceiver
|
||||
lateinit var testReviewReceiver: BroadcastReceiver
|
||||
|
||||
//@AndroidEntryPoint
|
||||
@ExperimentalMaterial3Api
|
||||
class MainActivity : ComponentActivity() {
|
||||
companion object {
|
||||
init {
|
||||
if (BuildConfig.FLAVOR == "xposed") {
|
||||
if (XposedState.isAvailable && XposedState.bluetoothScopeEnabled) {
|
||||
System.loadLibrary("l2c_fcr_hook")
|
||||
}
|
||||
}
|
||||
@@ -174,7 +171,7 @@ class MainActivity : ComponentActivity() {
|
||||
enableEdgeToEdge()
|
||||
|
||||
setContent {
|
||||
_root_ide_package_.me.kavishdevar.librepods.presentation.theme.LibrePodsTheme {
|
||||
LibrePodsTheme {
|
||||
Main()
|
||||
}
|
||||
}
|
||||
@@ -221,143 +218,87 @@ class MainActivity : ComponentActivity() {
|
||||
fun Main() {
|
||||
val context = LocalContext.current
|
||||
val sharedPreferences = context.getSharedPreferences("settings", MODE_PRIVATE)
|
||||
if (!isSupported(sharedPreferences)) {
|
||||
val showDialog = remember { mutableStateOf(false) }
|
||||
val blockTouches = remember { mutableStateOf(false) }
|
||||
val tapCount = remember { mutableIntStateOf(0) }
|
||||
val lastTapTime = remember { mutableLongStateOf(0L) }
|
||||
|
||||
if (!isSupported(sharedPreferences) && !XposedState.bluetoothScopeEnabled) {
|
||||
val hazeState = rememberHazeState()
|
||||
val backdrop = rememberLayerBackdrop()
|
||||
val isDarkTheme = isSystemInDarkTheme()
|
||||
val textColor = if (isDarkTheme) Color.White else Color.Black
|
||||
val backgroundColor = if (isSystemInDarkTheme()) Color(0xFF1C1C1E) else Color(0xFFFFFFFF)
|
||||
|
||||
val scrollState = rememberScrollState()
|
||||
|
||||
LaunchedEffect(blockTouches) {
|
||||
if (blockTouches.value) {
|
||||
delay(500)
|
||||
blockTouches.value = false
|
||||
}
|
||||
}
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.hazeSource(hazeState)
|
||||
.background(if (isSystemInDarkTheme()) Color.Black else Color(0xFFF2F2F7)),
|
||||
.layerBackdrop(backdrop)
|
||||
.background(if (isDarkTheme) Color.Black else Color(0xFFF2F2F7)),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
Box (
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.then(
|
||||
if (blockTouches.value)
|
||||
{
|
||||
Modifier.pointerInput(Unit) {
|
||||
awaitPointerEventScope {
|
||||
while (true) {
|
||||
val event = awaitPointerEvent(PointerEventPass.Initial)
|
||||
event.changes.forEach { it.consume() }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else Modifier
|
||||
)
|
||||
)
|
||||
Column (
|
||||
verticalArrangement = Arrangement.spacedBy(8.dp)
|
||||
.padding(horizontal = 16.dp)
|
||||
.verticalScroll(scrollState),
|
||||
verticalArrangement = Arrangement
|
||||
.spacedBy(16.dp)
|
||||
) {
|
||||
Text(
|
||||
text = "Not supported",
|
||||
style = TextStyle(
|
||||
fontFamily = FontFamily(Font(R.font.sf_pro)),
|
||||
fontWeight = FontWeight.SemiBold,
|
||||
color = if (isSystemInDarkTheme()) Color.White else Color.Black,
|
||||
fontSize = 20.sp
|
||||
),
|
||||
textAlign = TextAlign.Center,
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
)
|
||||
Row (
|
||||
modifier = Modifier.fillMaxWidth().pointerInput(Unit) {
|
||||
detectTapGestures(
|
||||
onTap = {
|
||||
val now = System.currentTimeMillis()
|
||||
|
||||
if (now - lastTapTime.longValue > 400) {
|
||||
tapCount.intValue = 0
|
||||
}
|
||||
|
||||
tapCount.intValue++
|
||||
lastTapTime.longValue = now
|
||||
|
||||
if (tapCount.intValue >= 7) {
|
||||
showDialog.value = true
|
||||
blockTouches.value = true
|
||||
}
|
||||
}
|
||||
)
|
||||
},
|
||||
horizontalArrangement = Arrangement.Center
|
||||
Spacer(modifier = Modifier.height(48.dp))
|
||||
Column(
|
||||
modifier = Modifier,
|
||||
verticalArrangement = Arrangement
|
||||
.spacedBy(16.dp)
|
||||
) {
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
Text(
|
||||
text = "Device Info:",
|
||||
text = stringResource(R.string.not_supported),
|
||||
style = TextStyle(
|
||||
fontFamily = FontFamily(Font(R.font.sf_pro)),
|
||||
fontWeight = FontWeight.Medium,
|
||||
color = if (isSystemInDarkTheme()) Color.White else Color.Black,
|
||||
fontSize = 16.sp
|
||||
fontWeight = FontWeight.SemiBold,
|
||||
color = textColor,
|
||||
fontSize = 28.sp,
|
||||
textAlign = TextAlign.Center
|
||||
),
|
||||
textAlign = TextAlign.End,
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
)
|
||||
Spacer(modifier = Modifier.width(4.dp))
|
||||
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.background(backgroundColor, RoundedCornerShape(28.dp))
|
||||
.clip(RoundedCornerShape(28.dp))
|
||||
) {
|
||||
Text(
|
||||
text = stringResource(R.string.check_the_repository_for_more_info),
|
||||
style = TextStyle(
|
||||
fontFamily = FontFamily(Font(R.font.sf_pro)),
|
||||
fontWeight = FontWeight.Medium,
|
||||
color = if (isDarkTheme) Color.White else Color.Black,
|
||||
fontSize = 16.sp
|
||||
),
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 12.dp, vertical = 16.dp)
|
||||
)
|
||||
}
|
||||
Spacer(modifier = Modifier.height(4.dp))
|
||||
Text(
|
||||
text =
|
||||
"MANUFACTURER=${Build.MANUFACTURER}\n" +
|
||||
"MODEL=${Build.MODEL}\n" +
|
||||
"BUILD_ID=${Build.ID}\n" +
|
||||
"SDK_INT_FULL= ${Build.VERSION.SDK_INT_FULL}\n",
|
||||
text = stringResource(R.string.enable_app_in_xposed_or_update_device),
|
||||
style = TextStyle(
|
||||
fontFamily = FontFamily(Font(R.font.hack)),
|
||||
fontWeight = FontWeight.Medium,
|
||||
color = if (isSystemInDarkTheme()) Color.White else Color.Black,
|
||||
fontSize = 16.sp
|
||||
fontFamily = FontFamily(Font(R.font.sf_pro)),
|
||||
fontWeight = FontWeight.Light,
|
||||
color = if (isDarkTheme) Color.White else Color.Black,
|
||||
fontSize = 14.sp
|
||||
),
|
||||
textAlign = TextAlign.Start,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 16.dp, vertical = 16.dp)
|
||||
)
|
||||
DeviceInfoCard()
|
||||
AppInfoCard()
|
||||
}
|
||||
Text(
|
||||
text = "Check the repository for more info.",
|
||||
style = TextStyle(
|
||||
fontFamily = FontFamily(Font(R.font.sf_pro)),
|
||||
fontWeight = FontWeight.Medium,
|
||||
color = if (isSystemInDarkTheme()) Color.White else Color.Black,
|
||||
fontSize = 18.sp
|
||||
),
|
||||
textAlign = TextAlign.Center,
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
)
|
||||
Spacer(modifier = Modifier.height(48.dp))
|
||||
}
|
||||
}
|
||||
|
||||
ConfirmationDialog(
|
||||
showDialog = showDialog,
|
||||
title = "Confirm device check bypass?",
|
||||
message = "Are you sure your device is supported with LibrePods?",
|
||||
confirmText = "Yes",
|
||||
dismissText = "No",
|
||||
onConfirm = {
|
||||
showDialog.value = false
|
||||
sharedPreferences.edit {
|
||||
tapCount.intValue = 0
|
||||
putBoolean("bypass_device_check", true)
|
||||
val intent = Intent(context, MainActivity::class.java)
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK)
|
||||
context.startActivity(intent)
|
||||
}
|
||||
},
|
||||
onDismiss = {
|
||||
showDialog.value = false
|
||||
},
|
||||
hazeState = hazeState
|
||||
)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -371,8 +312,6 @@ fun Main() {
|
||||
)
|
||||
}
|
||||
|
||||
BillingManager.provider = BillingProviderFactory.create(context)
|
||||
|
||||
val bluetoothPermissions = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||
listOf(
|
||||
"android.permission.BLUETOOTH_CONNECT",
|
||||
@@ -420,6 +359,31 @@ fun Main() {
|
||||
|
||||
val navController = rememberNavController()
|
||||
|
||||
LaunchedEffect(Unit) {
|
||||
if (BuildConfig.PLAY_BUILD) {
|
||||
val now = System.currentTimeMillis()
|
||||
val firstConn =
|
||||
sharedPreferences.getLong("first_connection_successful_time", 0L)
|
||||
|
||||
val alreadyPrompted =
|
||||
sharedPreferences.getBoolean("review_prompted", false)
|
||||
|
||||
val oneDay = 24 * 60 * 60 * 1000L
|
||||
|
||||
if (
|
||||
firstConn != 0L &&
|
||||
!alreadyPrompted &&
|
||||
(now - firstConn) > oneDay
|
||||
) {
|
||||
triggerReviewFlow(context as? Activity ?: return@LaunchedEffect)
|
||||
|
||||
sharedPreferences.edit {
|
||||
putBoolean("review_prompted", true)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Box(
|
||||
modifier = Modifier.fillMaxSize()
|
||||
) {
|
||||
@@ -508,7 +472,7 @@ fun Main() {
|
||||
if (airPodsViewModel != null) VersionScreen(airPodsViewModel)
|
||||
}
|
||||
composable("hearing_protection") {
|
||||
if (airPodsViewModel != null) HearingProtectionScreen(airPodsViewModel)
|
||||
if (airPodsViewModel != null) HearingProtectionScreen(airPodsViewModel, navController)
|
||||
}
|
||||
composable("purchase_screen") {
|
||||
val purchaseViewModel: PurchaseViewModel = viewModel()
|
||||
@@ -523,10 +487,6 @@ fun Main() {
|
||||
navController.addOnDestinationChangedListener { _, destination, _ ->
|
||||
showBackButton.value =
|
||||
destination.route != "settings" // && destination.route != "onboarding"
|
||||
Log.d(
|
||||
"MainActivity",
|
||||
"Navigated to ${destination.route}, showBackButton: ${showBackButton.value}"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -561,6 +521,12 @@ fun Main() {
|
||||
override fun onServiceConnected(name: ComponentName?, service: IBinder?) {
|
||||
val binder = service as AirPodsService.LocalBinder
|
||||
airPodsService.value = binder.getService()
|
||||
|
||||
if (!sharedPreferences.contains("first_connection_successful_time")) {
|
||||
sharedPreferences.edit {
|
||||
putLong("first_connection_successful_time", System.currentTimeMillis())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onServiceDisconnected(name: ComponentName?) {
|
||||
@@ -586,6 +552,17 @@ fun Main() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun triggerReviewFlow(activity: Activity) {
|
||||
val manager = ReviewManagerFactory.create(activity)
|
||||
val request = manager.requestReviewFlow()
|
||||
request.addOnCompleteListener { task ->
|
||||
if (task.isSuccessful) {
|
||||
val reviewInfo = task.result
|
||||
manager.launchReviewFlow(activity, reviewInfo)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalPermissionsApi::class, ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun PermissionsScreen(
|
||||
|
||||
@@ -26,4 +26,5 @@ interface BillingProvider {
|
||||
val price: StateFlow<String>
|
||||
fun purchase(activity: Activity)
|
||||
fun queryPurchases()
|
||||
fun restorePurchases()
|
||||
}
|
||||
|
||||
@@ -31,13 +31,13 @@ import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import me.kavishdevar.librepods.R
|
||||
|
||||
class FOSSBillingProvider(context: Context): BillingProvider {
|
||||
private val _isPremium = MutableStateFlow(false)
|
||||
override val isPremium: StateFlow<Boolean> = _isPremium
|
||||
|
||||
private val _price = MutableStateFlow("Any")
|
||||
private val _price = MutableStateFlow(context.getString(R.string.name_your_own_price))
|
||||
override val price: StateFlow<String> = _price
|
||||
|
||||
private val sharedPreferences = context.getSharedPreferences("settings", Context.MODE_PRIVATE)
|
||||
@@ -57,11 +57,9 @@ class FOSSBillingProvider(context: Context): BillingProvider {
|
||||
purchaseJob?.cancel()
|
||||
|
||||
purchaseJob = scope.launch {
|
||||
delay(2_000)
|
||||
withContext(Dispatchers.Main) {
|
||||
_isPremium.value = true
|
||||
sharedPreferences.edit { putBoolean("foss_upgraded", true) }
|
||||
}
|
||||
delay(5_000)
|
||||
_isPremium.value = true
|
||||
sharedPreferences.edit { putBoolean("foss_upgraded", true) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,4 +69,9 @@ class FOSSBillingProvider(context: Context): BillingProvider {
|
||||
_isPremium.value = stored
|
||||
}
|
||||
}
|
||||
|
||||
override fun restorePurchases() {
|
||||
_isPremium.value = true
|
||||
sharedPreferences.edit { putBoolean("foss_upgraded", true) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -162,21 +162,19 @@ class PlayBillingProvider(
|
||||
it.purchaseState == Purchase.PurchaseState.PURCHASED
|
||||
}
|
||||
|
||||
|
||||
// val navigateToPurchase = purchases.find {
|
||||
// val purchase = purchases.find {
|
||||
// it.products.contains(PREMIUM_PRODUCT_ID) && it.purchaseState == Purchase.PurchaseState.PURCHASED
|
||||
// }
|
||||
//
|
||||
// if (navigateToPurchase != null) {
|
||||
// if (purchase != null) {
|
||||
// val consumeParams = ConsumeParams.newBuilder()
|
||||
// .setPurchaseToken(navigateToPurchase.purchaseToken)
|
||||
// .setPurchaseToken(purchase.purchaseToken)
|
||||
// .build()
|
||||
// scope.launch {
|
||||
// billingClient.consumeAsync(consumeParams) { _, _ ->}
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
_isPremium.value = hasPremium
|
||||
|
||||
scope.launch {
|
||||
@@ -201,4 +199,8 @@ class PlayBillingProvider(
|
||||
queryExistingPurchases()
|
||||
}
|
||||
}
|
||||
|
||||
override fun restorePurchases() {
|
||||
queryPurchases()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,7 +109,8 @@ class AACPManager {
|
||||
EAR_DETECTION_CONFIG(0x0A), AUTOMATIC_CONNECTION_CONFIG(0x20), OWNS_CONNECTION(0x06), PPE_TOGGLE_CONFIG(
|
||||
0x37
|
||||
),
|
||||
PPE_CAP_LEVEL_CONFIG(0x38);
|
||||
PPE_CAP_LEVEL_CONFIG(0x38),
|
||||
DYNAMIC_END_OF_CHARGE(0x3B);
|
||||
|
||||
companion object {
|
||||
fun fromByte(byte: Byte): ControlCommandIdentifiers? =
|
||||
@@ -207,10 +208,7 @@ class AACPManager {
|
||||
identifier: ControlCommandIdentifiers, value: ByteArray
|
||||
) {
|
||||
val existingStatus = getControlCommandStatus(identifier)
|
||||
if (existingStatus == value) {
|
||||
controlCommandStatusList.remove(existingStatus)
|
||||
}
|
||||
if (existingStatus != null) {
|
||||
if (existingStatus?.value.contentEquals(value)) {
|
||||
controlCommandStatusList.remove(existingStatus)
|
||||
}
|
||||
controlCommandListeners[identifier]?.forEach { listener ->
|
||||
@@ -363,7 +361,13 @@ class AACPManager {
|
||||
}
|
||||
val key = ByteArray(keyLength)
|
||||
System.arraycopy(data, offset, key, 0, keyLength)
|
||||
keys[ProximityKeyType.fromByte(keyType)] = key
|
||||
try {
|
||||
keys[ProximityKeyType.fromByte(keyType)] = key
|
||||
} catch (e: Exception) {
|
||||
Log.e(
|
||||
TAG, "incorrect key type received: $keyType, ${key.toHexString()}"
|
||||
)
|
||||
}
|
||||
offset += keyLength
|
||||
Log.d(
|
||||
TAG, "Parsed Proximity Key: Type: ${keyType}, Length: $keyLength, Key: ${
|
||||
@@ -408,7 +412,13 @@ class AACPManager {
|
||||
}
|
||||
|
||||
Opcodes.CONTROL_COMMAND -> {
|
||||
val controlCommand = ControlCommand.fromByteArray(packet)
|
||||
val controlCommand = try {
|
||||
ControlCommand.fromByteArray(packet)
|
||||
} catch (e: Exception) {
|
||||
Log.w(TAG, "Failed to parse control command: ${e.message}")
|
||||
callback?.onUnknownPacketReceived(packet)
|
||||
return
|
||||
}
|
||||
setControlCommandStatusValue(
|
||||
ControlCommandIdentifiers.fromByte(controlCommand.identifier) ?: return,
|
||||
controlCommand.value
|
||||
@@ -908,7 +918,7 @@ class AACPManager {
|
||||
)
|
||||
buffer.put(byteArrayOf(0x01, 0xE5.toByte(), 0x4A)) // unknown, constant
|
||||
buffer.put("PlayingApp".toByteArray())
|
||||
buffer.put(byteArrayOf(0x56)) // 'V', seems like a identifier or a separator
|
||||
buffer.put(byteArrayOf(0x56)) // 'V', seems like an identifier or a separator
|
||||
buffer.put("com.google.ios.youtube".toByteArray()) // package name, hardcoding for now, aforementioned reason
|
||||
buffer.put(byteArrayOf(0x52)) // 'R'
|
||||
buffer.put("HostStreamingState".toByteArray())
|
||||
@@ -1072,25 +1082,25 @@ class AACPManager {
|
||||
|
||||
companion object {
|
||||
fun fromByteArray(data: ByteArray): ControlCommand {
|
||||
if (data.size < 4) {
|
||||
throw IllegalArgumentException("Data array too short to parse ControlCommand")
|
||||
var offset = 0
|
||||
while (data.size - offset >= 4 &&
|
||||
data[offset] == 0x04.toByte() &&
|
||||
data[offset + 1] == 0x00.toByte() &&
|
||||
data[offset + 2] == 0x04.toByte() &&
|
||||
data[offset + 3] == 0x00.toByte()
|
||||
) {
|
||||
offset += 4
|
||||
}
|
||||
if (data[0] == 0x04.toByte() && data[1] == 0x00.toByte() && data[2] == 0x04.toByte() && data[3] == 0x00.toByte()) {
|
||||
val newData = ByteArray(data.size - 4)
|
||||
System.arraycopy(data, 4, newData, 0, data.size - 4)
|
||||
return fromByteArray(newData)
|
||||
if (data.size - offset < 7) {
|
||||
throw IllegalArgumentException("Too short for ControlCommand")
|
||||
}
|
||||
if (data[0] != Opcodes.CONTROL_COMMAND) {
|
||||
throw IllegalArgumentException("Data array does not start with CONTROL_COMMAND opcode")
|
||||
if (data[offset] != Opcodes.CONTROL_COMMAND) {
|
||||
throw IllegalArgumentException("Invalid opcode")
|
||||
}
|
||||
val identifier = data[2]
|
||||
|
||||
val value = ByteArray(4)
|
||||
System.arraycopy(data, 3, value, 0, 4)
|
||||
|
||||
val trimmedValue = value.dropLastWhile { it == 0x00.toByte() }.toByteArray()
|
||||
val finalValue = if (trimmedValue.isEmpty()) byteArrayOf(0x00) else trimmedValue
|
||||
return ControlCommand(identifier, finalValue)
|
||||
val identifier = data[offset + 2]
|
||||
val value = data.copyOfRange(offset + 3, offset + 7)
|
||||
val trimmed = value.dropLastWhile { it == 0x00.toByte() }.toByteArray()
|
||||
return ControlCommand(identifier, if (trimmed.isEmpty()) byteArrayOf(0x00) else trimmed)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1116,7 +1126,13 @@ class AACPManager {
|
||||
Log.d(TAG, "Sending packet: ${packet.joinToString(" ") { "%02X".format(it) }}")
|
||||
|
||||
if (packet[4] == Opcodes.CONTROL_COMMAND) {
|
||||
val controlCommand = ControlCommand.fromByteArray(packet)
|
||||
val controlCommand = try {
|
||||
ControlCommand.fromByteArray(packet)
|
||||
} catch (e: Exception) {
|
||||
Log.w(TAG, "Invalid control command: ${e.message}")
|
||||
callback?.onUnknownPacketReceived(packet)
|
||||
return false
|
||||
}
|
||||
Log.d(
|
||||
TAG, "Control command: ${controlCommand.identifier.toHexString()} - ${
|
||||
controlCommand.value.joinToString(" ") { "%02X".format(it) }
|
||||
|
||||
@@ -72,7 +72,11 @@ class ATTManager(private val adapter: BluetoothAdapter, private val device: Blue
|
||||
fun connect() {
|
||||
val uuid = ParcelUuid.fromString("00000000-0000-0000-0000-000000000000")
|
||||
|
||||
socket = createBluetoothSocket(adapter, device, uuid)
|
||||
try {
|
||||
socket = createBluetoothSocket(adapter, device, uuid)
|
||||
} catch (e: Exception) {
|
||||
Log.w(TAG, "Failed to create socket")
|
||||
}
|
||||
try {
|
||||
socket!!.connect()
|
||||
} catch (e: Exception) {
|
||||
@@ -168,6 +172,7 @@ class ATTManager(private val adapter: BluetoothAdapter, private val device: Blue
|
||||
}
|
||||
|
||||
private fun writeRaw(pdu: ByteArray) {
|
||||
if (output == null) return
|
||||
output?.write(pdu)
|
||||
output?.flush()
|
||||
Log.d(TAG, "writeRaw: ${pdu.joinToString(" ") { String.format("%02X", it) }}")
|
||||
@@ -203,7 +208,7 @@ class ATTManager(private val adapter: BluetoothAdapter, private val device: Blue
|
||||
private fun createBluetoothSocket(adapter: BluetoothAdapter, device: BluetoothDevice, uuid: ParcelUuid): BluetoothSocket {
|
||||
val type = 3 // L2CAP
|
||||
val constructorSpecs = listOf(
|
||||
arrayOf(adapter, device, type, true, 31, uuid),
|
||||
arrayOf(adapter, device, type, true, true, 31, uuid),
|
||||
arrayOf(device, type, true, true, 31, uuid),
|
||||
arrayOf(device, type, 1, true, true, 31, uuid),
|
||||
arrayOf(type, 1, true, true, device, 31, uuid),
|
||||
|
||||
@@ -72,6 +72,7 @@ enum class NoiseControlMode {
|
||||
class AirPodsNotifications {
|
||||
companion object {
|
||||
const val AIRPODS_CONNECTED = "me.kavishdevar.librepods.AIRPODS_CONNECTED"
|
||||
const val AIRPODS_L2CAP_CONNECTED = "me.kavishdevar.librepods.AIRPODS_CONNECTED"
|
||||
const val AIRPODS_DATA = "me.kavishdevar.librepods.AIRPODS_DATA"
|
||||
const val EAR_DETECTION_DATA = "me.kavishdevar.librepods.EAR_DETECTION_DATA"
|
||||
const val ANC_DATA = "me.kavishdevar.librepods.ANC_DATA"
|
||||
|
||||
@@ -0,0 +1,193 @@
|
||||
/*
|
||||
LibrePods - AirPods liberated from Apple’s ecosystem
|
||||
Copyright (C) 2025 LibrePods contributors
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package me.kavishdevar.librepods.presentation.components
|
||||
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.isSystemInDarkTheme
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.HorizontalDivider
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.layout.onGloballyPositioned
|
||||
import androidx.compose.ui.platform.LocalDensity
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.TextStyle
|
||||
import androidx.compose.ui.text.font.Font
|
||||
import androidx.compose.ui.text.font.FontFamily
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import me.kavishdevar.librepods.BuildConfig
|
||||
import me.kavishdevar.librepods.R
|
||||
|
||||
@Composable
|
||||
fun AppInfoCard() {
|
||||
val rowHeight = remember { mutableStateOf(0.dp) }
|
||||
val density = LocalDensity.current
|
||||
val isDarkTheme = isSystemInDarkTheme()
|
||||
val backgroundColor = if (isDarkTheme) Color(0xFF1C1C1E) else Color(0xFFFFFFFF)
|
||||
val textColor = if (isDarkTheme) Color.White else Color.Black
|
||||
|
||||
Column {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.background(if (isDarkTheme) Color.Black else Color(0xFFF2F2F7))
|
||||
.padding(start = 16.dp, bottom = 8.dp, end = 4.dp)
|
||||
) {
|
||||
Text(
|
||||
text = stringResource(R.string.about), style = TextStyle(
|
||||
fontSize = 14.sp,
|
||||
fontWeight = FontWeight.Bold,
|
||||
color = textColor.copy(alpha = 0.6f),
|
||||
fontFamily = FontFamily(Font(R.font.sf_pro))
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.clip(RoundedCornerShape(28.dp))
|
||||
.fillMaxWidth()
|
||||
.background(backgroundColor, RoundedCornerShape(28.dp))
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(16.dp)
|
||||
.onGloballyPositioned { coordinates ->
|
||||
rowHeight.value = with(density) { coordinates.size.height.toDp() }
|
||||
},
|
||||
horizontalArrangement = Arrangement.SpaceBetween,
|
||||
) {
|
||||
Text(
|
||||
text = stringResource(R.string.version), style = TextStyle(
|
||||
fontSize = 16.sp,
|
||||
color = textColor,
|
||||
fontFamily = FontFamily(Font(R.font.sf_pro))
|
||||
)
|
||||
)
|
||||
Text(
|
||||
text = BuildConfig.VERSION_NAME, style = TextStyle(
|
||||
fontSize = 16.sp,
|
||||
color = if (isDarkTheme) Color.White.copy(alpha = 0.6f) else Color.Black.copy(
|
||||
alpha = 0.8f
|
||||
),
|
||||
fontFamily = FontFamily(Font(R.font.sf_pro))
|
||||
)
|
||||
)
|
||||
}
|
||||
HorizontalDivider(
|
||||
thickness = 1.dp,
|
||||
color = Color(0x40888888),
|
||||
modifier = Modifier.padding(horizontal = 12.dp)
|
||||
)
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(16.dp),
|
||||
horizontalArrangement = Arrangement.SpaceBetween,
|
||||
) {
|
||||
Text(
|
||||
text = stringResource(R.string.version_code), style = TextStyle(
|
||||
fontSize = 16.sp,
|
||||
color = textColor,
|
||||
fontFamily = FontFamily(Font(R.font.sf_pro))
|
||||
)
|
||||
)
|
||||
Text(
|
||||
text = BuildConfig.VERSION_CODE.toString(), style = TextStyle(
|
||||
fontSize = 16.sp,
|
||||
color = if (isDarkTheme) Color.White.copy(alpha = 0.6f) else Color.Black.copy(
|
||||
alpha = 0.8f
|
||||
),
|
||||
fontFamily = FontFamily(Font(R.font.sf_pro))
|
||||
)
|
||||
)
|
||||
}
|
||||
HorizontalDivider(
|
||||
thickness = 1.dp,
|
||||
color = Color(0x40888888),
|
||||
modifier = Modifier.padding(horizontal = 12.dp)
|
||||
)
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(16.dp),
|
||||
horizontalArrangement = Arrangement.SpaceBetween,
|
||||
) {
|
||||
Text(
|
||||
text = stringResource(R.string.flavor), style = TextStyle(
|
||||
fontSize = 16.sp,
|
||||
color = textColor,
|
||||
fontFamily = FontFamily(Font(R.font.sf_pro))
|
||||
)
|
||||
)
|
||||
Text(
|
||||
text = BuildConfig.FLAVOR, style = TextStyle(
|
||||
fontSize = 16.sp,
|
||||
color = if (isDarkTheme) Color.White.copy(alpha = 0.6f) else Color.Black.copy(
|
||||
alpha = 0.8f
|
||||
),
|
||||
fontFamily = FontFamily(Font(R.font.sf_pro))
|
||||
)
|
||||
)
|
||||
}
|
||||
HorizontalDivider(
|
||||
thickness = 1.dp,
|
||||
color = Color(0x40888888),
|
||||
modifier = Modifier.padding(horizontal = 12.dp)
|
||||
)
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(16.dp),
|
||||
horizontalArrangement = Arrangement.SpaceBetween,
|
||||
) {
|
||||
Text(
|
||||
text = stringResource(R.string.build_type), style = TextStyle(
|
||||
fontSize = 16.sp,
|
||||
color = textColor,
|
||||
fontFamily = FontFamily(Font(R.font.sf_pro))
|
||||
)
|
||||
)
|
||||
Text(
|
||||
text = BuildConfig.BUILD_TYPE,
|
||||
style = TextStyle(
|
||||
fontSize = 16.sp,
|
||||
color = if (isDarkTheme) Color.White.copy(alpha = 0.6f) else Color.Black.copy(
|
||||
alpha = 0.8f
|
||||
),
|
||||
fontFamily = FontFamily(Font(R.font.sf_pro))
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,37 +18,32 @@
|
||||
|
||||
package me.kavishdevar.librepods.presentation.components
|
||||
|
||||
import androidx.compose.animation.AnimatedVisibility
|
||||
import androidx.compose.animation.fadeIn
|
||||
import androidx.compose.animation.fadeOut
|
||||
import androidx.compose.animation.scaleIn
|
||||
import androidx.compose.animation.scaleOut
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.isSystemInDarkTheme
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxHeight
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.requiredWidthIn
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.HorizontalDivider
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.MutableState
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
|
||||
import androidx.compose.ui.input.pointer.PointerEventType
|
||||
import androidx.compose.ui.input.pointer.pointerInput
|
||||
import androidx.compose.ui.platform.LocalHapticFeedback
|
||||
import androidx.compose.ui.text.TextStyle
|
||||
import androidx.compose.ui.text.font.Font
|
||||
import androidx.compose.ui.text.font.FontFamily
|
||||
@@ -56,13 +51,13 @@ import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.compose.ui.window.Dialog
|
||||
import androidx.compose.ui.window.DialogProperties
|
||||
import dev.chrisbanes.haze.HazeState
|
||||
import dev.chrisbanes.haze.hazeEffect
|
||||
import dev.chrisbanes.haze.materials.CupertinoMaterials
|
||||
import com.kyant.backdrop.backdrops.LayerBackdrop
|
||||
import com.kyant.backdrop.backdrops.rememberLayerBackdrop
|
||||
import com.kyant.backdrop.drawBackdrop
|
||||
import com.kyant.backdrop.effects.blur
|
||||
import com.kyant.backdrop.effects.lens
|
||||
import com.kyant.backdrop.effects.vibrancy
|
||||
import dev.chrisbanes.haze.materials.ExperimentalHazeMaterialsApi
|
||||
import kotlinx.coroutines.launch
|
||||
import me.kavishdevar.librepods.R
|
||||
|
||||
@ExperimentalHazeMaterialsApi
|
||||
@@ -75,162 +70,107 @@ fun ConfirmationDialog(
|
||||
dismissText: String = "Cancel",
|
||||
onConfirm: () -> Unit,
|
||||
onDismiss: () -> Unit = { showDialog.value = false },
|
||||
hazeState: HazeState,
|
||||
backdrop: LayerBackdrop,
|
||||
) {
|
||||
val isDarkTheme = isSystemInDarkTheme()
|
||||
val textColor = if (isDarkTheme) Color.White else Color.Black
|
||||
val accentColor = if (isDarkTheme) Color(0xFF007AFF) else Color(0xFF3C6DF5)
|
||||
val accentColor = if (isDarkTheme) Color(0xFF0091FF) else Color(0xFF0088FF)
|
||||
|
||||
val haptics = LocalHapticFeedback.current
|
||||
val scope = rememberCoroutineScope()
|
||||
|
||||
if (showDialog.value) {
|
||||
Dialog(
|
||||
onDismissRequest = { showDialog.value = false },
|
||||
properties = DialogProperties(
|
||||
dismissOnBackPress = false,
|
||||
dismissOnClickOutside = false
|
||||
)
|
||||
AnimatedVisibility(
|
||||
visible = showDialog.value,
|
||||
enter = scaleIn(initialScale = 1.05f) + fadeIn(),
|
||||
exit = scaleOut(targetScale = 1.05f) + fadeOut()
|
||||
) {
|
||||
Box(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
val innerBackdrop = rememberLayerBackdrop()
|
||||
Box(
|
||||
modifier = Modifier
|
||||
// .fillMaxWidth(0.75f)
|
||||
.requiredWidthIn(min = 200.dp, max = 360.dp)
|
||||
.background(Color.Transparent, RoundedCornerShape(14.dp))
|
||||
.clip(RoundedCornerShape(14.dp))
|
||||
.hazeEffect(
|
||||
hazeState,
|
||||
style = CupertinoMaterials.regular(
|
||||
containerColor = if (isDarkTheme) Color(0xFF1C1C1E).copy(alpha = 0.95f) else Color.White.copy(alpha = 0.95f)
|
||||
)
|
||||
)
|
||||
.fillMaxSize()
|
||||
.background(Color.Black.copy(alpha = 0.4f))
|
||||
.clickable(enabled = false, onClick = {}),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
Column(horizontalAlignment = Alignment.CenterHorizontally) {
|
||||
Spacer(modifier = Modifier.height(24.dp))
|
||||
Text(
|
||||
title,
|
||||
style = TextStyle(
|
||||
fontSize = 16.sp,
|
||||
fontWeight = FontWeight.Bold,
|
||||
color = textColor,
|
||||
fontFamily = FontFamily(Font(R.font.sf_pro))
|
||||
),
|
||||
textAlign = TextAlign.Center,
|
||||
modifier = Modifier.padding(horizontal = 16.dp)
|
||||
)
|
||||
Spacer(modifier = Modifier.height(12.dp))
|
||||
Text(
|
||||
message,
|
||||
style = TextStyle(
|
||||
fontSize = 14.sp,
|
||||
color = textColor.copy(alpha = 0.8f),
|
||||
fontFamily = FontFamily(Font(R.font.sf_pro))
|
||||
),
|
||||
textAlign = TextAlign.Center,
|
||||
modifier = Modifier.padding(horizontal = 16.dp)
|
||||
)
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
HorizontalDivider(
|
||||
thickness = 1.dp,
|
||||
color = Color(0x40888888),
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
)
|
||||
var leftPressed by remember { mutableStateOf(false) }
|
||||
var rightPressed by remember { mutableStateOf(false) }
|
||||
val pressedColor = if (isDarkTheme) Color(0x40888888) else Color(0x40D9D9D9)
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.height(48.dp)
|
||||
.pointerInput(Unit) {
|
||||
awaitPointerEventScope {
|
||||
while (true) {
|
||||
val event = awaitPointerEvent()
|
||||
val position = event.changes.first().position
|
||||
val width = size.width.toFloat()
|
||||
val height = size.height.toFloat()
|
||||
val isWithinBounds = position.y >= 0 && position.y <= height
|
||||
val isLeft = position.x < width / 2
|
||||
event.changes.first().consume()
|
||||
when (event.type) {
|
||||
PointerEventType.Press -> {
|
||||
if (isWithinBounds) {
|
||||
leftPressed = isLeft
|
||||
rightPressed = !isLeft
|
||||
} else {
|
||||
leftPressed = false
|
||||
rightPressed = false
|
||||
}
|
||||
}
|
||||
PointerEventType.Move -> {
|
||||
if (isWithinBounds) {
|
||||
if (leftPressed != isLeft) scope.launch { haptics.performHapticFeedback(
|
||||
HapticFeedbackType.SegmentTick) }
|
||||
leftPressed = isLeft
|
||||
rightPressed = !isLeft
|
||||
} else {
|
||||
leftPressed = false
|
||||
rightPressed = false
|
||||
}
|
||||
}
|
||||
PointerEventType.Release -> {
|
||||
if (isWithinBounds) {
|
||||
if (leftPressed) {
|
||||
scope.launch { haptics.performHapticFeedback(
|
||||
HapticFeedbackType.Reject) }
|
||||
onDismiss()
|
||||
} else if (rightPressed) {
|
||||
scope.launch { haptics.performHapticFeedback(
|
||||
HapticFeedbackType.Confirm) }
|
||||
onConfirm()
|
||||
}
|
||||
}
|
||||
leftPressed = false
|
||||
rightPressed = false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.requiredWidthIn(min = 200.dp, max = 360.dp)
|
||||
.clip(RoundedCornerShape(48.dp))
|
||||
.drawBackdrop(
|
||||
backdrop = backdrop,
|
||||
exportedBackdrop = innerBackdrop,
|
||||
shape = { RoundedCornerShape(48.dp) },
|
||||
effects = {
|
||||
vibrancy()
|
||||
blur(4f.dp.toPx())
|
||||
lens(12f.dp.toPx(), 48f.dp.toPx(), true)
|
||||
},
|
||||
horizontalArrangement = Arrangement.Start,
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.fillMaxHeight()
|
||||
.background(if (leftPressed) pressedColor else Color.Transparent),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
Text(
|
||||
text = dismissText,
|
||||
style = TextStyle(
|
||||
color = accentColor,
|
||||
fontFamily = FontFamily(Font(R.font.sf_pro))
|
||||
onDrawSurface = {
|
||||
drawRect(
|
||||
if (isDarkTheme) Color(0xFF1F1F1F).copy(alpha = 0.35f) else Color(0xFFE0E0E0).copy(alpha = 0.7f)
|
||||
)
|
||||
)
|
||||
}
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.width(1.dp)
|
||||
.fillMaxHeight()
|
||||
.background(Color(0x40888888))
|
||||
})) {
|
||||
Column(horizontalAlignment = Alignment.CenterHorizontally) {
|
||||
Spacer(modifier = Modifier.height(24.dp))
|
||||
Text(
|
||||
title,
|
||||
style = TextStyle(
|
||||
fontSize = 16.sp,
|
||||
fontWeight = FontWeight.Bold,
|
||||
color = textColor,
|
||||
fontFamily = FontFamily(Font(R.font.sf_pro))
|
||||
),
|
||||
textAlign = TextAlign.Center,
|
||||
modifier = Modifier.padding(horizontal = 16.dp)
|
||||
)
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.fillMaxHeight()
|
||||
.background(if (rightPressed) pressedColor else Color.Transparent),
|
||||
contentAlignment = Alignment.Center
|
||||
Spacer(modifier = Modifier.height(12.dp))
|
||||
Text(
|
||||
message,
|
||||
style = TextStyle(
|
||||
fontSize = 14.sp,
|
||||
color = textColor.copy(alpha = 0.8f),
|
||||
fontFamily = FontFamily(Font(R.font.sf_pro))
|
||||
),
|
||||
textAlign = TextAlign.Center,
|
||||
modifier = Modifier.padding(horizontal = 16.dp)
|
||||
)
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(0.9f),
|
||||
horizontalArrangement = Arrangement.spacedBy(24.dp)
|
||||
) {
|
||||
Text(
|
||||
text = confirmText,
|
||||
style = TextStyle(
|
||||
color = accentColor,
|
||||
fontFamily = FontFamily(Font(R.font.sf_pro))
|
||||
StyledButton(
|
||||
onClick = onDismiss,
|
||||
backdrop = innerBackdrop,
|
||||
modifier = Modifier.weight(1f),
|
||||
) {
|
||||
Text(
|
||||
text = dismissText, style = TextStyle(
|
||||
fontFamily = FontFamily(Font(R.font.sf_pro)),
|
||||
fontWeight = FontWeight.Medium,
|
||||
fontSize = 14.sp,
|
||||
color = textColor
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
StyledButton(
|
||||
onClick = onConfirm,
|
||||
backdrop = innerBackdrop,
|
||||
modifier = Modifier.weight(1f),
|
||||
surfaceColor = accentColor
|
||||
) {
|
||||
Text(
|
||||
text = confirmText, style = TextStyle(
|
||||
fontFamily = FontFamily(Font(R.font.sf_pro)),
|
||||
fontWeight = FontWeight.Medium,
|
||||
fontSize = 14.sp,
|
||||
color = Color.White
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
Spacer(modifier = Modifier.height(24.dp))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,235 @@
|
||||
package me.kavishdevar.librepods.presentation.components
|
||||
|
||||
import android.os.Build
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.isSystemInDarkTheme
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.HorizontalDivider
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.layout.onGloballyPositioned
|
||||
import androidx.compose.ui.platform.LocalDensity
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.TextStyle
|
||||
import androidx.compose.ui.text.font.Font
|
||||
import androidx.compose.ui.text.font.FontFamily
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import me.kavishdevar.librepods.R
|
||||
import me.kavishdevar.librepods.utils.XposedState
|
||||
|
||||
@Composable
|
||||
fun DeviceInfoCard() {
|
||||
val isDarkTheme = isSystemInDarkTheme()
|
||||
|
||||
val textColor = if (isDarkTheme) Color.White else Color.Black
|
||||
val backgroundColor = if (isDarkTheme) Color(0xFF1C1C1E) else Color(0xFFFFFFFF)
|
||||
|
||||
val rowHeight = remember { mutableStateOf(0.dp) }
|
||||
val density = LocalDensity.current
|
||||
|
||||
Column (
|
||||
verticalArrangement = Arrangement.spacedBy(8.dp)
|
||||
) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.background(if (isDarkTheme) Color.Black else Color(0xFFF2F2F7))
|
||||
.padding(start = 16.dp, top = 24.dp, end = 4.dp)
|
||||
) {
|
||||
Text(
|
||||
text = stringResource(R.string.device_info), style = TextStyle(
|
||||
fontSize = 14.sp,
|
||||
fontWeight = FontWeight.Bold,
|
||||
color = textColor.copy(alpha = 0.6f),
|
||||
fontFamily = FontFamily(Font(R.font.sf_pro))
|
||||
)
|
||||
)
|
||||
}
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.clip(RoundedCornerShape(28.dp))
|
||||
.fillMaxWidth()
|
||||
.background(backgroundColor, RoundedCornerShape(28.dp))
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(16.dp)
|
||||
.onGloballyPositioned { coordinates ->
|
||||
rowHeight.value = with(density) { coordinates.size.height.toDp() }
|
||||
},
|
||||
horizontalArrangement = Arrangement.SpaceBetween,
|
||||
) {
|
||||
Text(
|
||||
text = stringResource(R.string.manufacturer), style = TextStyle(
|
||||
fontSize = 16.sp,
|
||||
color = textColor,
|
||||
fontFamily = FontFamily(Font(R.font.sf_pro))
|
||||
)
|
||||
)
|
||||
Text(
|
||||
text = Build.MANUFACTURER, style = TextStyle(
|
||||
fontSize = 16.sp,
|
||||
color = if (isDarkTheme) Color.White.copy(alpha = 0.6f) else Color.Black.copy(
|
||||
alpha = 0.8f
|
||||
),
|
||||
fontFamily = FontFamily(Font(R.font.sf_pro))
|
||||
)
|
||||
)
|
||||
}
|
||||
HorizontalDivider(
|
||||
thickness = 1.dp,
|
||||
color = Color(0x40888888),
|
||||
modifier = Modifier.padding(horizontal = 12.dp)
|
||||
)
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(16.dp),
|
||||
horizontalArrangement = Arrangement.SpaceBetween,
|
||||
) {
|
||||
Text(
|
||||
text = stringResource(R.string.model_number), style = TextStyle(
|
||||
fontSize = 16.sp,
|
||||
color = textColor,
|
||||
fontFamily = FontFamily(Font(R.font.sf_pro))
|
||||
)
|
||||
)
|
||||
Text(
|
||||
text = Build.MODEL, style = TextStyle(
|
||||
fontSize = 16.sp,
|
||||
color = if (isDarkTheme) Color.White.copy(alpha = 0.6f) else Color.Black.copy(
|
||||
alpha = 0.8f
|
||||
),
|
||||
fontFamily = FontFamily(Font(R.font.sf_pro))
|
||||
)
|
||||
)
|
||||
}
|
||||
HorizontalDivider(
|
||||
thickness = 1.dp,
|
||||
color = Color(0x40888888),
|
||||
modifier = Modifier.padding(horizontal = 12.dp)
|
||||
)
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(16.dp),
|
||||
horizontalArrangement = Arrangement.SpaceBetween,
|
||||
) {
|
||||
Text(
|
||||
text = stringResource(R.string.build_id), style = TextStyle(
|
||||
fontSize = 16.sp,
|
||||
color = textColor,
|
||||
fontFamily = FontFamily(Font(R.font.sf_pro))
|
||||
)
|
||||
)
|
||||
Text(
|
||||
text = Build.DISPLAY, style = TextStyle(
|
||||
fontSize = 16.sp,
|
||||
color = if (isDarkTheme) Color.White.copy(alpha = 0.6f) else Color.Black.copy(
|
||||
alpha = 0.8f
|
||||
),
|
||||
fontFamily = FontFamily(Font(R.font.sf_pro))
|
||||
)
|
||||
)
|
||||
}
|
||||
HorizontalDivider(
|
||||
thickness = 1.dp,
|
||||
color = Color(0x40888888),
|
||||
modifier = Modifier.padding(horizontal = 12.dp)
|
||||
)
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(16.dp),
|
||||
horizontalArrangement = Arrangement.SpaceBetween,
|
||||
) {
|
||||
Text(
|
||||
text = stringResource(R.string.version), style = TextStyle(
|
||||
fontSize = 16.sp,
|
||||
color = textColor,
|
||||
fontFamily = FontFamily(Font(R.font.sf_pro))
|
||||
)
|
||||
)
|
||||
Text(
|
||||
text = Build.ID + " (${Build.VERSION.SDK_INT_FULL})",
|
||||
style = TextStyle(
|
||||
fontSize = 16.sp,
|
||||
color = if (isDarkTheme) Color.White.copy(alpha = 0.6f) else Color.Black.copy(
|
||||
alpha = 0.8f
|
||||
),
|
||||
fontFamily = FontFamily(Font(R.font.sf_pro))
|
||||
)
|
||||
)
|
||||
}
|
||||
HorizontalDivider(
|
||||
thickness = 1.dp,
|
||||
color = Color(0x40888888),
|
||||
modifier = Modifier.padding(horizontal = 12.dp)
|
||||
)
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(16.dp),
|
||||
horizontalArrangement = Arrangement.SpaceBetween,
|
||||
) {
|
||||
Text(
|
||||
text = stringResource(R.string.xposed_available), style = TextStyle(
|
||||
fontSize = 16.sp,
|
||||
color = textColor,
|
||||
fontFamily = FontFamily(Font(R.font.sf_pro))
|
||||
)
|
||||
)
|
||||
Text(
|
||||
text = if (XposedState.isAvailable) stringResource(R.string.yes) else stringResource(R.string.no), style = TextStyle(
|
||||
fontSize = 16.sp,
|
||||
color = if (isDarkTheme) Color.White.copy(alpha = 0.6f) else Color.Black.copy(
|
||||
alpha = 0.8f
|
||||
),
|
||||
fontFamily = FontFamily(Font(R.font.sf_pro))
|
||||
)
|
||||
)
|
||||
}
|
||||
HorizontalDivider(
|
||||
thickness = 1.dp,
|
||||
color = Color(0x40888888),
|
||||
modifier = Modifier.padding(horizontal = 12.dp)
|
||||
)
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(16.dp),
|
||||
horizontalArrangement = Arrangement.SpaceBetween,
|
||||
) {
|
||||
Text(
|
||||
text = stringResource(R.string.app_enabled_in_xposed), style = TextStyle(
|
||||
fontSize = 16.sp,
|
||||
color = textColor,
|
||||
fontFamily = FontFamily(Font(R.font.sf_pro))
|
||||
)
|
||||
)
|
||||
Text(
|
||||
text = if (XposedState.bluetoothScopeEnabled) stringResource(R.string.yes) else stringResource(R.string.no), style = TextStyle(
|
||||
fontSize = 16.sp,
|
||||
color = if (isDarkTheme) Color.White.copy(alpha = 0.6f) else Color.Black.copy(
|
||||
alpha = 0.8f
|
||||
),
|
||||
fontFamily = FontFamily(Font(R.font.sf_pro))
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
package me.kavishdevar.librepods.presentation.components
|
||||
|
||||
import androidx.compose.animation.core.animateFloatAsState
|
||||
import androidx.compose.foundation.isSystemInDarkTheme
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.ModalBottomSheet
|
||||
import androidx.compose.material3.SheetValue
|
||||
import androidx.compose.material3.rememberModalBottomSheetState
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.lerp
|
||||
import com.kyant.backdrop.backdrops.LayerBackdrop
|
||||
import com.kyant.backdrop.backdrops.rememberLayerBackdrop
|
||||
import com.kyant.backdrop.drawBackdrop
|
||||
import com.kyant.backdrop.effects.blur
|
||||
import com.kyant.backdrop.effects.lens
|
||||
import com.kyant.backdrop.effects.vibrancy
|
||||
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun StyledBottomSheet(
|
||||
visible: Boolean,
|
||||
onDismiss: () -> Unit,
|
||||
backdrop: LayerBackdrop,
|
||||
content: @Composable (innerBackdrop: LayerBackdrop, progress: Float) -> Unit
|
||||
) {
|
||||
if (!visible) return
|
||||
|
||||
val isDarkTheme = isSystemInDarkTheme()
|
||||
val sheetState = rememberModalBottomSheetState(false) // move this to parent composable
|
||||
|
||||
val isExpanded = sheetState.targetValue == SheetValue.Expanded
|
||||
|
||||
val progress by animateFloatAsState(
|
||||
targetValue = if (isExpanded) 1f else 0f,
|
||||
label = "sheetProgress"
|
||||
)
|
||||
|
||||
val animatedCorner = lerp(48.dp, 42.dp, progress)
|
||||
|
||||
ModalBottomSheet(
|
||||
onDismissRequest = onDismiss,
|
||||
sheetState = sheetState,
|
||||
containerColor = Color.Transparent,
|
||||
dragHandle = { },
|
||||
shape = RoundedCornerShape(animatedCorner),
|
||||
scrimColor = Color.Transparent,
|
||||
modifier = Modifier.padding(4.dp)
|
||||
) {
|
||||
val innerBackdrop = rememberLayerBackdrop()
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.clip(RoundedCornerShape(animatedCorner))
|
||||
.drawBackdrop(
|
||||
backdrop = backdrop,
|
||||
exportedBackdrop = innerBackdrop,
|
||||
shape = { RoundedCornerShape(animatedCorner) },
|
||||
effects = {
|
||||
vibrancy()
|
||||
blur(4f.dp.toPx())
|
||||
lens(12f.dp.toPx(), 48f.dp.toPx(), true)
|
||||
},
|
||||
onDrawSurface = {
|
||||
drawRect(
|
||||
if (isDarkTheme) Color.DarkGray.copy(alpha = 0.3f) else Color(
|
||||
0xFFE0E0E0
|
||||
).copy(alpha = 0.45f)
|
||||
)
|
||||
}
|
||||
)
|
||||
.padding(top = 24.dp)
|
||||
.padding(horizontal = 16.dp)
|
||||
) {
|
||||
content(innerBackdrop, progress)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -77,8 +77,10 @@ fun StyledButton(
|
||||
tint: Color = Color.Unspecified,
|
||||
surfaceColor: Color = Color.Unspecified,
|
||||
maxScale: Float = 0.1f,
|
||||
enabled: Boolean = true,
|
||||
content: @Composable RowScope.() -> Unit,
|
||||
) {
|
||||
val isInteractive = enabled && isInteractive
|
||||
val scope = rememberCoroutineScope()
|
||||
val haptics = LocalHapticFeedback.current
|
||||
val progressAnimation = remember { Animatable(0f) }
|
||||
@@ -125,8 +127,8 @@ half4 main(float2 coord) {
|
||||
} else {
|
||||
drawRect(Color.White.copy(0.1f))
|
||||
}
|
||||
if (surfaceColor.isSpecified) {
|
||||
val color = if (!isInteractive && isPressed) {
|
||||
if (surfaceColor.isSpecified && enabled) {
|
||||
val color = if (isPressed) {
|
||||
Color(
|
||||
red = surfaceColor.red * 0.5f,
|
||||
green = surfaceColor.green * 0.5f,
|
||||
@@ -137,6 +139,11 @@ half4 main(float2 coord) {
|
||||
surfaceColor
|
||||
}
|
||||
drawRect(color)
|
||||
} else {
|
||||
if (isPressed) {
|
||||
drawRect(Color.Black.copy(alpha = 0.4f))
|
||||
drawRect(Color.White.copy(alpha = 0.2f))
|
||||
}
|
||||
}
|
||||
},
|
||||
onDrawFront = null,
|
||||
@@ -245,8 +252,10 @@ half4 main(float2 coord) {
|
||||
indication = null,
|
||||
role = Role.Button,
|
||||
onClick = {
|
||||
haptics.performHapticFeedback(HapticFeedbackType.ContextClick)
|
||||
onClick()
|
||||
if (enabled) {
|
||||
haptics.performHapticFeedback(HapticFeedbackType.ContextClick)
|
||||
onClick()
|
||||
}
|
||||
}
|
||||
)
|
||||
.then(
|
||||
@@ -302,8 +311,10 @@ half4 main(float2 coord) {
|
||||
isPressed = false
|
||||
},
|
||||
onTap = {
|
||||
haptics.performHapticFeedback(HapticFeedbackType.ContextClick)
|
||||
onClick()
|
||||
if (enabled) {
|
||||
haptics.performHapticFeedback(HapticFeedbackType.ContextClick)
|
||||
onClick()
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@@ -52,6 +52,7 @@ import androidx.compose.ui.graphics.rememberGraphicsLayer
|
||||
import androidx.compose.ui.graphics.toArgb
|
||||
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
|
||||
import androidx.compose.ui.input.pointer.pointerInput
|
||||
import androidx.compose.ui.platform.LocalDensity
|
||||
import androidx.compose.ui.platform.LocalHapticFeedback
|
||||
import androidx.compose.ui.text.TextStyle
|
||||
import androidx.compose.ui.text.font.Font
|
||||
@@ -81,9 +82,11 @@ import kotlin.math.tanh
|
||||
fun StyledIconButton(
|
||||
modifier: Modifier = Modifier,
|
||||
icon: String,
|
||||
tint: Color = Color.Unspecified,
|
||||
iconTint: Color = Color.Unspecified,
|
||||
surfaceColor: Color = Color.Unspecified,
|
||||
backdrop: LayerBackdrop = rememberLayerBackdrop(),
|
||||
onClick: () -> Unit
|
||||
onClick: () -> Unit,
|
||||
enabled: Boolean = true
|
||||
) {
|
||||
val haptics = LocalHapticFeedback.current
|
||||
val darkMode = isSystemInDarkTheme()
|
||||
@@ -96,6 +99,7 @@ fun StyledIconButton(
|
||||
val innerShadowLayer = rememberGraphicsLayer().apply {
|
||||
compositingStrategy = CompositingStrategy.Offscreen
|
||||
}
|
||||
val density = LocalDensity.current
|
||||
|
||||
val interactiveHighlightShader = remember {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||
@@ -120,8 +124,10 @@ half4 main(float2 coord) {
|
||||
val isDarkTheme = isSystemInDarkTheme()
|
||||
TextButton(
|
||||
onClick = {
|
||||
scope.launch { haptics.performHapticFeedback(HapticFeedbackType.ContextClick) }
|
||||
onClick()
|
||||
if (enabled) {
|
||||
scope.launch { haptics.performHapticFeedback(HapticFeedbackType.ContextClick) }
|
||||
onClick()
|
||||
}
|
||||
},
|
||||
shape = RoundedCornerShape(56.dp),
|
||||
modifier = modifier
|
||||
@@ -137,6 +143,7 @@ half4 main(float2 coord) {
|
||||
)
|
||||
},
|
||||
layerBlock = {
|
||||
if (!enabled) return@drawBackdrop
|
||||
val width = size.width
|
||||
val height = size.height
|
||||
|
||||
@@ -161,6 +168,12 @@ half4 main(float2 coord) {
|
||||
(height / width).fastCoerceAtMost(1f)
|
||||
},
|
||||
onDrawSurface = {
|
||||
if (!enabled) {
|
||||
drawRect(
|
||||
(if (isDarkTheme) Color(0xFFAFAFAF) else Color.White).copy(0.5f)
|
||||
)
|
||||
return@drawBackdrop
|
||||
}
|
||||
val progress = progressAnimation.value.coerceIn(0f, 1f)
|
||||
|
||||
val shape = RoundedCornerShape(56.dp)
|
||||
@@ -187,6 +200,10 @@ half4 main(float2 coord) {
|
||||
}
|
||||
drawLayer(innerShadowLayer)
|
||||
|
||||
if (surfaceColor.isSpecified) {
|
||||
drawRect(surfaceColor)
|
||||
}
|
||||
|
||||
drawRect(
|
||||
(if (isDarkTheme) Color(0xFFAFAFAF) else Color.White).copy(
|
||||
progress.coerceIn(
|
||||
@@ -197,6 +214,7 @@ half4 main(float2 coord) {
|
||||
)
|
||||
},
|
||||
onDrawFront = {
|
||||
if (!enabled) return@drawBackdrop
|
||||
val progress = progressAnimation.value.fastCoerceIn(0f, 1f)
|
||||
if (progress > 0f) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU && interactiveHighlightShader != null) {
|
||||
@@ -241,40 +259,46 @@ half4 main(float2 coord) {
|
||||
)
|
||||
.pointerInput(scope) {
|
||||
val onDragStop: () -> Unit = {
|
||||
scope.launch {
|
||||
launch { haptics.performHapticFeedback(HapticFeedbackType.Reject) }
|
||||
launch { progressAnimation.animateTo(0f, progressAnimationSpec) }
|
||||
launch { offsetAnimation.animateTo(Offset.Zero, offsetAnimationSpec) }
|
||||
if (enabled) {
|
||||
scope.launch {
|
||||
launch { haptics.performHapticFeedback(HapticFeedbackType.Reject) }
|
||||
launch { progressAnimation.animateTo(0f, progressAnimationSpec) }
|
||||
launch { offsetAnimation.animateTo(Offset.Zero, offsetAnimationSpec) }
|
||||
}
|
||||
}
|
||||
}
|
||||
inspectDragGestures(
|
||||
onDragStart = { down ->
|
||||
pressStartPosition = down.position
|
||||
scope.launch {
|
||||
launch { haptics.performHapticFeedback(HapticFeedbackType.SegmentFrequentTick) }
|
||||
launch { progressAnimation.animateTo(1f, progressAnimationSpec) }
|
||||
launch { offsetAnimation.snapTo(Offset.Zero) }
|
||||
if (enabled) {
|
||||
pressStartPosition = down.position
|
||||
scope.launch {
|
||||
launch { haptics.performHapticFeedback(HapticFeedbackType.SegmentFrequentTick) }
|
||||
launch { progressAnimation.animateTo(1f, progressAnimationSpec) }
|
||||
launch { offsetAnimation.snapTo(Offset.Zero) }
|
||||
}
|
||||
}
|
||||
},
|
||||
onDragEnd = { onDragStop() },
|
||||
onDragCancel = onDragStop
|
||||
) { _, dragAmount ->
|
||||
scope.launch {
|
||||
if (dragAmount.getDistanceSquared() > 350) haptics.performHapticFeedback(
|
||||
HapticFeedbackType.SegmentFrequentTick
|
||||
)
|
||||
offsetAnimation.snapTo(offsetAnimation.value + dragAmount)
|
||||
if (enabled) {
|
||||
if (dragAmount.getDistanceSquared() > 350) haptics.performHapticFeedback(
|
||||
HapticFeedbackType.SegmentFrequentTick
|
||||
)
|
||||
offsetAnimation.snapTo(offsetAnimation.value + dragAmount)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.size(48.dp),
|
||||
.size(with(density) { 48.sp.toDp() }),
|
||||
) {
|
||||
Text(
|
||||
text = icon,
|
||||
style = TextStyle(
|
||||
fontSize = 16.sp,
|
||||
fontSize = 20.sp,
|
||||
fontWeight = FontWeight.Normal,
|
||||
color = if (tint.isSpecified) tint else if (darkMode) Color.White else Color.Black,
|
||||
color = if (iconTint.isSpecified) iconTint else if (darkMode) Color.White else Color.Black,
|
||||
fontFamily = FontFamily(Font(R.font.sf_pro))
|
||||
)
|
||||
)
|
||||
|
||||
@@ -0,0 +1,154 @@
|
||||
package me.kavishdevar.librepods.presentation.components
|
||||
|
||||
import android.R.attr.singleLine
|
||||
import androidx.compose.animation.core.animateDp
|
||||
import androidx.compose.animation.core.animateDpAsState
|
||||
import androidx.compose.animation.core.updateTransition
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.gestures.detectTapGestures
|
||||
import androidx.compose.foundation.isSystemInDarkTheme
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.heightIn
|
||||
import androidx.compose.foundation.layout.offset
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.foundation.text.BasicTextField
|
||||
import androidx.compose.foundation.text.input.TextFieldLineLimits
|
||||
import androidx.compose.foundation.text.input.TextFieldState
|
||||
import androidx.compose.foundation.text.input.clearText
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.focus.FocusRequester
|
||||
import androidx.compose.ui.focus.focusRequester
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.SolidColor
|
||||
import androidx.compose.ui.input.pointer.pointerInput
|
||||
import androidx.compose.ui.platform.LocalDensity
|
||||
import androidx.compose.ui.text.TextStyle
|
||||
import androidx.compose.ui.text.font.Font
|
||||
import androidx.compose.ui.text.font.FontFamily
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import me.kavishdevar.librepods.R
|
||||
|
||||
|
||||
@Composable
|
||||
fun StyledInputField(
|
||||
inputState: TextFieldState,
|
||||
focusRequester: FocusRequester,
|
||||
placeholder: String = "",
|
||||
singleLine: Boolean = true
|
||||
){
|
||||
val isDarkTheme = isSystemInDarkTheme()
|
||||
val backgroundColor = if (isDarkTheme) Color(0xFF1C1C1E) else Color(0xFFFFFFFF)
|
||||
val textColor = if (isDarkTheme) Color.White else Color.Black
|
||||
val minHeight = if (singleLine) 58.dp else 120.dp
|
||||
val verticalAlignment = if (singleLine) Alignment.CenterVertically else Alignment.Top
|
||||
val hasText = inputState.text.isNotEmpty()
|
||||
val density = LocalDensity.current
|
||||
val spacerHeight by animateDpAsState(
|
||||
targetValue = if (hasText) with(density) { 32.sp.toDp() } else 0.dp,
|
||||
label = "labelSpacer"
|
||||
)
|
||||
|
||||
val transition = updateTransition(hasText, label = "floating")
|
||||
val yOffset by transition.animateDp(label = "y") {
|
||||
if (it) with (density) { (-48).sp.toDp() } else 0.dp
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.height(spacerHeight))
|
||||
|
||||
Box(
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
) {
|
||||
Row(
|
||||
verticalAlignment = verticalAlignment,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.heightIn(min = minHeight)
|
||||
.background(
|
||||
backgroundColor,
|
||||
RoundedCornerShape(28.dp)
|
||||
)
|
||||
.padding(horizontal = 16.dp, vertical = 8.dp)
|
||||
.pointerInput(Unit) {
|
||||
detectTapGestures {
|
||||
focusRequester.requestFocus()
|
||||
}
|
||||
}
|
||||
) {
|
||||
BasicTextField(
|
||||
state = inputState,
|
||||
lineLimits = if (singleLine) TextFieldLineLimits.SingleLine else TextFieldLineLimits.Default,
|
||||
textStyle = TextStyle(
|
||||
fontSize = 16.sp,
|
||||
color = textColor,
|
||||
fontFamily = FontFamily(Font(R.font.sf_pro))
|
||||
),
|
||||
cursorBrush = SolidColor(textColor),
|
||||
decorator = { innerTextField ->
|
||||
Row(
|
||||
modifier = Modifier.padding(top = if (singleLine) 0.dp else 16.dp),
|
||||
verticalAlignment = verticalAlignment,
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.weight(1f),
|
||||
contentAlignment = if (singleLine) Alignment.CenterStart else Alignment.TopStart
|
||||
) {
|
||||
Text(
|
||||
text = placeholder,
|
||||
style = TextStyle(
|
||||
fontSize = 16.sp,
|
||||
fontWeight = FontWeight.Light,
|
||||
fontFamily = FontFamily(Font(R.font.sf_pro)),
|
||||
color = textColor.copy(alpha = 0.8f)
|
||||
),
|
||||
modifier = Modifier
|
||||
.offset(y = yOffset)
|
||||
)
|
||||
|
||||
innerTextField()
|
||||
}
|
||||
}
|
||||
if (singleLine && !inputState.text.isEmpty()) {
|
||||
IconButton(
|
||||
onClick = {
|
||||
inputState.clearText()
|
||||
}
|
||||
) {
|
||||
Text(
|
||||
text = "",
|
||||
style = TextStyle(
|
||||
fontSize = 16.sp,
|
||||
fontFamily = FontFamily(Font(R.font.sf_pro)),
|
||||
color = if (isDarkTheme) Color.White.copy(alpha = 0.6f) else Color.Black.copy(
|
||||
alpha = 0.6f
|
||||
)
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(start = 8.dp)
|
||||
.focusRequester(focusRequester)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -77,7 +77,7 @@ fun StyledScaffold(
|
||||
.clip(RoundedCornerShape(52.dp))
|
||||
) { paddingValues ->
|
||||
val topPadding = paddingValues.calculateTopPadding()
|
||||
val bottomPadding = paddingValues.calculateBottomPadding()
|
||||
val bottomPadding = paddingValues.calculateBottomPadding() + 16.dp
|
||||
val startPadding = paddingValues.calculateLeftPadding(LocalLayoutDirection.current)
|
||||
val endPadding = paddingValues.calculateRightPadding(LocalLayoutDirection.current)
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@ import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.heightIn
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.wrapContentWidth
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
@@ -39,7 +40,6 @@ import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
@@ -74,7 +74,6 @@ fun StyledSelectList(
|
||||
val backgroundColor = if (isDarkTheme) Color(0xFF1C1C1E) else Color(0xFFFFFFFF)
|
||||
val textColor = if (isDarkTheme) Color.White else Color.Black
|
||||
|
||||
val scope = rememberCoroutineScope()
|
||||
val haptics = LocalHapticFeedback.current
|
||||
|
||||
Column(
|
||||
@@ -100,7 +99,7 @@ fun StyledSelectList(
|
||||
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.height(if (hasIcon) 72.dp else 55.dp)
|
||||
.heightIn(min = if (hasIcon) 72.dp else 55.dp)
|
||||
.background(animatedBackgroundColor, shape)
|
||||
.pointerInput(Unit) {
|
||||
detectTapGestures(
|
||||
|
||||
@@ -712,8 +712,16 @@ class IslandWindow(private val context: Context) {
|
||||
}
|
||||
isClosing = false
|
||||
// Make sure all animations are canceled
|
||||
springAnimation.cancel()
|
||||
flingAnimator.cancel()
|
||||
try {
|
||||
springAnimation.cancel()
|
||||
} catch (e: Exception) {
|
||||
e("IslandWindow", "Error cancelling spring animation $e")
|
||||
}
|
||||
try {
|
||||
flingAnimator.cancel()
|
||||
} catch (e: Exception) {
|
||||
e("IslandWindow", "Error cancelling fling animation $e")
|
||||
}
|
||||
}
|
||||
|
||||
fun forceClose() {
|
||||
|
||||
@@ -20,6 +20,7 @@ package me.kavishdevar.librepods.presentation.screens
|
||||
|
||||
// import me.kavishdevar.librepods.utils.RadareOffsetFinder
|
||||
import android.annotation.SuppressLint
|
||||
import android.util.Log
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.gestures.detectDragGesturesAfterLongPress
|
||||
import androidx.compose.foundation.gestures.detectTapGestures
|
||||
@@ -39,6 +40,7 @@ import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableLongStateOf
|
||||
@@ -71,6 +73,10 @@ import com.kyant.backdrop.backdrops.rememberLayerBackdrop
|
||||
import dev.chrisbanes.haze.HazeState
|
||||
import dev.chrisbanes.haze.hazeSource
|
||||
import dev.chrisbanes.haze.materials.ExperimentalHazeMaterialsApi
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
import me.kavishdevar.librepods.R
|
||||
import me.kavishdevar.librepods.bluetooth.AACPManager
|
||||
@@ -85,8 +91,8 @@ import me.kavishdevar.librepods.presentation.components.StyledToggle
|
||||
import me.kavishdevar.librepods.presentation.viewmodel.AirPodsViewModel
|
||||
import kotlin.io.encoding.ExperimentalEncodingApi
|
||||
|
||||
//private var phoneMediaDebounceJob: Job? = null
|
||||
//private var toneVolumeDebounceJob: Job? = null
|
||||
private var phoneMediaDebounceJob: Job? = null
|
||||
private var toneVolumeDebounceJob: Job? = null
|
||||
//private const val TAG = "AccessibilitySettings"
|
||||
|
||||
@SuppressLint("DefaultLocale")
|
||||
@@ -99,7 +105,13 @@ fun AccessibilitySettingsScreen(viewModel: AirPodsViewModel, navController: NavC
|
||||
val isDarkTheme = isSystemInDarkTheme()
|
||||
val textColor = if (isDarkTheme) Color.White else Color.Black
|
||||
|
||||
val hearingAidEnabled = state.controlStates[AACPManager.Companion.ControlCommandIdentifiers.HEARING_AID]?.getOrNull(1)?.toInt() == 1 && state.controlStates[AACPManager.Companion.ControlCommandIdentifiers.HEARING_AID]?.getOrNull(0)?.toInt() == 1
|
||||
val hearingAidEnabled =
|
||||
state.controlStates[AACPManager.Companion.ControlCommandIdentifiers.HEARING_AID]?.getOrNull(
|
||||
1
|
||||
)
|
||||
?.toInt() == 1 && state.controlStates[AACPManager.Companion.ControlCommandIdentifiers.HEARING_AID]?.getOrNull(
|
||||
0
|
||||
)?.toInt() == 1
|
||||
|
||||
val backdrop = rememberLayerBackdrop()
|
||||
|
||||
@@ -125,7 +137,7 @@ fun AccessibilitySettingsScreen(viewModel: AirPodsViewModel, navController: NavC
|
||||
backdrop = rememberLayerBackdrop(),
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
maxScale = 0.05f,
|
||||
tint = if (isSystemInDarkTheme()) Color(0xFF916100) else Color(0xFFE59900)
|
||||
surfaceColor = if (isSystemInDarkTheme()) Color(0xFF916100) else Color(0xFFE59900)
|
||||
) {
|
||||
Text(
|
||||
stringResource(R.string.unlock_advanced_features),
|
||||
@@ -149,7 +161,10 @@ fun AccessibilitySettingsScreen(viewModel: AirPodsViewModel, navController: NavC
|
||||
2.toByte() to stringResource(R.string.slowest)
|
||||
)
|
||||
|
||||
val selectedPressSpeedValue = state.controlStates[AACPManager.Companion.ControlCommandIdentifiers.DOUBLE_CLICK_INTERVAL]?.getOrNull(0)
|
||||
val selectedPressSpeedValue =
|
||||
state.controlStates[AACPManager.Companion.ControlCommandIdentifiers.DOUBLE_CLICK_INTERVAL]?.getOrNull(
|
||||
0
|
||||
)
|
||||
var selectedPressSpeed by remember {
|
||||
mutableStateOf(
|
||||
pressSpeedOptions[selectedPressSpeedValue] ?: pressSpeedOptions[0]
|
||||
@@ -162,7 +177,10 @@ fun AccessibilitySettingsScreen(viewModel: AirPodsViewModel, navController: NavC
|
||||
2.toByte() to stringResource(R.string.slowest)
|
||||
)
|
||||
|
||||
val selectedPressAndHoldDurationValue = state.controlStates[AACPManager.Companion.ControlCommandIdentifiers.CLICK_HOLD_INTERVAL]?.getOrNull(0)
|
||||
val selectedPressAndHoldDurationValue =
|
||||
state.controlStates[AACPManager.Companion.ControlCommandIdentifiers.CLICK_HOLD_INTERVAL]?.getOrNull(
|
||||
0
|
||||
)
|
||||
var selectedPressAndHoldDuration by remember {
|
||||
mutableStateOf(
|
||||
pressAndHoldDurationOptions[selectedPressAndHoldDurationValue]
|
||||
@@ -175,7 +193,10 @@ fun AccessibilitySettingsScreen(viewModel: AirPodsViewModel, navController: NavC
|
||||
2.toByte() to stringResource(R.string.longer),
|
||||
3.toByte() to stringResource(R.string.longest)
|
||||
)
|
||||
val selectedVolumeSwipeSpeedValue = state.controlStates[AACPManager.Companion.ControlCommandIdentifiers.VOLUME_SWIPE_INTERVAL]?.getOrNull(0)
|
||||
val selectedVolumeSwipeSpeedValue =
|
||||
state.controlStates[AACPManager.Companion.ControlCommandIdentifiers.VOLUME_SWIPE_INTERVAL]?.getOrNull(
|
||||
0
|
||||
)
|
||||
var selectedVolumeSwipeSpeed by remember {
|
||||
mutableStateOf(
|
||||
volumeSwipeSpeedOptions[selectedVolumeSwipeSpeedValue]
|
||||
@@ -183,43 +204,42 @@ fun AccessibilitySettingsScreen(viewModel: AirPodsViewModel, navController: NavC
|
||||
)
|
||||
}
|
||||
|
||||
// LaunchedEffect(phoneMediaEQ.value, phoneEQEnabled.value, mediaEQEnabled.value) {
|
||||
// phoneMediaDebounceJob?.cancel()
|
||||
// phoneMediaDebounceJob = CoroutineScope(Dispatchers.IO).launch {
|
||||
// delay(150)
|
||||
// val manager = ServiceManager.getService()?.aacpManager
|
||||
// if (manager == null) {
|
||||
// Log.w(TAG, "Cannot write EQ: AACPManager not available")
|
||||
// return@launch
|
||||
// }
|
||||
// try {
|
||||
// val phoneByte = if (phoneEQEnabled.value) 0x01.toByte() else 0x02.toByte()
|
||||
// val mediaByte = if (mediaEQEnabled.value) 0x01.toByte() else 0x02.toByte()
|
||||
// Log.d(
|
||||
// TAG,
|
||||
// "Sending phone/media EQ (phoneEnabled=${phoneEQEnabled.value}, mediaEnabled=${mediaEQEnabled.value})"
|
||||
// )
|
||||
// manager.sendPhoneMediaEQ(phoneMediaEQ.value, phoneByte, mediaByte)
|
||||
// } catch (e: Exception) {
|
||||
// Log.w(TAG, "Error sending phone/media EQ: ${e.message}")
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
Box (
|
||||
val phoneMediaEQ = remember { mutableStateOf(FloatArray(8) { 0.5f }) }
|
||||
val phoneEQEnabled = remember { mutableStateOf(false) }
|
||||
val mediaEQEnabled = remember { mutableStateOf(false) }
|
||||
|
||||
LaunchedEffect(phoneMediaEQ.value, phoneEQEnabled.value, mediaEQEnabled.value) {
|
||||
phoneMediaDebounceJob?.cancel()
|
||||
phoneMediaDebounceJob = CoroutineScope(Dispatchers.IO).launch {
|
||||
delay(150)
|
||||
try {
|
||||
val phoneByte = if (phoneEQEnabled.value) 0x01.toByte() else 0x02.toByte()
|
||||
val mediaByte = if (mediaEQEnabled.value) 0x01.toByte() else 0x02.toByte()
|
||||
Log.d(
|
||||
"AccessibilitySettingsScreen",
|
||||
"Sending phone/media EQ (phoneEnabled=${phoneEQEnabled.value}, mediaEnabled=${mediaEQEnabled.value})"
|
||||
)
|
||||
viewModel.sendPhoneMediaEQ(phoneMediaEQ.value, phoneByte, mediaByte)
|
||||
} catch (e: Exception) {
|
||||
Log.w(
|
||||
"AccessibilitySettingsScreen",
|
||||
"Error sending phone/media EQ: ${e.message}"
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
Box(
|
||||
modifier = Modifier.then(
|
||||
if (!state.isPremium) {
|
||||
Modifier
|
||||
.pointerInput(Unit) {
|
||||
awaitPointerEventScope {
|
||||
while (true) {
|
||||
val event = awaitPointerEvent(PointerEventPass.Initial)
|
||||
event.changes.forEach { it.consume() }
|
||||
}
|
||||
}
|
||||
}
|
||||
} else Modifier
|
||||
)
|
||||
) {
|
||||
Modifier.pointerInput(Unit) {
|
||||
awaitPointerEventScope {
|
||||
while (true) {
|
||||
val event = awaitPointerEvent(PointerEventPass.Initial)
|
||||
event.changes.forEach { it.consume() }
|
||||
}
|
||||
}
|
||||
}
|
||||
} else Modifier)) {
|
||||
DropdownMenuComponent(
|
||||
label = stringResource(R.string.press_speed),
|
||||
description = stringResource(R.string.press_speed_description),
|
||||
@@ -239,21 +259,18 @@ fun AccessibilitySettingsScreen(viewModel: AirPodsViewModel, navController: NavC
|
||||
)
|
||||
}
|
||||
|
||||
Box (
|
||||
Box(
|
||||
modifier = Modifier.then(
|
||||
if (!state.isPremium) {
|
||||
Modifier
|
||||
.pointerInput(Unit) {
|
||||
awaitPointerEventScope {
|
||||
while (true) {
|
||||
val event = awaitPointerEvent(PointerEventPass.Initial)
|
||||
event.changes.forEach { it.consume() }
|
||||
}
|
||||
}
|
||||
}
|
||||
} else Modifier
|
||||
)
|
||||
) {
|
||||
if (!state.isPremium) {
|
||||
Modifier.pointerInput(Unit) {
|
||||
awaitPointerEventScope {
|
||||
while (true) {
|
||||
val event = awaitPointerEvent(PointerEventPass.Initial)
|
||||
event.changes.forEach { it.consume() }
|
||||
}
|
||||
}
|
||||
}
|
||||
} else Modifier)) {
|
||||
DropdownMenuComponent(
|
||||
label = stringResource(R.string.press_and_hold_duration),
|
||||
description = stringResource(R.string.press_and_hold_duration_description),
|
||||
@@ -278,8 +295,14 @@ fun AccessibilitySettingsScreen(viewModel: AirPodsViewModel, navController: NavC
|
||||
label = stringResource(R.string.noise_cancellation_single_airpod),
|
||||
description = stringResource(R.string.noise_cancellation_single_airpod_description),
|
||||
independent = true,
|
||||
checked = state.controlStates[AACPManager.Companion.ControlCommandIdentifiers.ONE_BUD_ANC_MODE]?.getOrNull(0) == 0x01.toByte(),
|
||||
onCheckedChange = { viewModel.setControlCommandBoolean(AACPManager.Companion.ControlCommandIdentifiers.ONE_BUD_ANC_MODE, it) },
|
||||
checked = state.controlStates[AACPManager.Companion.ControlCommandIdentifiers.ONE_BUD_ANC_MODE]?.getOrNull(
|
||||
0
|
||||
) == 0x01.toByte(),
|
||||
onCheckedChange = {
|
||||
viewModel.setControlCommandBoolean(
|
||||
AACPManager.Companion.ControlCommandIdentifiers.ONE_BUD_ANC_MODE, it
|
||||
)
|
||||
},
|
||||
enabled = state.isPremium
|
||||
)
|
||||
|
||||
@@ -288,7 +311,12 @@ fun AccessibilitySettingsScreen(viewModel: AirPodsViewModel, navController: NavC
|
||||
label = stringResource(R.string.loud_sound_reduction),
|
||||
description = stringResource(R.string.loud_sound_reduction_description),
|
||||
checked = state.loudSoundReductionEnabled,
|
||||
onCheckedChange = { viewModel.setATTCharacteristicValue(ATTHandles.LOUD_SOUND_REDUCTION, if (it) byteArrayOf(0x01) else byteArrayOf(0x00)) },
|
||||
onCheckedChange = {
|
||||
viewModel.setATTCharacteristicValue(
|
||||
ATTHandles.LOUD_SOUND_REDUCTION,
|
||||
if (it) byteArrayOf(0x01) else byteArrayOf(0x00)
|
||||
)
|
||||
},
|
||||
enabled = state.isPremium
|
||||
)
|
||||
}
|
||||
@@ -302,13 +330,19 @@ fun AccessibilitySettingsScreen(viewModel: AirPodsViewModel, navController: NavC
|
||||
)
|
||||
}
|
||||
|
||||
val toneVolumeValue = state.controlStates[AACPManager.Companion.ControlCommandIdentifiers.CHIME_VOLUME]?.getOrNull(0)?.toFloat() ?: 75f
|
||||
val toneVolumeValue =
|
||||
state.controlStates[AACPManager.Companion.ControlCommandIdentifiers.CHIME_VOLUME]?.getOrNull(
|
||||
0
|
||||
)?.toFloat() ?: 75f
|
||||
StyledSlider(
|
||||
label = stringResource(R.string.tone_volume),
|
||||
description = stringResource(R.string.tone_volume_description),
|
||||
value = toneVolumeValue,
|
||||
onValueChange = {
|
||||
viewModel.setControlCommandValue(AACPManager.Companion.ControlCommandIdentifiers.CHIME_VOLUME, byteArrayOf(it.toInt().toByte(), 0x50))
|
||||
viewModel.setControlCommandValue(
|
||||
AACPManager.Companion.ControlCommandIdentifiers.CHIME_VOLUME,
|
||||
byteArrayOf(it.toInt().toByte(), 0x50)
|
||||
)
|
||||
},
|
||||
valueRange = 0f..100f,
|
||||
snapPoints = listOf(75f),
|
||||
@@ -319,30 +353,34 @@ fun AccessibilitySettingsScreen(viewModel: AirPodsViewModel, navController: NavC
|
||||
)
|
||||
|
||||
if (state.capabilities.contains(Capability.SWIPE_FOR_VOLUME)) {
|
||||
val volumeSwipeEnabled = state.controlStates[AACPManager.Companion.ControlCommandIdentifiers.VOLUME_SWIPE_MODE]?.getOrNull(0)?.toInt() == 0x01
|
||||
val volumeSwipeEnabled =
|
||||
state.controlStates[AACPManager.Companion.ControlCommandIdentifiers.VOLUME_SWIPE_MODE]?.getOrNull(
|
||||
0
|
||||
)?.toInt() == 0x01
|
||||
StyledToggle(
|
||||
label = stringResource(R.string.volume_control),
|
||||
description = stringResource(R.string.volume_control_description),
|
||||
checked = volumeSwipeEnabled,
|
||||
onCheckedChange = { viewModel.setControlCommandBoolean(AACPManager.Companion.ControlCommandIdentifiers.VOLUME_SWIPE_MODE, it) },
|
||||
onCheckedChange = {
|
||||
viewModel.setControlCommandBoolean(
|
||||
AACPManager.Companion.ControlCommandIdentifiers.VOLUME_SWIPE_MODE, it
|
||||
)
|
||||
},
|
||||
enabled = state.isPremium
|
||||
)
|
||||
|
||||
Box (
|
||||
Box(
|
||||
modifier = Modifier.then(
|
||||
if (!state.isPremium) {
|
||||
Modifier
|
||||
.pointerInput(Unit) {
|
||||
awaitPointerEventScope {
|
||||
while (true) {
|
||||
val event = awaitPointerEvent(PointerEventPass.Initial)
|
||||
event.changes.forEach { it.consume() }
|
||||
}
|
||||
}
|
||||
}
|
||||
} else Modifier
|
||||
)
|
||||
) {
|
||||
Modifier.pointerInput(Unit) {
|
||||
awaitPointerEventScope {
|
||||
while (true) {
|
||||
val event = awaitPointerEvent(PointerEventPass.Initial)
|
||||
event.changes.forEach { it.consume() }
|
||||
}
|
||||
}
|
||||
}
|
||||
} else Modifier)) {
|
||||
DropdownMenuComponent(
|
||||
label = stringResource(R.string.volume_swipe_speed),
|
||||
description = stringResource(R.string.volume_swipe_speed_description),
|
||||
@@ -364,21 +402,22 @@ fun AccessibilitySettingsScreen(viewModel: AirPodsViewModel, navController: NavC
|
||||
}
|
||||
}
|
||||
|
||||
// if (!hearingAidEnabled.value&& BuildConfig.FLAVOR == "xposed") {
|
||||
// if (!hearingAidEnabled && XposedState.isAvailable) {
|
||||
// Text(
|
||||
// text = stringResource(R.string.apply_eq_to),
|
||||
// style = TextStyle(
|
||||
// text = stringResource(R.string.apply_eq_to), style = TextStyle(
|
||||
// fontSize = 14.sp,
|
||||
// fontWeight = FontWeight.Bold,
|
||||
// color = textColor.copy(alpha = 0.6f),
|
||||
// fontFamily = FontFamily(Font(R.font.sf_pro))
|
||||
// ),
|
||||
// modifier = Modifier.padding(8.dp, bottom = 0.dp)
|
||||
// ), modifier = Modifier.padding(8.dp, bottom = 0.dp)
|
||||
// )
|
||||
// Column(
|
||||
// modifier = Modifier
|
||||
// .fillMaxWidth()
|
||||
// .background(backgroundColor, RoundedCornerShape(28.dp))
|
||||
// .background(
|
||||
// if (isDarkTheme) Color(0xFF1C1C1E) else Color(0xFFFFFFFF),
|
||||
// RoundedCornerShape(28.dp)
|
||||
// )
|
||||
// .padding(vertical = 0.dp)
|
||||
// ) {
|
||||
// val darkModeLocal = isSystemInDarkTheme()
|
||||
@@ -405,17 +444,19 @@ fun AccessibilitySettingsScreen(viewModel: AirPodsViewModel, navController: NavC
|
||||
// detectTapGestures(
|
||||
// onPress = {
|
||||
// phoneBackgroundColor =
|
||||
// if (darkModeLocal) Color(0x40888888) else Color(0x40D9D9D9)
|
||||
// if (darkModeLocal) Color(0x40888888) else Color(
|
||||
// 0x40D9D9D9
|
||||
// )
|
||||
// tryAwaitRelease()
|
||||
// phoneBackgroundColor =
|
||||
// if (darkModeLocal) Color(0xFF1C1C1E) else Color(0xFFFFFFFF)
|
||||
// if (darkModeLocal) Color(0xFF1C1C1E) else Color(
|
||||
// 0xFFFFFFFF
|
||||
// )
|
||||
// phoneEQEnabled.value = !phoneEQEnabled.value
|
||||
// }
|
||||
// )
|
||||
// })
|
||||
// }
|
||||
// .padding(horizontal = 16.dp),
|
||||
// verticalAlignment = Alignment.CenterVertically
|
||||
// ) {
|
||||
// verticalAlignment = Alignment.CenterVertically) {
|
||||
// Text(
|
||||
// stringResource(R.string.phone),
|
||||
// fontSize = 16.sp,
|
||||
@@ -441,8 +482,7 @@ fun AccessibilitySettingsScreen(viewModel: AirPodsViewModel, navController: NavC
|
||||
// }
|
||||
//
|
||||
// HorizontalDivider(
|
||||
// thickness = 1.dp,
|
||||
// color = Color(0x40888888)
|
||||
// thickness = 1.dp, color = Color(0x40888888)
|
||||
// )
|
||||
//
|
||||
// val mediaShape = RoundedCornerShape(bottomStart = 28.dp, bottomEnd = 28.dp)
|
||||
@@ -467,17 +507,19 @@ fun AccessibilitySettingsScreen(viewModel: AirPodsViewModel, navController: NavC
|
||||
// detectTapGestures(
|
||||
// onPress = {
|
||||
// mediaBackgroundColor =
|
||||
// if (darkModeLocal) Color(0x40888888) else Color(0x40D9D9D9)
|
||||
// if (darkModeLocal) Color(0x40888888) else Color(
|
||||
// 0x40D9D9D9
|
||||
// )
|
||||
// tryAwaitRelease()
|
||||
// mediaBackgroundColor =
|
||||
// if (darkModeLocal) Color(0xFF1C1C1E) else Color(0xFFFFFFFF)
|
||||
// if (darkModeLocal) Color(0xFF1C1C1E) else Color(
|
||||
// 0xFFFFFFFF
|
||||
// )
|
||||
// mediaEQEnabled.value = !mediaEQEnabled.value
|
||||
// }
|
||||
// )
|
||||
// })
|
||||
// }
|
||||
// .padding(horizontal = 16.dp),
|
||||
// verticalAlignment = Alignment.CenterVertically
|
||||
// ) {
|
||||
// verticalAlignment = Alignment.CenterVertically) {
|
||||
// Text(
|
||||
// stringResource(R.string.media),
|
||||
// fontSize = 16.sp,
|
||||
@@ -502,90 +544,97 @@ fun AccessibilitySettingsScreen(viewModel: AirPodsViewModel, navController: NavC
|
||||
// )
|
||||
// }
|
||||
// }
|
||||
|
||||
// EQ Settings. Don't seem to have an effect?
|
||||
// Column(
|
||||
// modifier = Modifier
|
||||
// .fillMaxWidth()
|
||||
// .background(backgroundColor, RoundedCornerShape(28.dp))
|
||||
// .padding(12.dp),
|
||||
// horizontalAlignment = Alignment.CenterHorizontally
|
||||
// ) {
|
||||
// for (i in 0 until 8) {
|
||||
// val eqPhoneValue =
|
||||
// remember(phoneMediaEQ.value[i]) { mutableFloatStateOf(phoneMediaEQ.value[i]) }
|
||||
// Row(
|
||||
// horizontalArrangement = Arrangement.SpaceBetween,
|
||||
// verticalAlignment = Alignment.CenterVertically,
|
||||
// modifier = Modifier
|
||||
// .fillMaxWidth()
|
||||
// .height(38.dp)
|
||||
// ) {
|
||||
// Text(
|
||||
// text = String.format("%.2f", eqPhoneValue.floatValue),
|
||||
// fontSize = 12.sp,
|
||||
// color = textColor,
|
||||
// modifier = Modifier.padding(bottom = 4.dp)
|
||||
// )
|
||||
|
||||
// Slider(
|
||||
// value = eqPhoneValue.floatValue,
|
||||
// onValueChange = { newVal ->
|
||||
// eqPhoneValue.floatValue = newVal
|
||||
// val newEQ = phoneMediaEQ.value.copyOf()
|
||||
// newEQ[i] = eqPhoneValue.floatValue
|
||||
// phoneMediaEQ.value = newEQ
|
||||
// },
|
||||
// valueRange = 0f..100f,
|
||||
// modifier = Modifier
|
||||
// .fillMaxWidth(0.9f)
|
||||
// .height(36.dp),
|
||||
// colors = SliderDefaults.colors(
|
||||
// thumbColor = thumbColor,
|
||||
// activeTrackColor = activeTrackColor,
|
||||
// inactiveTrackColor = trackColor
|
||||
// ),
|
||||
// thumb = {
|
||||
// Box(
|
||||
// modifier = Modifier
|
||||
// .size(24.dp)
|
||||
// .shadow(4.dp, CircleShape)
|
||||
// .background(thumbColor, CircleShape)
|
||||
// )
|
||||
// },
|
||||
// track = {
|
||||
// Box(
|
||||
// modifier = Modifier
|
||||
// .fillMaxWidth()
|
||||
// .height(12.dp),
|
||||
// contentAlignment = Alignment.CenterStart
|
||||
// )
|
||||
// {
|
||||
// Box(
|
||||
// modifier = Modifier
|
||||
// .fillMaxWidth()
|
||||
// .height(4.dp)
|
||||
// .background(trackColor, RoundedCornerShape(4.dp))
|
||||
// )
|
||||
// Box(
|
||||
// modifier = Modifier
|
||||
// .fillMaxWidth(eqPhoneValue.floatValue / 100f)
|
||||
// .height(4.dp)
|
||||
// .background(activeTrackColor, RoundedCornerShape(4.dp))
|
||||
// )
|
||||
// }
|
||||
// }
|
||||
// )
|
||||
|
||||
// Text(
|
||||
// text = stringResource(R.string.band_label, i + 1),
|
||||
// fontSize = 12.sp,
|
||||
// color = textColor,
|
||||
// modifier = Modifier.padding(top = 4.dp)
|
||||
// )
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//// EQ Settings. Don't seem to have an effect?
|
||||
// Column(
|
||||
// modifier = Modifier
|
||||
// .fillMaxWidth()
|
||||
// .background(
|
||||
// if (isDarkTheme) Color(0xFF1C1C1E) else Color(0xFFFFFFFF),
|
||||
// RoundedCornerShape(28.dp)
|
||||
// )
|
||||
// .padding(12.dp), horizontalAlignment = Alignment.CenterHorizontally
|
||||
// ) {
|
||||
// val trackColor = if (isDarkTheme) Color(0xFFB3B3B3) else Color(0xFF929491)
|
||||
// val activeTrackColor = if (isDarkTheme) Color(0xFF007AFF) else Color(0xFF3C6DF5)
|
||||
// val thumbColor = if (isDarkTheme) Color(0xFFFFFFFF) else Color(0xFFFFFFFF)
|
||||
//
|
||||
// for (i in 0 until 8) {
|
||||
// val eqPhoneValue =
|
||||
// remember(phoneMediaEQ.value[i]) { mutableFloatStateOf(phoneMediaEQ.value[i]) }
|
||||
// Row(
|
||||
// horizontalArrangement = Arrangement.SpaceBetween,
|
||||
// verticalAlignment = Alignment.CenterVertically,
|
||||
// modifier = Modifier
|
||||
// .fillMaxWidth()
|
||||
// .height(38.dp)
|
||||
// ) {
|
||||
// Text(
|
||||
// text = String.format("%.2f", eqPhoneValue.floatValue),
|
||||
// fontSize = 12.sp,
|
||||
// color = textColor,
|
||||
// modifier = Modifier.padding(bottom = 4.dp)
|
||||
// )
|
||||
//
|
||||
// Slider(
|
||||
// value = eqPhoneValue.floatValue,
|
||||
// onValueChange = { newVal ->
|
||||
// eqPhoneValue.floatValue = newVal
|
||||
// val newEQ = phoneMediaEQ.value.copyOf()
|
||||
// newEQ[i] = eqPhoneValue.floatValue
|
||||
// phoneMediaEQ.value = newEQ
|
||||
// },
|
||||
// valueRange = 0f..100f,
|
||||
// modifier = Modifier
|
||||
// .fillMaxWidth(0.9f)
|
||||
// .height(36.dp),
|
||||
// colors = SliderDefaults.colors(
|
||||
// thumbColor = thumbColor,
|
||||
// activeTrackColor = activeTrackColor,
|
||||
// inactiveTrackColor = trackColor
|
||||
// ),
|
||||
// thumb = {
|
||||
// Box(
|
||||
// modifier = Modifier
|
||||
// .size(24.dp)
|
||||
// .shadow(4.dp, CircleShape)
|
||||
// .background(thumbColor, CircleShape)
|
||||
// )
|
||||
// },
|
||||
// track = {
|
||||
// Box(
|
||||
// modifier = Modifier
|
||||
// .fillMaxWidth()
|
||||
// .height(12.dp),
|
||||
// contentAlignment = Alignment.CenterStart
|
||||
// ) {
|
||||
// Box(
|
||||
// modifier = Modifier
|
||||
// .fillMaxWidth()
|
||||
// .height(4.dp)
|
||||
// .background(trackColor, RoundedCornerShape(4.dp))
|
||||
// )
|
||||
// Box(
|
||||
// modifier = Modifier
|
||||
// .fillMaxWidth(eqPhoneValue.floatValue / 100f)
|
||||
// .height(4.dp)
|
||||
// .background(
|
||||
// activeTrackColor, RoundedCornerShape(4.dp)
|
||||
// )
|
||||
// )
|
||||
// }
|
||||
// })
|
||||
//
|
||||
// Text(
|
||||
// text = stringResource(R.string.band_label, i + 1),
|
||||
// fontSize = 12.sp,
|
||||
// color = textColor,
|
||||
// modifier = Modifier.padding(top = 4.dp)
|
||||
// )
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
Spacer(modifier = Modifier.height(bottomPadding))
|
||||
}
|
||||
}
|
||||
@@ -616,7 +665,7 @@ private fun DropdownMenuComponent(
|
||||
val haptics = LocalHapticFeedback.current
|
||||
val scope = rememberCoroutineScope()
|
||||
|
||||
Column(modifier = Modifier.fillMaxWidth()){
|
||||
Column(modifier = Modifier.fillMaxWidth()) {
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
@@ -630,14 +679,14 @@ private fun DropdownMenuComponent(
|
||||
} else Modifier
|
||||
)
|
||||
.background(
|
||||
if (independent) (if (isSystemInDarkTheme()) Color(0xFF1C1C1E) else Color(0xFFFFFFFF)) else Color.Transparent,
|
||||
if (independent) (if (isSystemInDarkTheme()) Color(0xFF1C1C1E) else Color(
|
||||
0xFFFFFFFF
|
||||
)) else Color.Transparent,
|
||||
if (independent) RoundedCornerShape(28.dp) else RoundedCornerShape(0.dp)
|
||||
)
|
||||
then(
|
||||
if (independent) Modifier.padding(horizontal = 4.dp) else Modifier
|
||||
)
|
||||
.clip(if (independent) RoundedCornerShape(28.dp) else RoundedCornerShape(0.dp))
|
||||
){
|
||||
) then (if (independent) Modifier.padding(horizontal = 4.dp) else Modifier).clip(
|
||||
if (independent) RoundedCornerShape(28.dp) else RoundedCornerShape(0.dp)
|
||||
)
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
@@ -658,98 +707,94 @@ private fun DropdownMenuComponent(
|
||||
}
|
||||
}
|
||||
.pointerInput(Unit) {
|
||||
detectDragGesturesAfterLongPress(
|
||||
onDragStart = { offset ->
|
||||
val now = System.currentTimeMillis()
|
||||
touchOffset = offset
|
||||
if (!expanded && now - lastDismissTime > 250L) {
|
||||
expanded = true
|
||||
}
|
||||
lastDismissTime = now
|
||||
parentDragActive = true
|
||||
parentHoveredIndex = 0
|
||||
},
|
||||
onDrag = { change, _ ->
|
||||
val current = change.position
|
||||
val touch = touchOffset ?: current
|
||||
val posInPopupY = current.y - touch.y
|
||||
val idx = (posInPopupY / itemHeightPx).toInt()
|
||||
if (idx != previousIdx) {
|
||||
scope.launch { haptics.performHapticFeedback(HapticFeedbackType.SegmentTick) }
|
||||
}
|
||||
parentHoveredIndex = idx
|
||||
previousIdx = idx
|
||||
},
|
||||
onDragEnd = {
|
||||
parentDragActive = false
|
||||
parentHoveredIndex?.let { idx ->
|
||||
if (idx in options.indices) {
|
||||
onOptionSelected(options[idx])
|
||||
expanded = false
|
||||
lastDismissTime = System.currentTimeMillis()
|
||||
}
|
||||
}
|
||||
if (parentHoveredIndex != null && parentHoveredIndex in options.indices) {
|
||||
scope.launch { haptics.performHapticFeedback(HapticFeedbackType.GestureEnd) }
|
||||
}
|
||||
parentHoveredIndex = null
|
||||
},
|
||||
onDragCancel = {
|
||||
parentDragActive = false
|
||||
parentHoveredIndex = null
|
||||
detectDragGesturesAfterLongPress(onDragStart = { offset ->
|
||||
val now = System.currentTimeMillis()
|
||||
touchOffset = offset
|
||||
if (!expanded && now - lastDismissTime > 250L) {
|
||||
expanded = true
|
||||
}
|
||||
)
|
||||
lastDismissTime = now
|
||||
parentDragActive = true
|
||||
parentHoveredIndex = 0
|
||||
}, onDrag = { change, _ ->
|
||||
val current = change.position
|
||||
val touch = touchOffset ?: current
|
||||
val posInPopupY = current.y - touch.y
|
||||
val idx = (posInPopupY / itemHeightPx).toInt()
|
||||
if (idx != previousIdx) {
|
||||
scope.launch {
|
||||
haptics.performHapticFeedback(
|
||||
HapticFeedbackType.SegmentTick
|
||||
)
|
||||
}
|
||||
}
|
||||
parentHoveredIndex = idx
|
||||
previousIdx = idx
|
||||
}, onDragEnd = {
|
||||
parentDragActive = false
|
||||
parentHoveredIndex?.let { idx ->
|
||||
if (idx in options.indices) {
|
||||
onOptionSelected(options[idx])
|
||||
expanded = false
|
||||
lastDismissTime = System.currentTimeMillis()
|
||||
}
|
||||
}
|
||||
if (parentHoveredIndex != null && parentHoveredIndex in options.indices) {
|
||||
scope.launch {
|
||||
haptics.performHapticFeedback(
|
||||
HapticFeedbackType.GestureEnd
|
||||
)
|
||||
}
|
||||
}
|
||||
parentHoveredIndex = null
|
||||
}, onDragCancel = {
|
||||
parentDragActive = false
|
||||
parentHoveredIndex = null
|
||||
})
|
||||
},
|
||||
horizontalArrangement = Arrangement.SpaceBetween,
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier.weight(1f)
|
||||
){
|
||||
) {
|
||||
Text(
|
||||
text = label,
|
||||
fontSize = 16.sp,
|
||||
color = textColor,
|
||||
modifier = Modifier.padding(bottom = 4.dp)
|
||||
)
|
||||
if (!independent && description != null){
|
||||
if (!independent && description != null) {
|
||||
Text(
|
||||
text = description,
|
||||
style = TextStyle(
|
||||
text = description, style = TextStyle(
|
||||
fontSize = 12.sp,
|
||||
fontWeight = FontWeight.Light,
|
||||
color = textColor.copy(alpha = 0.6f),
|
||||
fontFamily = FontFamily(Font(R.font.sf_pro))
|
||||
),
|
||||
modifier = Modifier.padding(16.dp, top = 0.dp, bottom = 2.dp)
|
||||
), modifier = Modifier.padding(16.dp, top = 0.dp, bottom = 2.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
Box(
|
||||
modifier = Modifier.onGloballyPositioned { coordinates ->
|
||||
boxPosition = coordinates.positionInParent()
|
||||
}
|
||||
) {
|
||||
}) {
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Text(
|
||||
text = selectedOption,
|
||||
style = TextStyle(
|
||||
text = selectedOption, style = TextStyle(
|
||||
fontSize = 16.sp,
|
||||
color = textColor.copy(alpha = 0.8f),
|
||||
fontFamily = FontFamily(Font(R.font.sf_pro))
|
||||
)
|
||||
)
|
||||
Text(
|
||||
text = "",
|
||||
style = TextStyle(
|
||||
text = "", style = TextStyle(
|
||||
fontSize = 16.sp,
|
||||
color = textColor.copy(alpha = 0.6f),
|
||||
fontFamily = FontFamily(Font(R.font.sf_pro))
|
||||
),
|
||||
modifier = Modifier
|
||||
.padding(start = 6.dp)
|
||||
), modifier = Modifier.padding(start = 6.dp)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -774,19 +819,22 @@ private fun DropdownMenuComponent(
|
||||
}
|
||||
}
|
||||
}
|
||||
if (independent && description != null){
|
||||
if (independent && description != null) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 16.dp)
|
||||
.background(if (isSystemInDarkTheme()) Color(0xFF000000) else Color(0xFFF2F2F7))
|
||||
){
|
||||
.background(
|
||||
if (isSystemInDarkTheme()) Color(0xFF000000) else Color(0xFFF2F2F7)
|
||||
)
|
||||
) {
|
||||
Text(
|
||||
text = description,
|
||||
style = TextStyle(
|
||||
text = description, style = TextStyle(
|
||||
fontSize = 12.sp,
|
||||
fontWeight = FontWeight.Light,
|
||||
color = (if (isSystemInDarkTheme()) Color.White else Color.Black).copy(alpha = 0.6f),
|
||||
color = (if (isSystemInDarkTheme()) Color.White else Color.Black).copy(
|
||||
alpha = 0.6f
|
||||
),
|
||||
fontFamily = FontFamily(Font(R.font.sf_pro))
|
||||
)
|
||||
)
|
||||
|
||||
@@ -51,10 +51,10 @@ import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
import me.kavishdevar.librepods.R
|
||||
import me.kavishdevar.librepods.bluetooth.AACPManager
|
||||
import me.kavishdevar.librepods.presentation.components.StyledButton
|
||||
import me.kavishdevar.librepods.presentation.components.StyledScaffold
|
||||
import me.kavishdevar.librepods.presentation.components.StyledSlider
|
||||
import me.kavishdevar.librepods.bluetooth.AACPManager
|
||||
import me.kavishdevar.librepods.presentation.viewmodel.AirPodsViewModel
|
||||
|
||||
@Composable
|
||||
@@ -81,7 +81,7 @@ fun AdaptiveStrengthScreen(viewModel: AirPodsViewModel, navController: NavContro
|
||||
backdrop = rememberLayerBackdrop(),
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
maxScale = 0.05f,
|
||||
tint = if (isSystemInDarkTheme()) Color(0xFF916100) else Color(0xFFE59900)
|
||||
surfaceColor = if (isSystemInDarkTheme()) Color(0xFF916100) else Color(0xFFE59900)
|
||||
) {
|
||||
Text(
|
||||
stringResource(R.string.unlock_advanced_features),
|
||||
@@ -95,11 +95,7 @@ fun AdaptiveStrengthScreen(viewModel: AirPodsViewModel, navController: NavContro
|
||||
}
|
||||
}
|
||||
val sliderValue = remember {
|
||||
mutableFloatStateOf(
|
||||
state.controlStates[AACPManager.Companion.ControlCommandIdentifiers.AUTO_ANC_STRENGTH]?.getOrNull(
|
||||
0
|
||||
)?.toFloat() ?: 50f
|
||||
)
|
||||
mutableFloatStateOf(100f - (state.controlStates[AACPManager.Companion.ControlCommandIdentifiers.AUTO_ANC_STRENGTH]?.getOrNull(0)?.toFloat() ?: 50f))
|
||||
}
|
||||
var job by remember { mutableStateOf<Job?>(null) }
|
||||
val scope = rememberCoroutineScope()
|
||||
|
||||
@@ -32,6 +32,7 @@ import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.heightIn
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
@@ -130,7 +131,6 @@ fun AirPodsSettingsScreen(viewModel: AirPodsViewModel, navController: NavControl
|
||||
viewModel.refreshInitialData()
|
||||
}
|
||||
|
||||
isSystemInDarkTheme()
|
||||
val hazeStateS = remember { mutableStateOf(HazeState()) }
|
||||
|
||||
StyledScaffold(
|
||||
@@ -239,13 +239,11 @@ fun AirPodsSettingsScreen(viewModel: AirPodsViewModel, navController: NavControl
|
||||
|
||||
item(key = "spacer_call") { Spacer(modifier = Modifier.height(16.dp)) }
|
||||
item(key = "call_control") {
|
||||
val flipped =
|
||||
state.controlStates[AACPManager.Companion.ControlCommandIdentifiers.CALL_MANAGEMENT_CONFIG]?.take(
|
||||
2
|
||||
)?.equals(byteArrayOf(0x00.toByte(), 0x02.toByte()))
|
||||
val bytes = state.controlStates[AACPManager.Companion.ControlCommandIdentifiers.CALL_MANAGEMENT_CONFIG]?.take(2)?.toByteArray() ?: byteArrayOf(0x00, 0x00)
|
||||
val flipped = try { bytes[1] == 0x02.toByte() } catch (e: Exception) { false }
|
||||
CallControlSettings(
|
||||
hazeState = hazeState,
|
||||
flipped = flipped == true,
|
||||
flipped = flipped,
|
||||
onCallControlValueChanged = {
|
||||
viewModel.setControlCommandValue(
|
||||
AACPManager.Companion.ControlCommandIdentifiers.CALL_MANAGEMENT_CONFIG,
|
||||
@@ -277,7 +275,7 @@ fun AirPodsSettingsScreen(viewModel: AirPodsViewModel, navController: NavControl
|
||||
backdrop = rememberLayerBackdrop(),
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
maxScale = 0.05f,
|
||||
tint = if (isSystemInDarkTheme()) Color(0xFF916100) else Color(
|
||||
surfaceColor = if (isSystemInDarkTheme()) Color(0xFF916100) else Color(
|
||||
0xFFE59900
|
||||
)
|
||||
) {
|
||||
@@ -399,6 +397,16 @@ fun AirPodsSettingsScreen(viewModel: AirPodsViewModel, navController: NavControl
|
||||
}
|
||||
}
|
||||
|
||||
item(key = "spacer_dynamic_end_of_charge") { Spacer(modifier = Modifier.height(16.dp)) }
|
||||
item(key = "dynamic_end_of_charge") {
|
||||
StyledToggle(
|
||||
label = stringResource(R.string.optimized_charging),
|
||||
description = stringResource(R.string.optimized_charging_description),
|
||||
checked = state.dynamicEndOfCharge,
|
||||
onCheckedChange = viewModel::setDynamicEndOfCharge
|
||||
)
|
||||
}
|
||||
|
||||
item(key = "spacer_accessibility") { Spacer(modifier = Modifier.height(16.dp)) }
|
||||
item(key = "accessibility") {
|
||||
NavigationButton(
|
||||
@@ -432,6 +440,30 @@ fun AirPodsSettingsScreen(viewModel: AirPodsViewModel, navController: NavControl
|
||||
)
|
||||
}
|
||||
|
||||
item(key = "spacer_disconnect") { Spacer(modifier = Modifier.height(28.dp)) }
|
||||
item(key = "disconnect_button") {
|
||||
StyledButton(
|
||||
onClick = viewModel::disconnect,
|
||||
backdrop = rememberLayerBackdrop(),
|
||||
isInteractive = false,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.heightIn(min = 56.dp)
|
||||
) {
|
||||
Text(
|
||||
text = stringResource(R.string.disconnect),
|
||||
style = TextStyle(
|
||||
fontSize = 16.sp,
|
||||
fontWeight = FontWeight.Normal,
|
||||
color = if (isSystemInDarkTheme()) Color(0xFF0091FF) else Color(0xFF0088FF),
|
||||
fontFamily = FontFamily(Font(R.font.sf_pro))
|
||||
),
|
||||
textAlign = TextAlign.Start,
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// item(key = "spacer_debug") { Spacer(modifier = Modifier.height(16.dp)) }
|
||||
// item(key = "debug") { NavigationButton("debug", "Debug", navController) }
|
||||
item(key = "spacer_bottom") { Spacer(Modifier.height(bottomPadding)) }
|
||||
@@ -519,19 +551,22 @@ fun AirPodsSettingsScreen(viewModel: AirPodsViewModel, navController: NavControl
|
||||
}
|
||||
Spacer(Modifier.height(16.dp))
|
||||
}
|
||||
StyledButton(
|
||||
onClick = {
|
||||
viewModel.reconnectFromSavedMac()
|
||||
}, backdrop = backdrop, modifier = Modifier.fillMaxWidth(0.9f)
|
||||
) {
|
||||
Text(
|
||||
text = stringResource(R.string.reconnect_to_last_device), style = TextStyle(
|
||||
fontSize = 16.sp,
|
||||
fontWeight = FontWeight.Medium,
|
||||
fontFamily = FontFamily(Font(R.font.sf_pro)),
|
||||
color = if (isSystemInDarkTheme()) Color.White else Color.Black
|
||||
if (state.connectionSuccessful) {
|
||||
StyledButton(
|
||||
onClick = {
|
||||
viewModel.reconnectFromSavedMac()
|
||||
}, backdrop = backdrop, modifier = Modifier.fillMaxWidth(0.9f)
|
||||
) {
|
||||
Text(
|
||||
text = stringResource(R.string.reconnect_to_last_device),
|
||||
style = TextStyle(
|
||||
fontSize = 16.sp,
|
||||
fontWeight = FontWeight.Medium,
|
||||
fontFamily = FontFamily(Font(R.font.sf_pro)),
|
||||
color = if (isSystemInDarkTheme()) Color.White else Color.Black
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,11 +19,13 @@
|
||||
package me.kavishdevar.librepods.presentation.screens
|
||||
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.os.Build
|
||||
import android.widget.Toast
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.isSystemInDarkTheme
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
@@ -34,8 +36,11 @@ import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.foundation.text.KeyboardOptions
|
||||
import androidx.compose.foundation.text.input.TextFieldState
|
||||
import androidx.compose.foundation.text.input.clearText
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material3.AlertDialog
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.HorizontalDivider
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.OutlinedTextField
|
||||
@@ -48,12 +53,12 @@ import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.focus.FocusRequester
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.layout.onGloballyPositioned
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.platform.LocalDensity
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.TextStyle
|
||||
import androidx.compose.ui.text.font.Font
|
||||
@@ -61,7 +66,9 @@ import androidx.compose.ui.text.font.FontFamily
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.input.KeyboardCapitalization
|
||||
import androidx.compose.ui.text.input.KeyboardType
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.lerp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.core.net.toUri
|
||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||
@@ -71,14 +78,20 @@ import com.kyant.backdrop.backdrops.rememberLayerBackdrop
|
||||
import dev.chrisbanes.haze.hazeSource
|
||||
import me.kavishdevar.librepods.BuildConfig
|
||||
import me.kavishdevar.librepods.R
|
||||
import me.kavishdevar.librepods.presentation.components.AppInfoCard
|
||||
import me.kavishdevar.librepods.presentation.components.DeviceInfoCard
|
||||
import me.kavishdevar.librepods.presentation.components.NavigationButton
|
||||
import me.kavishdevar.librepods.presentation.components.StyledBottomSheet
|
||||
import me.kavishdevar.librepods.presentation.components.StyledButton
|
||||
import me.kavishdevar.librepods.presentation.components.StyledIconButton
|
||||
import me.kavishdevar.librepods.presentation.components.StyledInputField
|
||||
import me.kavishdevar.librepods.presentation.components.StyledScaffold
|
||||
import me.kavishdevar.librepods.presentation.components.StyledSlider
|
||||
import me.kavishdevar.librepods.presentation.components.StyledToggle
|
||||
import me.kavishdevar.librepods.presentation.viewmodel.AppSettingsViewModel
|
||||
import java.util.Locale.getDefault
|
||||
import me.kavishdevar.librepods.utils.XposedState
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun AppSettingsScreen(
|
||||
navController: NavController, viewModel: AppSettingsViewModel = viewModel()
|
||||
@@ -89,6 +102,12 @@ fun AppSettingsScreen(
|
||||
|
||||
val backdrop = rememberLayerBackdrop()
|
||||
|
||||
val contactBottomSheet = remember { mutableStateOf(false) }
|
||||
val subjectState = remember { TextFieldState() }
|
||||
val descriptionState = remember { TextFieldState() }
|
||||
val subjectFocusRequester = remember { FocusRequester() }
|
||||
val descriptionFocusRequester = remember { FocusRequester() }
|
||||
|
||||
StyledScaffold(
|
||||
title = stringResource(R.string.settings)
|
||||
) { topPadding, hazeState, bottomPadding ->
|
||||
@@ -106,7 +125,7 @@ fun AppSettingsScreen(
|
||||
val backgroundColor = if (isDarkTheme) Color(0xFF1C1C1E) else Color(0xFFFFFFFF)
|
||||
val textColor = if (isDarkTheme) Color.White else Color.Black
|
||||
|
||||
if (!state.isPremium) {
|
||||
if (!state.isPremium && state.connectionSuccessful) {
|
||||
StyledButton(
|
||||
onClick = {
|
||||
navController.navigate("purchase_screen")
|
||||
@@ -114,7 +133,7 @@ fun AppSettingsScreen(
|
||||
backdrop = rememberLayerBackdrop(),
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
maxScale = 0.05f,
|
||||
tint = if (isSystemInDarkTheme()) Color(0xFF916100) else Color(0xFFE59900)
|
||||
surfaceColor = if (isSystemInDarkTheme()) Color(0xFF916100) else Color(0xFFE59900)
|
||||
) {
|
||||
Text(
|
||||
stringResource(R.string.unlock_advanced_features),
|
||||
@@ -128,249 +147,317 @@ fun AppSettingsScreen(
|
||||
}
|
||||
}
|
||||
|
||||
StyledToggle(
|
||||
title = stringResource(R.string.widget),
|
||||
label = stringResource(R.string.show_phone_battery_in_widget),
|
||||
description = stringResource(R.string.show_phone_battery_in_widget_description),
|
||||
checked = state.showPhoneBatteryInWidget,
|
||||
onCheckedChange = viewModel::setShowPhoneBatteryInWidget,
|
||||
enabled = state.isPremium
|
||||
)
|
||||
|
||||
Text(
|
||||
text = stringResource(R.string.conversational_awareness), style = TextStyle(
|
||||
fontSize = 14.sp,
|
||||
fontWeight = FontWeight.Bold,
|
||||
color = textColor.copy(alpha = 0.6f),
|
||||
fontFamily = FontFamily(Font(R.font.sf_pro))
|
||||
), modifier = Modifier.padding(16.dp, bottom = 2.dp, top = 24.dp)
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(2.dp))
|
||||
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.background(
|
||||
backgroundColor, RoundedCornerShape(28.dp)
|
||||
)
|
||||
.padding(vertical = 4.dp)
|
||||
) {
|
||||
if (state.connectionSuccessful) {
|
||||
StyledToggle(
|
||||
label = stringResource(R.string.conversational_awareness_pause_music),
|
||||
description = stringResource(R.string.conversational_awareness_pause_music_description),
|
||||
checked = state.conversationalAwarenessPauseMusicEnabled,
|
||||
onCheckedChange = viewModel::setConversationalAwarenessPauseMusicEnabled,
|
||||
independent = false,
|
||||
title = stringResource(R.string.widget),
|
||||
label = stringResource(R.string.show_phone_battery_in_widget),
|
||||
description = stringResource(R.string.show_phone_battery_in_widget_description),
|
||||
checked = state.showPhoneBatteryInWidget,
|
||||
onCheckedChange = viewModel::setShowPhoneBatteryInWidget,
|
||||
enabled = state.isPremium
|
||||
)
|
||||
|
||||
HorizontalDivider(
|
||||
thickness = 1.dp,
|
||||
color = Color(0x40888888),
|
||||
modifier = Modifier.padding(horizontal = 12.dp)
|
||||
Text(
|
||||
text = stringResource(R.string.popup_animations), style = TextStyle(
|
||||
fontSize = 14.sp,
|
||||
fontWeight = FontWeight.Bold,
|
||||
color = textColor.copy(alpha = 0.6f),
|
||||
fontFamily = FontFamily(Font(R.font.sf_pro))
|
||||
), modifier = Modifier.padding(16.dp, bottom = 2.dp, top = 24.dp)
|
||||
)
|
||||
|
||||
StyledToggle(
|
||||
label = stringResource(R.string.relative_conversational_awareness_volume),
|
||||
description = stringResource(R.string.relative_conversational_awareness_volume_description),
|
||||
checked = state.relativeConversationalAwarenessVolumeEnabled,
|
||||
onCheckedChange = viewModel::setRelativeConversationalAwarenessVolumeEnabled,
|
||||
independent = false,
|
||||
enabled = state.isPremium,
|
||||
Spacer(modifier = Modifier.height(2.dp))
|
||||
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.background(
|
||||
backgroundColor, RoundedCornerShape(28.dp)
|
||||
)
|
||||
.padding(vertical = 4.dp)
|
||||
) {
|
||||
StyledToggle(
|
||||
label = stringResource(R.string.show_bottom_sheet_popup),
|
||||
description = stringResource(R.string.show_bottom_sheet_popup_description),
|
||||
checked = state.showBottomSheetPopup,
|
||||
onCheckedChange = viewModel::setShowBottomSheetPopup,
|
||||
independent = false
|
||||
)
|
||||
|
||||
HorizontalDivider(
|
||||
thickness = 1.dp,
|
||||
color = Color(0x40888888),
|
||||
modifier = Modifier.padding(horizontal = 12.dp)
|
||||
)
|
||||
|
||||
StyledToggle(
|
||||
label = stringResource(R.string.show_island_popup),
|
||||
description = stringResource(R.string.show_island_popup_description),
|
||||
checked = state.showIslandPopup,
|
||||
onCheckedChange = viewModel::setShowIslandPopup,
|
||||
independent = false
|
||||
)
|
||||
}
|
||||
|
||||
Text(
|
||||
text = stringResource(R.string.conversational_awareness), style = TextStyle(
|
||||
fontSize = 14.sp,
|
||||
fontWeight = FontWeight.Bold,
|
||||
color = textColor.copy(alpha = 0.6f),
|
||||
fontFamily = FontFamily(Font(R.font.sf_pro))
|
||||
), modifier = Modifier.padding(16.dp, bottom = 2.dp, top = 24.dp)
|
||||
)
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
Spacer(modifier = Modifier.height(2.dp))
|
||||
|
||||
val conversationalAwarenessVolume = state.conversationalAwarenessVolume
|
||||
LaunchedEffect(conversationalAwarenessVolume) {
|
||||
viewModel.setConversationalAwarenessVolume(conversationalAwarenessVolume)
|
||||
}
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.background(
|
||||
backgroundColor, RoundedCornerShape(28.dp)
|
||||
)
|
||||
.padding(vertical = 4.dp)
|
||||
) {
|
||||
StyledToggle(
|
||||
label = stringResource(R.string.conversational_awareness_pause_music),
|
||||
description = stringResource(R.string.conversational_awareness_pause_music_description),
|
||||
checked = state.conversationalAwarenessPauseMusicEnabled,
|
||||
onCheckedChange = viewModel::setConversationalAwarenessPauseMusicEnabled,
|
||||
independent = false,
|
||||
enabled = state.isPremium
|
||||
)
|
||||
|
||||
StyledSlider(
|
||||
label = stringResource(R.string.conversational_awareness_volume),
|
||||
value = conversationalAwarenessVolume,
|
||||
valueRange = 10f..85f,
|
||||
snapPoints = listOf(44f),
|
||||
startLabel = "10%",
|
||||
endLabel = "85%",
|
||||
onValueChange = { newValue -> viewModel.setConversationalAwarenessVolume(newValue) },
|
||||
independent = true,
|
||||
enabled = state.isPremium
|
||||
)
|
||||
HorizontalDivider(
|
||||
thickness = 1.dp,
|
||||
color = Color(0x40888888),
|
||||
modifier = Modifier.padding(horizontal = 12.dp)
|
||||
)
|
||||
|
||||
StyledToggle(
|
||||
label = stringResource(R.string.relative_conversational_awareness_volume),
|
||||
description = stringResource(R.string.relative_conversational_awareness_volume_description),
|
||||
checked = state.relativeConversationalAwarenessVolumeEnabled,
|
||||
onCheckedChange = viewModel::setRelativeConversationalAwarenessVolumeEnabled,
|
||||
independent = false,
|
||||
enabled = state.isPremium,
|
||||
)
|
||||
}
|
||||
|
||||
if (!BuildConfig.PLAY_BUILD) {
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
|
||||
NavigationButton(
|
||||
to = "",
|
||||
title = stringResource(R.string.camera_control),
|
||||
name = stringResource(R.string.set_custom_camera_package),
|
||||
navController = navController,
|
||||
onClick = {
|
||||
if (state.isPremium) viewModel.setShowCameraDialog(true)
|
||||
val conversationalAwarenessVolume = state.conversationalAwarenessVolume
|
||||
LaunchedEffect(conversationalAwarenessVolume) {
|
||||
viewModel.setConversationalAwarenessVolume(conversationalAwarenessVolume)
|
||||
}
|
||||
|
||||
StyledSlider(
|
||||
label = stringResource(R.string.conversational_awareness_volume),
|
||||
value = conversationalAwarenessVolume,
|
||||
valueRange = 10f..85f,
|
||||
snapPoints = listOf(44f),
|
||||
startLabel = "10%",
|
||||
endLabel = "85%",
|
||||
onValueChange = { newValue ->
|
||||
viewModel.setConversationalAwarenessVolume(
|
||||
newValue
|
||||
)
|
||||
},
|
||||
independent = true,
|
||||
description = stringResource(R.string.camera_control_app_description)
|
||||
)
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
if (BuildConfig.FLAVOR == "xposed") {
|
||||
StyledToggle(
|
||||
title = stringResource(R.string.ear_detection),
|
||||
label = stringResource(R.string.disconnect_when_not_wearing),
|
||||
description = stringResource(R.string.disconnect_when_not_wearing_description),
|
||||
checked = state.disconnectWhenNotWearing,
|
||||
onCheckedChange = viewModel::setDisconnectWhenNotWearing,
|
||||
enabled = state.isPremium
|
||||
)
|
||||
}
|
||||
|
||||
Text(
|
||||
text = stringResource(R.string.takeover_airpods_state), style = TextStyle(
|
||||
fontSize = 14.sp,
|
||||
fontWeight = FontWeight.Bold,
|
||||
color = textColor.copy(alpha = 0.6f),
|
||||
fontFamily = FontFamily(Font(R.font.sf_pro))
|
||||
), modifier = Modifier.padding(16.dp, bottom = 2.dp, top = 24.dp)
|
||||
)
|
||||
// if (!BuildConfig.PLAY_BUILD) {
|
||||
// Spacer(modifier = Modifier.height(16.dp))
|
||||
//
|
||||
// NavigationButton(
|
||||
// to = "",
|
||||
// title = stringResource(R.string.camera_control),
|
||||
// name = stringResource(R.string.set_custom_camera_package),
|
||||
// navController = navController,
|
||||
// onClick = {
|
||||
// if (state.isPremium) viewModel.setShowCameraDialog(true)
|
||||
// },
|
||||
// independent = true,
|
||||
// description = stringResource(R.string.camera_control_app_description)
|
||||
// )
|
||||
// }
|
||||
|
||||
Spacer(modifier = Modifier.height(4.dp))
|
||||
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.background(
|
||||
backgroundColor, RoundedCornerShape(28.dp)
|
||||
)
|
||||
.padding(vertical = 4.dp)
|
||||
) {
|
||||
StyledToggle(
|
||||
label = stringResource(R.string.takeover_disconnected),
|
||||
description = stringResource(R.string.takeover_disconnected_desc),
|
||||
checked = state.takeoverWhenDisconnected,
|
||||
onCheckedChange = viewModel::setTakeoverWhenDisconnected,
|
||||
independent = false,
|
||||
enabled = state.isPremium
|
||||
)
|
||||
HorizontalDivider(
|
||||
thickness = 1.dp,
|
||||
color = Color(0x40888888),
|
||||
modifier = Modifier.padding(horizontal = 12.dp)
|
||||
)
|
||||
|
||||
StyledToggle(
|
||||
label = stringResource(R.string.takeover_idle),
|
||||
description = stringResource(R.string.takeover_idle_desc),
|
||||
checked = state.takeoverWhenIdle,
|
||||
onCheckedChange = viewModel::setTakeoverWhenIdle,
|
||||
independent = false,
|
||||
enabled = state.isPremium
|
||||
)
|
||||
HorizontalDivider(
|
||||
thickness = 1.dp,
|
||||
color = Color(0x40888888),
|
||||
modifier = Modifier.padding(horizontal = 12.dp)
|
||||
)
|
||||
|
||||
StyledToggle(
|
||||
label = stringResource(R.string.takeover_music),
|
||||
description = stringResource(R.string.takeover_music_desc),
|
||||
checked = state.takeoverWhenMusic,
|
||||
onCheckedChange = viewModel::setTakeoverWhenMusic,
|
||||
independent = false,
|
||||
enabled = state.isPremium
|
||||
)
|
||||
HorizontalDivider(
|
||||
thickness = 1.dp,
|
||||
color = Color(0x40888888),
|
||||
modifier = Modifier.padding(horizontal = 12.dp)
|
||||
)
|
||||
|
||||
StyledToggle(
|
||||
label = stringResource(R.string.takeover_call),
|
||||
description = stringResource(R.string.takeover_call_desc),
|
||||
checked = state.takeoverWhenCall,
|
||||
onCheckedChange = viewModel::setTakeoverWhenCall,
|
||||
independent = false,
|
||||
enabled = state.isPremium
|
||||
)
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
|
||||
Text(
|
||||
text = stringResource(R.string.takeover_phone_state), style = TextStyle(
|
||||
fontSize = 14.sp,
|
||||
fontWeight = FontWeight.Bold,
|
||||
color = textColor.copy(alpha = 0.6f),
|
||||
fontFamily = FontFamily(Font(R.font.sf_pro))
|
||||
), modifier = Modifier.padding(horizontal = 16.dp)
|
||||
)
|
||||
Spacer(modifier = Modifier.height(4.dp))
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.background(
|
||||
backgroundColor, RoundedCornerShape(28.dp)
|
||||
)
|
||||
.padding(vertical = 4.dp)
|
||||
) {
|
||||
StyledToggle(
|
||||
label = stringResource(R.string.takeover_ringing_call),
|
||||
description = stringResource(R.string.takeover_ringing_call_desc),
|
||||
checked = state.takeoverWhenRingingCall,
|
||||
onCheckedChange = viewModel::setTakeoverWhenRingingCall,
|
||||
independent = false,
|
||||
enabled = state.isPremium
|
||||
)
|
||||
HorizontalDivider(
|
||||
thickness = 1.dp,
|
||||
color = Color(0x40888888),
|
||||
modifier = Modifier.padding(horizontal = 12.dp)
|
||||
)
|
||||
|
||||
StyledToggle(
|
||||
label = stringResource(R.string.takeover_media_start),
|
||||
description = stringResource(R.string.takeover_media_start_desc),
|
||||
checked = state.takeoverWhenMediaStart,
|
||||
onCheckedChange = viewModel::setTakeoverWhenMediaStart,
|
||||
independent = false,
|
||||
enabled = state.isPremium
|
||||
)
|
||||
}
|
||||
|
||||
Text(
|
||||
text = stringResource(R.string.advanced_options), style = TextStyle(
|
||||
fontSize = 14.sp,
|
||||
fontWeight = FontWeight.Bold,
|
||||
color = textColor.copy(alpha = 0.6f),
|
||||
fontFamily = FontFamily(Font(R.font.sf_pro))
|
||||
), modifier = Modifier.padding(16.dp, bottom = 2.dp, top = 24.dp)
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(2.dp))
|
||||
|
||||
StyledToggle(
|
||||
label = stringResource(R.string.use_alternate_head_tracking_packets),
|
||||
description = stringResource(R.string.use_alternate_head_tracking_packets_description),
|
||||
checked = state.useAlternateHeadTrackingPackets,
|
||||
onCheckedChange = viewModel::setUseAlternateHeadTrackingPackets,
|
||||
independent = true,
|
||||
enabled = state.isPremium
|
||||
)
|
||||
|
||||
|
||||
if (BuildConfig.FLAVOR == "xposed") {
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
val restartBluetoothText = stringResource(R.string.found_offset_restart_bluetooth)
|
||||
if (context.checkSelfPermission("android.permission.BLUETOOTH_PRIVILEGED") == PackageManager.PERMISSION_GRANTED) {
|
||||
StyledToggle(
|
||||
title = stringResource(R.string.ear_detection),
|
||||
label = stringResource(R.string.disconnect_when_not_wearing),
|
||||
description = stringResource(R.string.disconnect_when_not_wearing_description),
|
||||
checked = state.disconnectWhenNotWearing,
|
||||
onCheckedChange = viewModel::setDisconnectWhenNotWearing,
|
||||
enabled = state.isPremium
|
||||
)
|
||||
}
|
||||
|
||||
Text(
|
||||
text = stringResource(R.string.takeover_airpods_state), style = TextStyle(
|
||||
fontSize = 14.sp,
|
||||
fontWeight = FontWeight.Bold,
|
||||
color = textColor.copy(alpha = 0.6f),
|
||||
fontFamily = FontFamily(Font(R.font.sf_pro))
|
||||
), modifier = Modifier.padding(16.dp, bottom = 2.dp, top = 24.dp)
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(4.dp))
|
||||
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.background(
|
||||
backgroundColor, RoundedCornerShape(28.dp)
|
||||
)
|
||||
.padding(vertical = 4.dp)
|
||||
) {
|
||||
StyledToggle(
|
||||
label = stringResource(R.string.takeover_disconnected),
|
||||
description = stringResource(R.string.takeover_disconnected_desc),
|
||||
checked = state.takeoverWhenDisconnected,
|
||||
onCheckedChange = viewModel::setTakeoverWhenDisconnected,
|
||||
independent = false,
|
||||
enabled = state.isPremium
|
||||
)
|
||||
HorizontalDivider(
|
||||
thickness = 1.dp,
|
||||
color = Color(0x40888888),
|
||||
modifier = Modifier.padding(horizontal = 12.dp)
|
||||
)
|
||||
|
||||
StyledToggle(
|
||||
label = stringResource(R.string.takeover_idle),
|
||||
description = stringResource(R.string.takeover_idle_desc),
|
||||
checked = state.takeoverWhenIdle,
|
||||
onCheckedChange = viewModel::setTakeoverWhenIdle,
|
||||
independent = false,
|
||||
enabled = state.isPremium
|
||||
)
|
||||
HorizontalDivider(
|
||||
thickness = 1.dp,
|
||||
color = Color(0x40888888),
|
||||
modifier = Modifier.padding(horizontal = 12.dp)
|
||||
)
|
||||
|
||||
StyledToggle(
|
||||
label = stringResource(R.string.takeover_music),
|
||||
description = stringResource(R.string.takeover_music_desc),
|
||||
checked = state.takeoverWhenMusic,
|
||||
onCheckedChange = viewModel::setTakeoverWhenMusic,
|
||||
independent = false,
|
||||
enabled = state.isPremium
|
||||
)
|
||||
HorizontalDivider(
|
||||
thickness = 1.dp,
|
||||
color = Color(0x40888888),
|
||||
modifier = Modifier.padding(horizontal = 12.dp)
|
||||
)
|
||||
|
||||
StyledToggle(
|
||||
label = stringResource(R.string.takeover_call),
|
||||
description = stringResource(R.string.takeover_call_desc),
|
||||
checked = state.takeoverWhenCall,
|
||||
onCheckedChange = viewModel::setTakeoverWhenCall,
|
||||
independent = false,
|
||||
enabled = state.isPremium
|
||||
)
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
|
||||
Text(
|
||||
text = stringResource(R.string.takeover_phone_state), style = TextStyle(
|
||||
fontSize = 14.sp,
|
||||
fontWeight = FontWeight.Bold,
|
||||
color = textColor.copy(alpha = 0.6f),
|
||||
fontFamily = FontFamily(Font(R.font.sf_pro))
|
||||
), modifier = Modifier.padding(horizontal = 16.dp)
|
||||
)
|
||||
Spacer(modifier = Modifier.height(4.dp))
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.background(
|
||||
backgroundColor, RoundedCornerShape(28.dp)
|
||||
)
|
||||
.padding(vertical = 4.dp)
|
||||
) {
|
||||
StyledToggle(
|
||||
label = stringResource(R.string.takeover_ringing_call),
|
||||
description = stringResource(R.string.takeover_ringing_call_desc),
|
||||
checked = state.takeoverWhenRingingCall,
|
||||
onCheckedChange = viewModel::setTakeoverWhenRingingCall,
|
||||
independent = false,
|
||||
enabled = state.isPremium
|
||||
)
|
||||
HorizontalDivider(
|
||||
thickness = 1.dp,
|
||||
color = Color(0x40888888),
|
||||
modifier = Modifier.padding(horizontal = 12.dp)
|
||||
)
|
||||
|
||||
StyledToggle(
|
||||
label = stringResource(R.string.takeover_media_start),
|
||||
description = stringResource(R.string.takeover_media_start_desc),
|
||||
checked = state.takeoverWhenMediaStart,
|
||||
onCheckedChange = viewModel::setTakeoverWhenMediaStart,
|
||||
independent = false,
|
||||
enabled = state.isPremium
|
||||
)
|
||||
}
|
||||
|
||||
Text(
|
||||
text = stringResource(R.string.advanced_options), style = TextStyle(
|
||||
fontSize = 14.sp,
|
||||
fontWeight = FontWeight.Bold,
|
||||
color = textColor.copy(alpha = 0.6f),
|
||||
fontFamily = FontFamily(Font(R.font.sf_pro))
|
||||
), modifier = Modifier.padding(16.dp, bottom = 2.dp, top = 24.dp)
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(2.dp))
|
||||
|
||||
StyledToggle(
|
||||
label = stringResource(R.string.act_as_an_apple_device),
|
||||
description = stringResource(R.string.act_as_an_apple_device_description) + "\n" + stringResource(
|
||||
R.string.requires_xposed
|
||||
).replaceFirstChar { if (it.isLowerCase()) it.titlecase(getDefault()) else it.toString() },
|
||||
label = stringResource(R.string.use_alternate_head_tracking_packets),
|
||||
description = stringResource(R.string.use_alternate_head_tracking_packets_description),
|
||||
checked = state.useAlternateHeadTrackingPackets,
|
||||
onCheckedChange = viewModel::setUseAlternateHeadTrackingPackets,
|
||||
independent = true,
|
||||
enabled = state.isPremium
|
||||
)
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
} else {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.background(if (isDarkTheme) Color.Black else Color(0xFFF2F2F7))
|
||||
.padding(horizontal = 16.dp)
|
||||
.padding(top = 16.dp, bottom = 2.dp)
|
||||
) {
|
||||
Text(
|
||||
text = stringResource(R.string.customizations_unavailable),
|
||||
style = TextStyle(
|
||||
fontSize = 16.sp,
|
||||
fontWeight = FontWeight.Normal,
|
||||
fontFamily = FontFamily(Font(R.font.sf_pro)),
|
||||
color = textColor.copy(alpha = 0.6f),
|
||||
),
|
||||
modifier = Modifier
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
if (XposedState.isAvailable && XposedState.bluetoothScopeEnabled) {
|
||||
val restartBluetoothText =
|
||||
stringResource(R.string.found_offset_restart_bluetooth)
|
||||
StyledToggle(
|
||||
label = stringResource(R.string.act_as_an_apple_device) + " (${
|
||||
stringResource(
|
||||
R.string.requires_xposed
|
||||
)
|
||||
})",
|
||||
description = stringResource(R.string.act_as_an_apple_device_description),
|
||||
checked = state.vendorIdHook,
|
||||
onCheckedChange = { enabled ->
|
||||
Toast.makeText(context, restartBluetoothText, Toast.LENGTH_SHORT).show()
|
||||
@@ -381,8 +468,8 @@ fun AppSettingsScreen(
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
if (!BuildConfig.PLAY_BUILD) {
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
NavigationButton(
|
||||
to = "troubleshooting",
|
||||
name = stringResource(R.string.troubleshooting),
|
||||
@@ -394,14 +481,20 @@ fun AppSettingsScreen(
|
||||
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
|
||||
Text(
|
||||
text = stringResource(R.string.contact), style = TextStyle(
|
||||
fontSize = 14.sp,
|
||||
fontWeight = FontWeight.Bold,
|
||||
color = textColor.copy(alpha = 0.6f),
|
||||
fontFamily = FontFamily(Font(R.font.sf_pro))
|
||||
), modifier = Modifier.padding(16.dp, bottom = 2.dp, top = 24.dp)
|
||||
)
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.background(if (isDarkTheme) Color.Black else Color(0xFFF2F2F7))
|
||||
.padding(start = 16.dp, bottom = 2.dp, top = 24.dp, end = 4.dp)
|
||||
) {
|
||||
Text(
|
||||
text = stringResource(R.string.contact), style = TextStyle(
|
||||
fontSize = 14.sp,
|
||||
fontWeight = FontWeight.Bold,
|
||||
color = textColor.copy(alpha = 0.6f),
|
||||
fontFamily = FontFamily(Font(R.font.sf_pro))
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.height(4.dp))
|
||||
Column(
|
||||
@@ -416,28 +509,7 @@ fun AppSettingsScreen(
|
||||
to = "",
|
||||
name = stringResource(R.string.email),
|
||||
navController = navController,
|
||||
onClick = {
|
||||
val intent = Intent(Intent.ACTION_SENDTO).apply {
|
||||
data = "mailto:".toUri()
|
||||
putExtra(Intent.EXTRA_EMAIL, arrayOf("contact@kavish.xyz"))
|
||||
putExtra(Intent.EXTRA_SUBJECT, "LibrePods: ")
|
||||
putExtra(
|
||||
Intent.EXTRA_TEXT,
|
||||
"\n\n\n----------" +
|
||||
"\nPhone details:" +
|
||||
"\nDEVICE: ${Build.DEVICE}" +
|
||||
"\nMANUFACTURER: ${Build.MANUFACTURER} (${Build.BRAND})" +
|
||||
"\nMODEL: ${Build.MODEL} (${Build.PRODUCT})" +
|
||||
"\nVERSION: ${Build.DISPLAY} (${Build.VERSION.SDK_INT_FULL})" +
|
||||
"\n\nApp details:" +
|
||||
"\nVERSION: ${BuildConfig.VERSION_NAME}" +
|
||||
"\nVERSION_CODE: ${BuildConfig.VERSION_CODE}" +
|
||||
"\nFLAVOR: ${BuildConfig.FLAVOR}" +
|
||||
"\nBUILD_TYPE: ${BuildConfig.BUILD_TYPE}"
|
||||
)
|
||||
}
|
||||
context.startActivity(intent)
|
||||
},
|
||||
onClick = { contactBottomSheet.value = true },
|
||||
independent = false
|
||||
)
|
||||
|
||||
@@ -480,140 +552,10 @@ fun AppSettingsScreen(
|
||||
)
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
|
||||
Text(
|
||||
text = stringResource(R.string.about), style = TextStyle(
|
||||
fontSize = 14.sp,
|
||||
fontWeight = FontWeight.Bold,
|
||||
color = textColor.copy(alpha = 0.6f),
|
||||
fontFamily = FontFamily(Font(R.font.sf_pro))
|
||||
), modifier = Modifier.padding(16.dp, bottom = 2.dp, top = 24.dp)
|
||||
)
|
||||
|
||||
val rowHeight = remember { mutableStateOf(0.dp) }
|
||||
val density = LocalDensity.current
|
||||
|
||||
Spacer(modifier = Modifier.height(4.dp))
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.clip(RoundedCornerShape(28.dp))
|
||||
.fillMaxWidth()
|
||||
.background(backgroundColor, RoundedCornerShape(28.dp))
|
||||
.padding(top = 2.dp)
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(16.dp)
|
||||
.onGloballyPositioned { coordinates ->
|
||||
rowHeight.value = with(density) { coordinates.size.height.toDp() }
|
||||
},
|
||||
horizontalArrangement = Arrangement.SpaceBetween,
|
||||
) {
|
||||
Text(
|
||||
text = stringResource(R.string.version), style = TextStyle(
|
||||
fontSize = 16.sp,
|
||||
color = textColor,
|
||||
fontFamily = FontFamily(Font(R.font.sf_pro))
|
||||
)
|
||||
)
|
||||
Text(
|
||||
text = BuildConfig.VERSION_NAME, style = TextStyle(
|
||||
fontSize = 16.sp,
|
||||
color = if (isDarkTheme) Color.White.copy(alpha = 0.6f) else Color.Black.copy(
|
||||
alpha = 0.8f
|
||||
),
|
||||
fontFamily = FontFamily(Font(R.font.sf_pro))
|
||||
)
|
||||
)
|
||||
}
|
||||
HorizontalDivider(
|
||||
thickness = 1.dp,
|
||||
color = Color(0x40888888),
|
||||
modifier = Modifier.padding(horizontal = 12.dp)
|
||||
)
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(16.dp),
|
||||
horizontalArrangement = Arrangement.SpaceBetween,
|
||||
) {
|
||||
Text(
|
||||
text = stringResource(R.string.version_code), style = TextStyle(
|
||||
fontSize = 16.sp,
|
||||
color = textColor,
|
||||
fontFamily = FontFamily(Font(R.font.sf_pro))
|
||||
)
|
||||
)
|
||||
Text(
|
||||
text = BuildConfig.VERSION_CODE.toString(), style = TextStyle(
|
||||
fontSize = 16.sp,
|
||||
color = if (isDarkTheme) Color.White.copy(alpha = 0.6f) else Color.Black.copy(
|
||||
alpha = 0.8f
|
||||
),
|
||||
fontFamily = FontFamily(Font(R.font.sf_pro))
|
||||
)
|
||||
)
|
||||
}
|
||||
HorizontalDivider(
|
||||
thickness = 1.dp,
|
||||
color = Color(0x40888888),
|
||||
modifier = Modifier.padding(horizontal = 12.dp)
|
||||
)
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(16.dp),
|
||||
horizontalArrangement = Arrangement.SpaceBetween,
|
||||
) {
|
||||
Text(
|
||||
text = stringResource(R.string.flavor), style = TextStyle(
|
||||
fontSize = 16.sp,
|
||||
color = textColor,
|
||||
fontFamily = FontFamily(Font(R.font.sf_pro))
|
||||
)
|
||||
)
|
||||
Text(
|
||||
text = BuildConfig.FLAVOR, style = TextStyle(
|
||||
fontSize = 16.sp,
|
||||
color = if (isDarkTheme) Color.White.copy(alpha = 0.6f) else Color.Black.copy(
|
||||
alpha = 0.8f
|
||||
),
|
||||
fontFamily = FontFamily(Font(R.font.sf_pro))
|
||||
)
|
||||
)
|
||||
}
|
||||
HorizontalDivider(
|
||||
thickness = 1.dp,
|
||||
color = Color(0x40888888),
|
||||
modifier = Modifier.padding(horizontal = 12.dp)
|
||||
)
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(16.dp),
|
||||
horizontalArrangement = Arrangement.SpaceBetween,
|
||||
) {
|
||||
Text(
|
||||
text = stringResource(R.string.build_type), style = TextStyle(
|
||||
fontSize = 16.sp,
|
||||
color = textColor,
|
||||
fontFamily = FontFamily(Font(R.font.sf_pro))
|
||||
)
|
||||
)
|
||||
Text(
|
||||
text = BuildConfig.BUILD_TYPE,
|
||||
style = TextStyle(
|
||||
fontSize = 16.sp,
|
||||
color = if (isDarkTheme) Color.White.copy(alpha = 0.6f) else Color.Black.copy(
|
||||
alpha = 0.8f
|
||||
),
|
||||
fontFamily = FontFamily(Font(R.font.sf_pro))
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
Spacer(modifier = Modifier.height(20.dp))
|
||||
DeviceInfoCard()
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
AppInfoCard()
|
||||
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
|
||||
@@ -694,5 +636,94 @@ fun AppSettingsScreen(
|
||||
})
|
||||
}
|
||||
}
|
||||
StyledBottomSheet(
|
||||
visible = contactBottomSheet.value,
|
||||
onDismiss = { contactBottomSheet.value = false },
|
||||
backdrop = backdrop
|
||||
) { innerBackdrop, progress ->
|
||||
val animatedPadding = lerp(16.dp, 2.dp, progress)
|
||||
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = animatedPadding)
|
||||
.padding(bottom = 16.dp),
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(bottom = 16.dp),
|
||||
horizontalArrangement = Arrangement.SpaceBetween,
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
StyledIconButton(
|
||||
icon = "\uDBC0\uDD84",
|
||||
backdrop = innerBackdrop,
|
||||
onClick = { contactBottomSheet.value = false }
|
||||
)
|
||||
Text (
|
||||
text = stringResource(R.string.describe_your_issue),
|
||||
style = TextStyle(
|
||||
fontSize = 18.sp,
|
||||
fontFamily = FontFamily(Font(R.font.sf_pro)),
|
||||
fontWeight = FontWeight.Bold,
|
||||
textAlign = TextAlign.Center,
|
||||
color = if (isSystemInDarkTheme()) Color.White else Color.Black
|
||||
)
|
||||
)
|
||||
StyledIconButton(
|
||||
icon = "\uDBC0\uDE1F",
|
||||
backdrop = innerBackdrop,
|
||||
surfaceColor = if (isSystemInDarkTheme()) Color(0xFF0091FF) else Color(0xFF0088FF),
|
||||
iconTint = if (subjectState.text.isNotEmpty() && descriptionState.text.isNotEmpty()) Color.White else Color.Gray,
|
||||
enabled = subjectState.text.isNotEmpty() && descriptionState.text.isNotEmpty(),
|
||||
onClick = {
|
||||
contactBottomSheet.value = false
|
||||
val intent = Intent(Intent.ACTION_SENDTO).apply {
|
||||
data = "mailto:".toUri()
|
||||
putExtra(Intent.EXTRA_EMAIL, arrayOf("contact@kavish.xyz"))
|
||||
putExtra(Intent.EXTRA_SUBJECT, "LibrePods: ${subjectState.text}")
|
||||
putExtra(
|
||||
Intent.EXTRA_TEXT,
|
||||
"${descriptionState.text}" +
|
||||
"\n\n----------" +
|
||||
"\nPhone details:" +
|
||||
"\nMANUFACTURER: ${Build.MANUFACTURER}" +
|
||||
"\nMODEL: ${Build.MODEL} (${Build.PRODUCT})" +
|
||||
"\nDISPLAY_VERSION: ${Build.DISPLAY}" +
|
||||
"\nID: ${Build.ID} (SDK ${Build.VERSION.SDK_INT_FULL})" +
|
||||
"\nXposed enabled/active: ${XposedState.isAvailable}/${XposedState.bluetoothScopeEnabled}" +
|
||||
"\n\nApp details:" +
|
||||
"\nVERSION: ${BuildConfig.VERSION_NAME}" +
|
||||
"\nVERSION_CODE: ${BuildConfig.VERSION_CODE}" +
|
||||
"\nFLAVOR: ${BuildConfig.FLAVOR}" +
|
||||
"\nBUILD_TYPE: ${BuildConfig.BUILD_TYPE}"
|
||||
)
|
||||
}
|
||||
context.startActivity(intent)
|
||||
subjectState.clearText()
|
||||
descriptionState.clearText()
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
|
||||
StyledInputField(
|
||||
inputState = subjectState,
|
||||
focusRequester = subjectFocusRequester,
|
||||
placeholder = stringResource(R.string.subject),
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(12.dp))
|
||||
|
||||
StyledInputField(
|
||||
inputState = descriptionState,
|
||||
focusRequester = descriptionFocusRequester,
|
||||
placeholder = stringResource(R.string.describe_your_issue),
|
||||
singleLine = false
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,9 +99,9 @@ import me.kavishdevar.librepods.presentation.components.StyledButton
|
||||
import me.kavishdevar.librepods.presentation.components.StyledIconButton
|
||||
import me.kavishdevar.librepods.presentation.components.StyledScaffold
|
||||
import me.kavishdevar.librepods.presentation.components.StyledToggle
|
||||
import me.kavishdevar.librepods.presentation.viewmodel.AirPodsViewModel
|
||||
import me.kavishdevar.librepods.services.ServiceManager
|
||||
import me.kavishdevar.librepods.utils.HeadTracking
|
||||
import me.kavishdevar.librepods.presentation.viewmodel.AirPodsViewModel
|
||||
import kotlin.io.encoding.ExperimentalEncodingApi
|
||||
import kotlin.math.abs
|
||||
import kotlin.math.cos
|
||||
@@ -151,9 +151,13 @@ fun HeadTrackingScreen(viewModel: AirPodsViewModel, navController: NavController
|
||||
|
||||
var lastClickTime by remember { mutableLongStateOf(0L) }
|
||||
var shouldExplode by remember { mutableStateOf(false) }
|
||||
|
||||
val scrollState = rememberScrollState()
|
||||
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth(),
|
||||
.fillMaxWidth()
|
||||
.verticalScroll(scrollState),
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
Column (
|
||||
@@ -163,7 +167,6 @@ fun HeadTrackingScreen(viewModel: AirPodsViewModel, navController: NavController
|
||||
.layerBackdrop(backdrop)
|
||||
.padding(top = 8.dp)
|
||||
.padding(horizontal = 16.dp)
|
||||
.verticalScroll(scrollState)
|
||||
) {
|
||||
Spacer(modifier = Modifier.height(topPadding))
|
||||
|
||||
@@ -175,7 +178,7 @@ fun HeadTrackingScreen(viewModel: AirPodsViewModel, navController: NavController
|
||||
backdrop = rememberLayerBackdrop(),
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
maxScale = 0.05f,
|
||||
tint = if (isSystemInDarkTheme()) Color(0xFF916100) else Color(0xFFE59900)
|
||||
surfaceColor = if (isSystemInDarkTheme()) Color(0xFF916100) else Color(0xFFE59900)
|
||||
) {
|
||||
Text(
|
||||
stringResource(R.string.unlock_advanced_features),
|
||||
@@ -194,7 +197,7 @@ fun HeadTrackingScreen(viewModel: AirPodsViewModel, navController: NavController
|
||||
label = "Head Gestures",
|
||||
checked = state.headGesturesEnabled,
|
||||
onCheckedChange = { viewModel.setHeadGesturesEnabled(it) },
|
||||
enabled = state.isPremium,
|
||||
enabled = state.isPremium || state.headGesturesEnabled,
|
||||
description = stringResource(R.string.head_gestures_details)
|
||||
)
|
||||
|
||||
|
||||
@@ -270,7 +270,7 @@ fun HearingAidScreen(viewModel: AirPodsViewModel, navController: NavController)
|
||||
hearingAidEnabled.value = false
|
||||
showDialog.value = false
|
||||
},
|
||||
hazeState = hazeStateS.value,
|
||||
// backdrop = backdrop
|
||||
// hazeState = hazeStateS.value,
|
||||
backdrop = backdrop
|
||||
)
|
||||
}
|
||||
|
||||
@@ -18,29 +18,39 @@
|
||||
|
||||
package me.kavishdevar.librepods.presentation.screens
|
||||
|
||||
import androidx.compose.foundation.isSystemInDarkTheme
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.TextStyle
|
||||
import androidx.compose.ui.text.font.Font
|
||||
import androidx.compose.ui.text.font.FontFamily
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.navigation.NavController
|
||||
import com.kyant.backdrop.backdrops.layerBackdrop
|
||||
import com.kyant.backdrop.backdrops.rememberLayerBackdrop
|
||||
import me.kavishdevar.librepods.BuildConfig
|
||||
import me.kavishdevar.librepods.R
|
||||
import me.kavishdevar.librepods.presentation.components.StyledScaffold
|
||||
import me.kavishdevar.librepods.presentation.components.StyledToggle
|
||||
import me.kavishdevar.librepods.bluetooth.AACPManager
|
||||
import me.kavishdevar.librepods.bluetooth.ATTHandles
|
||||
import me.kavishdevar.librepods.presentation.components.StyledButton
|
||||
import me.kavishdevar.librepods.presentation.components.StyledScaffold
|
||||
import me.kavishdevar.librepods.presentation.components.StyledToggle
|
||||
import me.kavishdevar.librepods.presentation.viewmodel.AirPodsViewModel
|
||||
|
||||
@Composable
|
||||
fun HearingProtectionScreen(viewModel: AirPodsViewModel) {
|
||||
fun HearingProtectionScreen(viewModel: AirPodsViewModel, navController: NavController) {
|
||||
val backdrop = rememberLayerBackdrop()
|
||||
val state by viewModel.uiState.collectAsState()
|
||||
StyledScaffold(
|
||||
@@ -53,7 +63,27 @@ fun HearingProtectionScreen(viewModel: AirPodsViewModel) {
|
||||
.padding(horizontal = 16.dp)
|
||||
) {
|
||||
Spacer(modifier = Modifier.height(spacerHeight))
|
||||
|
||||
if (!state.isPremium) {
|
||||
StyledButton(
|
||||
onClick = {
|
||||
navController.navigate("purchase_screen")
|
||||
},
|
||||
backdrop = rememberLayerBackdrop(),
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
maxScale = 0.05f,
|
||||
surfaceColor = if (isSystemInDarkTheme()) Color(0xFF916100) else Color(0xFFE59900)
|
||||
) {
|
||||
Text(
|
||||
stringResource(R.string.unlock_advanced_features),
|
||||
style = TextStyle(
|
||||
fontSize = 16.sp,
|
||||
fontWeight = FontWeight.Medium,
|
||||
fontFamily = FontFamily(Font(R.font.sf_pro)),
|
||||
color = Color.White
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
if (state.vendorIdHook) {
|
||||
StyledToggle(
|
||||
title = stringResource(R.string.environmental_noise),
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
|
||||
package me.kavishdevar.librepods.presentation.screens
|
||||
|
||||
import android.content.Context
|
||||
import android.util.Log
|
||||
import androidx.compose.foundation.isSystemInDarkTheme
|
||||
import androidx.compose.foundation.layout.Column
|
||||
@@ -34,13 +33,8 @@ import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableIntStateOf
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.TextStyle
|
||||
import androidx.compose.ui.text.font.Font
|
||||
@@ -48,19 +42,17 @@ import androidx.compose.ui.text.font.FontFamily
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.core.content.edit
|
||||
import androidx.navigation.NavController
|
||||
import com.kyant.backdrop.backdrops.layerBackdrop
|
||||
import com.kyant.backdrop.backdrops.rememberLayerBackdrop
|
||||
import dev.chrisbanes.haze.materials.ExperimentalHazeMaterialsApi
|
||||
import me.kavishdevar.librepods.R
|
||||
import me.kavishdevar.librepods.bluetooth.AACPManager
|
||||
import me.kavishdevar.librepods.data.StemAction
|
||||
import me.kavishdevar.librepods.presentation.components.SelectItem
|
||||
import me.kavishdevar.librepods.presentation.components.StyledButton
|
||||
import me.kavishdevar.librepods.presentation.components.StyledScaffold
|
||||
import me.kavishdevar.librepods.presentation.components.StyledSelectList
|
||||
import me.kavishdevar.librepods.data.StemAction
|
||||
import me.kavishdevar.librepods.services.ServiceManager
|
||||
import me.kavishdevar.librepods.bluetooth.AACPManager
|
||||
import me.kavishdevar.librepods.presentation.viewmodel.AirPodsViewModel
|
||||
import kotlin.experimental.and
|
||||
import kotlin.io.encoding.ExperimentalEncodingApi
|
||||
@@ -82,12 +74,7 @@ fun LongPress(viewModel: AirPodsViewModel, name: String, navController: NavContr
|
||||
Log.d("PressAndHoldSettingsScreen", "Noise Cancellation mode: ${(modesByte and 0x02) != 0.toByte()}")
|
||||
Log.d("PressAndHoldSettingsScreen", "Adaptive mode: ${(modesByte and 0x08) != 0.toByte()}")
|
||||
|
||||
val context = LocalContext.current
|
||||
val sharedPreferences = context.getSharedPreferences("settings", Context.MODE_PRIVATE)
|
||||
val prefKey = if (name.lowercase() == "left") "left_long_press_action" else "right_long_press_action"
|
||||
val longPressActionPref = sharedPreferences.getString(prefKey, StemAction.CYCLE_NOISE_CONTROL_MODES.name)
|
||||
Log.d("PressAndHoldSettingsScreen", "Long press action preference ($prefKey): $longPressActionPref")
|
||||
var longPressAction by remember { mutableStateOf(StemAction.valueOf(longPressActionPref ?: StemAction.CYCLE_NOISE_CONTROL_MODES.name)) }
|
||||
val longPressAction = if (name.lowercase() == "left") state.leftAction else state.rightAction
|
||||
val backdrop = rememberLayerBackdrop()
|
||||
StyledScaffold(
|
||||
title = name
|
||||
@@ -105,16 +92,14 @@ fun LongPress(viewModel: AirPodsViewModel, name: String, navController: NavContr
|
||||
name = stringResource(R.string.noise_control),
|
||||
selected = longPressAction == StemAction.CYCLE_NOISE_CONTROL_MODES,
|
||||
onClick = {
|
||||
longPressAction = StemAction.CYCLE_NOISE_CONTROL_MODES
|
||||
sharedPreferences.edit { putString(prefKey, StemAction.CYCLE_NOISE_CONTROL_MODES.name) }
|
||||
viewModel.setLongPressAction(name, StemAction.CYCLE_NOISE_CONTROL_MODES)
|
||||
}
|
||||
),
|
||||
SelectItem(
|
||||
name = stringResource(R.string.digital_assistant),
|
||||
selected = longPressAction == StemAction.DIGITAL_ASSISTANT,
|
||||
onClick = {
|
||||
longPressAction = StemAction.DIGITAL_ASSISTANT
|
||||
sharedPreferences.edit { putString(prefKey, StemAction.DIGITAL_ASSISTANT.name) }
|
||||
viewModel.setLongPressAction(name, StemAction.DIGITAL_ASSISTANT)
|
||||
},
|
||||
enabled = state.isPremium
|
||||
)
|
||||
@@ -130,7 +115,7 @@ fun LongPress(viewModel: AirPodsViewModel, name: String, navController: NavContr
|
||||
backdrop = rememberLayerBackdrop(),
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
maxScale = 0.05f,
|
||||
tint = if (isSystemInDarkTheme()) Color(0xFF916100) else Color(0xFFE59900)
|
||||
surfaceColor = if (isSystemInDarkTheme()) Color(0xFF916100) else Color(0xFFE59900)
|
||||
) {
|
||||
Text(
|
||||
stringResource(R.string.unlock_advanced_features),
|
||||
@@ -162,21 +147,10 @@ fun LongPress(viewModel: AirPodsViewModel, name: String, navController: NavContr
|
||||
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
|
||||
val offListeningModeValue = ServiceManager.getService()!!.aacpManager.controlCommandStatusList.find {
|
||||
it.identifier == AACPManager.Companion.ControlCommandIdentifiers.ALLOW_OFF_OPTION
|
||||
}?.value?.takeIf { it.isNotEmpty() }?.get(0)
|
||||
Log.d("PressAndHoldSettingsScreen", "Allow Off state: $offListeningModeValue")
|
||||
val allowOff = offListeningModeValue == 1.toByte()
|
||||
Log.d("PressAndHoldSettingsScreen", "Allow Off option: $allowOff")
|
||||
|
||||
val initialByte = state.controlStates[AACPManager.Companion.ControlCommandIdentifiers.LISTENING_MODE_CONFIGS]
|
||||
?.get(0)?.toInt()
|
||||
?: sharedPreferences.getInt("long_press_byte", 0b0101)
|
||||
|
||||
var currentByte by remember { mutableIntStateOf(initialByte) }
|
||||
val currentByte = state.controlStates[AACPManager.Companion.ControlCommandIdentifiers.LISTENING_MODE_CONFIGS]?.get(0)?.toInt() ?: 0
|
||||
|
||||
val listeningModeItems = mutableListOf<SelectItem>()
|
||||
if (allowOff) {
|
||||
if (state.offListeningMode) {
|
||||
listeningModeItems.add(
|
||||
SelectItem(
|
||||
name = stringResource(R.string.off),
|
||||
@@ -184,21 +158,7 @@ fun LongPress(viewModel: AirPodsViewModel, name: String, navController: NavContr
|
||||
iconRes = R.drawable.noise_cancellation,
|
||||
selected = (currentByte and 0x01) != 0,
|
||||
onClick = {
|
||||
val bit = 0x01
|
||||
val newValue = if ((currentByte and bit) != 0) {
|
||||
val temp = currentByte and bit.inv()
|
||||
if (countEnabledModes(temp) >= 2) temp else currentByte
|
||||
} else {
|
||||
currentByte or bit
|
||||
}
|
||||
viewModel.setControlCommandByte(
|
||||
AACPManager.Companion.ControlCommandIdentifiers.LISTENING_MODE_CONFIGS,
|
||||
newValue.toByte()
|
||||
)
|
||||
sharedPreferences.edit {
|
||||
putInt("long_press_byte", newValue)
|
||||
}
|
||||
currentByte = newValue
|
||||
viewModel.toggleListeningMode(0x01)
|
||||
}
|
||||
)
|
||||
)
|
||||
@@ -210,21 +170,7 @@ fun LongPress(viewModel: AirPodsViewModel, name: String, navController: NavContr
|
||||
iconRes = R.drawable.transparency,
|
||||
selected = (currentByte and 0x04) != 0,
|
||||
onClick = {
|
||||
val bit = 0x04
|
||||
val newValue = if ((currentByte and bit) != 0) {
|
||||
val temp = currentByte and bit.inv()
|
||||
if (countEnabledModes(temp) >= 2) temp else currentByte
|
||||
} else {
|
||||
currentByte or bit
|
||||
}
|
||||
viewModel.setControlCommandByte(
|
||||
AACPManager.Companion.ControlCommandIdentifiers.LISTENING_MODE_CONFIGS,
|
||||
newValue.toByte()
|
||||
)
|
||||
sharedPreferences.edit {
|
||||
putInt("long_press_byte", newValue)
|
||||
}
|
||||
currentByte = newValue
|
||||
viewModel.toggleListeningMode(0x04)
|
||||
}
|
||||
),
|
||||
SelectItem(
|
||||
@@ -233,21 +179,7 @@ fun LongPress(viewModel: AirPodsViewModel, name: String, navController: NavContr
|
||||
iconRes = R.drawable.adaptive,
|
||||
selected = (currentByte and 0x08) != 0,
|
||||
onClick = {
|
||||
val bit = 0x08
|
||||
val newValue = if ((currentByte and bit) != 0) {
|
||||
val temp = currentByte and bit.inv()
|
||||
if (countEnabledModes(temp) >= 2) temp else currentByte
|
||||
} else {
|
||||
currentByte or bit
|
||||
}
|
||||
viewModel.setControlCommandByte(
|
||||
AACPManager.Companion.ControlCommandIdentifiers.LISTENING_MODE_CONFIGS,
|
||||
newValue.toByte()
|
||||
)
|
||||
sharedPreferences.edit {
|
||||
putInt("long_press_byte", newValue)
|
||||
}
|
||||
currentByte = newValue
|
||||
viewModel.toggleListeningMode(0x08)
|
||||
}
|
||||
),
|
||||
SelectItem(
|
||||
@@ -256,21 +188,7 @@ fun LongPress(viewModel: AirPodsViewModel, name: String, navController: NavContr
|
||||
iconRes = R.drawable.noise_cancellation,
|
||||
selected = (currentByte and 0x02) != 0,
|
||||
onClick = {
|
||||
val bit = 0x02
|
||||
val newValue = if ((currentByte and bit) != 0) {
|
||||
val temp = currentByte and bit.inv()
|
||||
if (countEnabledModes(temp) >= 2) temp else currentByte
|
||||
} else {
|
||||
currentByte or bit
|
||||
}
|
||||
viewModel.setControlCommandByte(
|
||||
AACPManager.Companion.ControlCommandIdentifiers.LISTENING_MODE_CONFIGS,
|
||||
newValue.toByte()
|
||||
)
|
||||
sharedPreferences.edit {
|
||||
putInt("long_press_byte", newValue)
|
||||
}
|
||||
currentByte = newValue
|
||||
viewModel.toggleListeningMode(0x02)
|
||||
}
|
||||
)
|
||||
))
|
||||
@@ -290,14 +208,4 @@ fun LongPress(viewModel: AirPodsViewModel, name: String, navController: NavContr
|
||||
}
|
||||
}
|
||||
}
|
||||
Log.d("PressAndHoldSettingsScreen", "Current byte: ${modesByte.toString(2)}")
|
||||
}
|
||||
|
||||
fun countEnabledModes(byteValue: Int): Int {
|
||||
var count = 0
|
||||
if ((byteValue and 0x01) != 0) count++
|
||||
if ((byteValue and 0x02) != 0) count++
|
||||
if ((byteValue and 0x04) != 0) count++
|
||||
if ((byteValue and 0x08) != 0) count++
|
||||
return count
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ fun PurchaseScreen(
|
||||
.padding(horizontal = 16.dp, vertical = 4.dp)
|
||||
) {
|
||||
Text(
|
||||
text = "Free features",
|
||||
text = stringResource(R.string.free_features),
|
||||
style = TextStyle(
|
||||
fontSize = 14.sp,
|
||||
fontWeight = FontWeight.Bold,
|
||||
@@ -242,7 +242,7 @@ fun PurchaseScreen(
|
||||
.padding(horizontal = 16.dp, vertical = 4.dp)
|
||||
) {
|
||||
Text(
|
||||
text = "Advanced features",
|
||||
text = stringResource(R.string.advanced_features),
|
||||
style = TextStyle(
|
||||
fontSize = 14.sp,
|
||||
fontWeight = FontWeight.Bold,
|
||||
@@ -288,6 +288,36 @@ fun PurchaseScreen(
|
||||
modifier = Modifier
|
||||
.padding(horizontal = 12.dp)
|
||||
)
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 12.dp, vertical = 4.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(2.dp)
|
||||
) {
|
||||
Text(
|
||||
text = stringResource(R.string.digital_assistant_on_long_press),
|
||||
style = TextStyle(
|
||||
fontSize = 16.sp,
|
||||
fontWeight = FontWeight.Normal,
|
||||
fontFamily = FontFamily(Font(R.font.sf_pro)),
|
||||
color = textColor
|
||||
)
|
||||
)
|
||||
Text(
|
||||
text = stringResource(R.string.digital_assistant_on_long_press_description),
|
||||
style = TextStyle(
|
||||
fontSize = 12.sp,
|
||||
color = textColor.copy(0.6f),
|
||||
fontFamily = FontFamily(Font(R.font.sf_pro)),
|
||||
)
|
||||
)
|
||||
}
|
||||
HorizontalDivider(
|
||||
thickness = 1.dp,
|
||||
color = Color(0x40888888),
|
||||
modifier = Modifier
|
||||
.padding(horizontal = 12.dp)
|
||||
)
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
@@ -456,10 +486,11 @@ fun PurchaseScreen(
|
||||
backdrop = rememberLayerBackdrop(),
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
maxScale = 0.05f,
|
||||
tint = if (isSystemInDarkTheme()) Color(0xFF916100) else Color(0xFFE59900)
|
||||
surfaceColor = if (isSystemInDarkTheme()) Color(0xFF0091FF)
|
||||
else Color(0xFF0088FF) // if (isSystemInDarkTheme()) Color(0xFF916100) else Color(0xFFE59900)
|
||||
) {
|
||||
Text(
|
||||
stringResource(R.string.buy),
|
||||
stringResource(R.string.buy_price, state.price),
|
||||
style = TextStyle(
|
||||
fontSize = 16.sp,
|
||||
fontWeight = FontWeight.Medium,
|
||||
@@ -478,6 +509,7 @@ fun PurchaseScreen(
|
||||
backdrop = rememberLayerBackdrop(),
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
maxScale = 0.05f,
|
||||
isInteractive = false
|
||||
) {
|
||||
Text(
|
||||
stringResource(R.string.restore_purchases),
|
||||
|
||||
@@ -21,45 +21,26 @@
|
||||
package me.kavishdevar.librepods.presentation.screens
|
||||
|
||||
import android.content.Context
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.isSystemInDarkTheme
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.foundation.text.BasicTextField
|
||||
import androidx.compose.foundation.text.input.rememberTextFieldState
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.focus.FocusRequester
|
||||
import androidx.compose.ui.focus.focusRequester
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.SolidColor
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.TextRange
|
||||
import androidx.compose.ui.text.TextStyle
|
||||
import androidx.compose.ui.text.font.Font
|
||||
import androidx.compose.ui.text.font.FontFamily
|
||||
import androidx.compose.ui.text.input.TextFieldValue
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.core.content.edit
|
||||
import com.kyant.backdrop.backdrops.layerBackdrop
|
||||
import com.kyant.backdrop.backdrops.rememberLayerBackdrop
|
||||
import dev.chrisbanes.haze.materials.ExperimentalHazeMaterialsApi
|
||||
import me.kavishdevar.librepods.R
|
||||
import me.kavishdevar.librepods.presentation.components.StyledInputField
|
||||
import me.kavishdevar.librepods.presentation.components.StyledScaffold
|
||||
import me.kavishdevar.librepods.presentation.viewmodel.AirPodsViewModel
|
||||
import kotlin.io.encoding.ExperimentalEncodingApi
|
||||
@@ -69,89 +50,35 @@ import kotlin.io.encoding.ExperimentalEncodingApi
|
||||
@Composable
|
||||
fun RenameScreen(viewModel: AirPodsViewModel) {
|
||||
val sharedPreferences = LocalContext.current.getSharedPreferences("settings", Context.MODE_PRIVATE)
|
||||
val name = remember { mutableStateOf(TextFieldValue(sharedPreferences.getString("name", "") ?: "")) }
|
||||
val focusRequester = remember { FocusRequester() }
|
||||
val keyboardController = LocalSoftwareKeyboardController.current
|
||||
|
||||
LaunchedEffect(Unit) {
|
||||
focusRequester.requestFocus()
|
||||
keyboardController?.show()
|
||||
name.value = name.value.copy(selection = TextRange(name.value.text.length))
|
||||
}
|
||||
|
||||
val backdrop = rememberLayerBackdrop()
|
||||
|
||||
StyledScaffold(
|
||||
title = stringResource(R.string.name),
|
||||
) { spacerHeight ->
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.layerBackdrop(backdrop)
|
||||
.padding(horizontal = 16.dp)
|
||||
) {
|
||||
Spacer(modifier = Modifier.height(spacerHeight))
|
||||
val isDarkTheme = isSystemInDarkTheme()
|
||||
val backgroundColor = if (isDarkTheme) Color(0xFF1C1C1E) else Color(0xFFFFFFFF)
|
||||
val textColor = if (isDarkTheme) Color.White else Color.Black
|
||||
val cursorColor = if (isDarkTheme) Color.White else Color.Black
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.height(58.dp)
|
||||
.background(
|
||||
backgroundColor,
|
||||
RoundedCornerShape(28.dp)
|
||||
)
|
||||
.padding(horizontal = 16.dp, vertical = 8.dp)
|
||||
) {
|
||||
BasicTextField(
|
||||
value = name.value,
|
||||
onValueChange = {
|
||||
name.value = it
|
||||
sharedPreferences.edit {putString("name", it.text)}
|
||||
viewModel.setName(it.text)
|
||||
},
|
||||
textStyle = TextStyle(
|
||||
fontSize = 16.sp,
|
||||
color = textColor,
|
||||
fontFamily = FontFamily(Font(R.font.sf_pro))
|
||||
),
|
||||
singleLine = true,
|
||||
cursorBrush = SolidColor(cursorColor),
|
||||
decorationBox = { innerTextField ->
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
) {
|
||||
innerTextField()
|
||||
}
|
||||
IconButton(
|
||||
onClick = {
|
||||
name.value = TextFieldValue("")
|
||||
}
|
||||
) {
|
||||
Text(
|
||||
text = "",
|
||||
style = TextStyle(
|
||||
fontSize = 16.sp,
|
||||
fontFamily = FontFamily(Font(R.font.sf_pro)),
|
||||
color = if (isDarkTheme) Color.White.copy(alpha = 0.6f) else Color.Black.copy(alpha = 0.6f)
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
},
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(start = 8.dp)
|
||||
.focusRequester(focusRequester)
|
||||
)
|
||||
|
||||
val textFieldState = rememberTextFieldState()
|
||||
textFieldState.edit { sharedPreferences.getString("name", "") ?: "" }
|
||||
LaunchedEffect(textFieldState.text) {
|
||||
sharedPreferences.edit {putString("name", textFieldState.text as String?)}
|
||||
viewModel.setName(textFieldState.text.toString())
|
||||
}
|
||||
|
||||
StyledInputField(
|
||||
textFieldState,
|
||||
focusRequester
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,8 @@ import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.IntentFilter
|
||||
import android.content.SharedPreferences
|
||||
import android.util.Log
|
||||
import android.content.pm.PackageManager
|
||||
import android.widget.Toast
|
||||
import androidx.core.content.edit
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
@@ -34,7 +35,6 @@ import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.update
|
||||
import kotlinx.coroutines.launch
|
||||
import me.kavishdevar.librepods.BuildConfig
|
||||
import me.kavishdevar.librepods.billing.BillingManager
|
||||
import me.kavishdevar.librepods.bluetooth.AACPManager
|
||||
import me.kavishdevar.librepods.bluetooth.AACPManager.Companion.ControlCommandIdentifiers
|
||||
@@ -89,7 +89,11 @@ data class AirPodsUiState(
|
||||
val hearingAidData: ByteArray = byteArrayOf(),
|
||||
|
||||
val isPremium: Boolean = false,
|
||||
val vendorIdHook: Boolean = false
|
||||
val vendorIdHook: Boolean = false,
|
||||
|
||||
val dynamicEndOfCharge: Boolean = false,
|
||||
|
||||
val connectionSuccessful: Boolean = false
|
||||
)
|
||||
|
||||
class AirPodsViewModel(
|
||||
@@ -111,8 +115,6 @@ class AirPodsViewModel(
|
||||
private var isDemoMode = false
|
||||
val demoActivated = MutableSharedFlow<Unit>()
|
||||
|
||||
private var billingFirstCollectDone = false
|
||||
|
||||
private val listeners =
|
||||
mutableMapOf<ControlCommandIdentifiers, AACPManager.ControlCommandListener>()
|
||||
|
||||
@@ -164,21 +166,18 @@ class AirPodsViewModel(
|
||||
private fun observeBilling() {
|
||||
if (isDemoMode) return
|
||||
viewModelScope.launch {
|
||||
if (!BuildConfig.PLAY_BUILD) billingFirstCollectDone = true // FOSS doesn't send multiple events
|
||||
// if (!BuildConfig.PLAY_BUILD) billingFirstCollectDone = true // FOSS doesn't send multiple events
|
||||
BillingManager.provider.isPremium.collect { premium ->
|
||||
if (!billingFirstCollectDone) {
|
||||
billingFirstCollectDone = true
|
||||
return@collect
|
||||
}
|
||||
// if (!billingFirstCollectDone) {
|
||||
// billingFirstCollectDone = true
|
||||
// return@collect
|
||||
// }
|
||||
if (!premium) {
|
||||
Log.d("AirPodsViewModel", "we are not premium")
|
||||
setControlCommandBoolean(
|
||||
ControlCommandIdentifiers.CONVERSATION_DETECT_CONFIG,
|
||||
false
|
||||
)
|
||||
setHeadGesturesEnabled(false)
|
||||
} else {
|
||||
Log.d("AirPodsViewModel", "we are premium")
|
||||
}
|
||||
_uiState.update { it.copy(isPremium = premium) }
|
||||
}
|
||||
@@ -188,8 +187,9 @@ class AirPodsViewModel(
|
||||
private fun observeBroadcasts() {
|
||||
broadcastReceiver = object : BroadcastReceiver() {
|
||||
override fun onReceive(context: Context?, intent: Intent?) {
|
||||
if (!isDemoMode) when (intent?.action) {
|
||||
AirPodsNotifications.AIRPODS_CONNECTED -> {
|
||||
val action = intent?.action ?: return
|
||||
if (!isDemoMode) when (action) {
|
||||
AirPodsNotifications.AIRPODS_L2CAP_CONNECTED -> {
|
||||
_uiState.update {
|
||||
it.copy(isLocallyConnected = true)
|
||||
}
|
||||
@@ -202,10 +202,8 @@ class AirPodsViewModel(
|
||||
}
|
||||
|
||||
AirPodsNotifications.BATTERY_DATA -> {
|
||||
val data = intent.getParcelableArrayListExtra("data", Battery::class.java)
|
||||
?.toList() ?: emptyList()
|
||||
_uiState.update {
|
||||
it.copy(battery = data)
|
||||
it.copy(battery = service.getBattery())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -274,13 +272,20 @@ class AirPodsViewModel(
|
||||
val current = state.controlStates[identifier]
|
||||
if (current?.contentEquals(value) == true) return@update state
|
||||
|
||||
state.copy(
|
||||
controlStates = state.controlStates + (identifier to value)
|
||||
)
|
||||
if (identifier == ControlCommandIdentifiers.DYNAMIC_END_OF_CHARGE) {
|
||||
state.copy(
|
||||
dynamicEndOfCharge = value[0] == 0x01.toByte(),
|
||||
controlStates = state.controlStates + (identifier to value)
|
||||
)
|
||||
} else {
|
||||
state.copy(
|
||||
controlStates = state.controlStates + (identifier to value)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
listeners[identifier] = listener as AACPManager.ControlCommandListener
|
||||
listeners[identifier] = listener
|
||||
}
|
||||
|
||||
// I'm lazy, sorry.
|
||||
@@ -311,6 +316,7 @@ class AirPodsViewModel(
|
||||
ControlCommandIdentifiers.AUTOMATIC_CONNECTION_CONFIG,
|
||||
ControlCommandIdentifiers.OWNS_CONNECTION,
|
||||
ControlCommandIdentifiers.PPE_TOGGLE_CONFIG,
|
||||
ControlCommandIdentifiers.DYNAMIC_END_OF_CHARGE
|
||||
)
|
||||
for (identifier in identifiersList) {
|
||||
observeControl(identifier)
|
||||
@@ -348,6 +354,9 @@ class AirPodsViewModel(
|
||||
) ?: "CYCLE_NOISE_CONTROL_MODES"
|
||||
)
|
||||
val vendorIdHook = xposedRemotePref.getBoolean("vendor_id_hook", false)
|
||||
val dynamicEndOfCharge = sharedPreferences.getBoolean("dynamic_end_of_charge", false)
|
||||
|
||||
val connectionSuccessful = sharedPreferences.getBoolean("connection_successful", false)
|
||||
|
||||
_uiState.update {
|
||||
it.copy(
|
||||
@@ -357,7 +366,9 @@ class AirPodsViewModel(
|
||||
headGesturesEnabled = headGesturesEnabled,
|
||||
leftAction = leftAction,
|
||||
rightAction = rightAction,
|
||||
vendorIdHook = vendorIdHook
|
||||
vendorIdHook = vendorIdHook,
|
||||
dynamicEndOfCharge = dynamicEndOfCharge,
|
||||
connectionSuccessful = connectionSuccessful
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -365,7 +376,6 @@ class AirPodsViewModel(
|
||||
fun setOffListeningMode(enabled: Boolean) {
|
||||
sharedPreferences.edit { putBoolean("off_listening_mode", enabled) }
|
||||
setControlCommandBoolean(ControlCommandIdentifiers.ALLOW_OFF_OPTION, enabled)
|
||||
Log.d("AirPodsViewModel", "Hello???? $enabled")
|
||||
_uiState.update {
|
||||
it.copy(offListeningMode = enabled)
|
||||
}
|
||||
@@ -378,6 +388,14 @@ class AirPodsViewModel(
|
||||
}
|
||||
}
|
||||
|
||||
fun setDynamicEndOfCharge(enabled: Boolean) {
|
||||
service.aacpManager.sendControlCommand(ControlCommandIdentifiers.DYNAMIC_END_OF_CHARGE.value, enabled)
|
||||
sharedPreferences.edit { putBoolean("dynamic_end_of_charge", enabled) }
|
||||
_uiState.update {
|
||||
it.copy(dynamicEndOfCharge = enabled)
|
||||
}
|
||||
}
|
||||
|
||||
private fun loadControlList() {
|
||||
_uiState.update {
|
||||
it.copy(
|
||||
@@ -440,7 +458,15 @@ class AirPodsViewModel(
|
||||
_uiState.update { it.copy(loudSoundReductionEnabled = value[0].toInt() == 0x01) }
|
||||
}
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
service.attManager?.write(handle, value)
|
||||
try {
|
||||
service.attManager?.connect()
|
||||
while (service.attManager?.socket?.isConnected != true) {
|
||||
delay(250)
|
||||
}
|
||||
service.attManager?.write(handle, value)
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -463,13 +489,16 @@ class AirPodsViewModel(
|
||||
fun observeATT() {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
service.attManager?.connect()
|
||||
while (service.attManager?.socket?.isConnected != true) {
|
||||
delay(1000)
|
||||
}
|
||||
service.attManager?.enableNotifications(ATTHandles.LOUD_SOUND_REDUCTION)
|
||||
service.attManager?.enableNotifications(ATTHandles.TRANSPARENCY)
|
||||
service.attManager?.enableNotifications(ATTHandles.HEARING_AID)
|
||||
|
||||
while (true) {
|
||||
refreshATT()
|
||||
delay(10000)
|
||||
delay(15000)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -494,10 +523,6 @@ class AirPodsViewModel(
|
||||
}
|
||||
}
|
||||
|
||||
// fun purchase(context: Context) {
|
||||
// BillingManager.provider.purchase(context as Activity)
|
||||
// }
|
||||
|
||||
fun activateDemoMode() {
|
||||
isDemoMode = true
|
||||
viewModelScope.launch {
|
||||
@@ -530,8 +555,50 @@ class AirPodsViewModel(
|
||||
modelName = fakeInstance.model.displayName,
|
||||
actualModel = fakeInstance.actualModelNumber,
|
||||
serialNumbers = listOf("DEMO", "DEMO", "DEMO"),
|
||||
version3 = "Demo Firmware"
|
||||
version3 = "Demo Firmware",
|
||||
isPremium = true
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun sendPhoneMediaEQ(eq: FloatArray, phoneByte: Byte, mediaByte: Byte) {
|
||||
service.aacpManager.sendPhoneMediaEQ(eq, phoneByte, mediaByte)
|
||||
}
|
||||
|
||||
fun setLongPressAction(side: String, action: StemAction) {
|
||||
val prefKey = if (side.lowercase() == "left") "left_long_press_action" else "right_long_press_action"
|
||||
sharedPreferences.edit { putString(prefKey, action.name) }
|
||||
_uiState.update {
|
||||
if (side.lowercase() == "left") it.copy(leftAction = action) else it.copy(rightAction = action)
|
||||
}
|
||||
}
|
||||
|
||||
private fun countEnabledModes(byteValue: Int): Int {
|
||||
var count = 0
|
||||
if ((byteValue and 0x01) != 0) count++
|
||||
if ((byteValue and 0x02) != 0) count++
|
||||
if ((byteValue and 0x04) != 0) count++
|
||||
if ((byteValue and 0x08) != 0) count++
|
||||
return count
|
||||
}
|
||||
|
||||
fun toggleListeningMode(modeBit: Int) {
|
||||
val currentByte = uiState.value.controlStates[ControlCommandIdentifiers.LISTENING_MODE_CONFIGS]?.get(0)?.toInt() ?: 0
|
||||
val newValue = if ((currentByte and modeBit) != 0) {
|
||||
val temp = currentByte and modeBit.inv()
|
||||
if (countEnabledModes(temp) >= 2) temp else currentByte
|
||||
} else {
|
||||
currentByte or modeBit
|
||||
}
|
||||
setControlCommandByte(ControlCommandIdentifiers.LISTENING_MODE_CONFIGS, newValue.toByte())
|
||||
sharedPreferences.edit { putInt("long_press_byte", newValue) }
|
||||
}
|
||||
|
||||
fun disconnect() {
|
||||
service.disconnectAirPods()
|
||||
if (appContext.checkSelfPermission("android.permission.BLUETOOTH_PRIVILEGED") != PackageManager.PERMISSION_GRANTED) {
|
||||
Toast.makeText(appContext, "App has disconnected, disconnect from Android Settings.",
|
||||
Toast.LENGTH_LONG).show()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package me.kavishdevar.librepods.presentation.viewmodel
|
||||
|
||||
import android.app.Application
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import androidx.core.content.edit
|
||||
import androidx.lifecycle.AndroidViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
@@ -9,10 +10,8 @@ import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import kotlinx.coroutines.flow.update
|
||||
import kotlinx.coroutines.launch
|
||||
import me.kavishdevar.librepods.BuildConfig
|
||||
import me.kavishdevar.librepods.billing.BillingManager
|
||||
import me.kavishdevar.librepods.data.XposedRemotePrefProvider
|
||||
import me.kavishdevar.librepods.utils.NativeBridge
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
data class AppSettingsUiState(
|
||||
@@ -32,7 +31,10 @@ data class AppSettingsUiState(
|
||||
val cameraPackageValue: String = "",
|
||||
val cameraPackageError: String? = null,
|
||||
val vendorIdHook: Boolean = false,
|
||||
val isPremium: Boolean = false
|
||||
val isPremium: Boolean = false,
|
||||
val connectionSuccessful: Boolean = false,
|
||||
val showBottomSheetPopup: Boolean = true,
|
||||
val showIslandPopup: Boolean = true
|
||||
)
|
||||
|
||||
class AppSettingsViewModel(application: Application) : AndroidViewModel(application) {
|
||||
@@ -43,9 +45,22 @@ class AppSettingsViewModel(application: Application) : AndroidViewModel(applicat
|
||||
|
||||
private val xposedRemotePref = XposedRemotePrefProvider.create()
|
||||
|
||||
val sharedPrefListener = SharedPreferences.OnSharedPreferenceChangeListener { sharedPref, key ->
|
||||
if (key == "connection_successful") {
|
||||
_uiState.update { it.copy(connectionSuccessful = sharedPref.getBoolean(key, false)) }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
init {
|
||||
loadSettings()
|
||||
observeBilling()
|
||||
sharedPreferences.registerOnSharedPreferenceChangeListener(sharedPrefListener)
|
||||
}
|
||||
|
||||
override fun onCleared() {
|
||||
sharedPreferences.unregisterOnSharedPreferenceChangeListener(sharedPrefListener)
|
||||
super.onCleared()
|
||||
}
|
||||
|
||||
private fun observeBilling() {
|
||||
@@ -72,12 +87,12 @@ class AppSettingsViewModel(application: Application) : AndroidViewModel(applicat
|
||||
useAlternateHeadTrackingPackets = sharedPreferences.getBoolean("use_alternate_head_tracking_packets", true),
|
||||
conversationalAwarenessVolume = sharedPreferences.getInt("conversational_awareness_volume", 43).toFloat(),
|
||||
cameraPackageValue = sharedPreferences.getString("custom_camera_package", "") ?: "",
|
||||
vendorIdHook = xposedRemotePref.getBoolean("vendor_id_hook", false)
|
||||
vendorIdHook = xposedRemotePref.getBoolean("vendor_id_hook", false),
|
||||
connectionSuccessful = sharedPreferences.getBoolean("connection_successful", false),
|
||||
showBottomSheetPopup = sharedPreferences.getBoolean("show_bottom_sheet_popup", true),
|
||||
showIslandPopup = sharedPreferences.getBoolean("show_island_popup", true)
|
||||
)
|
||||
}
|
||||
if (BuildConfig.FLAVOR == "xposed") {
|
||||
NativeBridge.setSdpHook(_uiState.value.vendorIdHook)
|
||||
}
|
||||
}
|
||||
|
||||
fun setShowPhoneBatteryInWidget(enabled: Boolean) {
|
||||
@@ -162,8 +177,17 @@ class AppSettingsViewModel(application: Application) : AndroidViewModel(applicat
|
||||
}
|
||||
|
||||
fun setVendorIdHook(enabled: Boolean) {
|
||||
NativeBridge.setSdpHook(enabled)
|
||||
xposedRemotePref.putBoolean("vendor_id_hook", enabled)
|
||||
_uiState.update { it.copy(vendorIdHook = enabled) }
|
||||
}
|
||||
|
||||
fun setShowBottomSheetPopup(enabled: Boolean) {
|
||||
sharedPreferences.edit { putBoolean("show_bottom_sheet_popup", enabled) }
|
||||
_uiState.update { it.copy(showBottomSheetPopup = enabled) }
|
||||
}
|
||||
|
||||
fun setShowIslandPopup(enabled: Boolean) {
|
||||
sharedPreferences.edit { putBoolean("show_island_popup", enabled) }
|
||||
_uiState.update { it.copy(showIslandPopup = enabled) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,6 +42,6 @@ class PurchaseViewModel(application: Application) : AndroidViewModel(application
|
||||
}
|
||||
|
||||
fun restorePurchases() {
|
||||
BillingManager.provider.queryPurchases()
|
||||
BillingManager.provider.restorePurchases()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,8 +28,8 @@ import android.content.Intent
|
||||
import android.util.Log
|
||||
import android.widget.RemoteViews
|
||||
import me.kavishdevar.librepods.R
|
||||
import me.kavishdevar.librepods.services.ServiceManager
|
||||
import me.kavishdevar.librepods.bluetooth.AACPManager
|
||||
import me.kavishdevar.librepods.services.ServiceManager
|
||||
import kotlin.io.encoding.ExperimentalEncodingApi
|
||||
|
||||
class NoiseControlWidget : AppWidgetProvider() {
|
||||
@@ -82,8 +82,14 @@ class NoiseControlWidget : AppWidgetProvider() {
|
||||
if (intent.action == "ACTION_SET_ANC_MODE") {
|
||||
val mode = intent.getIntExtra("ANC_MODE", 1)
|
||||
Log.d("NoiseControlWidget", "Setting ANC mode to $mode")
|
||||
ServiceManager.getService()!!
|
||||
.aacpManager
|
||||
val service = ServiceManager.getService()
|
||||
|
||||
if (service == null) {
|
||||
Log.w("NoiseControlWidget", "Service unavailable")
|
||||
return
|
||||
}
|
||||
|
||||
service.aacpManager
|
||||
.sendControlCommand(
|
||||
AACPManager.Companion.ControlCommandIdentifiers.LISTENING_MODE.value,
|
||||
mode.toByte()
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
@file:OptIn(ExperimentalEncodingApi::class) @file:Suppress("DEPRECATION")
|
||||
@file:OptIn(ExperimentalEncodingApi::class)
|
||||
|
||||
package me.kavishdevar.librepods.services
|
||||
|
||||
@@ -58,7 +58,7 @@ import android.os.ParcelUuid
|
||||
import android.os.UserHandle
|
||||
import android.provider.Settings
|
||||
import android.telecom.TelecomManager
|
||||
import android.telephony.PhoneStateListener
|
||||
import android.telephony.TelephonyCallback
|
||||
import android.telephony.TelephonyManager
|
||||
import android.util.Log
|
||||
import android.util.TypedValue
|
||||
@@ -126,6 +126,7 @@ import me.kavishdevar.librepods.utils.SystemApisUtils.METADATA_UNTETHERED_RIGHT_
|
||||
import me.kavishdevar.librepods.utils.SystemApisUtils.METADATA_UNTETHERED_RIGHT_LOW_BATTERY_THRESHOLD
|
||||
import java.nio.ByteBuffer
|
||||
import java.nio.ByteOrder
|
||||
import java.time.LocalDateTime
|
||||
import kotlin.io.encoding.Base64
|
||||
import kotlin.io.encoding.ExperimentalEncodingApi
|
||||
|
||||
@@ -222,7 +223,7 @@ class AirPodsService : Service(), SharedPreferences.OnSharedPreferenceChangeList
|
||||
val packetLogsFlow: StateFlow<Set<String>> get() = _packetLogsFlow
|
||||
|
||||
private lateinit var telephonyManager: TelephonyManager
|
||||
private lateinit var phoneStateListener: PhoneStateListener
|
||||
private lateinit var phoneStateListener: TelephonyCallback
|
||||
private val maxLogEntries = 1000
|
||||
private val inMemoryLogs = mutableSetOf<String>()
|
||||
|
||||
@@ -361,7 +362,7 @@ class AirPodsService : Service(), SharedPreferences.OnSharedPreferenceChangeList
|
||||
}
|
||||
|
||||
|
||||
@SuppressLint("MissingPermission", "UnspecifiedRegisterReceiverFlag")
|
||||
@SuppressLint("MissingPermission", "UnspecifiedRegisterReceiverFlag", "HardwareIds")
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
Log.i(TAG, "lib exempt worked: ${isBluetoothSocketExempted()}")
|
||||
@@ -383,7 +384,11 @@ class AirPodsService : Service(), SharedPreferences.OnSharedPreferenceChangeList
|
||||
|
||||
localMac = config.selfMacAddress
|
||||
if (localMac.isEmpty()) {
|
||||
if (BuildConfig.FLAVOR == "xposed") {
|
||||
if (checkSelfPermission("android.permission.LOCAL_MAC_ADDRESS") == PackageManager.PERMISSION_GRANTED) {
|
||||
val bluetoothManager = getSystemService(BluetoothManager::class.java)
|
||||
val bluetoothAdapter = bluetoothManager.adapter
|
||||
localMac = bluetoothAdapter.address
|
||||
} else {
|
||||
localMac = try {
|
||||
val process = Runtime.getRuntime().exec(
|
||||
arrayOf("su", "-c", "settings get secure bluetooth_address")
|
||||
@@ -522,7 +527,7 @@ class AirPodsService : Service(), SharedPreferences.OnSharedPreferenceChangeList
|
||||
|
||||
initializeConfig()
|
||||
|
||||
ancModeReceiver = object : BroadcastReceiver() {
|
||||
externalBroadcastReceiver = object : BroadcastReceiver() {
|
||||
override fun onReceive(context: Context?, intent: Intent?) {
|
||||
if (intent?.action == "me.kavishdevar.librepods.SET_ANC_MODE") {
|
||||
if (intent.hasExtra("mode")) {
|
||||
@@ -535,28 +540,12 @@ class AirPodsService : Service(), SharedPreferences.OnSharedPreferenceChangeList
|
||||
}
|
||||
} else {
|
||||
val currentMode = ancNotification.status
|
||||
val configByte = sharedPreferences.getInt("long_press_byte", 0b0111)
|
||||
val allowOffModeValue =
|
||||
aacpManager.controlCommandStatusList.find { it.identifier == AACPManager.Companion.ControlCommandIdentifiers.ALLOW_OFF_OPTION }
|
||||
val allowOffMode = allowOffModeValue?.value?.takeIf { it.isNotEmpty() }
|
||||
?.get(0) == 0x01.toByte()
|
||||
|
||||
val nextMode = if (allowOffMode) {
|
||||
when (currentMode) {
|
||||
1 -> 2
|
||||
2 -> 3
|
||||
3 -> 4
|
||||
4 -> 1
|
||||
else -> 1
|
||||
}
|
||||
} else {
|
||||
when (currentMode) {
|
||||
1 -> 2
|
||||
2 -> 3
|
||||
3 -> 4
|
||||
4 -> 2
|
||||
else -> 2
|
||||
}
|
||||
}
|
||||
val allowOffMode =
|
||||
allowOffModeValue?.value?.takeIf { it.isNotEmpty() }?.get(0) == 0x01.toByte() || sharedPreferences.getBoolean("off_listening_mode", true)
|
||||
val nextMode = getNextMode(currentMode = currentMode, configByte = configByte, allowOffMode)
|
||||
|
||||
aacpManager.sendControlCommand(
|
||||
AACPManager.Companion.ControlCommandIdentifiers.LISTENING_MODE.value,
|
||||
@@ -564,7 +553,15 @@ class AirPodsService : Service(), SharedPreferences.OnSharedPreferenceChangeList
|
||||
)
|
||||
Log.d(
|
||||
TAG,
|
||||
"Cycling ANC mode from $currentMode to $nextMode (offListeningMode: $allowOffMode)"
|
||||
"Cycling ANC mode from $currentMode to $nextMode"
|
||||
)
|
||||
}
|
||||
} else if (intent?.action == "me.kavishdevar.librepods.CONVO_DETECT") {
|
||||
if (intent.hasExtra("enabled")) {
|
||||
val enabled = intent.getBooleanExtra("enabled", false)
|
||||
aacpManager.sendControlCommand(
|
||||
AACPManager.Companion.ControlCommandIdentifiers.CONVERSATION_DETECT_CONFIG.value,
|
||||
enabled
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -572,10 +569,10 @@ class AirPodsService : Service(), SharedPreferences.OnSharedPreferenceChangeList
|
||||
}
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||
registerReceiver(ancModeReceiver, ancModeFilter, RECEIVER_EXPORTED)
|
||||
registerReceiver(externalBroadcastReceiver, externalBroadcastFilter, RECEIVER_EXPORTED)
|
||||
} else {
|
||||
@Suppress("UnspecifiedRegisterReceiverFlag") registerReceiver(
|
||||
ancModeReceiver, ancModeFilter
|
||||
externalBroadcastReceiver, externalBroadcastFilter
|
||||
)
|
||||
}
|
||||
val audioManager = this@AirPodsService.getSystemService(AUDIO_SERVICE) as AudioManager
|
||||
@@ -594,10 +591,8 @@ class AirPodsService : Service(), SharedPreferences.OnSharedPreferenceChangeList
|
||||
macAddress = sharedPreferences.getString("mac_address", "") ?: ""
|
||||
|
||||
telephonyManager = getSystemService(TELEPHONY_SERVICE) as TelephonyManager
|
||||
phoneStateListener = object : PhoneStateListener() {
|
||||
@Deprecated("Deprecated in Java")
|
||||
override fun onCallStateChanged(state: Int, phoneNumber: String?) {
|
||||
super.onCallStateChanged(state, phoneNumber)
|
||||
phoneStateListener = object: TelephonyCallback(), TelephonyCallback.CallStateListener {
|
||||
override fun onCallStateChanged(state: Int) {
|
||||
when (state) {
|
||||
TelephonyManager.CALL_STATE_RINGING -> {
|
||||
val leAvailableForAudio =
|
||||
@@ -607,7 +602,6 @@ class AirPodsService : Service(), SharedPreferences.OnSharedPreferenceChangeList
|
||||
takeOver("call")
|
||||
}
|
||||
if (config.headGestures) {
|
||||
callNumber = phoneNumber
|
||||
handleIncomingCall()
|
||||
}
|
||||
}
|
||||
@@ -626,13 +620,14 @@ class AirPodsService : Service(), SharedPreferences.OnSharedPreferenceChangeList
|
||||
|
||||
TelephonyManager.CALL_STATE_IDLE -> {
|
||||
isInCall = false
|
||||
callNumber = null
|
||||
gestureDetector?.stopDetection()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
telephonyManager.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE)
|
||||
if (checkSelfPermission("android.permission.READ_PHONE_STATE") == PackageManager.PERMISSION_GRANTED) {
|
||||
telephonyManager.registerTelephonyCallback(mainExecutor, phoneStateListener)
|
||||
}
|
||||
|
||||
if (config.showPhoneBatteryInWidget) {
|
||||
widgetMobileBatteryEnabled = true
|
||||
@@ -842,7 +837,7 @@ class AirPodsService : Service(), SharedPreferences.OnSharedPreferenceChangeList
|
||||
) || (cameraActive && config.cameraAction == StemPressType.LONG_PRESS)
|
||||
Log.d(
|
||||
TAG,
|
||||
"Setting up stem actions: " + "Single Press Customized: $singlePressCustomized, " + "Double Press Customized: $doublePressCustomized, " + "Triple Press Customized: $triplePressCustomized, " + "Long Press Customized: $longPressCustomized"
|
||||
"Setting up stem actions: Single Press Customized: $singlePressCustomized, Double Press Customized: $doublePressCustomized, Triple Press Customized: $triplePressCustomized, Long Press Customized: $longPressCustomized"
|
||||
)
|
||||
aacpManager.sendStemConfigPacket(
|
||||
singlePressCustomized,
|
||||
@@ -913,7 +908,7 @@ class AirPodsService : Service(), SharedPreferences.OnSharedPreferenceChangeList
|
||||
|
||||
if (conversationAwarenessNotification.status == 1.toByte() || conversationAwarenessNotification.status == 2.toByte()) {
|
||||
MediaController.startSpeaking()
|
||||
} else if (conversationAwarenessNotification.status == 8.toByte() || conversationAwarenessNotification.status == 9.toByte()) {
|
||||
} else if (conversationAwarenessNotification.status == 6.toByte() ||conversationAwarenessNotification.status == 8.toByte() || conversationAwarenessNotification.status == 9.toByte()) {
|
||||
MediaController.stopSpeaking()
|
||||
}
|
||||
|
||||
@@ -1062,6 +1057,7 @@ class AirPodsService : Service(), SharedPreferences.OnSharedPreferenceChangeList
|
||||
version2 = config.airpodsVersion2,
|
||||
version3 = config.airpodsVersion3,
|
||||
)
|
||||
if (device != null) setMetadatas(device!!)
|
||||
}
|
||||
sendBroadcast(
|
||||
Intent(AirPodsNotifications.AIRPODS_INFORMATION_UPDATED).setPackage(
|
||||
@@ -1113,7 +1109,7 @@ class AirPodsService : Service(), SharedPreferences.OnSharedPreferenceChangeList
|
||||
"AirPodsParser",
|
||||
"Audio source changed mac: ${aacpManager.audioSource?.mac}, type: ${aacpManager.audioSource?.type?.name}"
|
||||
)
|
||||
if (aacpManager.audioSource?.type != AACPManager.Companion.AudioSourceType.NONE && aacpManager.audioSource?.mac != localMac) {
|
||||
if (localMac!="" && (aacpManager.audioSource?.type != AACPManager.Companion.AudioSourceType.NONE && aacpManager.audioSource?.mac != localMac)) {
|
||||
Log.d(
|
||||
"AirPodsParser",
|
||||
"Audio source is another device, better to give up aacp control"
|
||||
@@ -1269,6 +1265,14 @@ class AirPodsService : Service(), SharedPreferences.OnSharedPreferenceChangeList
|
||||
disconnectAudio(this@AirPodsService, device)
|
||||
}
|
||||
}
|
||||
val wasNone = inEarData == listOf(false, false)
|
||||
val nowSingle = newInEarData.count { it } == 1
|
||||
|
||||
if (wasNone && nowSingle) {
|
||||
MediaController.sendPlay()
|
||||
MediaController.iPausedTheMedia = false
|
||||
return
|
||||
}
|
||||
|
||||
if (inEarData.contains(false) && newInEarData == listOf(true, true)) {
|
||||
Log.d("AirPodsParser", "User put in both AirPods from just one.")
|
||||
@@ -1641,6 +1645,9 @@ class AirPodsService : Service(), SharedPreferences.OnSharedPreferenceChangeList
|
||||
|
||||
var popupShown = false
|
||||
fun showPopup(service: Service, name: String) {
|
||||
if (!sharedPreferences.getBoolean("show_bottom_sheet_popup", true)) {
|
||||
return
|
||||
}
|
||||
if (!Settings.canDrawOverlays(service)) {
|
||||
Log.d(TAG, "No permission for SYSTEM_ALERT_WINDOW")
|
||||
return
|
||||
@@ -1665,6 +1672,9 @@ class AirPodsService : Service(), SharedPreferences.OnSharedPreferenceChangeList
|
||||
otherDeviceName: String? = null
|
||||
) {
|
||||
Log.d(TAG, "Showing island window")
|
||||
if (!sharedPreferences.getBoolean("show_island_popup", true)) {
|
||||
return
|
||||
}
|
||||
if (!Settings.canDrawOverlays(service)) {
|
||||
Log.d(TAG, "No permission for SYSTEM_ALERT_WINDOW")
|
||||
return
|
||||
@@ -1714,7 +1724,7 @@ class AirPodsService : Service(), SharedPreferences.OnSharedPreferenceChangeList
|
||||
val disconnectedNotificationChannel = NotificationChannel(
|
||||
"background_service_status",
|
||||
"Background Service Status",
|
||||
NotificationManager.IMPORTANCE_LOW
|
||||
NotificationManager.IMPORTANCE_NONE
|
||||
)
|
||||
|
||||
val connectedNotificationChannel = NotificationChannel(
|
||||
@@ -1805,6 +1815,7 @@ class AirPodsService : Service(), SharedPreferences.OnSharedPreferenceChangeList
|
||||
}
|
||||
|
||||
fun sendBatteryBroadcast() {
|
||||
broadcastBatteryInformation()
|
||||
sendBroadcast(Intent(AirPodsNotifications.BATTERY_DATA).apply {
|
||||
putParcelableArrayListExtra("data", ArrayList(batteryNotification.getBattery()))
|
||||
setPackage(packageName)
|
||||
@@ -1821,47 +1832,51 @@ class AirPodsService : Service(), SharedPreferences.OnSharedPreferenceChangeList
|
||||
}
|
||||
|
||||
fun setBatteryMetadata() {
|
||||
if (BuildConfig.FLAVOR != "xposed") return
|
||||
device?.let { it ->
|
||||
SystemApisUtils.setMetadata(
|
||||
it,
|
||||
it.METADATA_UNTETHERED_CASE_BATTERY,
|
||||
batteryNotification.getBattery()
|
||||
.find { it.component == BatteryComponent.CASE }?.level.toString().toByteArray()
|
||||
)
|
||||
SystemApisUtils.setMetadata(
|
||||
it,
|
||||
it.METADATA_UNTETHERED_CASE_CHARGING,
|
||||
(if (batteryNotification.getBattery()
|
||||
.find { it.component == BatteryComponent.CASE }?.status == BatteryStatus.CHARGING
|
||||
) "1".toByteArray() else "0".toByteArray())
|
||||
)
|
||||
SystemApisUtils.setMetadata(
|
||||
it,
|
||||
it.METADATA_UNTETHERED_LEFT_BATTERY,
|
||||
batteryNotification.getBattery()
|
||||
.find { it.component == BatteryComponent.LEFT }?.level.toString().toByteArray()
|
||||
)
|
||||
SystemApisUtils.setMetadata(
|
||||
it,
|
||||
it.METADATA_UNTETHERED_LEFT_CHARGING,
|
||||
(if (batteryNotification.getBattery()
|
||||
.find { it.component == BatteryComponent.LEFT }?.status == BatteryStatus.CHARGING
|
||||
) "1".toByteArray() else "0".toByteArray())
|
||||
)
|
||||
SystemApisUtils.setMetadata(
|
||||
it,
|
||||
it.METADATA_UNTETHERED_RIGHT_BATTERY,
|
||||
batteryNotification.getBattery()
|
||||
.find { it.component == BatteryComponent.RIGHT }?.level.toString().toByteArray()
|
||||
)
|
||||
SystemApisUtils.setMetadata(
|
||||
it,
|
||||
it.METADATA_UNTETHERED_RIGHT_CHARGING,
|
||||
(if (batteryNotification.getBattery()
|
||||
.find { it.component == BatteryComponent.RIGHT }?.status == BatteryStatus.CHARGING
|
||||
) "1".toByteArray() else "0".toByteArray())
|
||||
)
|
||||
if (checkSelfPermission("android.permission.BLUETOOTH_PRIVILEGED") != PackageManager.PERMISSION_GRANTED) {
|
||||
device?.let { it ->
|
||||
SystemApisUtils.setMetadata(
|
||||
it,
|
||||
it.METADATA_UNTETHERED_CASE_BATTERY,
|
||||
batteryNotification.getBattery()
|
||||
.find { it.component == BatteryComponent.CASE }?.level.toString()
|
||||
.toByteArray()
|
||||
)
|
||||
SystemApisUtils.setMetadata(
|
||||
it,
|
||||
it.METADATA_UNTETHERED_CASE_CHARGING,
|
||||
(if (batteryNotification.getBattery()
|
||||
.find { it.component == BatteryComponent.CASE }?.status == BatteryStatus.CHARGING
|
||||
) "1".toByteArray() else "0".toByteArray())
|
||||
)
|
||||
SystemApisUtils.setMetadata(
|
||||
it,
|
||||
it.METADATA_UNTETHERED_LEFT_BATTERY,
|
||||
batteryNotification.getBattery()
|
||||
.find { it.component == BatteryComponent.LEFT }?.level.toString()
|
||||
.toByteArray()
|
||||
)
|
||||
SystemApisUtils.setMetadata(
|
||||
it,
|
||||
it.METADATA_UNTETHERED_LEFT_CHARGING,
|
||||
(if (batteryNotification.getBattery()
|
||||
.find { it.component == BatteryComponent.LEFT }?.status == BatteryStatus.CHARGING
|
||||
) "1".toByteArray() else "0".toByteArray())
|
||||
)
|
||||
SystemApisUtils.setMetadata(
|
||||
it,
|
||||
it.METADATA_UNTETHERED_RIGHT_BATTERY,
|
||||
batteryNotification.getBattery()
|
||||
.find { it.component == BatteryComponent.RIGHT }?.level.toString()
|
||||
.toByteArray()
|
||||
)
|
||||
SystemApisUtils.setMetadata(
|
||||
it,
|
||||
it.METADATA_UNTETHERED_RIGHT_CHARGING,
|
||||
(if (batteryNotification.getBattery()
|
||||
.find { it.component == BatteryComponent.RIGHT }?.status == BatteryStatus.CHARGING
|
||||
) "1".toByteArray() else "0".toByteArray())
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1962,7 +1977,7 @@ class AirPodsService : Service(), SharedPreferences.OnSharedPreferenceChangeList
|
||||
val allowOffModeValue =
|
||||
aacpManager.controlCommandStatusList.find { it.identifier == AACPManager.Companion.ControlCommandIdentifiers.ALLOW_OFF_OPTION }
|
||||
val allowOffMode =
|
||||
allowOffModeValue?.value?.takeIf { it.isNotEmpty() }?.get(0) == 0x01.toByte()
|
||||
allowOffModeValue?.value?.takeIf { it.isNotEmpty() }?.get(0) == 0x01.toByte() || sharedPreferences.getBoolean("off_listening_mode", true)
|
||||
it.setInt(
|
||||
R.id.widget_off_button,
|
||||
"setBackgroundResource",
|
||||
@@ -2012,7 +2027,6 @@ class AirPodsService : Service(), SharedPreferences.OnSharedPreferenceChangeList
|
||||
connected: Boolean, airpodsName: String? = null, batteryList: List<Battery>? = null
|
||||
) {
|
||||
val notificationManager = getSystemService(NotificationManager::class.java)
|
||||
var updatedNotification: Notification?
|
||||
|
||||
val notificationIntent = Intent(this, MainActivity::class.java)
|
||||
val pendingIntent = PendingIntent.getActivity(
|
||||
@@ -2072,13 +2086,6 @@ class AirPodsService : Service(), SharedPreferences.OnSharedPreferenceChangeList
|
||||
notificationManager.notify(2, updatedNotification)
|
||||
notificationManager.cancel(1)
|
||||
} else if (!connected) {
|
||||
updatedNotification = NotificationCompat.Builder(this, "background_service_status")
|
||||
.setSmallIcon(R.drawable.airpods).setContentTitle("AirPods not connected")
|
||||
.setContentText("Tap to open app").setContentIntent(pendingIntent)
|
||||
.setCategory(Notification.CATEGORY_SERVICE)
|
||||
.setPriority(NotificationCompat.PRIORITY_LOW).setOngoing(true).build()
|
||||
|
||||
notificationManager.notify(1, updatedNotification)
|
||||
notificationManager.cancel(2)
|
||||
} else if (!config.bleOnlyMode && !socket.isConnected) {
|
||||
showSocketConnectionFailureNotification("Socket created, but not connected. Check logs")
|
||||
@@ -2108,7 +2115,7 @@ class AirPodsService : Service(), SharedPreferences.OnSharedPreferenceChangeList
|
||||
return suspendCancellableCoroutine { continuation ->
|
||||
gestureDetector?.startDetection(doNotStop = true) { accepted ->
|
||||
if (continuation.isActive) {
|
||||
continuation.resume(accepted) {
|
||||
continuation.resume(accepted) { _, _, _ ->
|
||||
gestureDetector?.stopDetection()
|
||||
}
|
||||
}
|
||||
@@ -2121,7 +2128,7 @@ class AirPodsService : Service(), SharedPreferences.OnSharedPreferenceChangeList
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||
val telecomManager = getSystemService(TELECOM_SERVICE) as TelecomManager
|
||||
if (checkSelfPermission(Manifest.permission.ANSWER_PHONE_CALLS) == PackageManager.PERMISSION_GRANTED) {
|
||||
telecomManager.acceptRingingCall()
|
||||
telecomManager.acceptRingingCall() // TODO: Switch to InCallService (needs CDM association)
|
||||
}
|
||||
} else {
|
||||
val telephonyService = getSystemService(TELEPHONY_SERVICE) as TelephonyManager
|
||||
@@ -2148,7 +2155,7 @@ class AirPodsService : Service(), SharedPreferences.OnSharedPreferenceChangeList
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||
val telecomManager = getSystemService(TELECOM_SERVICE) as TelecomManager
|
||||
if (checkSelfPermission(Manifest.permission.ANSWER_PHONE_CALLS) == PackageManager.PERMISSION_GRANTED) {
|
||||
telecomManager.endCall()
|
||||
telecomManager.endCall() // TODO: Switch to InCallService (needs CDM association)
|
||||
}
|
||||
} else {
|
||||
val telephonyService = getSystemService(TELEPHONY_SERVICE) as TelephonyManager
|
||||
@@ -2221,9 +2228,9 @@ class AirPodsService : Service(), SharedPreferences.OnSharedPreferenceChangeList
|
||||
@Suppress("PrivatePropertyName")
|
||||
private val ACTION_ASI_UPDATE_BLUETOOTH_DATA = "batterywidget.impl.action.update_bluetooth_data"
|
||||
|
||||
@Suppress("MissingPermission", "unused")
|
||||
@SuppressLint("MissingPermission")
|
||||
fun broadcastBatteryInformation() {
|
||||
if (device == null) return
|
||||
if (device == null || checkSelfPermission("android.permission.INTERACT_ACROSS_USERS") != PackageManager.PERMISSION_GRANTED) return
|
||||
|
||||
val batteryList = batteryNotification.getBattery()
|
||||
val leftBattery = batteryList.find { it.component == BatteryComponent.LEFT }
|
||||
@@ -2307,7 +2314,11 @@ class AirPodsService : Service(), SharedPreferences.OnSharedPreferenceChangeList
|
||||
}
|
||||
|
||||
private fun setMetadatas(d: BluetoothDevice) {
|
||||
if (BuildConfig.FLAVOR != "xposed") return
|
||||
if (checkSelfPermission("android.permission.BLUETOOTH_PRIVILEGED") != PackageManager.PERMISSION_GRANTED) {
|
||||
Log.d(TAG, "no permission BLUETOOTH_PRIVILEGED, returning")
|
||||
return
|
||||
}
|
||||
Log.d(TAG, "has permission BLUETOOTH_PRIVILEGED, proceeding")
|
||||
d.let { device ->
|
||||
val instance = airpodsInstance
|
||||
if (instance != null) {
|
||||
@@ -2377,7 +2388,7 @@ class AirPodsService : Service(), SharedPreferences.OnSharedPreferenceChangeList
|
||||
val context = context?.applicationContext
|
||||
val name = context?.getSharedPreferences("settings", MODE_PRIVATE)
|
||||
?.getString("name", bluetoothDevice?.name)
|
||||
if (bluetoothDevice != null && action != null && !action.isEmpty()) {
|
||||
if (bluetoothDevice != null && !action.isNullOrEmpty()) {
|
||||
Log.d(TAG, "Received bluetooth connection broadcast: action=$action")
|
||||
if (BluetoothDevice.ACTION_ACL_CONNECTED == action) {
|
||||
val uuid = ParcelUuid.fromString("74ec2172-0bad-4d01-8f77-997b2be0722a")
|
||||
@@ -2395,8 +2406,11 @@ class AirPodsService : Service(), SharedPreferences.OnSharedPreferenceChangeList
|
||||
}
|
||||
}
|
||||
|
||||
val ancModeFilter = IntentFilter("me.kavishdevar.librepods.SET_ANC_MODE")
|
||||
var ancModeReceiver: BroadcastReceiver? = null
|
||||
val externalBroadcastFilter = IntentFilter().apply {
|
||||
addAction("me.kavishdevar.librepods.SET_ANC_MODE")
|
||||
addAction("me.kavishdevar.librepods.CONVO_DETECT")
|
||||
}
|
||||
var externalBroadcastReceiver: BroadcastReceiver? = null
|
||||
|
||||
@SuppressLint("InlinedApi", "MissingPermission", "UnspecifiedRegisterReceiverFlag")
|
||||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
||||
@@ -2434,16 +2448,13 @@ class AirPodsService : Service(), SharedPreferences.OnSharedPreferenceChangeList
|
||||
)
|
||||
otherDeviceTookOver = false
|
||||
}
|
||||
val ownsConnection = aacpManager.getControlCommandStatus(AACPManager.Companion.ControlCommandIdentifiers.OWNS_CONNECTION)?.value?.get(0)?.toInt()
|
||||
Log.d(
|
||||
TAG, "owns connection: ${
|
||||
aacpManager.getControlCommandStatus(AACPManager.Companion.ControlCommandIdentifiers.OWNS_CONNECTION)?.value?.get(
|
||||
0
|
||||
)?.toInt()
|
||||
}"
|
||||
TAG, "owns connection: $ownsConnection"
|
||||
)
|
||||
if (!::socket.isInitialized) return
|
||||
if (socket.isConnected) {
|
||||
if (BuildConfig.FLAVOR != "xposed") {
|
||||
if (!XposedRemotePrefProvider.create().getBoolean("vendor_id_hook", false) || ownsConnection == 0) {
|
||||
Log.d(TAG, "not taking over, vendorid is probably not set to apple")
|
||||
return
|
||||
}
|
||||
@@ -2693,6 +2704,7 @@ class AirPodsService : Service(), SharedPreferences.OnSharedPreferenceChangeList
|
||||
version2 = config.airpodsVersion2,
|
||||
version3 = config.airpodsVersion3,
|
||||
)
|
||||
setMetadatas(device)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2700,7 +2712,18 @@ class AirPodsService : Service(), SharedPreferences.OnSharedPreferenceChangeList
|
||||
true, config.deviceName, batteryNotification.getBattery()
|
||||
)
|
||||
Log.d(TAG, "<LogCollector:Complete:Success> Socket connected")
|
||||
sharedPreferences.edit { putBoolean("connection_successful", true) }
|
||||
if (!sharedPreferences.contains("first_connection_successful_time")) {
|
||||
sharedPreferences.edit {
|
||||
putLong(
|
||||
"first_connection_successful_time",
|
||||
System.currentTimeMillis()
|
||||
)
|
||||
}
|
||||
}
|
||||
sendBroadcast(Intent(AirPodsNotifications.AIRPODS_L2CAP_CONNECTED))
|
||||
} catch (e: Exception) {
|
||||
// sharedPreferences.edit { putBoolean("connection_successful", false) }
|
||||
Log.d(
|
||||
TAG, "<LogCollector:Complete:Failed> Socket not connected, ${e.message}"
|
||||
)
|
||||
@@ -2763,33 +2786,43 @@ class AirPodsService : Service(), SharedPreferences.OnSharedPreferenceChangeList
|
||||
|
||||
while (socket.isConnected) {
|
||||
socket.let { it ->
|
||||
val buffer = ByteArray(1024)
|
||||
val bytesRead = it.inputStream.read(buffer)
|
||||
var data: ByteArray
|
||||
if (bytesRead > 0) {
|
||||
data = buffer.copyOfRange(0, bytesRead)
|
||||
sendBroadcast(Intent(AirPodsNotifications.AIRPODS_DATA).apply {
|
||||
putExtra("data", buffer.copyOfRange(0, bytesRead))
|
||||
setPackage(packageName)
|
||||
})
|
||||
val bytes = buffer.copyOfRange(0, bytesRead)
|
||||
val formattedHex = bytes.joinToString(" ") { "%02X".format(it) }
|
||||
try {
|
||||
val buffer = ByteArray(1024)
|
||||
val bytesRead = it.inputStream.read(buffer)
|
||||
var data: ByteArray
|
||||
if (bytesRead > 0) {
|
||||
data = buffer.copyOfRange(0, bytesRead)
|
||||
sendBroadcast(Intent(AirPodsNotifications.AIRPODS_DATA).apply {
|
||||
putExtra("data", buffer.copyOfRange(0, bytesRead))
|
||||
setPackage(packageName)
|
||||
})
|
||||
val bytes = buffer.copyOfRange(0, bytesRead)
|
||||
val formattedHex = bytes.joinToString(" ") { "%02X".format(it) }
|
||||
// CrossDevice.sendReceivedPacket(bytes)
|
||||
updateNotificationContent(
|
||||
true,
|
||||
sharedPreferences.getString("name", device.name),
|
||||
batteryNotification.getBattery()
|
||||
)
|
||||
updateNotificationContent(
|
||||
true,
|
||||
sharedPreferences.getString("name", device.name),
|
||||
batteryNotification.getBattery()
|
||||
)
|
||||
|
||||
aacpManager.receivePacket(data)
|
||||
aacpManager.receivePacket(data)
|
||||
|
||||
if (!isHeadTrackingData(data)) {
|
||||
Log.d("AirPodsData", "Data received: $formattedHex")
|
||||
logPacket(data, "AirPods")
|
||||
if (!isHeadTrackingData(data)) {
|
||||
Log.d("AirPodsData", "Data received: $formattedHex")
|
||||
logPacket(data, "AirPods")
|
||||
}
|
||||
|
||||
} else if (bytesRead == -1) {
|
||||
Log.d("AirPods Service", "Socket closed (bytesRead = -1)")
|
||||
sendBroadcast(Intent(AirPodsNotifications.AIRPODS_DISCONNECTED).apply {
|
||||
setPackage(packageName)
|
||||
})
|
||||
aacpManager.disconnected()
|
||||
return@launch
|
||||
}
|
||||
|
||||
} else if (bytesRead == -1) {
|
||||
Log.d("AirPods Service", "Socket closed (bytesRead = -1)")
|
||||
} catch (e: Exception) {
|
||||
Log.w(TAG, "Error reading data, we have probably disconnected.")
|
||||
e.printStackTrace()
|
||||
sendBroadcast(Intent(AirPodsNotifications.AIRPODS_DISCONNECTED).apply {
|
||||
setPackage(packageName)
|
||||
})
|
||||
@@ -2865,21 +2898,42 @@ class AirPodsService : Service(), SharedPreferences.OnSharedPreferenceChangeList
|
||||
})
|
||||
|
||||
val bluetoothAdapter = getSystemService(BluetoothManager::class.java).adapter
|
||||
bluetoothAdapter.getProfileProxy(this, object : BluetoothProfile.ServiceListener {
|
||||
override fun onServiceConnected(profile: Int, proxy: BluetoothProfile) {
|
||||
if (profile == BluetoothProfile.A2DP) {
|
||||
val connectedDevices = proxy.connectedDevices
|
||||
if (connectedDevices.isNotEmpty()) {
|
||||
MediaController.sendPause()
|
||||
if (checkSelfPermission("android.permission.BLUETOOTH_PRIVILEGED") == PackageManager.PERMISSION_GRANTED){
|
||||
bluetoothAdapter.getProfileProxy(this, object : BluetoothProfile.ServiceListener {
|
||||
override fun onServiceConnected(profile: Int, proxy: BluetoothProfile) {
|
||||
if (profile == BluetoothProfile.A2DP) {
|
||||
val connectedDevices = proxy.connectedDevices
|
||||
if (connectedDevices.isNotEmpty()) {
|
||||
MediaController.sendPause()
|
||||
}
|
||||
}
|
||||
bluetoothAdapter.closeProfileProxy(profile, proxy)
|
||||
}
|
||||
bluetoothAdapter.closeProfileProxy(profile, proxy)
|
||||
|
||||
override fun onServiceDisconnected(profile: Int) {}
|
||||
}, BluetoothProfile.A2DP)
|
||||
try {
|
||||
device?.disconnect()
|
||||
} catch (e: Exception) {
|
||||
Log.w(TAG, "device.disconnect() failed, $e")
|
||||
}
|
||||
}
|
||||
if (checkSelfPermission("android.permission.MODIFY_PHONE_STATE") == PackageManager.PERMISSION_GRANTED){
|
||||
bluetoothAdapter.getProfileProxy(this, object : BluetoothProfile.ServiceListener {
|
||||
override fun onServiceConnected(profile: Int, proxy: BluetoothProfile) {
|
||||
if (profile == BluetoothProfile.HEADSET) {
|
||||
val connectedDevices = proxy.connectedDevices
|
||||
if (connectedDevices.isNotEmpty()) {
|
||||
MediaController.sendPause()
|
||||
}
|
||||
}
|
||||
bluetoothAdapter.closeProfileProxy(profile, proxy)
|
||||
}
|
||||
|
||||
override fun onServiceDisconnected(profile: Int) {}
|
||||
}, BluetoothProfile.A2DP)
|
||||
override fun onServiceDisconnected(profile: Int) {}
|
||||
}, BluetoothProfile.HEADSET)
|
||||
}
|
||||
Log.d(TAG, "Disconnected AirPods upon user request")
|
||||
|
||||
}
|
||||
|
||||
val earDetectionNotification = AirPodsNotifications.EarDetection()
|
||||
@@ -2912,47 +2966,59 @@ class AirPodsService : Service(), SharedPreferences.OnSharedPreferenceChangeList
|
||||
|
||||
fun disconnectAudio(context: Context, device: BluetoothDevice?) {
|
||||
val bluetoothAdapter = context.getSystemService(BluetoothManager::class.java).adapter
|
||||
bluetoothAdapter?.getProfileProxy(context, object : BluetoothProfile.ServiceListener {
|
||||
override fun onServiceConnected(profile: Int, proxy: BluetoothProfile) {
|
||||
if (profile == BluetoothProfile.A2DP) {
|
||||
try {
|
||||
if (proxy.getConnectionState(device) == BluetoothProfile.STATE_DISCONNECTED) {
|
||||
Log.d(TAG, "Already disconnected from A2DP")
|
||||
return
|
||||
if (checkSelfPermission("android.permission.BLUETOOTH_PRIVILEGED") == PackageManager.PERMISSION_GRANTED) {
|
||||
bluetoothAdapter?.getProfileProxy(context, object : BluetoothProfile.ServiceListener {
|
||||
override fun onServiceConnected(profile: Int, proxy: BluetoothProfile) {
|
||||
if (profile == BluetoothProfile.A2DP) {
|
||||
try {
|
||||
if (proxy.getConnectionState(device) == BluetoothProfile.STATE_DISCONNECTED) {
|
||||
Log.d(TAG, "Already disconnected from A2DP")
|
||||
return
|
||||
}
|
||||
val method = proxy.javaClass.getMethod(
|
||||
"setConnectionPolicy", BluetoothDevice::class.java, Int::class.java
|
||||
)
|
||||
Log.d(TAG, "calling A2DP.setConnectionPolicy for ${device?.address} to 0")
|
||||
method.invoke(proxy, device, 0)
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
} finally {
|
||||
bluetoothAdapter.closeProfileProxy(BluetoothProfile.A2DP, proxy)
|
||||
}
|
||||
val method = proxy.javaClass.getMethod(
|
||||
"setConnectionPolicy", BluetoothDevice::class.java, Int::class.java
|
||||
)
|
||||
method.invoke(proxy, device, 0)
|
||||
} catch (e: Exception) {
|
||||
Log.w(TAG, "we probably do not have BLUETOOTH_PRIVILEGED")
|
||||
} finally {
|
||||
bluetoothAdapter.closeProfileProxy(BluetoothProfile.A2DP, proxy)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onServiceDisconnected(profile: Int) {}
|
||||
}, BluetoothProfile.A2DP)
|
||||
// requires protected permission (MODIFY_PHONE_STATE)
|
||||
// bluetoothAdapter?.getProfileProxy(context, object : BluetoothProfile.ServiceListener {
|
||||
// override fun onServiceConnected(profile: Int, proxy: BluetoothProfile) {
|
||||
// if (profile == BluetoothProfile.HEADSET) {
|
||||
// try {
|
||||
// val method =
|
||||
// proxy.javaClass.getMethod("setConnectionPolicy", BluetoothDevice::class.java, Int::class.java)
|
||||
// method.invoke(proxy, device, 0)
|
||||
// } catch (e: Exception) {
|
||||
// e.printStackTrace()
|
||||
// } finally {
|
||||
// bluetoothAdapter.closeProfileProxy(BluetoothProfile.HEADSET, proxy)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// override fun onServiceDisconnected(profile: Int) {}
|
||||
// }, BluetoothProfile.HEADSET)
|
||||
override fun onServiceDisconnected(profile: Int) {}
|
||||
}, BluetoothProfile.A2DP)
|
||||
} else {
|
||||
Log.d(TAG, "not disconnecting A2DP, no BLUETOOTH_PRIVILEGED permission")
|
||||
}
|
||||
if (checkSelfPermission("android.permission.MODIFY_PHONE_STATE") == PackageManager.PERMISSION_GRANTED) {
|
||||
bluetoothAdapter?.getProfileProxy(context, object : BluetoothProfile.ServiceListener {
|
||||
override fun onServiceConnected(profile: Int, proxy: BluetoothProfile) {
|
||||
if (profile == BluetoothProfile.HEADSET) {
|
||||
try {
|
||||
val method =
|
||||
proxy.javaClass.getMethod(
|
||||
"setConnectionPolicy",
|
||||
BluetoothDevice::class.java,
|
||||
Int::class.java
|
||||
)
|
||||
Log.d(TAG, "calling HEADSET.setConnectionPolicy for ${device?.address} to 0")
|
||||
method.invoke(proxy, device, 0)
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
} finally {
|
||||
bluetoothAdapter.closeProfileProxy(BluetoothProfile.HEADSET, proxy)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onServiceDisconnected(profile: Int) {}
|
||||
}, BluetoothProfile.HEADSET)
|
||||
} else {
|
||||
Log.d(TAG, "not disconnecting HEADSET, no MODIFIY_PHONE_STATE permission")
|
||||
}
|
||||
}
|
||||
|
||||
fun connectAudio(context: Context, device: BluetoothDevice?) {
|
||||
@@ -2961,49 +3027,75 @@ class AirPodsService : Service(), SharedPreferences.OnSharedPreferenceChangeList
|
||||
bluetoothAdapter?.getProfileProxy(context, object : BluetoothProfile.ServiceListener {
|
||||
override fun onServiceConnected(profile: Int, proxy: BluetoothProfile) {
|
||||
if (profile == BluetoothProfile.A2DP) {
|
||||
try {
|
||||
val policyMethod = proxy.javaClass.getMethod(
|
||||
"setConnectionPolicy", BluetoothDevice::class.java, Int::class.java
|
||||
)
|
||||
policyMethod.invoke(proxy, device, 100)
|
||||
if (context.checkSelfPermission("android.permission.BLUETOOTH_PRIVILEGED") == PackageManager.PERMISSION_GRANTED) {
|
||||
try {
|
||||
val policyMethod = proxy.javaClass.getMethod(
|
||||
"setConnectionPolicy",
|
||||
BluetoothDevice::class.java,
|
||||
Int::class.java
|
||||
)
|
||||
Log.d(TAG, "calling A2DP.setConnectionPolicy for ${device?.address} to 100")
|
||||
policyMethod.invoke(proxy, device, 100)
|
||||
|
||||
val connectMethod =
|
||||
proxy.javaClass.getMethod("connect", BluetoothDevice::class.java)
|
||||
connectMethod.invoke(
|
||||
proxy, device
|
||||
)
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
} finally {
|
||||
bluetoothAdapter.closeProfileProxy(BluetoothProfile.A2DP, proxy)
|
||||
if (MediaController.pausedWhileTakingOver) {
|
||||
MediaController.sendPlay()
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
val connectMethod =
|
||||
proxy.javaClass.getMethod("connect", BluetoothDevice::class.java)
|
||||
connectMethod.invoke(
|
||||
proxy, device
|
||||
) // reduces the slight delay between allowing and actually connecting
|
||||
} catch (e: Exception) {
|
||||
Log.w(TAG, "we probably do not have BLUETOOTH_PRIVILEGED")
|
||||
} finally {
|
||||
bluetoothAdapter.closeProfileProxy(BluetoothProfile.A2DP, proxy)
|
||||
if (MediaController.pausedWhileTakingOver) {
|
||||
MediaController.sendPlay()
|
||||
}
|
||||
)
|
||||
Log.d(TAG, "not setting connection policy for A2DP, no BLUETOOTH_PRIVILEGED permission. just called connect")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onServiceDisconnected(profile: Int) {}
|
||||
}, BluetoothProfile.A2DP)
|
||||
// requires protected permission (MODIFY_PHONE_STATE)
|
||||
// bluetoothAdapter?.getProfileProxy(context, object : BluetoothProfile.ServiceListener {
|
||||
// override fun onServiceConnected(profile: Int, proxy: BluetoothProfile) {
|
||||
// if (profile == BluetoothProfile.HEADSET) {
|
||||
// try {
|
||||
// val policyMethod = proxy.javaClass.getMethod("setConnectionPolicy", BluetoothDevice::class.java, Int::class.java)
|
||||
// policyMethod.invoke(proxy, device, 100)
|
||||
// val connectMethod =
|
||||
// proxy.javaClass.getMethod("connect", BluetoothDevice::class.java)
|
||||
// connectMethod.invoke(proxy, device)
|
||||
// } catch (e: Exception) {
|
||||
// e.printStackTrace()
|
||||
// } finally {
|
||||
// bluetoothAdapter.closeProfileProxy(BluetoothProfile.HEADSET, proxy)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// override fun onServiceDisconnected(profile: Int) {}
|
||||
// }, BluetoothProfile.HEADSET)
|
||||
|
||||
bluetoothAdapter?.getProfileProxy(context, object : BluetoothProfile.ServiceListener {
|
||||
override fun onServiceConnected(profile: Int, proxy: BluetoothProfile) {
|
||||
if (profile == BluetoothProfile.HEADSET) {
|
||||
if (checkSelfPermission("android.permission.MODIFY_PHONE_STATE") == PackageManager.PERMISSION_GRANTED) {
|
||||
try {
|
||||
val policyMethod = proxy.javaClass.getMethod(
|
||||
"setConnectionPolicy",
|
||||
BluetoothDevice::class.java,
|
||||
Int::class.java
|
||||
)
|
||||
Log.d(
|
||||
TAG,
|
||||
"calling HEADSET.setConnectionPolicy for ${device?.address} to 100"
|
||||
)
|
||||
policyMethod.invoke(proxy, device, 100)
|
||||
val connectMethod =
|
||||
proxy.javaClass.getMethod("connect", BluetoothDevice::class.java)
|
||||
connectMethod.invoke(proxy, device)
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
} finally {
|
||||
bluetoothAdapter.closeProfileProxy(BluetoothProfile.HEADSET, proxy)
|
||||
}
|
||||
} else {
|
||||
Log.d(TAG, "not setting connection policy for HEADSET, no MODIFIY_PHONE_STATE permission")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onServiceDisconnected(profile: Int) {}
|
||||
}, BluetoothProfile.HEADSET)
|
||||
}
|
||||
|
||||
fun setName(name: String) {
|
||||
@@ -3011,6 +3103,7 @@ class AirPodsService : Service(), SharedPreferences.OnSharedPreferenceChangeList
|
||||
|
||||
if (config.deviceName != name) {
|
||||
config.deviceName = name
|
||||
device?.alias = name
|
||||
sharedPreferences.edit { putString("name", name) }
|
||||
}
|
||||
|
||||
@@ -3031,7 +3124,7 @@ class AirPodsService : Service(), SharedPreferences.OnSharedPreferenceChangeList
|
||||
e.printStackTrace()
|
||||
}
|
||||
try {
|
||||
unregisterReceiver(ancModeReceiver)
|
||||
unregisterReceiver(externalBroadcastReceiver)
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
@@ -3050,7 +3143,9 @@ class AirPodsService : Service(), SharedPreferences.OnSharedPreferenceChangeList
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
telephonyManager.listen(phoneStateListener, PhoneStateListener.LISTEN_NONE)
|
||||
if (checkSelfPermission("android.permission.READ_PHONE_STATE") == PackageManager.PERMISSION_GRANTED) {
|
||||
telephonyManager.unregisterTelephonyCallback(phoneStateListener)
|
||||
}
|
||||
// isConnectedLocally = false
|
||||
// CrossDevice.isAvailable = true
|
||||
super.onDestroy()
|
||||
@@ -3100,6 +3195,7 @@ class AirPodsService : Service(), SharedPreferences.OnSharedPreferenceChangeList
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
Log.d(TAG, "connecting to $macAddress")
|
||||
connectToSocket(bluetoothAdapter, device!!, manual = true)
|
||||
connectAudio(this@AirPodsService, device!!)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3113,3 +3209,20 @@ private fun Int.dpToPx(): Int {
|
||||
val density = Resources.getSystem().displayMetrics.density
|
||||
return (this * density).toInt()
|
||||
}
|
||||
|
||||
fun getNextMode(currentMode: Int, configByte: Int, offmodeEnabled: Boolean): Int {
|
||||
val enabledModes = buildList {
|
||||
if ((configByte and 0x01) != 0 && offmodeEnabled) add(1)
|
||||
if ((configByte and 0x04) != 0) add(3)
|
||||
if ((configByte and 0x08) != 0) add(4)
|
||||
if ((configByte and 0x02) != 0) add(2)
|
||||
}
|
||||
Log.d(TAG, "currentMode: $currentMode, config: ${configByte.toString(2)}")
|
||||
|
||||
if (enabledModes.isEmpty()) return currentMode
|
||||
|
||||
val currentIndex = enabledModes.indexOf(currentMode)
|
||||
val nextIndex = if (currentIndex == -1) 0 else (currentIndex + 1) % enabledModes.size
|
||||
|
||||
return enabledModes[nextIndex]
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ class KotlinModule: XposedModule() {
|
||||
log(Log.INFO, TAG, "framework: $frameworkName($frameworkVersionCode) API $apiVersion")
|
||||
}
|
||||
|
||||
@SuppressLint("UnsafeDynamicallyLoadedCode")
|
||||
override fun onPackageLoaded(param: PackageLoadedParam) {
|
||||
log(Log.INFO, TAG, "onPackageLoaded :: ${param.packageName}")
|
||||
|
||||
@@ -27,8 +28,36 @@ class KotlinModule: XposedModule() {
|
||||
log(Log.INFO, TAG, "Bluetooth app detected, hooking l2c_fcr_chk_chan_modes")
|
||||
try {
|
||||
if (param.isFirstPackage) {
|
||||
log(Log.INFO, TAG, "Loading native library for Bluetooth hook")
|
||||
System.loadLibrary("l2c_fcr_hook")
|
||||
val abi = android.os.Build.SUPPORTED_ABIS.first()
|
||||
val soName = "libl2c_fcr_hook.so"
|
||||
|
||||
val candidates = buildList {
|
||||
add("${moduleApplicationInfo.sourceDir}!/lib/$abi/$soName")
|
||||
|
||||
moduleApplicationInfo.splitSourceDirs?.forEach { split ->
|
||||
add("$split!/lib/$abi/$soName")
|
||||
}
|
||||
}
|
||||
|
||||
var loaded = false
|
||||
|
||||
for (path in candidates) {
|
||||
try {
|
||||
log(Log.INFO, TAG, "Trying to load native lib from $path")
|
||||
System.load(path)
|
||||
log(Log.INFO, TAG, "Loaded native lib from $path")
|
||||
loaded = true
|
||||
break
|
||||
} catch (e: Throwable) {
|
||||
log(Log.WARN, TAG, "Failed to load from $path: ${e.message}")
|
||||
}
|
||||
}
|
||||
|
||||
if (!loaded) {
|
||||
log(Log.ERROR, TAG, "Could not load $soName from base or splits")
|
||||
return
|
||||
}
|
||||
|
||||
val remotePrefValue = getRemotePreferences("me.kavishdevar.librepods").getBoolean("vendor_id_hook", false)
|
||||
log(Log.INFO, TAG, "sdp hook enabled (remote pref): $remotePrefValue")
|
||||
NativeBridge.setSdpHook(remotePrefValue)
|
||||
@@ -171,8 +171,10 @@ object MediaController {
|
||||
}
|
||||
|
||||
if (configs != null && !iPausedTheMedia) {
|
||||
val localMac = ServiceManager.getService()?.localMac ?: return
|
||||
if (localMac == "") return
|
||||
ServiceManager.getService()?.aacpManager?.sendMediaInformataion(
|
||||
ServiceManager.getService()?.localMac ?: return,
|
||||
localMac,
|
||||
isActive
|
||||
)
|
||||
Log.d("MediaController", "User changed media state themselves; will wait for ear detection pause before auto-play")
|
||||
|
||||
@@ -20,25 +20,26 @@ package me.kavishdevar.librepods.utils
|
||||
|
||||
import android.content.SharedPreferences
|
||||
import android.os.Build
|
||||
import me.kavishdevar.librepods.BuildConfig
|
||||
|
||||
fun isSupported(sharedPreferences: SharedPreferences): Boolean {
|
||||
val isPixel = Build.MANUFACTURER.lowercase() == "google"
|
||||
val isOppoOrOnePlus = Build.MANUFACTURER.lowercase() in listOf("oneplus", "oppo")
|
||||
val isOppoFamily = Build.MANUFACTURER.lowercase() in listOf("oneplus", "oppo", "realme")
|
||||
val isBypassFlagActive = sharedPreferences.getBoolean("bypass_device_check.v2", false)
|
||||
|
||||
if (isBypassFlagActive) return true
|
||||
|
||||
if (isPixel) {
|
||||
when (Build.VERSION.SDK_INT) {
|
||||
36 -> {
|
||||
return Build.ID == "CP1A.260305.018" || Build.ID == "CP1A.260405.005"
|
||||
return Build.ID.startsWith("CP1A")
|
||||
}
|
||||
|
||||
37 -> {
|
||||
return true
|
||||
}
|
||||
}
|
||||
} else if (isOppoOrOnePlus) {
|
||||
return true
|
||||
} else if (isOppoFamily) {
|
||||
return Build.VERSION.SDK_INT >= 36
|
||||
}
|
||||
return if (BuildConfig.FLAVOR == "xposed") true
|
||||
else sharedPreferences.getBoolean("bypass_device_check", false)
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
package me.kavishdevar.librepods.utils
|
||||
|
||||
object XposedState {
|
||||
var isAvailable: Boolean = false
|
||||
var bluetoothScopeEnabled: Boolean = false
|
||||
}
|
||||
7
android/app/src/main/res/values-de/strings.xml
Normal file
7
android/app/src/main/res/values-de/strings.xml
Normal file
@@ -0,0 +1,7 @@
|
||||
<resources xmlns:tools="http://schemas.android.com/tools" tools:ignore="MissingTranslation">
|
||||
<string name="popup_animations">Popup-Animationen</string>
|
||||
<string name="show_bottom_sheet_popup">Popup unten</string>
|
||||
<string name="show_bottom_sheet_popup_description">Zeigt das Popup im iOS-Stil unten an, wenn AirPods sich verbinden.</string>
|
||||
<string name="show_island_popup">Dynamic Island Popup</string>
|
||||
<string name="show_island_popup_description">Zeigt das Popup im Dynamic-Island-Stil oben für Verbindungs- und Übergabe-Ereignisse.</string>
|
||||
</resources>
|
||||
@@ -210,4 +210,9 @@
|
||||
<string name="listening_mode_transparency_description">Deja entrar los sonidos externos</string>
|
||||
<string name="listening_mode_adaptive_description">Ajuste dinámico del ruido externo</string>
|
||||
<string name="listening_mode_noise_cancellation_description">Bloquea los sonidos externos</string>
|
||||
<string name="popup_animations">Animaciones emergentes</string>
|
||||
<string name="show_bottom_sheet_popup">Ventana emergente inferior</string>
|
||||
<string name="show_bottom_sheet_popup_description">Muestra la ventana emergente estilo iOS en la parte inferior cuando los AirPods se conectan.</string>
|
||||
<string name="show_island_popup">Ventana emergente Dynamic Island</string>
|
||||
<string name="show_island_popup_description">Muestra la ventana emergente estilo Dynamic Island en la parte superior para eventos de conexión y traspaso.</string>
|
||||
</resources>
|
||||
|
||||
@@ -210,4 +210,9 @@
|
||||
<string name="listening_mode_transparency_description">Laisser entrer les sons extérieurs</string>
|
||||
<string name="listening_mode_adaptive_description">Ajuster dynamiquement les sons extérieurs</string>
|
||||
<string name="listening_mode_noise_cancellation_description">Bloquer les sons extérieurs</string>
|
||||
<string name="popup_animations">Animations contextuelles</string>
|
||||
<string name="show_bottom_sheet_popup">Fenêtre contextuelle en bas</string>
|
||||
<string name="show_bottom_sheet_popup_description">Afficher la fenêtre contextuelle de style iOS en bas de l\'écran lors de la connexion des AirPods.</string>
|
||||
<string name="show_island_popup">Fenêtre Dynamic Island</string>
|
||||
<string name="show_island_popup_description">Afficher la fenêtre de style Dynamic Island en haut de l\'écran pour les événements de connexion et de transfert.</string>
|
||||
</resources>
|
||||
|
||||
@@ -210,4 +210,9 @@
|
||||
<string name="listening_mode_transparency_description">Permite sons externos</string>
|
||||
<string name="listening_mode_adaptive_description">Ajusta dinamicamente o ruído externo</string>
|
||||
<string name="listening_mode_noise_cancellation_description">Bloqueia sons externos</string>
|
||||
<string name="popup_animations">Animações de pop-up</string>
|
||||
<string name="show_bottom_sheet_popup">Pop-up inferior</string>
|
||||
<string name="show_bottom_sheet_popup_description">Exibe o pop-up estilo iOS na parte inferior quando os AirPods se conectam.</string>
|
||||
<string name="show_island_popup">Pop-up Dynamic Island</string>
|
||||
<string name="show_island_popup_description">Exibe o pop-up estilo Dynamic Island no topo da tela em eventos de conexão e transferência.</string>
|
||||
</resources>
|
||||
|
||||
@@ -152,7 +152,7 @@
|
||||
<string name="set_identity_resolving_key">設定身分解析金鑰 (IRK)</string>
|
||||
<string name="set_identity_resolving_key_description">手動設定用於解析 BLE 隨機位址的 IRK 值</string>
|
||||
<string name="set_encryption_key">設定加密金鑰</string>
|
||||
<string name="set_encryption_key_description">手動設定用於解密 BLE 廣播的 ENC_KEY值</string>
|
||||
<string name="set_encryption_key_description">手動設定用於解密 BLE 廣播的 ENC_KEY 值</string>
|
||||
<string name="use_alternate_head_tracking_packets">使用替代頭部追蹤封包</string>
|
||||
<string name="use_alternate_head_tracking_packets_description">如果頭部追蹤對你無效,請啟用此選項。這會傳送不同的資料給 AirPods 以請求/停止頭部追蹤資料。</string>
|
||||
<string name="act_as_an_apple_device">作為 Apple 裝置</string>
|
||||
@@ -212,4 +212,33 @@
|
||||
<string name="listening_mode_transparency_description">允許外部聲音</string>
|
||||
<string name="listening_mode_adaptive_description">動態調整外部噪音</string>
|
||||
<string name="listening_mode_noise_cancellation_description">阻隔外部聲音</string>
|
||||
<string name="unlock_advanced_features">解鎖進階功能</string>
|
||||
<string name="buy_price">購買 %s</string>
|
||||
<string name="restore_purchases">恢復購買</string>
|
||||
<string name="ear_detection_description">取下時自動停止播放音訊,戴上時恢復播放。</string>
|
||||
<string name="battery">電池</string>
|
||||
<string name="battery_description">在應用程式與通知中查看準確的電池狀態。</string>
|
||||
<string name="noise_control_description">直接從應用程式或快速設定中切換聽覺模式。</string>
|
||||
<string name="advanced_device_settings">進階裝置設定</string>
|
||||
<string name="advanced_device_settings_description">自訂個人化音量、自適應音訊、入睡時暫停媒體及其他輔助使用設定等功能。</string>
|
||||
<string name="automatic_connection">自動連線</string>
|
||||
<string name="automatic_connection_description">啟用並自訂自動連接至 AirPods 的功能。</string>
|
||||
<string name="customizations_description">存取應用程式自訂功能,包括小工具中的手機電量、對話感知音量,以及更多即將推出的自訂功能。</string>
|
||||
<string name="support_the_development">支援開發</string>
|
||||
<string name="support_development_description">LibrePods 由單一開發者開發。升級有助於維持應用程式的運作。</string>
|
||||
<string name="feature_availability_disclaimer">功能的可用性取決於你的 AirPods 型號與韌體版本。</string>
|
||||
<string name="contact">聯絡</string>
|
||||
<string name="email">電子郵件</string>
|
||||
<string name="discord">Discord</string>
|
||||
<string name="github_issues">GitHub Issues</string>
|
||||
<string name="version_code">版本代碼</string>
|
||||
<string name="build_type">建置類型</string>
|
||||
<string name="no">否</string>
|
||||
<string name="yes">是</string>
|
||||
<string name="settings">設定</string>
|
||||
<string name="requires_xposed">需要 Xposed</string>
|
||||
<string name="bypass_compatibility_check">略過相容性檢查</string>
|
||||
<string name="bypass_compatiblity_check_confirmation">你確定你的裝置原生支援或已啟用 Xposed 模組嗎?</string>
|
||||
<string name="not_supported">不支援</string>
|
||||
<string name="check_the_repository_for_more_info">請查看儲存庫以獲取更多資訊。</string>
|
||||
</resources>
|
||||
|
||||
@@ -140,6 +140,11 @@
|
||||
<string name="widget">Widget</string>
|
||||
<string name="show_phone_battery_in_widget">Show phone battery in widget</string>
|
||||
<string name="show_phone_battery_in_widget_description">Display your phone\'s battery level in the widget alongside AirPods battery</string>
|
||||
<string name="popup_animations">Popup Animations</string>
|
||||
<string name="show_bottom_sheet_popup">Bottom sheet popup</string>
|
||||
<string name="show_bottom_sheet_popup_description">Show the iOS-style modal popup at the bottom when AirPods connect.</string>
|
||||
<string name="show_island_popup">Dynamic Island popup</string>
|
||||
<string name="show_island_popup_description">Show the Dynamic Island-style popup at the top for connection and takeover events.</string>
|
||||
<string name="conversational_awareness_volume">Conversational Awareness Volume</string>
|
||||
<string name="quick_settings_tile">Quick Settings Tile</string>
|
||||
<string name="open_dialog_for_controlling">Open dialog for controlling</string>
|
||||
@@ -211,7 +216,7 @@
|
||||
<string name="listening_mode_adaptive_description">Dynamically adjust external noise</string>
|
||||
<string name="listening_mode_noise_cancellation_description">Blocks out external sounds</string>
|
||||
<string name="unlock_advanced_features">Unlock advanced features</string>
|
||||
<string name="buy">Buy</string>
|
||||
<string name="buy_price">Buy %s</string>
|
||||
<string name="restore_purchases">Restore purchases</string>
|
||||
<string name="ear_detection_description">Automatically stop playing audio when you take them off, and resume playback when you put them back on.</string>
|
||||
<string name="battery">Battery</string>
|
||||
@@ -236,4 +241,39 @@
|
||||
<string name="yes">Yes</string>
|
||||
<string name="settings">Settings</string>
|
||||
<string name="requires_xposed">requires xposed</string>
|
||||
<string name="bypass_compatibility_check">Bypass compatibility check</string>
|
||||
<string name="bypass_compatiblity_check_confirmation">Are you sure your device is supported natively/you have Xposed module enabled?</string>
|
||||
<string name="not_supported">Not supported</string>
|
||||
<string name="check_the_repository_for_more_info">
|
||||
Many devices are not supported due to limitations in the Android Bluetooth stack.
|
||||
\nOn these devices, root access with an Xposed framework is required for full functionality.
|
||||
\n\nThis limitation has been addressed in newer Android versions. The following device configurations can run the app natively:
|
||||
\n• Google Pixel® running Android 16 March update and later with the lateset Play system update
|
||||
\n• Google Pixel® running 17 Beta 3 and above
|
||||
\n• OnePlus devices running OxygenOS 16 or later
|
||||
\n• Oppo devices running ColorOS 16 or later
|
||||
\n\nFor details, see the project documentation.
|
||||
</string>
|
||||
<string name="name_your_own_price">(Name your own price)</string>
|
||||
<string name="compatibility_play_dialog_confirmation">
|
||||
This device may not be supported due to platform limitations and requires an Xposed framework. Tick the checkbox below and type OK to continue.
|
||||
</string>
|
||||
<string name="type_ok_to_continue">Type "%s" to continue</string>
|
||||
<string name="proceed">Proceed</string>
|
||||
<string name="read_compatibility_requirements">I have read compatibility requirements.</string>
|
||||
<string name="device_info">Device information</string>
|
||||
<string name="build_id">Build ID</string>
|
||||
<string name="manufacturer">Manufacturer</string>
|
||||
<string name="free_features">Free features</string>
|
||||
<string name="advanced_features">Advanced features</string>
|
||||
<string name="digital_assistant_on_long_press">Digital Assistant on Long Press</string>
|
||||
<string name="digital_assistant_on_long_press_description">Invoke Digital Assistant when long pressing the AirPods Pro stem.</string>
|
||||
<string name="customizations_unavailable">Customizations unavailable. Connect your AirPods at least once to access.</string>
|
||||
<string name="xposed_available">Xposed available</string>
|
||||
<string name="app_enabled_in_xposed">App enabled in Xposed</string>
|
||||
<string name="subject">Subject</string>
|
||||
<string name="describe_your_issue">Describe your issue</string>
|
||||
<string name="optimized_charging">Optimized Charge Limit</string>
|
||||
<string name="optimized_charging_description">AirPods can learn from your daily usage and determine when to charge to an optmized limit and when to allow or full charge. This limit adapts to your daily usage and preserves your battery lifespan over time.\nThis setting may not affect unsupported AirPods, or AirPods on an older firmware version.</string>
|
||||
<string name="enable_app_in_xposed_or_update_device">Enable LibrePods in Xposed or update your device to proceed.</string>
|
||||
</resources>
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
package me.kavishdevar.librepods
|
||||
|
||||
import android.app.Application
|
||||
|
||||
class LibrePodsApplication: Application()
|
||||
@@ -1,11 +0,0 @@
|
||||
package me.kavishdevar.librepods.data
|
||||
|
||||
class XposedRemotePrefImpl: XposedRemotePref {
|
||||
override fun isAvailable(): Boolean { return false }
|
||||
|
||||
override fun getBoolean(key: String, def: Boolean): Boolean {
|
||||
return false
|
||||
}
|
||||
|
||||
override fun putBoolean(key: String, value: Boolean) { }
|
||||
}
|
||||
@@ -1,125 +0,0 @@
|
||||
package me.kavishdevar.librepods.utils
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.util.Log
|
||||
import android.widget.ImageView
|
||||
import androidx.core.net.toUri
|
||||
import io.github.libxposed.api.XposedModule
|
||||
import io.github.libxposed.api.XposedModuleInterface.ModuleLoadedParam
|
||||
import io.github.libxposed.api.XposedModuleInterface.PackageLoadedParam
|
||||
|
||||
private const val TAG = "LibrePodsHook"
|
||||
|
||||
@SuppressLint("DiscouragedApi", "PrivateApi")
|
||||
class KotlinModule: XposedModule() {
|
||||
override fun onModuleLoaded(param: ModuleLoadedParam) {
|
||||
log(Log.INFO, TAG, "module initialized at :: ${param.processName}")
|
||||
log(Log.INFO, TAG, "framework: $frameworkName($frameworkVersionCode) API $apiVersion")
|
||||
}
|
||||
|
||||
override fun onPackageLoaded(param: PackageLoadedParam) {
|
||||
log(Log.INFO, TAG, "onPackageLoaded :: ${param.packageName}")
|
||||
|
||||
if (param.packageName == "com.google.android.bluetooth" || param.packageName == "com.android.bluetooth") {
|
||||
log(Log.INFO, TAG, "Bluetooth app detected, hooking l2c_fcr_chk_chan_modes")
|
||||
try {
|
||||
if (param.isFirstPackage) {
|
||||
log(Log.INFO, TAG, "Loading native library for Bluetooth hook")
|
||||
|
||||
NativeBridge.setSdpHook(getRemotePreferences("me.kavishdevar.librepods").getBoolean("vendor_id_hook", false))
|
||||
System.loadLibrary("l2c_fcr_hook")
|
||||
log(Log.INFO, TAG, "Native library loaded successfully")
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
log(Log.ERROR, TAG, "Failed to load native library: ${e.message}")
|
||||
}
|
||||
}
|
||||
|
||||
if (param.packageName == "com.google.android.settings") {
|
||||
hookSettingsController(param, "com.google.android.settings.bluetooth.AdvancedBluetoothDetailsHeaderController")
|
||||
}
|
||||
|
||||
if (param.packageName == "com.android.settings") {
|
||||
hookSettingsController(param, "com.android.settings.bluetooth.AdvancedBluetoothDetailsHeaderController")
|
||||
}
|
||||
}
|
||||
|
||||
private fun hookSettingsController(param: PackageLoadedParam, className: String) {
|
||||
log(Log.INFO, TAG, "Settings app detected, hooking Bluetooth icon handling")
|
||||
try {
|
||||
val headerControllerClass = Class.forName(className, false, param.defaultClassLoader)
|
||||
val updateIconMethod = headerControllerClass.getDeclaredMethod(
|
||||
"updateIcon",
|
||||
ImageView::class.java,
|
||||
String::class.java
|
||||
)
|
||||
|
||||
hook(updateIconMethod).intercept { chain ->
|
||||
try {
|
||||
log(Log.INFO, TAG, "Bluetooth icon hook called with args: ${chain.args.joinToString(", ")}")
|
||||
val imageView = chain.args[0] as? ImageView
|
||||
val iconUri = chain.args[1] as? String
|
||||
|
||||
if (imageView == null || iconUri == null) {
|
||||
return@intercept chain.proceed()
|
||||
}
|
||||
|
||||
val uri = iconUri.toUri()
|
||||
if (!uri.toString().startsWith("android.resource://me.kavishdevar.librepods")) {
|
||||
return@intercept chain.proceed()
|
||||
}
|
||||
|
||||
log(Log.INFO, TAG, "Handling AirPods icon URI: $uri")
|
||||
|
||||
Handler(Looper.getMainLooper()).post {
|
||||
try {
|
||||
val context = imageView.context
|
||||
val packageName = uri.authority ?: return@post
|
||||
val packageContext = context.createPackageContext(
|
||||
packageName,
|
||||
Context.CONTEXT_IGNORE_SECURITY
|
||||
)
|
||||
|
||||
val resPath = uri.pathSegments
|
||||
if (resPath.size >= 2 && resPath[0] == "drawable") {
|
||||
val resourceName = resPath[1]
|
||||
val resourceId = packageContext.resources.getIdentifier(
|
||||
resourceName, "drawable", packageName
|
||||
)
|
||||
|
||||
if (resourceId != 0) {
|
||||
val drawable = packageContext.resources.getDrawable(
|
||||
resourceId, packageContext.theme
|
||||
)
|
||||
imageView.setImageDrawable(drawable)
|
||||
imageView.alpha = 1.0f
|
||||
log(Log.INFO, TAG, "Successfully loaded icon from resource: $resourceName")
|
||||
} else {
|
||||
log(Log.ERROR, TAG, "Resource not found: $resourceName")
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
log(Log.ERROR, TAG, "Error loading resource from URI $uri: ${e.message}")
|
||||
}
|
||||
}
|
||||
null
|
||||
} catch (e: Exception) {
|
||||
log(Log.ERROR, TAG, "Error in Bluetooth icon hook: ${e.message}")
|
||||
chain.proceed()
|
||||
}
|
||||
}
|
||||
|
||||
log(Log.INFO, TAG, "Successfully hooked updateIcon method in Bluetooth settings")
|
||||
} catch (e: Exception) {
|
||||
log(Log.ERROR, TAG, "Failed to hook Bluetooth icon handler: ${e.message}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
object NativeBridge {
|
||||
external fun setSdpHook(enabled: Boolean)
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
package me.kavishdevar.librepods.utils
|
||||
|
||||
import android.content.Context
|
||||
import io.github.libxposed.service.XposedService
|
||||
import io.github.libxposed.service.XposedServiceHelper
|
||||
|
||||
object XposedServiceHolder {
|
||||
var service: XposedService? = null
|
||||
}
|
||||
|
||||
|
||||
object XposedInitializer: XposedServiceHelper.OnServiceListener {
|
||||
private var initialized = false
|
||||
|
||||
fun ensureInit(context: Context) {
|
||||
if (initialized) return
|
||||
initialized = true
|
||||
XposedServiceHelper.registerListener(this)
|
||||
}
|
||||
|
||||
override fun onServiceBind(service: XposedService) {
|
||||
XposedServiceHolder.service = service
|
||||
}
|
||||
|
||||
override fun onServiceDied(service: XposedService) {
|
||||
XposedServiceHolder.service = null
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
package me.kavishdevar.librepods
|
||||
|
||||
import android.app.Application
|
||||
import io.github.libxposed.service.XposedService
|
||||
import io.github.libxposed.service.XposedServiceHelper
|
||||
import me.kavishdevar.librepods.utils.XposedServiceHolder
|
||||
|
||||
class LibrePodsApplication: Application(), XposedServiceHelper.OnServiceListener {
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
XposedServiceHelper.registerListener(this)
|
||||
}
|
||||
|
||||
override fun onServiceBind(p0: XposedService) {
|
||||
XposedServiceHolder.service = p0
|
||||
}
|
||||
|
||||
override fun onServiceDied(p0: XposedService) {
|
||||
XposedServiceHolder.service = null
|
||||
}
|
||||
}
|
||||
@@ -1,23 +1,25 @@
|
||||
[versions]
|
||||
accompanistPermissions = "0.37.3"
|
||||
agp = "9.1.0"
|
||||
kotlin = "2.3.20"
|
||||
agp = "9.1.1"
|
||||
kotlin = "2.3.21"
|
||||
coreKtx = "1.18.0"
|
||||
lifecycleRuntimeKtx = "2.10.0"
|
||||
activityCompose = "1.13.0"
|
||||
composeBom = "2026.03.01"
|
||||
composeBom = "2026.05.00"
|
||||
annotations = "26.1.0"
|
||||
navigationCompose = "2.9.7"
|
||||
navigationCompose = "2.9.8"
|
||||
constraintlayout = "2.2.1"
|
||||
haze = "1.7.2"
|
||||
hazeMaterials = "1.7.2"
|
||||
dynamicanimation = "1.1.0"
|
||||
aboutLibraries = "14.0.1"
|
||||
aboutLibraries = "14.2.0"
|
||||
materialIconsCore = "1.7.8"
|
||||
backdrop = "2.0.0-alpha03"
|
||||
billing = "8.3.0"
|
||||
hilt = "2.59.2"
|
||||
xposed = "101.0.0"
|
||||
lifecycleProcess = "2.10.0"
|
||||
play = "2.0.2"
|
||||
|
||||
[libraries]
|
||||
accompanist-permissions = { module = "com.google.accompanist:accompanist-permissions", version.ref = "accompanistPermissions" }
|
||||
@@ -47,6 +49,9 @@ hilt = { group = "com.google.dagger", name = "hilt-android", version.ref = "hilt
|
||||
hilt-compiler = { group = "com.google.dagger", name = "hilt-compiler", version.ref = "hilt" }
|
||||
libxposed-api = { group = "io.github.libxposed", name = "api", version.ref = "xposed" }
|
||||
libxposed-service = { group = "io.github.libxposed", name = "service", version.ref = "xposed" }
|
||||
androidx-lifecycle-process = { group = "androidx.lifecycle", name = "lifecycle-process", version.ref = "lifecycleProcess" }
|
||||
play-review = { group = "com.google.android.play", name="review", version.ref = "play" }
|
||||
play-review-ktx = { group = "com.google.android.play", name="review-ktx", version.ref = "play" }
|
||||
|
||||
[plugins]
|
||||
android-application = { id = "com.android.application", version.ref = "agp" }
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -eux
|
||||
|
||||
cd root-module
|
||||
rm -f ../btl2capfix.zip
|
||||
|
||||
# COPYFILE_DISABLE env is a macOS fix to avoid parasitic files in ZIPs: https://superuser.com/a/260264
|
||||
export COPYFILE_DISABLE=1
|
||||
curl -L -o ./radare2-5.9.9-android-aarch64.tar.gz "https://github.com/devnoname120/radare2/releases/download/5.9.8-android-aln/radare2-5.9.9-android-aarch64-aln.tar.gz"
|
||||
zip -r ../btl2capfix.zip . -x \*.DS_Store \*__MACOSX \*DEBIAN ._\* .gitignore
|
||||
@@ -16,53 +16,53 @@ Bytes that are not used are set to `0x00`. From what I've observed, the `data3`
|
||||
|
||||
## Identifiers and details
|
||||
|
||||
| Command identifier | Description |
|
||||
|--------------|---------------------|
|
||||
| 0x01 | Mic Mode |
|
||||
| 0x05 | Button Send Mode |
|
||||
| 0x06 | Owns connection |
|
||||
| 0x0A | Ear Detection |
|
||||
| 0x12 | VoiceTrigger for Siri |
|
||||
| 0x14 | SingleClickMode |
|
||||
| 0x15 | DoubleClickMode |
|
||||
| 0x16 | ClickHoldMode |
|
||||
| 0x17 | DoubleClickInterval |
|
||||
| 0x18 | ClickHoldInterval |
|
||||
| 0x1A | ListeningModeConfigs |
|
||||
| 0x1B | OneBudANCMode |
|
||||
| 0x1C | CrownRotationDirection |
|
||||
| 0x0D | ListeningMode |
|
||||
| 0x1E | AutoAnswerMode |
|
||||
| 0x1F | Chime Volume |
|
||||
| 0x20 | Connect Automatically |
|
||||
| 0x23 | VolumeSwipeInterval |
|
||||
| 0x24 | Call Management Config |
|
||||
| 0x25 | VolumeSwipeMode |
|
||||
| 0x26 | Adaptive Volume Config |
|
||||
| 0x27 | Software Mute config |
|
||||
| 0x28 | Conversation Detect config |
|
||||
| 0x29 | SSL |
|
||||
| 0x2C | Hearing Aid Enrolled and Hearing Aid Enabled |
|
||||
| 0x2E | AutoANC Strength |
|
||||
| 0x2F | HPS Gain Swipe |
|
||||
| 0x30 | HRM enable/disable state |
|
||||
| 0x31 | In Case Tone config |
|
||||
| 0x32 | Siri Multitone config |
|
||||
| 0x33 | Hearing Assist config |
|
||||
| 0x34 | Allow Off Option for Listening Mode config |
|
||||
| 0x35 | Sleep Detection config |
|
||||
| 0x36 | Allow Auto Connect |
|
||||
| 0x37 | PPE Toggle config |
|
||||
| 0x38 | Personal Protective Equipment Cap Level config |
|
||||
| 0x39 | Raw Gestures config |
|
||||
| 0x3A | Temporary Pairing Config |
|
||||
| 0x3B | Dynamic End of Charge config |
|
||||
| 0x3C | System Siri message config |
|
||||
| 0x3D | Hearing Aid Generic config |
|
||||
| 0x3E | Uplink EQ Bud config |
|
||||
| 0x3F | Uplink EQ Source config |
|
||||
| 0x40 | In Case Tone Volume |
|
||||
| 0x41 | Disable Button Input config |
|
||||
| Command identifier | Description |
|
||||
| ------------------ | ---------------------------------------------- |
|
||||
| 0x01 | Mic Mode |
|
||||
| 0x05 | Button Send Mode |
|
||||
| 0x06 | Owns connection |
|
||||
| 0x0A | Ear Detection |
|
||||
| 0x12 | VoiceTrigger for Siri |
|
||||
| 0x14 | SingleClickMode |
|
||||
| 0x15 | DoubleClickMode |
|
||||
| 0x16 | ClickHoldMode |
|
||||
| 0x17 | DoubleClickInterval |
|
||||
| 0x18 | ClickHoldInterval |
|
||||
| 0x1A | ListeningModeConfigs |
|
||||
| 0x1B | OneBudANCMode |
|
||||
| 0x1C | CrownRotationDirection |
|
||||
| 0x0D | ListeningMode |
|
||||
| 0x1E | AutoAnswerMode |
|
||||
| 0x1F | Chime Volume |
|
||||
| 0x20 | Connect Automatically |
|
||||
| 0x23 | VolumeSwipeInterval |
|
||||
| 0x24 | Call Management Config |
|
||||
| 0x25 | VolumeSwipeMode |
|
||||
| 0x26 | Adaptive Volume Config |
|
||||
| 0x27 | Software Mute config |
|
||||
| 0x28 | Conversation Detect config |
|
||||
| 0x29 | SSL |
|
||||
| 0x2C | Hearing Aid Enrolled and Hearing Aid Enabled |
|
||||
| 0x2E | AutoANC Strength |
|
||||
| 0x2F | HPS Gain Swipe |
|
||||
| 0x30 | HRM enable/disable state |
|
||||
| 0x31 | In Case Tone config |
|
||||
| 0x32 | Siri Multitone config |
|
||||
| 0x33 | Hearing Assist config |
|
||||
| 0x34 | Allow Off Option for Listening Mode config |
|
||||
| 0x35 | Sleep Detection config |
|
||||
| 0x36 | Allow Auto Connect |
|
||||
| 0x37 | PPE Toggle config |
|
||||
| 0x38 | Personal Protective Equipment Cap Level config |
|
||||
| 0x39 | Raw Gestures config |
|
||||
| 0x3A | Temporary Pairing Config |
|
||||
| 0x3B | Dynamic End of Charge config |
|
||||
| 0x3C | System Siri message config |
|
||||
| 0x3D | Hearing Aid Generic config |
|
||||
| 0x3E | Uplink EQ Bud config |
|
||||
| 0x3F | Uplink EQ Source config |
|
||||
| 0x40 | In Case Tone Volume |
|
||||
| 0x41 | Disable Button Input config |
|
||||
|
||||
## Command Details
|
||||
|
||||
|
||||
26
docs/device-info.md
Normal file
26
docs/device-info.md
Normal file
@@ -0,0 +1,26 @@
|
||||
---
|
||||
opcode: 0x001D
|
||||
title: Device Information
|
||||
description: Information about AirPods, such as model, firmware version, and serial number. This can not be requested from the accessory; it is only sent by the accessory to the host upon connection.
|
||||
---
|
||||
|
||||
## Device information
|
||||
|
||||
The device information packet is sent by the accessory to the host upon connection. It contains various details about the AirPods, including model number, software version, and serial number.
|
||||
|
||||
Each `null` indicates the start of a new string field.
|
||||
|
||||
The data is in this order:
|
||||
- Name
|
||||
- Model number
|
||||
- Manufacturer (always "Apple Inc.")
|
||||
- Serial number
|
||||
- Version 1
|
||||
- Version 2
|
||||
- Hardware revision (?) (I have `1.0.0`)
|
||||
- Updater app version (?) (I have `com.apple.accessory.updater.app.71`)
|
||||
- Serial number (Left Bud)
|
||||
- Serial number (Right Bud)
|
||||
- Version (?) (I have `8454371`)
|
||||
- A few more bytes, I don't know what they are
|
||||
|
||||
33
docs/opcodes.md
Normal file
33
docs/opcodes.md
Normal file
@@ -0,0 +1,33 @@
|
||||
# AACP opcodes
|
||||
|
||||
AACP (Apple Accessory Communication Protocol) uses various opcodes to define different types of actions and commands. Each opcode is a 16-bit integer that specifies the kind of operation being performed. The opcode is sent in little-endian format as part of the AACP packet structure.
|
||||
|
||||
|
||||
| Opcode (Hex) | Destination | Description |
|
||||
| ------------ | ----------- | ------------------------------------------------------------------ |
|
||||
| 0x0001 | Accessory | Unknown |
|
||||
| 0x0004 | Host | [Battery report](/docs/battery_report.md) |
|
||||
| 0x0006 | Host | [Ear detection](/docs/ear-detection_report.md) |
|
||||
| 0x0009 | Both | [Control commands](/docs/control_commands.md) |
|
||||
| 0x000D | Accessory | [Audio source req](/docs/audio-source.md) |
|
||||
| 0x000E | Host | [Audio source resp](/docs/audio-source.md) |
|
||||
| 0x000F | Accessory | [Notification register](/docs/notification-register.md) |
|
||||
| 0x0010 | Accessory | [Smart routing relay](/docs/smart-routing-relay.md#send) |
|
||||
| 0x0011 | Host | [Smart routing response](/docs/smart-routing-relay.md#receive) |
|
||||
| 0x0014 | Accessory | Send connected device MAC |
|
||||
| 0x0017 | Both | Multiple things - undocumented |
|
||||
| 0x0019 | Host | [Stem press](/docs/stem-press.md) |
|
||||
| 0x001B | Accessory | [Timestamp](/docs/timestamp.md) |
|
||||
| 0x001D | Host | [Device Information](/docs/device-info.md) |
|
||||
| 0x001E | Accessory | [Rename device](/docs/rename.md) |
|
||||
| 0x0022 | Accessory | Unknown |
|
||||
| 0x0029 | Accessory | [Host capabilities](/docs/host-capabilities.md#another-opcode) (?) |
|
||||
| 0x002B | Host | Paired devices (?) |
|
||||
| 0x002D | Accessory | [List of connected dev. req](/docs/connected-devices.md#send) |
|
||||
| 0x002E | Host | [List of connected devices](/docs/connected-devices.md#receive) |
|
||||
| 0x0030 | Accessory | [BLE keys req](/docs/ble-keys.md) |
|
||||
| 0x0031 | Host | [BLE keys response](/docs/ble-keys.md) |
|
||||
| 0x004B | Host | [Conversation awareness](/docs/conversational-awareness.md) |
|
||||
| 0x004D | Accessory | [Host capabilities](/docs/host-capabilities.md) |
|
||||
| 0x004F | Both | Information req/res (doesn't work, even with apple's DID) |
|
||||
| 0x0053 | Both | [EQ data](/docs/eq.md) |
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"version": "v0.0.3",
|
||||
"versionCode": 3,
|
||||
"zipUrl": "https://github.com/kavishdevar/librepods/releases/download/v0.0.3/btl2capfix-v0.0.3.zip",
|
||||
"changelog": "https://raw.githubusercontent.com/kavishdevar/librepods/main/CHANGELOG.md"
|
||||
}
|
||||
"version": "v0.2.6",
|
||||
"versionCode": 46,
|
||||
"zipUrl": "https://github.com/kavishdevar/librepods/releases/download/v0.2.6/LibrePods-FOSS-v0.2.6-release.zip",
|
||||
"changelog": "https://raw.githubusercontent.com/kavishdevar/librepods/main/extras/CHANGELOG.md"
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
# AirPods Head Tracking Visualizer
|
||||
|
||||
This implements head tracking with AirPods by gathering sensor data over l2cap, processing orientation and acceleration values, and detecting head gestures. The codebase is split into the following components:
|
||||
|
||||
# How to use
|
||||
|
||||
Connect your airpods and change the mac address in `plot.py` to your airpods mac address. Then run the following command to start the program.
|
||||
|
||||
```bash
|
||||
python plot.py
|
||||
```
|
||||
|
||||
Alternatively, you can directly run the `gestures.py` to just detect gestures.
|
||||
|
||||
```bash
|
||||
python gestures.py
|
||||
```
|
||||
|
||||
- **Connection and Data Collection**
|
||||
The project uses a custom ConnectionManager (imported in multiple files) to connect via Bluetooth to AirPods. Once connected, sensor packets are received in raw hex format. An AirPodsTracker class (in `plot.py`) handles the start/stop of tracking, logging of raw data, and parsing of packets into useful fields.
|
||||
|
||||
- **Orientation Calculation and Visualization**
|
||||
The `HeadOrientation` class (in `head_orientation.py`) is responsible for:
|
||||
- **Calibration:**
|
||||
A set number of samples (default 10) are collected to calculate the neutral (baseline) values for the sensors. For example:
|
||||
`o1_neutral = np.mean(samples[:, 0])`
|
||||
- **Calculating Angles:**
|
||||
For each new packet, the raw orientation values are normalized by subtracting the neutral baseline. Then:
|
||||
- **Pitch** is computed as:
|
||||
```
|
||||
pitch = (o2_norm + o3_norm) / 2 / 32000 * 180
|
||||
```
|
||||
This averages the deviations from neutral, scales the result to degrees (assuming a sensor range around 32000), thus giving a smooth estimation of up/down tilt.
|
||||
- **Yaw** is computed as:
|
||||
```
|
||||
yaw = (o2_norm - o3_norm) / 2 / 32000 * 180
|
||||
```
|
||||
Here, the difference between the two sensor axes is used to detect left/right rotation.
|
||||
- **ASCII Visualization:**
|
||||
Based on the calculated pitch and yaw, an ASCII art "face" is generated. The algorithm rotates points on a circle using simple trigonometric formulas (with scaling factors based on sensor depth) to build an approximate visual representation of head orientation.
|
||||
|
||||
- **Live Plotting and Interactive Commands**
|
||||
The code offers both terminal-based plotting and graphical plotting via matplotlib. The AirPodsTracker manages live plotting by maintaining a buffer of recent packets. When in terminal mode, the code uses libraries like `asciichartpy` and `drawille` to render charts; in graphical mode, it creates live-updating plots.
|
||||
|
||||
- **Gesture Detection**
|
||||
The `GestureDetector` class (in `gestures.py`) processes the head tracking data to detect nodding ("Yes") or head shaking ("No"):
|
||||
- **Smoothing:**
|
||||
Raw horizontal and vertical sensor data undergo moving-average smoothing using small fixed-size buffers. This reduces noise and provides a steadier signal.
|
||||
- **Peak and Trough Detection:**
|
||||
The code monitors small sections (e.g. the last 4 values) to compute variance and dynamically determine thresholds for direction changes. When a significant reversal (e.g. from increasing to decreasing) is detected that surpasses the dynamic threshold value (derived partly from a fixed threshold and variance), a peak or trough is recorded.
|
||||
- **Rhythm Consistency:**
|
||||
Time intervals between detected peaks are captured. The consistency of these intervals (by comparing them to their mean and computing relative variance) is used to evaluate whether the movement is rhythmic—a trait of intentional gestures.
|
||||
- **Confidence Calculation:**
|
||||
Multiple factors are considered:
|
||||
- **Amplitude Factor:** Compares the average detected peak amplitude with a constant (like 600) to provide a normalized measure.
|
||||
- **Rhythm Factor:** Derived from the consistency of the time intervals of the peaks.
|
||||
- **Alternation Factor:** Verifies that the signal alternates (for instance, switching between positive and negative values).
|
||||
- **Isolation Factor:** Checks that movement on the target axis (vertical for nodding, horizontal for shaking) dominates over the non-target axis.
|
||||
|
||||
A weighted sum of these factors forms a confidence score which, if above a predefined threshold (e.g. 0.7), confirms a detected gesture.
|
||||
@@ -1,29 +0,0 @@
|
||||
import logging
|
||||
from logging import Formatter, LogRecord
|
||||
from typing import Dict
|
||||
|
||||
class Colors:
|
||||
RESET: str = "\033[0m"
|
||||
BOLD: str = "\033[1m"
|
||||
RED: str = "\033[91m"
|
||||
GREEN: str = "\033[92m"
|
||||
YELLOW: str = "\033[93m"
|
||||
BLUE: str = "\033[94m"
|
||||
MAGENTA: str = "\033[95m"
|
||||
CYAN: str = "\033[96m"
|
||||
WHITE: str = "\033[97m"
|
||||
BG_BLACK: str = "\033[40m"
|
||||
|
||||
class ColorFormatter(Formatter):
|
||||
FORMATS: Dict[int, str] = {
|
||||
logging.DEBUG: f"{Colors.BLUE}[%(levelname)s] %(message)s{Colors.RESET}",
|
||||
logging.INFO: f"{Colors.GREEN}%(message)s{Colors.RESET}",
|
||||
logging.WARNING: f"{Colors.YELLOW}%(message)s{Colors.RESET}",
|
||||
logging.ERROR: f"{Colors.RED}[%(levelname)s] %(message)s{Colors.RESET}",
|
||||
logging.CRITICAL: f"{Colors.RED}{Colors.BOLD}[%(levelname)s] %(message)s{Colors.RESET}"
|
||||
}
|
||||
|
||||
def format(self, record: LogRecord) -> str:
|
||||
log_fmt: str = self.FORMATS.get(record.levelno)
|
||||
formatter: Formatter = Formatter(log_fmt, datefmt="%H:%M:%S")
|
||||
return formatter.format(record)
|
||||
@@ -1,64 +0,0 @@
|
||||
import bluetooth
|
||||
import logging
|
||||
from bluetooth import BluetoothSocket
|
||||
from logging import Logger
|
||||
|
||||
class ConnectionManager:
|
||||
INIT_CMD: str = "00 00 04 00 01 00 02 00 00 00 00 00 00 00 00 00"
|
||||
START_CMD: str = "04 00 04 00 17 00 00 00 10 00 10 00 08 A1 02 42 0B 08 0E 10 02 1A 05 01 40 9C 00 00"
|
||||
STOP_CMD: str = "04 00 04 00 17 00 00 00 10 00 11 00 08 7E 10 02 42 0B 08 4E 10 02 1A 05 01 00 00 00 00"
|
||||
|
||||
def __init__(self, bt_addr: str = "28:2D:7F:C2:05:5B", psm: int = 0x1001, logger: Logger = None) -> None:
|
||||
self.bt_addr: str = bt_addr
|
||||
self.psm: int = psm
|
||||
self.logger: Logger = logger if logger else logging.getLogger(__name__)
|
||||
self.sock: BluetoothSocket = None
|
||||
self.connected: bool = False
|
||||
self.started: bool = False
|
||||
|
||||
def connect(self) -> bool:
|
||||
self.logger.info(f"Connecting to {self.bt_addr} on PSM {self.psm:#04x}...")
|
||||
try:
|
||||
self.sock = BluetoothSocket(bluetooth.L2CAP)
|
||||
self.sock.connect((self.bt_addr, self.psm))
|
||||
self.connected = True
|
||||
self.logger.info("Connected to AirPods.")
|
||||
self.sock.send(bytes.fromhex(self.INIT_CMD))
|
||||
self.logger.info("Initialization complete.")
|
||||
except Exception as e:
|
||||
self.logger.error(f"Connection failed: {e}")
|
||||
self.connected = False
|
||||
return self.connected
|
||||
|
||||
def send_start(self) -> bool:
|
||||
if not self.connected:
|
||||
self.logger.error("Not connected. Cannot send START command.")
|
||||
return False
|
||||
if not self.started:
|
||||
self.sock.send(bytes.fromhex(self.START_CMD))
|
||||
self.started = True
|
||||
self.logger.info("START command sent.")
|
||||
else:
|
||||
self.logger.info("START command has already been sent.")
|
||||
return True
|
||||
|
||||
def send_stop(self) -> None:
|
||||
if self.connected and self.started:
|
||||
try:
|
||||
self.sock.send(bytes.fromhex(self.STOP_CMD))
|
||||
self.logger.info("STOP command sent.")
|
||||
self.started = False
|
||||
except Exception as e:
|
||||
self.logger.error(f"Error sending STOP command: {e}")
|
||||
else:
|
||||
self.logger.info("Cannot send STOP; not started or not connected.")
|
||||
|
||||
def disconnect(self) -> None:
|
||||
if self.sock:
|
||||
try:
|
||||
self.sock.close()
|
||||
self.logger.info("Disconnected from AirPods.")
|
||||
except Exception as e:
|
||||
self.logger.error(f"Error during disconnect: {e}")
|
||||
self.connected = False
|
||||
self.started = False
|
||||
@@ -1,358 +0,0 @@
|
||||
import logging
|
||||
import statistics
|
||||
import time
|
||||
from bluetooth import BluetoothSocket
|
||||
from collections import deque
|
||||
from colors import *
|
||||
from connection_manager import ConnectionManager
|
||||
from logging import Logger, StreamHandler
|
||||
from threading import Lock, Thread
|
||||
from typing import Any, Deque, List, Optional, Tuple
|
||||
|
||||
handler: StreamHandler = StreamHandler()
|
||||
handler.setFormatter(ColorFormatter())
|
||||
log: Logger = logging.getLogger(__name__)
|
||||
log.setLevel(logging.INFO)
|
||||
log.addHandler(handler)
|
||||
log.propagate = False
|
||||
|
||||
class GestureDetector:
|
||||
INIT_CMD: str = "00 00 04 00 01 00 02 00 00 00 00 00 00 00 00 00"
|
||||
START_CMD: str = "04 00 04 00 17 00 00 00 10 00 10 00 08 A1 02 42 0B 08 0E 10 02 1A 05 01 40 9C 00 00"
|
||||
STOP_CMD: str = "04 00 04 00 17 00 00 00 10 00 11 00 08 7E 10 02 42 0B 08 4E 10 02 1A 05 01 00 00 00 00"
|
||||
|
||||
def __init__(self, conn: ConnectionManager = None) -> None:
|
||||
self.sock: BluetoothSocket = None
|
||||
self.bt_addr: str = "28:2D:7F:C2:05:5B"
|
||||
self.psm: int = 0x1001
|
||||
self.running: bool = False
|
||||
self.data_lock: Lock = Lock()
|
||||
|
||||
self.horiz_buffer: Deque[int] = deque(maxlen=100)
|
||||
self.vert_buffer: Deque[int] = deque(maxlen=100)
|
||||
|
||||
self.horiz_avg_buffer: Deque[float] = deque(maxlen=5)
|
||||
self.vert_avg_buffer: Deque[float] = deque(maxlen=5)
|
||||
|
||||
self.horiz_peaks: List[int] = []
|
||||
self.horiz_troughs: List[int] = []
|
||||
self.vert_peaks: List[int] = []
|
||||
self.vert_troughs: List[int] = []
|
||||
|
||||
self.last_peak_time: float = 0
|
||||
self.peak_intervals: Deque[float] = deque(maxlen=5)
|
||||
|
||||
self.peak_threshold: int = 400
|
||||
self.direction_change_threshold: int = 175
|
||||
self.rhythm_consistency_threshold: float = 0.5
|
||||
|
||||
self.horiz_increasing: Optional[bool] = None
|
||||
self.vert_increasing: Optional[bool] = None
|
||||
|
||||
self.required_extremes = 3
|
||||
self.detection_timeout: int = 15
|
||||
|
||||
self.min_confidence_threshold: float = 0.7
|
||||
|
||||
self.conn: ConnectionManager = conn
|
||||
|
||||
def connect(self) -> bool:
|
||||
try:
|
||||
log.info(f"Connecting to AirPods at {self.bt_addr}...")
|
||||
if self.conn is None:
|
||||
self.conn = ConnectionManager(self.bt_addr, self.psm, logger=log)
|
||||
if not self.conn.connect():
|
||||
return False
|
||||
else:
|
||||
if not self.conn.connected:
|
||||
if not self.conn.connect():
|
||||
return False
|
||||
self.sock = self.conn.sock
|
||||
log.info(f"{Colors.GREEN}✓ Connected to AirPods via ConnectionManager{Colors.RESET}")
|
||||
return True
|
||||
except Exception as e:
|
||||
log.error(f"{Colors.RED}Connection failed: {e}{Colors.RESET}")
|
||||
return False
|
||||
|
||||
def process_data(self) -> None:
|
||||
"""Process incoming head tracking data."""
|
||||
self.conn.send_start()
|
||||
log.info(f"{Colors.GREEN}✓ Head tracking activated{Colors.RESET}")
|
||||
|
||||
self.running = True
|
||||
start_time: float = time.time()
|
||||
|
||||
log.info(f"{Colors.GREEN}Ready! Make a YES or NO gesture{Colors.RESET}")
|
||||
log.info(f"{Colors.YELLOW}Tip: Use natural, moderate speed head movements{Colors.RESET}")
|
||||
|
||||
while self.running:
|
||||
if time.time() - start_time > self.detection_timeout:
|
||||
log.warning(f"{Colors.YELLOW}⚠️ Detection timeout reached. No gesture detected.{Colors.RESET}")
|
||||
self.running = False
|
||||
break
|
||||
|
||||
try:
|
||||
if not self.sock:
|
||||
log.error("Socket not available.")
|
||||
break
|
||||
data: bytes = self.sock.recv(1024)
|
||||
formatted: str = self.format_hex(data)
|
||||
if self.is_valid_tracking_packet(formatted):
|
||||
raw_bytes: bytes = bytes.fromhex(formatted.replace(" ", ""))
|
||||
horizontal, vertical = self.extract_orientation_values(raw_bytes)
|
||||
|
||||
if horizontal is not None and vertical is not None:
|
||||
smooth_h, smooth_v = self.apply_smoothing(horizontal, vertical)
|
||||
|
||||
with self.data_lock:
|
||||
self.horiz_buffer.append(smooth_h)
|
||||
self.vert_buffer.append(smooth_v)
|
||||
|
||||
self.detect_peaks_and_troughs()
|
||||
gesture: Optional[str] = self.detect_gestures()
|
||||
|
||||
if gesture:
|
||||
self.running = False
|
||||
break
|
||||
|
||||
except Exception as e:
|
||||
if self.running:
|
||||
log.error(f"Data processing error: {e}")
|
||||
break
|
||||
|
||||
def disconnect(self) -> None:
|
||||
"""Disconnect from socket."""
|
||||
self.conn.disconnect()
|
||||
|
||||
def format_hex(self, data: bytes) -> str:
|
||||
"""Format binary data to readable hex string."""
|
||||
hex_str: str = data.hex()
|
||||
return ' '.join(hex_str[i:i+2] for i in range(0, len(hex_str), 2))
|
||||
|
||||
def is_valid_tracking_packet(self, hex_string: str) -> bool:
|
||||
"""Verify packet is a valid head tracking packet."""
|
||||
standard_header: str = "04 00 04 00 17 00 00 00 10 00 45 00"
|
||||
alternate_header: str = "04 00 04 00 17 00 00 00 10 00 44 00"
|
||||
if not hex_string.startswith(standard_header) and not hex_string.startswith(alternate_header):
|
||||
return False
|
||||
|
||||
if len(hex_string.split()) < 80:
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
def extract_orientation_values(self, raw_bytes: bytes) -> Tuple[Optional[int], Optional[int]]:
|
||||
"""Extract head orientation data from packet."""
|
||||
try:
|
||||
horizontal: int = int.from_bytes(raw_bytes[51:53], byteorder='little', signed=True)
|
||||
vertical: int = int.from_bytes(raw_bytes[53:55], byteorder='little', signed=True)
|
||||
|
||||
return horizontal, vertical
|
||||
except Exception as e:
|
||||
log.debug(f"Failed to extract orientation: {e}")
|
||||
return None, None
|
||||
|
||||
def apply_smoothing(self, horizontal: int, vertical: int) -> Tuple[float, float]:
|
||||
"""Apply moving average smoothing (Apple-like filtering)."""
|
||||
self.horiz_avg_buffer.append(horizontal)
|
||||
self.vert_avg_buffer.append(vertical)
|
||||
|
||||
smooth_horiz: float = sum(self.horiz_avg_buffer) / len(self.horiz_avg_buffer)
|
||||
smooth_vert: float = sum(self.vert_avg_buffer) / len(self.vert_avg_buffer)
|
||||
|
||||
return smooth_horiz, smooth_vert
|
||||
|
||||
def detect_peaks_and_troughs(self) -> None:
|
||||
"""Detect motion direction changes with Apple-like refinements."""
|
||||
if len(self.horiz_buffer) < 4 or len(self.vert_buffer) < 4:
|
||||
return
|
||||
|
||||
h_values: List[int] = list(self.horiz_buffer)[-4:]
|
||||
v_values: List[int] = list(self.vert_buffer)[-4:]
|
||||
|
||||
h_variance: float = statistics.variance(h_values) if len(h_values) > 1 else 0
|
||||
v_variance: float = statistics.variance(v_values) if len(v_values) > 1 else 0
|
||||
|
||||
current: int = self.horiz_buffer[-1]
|
||||
prev: int = self.horiz_buffer[-2]
|
||||
|
||||
if self.horiz_increasing is None:
|
||||
self.horiz_increasing = current > prev
|
||||
|
||||
dynamic_h_threshold: float = max(100, min(self.direction_change_threshold, h_variance / 3))
|
||||
|
||||
if self.horiz_increasing and current < prev - dynamic_h_threshold:
|
||||
if abs(prev) > self.peak_threshold:
|
||||
self.horiz_peaks.append((len(self.horiz_buffer)-1, prev, time.time()))
|
||||
direction: str = "➡️ " if prev > 0 else "⬅️ "
|
||||
log.info(f"{Colors.CYAN}{direction} Horizontal max: {prev} (threshold: {dynamic_h_threshold:.1f}){Colors.RESET}")
|
||||
|
||||
now: float = time.time()
|
||||
if self.last_peak_time > 0:
|
||||
interval: float = now - self.last_peak_time
|
||||
self.peak_intervals.append(interval)
|
||||
self.last_peak_time = now
|
||||
|
||||
self.horiz_increasing = False
|
||||
|
||||
elif not self.horiz_increasing and current > prev + dynamic_h_threshold:
|
||||
if abs(prev) > self.peak_threshold:
|
||||
self.horiz_troughs.append((len(self.horiz_buffer)-1, prev, time.time()))
|
||||
direction: str = "➡️ " if prev > 0 else "⬅️ "
|
||||
log.info(f"{Colors.CYAN}{direction} Horizontal max: {prev} (threshold: {dynamic_h_threshold:.1f}){Colors.RESET}")
|
||||
|
||||
now: float = time.time()
|
||||
if self.last_peak_time > 0:
|
||||
interval: float = now - self.last_peak_time
|
||||
self.peak_intervals.append(interval)
|
||||
self.last_peak_time = now
|
||||
|
||||
self.horiz_increasing = True
|
||||
|
||||
current: int = self.vert_buffer[-1]
|
||||
prev: int = self.vert_buffer[-2]
|
||||
|
||||
if self.vert_increasing is None:
|
||||
self.vert_increasing = current > prev
|
||||
|
||||
dynamic_v_threshold: float = max(100, min(self.direction_change_threshold, v_variance / 3))
|
||||
|
||||
if self.vert_increasing and current < prev - dynamic_v_threshold:
|
||||
if abs(prev) > self.peak_threshold:
|
||||
self.vert_peaks.append((len(self.vert_buffer)-1, prev, time.time()))
|
||||
direction: str = "⬆️ " if prev > 0 else "⬇️ "
|
||||
log.info(f"{Colors.MAGENTA}{direction} Vertical max: {prev} (threshold: {dynamic_v_threshold:.1f}){Colors.RESET}")
|
||||
|
||||
now: float = time.time()
|
||||
if self.last_peak_time > 0:
|
||||
interval: float = now - self.last_peak_time
|
||||
self.peak_intervals.append(interval)
|
||||
self.last_peak_time = now
|
||||
|
||||
self.vert_increasing = False
|
||||
|
||||
elif not self.vert_increasing and current > prev + dynamic_v_threshold:
|
||||
if abs(prev) > self.peak_threshold:
|
||||
self.vert_troughs.append((len(self.vert_buffer)-1, prev, time.time()))
|
||||
direction: str = "⬆️ " if prev > 0 else "⬇️ "
|
||||
log.info(f"{Colors.MAGENTA}{direction} Vertical max: {prev} (threshold: {dynamic_v_threshold:.1f}){Colors.RESET}")
|
||||
|
||||
now: float = time.time()
|
||||
if self.last_peak_time > 0:
|
||||
interval: float = now - self.last_peak_time
|
||||
self.peak_intervals.append(interval)
|
||||
self.last_peak_time = now
|
||||
|
||||
self.vert_increasing = True
|
||||
|
||||
def calculate_rhythm_consistency(self) -> float:
|
||||
"""Calculate how consistent the timing between peaks is (Apple-like)."""
|
||||
if len(self.peak_intervals) < 2:
|
||||
return 0
|
||||
|
||||
mean_interval: float = statistics.mean(self.peak_intervals)
|
||||
if mean_interval == 0:
|
||||
return 0
|
||||
|
||||
variances: List[float] = [(i/mean_interval - 1.0) ** 2 for i in self.peak_intervals]
|
||||
consistency: float = 1.0 - min(1.0, statistics.mean(variances) / self.rhythm_consistency_threshold)
|
||||
return max(0, consistency)
|
||||
|
||||
def calculate_confidence_score(self, extremes: List[Tuple[int, int, float]], is_vertical: bool = True) -> float:
|
||||
"""Calculate confidence score for gesture detection (Apple-like)."""
|
||||
if len(extremes) < self.required_extremes:
|
||||
return 0.0
|
||||
|
||||
sorted_extremes: List[Tuple[int, int, float]] = sorted(extremes, key=lambda x: x[0])
|
||||
|
||||
recent: List[Tuple[int, int, float]] = sorted_extremes[-self.required_extremes:]
|
||||
|
||||
avg_amplitude: float = sum(abs(val) for _, val, _ in recent) / len(recent)
|
||||
amplitude_factor: float = min(1.0, avg_amplitude / 600)
|
||||
|
||||
rhythm_factor: float = self.calculate_rhythm_consistency()
|
||||
|
||||
signs: List[int] = [1 if val > 0 else -1 for _, val, _ in recent]
|
||||
alternating: bool = all(signs[i] != signs[i-1] for i in range(1, len(signs)))
|
||||
alternation_factor: float = 1.0 if alternating else 0.5
|
||||
|
||||
if is_vertical:
|
||||
vert_amp: float = sum(abs(val) for _, val, _ in recent) / len(recent)
|
||||
horiz_vals: List[int] = list(self.horiz_buffer)[-len(recent)*2:]
|
||||
horiz_amp: float = sum(abs(val) for val in horiz_vals) / len(horiz_vals) if horiz_vals else 0
|
||||
isolation_factor: float = min(1.0, vert_amp / (horiz_amp + 0.1) * 1.2)
|
||||
else:
|
||||
horiz_amp: float = sum(abs(val) for _, val, _ in recent)
|
||||
vert_vals: List[int] = list(self.vert_buffer)[-len(recent)*2:]
|
||||
vert_amp: float = sum(abs(val) for val in vert_vals) / len(vert_vals) if vert_vals else 0
|
||||
isolation_factor: float = min(1.0, horiz_amp / (vert_amp + 0.1) * 1.2)
|
||||
|
||||
confidence: float = (
|
||||
amplitude_factor * 0.4 +
|
||||
rhythm_factor * 0.2 +
|
||||
alternation_factor * 0.2 +
|
||||
isolation_factor * 0.2
|
||||
)
|
||||
|
||||
return confidence
|
||||
|
||||
def detect_gestures(self) -> Optional[str]:
|
||||
"""Recognize head gesture patterns with Apple-like intelligence."""
|
||||
if len(self.vert_peaks) + len(self.vert_troughs) >= self.required_extremes:
|
||||
all_extremes: List[Tuple[int, int, float]] = sorted(self.vert_peaks + self.vert_troughs, key=lambda x: x[0])
|
||||
|
||||
confidence: float = self.calculate_confidence_score(all_extremes, is_vertical=True)
|
||||
|
||||
log.info(f"Vertical motion confidence: {confidence:.2f} (need {self.min_confidence_threshold:.2f})")
|
||||
|
||||
if confidence >= self.min_confidence_threshold:
|
||||
log.info(f"{Colors.GREEN}🎯 \"Yes\" Gesture Detected (confidence: {confidence:.2f}){Colors.RESET}")
|
||||
return "YES"
|
||||
|
||||
if len(self.horiz_peaks) + len(self.horiz_troughs) >= self.required_extremes:
|
||||
all_extremes: List[Tuple[int, int, float]] = sorted(self.horiz_peaks + self.horiz_troughs, key=lambda x: x[0])
|
||||
|
||||
confidence: float = self.calculate_confidence_score(all_extremes, is_vertical=False)
|
||||
|
||||
log.info(f"Horizontal motion confidence: {confidence:.2f} (need {self.min_confidence_threshold:.2f})")
|
||||
|
||||
if confidence >= self.min_confidence_threshold:
|
||||
log.info(f"{Colors.GREEN}🎯 \"No\" gesture detected (confidence: {confidence:.2f}){Colors.RESET}")
|
||||
return "NO"
|
||||
|
||||
return None
|
||||
|
||||
def start_detection(self) -> None:
|
||||
"""Begin gesture detection process."""
|
||||
log.info(f"{Colors.BOLD}{Colors.WHITE}Starting gesture detection...{Colors.RESET}")
|
||||
|
||||
if not self.connect():
|
||||
log.error(f"{Colors.RED}Failed to connect to AirPods.{Colors.RESET}")
|
||||
return
|
||||
|
||||
data_thread: Thread = Thread(target=self.process_data)
|
||||
data_thread.daemon = True
|
||||
data_thread.start()
|
||||
|
||||
try:
|
||||
data_thread.join(timeout=self.detection_timeout + 2)
|
||||
if data_thread.is_alive():
|
||||
log.warning(f"{Colors.YELLOW}⚠️ Timeout reached. Stopping detection.{Colors.RESET}")
|
||||
self.running = False
|
||||
except KeyboardInterrupt:
|
||||
log.info(f"{Colors.YELLOW}Detection canceled by user.{Colors.RESET}")
|
||||
self.running = False
|
||||
if __name__ == "__main__":
|
||||
self.disconnect()
|
||||
log.info(f"{Colors.GREEN}Gesture detection complete.{Colors.RESET}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
print(f"{Colors.BG_BLACK}{Colors.CYAN}╔════════════════════════════════════════╗{Colors.RESET}")
|
||||
print(f"{Colors.BG_BLACK}{Colors.CYAN}║ AirPods Head Gesture Detector ║{Colors.RESET}")
|
||||
print(f"{Colors.BG_BLACK}{Colors.CYAN}╚════════════════════════════════════════╝{Colors.RESET}")
|
||||
print(f"\n{Colors.WHITE}This program detects head gestures using AirPods:{Colors.RESET}")
|
||||
print(f"{Colors.GREEN}• YES: {Colors.WHITE}nodding head up and down{Colors.RESET}")
|
||||
print(f"{Colors.RED}• NO: {Colors.WHITE}shaking head left and right{Colors.RESET}\n")
|
||||
|
||||
detector: GestureDetector = GestureDetector()
|
||||
detector.start_detection()
|
||||
@@ -1,123 +0,0 @@
|
||||
import math
|
||||
import numpy as np
|
||||
import logging
|
||||
import os
|
||||
from colors import *
|
||||
from drawille import Canvas
|
||||
from logging import Logger, StreamHandler
|
||||
from matplotlib.animation import FuncAnimation
|
||||
from matplotlib.pyplot import Axes, Figure
|
||||
from numpy.typing import NDArray
|
||||
from os import terminal_size as TerminalSize
|
||||
from typing import Any, Dict, List, Optional, Tuple
|
||||
|
||||
handler: StreamHandler = StreamHandler()
|
||||
handler.setFormatter(ColorFormatter())
|
||||
log: Logger = logging.getLogger(__name__)
|
||||
log.setLevel(logging.INFO)
|
||||
log.addHandler(handler)
|
||||
log.propagate = False
|
||||
|
||||
class HeadOrientation:
|
||||
def __init__(self, use_terminal: bool = False) -> None:
|
||||
self.orientation_offset: int = 5500
|
||||
self.o1_neutral: int = 19000
|
||||
self.o2_neutral: int = 0
|
||||
self.o3_neutral: int = 0
|
||||
self.calibration_samples: List[List[int]] = []
|
||||
self.calibration_complete: bool = False
|
||||
self.calibration_sample_count: int = 10
|
||||
self.fig: Optional[Figure] = None
|
||||
self.ax: Optional[Axes] = None
|
||||
self.arrow: Any = None
|
||||
self.animation: Optional[FuncAnimation] = None
|
||||
self.use_terminal: bool = use_terminal
|
||||
|
||||
def reset_calibration(self) -> None:
|
||||
self.calibration_samples = []
|
||||
self.calibration_complete = False
|
||||
|
||||
def add_calibration_sample(self, orientation_values: List[int]) -> bool:
|
||||
if len(self.calibration_samples) < self.calibration_sample_count:
|
||||
self.calibration_samples.append(orientation_values)
|
||||
return False
|
||||
if not self.calibration_complete:
|
||||
self._calculate_calibration()
|
||||
return True
|
||||
return True
|
||||
|
||||
def _calculate_calibration(self) -> None:
|
||||
if len(self.calibration_samples) < 3:
|
||||
log.warning("Not enough calibration samples")
|
||||
return
|
||||
samples: NDArray[[List[int]]] = np.array(self.calibration_samples)
|
||||
self.o1_neutral: float = np.mean(samples[:, 0])
|
||||
avg_o2: float = np.mean(samples[:, 1])
|
||||
avg_o3: float = np.mean(samples[:, 2])
|
||||
self.o2_neutral: float = avg_o2
|
||||
self.o3_neutral: float = avg_o3
|
||||
log.info("Calibration complete: o1_neutral=%.2f, o2_neutral=%.2f, o3_neutral=%.2f",
|
||||
self.o1_neutral, self.o2_neutral, self.o3_neutral)
|
||||
self.calibration_complete = True
|
||||
|
||||
def calculate_orientation(self, o1: float, o2: float, o3: float) -> Dict[str, float]:
|
||||
if not self.calibration_complete:
|
||||
return {'pitch': 0, 'yaw': 0}
|
||||
o1_norm: float = o1 - self.o1_neutral
|
||||
o2_norm: float = o2 - self.o2_neutral
|
||||
o3_norm: float = o3 - self.o3_neutral
|
||||
pitch: float = (o2_norm + o3_norm) / 2 / 32000 * 180
|
||||
yaw: float = (o2_norm - o3_norm) / 2 / 32000 * 180
|
||||
return {'pitch': pitch, 'yaw': yaw}
|
||||
|
||||
def create_face_art(self, pitch: float, yaw: float) -> str:
|
||||
if self.use_terminal:
|
||||
try:
|
||||
ts: TerminalSize = os.get_terminal_size()
|
||||
width, height = ts.columns, ts.lines * 2
|
||||
except Exception:
|
||||
width, height = 80, 40
|
||||
else:
|
||||
width, height = 80, 40
|
||||
center_x, center_y = width // 2, height // 2
|
||||
radius: int = (min(width, height) // 2 - 2) // 2
|
||||
pitch_rad: float = math.radians(pitch)
|
||||
yaw_rad: float = math.radians(yaw)
|
||||
canvas: Canvas = Canvas()
|
||||
|
||||
def rotate_point(x: float, y: float, z: float, pitch_r: float, yaw_r: float) -> Tuple[int, int]:
|
||||
cos_y, sin_y = math.cos(yaw_r), math.sin(yaw_r)
|
||||
cos_p, sin_p = math.cos(pitch_r), math.sin(pitch_r)
|
||||
x1: float = x * cos_y - z * sin_y
|
||||
z1: float = x * sin_y + z * cos_y
|
||||
y1: float = y * cos_p - z1 * sin_p
|
||||
z2: float = y * sin_p + z1 * cos_p
|
||||
scale: float = 1 + (z2 / width)
|
||||
return int(center_x + x1 * scale), int(center_y + y1 * scale)
|
||||
for angle in range(0, 360, 2):
|
||||
rad: float = math.radians(angle)
|
||||
x: float = radius * math.cos(rad)
|
||||
y: float = radius * math.sin(rad)
|
||||
x1, y1 = rotate_point(x, y, 0, pitch_rad, yaw_rad)
|
||||
canvas.set(x1, y1)
|
||||
for eye in [(-radius//2, -radius//3, 2), (radius//2, -radius//3, 2)]:
|
||||
ex, ey, ez = eye
|
||||
x1, y1 = rotate_point(ex, ey, ez, pitch_rad, yaw_rad)
|
||||
for dx in [-1, 0, 1]:
|
||||
for dy in [-1, 0, 1]:
|
||||
canvas.set(x1 + dx, y1 + dy)
|
||||
nx, ny = rotate_point(0, 0, 1, pitch_rad, yaw_rad)
|
||||
for dx in [-1, 0, 1]:
|
||||
for dy in [-1, 0, 1]:
|
||||
canvas.set(nx + dx, ny + dy)
|
||||
smile_depth: int = radius // 8
|
||||
mouth_local_y: int = radius // 4
|
||||
mouth_length: int = radius
|
||||
for x_offset in range(-mouth_length // 2, mouth_length // 2 + 1):
|
||||
norm: float = abs(x_offset) / (mouth_length / 2)
|
||||
y_offset: int = int((1 - norm ** 2) * smile_depth)
|
||||
local_x: int = x_offset
|
||||
local_y: int = mouth_local_y + y_offset
|
||||
mx, my = rotate_point(local_x, local_y, 0, pitch_rad, yaw_rad)
|
||||
canvas.set(mx, my)
|
||||
return canvas.frame()
|
||||
@@ -1,843 +0,0 @@
|
||||
import asciichartpy as acp
|
||||
import logging
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
import os
|
||||
import struct
|
||||
import time
|
||||
from bluetooth import BluetoothSocket
|
||||
from colors import *
|
||||
from connection_manager import ConnectionManager
|
||||
from datetime import datetime as DateTime
|
||||
from drawille import Canvas
|
||||
from head_orientation import HeadOrientation
|
||||
from logging import Logger, StreamHandler
|
||||
from matplotlib.animation import FuncAnimation
|
||||
from matplotlib.legend import Legend
|
||||
from matplotlib.pyplot import Axes, Figure
|
||||
from numpy.typing import NDArray
|
||||
from rich.live import Live
|
||||
from rich.layout import Layout
|
||||
from rich.panel import Panel
|
||||
from rich.console import Console
|
||||
from threading import Lock, Thread
|
||||
from typing import Any, Dict, List, Optional, TextIO, Tuple, Union
|
||||
|
||||
handler: StreamHandler = StreamHandler()
|
||||
handler.setFormatter(ColorFormatter())
|
||||
logger: Logger = logging.getLogger("airpods-head-tracking")
|
||||
logger.setLevel(logging.INFO)
|
||||
logger.addHandler(handler)
|
||||
logger.propagate = True
|
||||
|
||||
INIT_CMD: str = "00 00 04 00 01 00 02 00 00 00 00 00 00 00 00 00"
|
||||
NOTIF_CMD: str = "04 00 04 00 0F 00 FF FF FE FF"
|
||||
START_CMD: str = "04 00 04 00 17 00 00 00 10 00 10 00 08 A1 02 42 0B 08 0E 10 02 1A 05 01 40 9C 00 00"
|
||||
STOP_CMD: str = "04 00 04 00 17 00 00 00 10 00 11 00 08 7E 10 02 42 0B 08 4E 10 02 1A 05 01 00 00 00 00"
|
||||
|
||||
KEY_FIELDS: Dict[str, Tuple[int, int]] = {
|
||||
"orientation 1": (43, 2),
|
||||
"orientation 2": (45, 2),
|
||||
"orientation 3": (47, 2),
|
||||
|
||||
"Horizontal Acceleration": (51, 2),
|
||||
"Vertical Acceleration": (53, 2),
|
||||
|
||||
"unkown 1": (61, 2),
|
||||
"unkown 2 ": (49, 2),
|
||||
}
|
||||
|
||||
class AirPodsTracker:
|
||||
def __init__(self) -> None:
|
||||
self.sock: BluetoothSocket = None
|
||||
self.recording: bool = False
|
||||
self.log_file: Optional[TextIO] = None
|
||||
self.listener_thread: Optional[Thread] = None
|
||||
self.bt_addr: str = "28:2D:7F:C2:05:5B"
|
||||
self.psm: int = 0x1001
|
||||
self.raw_packets: List[bytes] = []
|
||||
self.parsed_packets: List[bytes] = []
|
||||
self.live_data: List[bytes] = []
|
||||
self.live_plotting: bool = False
|
||||
self.animation: FuncAnimation = None
|
||||
self.fig: Optional[Figure] = None
|
||||
self.axes: Optional[Axes] = None
|
||||
self.lines: Dict[str, Any] = {}
|
||||
self.selected_fields: List[str] = []
|
||||
self.data_lock: Lock = Lock()
|
||||
self.orientation_offset: int = 5500
|
||||
self.use_terminal: bool = True # '--terminal' in sys.argv
|
||||
self.orientation_visualizer: HeadOrientation = HeadOrientation(use_terminal=self.use_terminal)
|
||||
|
||||
self.conn: Optional[ConnectionManager] = None
|
||||
|
||||
def connect(self):
|
||||
try:
|
||||
logger.info("Trying to connect to %s on PSM 0x%04X...", self.bt_addr, self.psm)
|
||||
self.conn = ConnectionManager(self.bt_addr, self.psm, logger=logger)
|
||||
if not self.conn.connect():
|
||||
logger.error("Connection failed via ConnectionManager.")
|
||||
return False
|
||||
self.sock = self.conn.sock
|
||||
self.sock.send(bytes.fromhex(NOTIF_CMD))
|
||||
logger.info("Sent initialization command.")
|
||||
|
||||
self.listener_thread = Thread(target=self.listen, daemon=True)
|
||||
self.listener_thread.start()
|
||||
return True
|
||||
except Exception as e:
|
||||
logger.error("Connection error: %s", e)
|
||||
return False
|
||||
|
||||
def start_tracking(self, duration: Optional[float] = None) -> None:
|
||||
if not self.recording:
|
||||
self.conn.send_start()
|
||||
filename: str = f"head_tracking_{DateTime.now().strftime('%Y%m%d_%H%M%S')}.log"
|
||||
self.log_file = open(filename, "w")
|
||||
self.recording = True
|
||||
logger.info("Recording started. Saving data to %s", filename)
|
||||
|
||||
if duration is not None and duration > 0:
|
||||
def auto_stop() -> None:
|
||||
time.sleep(duration)
|
||||
if self.recording:
|
||||
self.stop_tracking()
|
||||
logger.info("Recording automatically stopped after %s seconds.", duration)
|
||||
|
||||
timer_thread = Thread(target=auto_stop, daemon=True)
|
||||
timer_thread.start()
|
||||
logger.info("Will automatically stop recording after %s seconds.", duration)
|
||||
else:
|
||||
logger.info("Already recording.")
|
||||
|
||||
def stop_tracking(self) -> None:
|
||||
if self.recording:
|
||||
self.conn.send_stop()
|
||||
self.recording = False
|
||||
if self.log_file is not None:
|
||||
self.log_file.close()
|
||||
self.log_file = None
|
||||
logger.info("Recording stopped.")
|
||||
else:
|
||||
logger.info("Not currently recording.")
|
||||
|
||||
def format_hex(self, data: bytes) -> str:
|
||||
hex_str: str = data.hex()
|
||||
return ' '.join(hex_str[i:i + 2] for i in range(0, len(hex_str), 2))
|
||||
|
||||
def parse_raw_packet(self, hex_string: str) -> bytes:
|
||||
return bytes.fromhex(hex_string.replace(" ", ""))
|
||||
|
||||
def interpret_bytes(self, raw_bytes: bytes, start: int, length: int, data_type: str = "signed_short") -> Optional[Union[int, float]]:
|
||||
if start + length > len(raw_bytes):
|
||||
return None
|
||||
|
||||
match data_type:
|
||||
case "signed_short":
|
||||
return int.from_bytes(raw_bytes[start:start + 2], byteorder='little', signed=True)
|
||||
case "unsigned_short":
|
||||
return int.from_bytes(raw_bytes[start:start + 2], byteorder='little', signed=False)
|
||||
case "signed_short_be":
|
||||
return int.from_bytes(raw_bytes[start:start + 2], byteorder='big', signed=True)
|
||||
case "float_le":
|
||||
if start + 4 <= len(raw_bytes):
|
||||
return struct.unpack('<f', raw_bytes[start:start + 4])[0]
|
||||
case "float_be":
|
||||
if start + 4 <= len(raw_bytes):
|
||||
return struct.unpack('>f', raw_bytes[start:start + 4])[0]
|
||||
case _:
|
||||
return None
|
||||
|
||||
def normalize_orientation(self, value: Optional[Union[int, float]], field_name: str) -> Optional[Union[int, float]]:
|
||||
if 'orientation' in field_name.lower():
|
||||
return value + self.orientation_offset
|
||||
|
||||
return value
|
||||
|
||||
def parse_packet_all_fields(self, raw_bytes: bytes) -> Dict[str, Union[int, float]]:
|
||||
packet: Dict[str, Union[int, float]] = {}
|
||||
|
||||
packet["seq_num"] = int.from_bytes(raw_bytes[12:14], byteorder='little')
|
||||
|
||||
for field_name, (start, length) in KEY_FIELDS.items():
|
||||
if field_name == "float_val" and start + 4 <= len(raw_bytes):
|
||||
packet[field_name] = self.interpret_bytes(raw_bytes, start, 4, "float_le")
|
||||
else:
|
||||
raw_value = self.interpret_bytes(raw_bytes, start, length, "signed_short")
|
||||
if raw_value is not None:
|
||||
packet[field_name] = self.normalize_orientation(raw_value, field_name)
|
||||
|
||||
for i in range(30, min(90, len(raw_bytes) - 1), 2):
|
||||
field_name: str = f"byte_{i:02d}"
|
||||
raw_value: Optional[Union[int, float]] = self.interpret_bytes(raw_bytes, i, 2, "signed_short")
|
||||
if raw_value is not None:
|
||||
packet[field_name] = self.normalize_orientation(raw_value, field_name)
|
||||
|
||||
return packet
|
||||
|
||||
def apply_dark_theme(self, fig: Figure, axes: List[Axes]) -> None:
|
||||
fig.patch.set_facecolor('#1e1e1e')
|
||||
for ax in axes:
|
||||
ax.set_facecolor('#2d2d2d')
|
||||
|
||||
ax.title.set_color('white')
|
||||
ax.xaxis.label.set_color('white')
|
||||
ax.yaxis.label.set_color('white')
|
||||
ax.tick_params(colors='white')
|
||||
ax.tick_params(axis='x', colors='white')
|
||||
ax.tick_params(axis='y', colors='white')
|
||||
|
||||
ax.grid(True, color='#555555', alpha=0.3, linestyle='--')
|
||||
|
||||
for spine in ax.spines.values():
|
||||
spine.set_color('#555555')
|
||||
|
||||
legend: Optional[Legend] = ax.get_legend()
|
||||
if (legend):
|
||||
legend.get_frame().set_facecolor('#2d2d2d')
|
||||
legend.get_frame().set_alpha(0.7)
|
||||
for text in legend.get_texts():
|
||||
text.set_color('white')
|
||||
|
||||
def listen(self) -> None:
|
||||
while True:
|
||||
try:
|
||||
data: bytes = self.sock.recv(1024)
|
||||
formatted: str = self.format_hex(data)
|
||||
timestamp: str = DateTime.now().isoformat()
|
||||
|
||||
is_valid: bool = self.is_valid_tracking_packet(formatted)
|
||||
|
||||
if not self.live_plotting:
|
||||
if is_valid:
|
||||
logger.info("%s - Response: %s...", timestamp, formatted[:60])
|
||||
else:
|
||||
logger.info("%s - Skipped non-tracking packet.", timestamp)
|
||||
|
||||
if is_valid:
|
||||
if self.recording and self.log_file is not None:
|
||||
self.log_file.write(formatted + "\n")
|
||||
self.log_file.flush()
|
||||
|
||||
try:
|
||||
raw_bytes: bytes = self.parse_raw_packet(formatted)
|
||||
packet: Dict[str, Union[int, float]] = self.parse_packet_all_fields(raw_bytes)
|
||||
|
||||
with self.data_lock:
|
||||
self.live_data.append(packet)
|
||||
if len(self.live_data) > 300:
|
||||
self.live_data.pop(0)
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error parsing packet: {e}")
|
||||
|
||||
except Exception as e:
|
||||
logger.error("Error receiving data: %s", e)
|
||||
break
|
||||
|
||||
def load_log_file(self, filepath: str) -> bool:
|
||||
self.raw_packets = []
|
||||
self.parsed_packets = []
|
||||
try:
|
||||
with open(filepath, 'r') as f:
|
||||
for line in f:
|
||||
line = line.strip()
|
||||
if line:
|
||||
try:
|
||||
raw_bytes: bytes = self.parse_raw_packet(line)
|
||||
self.raw_packets.append(raw_bytes)
|
||||
packet: Dict[str, Union[int, float]] = self.parse_packet_all_fields(raw_bytes)
|
||||
|
||||
min_seq_num: int = min(
|
||||
[parsed_packet["seq_num"] for parsed_packet in self.parsed_packets], default=0
|
||||
)
|
||||
|
||||
if packet["seq_num"] > min_seq_num:
|
||||
self.parsed_packets.append(packet)
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error parsing line: {e}")
|
||||
|
||||
logger.info(f"Loaded {len(self.parsed_packets)} packets from {filepath}")
|
||||
return True
|
||||
except Exception as e:
|
||||
logger.error(f"Error loading log file: {e}")
|
||||
return False
|
||||
|
||||
def extract_field_values(self, field_name: str, data_source: str = 'loaded') -> List[Union[int, float]]:
|
||||
if data_source == 'loaded':
|
||||
data: List[Dict[str, Union[int, float]]] = self.parsed_packets
|
||||
else:
|
||||
with self.data_lock:
|
||||
data: List[Dict[str, Union[int, float]]] = self.live_data.copy()
|
||||
|
||||
values: List[Union[int, float]] = [packet.get(field_name, 0) for packet in data if field_name in packet]
|
||||
|
||||
if data_source == 'live' and len(values) > 5:
|
||||
try:
|
||||
values: NDArray[Any] = np.array(values, dtype=float)
|
||||
values = np.convolve(values, np.ones(5) / 5, mode='valid')
|
||||
except Exception as e:
|
||||
logger.warning(f"Smoothing error (non-critical): {e}")
|
||||
|
||||
return values
|
||||
|
||||
def is_valid_tracking_packet(self, hex_string: str) -> bool:
|
||||
standard_header: str = "04 00 04 00 17 00 00 00 10 00"
|
||||
|
||||
if not hex_string.startswith(standard_header):
|
||||
if self.live_plotting:
|
||||
logger.warning("Invalid packet header: %s", hex_string[:30])
|
||||
return False
|
||||
|
||||
if len(hex_string.split()) < 80:
|
||||
if self.live_plotting:
|
||||
logger.warning("Invalid packet length: %s", hex_string[:30])
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def plot_fields(self, field_names: Optional[List[str]] = None) -> None:
|
||||
if not self.parsed_packets:
|
||||
logger.error("No data to plot. Load a log file first.")
|
||||
return
|
||||
|
||||
if field_names is None:
|
||||
field_names: List[str] = list(KEY_FIELDS.keys())
|
||||
|
||||
if not self.orientation_visualizer.calibration_complete:
|
||||
if len(self.parsed_packets) < self.orientation_visualizer.calibration_sample_count:
|
||||
logger.error("Not enough packets for calibration. Need at least 10 packets.")
|
||||
return
|
||||
for packet in self.parsed_packets[:self.orientation_visualizer.calibration_sample_count]:
|
||||
self.orientation_visualizer.add_calibration_sample([
|
||||
packet.get('orientation 1', 0),
|
||||
packet.get('orientation 2', 0),
|
||||
packet.get('orientation 3', 0)
|
||||
])
|
||||
|
||||
if self.use_terminal:
|
||||
self._plot_fields_terminal(field_names)
|
||||
|
||||
else:
|
||||
acceleration_fields: List[str] = [f for f in field_names if 'acceleration' in f.lower()]
|
||||
orientation_fields: List[str] = [f for f in field_names if 'orientation' in f.lower()]
|
||||
other_fields: List[str] = [f for f in field_names if f not in acceleration_fields + orientation_fields]
|
||||
|
||||
fig, axes = plt.subplots(3, 1, figsize=(14, 12), sharex=True)
|
||||
self.apply_dark_theme(fig, axes)
|
||||
|
||||
acceleration_colors: List[str] = ['#FFFF00', '#00FFFF']
|
||||
orientation_colors: List[str] = ['#FF00FF', '#00FF00', '#FFA500']
|
||||
other_colors: List[str] = ['#52b788', '#f4a261', '#e76f51', '#2a9d8f']
|
||||
|
||||
if acceleration_fields:
|
||||
for i, field in enumerate(acceleration_fields):
|
||||
values = self.extract_field_values(field)
|
||||
axes[0].plot(values, label=field, color=acceleration_colors[i % len(acceleration_colors)], linewidth=2)
|
||||
axes[0].set_title("Acceleration Data", fontsize=14)
|
||||
axes[0].legend()
|
||||
|
||||
if orientation_fields:
|
||||
for i, field in enumerate(orientation_fields):
|
||||
values = self.extract_field_values(field)
|
||||
axes[1].plot(values, label=field, color=orientation_colors[i % len(orientation_colors)], linewidth=2)
|
||||
axes[1].set_title("Orientation Data", fontsize=14)
|
||||
axes[1].legend()
|
||||
|
||||
if other_fields:
|
||||
for i, field in enumerate(other_fields):
|
||||
values = self.extract_field_values(field)
|
||||
axes[2].plot(values, label=field, color=other_colors[i % len(other_colors)], linewidth=2)
|
||||
axes[2].set_title("Other Fields", fontsize=14)
|
||||
axes[2].legend()
|
||||
|
||||
plt.xlabel("Packet Index", fontsize=12)
|
||||
plt.tight_layout()
|
||||
plt.show()
|
||||
|
||||
def _plot_fields_terminal(self, field_names: List[str]) -> None:
|
||||
"""Internal method for terminal-based plotting"""
|
||||
terminal_width: int = os.get_terminal_size().columns
|
||||
plot_width: int = min(terminal_width - 10, 120)
|
||||
plot_height: int = 15
|
||||
|
||||
acceleration_fields: List[str] = [f for f in field_names if 'acceleration' in f.lower()]
|
||||
orientation_fields: List[str] = [f for f in field_names if 'orientation' in f.lower()]
|
||||
other_fields: List[str] = [f for f in field_names if f not in acceleration_fields + orientation_fields]
|
||||
|
||||
def plot_group(fields: List[str], title: str) -> None:
|
||||
if not fields:
|
||||
return
|
||||
|
||||
print(f"\n{title}")
|
||||
print("=" * len(title))
|
||||
|
||||
for field in fields:
|
||||
values: List[float] = self.extract_field_values(field)
|
||||
if len(values) > plot_width:
|
||||
values = values[-plot_width:]
|
||||
|
||||
if title == "Acceleration Data":
|
||||
chart: str = acp.plot(values, {'height': plot_height})
|
||||
print(chart)
|
||||
else:
|
||||
chart: str = acp.plot(values, {'height': plot_height})
|
||||
print(chart)
|
||||
|
||||
print(f"Min: {min(values):.2f}, Max: {max(values):.2f}, " + f"Mean: {np.mean(values):.2f}")
|
||||
print()
|
||||
|
||||
plot_group(acceleration_fields, "Acceleration Data")
|
||||
plot_group(orientation_fields, "Orientation Data")
|
||||
plot_group(other_fields, "Other Fields")
|
||||
|
||||
def create_braille_plot(self, values: List[float], width: int = 80, height: int = 20, y_label: bool = True, fixed_y_min: Optional[float] = None, fixed_y_max: Optional[float] = None) -> str:
|
||||
canvas: Canvas = Canvas()
|
||||
if fixed_y_min is None or fixed_y_max is None:
|
||||
local_min, local_max = min(values), max(values)
|
||||
else:
|
||||
local_min, local_max = fixed_y_min, fixed_y_max
|
||||
y_range: float = local_max - local_min or 1
|
||||
x_step: int = max(1, len(values) // width)
|
||||
for i, v in enumerate(values[::x_step]):
|
||||
y: int = int(((v - local_min) / y_range) * (height * 2 - 1))
|
||||
canvas.set(i, y)
|
||||
frame: str = canvas.frame()
|
||||
if y_label:
|
||||
lines: List[str] = frame.split('\n')
|
||||
labeled_lines: List[str] = []
|
||||
for idx, line in enumerate(lines):
|
||||
if idx == 0:
|
||||
labeled_lines.append(f"{local_max:6.0f} {line}")
|
||||
elif idx == len(lines)-1:
|
||||
labeled_lines.append(f"{local_min:6.0f} {line}")
|
||||
else:
|
||||
labeled_lines.append(" " + line)
|
||||
frame = "\n".join(labeled_lines)
|
||||
return frame
|
||||
|
||||
def _start_live_plotting_terminal(self, record_data: bool = False, duration: Optional[float] = None) -> None:
|
||||
import sys, select, tty, termios
|
||||
old_settings = termios.tcgetattr(sys.stdin)
|
||||
tty.setcbreak(sys.stdin.fileno())
|
||||
console: Console = Console()
|
||||
term_width: int = console.width
|
||||
plot_width: int = round(min(term_width / 2 - 15, 120))
|
||||
ori_height: int = 10
|
||||
|
||||
def make_compact_layout() -> Layout:
|
||||
layout: Layout = Layout()
|
||||
layout.split_column(
|
||||
Layout(name="header", size=3),
|
||||
Layout(name="main", ratio=1),
|
||||
)
|
||||
layout["main"].split_row(
|
||||
Layout(name="accelerations", ratio=1),
|
||||
Layout(name="orientations", ratio=1)
|
||||
)
|
||||
layout["accelerations"].split_column(
|
||||
Layout(name="vertical", ratio=1),
|
||||
Layout(name="horizontal", ratio=1)
|
||||
)
|
||||
layout["orientations"].split_column(
|
||||
Layout(name="face", ratio=1),
|
||||
Layout(name="raw", ratio=1)
|
||||
)
|
||||
return layout
|
||||
|
||||
layout: Layout = make_compact_layout()
|
||||
|
||||
try:
|
||||
import time
|
||||
with Live(layout, refresh_per_second=20, screen=True) as live:
|
||||
while True:
|
||||
if sys.stdin in select.select([sys.stdin], [], [], 0)[0]:
|
||||
ch = sys.stdin.read(1)
|
||||
if ch == 'p':
|
||||
self.paused = not self.paused
|
||||
logger.info("Paused" if self.paused else "Resumed")
|
||||
if self.paused:
|
||||
time.sleep(0.1)
|
||||
rec_str: str = " [red][REC][/red]" if record_data else ""
|
||||
left: str = "AirPods Head Tracking - v1.0.0"
|
||||
right: str = "Ctrl+C - Close | p - Pause" + rec_str
|
||||
status: str = "[bold red]Paused[/bold red]"
|
||||
header: List[str] = list(" " * term_width)
|
||||
header[0:len(left)] = list(left)
|
||||
header[term_width - len(right):] = list(right)
|
||||
start: int = (term_width - len(status)) // 2
|
||||
header[start:start+len(status)] = list(status)
|
||||
header_text: str = "".join(header)
|
||||
layout["header"].update(Panel(header_text, style="bold white on black"))
|
||||
continue
|
||||
|
||||
with self.data_lock:
|
||||
if len(self.live_data) < 1:
|
||||
continue
|
||||
latest: Dict[str, float] = self.live_data[-1]
|
||||
data: List[Dict[str, float]] = self.live_data[-plot_width:]
|
||||
|
||||
if not self.orientation_visualizer.calibration_complete:
|
||||
sample: List[float] = [
|
||||
latest.get('orientation 1', 0),
|
||||
latest.get('orientation 2', 0),
|
||||
latest.get('orientation 3', 0)
|
||||
]
|
||||
self.orientation_visualizer.add_calibration_sample(sample)
|
||||
time.sleep(0.05)
|
||||
rec_str: str = " [red][REC][/red]" if record_data else ""
|
||||
|
||||
left: str = "AirPods Head Tracking - v1.0.0"
|
||||
status: str = "[bold yellow]Calibrating...[/bold yellow]"
|
||||
right: str = "Ctrl+C - Close | p - Pause"
|
||||
remaining: int = max(term_width - len(left) - len(right), 0)
|
||||
header_text: str = f"{left}{status.center(remaining)}{right}{rec_str}"
|
||||
layout["header"].update(Panel(header_text, style="bold white on black"))
|
||||
live.refresh()
|
||||
continue
|
||||
|
||||
o1: float = latest.get('orientation 1', 0)
|
||||
o2: float = latest.get('orientation 2', 0)
|
||||
o3: float = latest.get('orientation 3', 0)
|
||||
orientation: Dict[str, float] = self.orientation_visualizer.calculate_orientation(o1, o2, o3)
|
||||
pitch: float = orientation['pitch']
|
||||
yaw: float = orientation['yaw']
|
||||
|
||||
h_accel: List[float] = [p.get('Horizontal Acceleration', 0) for p in data]
|
||||
v_accel: List[float] = [p.get('Vertical Acceleration', 0) for p in data]
|
||||
if len(h_accel) > plot_width:
|
||||
h_accel = h_accel[-plot_width:]
|
||||
if len(v_accel) > plot_width:
|
||||
v_accel = v_accel[-plot_width:]
|
||||
global_min: float = min(min(v_accel), min(h_accel))
|
||||
global_max: float = max(max(v_accel), max(h_accel))
|
||||
config_acc: Dict[str, float] = {'height': 20, 'min': global_min, 'max': global_max}
|
||||
vert_plot: str = acp.plot(v_accel, config_acc)
|
||||
horiz_plot: str = acp.plot(h_accel, config_acc)
|
||||
|
||||
rec_str: str = " [red][REC][/red]" if record_data else ""
|
||||
left: str = "AirPods Head Tracking - v1.0.0"
|
||||
right: str = "Ctrl+C - Close | p - Pause" + rec_str
|
||||
status: str = "[bold green]Live[/bold green]"
|
||||
header: List[str] = list(" " * term_width)
|
||||
header[0:len(left)] = list(left)
|
||||
header[term_width - len(right):] = list(right)
|
||||
start: int = (term_width - len(status)) // 2
|
||||
header[start:start+len(status)] = list(status)
|
||||
header_text: str = "".join(header)
|
||||
layout["header"].update(Panel(header_text, style="bold white on black"))
|
||||
|
||||
face_art: str = self.orientation_visualizer.create_face_art(pitch, yaw)
|
||||
layout["accelerations"]["vertical"].update(Panel(
|
||||
"[bold yellow]Vertical Acceleration[/]\n" +
|
||||
vert_plot + "\n" +
|
||||
f"Cur: {v_accel[-1]:6.1f} | Min: {min(v_accel):6.1f} | Max: {max(v_accel):6.1f}",
|
||||
style="yellow"
|
||||
))
|
||||
layout["accelerations"]["horizontal"].update(Panel(
|
||||
"[bold cyan]Horizontal Acceleration[/]\n" +
|
||||
horiz_plot + "\n" +
|
||||
f"Cur: {h_accel[-1]:6.1f} | Min: {min(h_accel):6.1f} | Max: {max(h_accel):6.1f}",
|
||||
style="cyan"
|
||||
))
|
||||
layout["orientations"]["face"].update(Panel(face_art, title="[green]Orientation - Visualization[/]", style="green"))
|
||||
|
||||
o2_values: List[float] = [p.get('orientation 2', 0) for p in data[-plot_width:]]
|
||||
o3_values: List[float] = [p.get('orientation 3', 0) for p in data[-plot_width:]]
|
||||
o2_values: List[float] = o2_values[:plot_width]
|
||||
o3_values: List[float] = o3_values[:plot_width]
|
||||
common_min: float = min(min(o2_values), min(o3_values))
|
||||
common_max: float = max(max(o2_values), max(o3_values))
|
||||
config_ori: Dict[str, float] = {'height': ori_height, 'min': common_min, 'max': common_max, 'format': "{:6.0f}"}
|
||||
chart_o2: str = acp.plot(o2_values, config_ori)
|
||||
chart_o3: str = acp.plot(o3_values, config_ori)
|
||||
layout["orientations"]["raw"].update(Panel(
|
||||
"[bold yellow]Orientation 1:[/]\n" + chart_o2 + "\n" +
|
||||
f"Cur: {o2_values[-1]:6.1f} | Min: {min(o2_values):6.1f} | Max: {max(o2_values):6.1f}\n\n" +
|
||||
"[bold green]Orientation 2:[/]\n" + chart_o3 + "\n" +
|
||||
f"Cur: {o3_values[-1]:6.1f} | Min: {min(o3_values):6.1f} | Max: {max(o3_values):6.1f}",
|
||||
title="[cyan]Orientation Raw[/]", style="yellow"
|
||||
))
|
||||
live.refresh()
|
||||
time.sleep(0.05)
|
||||
except KeyboardInterrupt:
|
||||
logger.info("\nStopped.")
|
||||
if record_data:
|
||||
self.stop_tracking()
|
||||
else:
|
||||
if self.sock:
|
||||
self.sock.send(bytes.fromhex(STOP_CMD))
|
||||
finally:
|
||||
termios.tcsetattr(sys.stdin, termios.TCSADRAIN, old_settings)
|
||||
|
||||
def _start_live_plotting(self, record_data: bool = False, duration: Optional[float] = None) -> None:
|
||||
terminal_width: int = os.get_terminal_size().columns
|
||||
plot_width: int = min(terminal_width - 10, 80)
|
||||
plot_height: int = 10
|
||||
|
||||
try:
|
||||
while True:
|
||||
os.system('clear' if os.name == 'posix' else 'cls')
|
||||
with self.data_lock:
|
||||
if len(self.live_data) == 0:
|
||||
print("\nWaiting for data...")
|
||||
time.sleep(0.1)
|
||||
continue
|
||||
|
||||
data: List[Dict[str, float]] = self.live_data[-plot_width:]
|
||||
|
||||
acceleration_fields: List[str] = [f for f in KEY_FIELDS.keys() if 'acceleration' in f.lower()]
|
||||
orientation_fields: List[str] = [f for f in KEY_FIELDS.keys() if 'orientation' in f.lower()]
|
||||
other_fields: List[str] = [f for f in KEY_FIELDS.keys() if f not in acceleration_fields + orientation_fields]
|
||||
|
||||
def plot_group(fields: List[str], title: str) -> None:
|
||||
if not fields:
|
||||
return
|
||||
|
||||
print(f"\n{title}")
|
||||
print("=" * len(title))
|
||||
|
||||
for field in fields:
|
||||
values: List[float] = [packet.get(field, 0) for packet in data if field in packet]
|
||||
if len(values) > 0:
|
||||
chart: str = acp.plot(values, {'height': plot_height})
|
||||
print(chart)
|
||||
print(f"Current: {values[-1]:.2f}, " +
|
||||
f"Min: {min(values):.2f}, Max: {max(values):.2f}")
|
||||
print()
|
||||
|
||||
plot_group(acceleration_fields, "Acceleration Data")
|
||||
plot_group(orientation_fields, "Orientation Data")
|
||||
plot_group(other_fields, "Other Fields")
|
||||
|
||||
print("\nPress Ctrl+C to stop plotting")
|
||||
time.sleep(0.1)
|
||||
|
||||
except KeyboardInterrupt:
|
||||
logger.info("\nLive plotting stopped.")
|
||||
self.sock.send(bytes.fromhex(STOP_CMD))
|
||||
if record_data:
|
||||
self.stop_tracking()
|
||||
self.live_plotting = False
|
||||
|
||||
def start_live_plotting(self, record_data: bool = False, duration: Optional[float] = None) -> None:
|
||||
if self.sock is None:
|
||||
if not self.connect():
|
||||
logger.error("Could not connect to AirPods. Live plotting aborted.")
|
||||
return
|
||||
if not self.recording and record_data:
|
||||
self.start_tracking(duration)
|
||||
logger.info("Recording enabled during live plotting")
|
||||
elif not self.recording:
|
||||
self.sock.send(bytes.fromhex(START_CMD))
|
||||
logger.info("Head tracking started (not recording to file)")
|
||||
with self.data_lock:
|
||||
self.live_data = []
|
||||
self.live_plotting = True
|
||||
self.paused = False
|
||||
if self.use_terminal:
|
||||
self._start_live_plotting_terminal(record_data, duration)
|
||||
else:
|
||||
from matplotlib.gridspec import GridSpec, GridSpecFromSubplotSpec
|
||||
fig: Figure = plt.figure(figsize=(14, 6))
|
||||
gs: GridSpec = GridSpec(1, 2, width_ratios=[1, 1])
|
||||
ax_accel: Axes = fig.add_subplot(gs[0])
|
||||
subgs: GridSpecFromSubplotSpec = GridSpecFromSubplotSpec(2, 1, subplot_spec=gs[1], height_ratios=[2, 1])
|
||||
ax_head_top: Axes = fig.add_subplot(subgs[0], projection='3d')
|
||||
ax_ori: Axes = fig.add_subplot(subgs[1])
|
||||
|
||||
ax_accel.set_title("Acceleration Data")
|
||||
ax_accel.set_xlabel("Packet Index")
|
||||
ax_accel.set_ylabel("Acceleration")
|
||||
ax_accel.legend(loc='upper right', framealpha=0.7)
|
||||
fig.patch.set_facecolor('#1e1e1e')
|
||||
ax_accel.set_facecolor('#2d2d2d')
|
||||
self.apply_dark_theme(fig, [ax_accel, ax_head_top, ax_ori])
|
||||
plt.ion()
|
||||
|
||||
def update_plot(_: int) -> None:
|
||||
with self.data_lock:
|
||||
data: List[Dict[str, float]] = self.live_data.copy()
|
||||
if len(data) == 0:
|
||||
return
|
||||
|
||||
latest: Dict[str, float] = data[-1]
|
||||
|
||||
if not self.orientation_visualizer.calibration_complete:
|
||||
sample: List[float] = [
|
||||
latest.get('orientation 1', 0),
|
||||
latest.get('orientation 2', 0),
|
||||
latest.get('orientation 3', 0)
|
||||
]
|
||||
self.orientation_visualizer.add_calibration_sample(sample)
|
||||
ax_head_top.cla()
|
||||
ax_head_top.text(0.5, 0.5, "Calibrating... please wait", horizontalalignment='center', verticalalignment='center', transform=ax_head_top.transAxes, color='white')
|
||||
fig.canvas.draw_idle()
|
||||
return
|
||||
|
||||
h_accel: List[float] = [p.get('Horizontal Acceleration', 0) for p in data]
|
||||
v_accel: List[float] = [p.get('Vertical Acceleration', 0) for p in data]
|
||||
x_vals: List[int] = list(range(len(h_accel)))
|
||||
ax_accel.cla()
|
||||
ax_accel.plot(x_vals, v_accel, label='Vertical Acceleration', color='#FFFF00', linewidth=2)
|
||||
ax_accel.plot(x_vals, h_accel, label='Horizontal Acceleration', color='#00FFFF', linewidth=2)
|
||||
ax_accel.set_title("Acceleration Data")
|
||||
ax_accel.set_xlabel("Packet Index")
|
||||
ax_accel.set_ylabel("Acceleration")
|
||||
ax_accel.legend(loc='upper right', framealpha=0.7)
|
||||
ax_accel.set_facecolor('#2d2d2d')
|
||||
ax_accel.title.set_color('white')
|
||||
ax_accel.xaxis.label.set_color('white')
|
||||
ax_accel.yaxis.label.set_color('white')
|
||||
|
||||
latest: Dict[str, float] = data[-1]
|
||||
o1: float = latest.get('orientation 1', 0)
|
||||
o2: float = latest.get('orientation 2', 0)
|
||||
o3: float = latest.get('orientation 3', 0)
|
||||
orientation: Dict[str, float] = self.orientation_visualizer.calculate_orientation(o1, o2, o3)
|
||||
pitch: float = orientation['pitch']
|
||||
yaw: float = orientation['yaw']
|
||||
|
||||
ax_head_top.cla()
|
||||
ax_head_top.set_title("Head Orientation")
|
||||
ax_head_top.set_xlim([-1, 1])
|
||||
ax_head_top.set_ylim([-1, 1])
|
||||
ax_head_top.set_zlim([-1, 1])
|
||||
ax_head_top.set_facecolor('#2d2d2d')
|
||||
pitch_rad = np.radians(pitch)
|
||||
yaw_rad = np.radians(yaw)
|
||||
Rz: NDArray[Any] = np.array([
|
||||
[np.cos(yaw_rad), np.sin(yaw_rad), 0],
|
||||
[-np.sin(yaw_rad), np.cos(yaw_rad), 0],
|
||||
[0, 0, 1]
|
||||
])
|
||||
Ry: NDArray[Any] = np.array([
|
||||
[np.cos(pitch_rad), 0, np.sin(pitch_rad)],
|
||||
[0, 1, 0],
|
||||
[-np.sin(pitch_rad), 0, np.cos(pitch_rad)]
|
||||
])
|
||||
R: NDArray[Any] = Rz @ Ry
|
||||
dir_vec: NDArray[Any] = R @ np.array([1, 0, 0])
|
||||
ax_head_top.quiver(0, 0, 0, dir_vec[0], dir_vec[1], dir_vec[2],
|
||||
color='r', length=0.8, linewidth=3)
|
||||
|
||||
ax_ori.cla()
|
||||
o2_values: List[float] = [p.get('orientation 2', 0) for p in data]
|
||||
o3_values: List[float] = [p.get('orientation 3', 0) for p in data]
|
||||
x_range: List[int] = list(range(len(o2_values)))
|
||||
ax_ori.plot(x_range, o2_values, label='Orientation 1', color='red', linewidth=2)
|
||||
ax_ori.plot(x_range, o3_values, label='Orientation 2', color='green', linewidth=2)
|
||||
ax_ori.set_facecolor('#2d2d2d')
|
||||
ax_ori.tick_params(colors='white')
|
||||
ax_ori.set_title("Orientation Raw")
|
||||
ax_ori.legend(facecolor='#2d2d2d', edgecolor='#555555',
|
||||
labelcolor='white', loc='upper right')
|
||||
ax_ori.text(0.95, 0.9, f"Pitch: {pitch:.1f}°\nYaw: {yaw:.1f}°",
|
||||
transform=ax_ori.transAxes, color='white',
|
||||
ha='right', va='top', bbox=dict(facecolor='#2d2d2d', alpha=0.5))
|
||||
fig.canvas.draw_idle()
|
||||
self.animation = FuncAnimation(
|
||||
fig, update_plot,
|
||||
interval=20,
|
||||
blit=False,
|
||||
cache_frame_data=False
|
||||
)
|
||||
plt.show(block=True)
|
||||
self.sock.send(bytes.fromhex(STOP_CMD))
|
||||
logger.info("Stopping head tracking AirPods.")
|
||||
if self.recording and record_data:
|
||||
self.stop_tracking()
|
||||
logger.info("Recording stopped after sending close command")
|
||||
else:
|
||||
logger.info("Live plotting ended (no recording to stop).")
|
||||
self.live_plotting = False
|
||||
self.animation = None
|
||||
plt.ioff()
|
||||
|
||||
def interactive_mode(self) -> None:
|
||||
from prompt_toolkit import PromptSession
|
||||
session: PromptSession = PromptSession("> ")
|
||||
logger.info("\nAirPods Head Tracking Analyzer")
|
||||
print("------------------------------")
|
||||
logger.info("Commands:")
|
||||
print(" connect - connect to your AirPods")
|
||||
print(" start [seconds] - start recording head tracking data, optionally for specified duration")
|
||||
print(" stop - stop recording")
|
||||
print(" load <file> - load and parse a log file")
|
||||
print(" plot - plot all sensor data fields")
|
||||
print(" live [seconds] - start live plotting (without recording), optionally stop recording after seconds")
|
||||
print(" liver [seconds] - start live plotting with recording, optionally stop recording after seconds")
|
||||
print(" gestures - start gesture detection")
|
||||
print(" quit - exit the program")
|
||||
|
||||
while True:
|
||||
try:
|
||||
cmd_input: str = session.prompt("> ")
|
||||
cmd_parts: List[str] = cmd_input.strip().split()
|
||||
if not cmd_parts:
|
||||
continue
|
||||
cmd = cmd_parts[0].lower()
|
||||
match cmd:
|
||||
case "connect":
|
||||
self.connect()
|
||||
case "start":
|
||||
duration = float(cmd_parts[1]) if len(cmd_parts) > 1 else None
|
||||
self.start_tracking(duration)
|
||||
case "stop":
|
||||
self.stop_tracking()
|
||||
case "load":
|
||||
if len(cmd_parts) > 1:
|
||||
self.load_log_file(cmd_parts[1])
|
||||
case "plot":
|
||||
self.plot_fields()
|
||||
case "live":
|
||||
duration = float(cmd_parts[1]) if len(cmd_parts) > 1 else None
|
||||
logger.info("Starting live plotting mode (without recording)%s.",
|
||||
f" for {duration} seconds" if duration else "")
|
||||
self.start_live_plotting(record_data=False, duration=duration)
|
||||
case "liver":
|
||||
duration = float(cmd_parts[1]) if len(cmd_parts) > 1 else None
|
||||
logger.info("Starting live plotting mode WITH recording%s.",
|
||||
f" for {duration} seconds" if duration else "")
|
||||
self.start_live_plotting(record_data=True, duration=duration)
|
||||
case "gestures":
|
||||
from gestures import GestureDetector
|
||||
if self.conn is not None:
|
||||
detector: GestureDetector = GestureDetector(conn=self.conn)
|
||||
else:
|
||||
detector: GestureDetector = GestureDetector()
|
||||
detector.start_detection()
|
||||
case "quit":
|
||||
logger.info("Exiting.")
|
||||
if self.conn != None:
|
||||
self.conn.disconnect()
|
||||
break
|
||||
case "help":
|
||||
logger.info("\nAirPods Head Tracking Analyzer")
|
||||
logger.info("------------------------------")
|
||||
logger.info("Commands:")
|
||||
logger.info(" connect - connect to your AirPods")
|
||||
logger.info(" start [seconds] - start recording head tracking data, optionally for specified duration")
|
||||
logger.info(" stop - stop recording")
|
||||
logger.info(" load <file> - load and parse a log file")
|
||||
logger.info(" plot - plot all sensor data fields")
|
||||
logger.info(" live [seconds] - start live plotting (without recording), optionally stop recording after seconds")
|
||||
logger.info(" liver [seconds] - start live plotting with recording, optionally stop recording after seconds")
|
||||
logger.info(" gestures - start gesture detection")
|
||||
logger.info(" quit - exit the program")
|
||||
case _:
|
||||
logger.info("Unknown command. Type 'help' to see available commands.")
|
||||
except KeyboardInterrupt:
|
||||
logger.info("Use 'quit' to exit.")
|
||||
except EOFError:
|
||||
logger.info("Exiting.")
|
||||
if self.conn != None:
|
||||
self.conn.disconnect()
|
||||
break
|
||||
|
||||
if __name__ == "__main__":
|
||||
import sys
|
||||
tracker: AirPodsTracker = AirPodsTracker()
|
||||
tracker.interactive_mode()
|
||||
@@ -1,6 +0,0 @@
|
||||
drawille
|
||||
numpy
|
||||
pybluez
|
||||
matplotlib
|
||||
asciichartpy
|
||||
rich
|
||||
7
root-module-manual/module.prop
Normal file
7
root-module-manual/module.prop
Normal file
@@ -0,0 +1,7 @@
|
||||
id=librepods
|
||||
name=LibrePods
|
||||
version=v0.2.6
|
||||
versionCode=46
|
||||
author=@kavishdevar
|
||||
description=Installs LibrePods as a system app for granting BLUETOOTH_PRIVILEGED and MODIFY_PHONE_STATE permission for better integraion with android.
|
||||
updateJson=https://raw.githubusercontent.com/kavishdevar/librepods/main/extras/update_nonpatch.json
|
||||
Binary file not shown.
@@ -1,3 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
exec /data/local/tmp/aln_unzip/busybox/busybox-arm64 xz "$@"
|
||||
@@ -1,190 +0,0 @@
|
||||
#!/system/bin/sh
|
||||
|
||||
# Note: these two exec redirs are not strictly POSIX-compliant, so they can be commented out if we notice that it shows a syntax error in some environments (unlikely to happen)
|
||||
|
||||
# Redirect stdout to ui_print otherwise it's not shown
|
||||
exec 1> >(while read -r line; do ui_print "[O] $line"; done)
|
||||
# Redirect stderr to ui_print otherwise it's not shown + ignore useless radare2 warning that clutters the logs
|
||||
exec 2> >(while read -r line; do echo "$line" | grep -qv "Cannot determine entrypoint, using" && ui_print "[E] $line"; done)
|
||||
|
||||
TEMP_DIR="/data/local/tmp/aln_patch"
|
||||
|
||||
# Note: this dir cannot be changed without recompiling radare2 because this prefix are hardcoded inside the radare2 binaries: /data/local/tmp/aln_unzip/org.radare.radare2installer/radare2/
|
||||
UNZIP_DIR="/data/local/tmp/aln_unzip"
|
||||
SOURCE_FILE=""
|
||||
LIBRARY_NAME=""
|
||||
APEX_DIR=false
|
||||
|
||||
# Clean things up if the script crashes or exits
|
||||
trap 'rm -rf "$TEMP_DIR" "$UNZIP_DIR"' EXIT INT TERM
|
||||
|
||||
# https://github.com/Magisk-Modules-Repo/busybox-ndk/blob/master/busybox-arm64
|
||||
BUSYBOX="$UNZIP_DIR/busybox/busybox-arm64"
|
||||
XZ="$UNZIP_DIR/busybox/xz"
|
||||
|
||||
rm -rf "$TEMP_DIR" "$UNZIP_DIR"
|
||||
mkdir -p "$TEMP_DIR" "$UNZIP_DIR"
|
||||
|
||||
# Manually extract the $ZIPFILE to a temporary directory
|
||||
ui_print "Extracting module files..."
|
||||
unzip -d "$UNZIP_DIR" -oq "$ZIPFILE" || {
|
||||
ui_print "Error: Failed to extract module files."
|
||||
abort "Failed to unzip $ZIPFILE"
|
||||
}
|
||||
|
||||
set_perm "$BUSYBOX" 0 0 755
|
||||
set_perm "$XZ" 0 0 755
|
||||
|
||||
# The bundled radare2 is a custom build that works without Termux: https://github.com/devnoname120/radare2/releases/tag/5.9.8-android-aln
|
||||
ui_print "Extracting radare2 to /data/local/tmp/aln_unzip..."
|
||||
$BUSYBOX tar xf "$UNZIP_DIR/radare2-5.9.9-android-aarch64-aln.tar.gz" -C / || {
|
||||
abort "Failed to extract "$UNZIP_DIR/radare2-5.9.9-android-aarch64-aln.tar.gz"."
|
||||
}
|
||||
|
||||
|
||||
if [ "$(uname -m)" = "aarch64" ]; then
|
||||
export LD_LIBRARY_PATH="$UNZIP_DIR/org.radare.radare2installer/radare2/lib:$LD_LIBRARY_PATH"
|
||||
export PATH="$UNZIP_DIR/org.radare.radare2installer/radare2/bin:$PATH"
|
||||
export PATH="$UNZIP_DIR/busybox:$PATH"
|
||||
export RABIN2="$UNZIP_DIR/org.radare.radare2installer/radare2/bin/rabin2"
|
||||
export RADARE2="$UNZIP_DIR/org.radare.radare2installer/radare2/bin/radare2"
|
||||
else
|
||||
abort "arm64 archicture required, arm32 not supported"
|
||||
fi
|
||||
|
||||
set_perm "$RABIN2" 0 0 755
|
||||
set_perm "$RADARE2" 0 0 755
|
||||
|
||||
if [ -f "$RABIN2" ]; then
|
||||
ui_print "rabin2 binary is ready."
|
||||
else
|
||||
ui_print "Error: rabin2 binary not found."
|
||||
abort "rabin2 binary not found."
|
||||
fi
|
||||
|
||||
if [ -f "$RADARE2" ]; then
|
||||
ui_print "radare2 binary is ready."
|
||||
else
|
||||
ui_print "Error: radare2 binary not found."
|
||||
abort "radare2 binary not found."
|
||||
fi
|
||||
|
||||
if [ -f "$BUSYBOX" ]; then
|
||||
ui_print "busybox binary is ready."
|
||||
else
|
||||
ui_print "Error: busybox binary not found."
|
||||
abort "busybox binary not found."
|
||||
fi
|
||||
|
||||
if [ -f "$XZ" ]; then
|
||||
ui_print "xz shim is ready."
|
||||
else
|
||||
ui_print "Error: xz shim not found."
|
||||
abort "xz shim not found."
|
||||
fi
|
||||
|
||||
for lib_path in \
|
||||
"/apex/com.android.btservices/lib64/libbluetooth_jni.so" \
|
||||
"/system/lib64/libbluetooth_jni.so" \
|
||||
"/system/lib64/libbluetooth_qti.so" \
|
||||
"/system_ext/lib64/libbluetooth_qti.so"; do
|
||||
if [ -f "$lib_path" ]; then
|
||||
ui_print "Detected library: $lib_path"
|
||||
[ -z "$SOURCE_FILE" ] && SOURCE_FILE="$lib_path"
|
||||
[ -z "$LIBRARY_NAME" ] && LIBRARY_NAME="$(basename "$lib_path")"
|
||||
fi
|
||||
done
|
||||
|
||||
[ -z "$SOURCE_FILE" ] && {
|
||||
ui_print "Error: No target library found."
|
||||
abort "No target library found."
|
||||
}
|
||||
|
||||
if echo "$LIBRARY_NAME" | grep -q "qti"; then
|
||||
ui_print "ERROR: \"qti\" Bluetooth libraries are NOT supported by the patcher and you won't be able to use aln. Aborting..."
|
||||
abort "Bluetooth driver not compatible."
|
||||
fi
|
||||
|
||||
ui_print "Calculating patch addresses for $SOURCE_FILE..."
|
||||
|
||||
# export R2_LIBDIR="$UNZIP_DIR/radare2-android/libs/arm64-v8a"
|
||||
# export R2_BINDIR="$UNZIP_DIR/radare2-android/bin/arm64-v8a"
|
||||
|
||||
# $RADARE2 -H 1>&2
|
||||
|
||||
# ldd $RABIN2 1>&2
|
||||
# ldd $RADARE2 1>&2
|
||||
|
||||
symbols="$($RABIN2 -q -E "$SOURCE_FILE")" || abort "Failed to extract symbols from $SOURCE_FILE."
|
||||
|
||||
get_symbol_address() {
|
||||
symb_address=$(echo "$symbols" | grep "$1" | cut -d ' ' -f1 | tr -d '\n')
|
||||
[ -n "$symb_address" ] || abort "Failed to obtain address for symbol $1"
|
||||
echo "$symb_address"
|
||||
}
|
||||
|
||||
l2c_fcr_chk_chan_modes_address="$(get_symbol_address 'l2c_fcr_chk_chan_modes')"
|
||||
ui_print " l2c_fcr_chk_chan_modes_address=$l2c_fcr_chk_chan_modes_address"
|
||||
|
||||
l2cu_send_peer_info_req_address="$(get_symbol_address 'l2cu_send_peer_info_req')"
|
||||
ui_print " l2cu_send_peer_info_req_address=$l2cu_send_peer_info_req_address"
|
||||
|
||||
|
||||
cp "$SOURCE_FILE" "$TEMP_DIR"
|
||||
|
||||
ui_print "Patching $LIBRARY_NAME..."
|
||||
|
||||
apply_patch() {
|
||||
$RADARE2 -q -e bin.cache=true -w -c "s $1; wx $2; wci" "$TEMP_DIR/$LIBRARY_NAME" || abort "Failed to apply $1 patch."
|
||||
}
|
||||
|
||||
apply_patch "$l2c_fcr_chk_chan_modes_address" "20008052c0035fd6"
|
||||
apply_patch "$l2cu_send_peer_info_req_address" "c0035fd6"
|
||||
|
||||
if [ -f "$TEMP_DIR/$LIBRARY_NAME" ]; then
|
||||
ui_print "Installing patched file..."
|
||||
|
||||
if echo "$SOURCE_FILE" | grep -q "/system/lib64"; then
|
||||
TARGET_DIR="$MODPATH/system/lib64"
|
||||
elif echo "$SOURCE_FILE" | grep -q "/apex/"; then
|
||||
TARGET_DIR="$MODPATH/system/lib64"
|
||||
APEX_DIR=true
|
||||
else
|
||||
TARGET_DIR="$MODPATH/system/lib"
|
||||
fi
|
||||
|
||||
mkdir -p "$TARGET_DIR"
|
||||
|
||||
cp "$TEMP_DIR/$LIBRARY_NAME" "$TARGET_DIR/$LIBRARY_NAME"
|
||||
set_perm "$TARGET_DIR/$LIBRARY_NAME" 0 0 644
|
||||
ui_print "Patched file installed at $TARGET_DIR/$LIBRARY_NAME"
|
||||
|
||||
if [ "$APEX_DIR" = true ]; then
|
||||
POST_DATA_FS_SCRIPT="$MODPATH/post-data-fs.sh"
|
||||
APEX_LIB_DIR="/apex/com.android.btservices/lib64"
|
||||
MOD_APEX_LIB_DIR="$MODPATH/apex/com.android.btservices/lib64"
|
||||
WORK_DIR="$MODPATH/apex/com.android.btservices/work"
|
||||
|
||||
mkdir -p "$MOD_APEX_LIB_DIR" "$WORK_DIR"
|
||||
|
||||
cp "$TEMP_DIR/$LIBRARY_NAME" "$MOD_APEX_LIB_DIR/$LIBRARY_NAME"
|
||||
set_perm "$MOD_APEX_LIB_DIR/$LIBRARY_NAME" 0 0 644
|
||||
|
||||
cat <<EOF > "$POST_DATA_FS_SCRIPT"
|
||||
#!/system/bin/sh
|
||||
mount -t overlay overlay -o lowerdir=$APEX_LIB_DIR,upperdir=$MOD_APEX_LIB_DIR,workdir=$WORK_DIR $APEX_LIB_DIR
|
||||
EOF
|
||||
|
||||
set_perm "$POST_DATA_FS_SCRIPT" 0 0 755
|
||||
ui_print "Created script for apex library handling."
|
||||
ui_print "You can now restart your device and test aln!"
|
||||
ui_print "Note: If your Bluetooth doesn't work anymore after restarting, then uninstall this module and report the issue at the link below."
|
||||
ui_print "https://github.com/kavishdevar/librepods/issues/new"
|
||||
fi
|
||||
else
|
||||
ui_print "Error: patched file missing."
|
||||
rm -rf "$TEMP_DIR" "$UNZIP_DIR"
|
||||
abort "Failed to patch the library."
|
||||
fi
|
||||
|
||||
rm -rf "$TEMP_DIR" "$UNZIP_DIR"
|
||||
@@ -1,7 +0,0 @@
|
||||
id=btl2capfix
|
||||
name=Bluetooth L2CAP workaround for AirPods
|
||||
version=v3
|
||||
versionCode=3
|
||||
author=@devnoname120 and @kavishdevar
|
||||
description=Fixes the Bluetooth L2CAP connection issue with AirPods
|
||||
updateJson=https://raw.githubusercontent.com/kavishdevar/librepods/main/update.json
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"version": "v0.1.0-rc.4",
|
||||
"versionCode": 3,
|
||||
"zipUrl": "https://github.com/kavishdevar/librepods/releases/download/v0.1.0-rc.4/LibrePods-v0.1.0-rc.4.zip",
|
||||
"changelog": "https://raw.githubusercontent.com/kavishdevar/librepods/main/CHANGELOG.md"
|
||||
}
|
||||
"version": "v0.2.6",
|
||||
"versionCode": 46,
|
||||
"zipUrl": "https://github.com/kavishdevar/librepods/releases/download/v0.2.6/LibrePods-FOSS-v0.2.6-release.zip",
|
||||
"changelog": "https://raw.githubusercontent.com/kavishdevar/librepods/main/extras/CHANGELOG.md"
|
||||
}
|
||||
Reference in New Issue
Block a user