-
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.
Showing
19 changed files
with
797 additions
and
4 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
67 changes: 67 additions & 0 deletions
67
app/src/main/java/es/upm/bienestaremocional/data/phonecalls/PhoneInfo.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,67 @@ | ||
package es.upm.bienestaremocional.data.phonecalls | ||
|
||
import android.Manifest.permission.READ_CALL_LOG | ||
import android.annotation.SuppressLint | ||
import android.content.Context | ||
import android.content.pm.PackageManager | ||
import android.database.Cursor | ||
import android.provider.CallLog.Calls.* | ||
import androidx.core.content.ContextCompat | ||
import es.upm.bienestaremocional.data.crypto.securePrivateData | ||
|
||
class PhoneInfo { | ||
|
||
fun getCallLogs(context: Context): String { | ||
//check permissions | ||
if (checkPermissions(context)) { | ||
val c = context.applicationContext | ||
val projection = arrayOf(CACHED_NAME, NUMBER, DATE, DURATION) | ||
|
||
val cursor = c.contentResolver.query( | ||
CONTENT_URI, | ||
projection, | ||
null, | ||
null, | ||
null, | ||
null | ||
) | ||
return cursorToList(cursor) | ||
} | ||
return "N/A" | ||
} | ||
|
||
private fun cursorToList(cursor: Cursor?): String { | ||
var message = "{" | ||
cursor?.use { | ||
while (it.moveToNext()) { | ||
var json: String = " \"Call\": {\"Name\": \"" + securePrivateData( | ||
it.getStringFromColumn(CACHED_NAME) | ||
) + | ||
"\", \"Number\": \"" + securePrivateData(it.getStringFromColumn(NUMBER)) + | ||
"\", \"Date\": \"" + it.getStringFromColumn(DATE) + | ||
"\", \"Duration\": \"" + it.getStringFromColumn(DURATION) + | ||
"\"}" | ||
|
||
if (it.moveToNext()) | ||
json += "," | ||
|
||
message += json | ||
} | ||
message += "}" | ||
} | ||
return message | ||
} | ||
|
||
@SuppressLint("Range") | ||
private fun Cursor.getStringFromColumn(columnName: String) = | ||
getString(getColumnIndex(columnName)) | ||
|
||
private fun checkPermissions(context: Context): Boolean { | ||
val permission = ContextCompat.checkSelfPermission( | ||
context, | ||
READ_CALL_LOG | ||
) | ||
|
||
return permission == PackageManager.PERMISSION_GRANTED | ||
} | ||
} |
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
26 changes: 26 additions & 0 deletions
26
app/src/main/java/es/upm/bienestaremocional/data/trafficstats/main.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,26 @@ | ||
package es.upm.bienestaremocional.data.trafficstats | ||
|
||
import android.annotation.SuppressLint | ||
import android.net.TrafficStats | ||
|
||
class Traffic { | ||
|
||
fun init(): String { | ||
if (TrafficStats.getTotalRxBytes() != TrafficStats.UNSUPPORTED.toLong() && | ||
TrafficStats.getTotalTxBytes() != TrafficStats.UNSUPPORTED.toLong()) { | ||
return run() | ||
} | ||
return "{\"WiFI\": \"N/A Kb\", \"Mobile\": \"N/A Kb\"}" | ||
} | ||
|
||
@SuppressLint("SetTextI18n") | ||
fun run(): String { | ||
val mobile = TrafficStats.getMobileRxBytes() + TrafficStats.getMobileTxBytes() | ||
val total = TrafficStats.getTotalRxBytes() + TrafficStats.getTotalTxBytes() | ||
val wiFi: Long = (total - mobile) / 1024 | ||
val mobileData: Long = mobile / 1024 | ||
|
||
return "{\"WiFI\": \"$wiFi Kb\", \"Mobile\": \"$mobileData Kb\"}" | ||
} | ||
|
||
} |
206 changes: 206 additions & 0 deletions
206
app/src/main/java/es/upm/bienestaremocional/data/usage/Usage.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,206 @@ | ||
package es.upm.bienestaremocional.data.usage | ||
|
||
import android.app.usage.UsageStats | ||
import android.app.usage.UsageStatsManager | ||
import android.content.Context | ||
import android.content.Context.USAGE_STATS_SERVICE | ||
import android.os.Build | ||
import android.util.Log | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import android.widget.* | ||
import androidx.annotation.RequiresApi | ||
import java.util.* | ||
|
||
class Usage( | ||
private val logTag: String | ||
) { | ||
private var mUsageStatsManager: UsageStatsManager? = null | ||
private var mAdapter: Usage.UsageStatsAdapter? = null | ||
|
||
var usageInfo: String = "" | ||
|
||
@RequiresApi(Build.VERSION_CODES.Q) | ||
internal inner class UsageStatsAdapter : BaseAdapter() { | ||
private val mPackageStats = ArrayList<UsageStats>() | ||
|
||
override fun getCount(): Int { | ||
return mPackageStats.size | ||
} | ||
|
||
override fun getItem(position: Int): Any { | ||
return mPackageStats[position] | ||
} | ||
|
||
override fun getItemId(position: Int): Long { | ||
return position.toLong() | ||
} | ||
|
||
override fun getView(position: Int, convertView: View, parent: ViewGroup): View { | ||
|
||
return convertView | ||
} | ||
|
||
init { | ||
val cal = Calendar.getInstance() | ||
cal.add(Calendar.HOUR, -6) | ||
val stats = mUsageStatsManager!!.queryUsageStats( | ||
UsageStatsManager.INTERVAL_BEST, | ||
cal.timeInMillis, System.currentTimeMillis() | ||
) | ||
if (stats != null) { | ||
val statCount = stats.size | ||
|
||
for (i in 0 until statCount) { | ||
val pkgStats = stats[i] | ||
val type = findApp(pkgStats.packageName) | ||
var message: String | ||
if ((type != "") && (pkgStats.totalTimeVisible > 0)) { | ||
if (usageInfo != "") | ||
usageInfo += ", " | ||
message = "\"Apps\": { \"AppName\": \"" + pkgStats.packageName + | ||
"\", \"firstTimeStamp\": " + pkgStats.firstTimeStamp + | ||
", \"lastTimeStamp\": " + pkgStats.lastTimeStamp + | ||
", \"lastTimeUsed\": " + pkgStats.lastTimeUsed + | ||
", \"lastTimeVisible\": " + pkgStats.lastTimeVisible + | ||
", \"totalTimeVisible\": " + pkgStats.totalTimeVisible + | ||
", \"AppType\": \"" + type + "\"}" | ||
|
||
usageInfo += message | ||
} | ||
} | ||
} | ||
else | ||
{ | ||
Log.d(logTag, "Usage data not available") | ||
} | ||
} | ||
} | ||
|
||
@RequiresApi(Build.VERSION_CODES.Q) | ||
fun getAppUsage(context: Context): String { | ||
mUsageStatsManager = context.getSystemService(USAGE_STATS_SERVICE) as UsageStatsManager | ||
|
||
mAdapter = UsageStatsAdapter() | ||
|
||
if (usageInfo != "") | ||
return usageInfo | ||
|
||
return "\"Apps\": \"N/A\"" | ||
} | ||
|
||
fun findApp(appName: String): String { | ||
val type = "N/A" | ||
val rRSS = listOf( | ||
"facebook", | ||
"twitter", | ||
"instagram", | ||
"tiktok", | ||
"snapchat", | ||
"whatsapp", | ||
"messenger", | ||
"telegram" | ||
) | ||
val dating = listOf("tinder", "badoo", "meetic", "bumble", "grindr") | ||
val games = listOf( | ||
"candy", | ||
"mine", | ||
"treasure", | ||
"crush", | ||
"sudoku", | ||
"game", | ||
"pokemongo", | ||
"impact", | ||
"scape", | ||
"among", | ||
"otome", | ||
"madness", | ||
"zombies" | ||
) | ||
val entertaining = listOf( | ||
"youtube", | ||
"netflix", | ||
"hbo", | ||
"disney", | ||
"prime", | ||
"video", | ||
"ivoox", | ||
"tiktok", | ||
"audible", | ||
"book", | ||
"crunchyroll", | ||
"firefox", | ||
"opera", | ||
"chrome", | ||
"9gag", | ||
"los40", | ||
"spotify", | ||
"rtve", | ||
"bbc", | ||
"duolingo" | ||
) | ||
val house = listOf( | ||
"santander", | ||
"bbva", | ||
"bankinter", | ||
"openbank", | ||
"repsol", | ||
"naturgy", | ||
"iberdrola", | ||
"tapo", | ||
"tplink", | ||
"aeat", | ||
"amazon", | ||
"cl@ve", | ||
"sodexo", | ||
"zooplus", | ||
"wallapop" | ||
) | ||
val work = listOf( | ||
"office", | ||
"word", | ||
"excel", | ||
"powerpoint", | ||
"authenticator", | ||
"teams", | ||
"slack", | ||
"zoom", | ||
"moodle" | ||
) | ||
|
||
val rRSSCount = rRSS.size | ||
for (i in 0 until rRSSCount) { | ||
if (appName.contains(rRSS[i])) | ||
return "RRSS" | ||
} | ||
val gamesCount = games.size | ||
for (i in 0 until gamesCount) { | ||
if (appName.contains(games[i])) | ||
return "games" | ||
} | ||
val datingCount = dating.size | ||
for (i in 0 until datingCount) { | ||
if (appName.contains(dating[i])) | ||
return "dating" | ||
} | ||
val houseCount = house.size | ||
for (i in 0 until houseCount) { | ||
if (appName.contains(house[i])) | ||
return "house" | ||
} | ||
val workCount = work.size | ||
for (i in 0 until workCount) { | ||
if (appName.contains(work[i])) | ||
return "work" | ||
} | ||
val entertainingCount = entertaining.size | ||
for (i in 0 until entertainingCount) { | ||
if (appName.contains(entertaining[i])) | ||
return "entertaining" | ||
} | ||
|
||
return type | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.