Merge 1.0.4 version to master (#17)
Co-authored-by: Sayed Owais Ali <sayed.owais@navi.com>
This commit is contained in:
committed by
Shivam Goyal
parent
c2ae033b7d
commit
203d67da05
@@ -25,7 +25,7 @@
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name=".activity.DemoActivity"
|
||||
android:name=".activity.SWWActivity"
|
||||
android:exported="true"
|
||||
android:theme="@style/Theme.AppCompat.Light" />
|
||||
</application>
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.alfred.demo
|
||||
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.util.Log
|
||||
import com.navi.alfred.model.ErrorMessage
|
||||
import com.navi.alfred.network.model.RequestInfo
|
||||
import com.navi.alfred.utils.AlfredConstants.BROADCAST_ACTION_TYPE
|
||||
import com.navi.alfred.utils.AlfredConstants.BROADCAST_ERROR_MESSAGE
|
||||
import com.navi.alfred.utils.AlfredConstants.BROADCAST_EXCEPTION
|
||||
import com.navi.alfred.utils.AlfredConstants.BROADCAST_REQUEST
|
||||
import android.widget.Toast
|
||||
import com.navi.alfred.utils.log
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
class AlfredNetworkFailureReceiver : BroadcastReceiver() {
|
||||
override fun onReceive(context: Context?, intent: Intent?) {
|
||||
if (intent?.action == BROADCAST_ACTION_TYPE) {
|
||||
try {
|
||||
val exception = intent.getSerializableExtra(BROADCAST_EXCEPTION)
|
||||
val request = intent.getParcelableExtra<RequestInfo>(BROADCAST_REQUEST)
|
||||
val errorMessage = intent.getParcelableExtra<ErrorMessage>(BROADCAST_ERROR_MESSAGE)
|
||||
|
||||
if (exception is Exception) {
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
Log.d(
|
||||
"AlfredNetworkFailure",
|
||||
"Network Failure exception = $exception, request = $request, errorMessage = $errorMessage"
|
||||
)
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
e.log()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,12 +2,10 @@ package com.alfred.demo
|
||||
|
||||
import android.app.Activity
|
||||
import android.app.Application
|
||||
import android.content.IntentFilter
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import androidx.appcompat.widget.AppCompatTextView
|
||||
import com.alfred.demo.activity.DemoActivity
|
||||
import com.alfred.demo.activity.SWWActivity
|
||||
import com.alfred.demo.activity.MainActivity
|
||||
import com.navi.alfred.AlfredConfig
|
||||
import com.navi.alfred.AlfredManager
|
||||
@@ -17,13 +15,10 @@ import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import com.github.anrwatchdog.ANRWatchDog
|
||||
import com.navi.alfred.callbacks.NetworkCallback
|
||||
import com.navi.alfred.model.ErrorMessage
|
||||
import com.navi.alfred.network.AlfredRetrofitProvider
|
||||
import okhttp3.Request
|
||||
import okhttp3.Response
|
||||
import com.navi.alfred.AlfredManager.isAlfredRecordingEnabled
|
||||
import com.navi.alfred.utils.AlfredConstants.BROADCAST_ACTION_TYPE
|
||||
|
||||
class MainApplication : Application(), Application.ActivityLifecycleCallbacks, NetworkCallback {
|
||||
class MainApplication : Application(), Application.ActivityLifecycleCallbacks {
|
||||
private var appForegroundCounter: Int = 0
|
||||
|
||||
override fun onCreate() {
|
||||
@@ -53,13 +48,8 @@ class MainApplication : Application(), Application.ActivityLifecycleCallbacks, N
|
||||
"LINE_NUMBER" to it.cause?.stackTrace?.get(0)?.lineNumber.toString(),
|
||||
"APP_IN_FOREGROUND" to isAppInForeground().toString()
|
||||
)
|
||||
if (AlfredManager.config.getAlfredStatus() && AlfredManager.config.getAnrEnableStatus()) {
|
||||
anrEventProperties["STACK_TRACE"] = it.cause?.stackTrace?.get(0).toString()
|
||||
val anrView =
|
||||
LayoutInflater.from(applicationContext).inflate(R.layout.anr_screen, null)
|
||||
AlfredManager.measureInflatedView(anrView)
|
||||
AlfredManager.handleAnrEvent(anrEventProperties, anrView)
|
||||
}
|
||||
anrEventProperties["STACK_TRACE"] = it.cause?.stackTrace?.get(0).toString()
|
||||
AlfredManager.handleAnrEvent(anrEventProperties)
|
||||
}.start()
|
||||
|
||||
// Crash Reporting to backend
|
||||
@@ -76,15 +66,10 @@ class MainApplication : Application(), Application.ActivityLifecycleCallbacks, N
|
||||
"LINE_NUMBER" to exception.stackTrace[0]?.lineNumber.toString(),
|
||||
"APP_IN_FOREGROUND" to isAppInForeground().toString()
|
||||
)
|
||||
if (AlfredManager.config.getAlfredStatus() && AlfredManager.config.getCrashEnableStatus()) {
|
||||
exception.stackTrace[0]?.let { stackTraceElement ->
|
||||
crashEventProperties["STACK_TRACE"] = stackTraceElement.toString()
|
||||
}
|
||||
val crashView =
|
||||
LayoutInflater.from(applicationContext).inflate(R.layout.crash_screen, null)
|
||||
AlfredManager.measureInflatedView(crashView)
|
||||
AlfredManager.handleCrashEvent(crashEventProperties, crashView.rootView)
|
||||
exception.stackTrace[0]?.let { stackTraceElement ->
|
||||
crashEventProperties["STACK_TRACE"] = stackTraceElement.toString()
|
||||
}
|
||||
AlfredManager.handleCrashEvent(crashEventProperties)
|
||||
} finally {
|
||||
defaultHandler?.uncaughtException(thread, exception)
|
||||
}
|
||||
@@ -110,13 +95,7 @@ class MainApplication : Application(), Application.ActivityLifecycleCallbacks, N
|
||||
override fun onActivityStopped(activity: Activity) {
|
||||
appForegroundCounter--
|
||||
if (appForegroundCounter == 0) {
|
||||
if (AlfredManager.config.getAlfredStatus() && AlfredManager.config.getEnableRecordingStatus()) {
|
||||
val appBackgroundView =
|
||||
LayoutInflater.from(this)
|
||||
.inflate(R.layout.app_background_screen, null)
|
||||
AlfredManager.measureInflatedView(appBackgroundView)
|
||||
AlfredManager.stopRecording(appBackgroundView)
|
||||
}
|
||||
AlfredManager.stopRecording()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,29 +106,23 @@ class MainApplication : Application(), Application.ActivityLifecycleCallbacks, N
|
||||
}
|
||||
|
||||
private fun startAlfredRecording(activity: Activity) {
|
||||
if (AlfredManager.config.getAlfredStatus() && AlfredManager.config.getEnableRecordingStatus()) {
|
||||
var screenName: kotlin.String? = null
|
||||
var moduleName: kotlin.String? = null
|
||||
var thirdPartyScreenView: View? = null
|
||||
if (isAlfredRecordingEnabled()) {
|
||||
val screenName: String?
|
||||
val moduleName: String?
|
||||
when (activity) {
|
||||
is MainActivity -> {
|
||||
screenName = "MainActivity"
|
||||
moduleName = "Demo App"
|
||||
}
|
||||
|
||||
is DemoActivity -> {
|
||||
screenName = "DemoActivity"
|
||||
is SWWActivity -> {
|
||||
screenName = "SWWActivity"
|
||||
moduleName = "Demo App"
|
||||
}
|
||||
|
||||
else -> {
|
||||
screenName = AlfredConstants.THIRD_PARTY_SCREEN
|
||||
moduleName = AlfredConstants.THIRD_PARTY_MODULE
|
||||
thirdPartyScreenView = LayoutInflater.from(applicationContext)
|
||||
.inflate(R.layout.third_party_screen, null)
|
||||
AlfredManager.measureInflatedView(thirdPartyScreenView)
|
||||
thirdPartyScreenView.findViewById<AppCompatTextView>(R.id.tv_third_party_name).text =
|
||||
"${activity.localClassName}"
|
||||
}
|
||||
}
|
||||
try {
|
||||
@@ -158,7 +131,6 @@ class MainApplication : Application(), Application.ActivityLifecycleCallbacks, N
|
||||
activity.window.decorView.rootView,
|
||||
screenName,
|
||||
moduleName,
|
||||
thirdPartyScreenView,
|
||||
onSessionIdGenerated = { sessionId ->
|
||||
Log.d("Alfred", "Alfred Session ID: $sessionId")
|
||||
}
|
||||
@@ -175,14 +147,16 @@ class MainApplication : Application(), Application.ActivityLifecycleCallbacks, N
|
||||
|
||||
private fun getAlfredCruiseInfo() {
|
||||
Log.d("Alfred", "Alfred - getAlfredCruiseInfo started")
|
||||
val appNetworkReceiver = AlfredNetworkFailureReceiver()
|
||||
val intentFilter = IntentFilter(BROADCAST_ACTION_TYPE)
|
||||
registerReceiver(appNetworkReceiver, intentFilter)
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
try {
|
||||
Log.d(
|
||||
"Alfred",
|
||||
"Alfred - getAlfredCruiseInfo started inside try thread = ${Thread.currentThread().name}"
|
||||
)
|
||||
AlfredManager.getCruiseConfig(cruiseApiSuccessful = { response ->
|
||||
AlfredRetrofitProvider.setNetworkCallback(this@MainApplication)
|
||||
AlfredManager.getAlfredCruiseInfo(cruiseApiSuccessful = { response ->
|
||||
Log.d(
|
||||
"Alfred",
|
||||
"Alfred - getAlfredCruiseInfo cruiseApiSuccessful h response = $response"
|
||||
@@ -194,20 +168,4 @@ class MainApplication : Application(), Application.ActivityLifecycleCallbacks, N
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onNetworkRequest(request: okhttp3.Request?) {
|
||||
Log.d("Alfred", "Alfred - onNetworkRequest request = $request")
|
||||
}
|
||||
|
||||
override fun onNetworkSuccess(response: Response?) {
|
||||
Log.d("Alfred", "Alfred - onNetworkSuccess response = $response")
|
||||
}
|
||||
|
||||
override fun onNetworkFailure(
|
||||
exception: Exception,
|
||||
errorMessage: ErrorMessage,
|
||||
request: Request
|
||||
) {
|
||||
Log.d("Alfred", "Alfred - onNetworkFailure exception = $exception request = $request")
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
package com.alfred.demo.activity
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.MotionEvent
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import com.alfred.demo.R
|
||||
import com.navi.alfred.AlfredManager
|
||||
|
||||
class DemoActivity : AppCompatActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_demo)
|
||||
}
|
||||
|
||||
override fun dispatchTouchEvent(ev: MotionEvent?): Boolean {
|
||||
AlfredManager.handleTouchEvent(
|
||||
ev,
|
||||
screenName = "Demo Activity",
|
||||
moduleName = "Alfred Demo App",
|
||||
)
|
||||
return super.dispatchTouchEvent(ev)
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,7 @@ class MainActivity : AppCompatActivity() {
|
||||
|
||||
val button = findViewById<Button>(R.id.button)
|
||||
button.setOnClickListener {
|
||||
val intent = Intent(this, DemoActivity::class.java)
|
||||
val intent = Intent(this, SWWActivity::class.java)
|
||||
startActivity(intent)
|
||||
}
|
||||
}
|
||||
|
||||
57
app/src/main/java/com/alfred/demo/activity/SWWActivity.kt
Normal file
57
app/src/main/java/com/alfred/demo/activity/SWWActivity.kt
Normal file
@@ -0,0 +1,57 @@
|
||||
package com.alfred.demo.activity
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.MotionEvent
|
||||
import android.widget.Button
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import com.alfred.demo.R
|
||||
import com.navi.alfred.AlfredManager
|
||||
|
||||
class SWWActivity : AppCompatActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_sww)
|
||||
|
||||
val button = findViewById<Button>(R.id.sww_button)
|
||||
button.setOnClickListener {
|
||||
onSSWError(
|
||||
"SWW Button Clicked",
|
||||
"400",
|
||||
"SWW Activity",
|
||||
"Alfred Demo App",
|
||||
400,
|
||||
"WIFI"
|
||||
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
override fun dispatchTouchEvent(ev: MotionEvent?): Boolean {
|
||||
AlfredManager.handleTouchEvent(
|
||||
ev,
|
||||
screenName = "Demo Activity",
|
||||
moduleName = "Alfred Demo App",
|
||||
)
|
||||
return super.dispatchTouchEvent(ev)
|
||||
}
|
||||
|
||||
private fun onSSWError(
|
||||
reason: String?,
|
||||
code: String?,
|
||||
screenName: String?,
|
||||
moduleName: String,
|
||||
statusCode: Int?,
|
||||
networkType: String?
|
||||
) {
|
||||
val swwEventProperties =
|
||||
mapOf(
|
||||
Pair("module", moduleName),
|
||||
Pair("reason", reason.orEmpty()),
|
||||
Pair("code", code.orEmpty()),
|
||||
Pair("screen_name", screenName.orEmpty()),
|
||||
Pair("status_code", statusCode.toString()),
|
||||
Pair("network_type", networkType.orEmpty())
|
||||
)
|
||||
AlfredManager.handleSWWEvent(swwEventProperties)
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="100dp"
|
||||
android:text="Alfred Demo!" />
|
||||
|
||||
</LinearLayout>
|
||||
@@ -15,6 +15,6 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:text="Open Demo Activity" />
|
||||
android:text="Open SWW Screen" />
|
||||
|
||||
</LinearLayout>
|
||||
21
app/src/main/res/layout/activity_sww.xml
Normal file
21
app/src/main/res/layout/activity_sww.xml
Normal file
@@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@color/white">
|
||||
|
||||
<Button
|
||||
android:id="@+id/sww_button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="10dp"
|
||||
android:text="Trigger SWW"
|
||||
android:textColor="@color/black"
|
||||
android:textSize="14sp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
Reference in New Issue
Block a user