Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wip ]adds bleak #21588

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions packages/bleak/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
TERMUX_PKG_HOMEPAGE=https://github.com/hbldh/bleak
TERMUX_PKG_DESCRIPTION="A cross platform Bluetooth Low Energy Client for Python using asyncio"
TERMUX_PKG_LICENSE="MIT"
TERMUX_PKG_MAINTAINER="@termux"
TERMUX_PKG_VERSION=0.22.2
TERMUX_PKG_SRCURL=https://github.com/hbldh/bleak/archive/refs/tags/v${TERMUX_PKG_VERSION}.tar.gz
TERMUX_PKG_SHA256=89aa893f3fda7f49435ba1cb836ab68180503dd308d23c9e04f667050ce0588c
TERMUX_PKG_AUTO_UPDATE=false
TERMUX_PKG_PYTHON_BUILD_DEPS="poetry"
TERMUX_PKG_DEPENDS="python, pyjnius"
TERMUX_PKG_PLATFORM_INDEPENDENT=true
TERMUX_PKG_BUILD_IN_SRC=true
TERMUX_PKG_ON_DEVICE_BUILD_NOT_SUPPORTED=true

termux_step_pre_configure() {
_ANDROID_JAR="$ANDROID_HOME/platforms/android-28/android.jar"
patch -p1 < "$TERMUX_PKG_BUILDER_DIR/defs.py.diff"
patch -p1 < "$TERMUX_PKG_BUILDER_DIR/utils.py.diff"
patch -p1 < "$TERMUX_PKG_BUILDER_DIR/pyproject.toml.diff"
curl -L https://github.com/hbldh/bleak/pull/1642.diff | patch -p1
curl -L https://github.com/hbldh/bleak/pull/1644.diff | patch -p1
}

termux_step_make() {
javac -encoding UTF-8 -source 1.8 -target 1.8 $(find . -name "*.java") -bootclasspath $_ANDROID_JAR
$ANDROID_HOME/build-tools/33.0.1/d8 $(find . -name "*.class") \
--lib $_ANDROID_JAR \
--release \
--output bleak/backends/p4android
}

termux_step_make_install() {
pip install --no-deps --no-build-isolation . --prefix $TERMUX_PREFIX
}
18 changes: 18 additions & 0 deletions packages/bleak/defs.py.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
diff --git a/bleak/backends/p4android/defs.py b/bleak/backends/p4android/defs.py
index xxxxxxx..yyyyyyy 100644
--- a/bleak/backends/p4android/defs.py
+++ b/bleak/backends/p4android/defs.py
@@ -23,10 +23,10 @@ BluetoothGattCharacteristic = autoclass("android.bluetooth.BluetoothGattCharacte
BluetoothGattDescriptor = autoclass("android.bluetooth.BluetoothGattDescriptor")
BluetoothProfile = autoclass("android.bluetooth.BluetoothProfile")

-PythonActivity = autoclass("org.kivy.android.PythonActivity")
ParcelUuid = autoclass("android.os.ParcelUuid")
-activity = cast("android.app.Activity", PythonActivity.mActivity)
-context = cast("android.content.Context", activity.getApplicationContext())
+PyJNIusService = autoclass('com.termux.api.apis.PyJNIusAPI$PyJNIusService')
+service = PyJNIusService.getServiceInstance()
+context = cast("android.content.Context", service.getApplicationContext())

ScanResult = autoclass("android.bluetooth.le.ScanResult")

9 changes: 9 additions & 0 deletions packages/bleak/pyproject.toml.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
diff --git a/pyproject.toml b/pyproject.toml
index xxxxxxx..yyyyyyy 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -15,6 +15,7 @@ classifiers = [
"Operating System :: MacOS :: MacOS X",
"Operating System :: Android",
]
+include = ["bleak/backends/p4android/classes.dex"]
13 changes: 13 additions & 0 deletions packages/bleak/utils.py.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/bleak/backends/p4android/utils.py b/bleak/backends/p4android/utils.py
index xxxxxxx..yyyyyyy 100644
--- a/bleak/backends/p4android/utils.py
+++ b/bleak/backends/p4android/utils.py
@@ -8,7 +8,7 @@ from ...exc import BleakError
logger = logging.getLogger(__name__)

class AsyncJavaCallbacks(PythonJavaClass):
- __javacontext__ = "app"
+ __javacontext__ = "dex"

def __init__(self, loop: asyncio.AbstractEventLoop):
self._loop = loop
26 changes: 26 additions & 0 deletions packages/pyjnius/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
TERMUX_PKG_HOMEPAGE=https://github.com/kivy/pyjnius
TERMUX_PKG_DESCRIPTION="Access Java classes from Python"
TERMUX_PKG_LICENSE="MIT"
TERMUX_PKG_MAINTAINER="@termux"
TERMUX_PKG_VERSION=1.6.1
TERMUX_PKG_SRCURL=https://github.com/kivy/pyjnius/archive/refs/tags/${TERMUX_PKG_VERSION}.tar.gz
TERMUX_PKG_SHA256=5f14fe3cc0e37fb15dae1ffd6c4c5f7bfec2bfaff0f82af21feec25b4d46c0ef
TERMUX_PKG_AUTO_UPDATE=false
TERMUX_PKG_PYTHON_BUILD_DEPS="poetry"
TERMUX_PKG_PYTHON_COMMON_DEPS="Cython"
TERMUX_PKG_DEPENDS="python"
TERMUX_PKG_BUILD_IN_SRC=true

termux_step_pre_configure() {
_ANDROID_JAR="$ANDROID_HOME/platforms/android-28/android.jar"
curl -L https://github.com/kivy/pyjnius/pull/732.diff | patch -p1
curl -L https://github.com/kivy/pyjnius/pull/733.diff | patch -p1
}

termux_step_make() {
python setup.py sdist
$ANDROID_HOME/build-tools/33.0.1/d8 $(find . -name "*.class") \
--lib $_ANDROID_JAR \
--release \
--output jnius/src/org/jnius/
}
Loading