Skip to content

Commit

Permalink
fix : 권한 처리 플로우 수정
Browse files Browse the repository at this point in the history
- api30 미만에 대한 권한 처리가 없었던 부분 추가
- 권한처리가 api 30 을 기점으로 복잡해지므로 splash 과정과 권한 처리를 별도 activity 로 분리
- 프로가드 룰이 없는데 설정되어 있던 부분 수정 (변조로 인한 datastore proto 파일에서 예외 발생)
- 헬스커넥트는 api 34 를 기점으로 내부 설치 또는 마켓 설치로 분류되는데, 일부 플레이콘솔 내부테스트에서 브라우저 또는 마켓이 없는 디바이스로 테스트를 하는데 이걸로 리젝 당해서 예외 처리로 수정
  • Loading branch information
jowunnal committed Apr 23, 2024
1 parent 1b53a3c commit 8703bc0
Show file tree
Hide file tree
Showing 13 changed files with 390 additions and 233 deletions.
16 changes: 1 addition & 15 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ android {
defaultConfig {
applicationId = "com.stepmate.app"
targetSdk = 34
versionCode = 2
versionCode = 6
versionName = "1.0.0"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
Expand All @@ -20,20 +20,6 @@ android {
}
}

packaging {
resources {
excludes += "/META-INF/{AL2.0,LGPL2.1,LICENSE.md,LICENSE-notice.md}"
}
}

configurations.all {
resolutionStrategy {
exclude(
group = "org.jetbrains.kotlinx",
module = "kotlinx-coroutines-debug"
)
}
}
}

dependencies {
Expand Down
20 changes: 20 additions & 0 deletions app/release/output-metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"version": 3,
"artifactType": {
"type": "APK",
"kind": "Directory"
},
"applicationId": "com.stepmate.app",
"variantName": "release",
"elements": [
{
"type": "SINGLE",
"filters": [],
"attributes": [],
"versionCode": 5,
"versionName": "1.0.0",
"outputFile": "app-release.apk"
}
],
"elementType": "File"
}
45 changes: 25 additions & 20 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,20 @@
<manifest xmlns:android="https://schemas.android.com/apk/res/android"
xmlns:tools="https://schemas.android.com/tools">

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.health.READ_STEPS"/>
<uses-permission android:name="android.permission.health.WRITE_STEPS"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.health.READ_STEPS" />
<uses-permission android:name="android.permission.health.WRITE_STEPS" />

<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" />

<uses-permission android:name="android.permission.POST_NOTIFICATIONS" android:minSdkVersion="33" />
<uses-permission
android:name="android.permission.POST_NOTIFICATIONS"
android:minSdkVersion="33" />

<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.ACTIVITY_RECOGNITION" android:minSdkVersion="29"/>
<uses-permission
android:name="android.permission.ACTIVITY_RECOGNITION"
android:minSdkVersion="29" />

<application
android:name="com.stepmate.app.StepMateApplication"
Expand All @@ -22,35 +26,37 @@
android:label="@string/app_name"
android:roundIcon="@drawable/ic_stepmate"
android:supportsRtl="true"
android:theme="@style/Theme.Stepwalk"
android:theme="@style/Theme.StepMate.Splash"
android:usesCleartextTraffic="true"
tools:targetApi="31">

<activity
android:name="com.stepmate.app.StepMateActivity"
android:name=".ui.navigation.permission.PermissionActivity"
android:exported="true"
android:theme="@style/Theme.Stepwalk"
android:windowSoftInputMode="adjustResize"
android:launchMode="singleTask">
android:theme="@style/Theme.StepMate.Splash">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="androidx.health.ACTION_SHOW_PERMISSIONS_RATIONALE" />
</intent-filter>
</activity>

<activity
android:name="com.stepmate.app.StepMateActivity"
android:exported="true"
android:launchMode="singleTask"
android:theme="@style/Theme.StepMate"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="step_walk"
android:host="home" />
<action android:name="androidx.health.ACTION_SHOW_PERMISSIONS_RATIONALE" />
</intent-filter>
</activity>

<activity-alias
android:name="ViewPermissionUsageActivity"
android:exported="true"
android:targetActivity="com.stepmate.app.StepMateActivity"
android:minSdkVersion="34"
android:permission="android.permission.START_VIEW_PERMISSION_USAGE"
android:minSdkVersion="34">
android:targetActivity="com.stepmate.app.StepMateActivity">
<intent-filter>
<action android:name="android.intent.action.VIEW_PERMISSION_USAGE" />
<category android:name="android.intent.category.HEALTH_PERMISSIONS" />
Expand All @@ -60,8 +66,7 @@
<provider
android:name="androidx.startup.InitializationProvider"
android:authorities="${applicationId}.androidx-startup"
tools:node="remove">
</provider>
tools:node="remove"></provider>

</application>

Expand Down
37 changes: 8 additions & 29 deletions app/src/main/kotlin/com/stepmate/app/StepMateActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package com.stepmate.app

import android.content.Intent
import android.os.Bundle
import android.view.View
import android.view.ViewTreeObserver
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.viewModels
Expand Down Expand Up @@ -35,17 +33,14 @@ import androidx.core.view.WindowCompat
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.lifecycle.lifecycleScope
import androidx.navigation.compose.rememberNavController
import androidx.navigation.navOptions
import com.stepmate.app.ui.StepMateViewModel
import com.stepmate.app.ui.navigation.NavigationDefaults
import com.stepmate.app.ui.navigation.NavigationGraph
import com.stepmate.app.ui.navigation.Router
import com.stepmate.app.ui.navigation.isShownBar
import com.stepmate.app.ui.navigation.permission.permissionRoute
import com.stepmate.app.ui.navigation.stepMateNavigationSuiteItems
import com.stepmate.design.component.StepMateSnackBar
import com.stepmate.design.theme.StepMateTheme
import com.stepmate.home.navigation.homeGraph
import com.stepmate.home.navigation.homeRoute
import com.stepmate.home.navigation.homeUserBody
import com.stepmate.home.service.StepException
Expand All @@ -60,30 +55,17 @@ class StepMateActivity : ComponentActivity() {
private val stepMateViewModel: StepMateViewModel by viewModels()

override fun onCreate(savedInstanceState: Bundle?) {

super.onCreate(savedInstanceState)

WindowCompat.setDecorFitsSystemWindows(window, false)

val content: View = findViewById(android.R.id.content)

content.viewTreeObserver.addOnPreDrawListener(
object : ViewTreeObserver.OnPreDrawListener {
override fun onPreDraw(): Boolean {
return run callback@{
lifecycleScope.launch {
stepMateViewModel.checkPermission()
setContent {
StepMateTheme {
StepMateApp()
}
}
content.viewTreeObserver.removeOnPreDrawListener(this@callback)
}.isCompleted
}
lifecycleScope.launch {
setContent {
StepMateTheme {
StepMateApp()
}
}
)
}
}

override fun onNewIntent(intent: Intent?) {
Expand All @@ -108,12 +90,10 @@ class StepMateActivity : ComponentActivity() {
val router = remember(navController) { Router(navController) }
val snackBarHostState = remember { SnackbarHostState() }

val permissionState by stepMateViewModel.permissionState.collectAsStateWithLifecycle()
val isBodyDataExist by stepMateViewModel.isBodyDataExist.collectAsStateWithLifecycle()
val isNeedReLogin by stepMateViewModel.isNeedReLogin.collectAsStateWithLifecycle()

LaunchedEffect(key1 = isNeedReLogin,) {
if(isNeedReLogin) {
LaunchedEffect(key1 = isNeedReLogin) {
if (isNeedReLogin) {
navController.navigateToLogin(null)
stepMateViewModel.updateIsNeedLogin(false)
}
Expand Down Expand Up @@ -175,8 +155,7 @@ class StepMateActivity : ComponentActivity() {
NavigationGraph(
router = router,
modifier = Modifier,
startDestination = if (permissionState) homeGraph else permissionRoute,
homeStartDestination = if (isBodyDataExist) homeRoute else homeUserBody,
homeStartDestination = if (stepMateViewModel.isBodyDataExist) homeRoute else homeUserBody,
showSnackBar = { snackBarMessage ->
coroutineScope.launch {
snackBarHostState.showSnackbar(
Expand Down
45 changes: 3 additions & 42 deletions app/src/main/kotlin/com/stepmate/app/ui/StepMateViewModel.kt
Original file line number Diff line number Diff line change
@@ -1,61 +1,22 @@
package com.stepmate.app.ui

import android.content.Context
import android.os.Build
import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.ViewModel
import dagger.hilt.android.lifecycle.HiltViewModel
import dagger.hilt.android.qualifiers.ApplicationContext
import com.stepmate.app.ui.navigation.permission.PermissionRequester
import com.stepmate.domain.usecase.user.GetBodyDataUseCases
import com.stepmate.home.HealthConnector
import com.stepmate.home.HealthConnector.Companion.healthConnectPermissions
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.update
import javax.inject.Inject

@HiltViewModel
internal class StepMateViewModel @Inject constructor(
@ApplicationContext private val applicationContext: Context,
private val healthConnector: HealthConnector,
private val getBodyDataUseCases: GetBodyDataUseCases,
savedStateHandle: SavedStateHandle,
) : ViewModel() {

private val _permissionState = MutableStateFlow(false)
val permissionState get() = _permissionState.asStateFlow()

private val _isBodyDataExist = MutableStateFlow(false)
val isBodyDataExist get() = _isBodyDataExist.asStateFlow()
val isBodyDataExist: Boolean = savedStateHandle["isBodyDataExist"] ?: false

private val _isNeedReLogin = MutableStateFlow(false)
val isNeedReLogin get() = _isNeedReLogin.asStateFlow()

suspend fun checkPermission() {
val isNotificationGranted =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU)
PermissionRequester.checkNotification(applicationContext)
else
true

val isActivityRecognitionGranted =
PermissionRequester.checkActivityRecognition(applicationContext)

val isExactAlarmGranted =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S)
PermissionRequester.checkExactAlarm(applicationContext)
else
true

val isHealthConnectGranted = healthConnector.checkPermissions(healthConnectPermissions)
isBodyDataExist()
_permissionState.update { isNotificationGranted && isActivityRecognitionGranted && isExactAlarmGranted && isHealthConnectGranted }
}

private suspend fun isBodyDataExist() = getBodyDataUseCases().onEach { bodyData ->
_isBodyDataExist.update { bodyData.age != 0 && bodyData.height != 0 && bodyData.weight != 0 }
}.first()

fun updateIsNeedLogin(bool: Boolean) = _isNeedReLogin.update { bool }
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,12 @@ import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.res.vectorResource
import androidx.navigation.NavDestination
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.navOptions
import com.stepmate.app.ui.navigation.permission.PermissionScreen
import com.stepmate.app.ui.navigation.permission.permissionRoute
import com.stepmate.core.SnackBarMessage
import com.stepmate.home.navigation.homeGraph
import com.stepmate.home.navigation.homeNavGraph
import com.stepmate.home.navigation.navigateToCalendar
import com.stepmate.home.navigation.navigateToHome
import com.stepmate.home.navigation.navigateToHomeGraph
import com.stepmate.home.navigation.navigateToHomeSetting
import com.stepmate.login.navigation.authNavGraph
import com.stepmate.login.navigation.navigateToFindId
Expand All @@ -47,24 +44,16 @@ import com.stepmate.ranking.navigation.rankingRoute
internal fun NavigationGraph(
router: Router,
modifier: Modifier = Modifier,
startDestination: String,
homeStartDestination: String,
showSnackBar: (SnackBarMessage) -> Unit,
) {
val navController = router.navController

NavHost(
navController = navController,
startDestination = startDestination,
startDestination = homeGraph,
modifier = modifier
) {
composable(route = permissionRoute) {
PermissionScreen(
showSnackBar = showSnackBar,
navigateToHomeGraph = navController::navigateToHomeGraph
)
}

homeNavGraph(
startDestination = homeStartDestination,
navigateToCalendar = navController::navigateToCalendar,
Expand Down
Loading

0 comments on commit 8703bc0

Please sign in to comment.