Skip to content

Commit

Permalink
App: Fix broken coding conventions
Browse files Browse the repository at this point in the history
This is a trivial patch that fixes broken coding conventions.

Signed-off-by: Wook Song <[email protected]>
  • Loading branch information
wooksong authored and niley7464 committed Jul 3, 2024
1 parent 6a49e07 commit 2138e14
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 46 deletions.
35 changes: 18 additions & 17 deletions ml_inference_offloading/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_SPECIAL_USE"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_SPECIAL_USE" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

<application android:name=".App"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Nnstreamerandroid">
<application
android:name=".App"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Nnstreamerandroid">

<service
android:name=".MainService"
android:enabled="true"
android:exported="true"
android:foregroundServiceType="specialUse" />
android:name=".MainService"
android:enabled="true"
android:exported="true"
android:foregroundServiceType="specialUse" />

<activity
android:name=".MainActivity"
android:exported="true"
android:label="@string/title_activity_main"
android:theme="@style/Theme.Nnstreamerandroid">
android:name=".MainActivity"
android:exported="true"
android:label="@string/title_activity_main"
android:theme="@style/Theme.Nnstreamerandroid">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand All @@ -34,4 +35,4 @@
</activity>
</application>

</manifest>
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ class MainActivity : ComponentActivity() {
}
}

inner class ModelAdapter(private val modelInfos: ArrayList<ModelInfo>) : RecyclerView.Adapter<ModelViewHolder>() {
inner class ModelAdapter(private val modelInfos: ArrayList<ModelInfo>) :
RecyclerView.Adapter<ModelViewHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ModelViewHolder {
val inflater = LayoutInflater.from(parent.context)
val view = inflater.inflate(R.layout.models, parent, false)
Expand Down Expand Up @@ -102,8 +103,7 @@ class MainActivity : ComponentActivity() {
stream.copyTo(it)
}
}
}
catch (e: IOException) {
} catch (e: IOException) {
Log.e(TAG, "Failed to copy file: $fileName")
e.printStackTrace()
return
Expand Down Expand Up @@ -133,28 +133,30 @@ class MainActivity : ComponentActivity() {
val path = getExternalFilesDir(null)!!.absolutePath

val mobileNet = File("$path/mobilenet_v1_1.0_224_quant.tflite")
val mobileNetFilter = "other/tensor,format=static,dimension=(string)3:224:224:1,type=uint8,framerate=0/1 ! " +
"tensor_filter framework=tensorflow-lite model=" + mobileNet.absolutePath + " ! " +
"other/tensor,format=static,dimension=(string)1001:1,type=uint8,framerate=0/1"
val mobileNetFilter =
"other/tensor,format=static,dimension=(string)3:224:224:1,type=uint8,framerate=0/1 ! " +
"tensor_filter framework=tensorflow-lite model=" + mobileNet.absolutePath + " ! " +
"other/tensor,format=static,dimension=(string)1001:1,type=uint8,framerate=0/1"
val mobileNetInfo = ModelInfo("MobileNet", mobileNetFilter)
modelList.add(mobileNetInfo)

val yolov8 = File("$path/yolov8s_float32.tflite")
val yolov8Filter = "other/tensors,num_tensors=1,format=static,dimensions=3:224:224:1,types=float32,framerate=0/1 ! " +
"tensor_filter framework=tensorflow-lite model=" + yolov8.absolutePath + " ! " +
"other/tensors,num_tensors=1,types=float32,format=static,dimensions=1029:84:1,framerate=0/1"
val yolov8Filter =
"other/tensors,num_tensors=1,format=static,dimensions=3:224:224:1,types=float32,framerate=0/1 ! " +
"tensor_filter framework=tensorflow-lite model=" + yolov8.absolutePath + " ! " +
"other/tensors,num_tensors=1,types=float32,format=static,dimensions=1029:84:1,framerate=0/1"

val yolov8Info = ModelInfo("Yolov8", yolov8Filter)
modelList.add(yolov8Info)

val recyclerView = findViewById<RecyclerView>(R.id.model_list)
recyclerView.adapter = ModelAdapter(modelList)
recyclerView.layoutManager = LinearLayoutManager(this, )
recyclerView.layoutManager = LinearLayoutManager(this)
}

override fun onStart() {
super.onStart()
Intent(this, MainService::class.java).also { intent->
Intent(this, MainService::class.java).also { intent ->
bindService(intent, connection, Context.BIND_AUTO_CREATE)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ class MainService : Service() {
|| Build.PRODUCT == "sdk_gphone64_arm64"
|| Build.FINGERPRINT == "robolectric"
|| Build.MANUFACTURER.contains("Geny")
private lateinit var serviceHandler : MainHandler
private lateinit var serviceLooper : Looper
private lateinit var serviceHandler: MainHandler
private lateinit var serviceLooper: Looper
private lateinit var handlerThread: HandlerThread
private var initialized = false
private var serverInfoMap = mutableMapOf<String,ServerInfo>()
private var serverInfoMap = mutableMapOf<String, ServerInfo>()

private fun startForeground() {
// Get NotificationManager
Expand All @@ -90,11 +90,12 @@ class MainService : Service() {
val chId = "mainService_ch0"
val chName = "ch0"
val chImportance = NotificationManager.IMPORTANCE_HIGH
val notificationChannel : NotificationChannel = NotificationChannel(chId, chName, chImportance).apply {
val chDesc = "This is a notification channel to run this service in the foreground."
val notificationChannel: NotificationChannel =
NotificationChannel(chId, chName, chImportance).apply {
val chDesc = "This is a notification channel to run this service in the foreground."

description = chDesc
}
description = chDesc
}

// Create the notification channel declared above
notificationManager.createNotificationChannel(notificationChannel)
Expand All @@ -107,14 +108,22 @@ class MainService : Service() {


// Check the FOREGROUND_SERVICE_SPECIAL_USE permission
val spUsePermission = ContextCompat.checkSelfPermission(this, Manifest.permission.FOREGROUND_SERVICE_SPECIAL_USE)
val spUsePermission = ContextCompat.checkSelfPermission(
this,
Manifest.permission.FOREGROUND_SERVICE_SPECIAL_USE
)
if (spUsePermission == PackageManager.PERMISSION_DENIED) {
stopSelf()
return
}

ServiceCompat.startForeground(this, 100, notification, ServiceInfo.FOREGROUND_SERVICE_TYPE_SPECIAL_USE)
}
ServiceCompat.startForeground(
this,
100,
notification,
ServiceInfo.FOREGROUND_SERVICE_TYPE_SPECIAL_USE
)
}

override fun onCreate() {
initNNStreamer()
Expand All @@ -123,9 +132,11 @@ class MainService : Service() {
stopSelf()
}

handlerThread = HandlerThread("ServiceStartArguments", Process.THREAD_PRIORITY_BACKGROUND).apply {
start()
}
handlerThread =
HandlerThread("ServiceStartArguments", Process.THREAD_PRIORITY_BACKGROUND).apply {
start()
}
this.applicationContext

serviceLooper = handlerThread.looper
serviceHandler = MainHandler(serviceLooper)
Expand Down Expand Up @@ -195,7 +206,8 @@ class MainService : Service() {

// TODO: Add an ApplicationContext Parameter
private fun getIpAddress(): String {
val connectivityManager = App.context().getSystemService(CONNECTIVITY_SERVICE) as ConnectivityManager
val connectivityManager =
App.context().getSystemService(CONNECTIVITY_SERVICE) as ConnectivityManager
val network = connectivityManager.activeNetwork
var inetAddress = if (isRunningOnEmulator) "10.0.2.2" else "localhost"
val linkProperties = connectivityManager.getLinkProperties(network) ?: return inetAddress
Expand All @@ -207,7 +219,7 @@ class MainService : Service() {
address !is Inet4Address -> continue
address.isLoopbackAddress -> continue
else -> {
inetAddress = address.hostAddress?:continue
inetAddress = address.hostAddress ?: continue

break
}
Expand Down Expand Up @@ -237,7 +249,7 @@ class MainService : Service() {
return serverInfoMap[name]?.port ?: -1
}

fun startServer(name:String, filter: String) {
fun startServer(name: String, filter: String) {
if (!serverInfoMap.containsKey(name)) {
val hostAddress = getIpAddress()
val port = findPort()
Expand All @@ -253,14 +265,14 @@ class MainService : Service() {
}
}

fun stopServer(name:String) {
fun stopServer(name: String) {
serverInfoMap[name]?.let { modelStatus ->
modelStatus.pipeline.stop()
modelStatus.status = Pipeline.State.PAUSED
}
}

fun closeServer(name:String) {
fun closeServer(name: String) {
serverInfoMap[name]?.let { modelStatus ->
modelStatus.pipeline.close()
serverInfoMap.remove(name)
Expand Down

0 comments on commit 2138e14

Please sign in to comment.