-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
virtual-device-app: Add android service for managing app server (#28399)
Signed-off-by: Jaehoon You <[email protected]> Signed-off-by: Charles Kim <[email protected]>
- Loading branch information
1 parent
d6de7e6
commit 1179154
Showing
17 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
92 changes: 92 additions & 0 deletions
92
...p/core/matter/src/main/java/com/matter/virtual/device/app/core/matter/MatterAppService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package com.matter.virtual.device.app.core.matter | ||
|
||
import android.app.Notification | ||
import android.app.NotificationChannel | ||
import android.app.NotificationManager | ||
import android.app.Service | ||
import android.content.Intent | ||
import android.os.Build | ||
import android.os.IBinder | ||
import androidx.core.app.NotificationCompat | ||
import dagger.hilt.android.AndroidEntryPoint | ||
import timber.log.Timber | ||
|
||
@AndroidEntryPoint | ||
class MatterAppService : Service() { | ||
|
||
override fun onCreate() { | ||
super.onCreate() | ||
Timber.d("onCreate()") | ||
} | ||
|
||
override fun onDestroy() { | ||
super.onDestroy() | ||
Timber.d("onDestroy()") | ||
} | ||
|
||
override fun onBind(intent: Intent?): IBinder? { | ||
Timber.d("onBind()") | ||
return null | ||
} | ||
|
||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { | ||
Timber.d("Hit") | ||
|
||
intent?.let { | ||
when (it.action) { | ||
MatterAppServiceConstants.ACTION_START_MATTER_APP_SERVICE -> { | ||
Timber.i("Start matter app service") | ||
startService() | ||
} | ||
MatterAppServiceConstants.ACTION_STOP_MATTER_APP_SERVICE -> { | ||
Timber.i("Stop matter app service") | ||
stopService() | ||
} | ||
else -> {} | ||
} | ||
} | ||
|
||
return START_REDELIVER_INTENT | ||
} | ||
|
||
private fun createNotificationChannel() { | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { | ||
val notificationChannel = | ||
NotificationChannel( | ||
MatterAppServiceConstants.NOTIFICATION_CHANNEL_ID, | ||
MatterAppServiceConstants.NOTIFICATION_CHANNEL_NAME, | ||
NotificationManager.IMPORTANCE_DEFAULT | ||
) | ||
|
||
val manager = getSystemService(NotificationManager::class.java) | ||
manager?.createNotificationChannel(notificationChannel) | ||
} | ||
} | ||
|
||
private fun cancelNotificationChannel() { | ||
val manager = getSystemService(NotificationManager::class.java) | ||
manager?.cancel(MatterAppServiceConstants.NOTIFICATION_FOREGROUND_ID) | ||
} | ||
|
||
private fun startService() { | ||
Timber.d("Hit") | ||
|
||
createNotificationChannel() | ||
|
||
val notification: Notification = | ||
NotificationCompat.Builder(this, MatterAppServiceConstants.NOTIFICATION_CHANNEL_ID) | ||
.setContentTitle("MatterApp Service") | ||
.setContentText("MatterApp is running") | ||
.setSmallIcon(R.mipmap.ic_launcher) | ||
.build() | ||
|
||
startForeground(MatterAppServiceConstants.NOTIFICATION_FOREGROUND_ID, notification) | ||
} | ||
|
||
private fun stopService() { | ||
Timber.d("Hit") | ||
cancelNotificationChannel() | ||
stopForeground(true) | ||
stopSelf() | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...tter/src/main/java/com/matter/virtual/device/app/core/matter/MatterAppServiceConstants.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.matter.virtual.device.app.core.matter | ||
|
||
object MatterAppServiceConstants { | ||
const val ACTION_START_MATTER_APP_SERVICE = "ACTION_START_MATTER_APP_SERVICE" | ||
const val ACTION_STOP_MATTER_APP_SERVICE = "ACTION_STOP_MATTER_APP_SERVICE" | ||
|
||
const val NOTIFICATION_CHANNEL_ID = "VIRTUAL_DEVICE" | ||
const val NOTIFICATION_FOREGROUND_ID = 1 | ||
const val NOTIFICATION_CHANNEL_NAME = "Matter App" | ||
} |