Skip to content

Commit

Permalink
Backup WIP:ActivityRecognitionStatCollector
Browse files Browse the repository at this point in the history
  • Loading branch information
highjun committed Nov 8, 2024
1 parent a343836 commit fae2599
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ val appModule = module {

// singleOf(::ActivityTransitionCollector)
singleOf(::AmbientLightCollector)
// singleOf(::ActivityRecognitionStatCollector)
singleOf(::ActivityRecognitionStatCollector)
// singleOf(::AppUsageLogCollector)
singleOf(::BatteryCollector)
// singleOf(::CallLogCollector)
Expand All @@ -54,8 +54,8 @@ val appModule = module {
get<ScreenCollector>(),
// get<NotificationCollector>(),
// get<UserInteractionCollector>(),
get<LocationCollector>()
// get<ActivityRecognitionStatCollector>()
get<LocationCollector>(),
get<ActivityRecognitionStatCollector>()
// get<ActivityTransitionCollector>()
// get<DataTrafficStatCollector>()
).map({ it.NAME to it }).toMap()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package kaist.iclab.field_tracker

import android.Manifest
import android.app.PendingIntent
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.content.pm.PackageManager
import android.os.Build
import android.os.Bundle
import android.provider.ContactsContract.Data
Expand All @@ -12,14 +17,23 @@ import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.ui.Modifier
import androidx.core.app.ActivityCompat
import com.google.android.gms.location.ActivityRecognition
import com.google.android.gms.location.ActivityRecognitionClient
import com.google.android.gms.location.ActivityRecognitionResult
import com.google.android.gms.location.DetectedActivity
import com.google.android.gms.location.LocationServices
import kaist.iclab.tracker.permission.PermissionActivity
import kaist.iclab.field_tracker.ui.MainScreen
import kaist.iclab.field_tracker.ui.theme.TrackerTheme
import kaist.iclab.tracker.Tracker
import kaist.iclab.tracker.collectors.ActivityRecognitionStatCollector
import kaist.iclab.tracker.collectors.ActivityRecognitionStatCollector.Entity
import kaist.iclab.tracker.collectors.DataTrafficStatCollector
import kaist.iclab.tracker.collectors.LocationCollector
import kaist.iclab.tracker.controller.DataEntity
import kaist.iclab.tracker.triggers.SystemBroadcastTrigger
import org.koin.android.ext.android.get
import org.koin.androidx.compose.KoinAndroidContext

class MainActivity : PermissionActivity() {
Expand All @@ -40,20 +54,12 @@ class MainActivity : PermissionActivity() {
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
Tracker.getPermissionManager().request(
arrayOf(Manifest.permission.POST_NOTIFICATIONS,
Manifest.permission.SCHEDULE_EXACT_ALARM)
){
arrayOf(Manifest.permission.POST_NOTIFICATIONS)
// Manifest.permission.SCHEDULE_EXACT_ALARM)
) {
Log.d("MAIN_ACTIVITY", "Permission $it")
}
}
// startActivity(Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS))
// val context = this@MainActivity
// val client = LocationServices.getFusedLocationProviderClient(context)

// val newLocation = LocationCollector(this, Tracker.getPermissionManager())
// newLocation.listener = { data:DataEntity ->
// Log.d(newLocation.NAME, "Data: $data")
// }
// newLocation.start()
}

}
16 changes: 8 additions & 8 deletions tracker-library/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@
<!-- dataSync|specialUse|location|health-->
<service
android:name=".controller.CollectorControllerImpl$CollectorService"
android:foregroundServiceType="dataSync|location"
android:foregroundServiceType="dataSync|location|health"
android:exported="false">
</service>

<service android:name=".collectors.NotificationCollector$NotificationTrigger"
android:exported="false"
android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE">
<intent-filter>
<action android:name="android.service.notification.NotificationListenerService" />
</intent-filter>
</service>
<!-- <service android:name=".collectors.NotificationCollector$NotificationTrigger"-->
<!-- android:exported="false"-->
<!-- android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE">-->
<!-- <intent-filter>-->
<!-- <action android:name="android.service.notification.NotificationListenerService" />-->
<!-- </intent-filter>-->
<!-- </service>-->

<service
android:name=".collectors.UserInteractionCollector$MyAccessibilityService"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ import kaist.iclab.tracker.controller.CollectorConfig
import kaist.iclab.tracker.controller.DataEntity
import kaist.iclab.tracker.permission.PermissionManagerInterface
import kaist.iclab.tracker.triggers.SystemBroadcastTrigger
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import java.lang.Thread.sleep
import java.util.concurrent.TimeUnit

class ActivityRecognitionStatCollector(
Expand Down Expand Up @@ -65,7 +69,19 @@ class ActivityRecognitionStatCollector(
super.start()
Log.d("AR", "started ${configFlow.value.interval}")
client.requestActivityUpdates(configFlow.value.interval, activityRecognitionIntent)
// .addOnFailureListener {
// Log.e("AR", "failed to request activity updates", it)
// }.addOnSuccessListener {
// Log.d("AR", "succeeded to request activity updates")
// }.addOnCanceledListener {
// Log.e("AR", "canceled to request activity updates" )
// }
broadcastTrigger.register()
// CoroutineScope(Dispatchers.IO).launch {
// sleep(10000)
// Log.d("AR", "send")
// activityRecognitionIntent.send(context, 0, Intent(ACTION))
// }
}

override fun stop() {
Expand All @@ -75,17 +91,17 @@ class ActivityRecognitionStatCollector(
}

val ACTION = "kaist.iclab.tracker.${NAME}_REQUEST"
val CODE = 0xF2

private val client: ActivityRecognitionClient by lazy {
ActivityRecognition.getClient(context)
}

private val activityRecognitionIntent by lazy {
PendingIntent.getBroadcast(
context, CODE,
context, 0,
Intent(ACTION),
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
else PendingIntent.FLAG_UPDATE_CURRENT
)
}

Expand Down

0 comments on commit fae2599

Please sign in to comment.