diff --git a/examples/virtual-device-app/android/App/app/src/main/AndroidManifest.xml b/examples/virtual-device-app/android/App/app/src/main/AndroidManifest.xml index a57ddde21a56eb..b971d9fb375a99 100644 --- a/examples/virtual-device-app/android/App/app/src/main/AndroidManifest.xml +++ b/examples/virtual-device-app/android/App/app/src/main/AndroidManifest.xml @@ -5,6 +5,7 @@ + + \ No newline at end of file diff --git a/examples/virtual-device-app/android/App/app/src/main/res/drawable/ic_launcher_background.xml b/examples/virtual-device-app/android/App/core/common/src/main/res/drawable/ic_launcher_background.xml similarity index 100% rename from examples/virtual-device-app/android/App/app/src/main/res/drawable/ic_launcher_background.xml rename to examples/virtual-device-app/android/App/core/common/src/main/res/drawable/ic_launcher_background.xml diff --git a/examples/virtual-device-app/android/App/app/src/main/res/drawable/ic_launcher_foreground.xml b/examples/virtual-device-app/android/App/core/common/src/main/res/drawable/ic_launcher_foreground.xml similarity index 100% rename from examples/virtual-device-app/android/App/app/src/main/res/drawable/ic_launcher_foreground.xml rename to examples/virtual-device-app/android/App/core/common/src/main/res/drawable/ic_launcher_foreground.xml diff --git a/examples/virtual-device-app/android/App/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml b/examples/virtual-device-app/android/App/core/common/src/main/res/mipmap-anydpi-v26/ic_launcher.xml similarity index 100% rename from examples/virtual-device-app/android/App/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml rename to examples/virtual-device-app/android/App/core/common/src/main/res/mipmap-anydpi-v26/ic_launcher.xml diff --git a/examples/virtual-device-app/android/App/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml b/examples/virtual-device-app/android/App/core/common/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml similarity index 100% rename from examples/virtual-device-app/android/App/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml rename to examples/virtual-device-app/android/App/core/common/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml diff --git a/examples/virtual-device-app/android/App/app/src/main/res/mipmap-hdpi/ic_launcher.png b/examples/virtual-device-app/android/App/core/common/src/main/res/mipmap-hdpi/ic_launcher.png similarity index 100% rename from examples/virtual-device-app/android/App/app/src/main/res/mipmap-hdpi/ic_launcher.png rename to examples/virtual-device-app/android/App/core/common/src/main/res/mipmap-hdpi/ic_launcher.png diff --git a/examples/virtual-device-app/android/App/app/src/main/res/mipmap-hdpi/ic_launcher_round.png b/examples/virtual-device-app/android/App/core/common/src/main/res/mipmap-hdpi/ic_launcher_round.png similarity index 100% rename from examples/virtual-device-app/android/App/app/src/main/res/mipmap-hdpi/ic_launcher_round.png rename to examples/virtual-device-app/android/App/core/common/src/main/res/mipmap-hdpi/ic_launcher_round.png diff --git a/examples/virtual-device-app/android/App/app/src/main/res/mipmap-mdpi/ic_launcher.png b/examples/virtual-device-app/android/App/core/common/src/main/res/mipmap-mdpi/ic_launcher.png similarity index 100% rename from examples/virtual-device-app/android/App/app/src/main/res/mipmap-mdpi/ic_launcher.png rename to examples/virtual-device-app/android/App/core/common/src/main/res/mipmap-mdpi/ic_launcher.png diff --git a/examples/virtual-device-app/android/App/app/src/main/res/mipmap-mdpi/ic_launcher_round.png b/examples/virtual-device-app/android/App/core/common/src/main/res/mipmap-mdpi/ic_launcher_round.png similarity index 100% rename from examples/virtual-device-app/android/App/app/src/main/res/mipmap-mdpi/ic_launcher_round.png rename to examples/virtual-device-app/android/App/core/common/src/main/res/mipmap-mdpi/ic_launcher_round.png diff --git a/examples/virtual-device-app/android/App/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/examples/virtual-device-app/android/App/core/common/src/main/res/mipmap-xhdpi/ic_launcher.png similarity index 100% rename from examples/virtual-device-app/android/App/app/src/main/res/mipmap-xhdpi/ic_launcher.png rename to examples/virtual-device-app/android/App/core/common/src/main/res/mipmap-xhdpi/ic_launcher.png diff --git a/examples/virtual-device-app/android/App/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png b/examples/virtual-device-app/android/App/core/common/src/main/res/mipmap-xhdpi/ic_launcher_round.png similarity index 100% rename from examples/virtual-device-app/android/App/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png rename to examples/virtual-device-app/android/App/core/common/src/main/res/mipmap-xhdpi/ic_launcher_round.png diff --git a/examples/virtual-device-app/android/App/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/examples/virtual-device-app/android/App/core/common/src/main/res/mipmap-xxhdpi/ic_launcher.png similarity index 100% rename from examples/virtual-device-app/android/App/app/src/main/res/mipmap-xxhdpi/ic_launcher.png rename to examples/virtual-device-app/android/App/core/common/src/main/res/mipmap-xxhdpi/ic_launcher.png diff --git a/examples/virtual-device-app/android/App/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png b/examples/virtual-device-app/android/App/core/common/src/main/res/mipmap-xxhdpi/ic_launcher_round.png similarity index 100% rename from examples/virtual-device-app/android/App/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png rename to examples/virtual-device-app/android/App/core/common/src/main/res/mipmap-xxhdpi/ic_launcher_round.png diff --git a/examples/virtual-device-app/android/App/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/examples/virtual-device-app/android/App/core/common/src/main/res/mipmap-xxxhdpi/ic_launcher.png similarity index 100% rename from examples/virtual-device-app/android/App/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png rename to examples/virtual-device-app/android/App/core/common/src/main/res/mipmap-xxxhdpi/ic_launcher.png diff --git a/examples/virtual-device-app/android/App/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png b/examples/virtual-device-app/android/App/core/common/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png similarity index 100% rename from examples/virtual-device-app/android/App/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png rename to examples/virtual-device-app/android/App/core/common/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png diff --git a/examples/virtual-device-app/android/App/core/matter/src/main/java/com/matter/virtual/device/app/core/matter/MatterAppService.kt b/examples/virtual-device-app/android/App/core/matter/src/main/java/com/matter/virtual/device/app/core/matter/MatterAppService.kt new file mode 100644 index 00000000000000..0bcbee73e5fcd2 --- /dev/null +++ b/examples/virtual-device-app/android/App/core/matter/src/main/java/com/matter/virtual/device/app/core/matter/MatterAppService.kt @@ -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() + } +} diff --git a/examples/virtual-device-app/android/App/core/matter/src/main/java/com/matter/virtual/device/app/core/matter/MatterAppServiceConstants.kt b/examples/virtual-device-app/android/App/core/matter/src/main/java/com/matter/virtual/device/app/core/matter/MatterAppServiceConstants.kt new file mode 100644 index 00000000000000..bcee27164c17de --- /dev/null +++ b/examples/virtual-device-app/android/App/core/matter/src/main/java/com/matter/virtual/device/app/core/matter/MatterAppServiceConstants.kt @@ -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" +}