Skip to content

Commit

Permalink
working on emulator
Browse files Browse the repository at this point in the history
  • Loading branch information
trbutler4 committed Sep 15, 2024
1 parent dba0c73 commit 26c5b6c
Show file tree
Hide file tree
Showing 22 changed files with 227 additions and 7 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
4 changes: 2 additions & 2 deletions examples/rust-example/android/.gradle/config.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#Tue Aug 06 06:20:19 CDT 2024
java.home=/snap/android-studio/161/jbr
#Sun Sep 15 17:30:36 CDT 2024
java.home=/usr/local/android-studio/jbr
Binary file modified examples/rust-example/android/.gradle/file-system.probe
Binary file not shown.
66 changes: 66 additions & 0 deletions examples/rust-example/android/.idea/other.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions examples/rust-example/android/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions examples/serviceexample/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions lightclientservice/.idea/deploymentTargetSelector.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 13 additions & 2 deletions lightclientservice/app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import org.jetbrains.kotlin.cli.jvm.main

plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.jetbrains.kotlin.android)
}

android {
namespace = "com.example.lightclientservice"
namespace = "com.snphone.lightclientservice"
compileSdk = 34

defaultConfig {
applicationId = "com.example.lightclientservice"
applicationId = "com.snphone.lightclientservice"
minSdk = 24
targetSdk = 34
versionCode = 1
Expand All @@ -33,13 +35,22 @@ android {
kotlinOptions {
jvmTarget = "1.8"
}

sourceSets {
named("main") {
jniLibs.srcDir("src/main/jniLibs/")
}
}

}

dependencies {

implementation(libs.androidx.core.ktx)
implementation(libs.androidx.appcompat)
implementation(libs.material)
implementation(libs.androidx.activity)
implementation(libs.androidx.constraintlayout)
testImplementation(libs.junit)
androidTestImplementation(libs.androidx.junit)
androidTestImplementation(libs.androidx.espresso.core)
Expand Down
11 changes: 10 additions & 1 deletion lightclientservice/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,19 @@
android:supportsRtl="true"
android:theme="@style/Theme.LightClientService"
tools:targetApi="31">
<activity
android:name="com.snphone.lightclientservice.MainActivity"
android:exported="true" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<service
android:name=".BeerusService"
android:enabled="true"
android:exported="true"></service>
android:exported="true" />
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

public class BeerusClient {

/**
* @param ethExecutionRpc
* @param starknetRpc
* @return
*/
public static native String run(String ethExecutionRpc, String starknetRpc);

static {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,68 @@ package com.snphone.lightclientservice

import android.app.Service
import android.content.Intent
import android.os.Handler
import android.os.HandlerThread
import android.os.IBinder
import android.os.Looper
import android.os.Message
import android.widget.Toast
import android.os.Process

class BeerusService : Service() {

override fun onBind(intent: Intent): IBinder {
TODO("Return the communication channel to the service.")
private var serviceLooper: Looper? = null
private var serviceHandler: ServiceHandler? = null

// this is what receives messages from the thread and dictates what work is done
private inner class ServiceHandler(looper: Looper): Handler(looper) {
override fun handleMessage(msg: Message) {
try {
val runResponse = BeerusClient.run("TODO", "TODO")
println(runResponse)
Thread.sleep(5000)
} catch (e: InterruptedException) {
Thread.currentThread().interrupt()
}

// stop the service so that we dont stop it in the middle of handling another job
stopSelf(msg.arg1)
}
}

override fun onCreate() {
// Starting up the thread that runs the service. Note that this creates
// a seperate thread because the service normally runs in the process's
// main thread, which we dont want to block. We also make it background
// priority so CPU-intensive work wil not disrupt our UI.
HandlerThread("ServiceStartArguments", Process.THREAD_PRIORITY_BACKGROUND).apply {
start()

// getting the HandlerThread's Looper and using it for out Handler
serviceLooper = looper
serviceHandler = ServiceHandler(looper)
}
}

override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
Toast.makeText(this, "service starting", Toast.LENGTH_SHORT).show()

// For each start request, send a message to start a job and deliver the
// start id so we know which request we're stopping when we finish the job
serviceHandler?.obtainMessage()?.also { msg ->
msg.arg1 = startId
serviceHandler?.sendMessage(msg)
}

// if we get killed, after returning from here, restart
return START_STICKY
}

override fun onBind(intent: Intent): IBinder? {
return null
}

override fun onDestroy() {
Toast.makeText(this, "service done", Toast.LENGTH_SHORT).show()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.snphone.lightclientservice

import android.content.Intent
import android.os.Bundle
import android.widget.Button
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity

class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
setContentView(R.layout.activity_main)

val startServiceButton: Button = findViewById(R.id.startServiceButton)
startServiceButton.setOnClickListener {
println("Attempting to start the service...")
// Create an intent to start the service
val serviceIntent = Intent(this, BeerusService::class.java)
// Start the service
startService(serviceIntent)
println("service started?")
}
}
}
Binary file not shown.
26 changes: 26 additions & 0 deletions lightclientservice/app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.snphone.lightclientservice.MainActivity">

<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
>

<Button
android:id="@+id/startServiceButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/start_service"
android:layout_centerInParent="true"
/>

</androidx.coordinatorlayout.widget.CoordinatorLayout>

</androidx.constraintlayout.widget.ConstraintLayout>
1 change: 1 addition & 0 deletions lightclientservice/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<resources>
<string name="app_name">light client service</string>
<string name="start_service">Start Service</string>
</resources>
4 changes: 4 additions & 0 deletions lightclientservice/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ junitVersion = "1.2.1"
espressoCore = "3.6.1"
appcompat = "1.7.0"
material = "1.12.0"
activity = "1.9.2"
constraintlayout = "2.1.4"

[libraries]
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
Expand All @@ -15,6 +17,8 @@ androidx-junit = { group = "androidx.test.ext", name = "junit", version.ref = "j
androidx-espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espressoCore" }
androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "appcompat" }
material = { group = "com.google.android.material", name = "material", version.ref = "material" }
androidx-activity = { group = "androidx.activity", name = "activity", version.ref = "activity" }
androidx-constraintlayout = { group = "androidx.constraintlayout", name = "constraintlayout", version.ref = "constraintlayout" }

[plugins]
android-application = { id = "com.android.application", version.ref = "agp" }
Expand Down

0 comments on commit 26c5b6c

Please sign in to comment.