Skip to content

Implement Sleepy API client with battery tracking and configuration UI - #6

Merged
RhenCloud merged 4 commits into
mainfrom
copilot/enhance-sleepy-client
Feb 21, 2026
Merged

Implement Sleepy API client with battery tracking and configuration UI#6
RhenCloud merged 4 commits into
mainfrom
copilot/enhance-sleepy-client

Conversation

Copilot AI commented Feb 21, 2026

Copy link
Copy Markdown
Contributor

Transforms the basic foreground app monitor into a full Sleepy client that reports device status to a Sleepy server via REST API.

Core Changes

API Integration

  • SleepyApiClient.kt: REST client for /api/device/set endpoint using OkHttp 4.12.0
  • Posts device status: { "id", "secret", "show_name", "using": true, "status": "AppName[80%]⚡️" }
  • 1-second debouncing in ForegroundAppMonitor.executeCustomOperations() to prevent request spam

Configuration Management

  • MainActivity.kt: Material Design UI for server URL, secret, device ID, display name, enable toggle
  • Stores config in system-level SharedPreferences (sleepy_config)
  • Loaded at hook initialization via loadConfiguration()

Battery Tracking

  • Reads battery level and charging state via BatteryManager
  • Formats status as AppName[Battery%]Icon (⚡️ charging / 🔋 not charging)

System Context Access

  • Obtains system context via ActivityThread.currentActivityThread().getSystemContext()
  • Required for PackageManager (app names) and BatteryManager (battery info)

Logging System

  • LogRepository.kt: Multi-level logging (VERBOSE, DEBUG, INFO, WARN, ERROR)
  • Flows to both Xposed logcat and internal log stream

Example Usage

// Configuration stored and loaded from SharedPreferences
Config(
    url = "https://sleepy.example.com/api/device/set",
    secret = "server-secret",
    id = "android-phone",
    showName = "My Phone",
    enabled = true
)

// Sent to server on app switch
{
  "secret": "server-secret",
  "id": "android-phone", 
  "show_name": "My Phone",
  "using": true,
  "status": "Chrome[85%]⚡️"
}

Dependencies Added

  • com.squareup.okhttp3:okhttp:4.12.0
  • com.google.android.material:material:1.11.0
  • androidx.lifecycle:lifecycle-*:2.7.0

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • dl.google.com
    • Triggering command: /usr/lib/jvm/temurin-17-jdk-amd64/bin/java /usr/lib/jvm/temurin-17-jdk-amd64/bin/java --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.invoke=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-opens=java.base/java.nio.charset=ALL-UNNAMED --add-opens=java.base/java.net=ALL-UNNAMED --add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED -Xmx2048m -Dfile.encoding=UTF-8 -Duser.country -Duser.language=en -Duser.variant -cp /home/REDACTED/.gradle/wrapper/dists/gradle-8.0-bin/ca5e32bp14vu59qr306oxotwh/gradle-8.0/lib/gradle-launcher-8.0.jar org.gradle.launcher.daemon.bootstrap.GradleDaemon 8.0 (dns block)
    • Triggering command: /usr/lib/jvm/temurin-17-jdk-amd64/bin/java /usr/lib/jvm/temurin-17-jdk-amd64/bin/java --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.lang.invoke=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.prefs/java.util.prefs=ALL-UNNAMED --add-opens java.prefs/java.util.prefs=ALL-UNNAMED --add-opens java.base/java.nio.charset=ALL-UNNAMED --add-opens java.base/java.net=ALL-UNNAMED --add-opens java.base/java.util.concurrent.atomic=ALL-UNNAMED -Xmx2048m (dns block)
    • Triggering command: /usr/bin/ping ping -c 2 dl.google.com (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 3 commits February 21, 2026 17:56
Co-authored-by: RhenCloud <111980217+RhenCloud@users.noreply.github.com>
Co-authored-by: RhenCloud <111980217+RhenCloud@users.noreply.github.com>
Co-authored-by: RhenCloud <111980217+RhenCloud@users.noreply.github.com>
Copilot AI changed the title [WIP] Enhance project to be a Sleepy client Implement Sleepy API client with battery tracking and configuration UI Feb 21, 2026
Copilot AI requested a review from RhenCloud February 21, 2026 18:01
@RhenCloud
RhenCloud marked this pull request as ready for review February 21, 2026 18:17
@RhenCloud
RhenCloud merged commit 5380665 into main Feb 21, 2026
1 check failed
@RhenCloud
RhenCloud deleted the copilot/enhance-sleepy-client branch February 21, 2026 18:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants