Skip to content

Commit

Permalink
v0.9.9-c
Browse files Browse the repository at this point in the history
  • Loading branch information
Woohyeok Choi committed Feb 22, 2020
1 parent 63a0e85 commit 0fa43ed
Show file tree
Hide file tree
Showing 17 changed files with 105 additions and 41 deletions.
16 changes: 8 additions & 8 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ android {
applicationId 'kaist.iclab.abclogger'
minSdkVersion 23
targetSdkVersion 29
versionCode 24
versionName "0.9.9-a"
versionCode config.version_code
versionName config.version_name
setProperty('archivesBaseName', applicationId + "-v" + versionName)
buildConfigField("String", "DB_NAME", "\"abc-logger\"")
buildConfigField("String", "PREF_NAME", "\"abc-logger-pref\"")
buildConfigField("Long", "DB_MAX_SIZE", "3145728L")
buildConfigField("Boolean", "IS_TEST_MODE", "false")
buildConfigField("String", "SERVER_ADDRESS", "\"143.248.100.24:50052\"")
buildConfigField("String", "TEST_SERVER_ADDRESS", "\"143.248.90.87:50055\"")
buildConfigField("String", "DB_NAME", "\"${config.db_name}\"")
buildConfigField("String", "PREF_NAME", "\"${config.pref_name}\"")
buildConfigField("Long", "DB_MAX_SIZE", "${config.db_max_size}L")
buildConfigField("Boolean", "IS_TEST_MODE", "${config.is_test_mode}")
buildConfigField("String", "SERVER_ADDRESS", "\"${config.server_address}\"")
buildConfigField("String", "TEST_SERVER_ADDRESS", "\"${config.test_server_address}\"")
}
buildTypes {
release {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class AbcApplication : Application() {
AbcCollector.bind(this@AbcApplication)

if (BuildConfig.IS_TEST_MODE) {
Debug.generateEntities(500000)
Debug.generateSurveyEntities(50)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ fun toHash(input: String, start: Int = 0, end: Int = input.length, algorithm: St

if (safeStart >= safeEnd || safeEnd > input.length) return input

val subString = input.substring(safeEnd, input.length - 1).toByteArray()
val subString = try { input.substring(safeEnd, input.length - 1).toByteArray() } catch (e: Exception) { return input }
val bytes = MessageDigest.getInstance(algorithm).digest(subString)

return input.substring(safeStart, safeEnd) + "\$" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.content.Context
import android.content.Intent
import android.database.ContentObserver
import android.os.Handler
import android.os.HandlerThread
import android.provider.CallLog
import androidx.core.database.getIntOrNull
import androidx.core.database.getLongOrNull
Expand Down Expand Up @@ -50,7 +51,14 @@ class CallLogCollector(private val context: Context) : BaseCollector<CallLogColl
context.contentResolver.safeUnregisterContentObserver(callLogObserver)
}

private val callLogObserver: ContentObserver = object : ContentObserver(Handler()) {
private val handler : Handler
get() {
val thread = HandlerThread(this::class.java.name)
thread.start()
return Handler(thread.looper)
}

private val callLogObserver: ContentObserver = object : ContentObserver(handler) {
override fun onChange(selfChange: Boolean) {
super.onChange(selfChange)
handleCallLogRetrieval()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import android.content.Context
import android.content.Intent
import android.database.ContentObserver
import android.os.Handler
import android.os.HandlerThread
import android.os.Looper
import android.provider.MediaStore
import androidx.core.database.getLongOrNull
import androidx.core.database.getStringOrNull
Expand All @@ -14,6 +16,7 @@ import kaist.iclab.abclogger.collector.*
import kaist.iclab.abclogger.commons.checkPermission
import kaist.iclab.abclogger.commons.safeRegisterContentObserver
import kaist.iclab.abclogger.commons.safeUnregisterContentObserver
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import java.util.concurrent.TimeUnit
import kotlin.reflect.KClass
Expand Down Expand Up @@ -148,28 +151,35 @@ class MediaCollector(private val context: Context) : BaseCollector<MediaCollecto
}
}

private val internalPhotoObserver: ContentObserver = object : ContentObserver(Handler()) {
private val handler : Handler
get() {
val thread = HandlerThread(this::class.java.name)
thread.start()
return Handler(thread.looper)
}

private val internalPhotoObserver: ContentObserver = object : ContentObserver(handler) {
override fun onChange(selfChange: Boolean) {
super.onChange(selfChange)
handleMediaRetrieval(TYPE_INTERNAL_PHOTO)
}
}

private val internalVideoObserver: ContentObserver = object : ContentObserver(Handler()) {
private val internalVideoObserver: ContentObserver = object : ContentObserver(handler) {
override fun onChange(selfChange: Boolean) {
super.onChange(selfChange)
handleMediaRetrieval(TYPE_INTERNAL_VIDEO)
}
}

private val externalPhotoObserver: ContentObserver = object : ContentObserver(Handler()) {
private val externalPhotoObserver: ContentObserver = object : ContentObserver(handler) {
override fun onChange(selfChange: Boolean) {
super.onChange(selfChange)
handleMediaRetrieval(TYPE_EXTERNAL_PHOTO)
}
}

private val externalVideoObserver: ContentObserver = object : ContentObserver(Handler()) {
private val externalVideoObserver: ContentObserver = object : ContentObserver(handler) {
override fun onChange(selfChange: Boolean) {
super.onChange(selfChange)
handleMediaRetrieval(TYPE_EXTERNAL_VIDEO)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import android.content.Intent
import android.database.ContentObserver
import android.net.Uri
import android.os.Handler
import android.os.HandlerThread
import android.provider.Telephony
import androidx.core.database.getIntOrNull
import androidx.core.database.getLongOrNull
Expand Down Expand Up @@ -132,14 +133,21 @@ class MessageCollector(private val context: Context) : BaseCollector<MessageColl
timestamps.max()?.also { timestamp -> setStatus(Status(lastTimeAccessedMms = timestamp)) }
}

private val smsObserver: ContentObserver = object : ContentObserver(Handler()) {
private val handler : Handler
get() {
val thread = HandlerThread(this::class.java.name)
thread.start()
return Handler(thread.looper)
}

private val smsObserver: ContentObserver = object : ContentObserver(handler) {
override fun onChange(selfChange: Boolean) {
super.onChange(selfChange)
handleSmsRetrieval()
}
}

private val mmsObserver: ContentObserver = object : ContentObserver(Handler()) {
private val mmsObserver: ContentObserver = object : ContentObserver(handler) {
override fun onChange(selfChange: Boolean) {
super.onChange(selfChange)
handleMmsRetrieval()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,10 @@ class SurveyCollector(private val context: Context) : BaseCollector<SurveyCollec
}

private suspend fun scheduleAll(event: AbcEvent? = null) {
val settings = updateSettings(event)
setStatus(Status(settings = settings))

settings?.forEach { setting -> scheduleSurvey(setting) }
updateSettings(event)?.let { updatedSettings ->
setStatus(Status(settings = updatedSettings))
updatedSettings.forEach { setting -> scheduleSurvey(setting) }
}
}

private suspend fun cancelAll() {
Expand Down Expand Up @@ -239,8 +239,8 @@ class SurveyCollector(private val context: Context) : BaseCollector<SurveyCollec

private suspend fun updateSettings(event: AbcEvent? = null): List<Status.Setting>? {
val startTime = getStatus()?.startTime ?: return null

return getStatus()?.settings?.mapNotNull { setting ->
val prevSettings = getStatus()?.settings
val newSettings = prevSettings?.mapNotNull { setting ->
setting.json?.let { json -> Survey.fromJson(json) }?.let { survey ->
when (survey) {
is IntervalBasedSurvey -> updateIntervalBasedSurvey(survey = survey, setting = setting, startTime = startTime)
Expand All @@ -250,6 +250,13 @@ class SurveyCollector(private val context: Context) : BaseCollector<SurveyCollec
}
}
}

val isUpdated = prevSettings?.any{ prevSetting ->
val newSetting= newSettings?.find { setting -> prevSetting.id == setting.id }
newSetting != prevSetting
} ?: false

return if (isUpdated) newSettings else prevSettings
}

private fun updateIntervalBasedSurvey(survey: IntervalBasedSurvey,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import kaist.iclab.abclogger.collector.BaseCollector
import kaist.iclab.abclogger.collector.BaseStatus
import kaist.iclab.abclogger.collector.fill
import kotlinx.coroutines.launch
import java.util.concurrent.Executors
import java.util.concurrent.atomic.AtomicLong
import kotlin.reflect.KClass

Expand Down Expand Up @@ -44,7 +45,7 @@ class DataTrafficCollector(private val context: Context) : BaseCollector<DataTra
context.getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager
}

private val dataListener = object : PhoneStateListener() {
private val dataListener = object : PhoneStateListener(Executors.newSingleThreadExecutor()) {
override fun onDataActivity(direction: Int) {
super.onDataActivity(direction)
if (direction in directions) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ object Notifications {
private val NOTIFICATION_SETTINGS = mapOf(
CHANNEL_ID_SURVEY to NotificationSetting(
name = "Survey",
category = NotificationCompat.CATEGORY_REMINDER,
priority = NotificationCompat.PRIORITY_MAX,
visibility = NotificationCompat.VISIBILITY_PUBLIC,
importance = NotificationManagerCompat.IMPORTANCE_MAX,
Expand All @@ -47,6 +48,7 @@ object Notifications {
),
CHANNEL_ID_FOREGROUND to NotificationSetting(
name = "Experiment in progress",
category = NotificationCompat.CATEGORY_PROGRESS,
priority = NotificationCompat.PRIORITY_MIN,
visibility = NotificationCompat.VISIBILITY_SECRET,
importance = NotificationManagerCompat.IMPORTANCE_MIN,
Expand All @@ -60,6 +62,7 @@ object Notifications {
),
CHANNEL_ID_PROGRESS to NotificationSetting(
name = "Upload",
category = NotificationCompat.CATEGORY_PROGRESS,
priority = NotificationCompat.PRIORITY_HIGH,
visibility = NotificationCompat.VISIBILITY_PRIVATE,
importance = NotificationManagerCompat.IMPORTANCE_HIGH,
Expand All @@ -73,6 +76,7 @@ object Notifications {
),
CHANNEL_ID_REQUIRE_SETTING to NotificationSetting(
name = "Error occurs",
category = NotificationCompat.CATEGORY_REMINDER,
priority = NotificationCompat.PRIORITY_MAX,
visibility = NotificationCompat.VISIBILITY_PRIVATE,
importance = NotificationManagerCompat.IMPORTANCE_MAX,
Expand All @@ -89,6 +93,7 @@ object Notifications {

private data class NotificationSetting(
val name: String,
val category: String,
val priority: Int,
val visibility: Int,
val importance: Int,
Expand Down Expand Up @@ -129,6 +134,7 @@ object Notifications {
} else {
setSound(null, null)
}

}
notificationManager.createNotificationChannel(newChannel)
}
Expand Down Expand Up @@ -193,6 +199,7 @@ object Notifications {
.setShowWhen(setting.showWhen)
.setWhen(timestamp)
.setAutoCancel(setting.autoCancel)
.setCategory(setting.category)
.apply {
if (setting.hasSound) setSound(DEFAULT_RINGTONE_URI)
if (setting.hasVibration) setVibrate(DEFAULT_VIBRATION_PATTERN)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ class ConfigViewModel(
nav?.navigateIntent(intent)
}
}

}
}
simple {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package kaist.iclab.abclogger.ui.question.item

import android.content.Context
import android.util.AttributeSet
import android.util.Log
import android.util.TypedValue
import android.view.View
import android.widget.CheckBox
Expand All @@ -23,17 +24,19 @@ class CheckBoxesView(context: Context, attrs: AttributeSet?) : QuestionView(cont
id = View.generateViewId()
text = context.getString(R.string.general_etc)
setTextSize(TypedValue.COMPLEX_UNIT_PX, resources.getDimension(R.dimen.txt_size_text))
setOnCheckedChangeListener { _, isChecked ->
edtEtc.isEnabled = isChecked
setOnCheckedChangeListener { view, isChecked ->
edtEtc.isEnabled = isChecked && view.isEnabled
edtEtc.hint = if (edtEtc.isEnabled) context.getString(R.string.general_free_text) else null
attrChanged?.onChange()
}
}

private val edtEtc: TextInputEditText = TextInputEditText(context).apply {
id = View.generateViewId()
setHint(R.string.general_free_text)
setTextSize(TypedValue.COMPLEX_UNIT_PX, resources.getDimension(R.dimen.txt_size_text))
addTextChangedListener({ _, _, _, _ -> }, { _, _, _, _ -> attrChanged?.onChange() }, {})
isEnabled = false
hint = null
}

init {
Expand All @@ -59,7 +62,7 @@ class CheckBoxesView(context: Context, attrs: AttributeSet?) : QuestionView(cont
}

override fun setAvailable(isAvailable: Boolean) {
(layoutCheckGroup.children + btnEtc + edtEtc).forEach { view -> view.isEnabled = isAvailable }
(layoutCheckGroup.children + btnEtc).forEach { view -> view.isEnabled = isAvailable }
}

override fun setShowEtc(showEtc: Boolean) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,19 @@ class HorizontalRadioButtonsView(context: Context, attributeSet: AttributeSet?)

private val edtEtc: EditText = EditText(context).apply {
id = View.generateViewId()
setHint(R.string.general_free_text)
setTextSize(TypedValue.COMPLEX_UNIT_PX, resources.getDimension(R.dimen.txt_size_text))
addTextChangedListener({ _, _, _, _ -> }, { _, _, _, _ -> attrChanged?.onChange() }, {})
isEnabled = false
hint = null
}

private val btnEtc: CheckBox = CheckBox(context).apply {
id = View.generateViewId()
text = context.getString(R.string.general_etc)
setTextSize(TypedValue.COMPLEX_UNIT_PX, resources.getDimension(R.dimen.txt_size_text))
setOnCheckedChangeListener { _, isChecked ->
edtEtc.isEnabled = isChecked
setOnCheckedChangeListener { view, isChecked ->
edtEtc.isEnabled = isChecked && view.isEnabled
edtEtc.hint = if (isChecked) context.getString(R.string.general_free_text) else null
layoutRadioGroup.isEnabled = !isChecked
layoutRadioGroup.children.forEach { (it as? CompoundButton)?.isEnabled = !isChecked }
attrChanged?.onChange()
Expand Down Expand Up @@ -61,7 +63,7 @@ class HorizontalRadioButtonsView(context: Context, attributeSet: AttributeSet?)
}

override fun setAvailable(isAvailable: Boolean) {
(layoutRadioGroup.children + btnEtc + edtEtc).forEach { view -> view.isEnabled = isAvailable }
(layoutRadioGroup.children + btnEtc).forEach { view -> view.isEnabled = isAvailable }
}

override fun setShowEtc(showEtc: Boolean) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,19 @@ class RadioButtonsView(context: Context, attributeSet: AttributeSet?) : Question

private val edtEtc: EditText = EditText(context).apply {
id = View.generateViewId()
setHint(R.string.general_free_text)
setTextSize(TypedValue.COMPLEX_UNIT_PX, resources.getDimension(R.dimen.txt_size_text))
addTextChangedListener({ _, _, _, _ -> }, { _, _, _, _ -> attrChanged?.onChange() }, {})
isEnabled = false
hint = null
}

private val btnEtc: CheckBox = CheckBox(context).apply {
id = View.generateViewId()
text = context.getString(R.string.general_etc)
setTextSize(TypedValue.COMPLEX_UNIT_PX, resources.getDimension(R.dimen.txt_size_text))
setOnCheckedChangeListener { _, isChecked ->
edtEtc.isEnabled = isChecked
setOnCheckedChangeListener { view, isChecked ->
edtEtc.isEnabled = isChecked && view.isEnabled
edtEtc.hint = if (isChecked) context.getString(R.string.general_free_text) else null
layoutRadioGroup.isEnabled = !isChecked
layoutRadioGroup.children.forEach { (it as? CompoundButton)?.isEnabled = !isChecked }
attrChanged?.onChange()
Expand Down Expand Up @@ -59,7 +61,7 @@ class RadioButtonsView(context: Context, attributeSet: AttributeSet?) : Question
}

override fun setAvailable(isAvailable: Boolean) {
(layoutRadioGroup.children + btnEtc + edtEtc).forEach { view -> view.isEnabled = isAvailable }
(layoutRadioGroup.children + btnEtc).forEach { view -> view.isEnabled = isAvailable }
}

override fun setShowEtc(showEtc: Boolean) {
Expand Down
Loading

0 comments on commit 0fa43ed

Please sign in to comment.