Skip to content

Commit

Permalink
Merge pull request #12 from skydoves/feature/device-info
Browse files Browse the repository at this point in the history
Add package info and device info on the stack trace screen
  • Loading branch information
skydoves authored Sep 17, 2023
2 parents 93c573a + ba09fe6 commit 284d16d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ package com.skydoves.snitcher.extensions
import android.app.Activity
import android.content.Context
import android.content.ContextWrapper
import android.content.pm.PackageInfo
import android.os.Build
import android.widget.Toast

@JvmSynthetic
Expand All @@ -34,3 +36,21 @@ internal fun Context.findActivity(): Activity? {
}
return null
}

@JvmSynthetic
internal fun Context.packageInfo(): PackageInfo? {
return try {
packageManager.getPackageInfo(packageName, 0)
} catch (e: Exception) {
null
}
}

@JvmSynthetic
internal fun PackageInfo?.versionCode(): Long? {
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
this?.longVersionCode
} else {
this?.versionCode?.toLong()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@file:OptIn(ExperimentalComposeUiApi::class)

package com.skydoves.snitcher.ui

import android.content.Intent
import android.content.Intent.FLAG_ACTIVITY_CLEAR_TASK
import android.os.Build
import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.background
import androidx.compose.foundation.border
Expand All @@ -41,7 +40,6 @@ import androidx.compose.material.icons.filled.RestartAlt
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.ClipboardManager
import androidx.compose.ui.platform.LocalClipboardManager
Expand All @@ -54,7 +52,9 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.skydoves.snitcher.R
import com.skydoves.snitcher.extensions.findActivity
import com.skydoves.snitcher.extensions.packageInfo
import com.skydoves.snitcher.extensions.toast
import com.skydoves.snitcher.extensions.versionCode
import com.skydoves.snitcher.model.SnitcherException
import com.skydoves.snitcher.ui.theme.SnitcherStatusBarColor
import com.skydoves.snitcher.ui.theme.SnitcherTheme
Expand All @@ -79,6 +79,7 @@ private fun ExceptionTraceScreenContent(
) {
val context = LocalContext.current
val scrollState = rememberScrollState()
val packageInfo = remember { context.packageInfo() }

Column(
modifier = Modifier
Expand All @@ -105,6 +106,14 @@ private fun ExceptionTraceScreenContent(
fontSize = 18.sp,
)

Text(
modifier = Modifier.padding(vertical = 6.dp),
text = "${packageInfo?.versionName} (${packageInfo?.versionCode()}) " +
"${Build.MANUFACTURER} ${Build.MODEL}",
color = SnitcherTheme.colors.textHighEmphasis,
fontSize = 18.sp,
)

SnitcherPrimaryButton(
modifier = Modifier.padding(vertical = 16.dp),
icon = Icons.Filled.RestartAlt,
Expand Down

0 comments on commit 284d16d

Please sign in to comment.