-
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
27 changed files
with
640 additions
and
619 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
59 changes: 43 additions & 16 deletions
59
field-smartphone/src/main/java/kaist/iclab/field_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,63 @@ | ||
package kaist.iclab.field_tracker | ||
|
||
import kaist.iclab.tracker.collectors.BatteryCollector | ||
import kaist.iclab.tracker.collectors.LocationCollector | ||
import kaist.iclab.tracker.collectors.TestCollector | ||
import kaist.iclab.tracker.controller.CollectorControllerInterface | ||
import kaist.iclab.tracker.database.DatabaseInterface | ||
import kaist.iclab.tracker.permission.PermissionManagerInterface | ||
import kaist.iclab.field_tracker.ui.AbstractMainViewModel | ||
import kaist.iclab.field_tracker.ui.MainViewModelImpl | ||
import kaist.iclab.tracker.Tracker | ||
import org.koin.core.module.dsl.singleOf | ||
import kaist.iclab.tracker.collectors.* | ||
import kaist.iclab.tracker.controller.CollectorControllerInterface | ||
import kaist.iclab.tracker.database.DatabaseInterface | ||
import kaist.iclab.tracker.database.TempDBImpl | ||
import kaist.iclab.tracker.permission.PermissionManagerInterface | ||
import org.koin.android.ext.koin.androidContext | ||
import org.koin.core.module.dsl.viewModel | ||
import org.koin.core.module.dsl.viewModelOf | ||
import org.koin.core.module.dsl.singleOf | ||
import org.koin.dsl.module | ||
|
||
|
||
val appModule = module { | ||
single<DatabaseInterface> { | ||
Tracker.getDatabase() | ||
} | ||
single<CollectorControllerInterface> { | ||
Tracker.getCollectorController() | ||
} | ||
single<PermissionManagerInterface> { | ||
Tracker.getPermissionManager() | ||
} | ||
// singleOf(::TestCollector) | ||
// singleOf(::BatteryCollector) | ||
single<DatabaseInterface> { | ||
TempDBImpl(androidContext()) | ||
} | ||
|
||
singleOf(::ActivityTransitionCollector) | ||
singleOf(::AmbientLightCollector) | ||
singleOf(::AppUsageLogCollector) | ||
singleOf(::BatteryCollector) | ||
singleOf(::CallLogCollector) | ||
singleOf(::DataTrafficStatCollector) | ||
singleOf(::LocationCollector) | ||
singleOf(::MessageLogCollector) | ||
singleOf(::NotificationCollector) | ||
singleOf(::ScreenCollector) | ||
singleOf(::UserInteractionCollector) | ||
singleOf(::WiFiScanCollector) | ||
|
||
viewModelOf(::MainViewModelImpl) | ||
viewModel<AbstractMainViewModel>{ | ||
get<MainViewModelImpl>() | ||
viewModel<AbstractMainViewModel> { | ||
val collectors = mapOf( | ||
"ActivityTransitionCollector" to get<ActivityTransitionCollector>(), | ||
"AmbientLightCollector" to get<AmbientLightCollector>(), | ||
"AppUsageLogCollector" to get<AppUsageLogCollector>(), | ||
"BatteryCollector" to get<BatteryCollector>(), | ||
"CallLogCollector" to get<CallLogCollector>(), | ||
"DataTrafficStatCollector" to get<DataTrafficStatCollector>(), | ||
"LocationCollector" to get<LocationCollector>(), | ||
"MessageLogCollector" to get<MessageLogCollector>(), | ||
"NotificationCollector" to get<NotificationCollector>(), | ||
"ScreenCollector" to get<ScreenCollector>(), | ||
"UserInteractionCollector" to get<UserInteractionCollector>(), | ||
"WiFiScanCollector" to get<WiFiScanCollector>() | ||
) | ||
MainViewModelImpl( | ||
get(), | ||
get(), | ||
get(), | ||
collectors | ||
) | ||
} | ||
} |
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
107 changes: 107 additions & 0 deletions
107
field-smartphone/src/main/java/kaist/iclab/field_tracker/database/CouchbaseDBImpl.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,107 @@ | ||
//package kaist.iclab.tracker.database | ||
// | ||
//import android.content.Context | ||
//import android.util.Log | ||
//import com.couchbase.lite.CouchbaseLite | ||
//import com.couchbase.lite.DataSource | ||
//import com.couchbase.lite.Database | ||
//import com.couchbase.lite.Expression | ||
//import com.couchbase.lite.MutableDocument | ||
//import com.couchbase.lite.Ordering | ||
//import com.couchbase.lite.Query | ||
//import com.couchbase.lite.QueryBuilder | ||
//import com.couchbase.lite.SelectResult | ||
//import com.couchbase.lite.collectionChangeFlow | ||
//import kotlinx.coroutines.flow.Flow | ||
//import kotlinx.coroutines.flow.map | ||
//import kotlinx.coroutines.flow.onStart | ||
// | ||
//class CouchbaseDBImpl( | ||
// context: Context, | ||
//) : DatabaseInterface { | ||
// | ||
// companion object { | ||
// const val TAG = "CouchbaseDBImpl" | ||
// const val LOG_COLLECTION = "LOG" | ||
// const val DB = "tracker" | ||
// } | ||
// | ||
// private val database: Database by lazy { | ||
// Database(DB) | ||
// } | ||
// | ||
// init { | ||
// // Initialize Couchbase Lite | ||
// CouchbaseLite.init(context) | ||
// } | ||
// | ||
// override fun insert(collectionName: String, data: Map<String, Any>): String { | ||
// val document = MutableDocument(data) | ||
// val collection = getCollection(collectionName) | ||
// collection.save(document) | ||
// return document.id | ||
// } | ||
// | ||
// override fun update(collectionName: String, data: Map<String, Any>) { | ||
// val collection = getCollection(collectionName) | ||
// val id = collection.indexes.firstOrNull() | ||
// val document = MutableDocument(id, data) | ||
// collection.save(document) | ||
// Log.d(TAG, "$collectionName Updated: ${document.toMap()}") | ||
// } | ||
// | ||
// override fun sync() { | ||
// TODO("Not yet implemented") | ||
// } | ||
// | ||
// override fun deleteAll() { | ||
// database.delete() | ||
// } | ||
// | ||
// override fun getAllDocs(collectionName: String): List<Map<String, Any>> { | ||
// val collection = getCollection(collectionName) | ||
// val query: Query = QueryBuilder.select(SelectResult.all()) | ||
// .from(DataSource.collection(collection)) | ||
// return query.execute().allResults().map { it.toMap() } | ||
// } | ||
// | ||
// override fun getDocsFlow(collectionName: String): Flow<List<Map<String, Any>>> { | ||
// val collection = getCollection(collectionName) | ||
// return collection.collectionChangeFlow().map { | ||
// getAllDocs(collectionName) | ||
// }.onStart { | ||
// emit(getAllDocs(collectionName)) | ||
// } | ||
// } | ||
// | ||
// override fun getLastDoc(collectionName: String): Map<String, Any> { | ||
// val collection = getCollection(collectionName) | ||
// val query: Query = QueryBuilder.select(SelectResult.all()) | ||
// .from(DataSource.collection(collection)) | ||
// .orderBy(Ordering.property("timestamp").descending()) | ||
// .limit(Expression.intValue(1)) | ||
// return query.execute().firstOrNull()?.getDictionary(0)?.toMap() ?: mapOf() | ||
// } | ||
// | ||
// override fun getLastDocFlow(collectionName: String): Flow<Map<String, Any>> { | ||
// val collection = getCollection(collectionName) | ||
// return collection.collectionChangeFlow().map { | ||
// getLastDoc(collectionName) | ||
// }.onStart { | ||
// emit(getLastDoc(collectionName)) | ||
// } | ||
// } | ||
// | ||
// override fun log(message: String) { | ||
// insert( | ||
// LOG_COLLECTION, | ||
// mapOf("timestamp" to System.currentTimeMillis(), "message" to message) | ||
// ) | ||
// } | ||
// | ||
// private fun getCollection(collectionName: String): com.couchbase.lite.Collection { | ||
// val collection = database.getCollection(collectionName) | ||
// ?: database.createCollection(collectionName) | ||
// return collection | ||
// } | ||
//} |
24 changes: 24 additions & 0 deletions
24
field-smartphone/src/main/java/kaist/iclab/field_tracker/database/DatabaseInterface.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,24 @@ | ||
package kaist.iclab.tracker.database | ||
|
||
import kotlinx.coroutines.flow.Flow | ||
|
||
interface DatabaseInterface { | ||
// fun insert(collectionName: String, data: Map<String, Any>): String | ||
// fun update(collectionName: String, data: Map<String, Any>) | ||
// | ||
// fun sync() | ||
// fun deleteAll() | ||
// | ||
// fun getDocsFlow(collectionName: String): Flow<List<Map<String, Any>>> | ||
// fun getAllDocs(collectionName: String): List<Map<String,Any>> | ||
// | ||
// fun getLastDocFlow(collectionName: String): Flow<Map<String, Any>> | ||
// fun getLastDoc(collectionName: String): Map<String, Any> | ||
// | ||
// /* Function to Log some messages*/ | ||
// fun log(message: String) | ||
|
||
/* Enable/Disable Collector */ | ||
fun updateConfig(name: String, value: Boolean) | ||
fun getConfigFlow(): Flow<Map<String,Boolean>> | ||
} |
5 changes: 1 addition & 4 deletions
5
...aist/iclab/tracker/database/FakeDBImpl.kt → ...clab/field_tracker/database/FakeDBImpl.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
47 changes: 47 additions & 0 deletions
47
field-smartphone/src/main/java/kaist/iclab/field_tracker/database/TempDBImpl.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,47 @@ | ||
package kaist.iclab.tracker.database | ||
|
||
import android.content.Context | ||
import com.couchbase.lite.CouchbaseLite | ||
import com.couchbase.lite.Database | ||
import com.couchbase.lite.MutableDocument | ||
import com.couchbase.lite.collectionChangeFlow | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.map | ||
import kotlinx.coroutines.flow.onStart | ||
|
||
class TempDBImpl(context: Context): DatabaseInterface { | ||
companion object { | ||
const val DB = "CONFIG" | ||
} | ||
private val database: Database by lazy { | ||
Database(DB) | ||
} | ||
|
||
init { | ||
CouchbaseLite.init(context) | ||
} | ||
|
||
override fun updateConfig(name: String, value: Boolean) { | ||
val collection = getCollection() | ||
val document = collection.getDocument(DB)?.toMutable() ?: MutableDocument(DB) | ||
document.setBoolean(name, value) | ||
collection.save(document) | ||
} | ||
|
||
override fun getConfigFlow(): Flow<Map<String, Boolean>> { | ||
val collection = getCollection() | ||
return collection.collectionChangeFlow().map { | ||
val document = collection.getDocument(DB) | ||
document?.toMap()?.filterValues { it is Boolean }?.mapValues { it.value as Boolean } ?: emptyMap() | ||
}.onStart { | ||
val document = collection.getDocument(DB) | ||
emit(document?.toMap()?.filterValues { it is Boolean }?.mapValues { it.value as Boolean } ?: emptyMap()) | ||
} | ||
} | ||
|
||
private fun getCollection(): com.couchbase.lite.Collection { | ||
val collection = database.getCollection(DB) | ||
?: database.createCollection(DB) | ||
return collection | ||
} | ||
} |
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
Oops, something went wrong.