Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pixels #2

Open
wants to merge 49 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
3a7d956
test
voronoff2803 Apr 15, 2023
367bf84
feat: http Interceptor works
CHEYSOFF Apr 15, 2023
8da9c0a
bad commit
CHEYSOFF Apr 15, 2023
3476877
Revert "bad commit"
CHEYSOFF Apr 15, 2023
cfb4680
fixed gradle
CHEYSOFF Apr 15, 2023
2693ff1
add retrofit
voronoff2803 Apr 15, 2023
369d7d4
add pixels folder
voronoff2803 Apr 15, 2023
ecf0694
Revert "add pixels folder"
voronoff2803 Apr 15, 2023
94a0fd3
add folder
voronoff2803 Apr 15, 2023
f022f8e
Feat: local SQLite bd (An-Vas)
An-Vas Apr 15, 2023
c83388d
Feat: created simple schedule for saving info to bd (An-Vas)
An-Vas Apr 15, 2023
614a7f3
add stack trace
voronoff2803 Apr 15, 2023
c190a76
Feat: schedule saving implementation moved to new file (An-Vas)
An-Vas Apr 15, 2023
e70b61c
added DbModel
CHEYSOFF Apr 15, 2023
78df867
Feat: bd optimized for DbModel for our case(An-Vas)
An-Vas Apr 15, 2023
44cff06
add picasso
voronoff2803 Apr 15, 2023
8582e13
fix
voronoff2803 Apr 15, 2023
79891f7
Feat: JSON parser Added (An-Vas)
An-Vas Apr 15, 2023
2eb83ac
Merge pull request #1 from voronoff2803/stackTrace
CHEYSOFF Apr 16, 2023
2ffb0d1
Fix: bd requests are not let the app fail any more (An-Vas)
An-Vas Apr 16, 2023
23c6d8d
Merge branch 'anvasLocalDbMade' of https://github.com/voronoff2803/It…
An-Vas Apr 16, 2023
bd70286
fix: gradle was not compiled (return for previous version)
An-Vas Apr 16, 2023
cfcde64
attempt to put in an object
CHEYSOFF Apr 16, 2023
8deea3a
singletone doesn't work
CHEYSOFF Apr 16, 2023
e7b4916
okhttpinterceptor sends to sql
CHEYSOFF Apr 16, 2023
92f863d
added compatibility an
CHEYSOFF Apr 16, 2023
2f8c9c8
fix: request to server sent succesfully(anvas))
An-Vas Apr 16, 2023
509ac4d
Merge pull request #2 from voronoff2803/anvasLocalDbMade
CHEYSOFF Apr 16, 2023
2e9a313
ms
voronoff2803 Apr 16, 2023
e3b8a29
quick fix
CHEYSOFF Apr 16, 2023
51d581f
Merge branch 'master' of https://github.com/voronoff2803/Itmo-hack-2023
CHEYSOFF Apr 16, 2023
6857f97
exo player + refactor
voronoff2803 Apr 16, 2023
88a1213
Merge branch 'master' of https://github.com/voronoff2803/Itmo-hack-2023
voronoff2803 Apr 16, 2023
a1c311b
picasso
voronoff2803 Apr 16, 2023
c9202cc
userId
voronoff2803 Apr 16, 2023
a96ec3c
minor
voronoff2803 Apr 16, 2023
e6fe831
web view
voronoff2803 Apr 16, 2023
bcee4b1
fix
voronoff2803 Apr 16, 2023
26a708e
exo player
voronoff2803 Apr 16, 2023
a9f9ce1
JNIClient made
CHEYSOFF Apr 16, 2023
86969bc
feat: README v1.0 addded
An-Vas Apr 16, 2023
1cbf398
Feat: Backend file added
An-Vas Apr 16, 2023
b4c8e71
added PixelSDK
CHEYSOFF Apr 16, 2023
2704821
Style: Updated README
An-Vas Apr 16, 2023
34ce532
Merge branch 'master' of https://github.com/voronoff2803/Itmo-hack-2023
CHEYSOFF Apr 16, 2023
5c33edc
quick fix
CHEYSOFF Apr 16, 2023
f9320d2
fixed time1 time2 bug
CHEYSOFF Apr 16, 2023
e421992
http bugfix
CHEYSOFF Apr 16, 2023
22b4b81
add
voronoff2803 Apr 16, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

*.bin
*.lock
.idea/workspace.xml
.idea/kotlinc.xml
.gradle/vcs-1/gc.properties
.gradle/buildOutputCleanup/cache.properties
*.bin
local.properties
local.properties
Binary file added .gradle/8.0/checksums/checksums.lock
Binary file not shown.
Binary file added .gradle/8.0/checksums/md5-checksums.bin
Binary file not shown.
Binary file added .gradle/8.0/checksums/sha1-checksums.bin
Binary file not shown.
Binary file not shown.
Empty file.
Binary file added .gradle/8.0/executionHistory/executionHistory.bin
Binary file not shown.
Binary file added .gradle/8.0/executionHistory/executionHistory.lock
Binary file not shown.
Binary file added .gradle/8.0/fileChanges/last-build.bin
Binary file not shown.
Binary file added .gradle/8.0/fileHashes/fileHashes.bin
Binary file not shown.
Binary file added .gradle/8.0/fileHashes/fileHashes.lock
Binary file not shown.
Binary file added .gradle/8.0/fileHashes/resourceHashesCache.bin
Binary file not shown.
Empty file added .gradle/8.0/gc.properties
Empty file.
Binary file added .gradle/file-system.probe
Binary file not shown.
1 change: 1 addition & 0 deletions .idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/Itmo-hack-2023.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Itmo-hack-2023
Решение кейса по отслеживанию и обработке трафика приложения, разработанное командой "Пиксели" в рамках хакатона ВК образование х ОК х ИТМО 15-16 апреля 2023 года. Мы предоставляем набор инструментов, упрощающих поиск и выявление ошибок, связанных с потреблением трафика приложением.

# Какие виды запросов мы поддерживаем?
### OKhttp

### Exoplayer

### Jni

### Picasso

### retrofit

### WebView


# Какой UI мы предоставляем?
Полученные в ходе работы библиотеки данные об использовании трафика отправляются на backend, где хранятся в POSTGRES. Имеется web приложение для иллюстрации изменений характеристик запросов

## Пример подключения:

```
PixelSDK.configure("172.0.0.0")
PixelSDK.getOkHttpClient()
PixelSDK.getPicassoClient()
PixelSDK.getWebViewClient()
```
7 changes: 7 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ android {
}
}



dependencies {

implementation 'androidx.core:core-ktx:1.7.0'
Expand Down Expand Up @@ -68,4 +70,9 @@ dependencies {
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'


implementation "com.github.kittinunf.fuel:fuel:2.3.1"


}
4 changes: 3 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.ItmoHack2023"
tools:targetApi="31">
tools:targetApi="31"
android:usesCleartextTraffic="true">
<activity
android:name=".MainActivity"
android:exported="true">
Expand All @@ -39,6 +40,7 @@
<activity android:name="ru.ok.android.itmohack2023.GlideActivity"/>
<activity android:name="ru.ok.android.itmohack2023.PicassoActivity"/>
<activity android:name="ru.ok.android.itmohack2023.DownloadManagerActivity"/>

</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.google.android.exoplayer2.MediaItem
import com.google.android.exoplayer2.source.hls.HlsMediaSource
import com.google.android.exoplayer2.ui.StyledPlayerView
import com.google.android.exoplayer2.upstream.DefaultHttpDataSource
import ru.ok.android.itmohack2023.pixels.exoPlayer.PixelExoPlayerProvider

class ExoPlayerActivity : AppCompatActivity() {

Expand All @@ -21,7 +22,8 @@ class ExoPlayerActivity : AppCompatActivity() {
}

private fun preparePlayer() {
exoPlayer = ExoPlayer.Builder(this).build()
//exoPlayer = ExoPlayer.Builder(this).build()
exoPlayer = PixelExoPlayerProvider().getClient(this)
exoPlayer?.playWhenReady = true
val playerView = findViewById<StyledPlayerView>(R.id.playerView)
playerView.player = exoPlayer
Expand Down Expand Up @@ -61,6 +63,6 @@ class ExoPlayerActivity : AppCompatActivity() {
}

companion object {
const val URL = "https://bitdash-a.akamaihd.net/content/sintel/hls/playlist.m3u8"
const val URL = "https://res.cloudinary.com/dannykeane/video/upload/sp_full_hd/q_80:qmax_90,ac_none/v1/dk-memoji-dark.m3u8"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import com.facebook.drawee.view.SimpleDraweeView
import com.facebook.imagepipeline.request.ImageRequestBuilder
import com.google.android.material.button.MaterialButton

//import com.facebook.imagepipeline.backends.okhttp3.OkHttpImagePipelineConfigFactory

class FrescoActivity : AppCompatActivity() {

private lateinit var animalsView: SimpleDraweeView
Expand Down
7 changes: 5 additions & 2 deletions app/src/main/java/ru/ok/android/itmohack2023/JNIActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@ import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import org.json.JSONArray
import org.json.JSONObject
import ru.ok.android.itmohack2023.pixels.JNI.JNIClient

class JNIActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_jniactivity)
Threads.ioPool.execute {
val taskName = "NativeFunctionTask"
val jniClient = JNIClient()
jniClient.execute(Runnable execute@{
var result = nativeFunction() ?: return@execute
result = result.dropWhile { it != '{' }

Expand All @@ -21,7 +24,7 @@ class JNIActivity : AppCompatActivity() {
runOnUiThread {
findViewById<TextView>(R.id.result).text = act
}
}
})
}

external fun nativeFunction(): String?
Expand Down
81 changes: 81 additions & 0 deletions app/src/main/java/ru/ok/android/itmohack2023/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,29 @@ package ru.ok.android.itmohack2023

import android.content.Intent
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.util.Log
import android.view.View
import android.net.TrafficStats
import androidx.appcompat.app.AppCompatActivity
import ru.ok.android.itmohack2023.db.DbManager
import ru.ok.android.itmohack2023.db.DbModel
import ru.ok.android.itmohack2023.db.DbSheduleSaver
import ru.ok.android.itmohack2023.db.DbSingletone
import java.io.BufferedReader
import java.io.IOException
import java.io.InputStreamReader
import java.text.SimpleDateFormat
import java.util.Date

class MainActivity : AppCompatActivity() {

var initialTxBytes = TrafficStats.getTotalTxBytes()
var initialRxBytes = TrafficStats.getTotalRxBytes()


lateinit var logReader: BufferedReader
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
Expand Down Expand Up @@ -45,5 +64,67 @@ class MainActivity : AppCompatActivity() {
findViewById<View>(R.id.downloadmanager).setOnClickListener {
startActivity(Intent(this, DownloadManagerActivity::class.java))
}

val dbSheduleSaver = DbSheduleSaver (this)
dbSheduleSaver.postOkRequest()


}

fun setupNetworkTrack() {
while(true) {
// Wait for a specific time interval
Thread.sleep(5000)

val currentTxBytes = TrafficStats.getTotalTxBytes()
val currentRxBytes = TrafficStats.getTotalRxBytes()

val txBytes = currentTxBytes - initialTxBytes
val rxBytes = currentRxBytes - initialRxBytes

if (txBytes > 1000000 || rxBytes > 1000000) {
initialTxBytes = TrafficStats.getTotalTxBytes()
initialRxBytes = TrafficStats.getTotalRxBytes()

getLogs()
}
}
}

fun getLogs() {
var result = ""

val logcatThread = Thread(Runnable {
try {
val process = Runtime.getRuntime().exec("logcat -v time") // "-v time" adds timestamp to log messages
logReader = BufferedReader(InputStreamReader(process.inputStream))

var line: String?
while (logReader.readLine().also { line = it } != null) {
result += line

}
} catch (e: IOException) {
Log.e("ERROR", "Error reading logcat")
}

val modelInstance = DbModel(
userID = DbSingletone.userId,
other = result
)

val tmpDb = DbManager (DbSingletone.context)
tmpDb.openDb()
tmpDb.insertToDb(modelInstance)
})

logcatThread.start()

// Stop reading logcat after 5 seconds
Handler(Looper.getMainLooper()).postDelayed({
logReader.close()
logcatThread.interrupt()
}, 5000)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ import androidx.appcompat.app.AppCompatActivity
import okhttp3.OkHttpClient
import okhttp3.Request
import org.json.JSONArray
import ru.ok.android.itmohack2023.pixels.okHttp.OkHttpInterceptor
import java.io.IOException

class OkHttpActivity : AppCompatActivity() {


override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_ok_http)
Expand All @@ -36,13 +38,17 @@ class OkHttpActivity : AppCompatActivity() {
}
}
}

}

@Throws(IOException::class)
fun run(url: String): String? {
val client = OkHttpClient.Builder()
.addInterceptor(OkHttpInterceptor())
.build()
val request: Request = Request.Builder()
.url(url)
.build()
OkHttpClient().newCall(request).execute().use { response -> return response.body?.string() }
client.newCall(request).execute().use { response -> return response.body?.string() }
}
}
13 changes: 9 additions & 4 deletions app/src/main/java/ru/ok/android/itmohack2023/PicassoActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ package ru.ok.android.itmohack2023
import android.os.Bundle
import android.widget.ImageView
import androidx.appcompat.app.AppCompatActivity
import com.bumptech.glide.Glide
import com.squareup.picasso.OkHttp3Downloader
import com.squareup.picasso.Picasso
import com.squareup.picasso.PicassoProvider
import okhttp3.OkHttpClient
import ru.ok.android.itmohack2023.pixels.okHttp.OkHttpInterceptor
import ru.ok.android.itmohack2023.pixels.picasso.PicassoClientProvider

class PicassoActivity : AppCompatActivity() {
private lateinit var dog1: ImageView
Expand All @@ -28,10 +32,11 @@ class PicassoActivity : AppCompatActivity() {
}

private fun bindImages() {
val picasso = PicassoClientProvider().getClient(this)

Picasso.get().load(URLS[(0 until size).random()]).placeholder(getDrawable(R.drawable.ico_dog)!!).into(dog1)
Picasso.get().load(URLS[(0 until size).random()]).placeholder(getDrawable(R.drawable.ico_dog)!!).into(dog2)
Picasso.get().load(URLS[(0 until size).random()]).placeholder(getDrawable(R.drawable.ico_dog)!!).into(dog3)
picasso.load(URLS[(0 until size).random()]).placeholder(getDrawable(R.drawable.ico_dog)!!).into(dog1)
picasso.load(URLS[(0 until size).random()]).placeholder(getDrawable(R.drawable.ico_dog)!!).into(dog2)
picasso.load(URLS[(0 until size).random()]).placeholder(getDrawable(R.drawable.ico_dog)!!).into(dog3)
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.annotation.SuppressLint
import android.os.Bundle
import android.webkit.WebView
import androidx.appcompat.app.AppCompatActivity
import ru.ok.android.itmohack2023.pixels.webview.PixelsWebViewClient


class WebViewActivity : AppCompatActivity() {
Expand All @@ -14,6 +15,12 @@ class WebViewActivity : AppCompatActivity() {
setContentView(R.layout.activity_web_view)
val webView = findViewById<WebView>(R.id.web_view)
webView.settings.javaScriptEnabled = true


webView.webViewClient = PixelsWebViewClient(webView)



val htmlText = resources.assets.open("webview.html")
.bufferedReader()
.use { it.readText() }
Expand Down
Loading