-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
120 additions
and
26 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
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
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
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
2 changes: 1 addition & 1 deletion
2
lab-smartphone/src/main/java/kaist/iclab/lab_galaxywatch_tracker/KoinModule.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
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
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
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
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
96 changes: 96 additions & 0 deletions
96
tracker-library/src/main/java/kaist/iclab/tracker/collectors/AppUsageEventCollector.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,96 @@ | ||
package kaist.iclab.tracker.collectors | ||
|
||
import android.Manifest | ||
import android.app.usage.UsageEvents | ||
import android.app.usage.UsageStatsManager | ||
import android.content.Context | ||
import android.os.Build | ||
import android.util.Log | ||
import kaist.iclab.tracker.database.DatabaseInterface | ||
import kaist.iclab.tracker.triggers.AlarmTrigger | ||
import java.util.concurrent.TimeUnit | ||
import kotlin.math.max | ||
|
||
|
||
class AppUsageEventCollector( | ||
override val context: Context, | ||
override val database: DatabaseInterface | ||
):AbstractCollector(context, database) { | ||
companion object { | ||
const val NAME = "APP_USAGE_EVENT" | ||
const val TAG = "AppUsageEventCollector" | ||
const val ACTION_REQUEST = "kaist.iclab.tracker.ACTION_APP_USAGE_EVENT_REQUEST" | ||
const val ACTION_CODE_REQUEST = 0x2 | ||
} | ||
|
||
override val NAME: String | ||
get() = Companion.NAME | ||
|
||
override val permissions: Array<String> = arrayOf( | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) Manifest.permission.PACKAGE_USAGE_STATS else null | ||
).filterNotNull().toTypedArray() | ||
|
||
var trigger: AlarmTrigger? = null | ||
|
||
var lastTimeDataWritten:Long = 0L | ||
|
||
fun listener() { | ||
val currTime = System.currentTimeMillis() | ||
val prevTime = max( | ||
currTime - TimeUnit.HOURS.toMillis(12), | ||
lastTimeDataWritten | ||
) | ||
val usageStatManager = | ||
context.getSystemService(Context.USAGE_STATS_SERVICE) as UsageStatsManager | ||
val events = usageStatManager.queryEvents(prevTime, currTime) | ||
while (events.hasNextEvent()) { | ||
val event = UsageEvents.Event() | ||
events.getNextEvent(event) | ||
event.toMap().let { | ||
Log.d(TAG, "EVENT $it") | ||
} | ||
} | ||
} | ||
|
||
fun UsageEvents.Event.toMap(): Map<String, Any> { | ||
val data = mutableMapOf( | ||
"timestamp" to this.timeStamp, | ||
"package_name" to this.packageName, | ||
"class_name" to this.className, | ||
"event_type" to this.eventType, | ||
// "configuration" to this.configuration, change it if there is need | ||
) | ||
/*TODO: getExtras parsing which is added on API Level 35*/ | ||
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { | ||
data["app_stand_by_bucket"] = this.appStandbyBucket | ||
} | ||
return data | ||
} | ||
|
||
/* Check whether the system allow to collect data | ||
* In case of sensor malfunction or broken, it would not be available.*/ | ||
override fun isAvailable() = true | ||
|
||
|
||
/* Start collector to collect data | ||
* */ | ||
override fun start(){ | ||
trigger = AlarmTrigger( | ||
context, | ||
ACTION_REQUEST, | ||
ACTION_CODE_REQUEST, | ||
60000L | ||
) { | ||
listener() | ||
} | ||
trigger?.register() | ||
} | ||
|
||
/* Stop collector to stop collecting data | ||
* */ | ||
override fun stop(){ | ||
trigger?.unregister() | ||
trigger = null | ||
} | ||
|
||
} |
2 changes: 1 addition & 1 deletion
2
...lectors/controller/CollectorController.kt → ...tracker/controller/CollectorController.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
2 changes: 1 addition & 1 deletion
2
...ontroller/CollectorControllerInterface.kt → ...ontroller/CollectorControllerInterface.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
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
2 changes: 1 addition & 1 deletion
2
wearable/src/main/java/kaist/iclab/lab_galaxywatch_tracker/KoinModule.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
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