Dala.Setup.Android (dala v0.0.12)

Copy Markdown View Source

Android Bluetooth/WiFi setup automation for Dala.

This module provides automated setup for Android Bluetooth and WiFi functionality by configuring the AndroidManifest.xml with required permissions and features, and ensuring DalaBridge.init() is called in the MainActivity.

Usage

From the command line (via Mix task):

mix dala.setup_bluetooth_wifi --platform android

From Elixir code:

Dala.Setup.Android.setup_bluetooth()
Dala.Setup.Android.setup_bluetooth("/path/to/android/directory")

What it does

  1. Finds AndroidManifest.xml in the android/ directory
  2. Adds required Bluetooth permissions:
    • BLUETOOTH
    • BLUETOOTH_ADMIN
    • BLUETOOTH_SCAN
    • BLUETOOTH_CONNECT
    • ACCESS_FINE_LOCATION
  3. Adds required WiFi permissions:
    • ACCESS_WIFI_STATE
    • CHANGE_WIFI_STATE
  4. Adds uses-feature for bluetooth_le with required=false
  5. Ensures DalaBridge.init() is called in MainActivity

Prerequisites

  • Android project must exist with an AndroidManifest.xml
  • DalaBridge.java should be present in the project

Summary

Functions

Add DalaBridge.init() call to the given Java/Kotlin file.

Check if DalaBridge.java exists in the project.

Check if DalaBridge.init() is called in the project.

Find Java/Kotlin source files in the Android project.

Find the AndroidManifest.xml path.

Check if AndroidManifest.xml exists in the project.

Print setup instructions without making changes.

Run the Android Bluetooth setup.

Run the Android WiFi setup.

Types

result()

@type result() :: {:ok, String.t()} | {:error, String.t()}

Functions

add_dala_bridge_init(file_path)

@spec add_dala_bridge_init(String.t()) :: :ok | {:error, String.t()}

Add DalaBridge.init() call to the given Java/Kotlin file.

Inserts the init call into the onCreate method. If no onCreate method exists, prints instructions for manual addition.

Returns :ok on success, {:error, reason} on failure.

bluetooth_files_present?()

@spec bluetooth_files_present?() :: boolean()

Check if DalaBridge.java exists in the project.

ensure_bridge_init()

@spec ensure_bridge_init() :: :ok | {:error, String.t()}

Check if DalaBridge.init() is called in the project.

Looks for the init call in MainActivity or Application class files. If not found, prints instructions for adding it. Optionally tries to add it automatically if the file is found.

find_java_files()

@spec find_java_files() :: [String.t()]

Find Java/Kotlin source files in the Android project.

Searches both common Android project layouts for .java and .kt files.

find_manifest()

@spec find_manifest() :: String.t() | nil

Find the AndroidManifest.xml path.

Searches both common Android project layouts:

  • android/src/main/AndroidManifest.xml
  • android/app/src/main/AndroidManifest.xml

Returns the path if found, nil otherwise.

manifest_present?()

@spec manifest_present?() :: boolean()

Check if AndroidManifest.xml exists in the project.

setup_bluetooth(android_dir \\ nil)

@spec setup_bluetooth(String.t() | nil) :: result()

Run the Android Bluetooth setup.

Adds Bluetooth permissions and features to AndroidManifest.xml. Idempotent — will not duplicate entries.

Returns {:ok, message} on success, {:error, reason} on failure.

setup_wifi(android_dir \\ nil)

@spec setup_wifi(String.t() | nil) :: result()

Run the Android WiFi setup.

Adds WiFi permissions to AndroidManifest.xml. Idempotent — will not duplicate entries.

Returns {:ok, message} on success, {:error, reason} on failure.