diff --git a/app/src/main/java/jp/atled/agileworks/model/AppRepository.kt b/app/src/main/java/jp/atled/agileworks/model/AppRepository.kt new file mode 100644 index 0000000000000000000000000000000000000000..87de81df651a202507385686220ea063fdd6db1b --- /dev/null +++ b/app/src/main/java/jp/atled/agileworks/model/AppRepository.kt @@ -0,0 +1,17 @@ +package jp.atled.agileworks.model + +class AppRepository { + fun getAppBackGroundStatus(): Boolean { + return appBackGroundStatus + } + + fun setAppBackGroundStatus(status: Boolean) { + appBackGroundStatus = status + } + + companion object { + fun getInstance() = AppRepository() + // アプリがバックグラウンドか + private var appBackGroundStatus = false + } +} \ No newline at end of file diff --git a/app/src/main/java/jp/atled/agileworks/view/base/BaseViewModel.kt b/app/src/main/java/jp/atled/agileworks/view/base/BaseViewModel.kt index 571531a7271a199d8c211eeee3b484300aa650f8..657b14562c0c11a19dba7659a149fb0be00e1995 100644 --- a/app/src/main/java/jp/atled/agileworks/view/base/BaseViewModel.kt +++ b/app/src/main/java/jp/atled/agileworks/view/base/BaseViewModel.kt @@ -8,6 +8,7 @@ import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.SharedFlow import kotlinx.coroutines.flow.asSharedFlow import kotlinx.coroutines.launch +import jp.atled.agileworks.model.AppRepository open class BaseViewModel : ViewModel() { @@ -23,4 +24,11 @@ open class BaseViewModel : ViewModel() { reselectedItemSource.emit(selectedId) } } + fun getAppBackGroundStatus(): Boolean { + return AppRepository.getInstance().getAppBackGroundStatus() + } + + fun setAppBackGroundStatus(status: Boolean) { + AppRepository.getInstance().setAppBackGroundStatus(status) + } } \ No newline at end of file diff --git a/app/src/main/java/jp/atled/agileworks/view/ui/documentweb/DocumentWebFragment.kt b/app/src/main/java/jp/atled/agileworks/view/ui/documentweb/DocumentWebFragment.kt index df918789684b4b3d37dfe936bc6934fe9777f586..b651560200ce422f16f0e6e1da87daafa3a933aa 100644 --- a/app/src/main/java/jp/atled/agileworks/view/ui/documentweb/DocumentWebFragment.kt +++ b/app/src/main/java/jp/atled/agileworks/view/ui/documentweb/DocumentWebFragment.kt @@ -12,8 +12,6 @@ import android.webkit.CookieManager import android.webkit.WebView import android.widget.Button import android.widget.RelativeLayout -import android.widget.TextView -import android.widget.Toolbar import androidx.core.view.GestureDetectorCompat import androidx.fragment.app.Fragment import androidx.fragment.app.activityViewModels @@ -108,6 +106,9 @@ class DocumentWebFragment : Fragment(), DocumentWebPresenter { displayDisconnectViewState() webShare.presenter.updateAutoReloadState(true) + + // アプリがバックグラウンドかの情報 + viewDataBinding?.viewModel?.setAppBackGroundStatus(false) } override fun onDestroyView() { @@ -135,6 +136,8 @@ class DocumentWebFragment : Fragment(), DocumentWebPresenter { } catch (e: Exception) { Log.e(TAG, "${e.message}") } + // バックグラウンドかの情報 + viewDataBinding?.viewModel?.setAppBackGroundStatus(true) } @SuppressLint("ClickableViewAccessibility") diff --git a/app/src/main/java/jp/atled/agileworks/view/ui/login/LoginFragment.kt b/app/src/main/java/jp/atled/agileworks/view/ui/login/LoginFragment.kt index 0b4d81da233d6c0f94e0c4747ca871085cbd394c..d670125e00e61121a631d63aa9023638bf0ab8da 100644 --- a/app/src/main/java/jp/atled/agileworks/view/ui/login/LoginFragment.kt +++ b/app/src/main/java/jp/atled/agileworks/view/ui/login/LoginFragment.kt @@ -75,16 +75,23 @@ class LoginFragment: Fragment() { } else { // 過去に認証したときの authState を取得 if (mOAuthService.getAuthState(savedInstanceState).isAuthorized) { - // 認証済みの場合、生体/デバイス認証を実行 - Log.d(TAG, "authState.isAuthorized == true") - if (BiometricPrompt.anyAuthenticationAvailable(this.requireContext())) { + if (binding.viewmodel?.getAppBackGroundStatus() == true) { + Log.d(TAG, "authState.isAuthorized == true") + Log.d(TAG,"appBackGroundStatus == true") disableLogin() - Handler().postDelayed({ - startBiometricPrompt() - }, 0) + onSuccessAuth() } else { - // 認証設定が全くされていない場合、一旦ログアウトしてから同じサーバ・ドメインで OAuth2 認証を再実行 - relogin() + // 認証済みの場合、生体/デバイス認証を実行 + Log.d(TAG, "authState.isAuthorized == true") + if (BiometricPrompt.anyAuthenticationAvailable(this.requireContext())) { + disableLogin() + Handler().postDelayed({ + startBiometricPrompt() + }, 0) + } else { + // 認証設定が全くされていない場合、一旦ログアウトしてから同じサーバ・ドメインで OAuth2 認証を再実行 + relogin() + } } } else { // 認証されていない場合、ログイン画面を表示 @@ -243,7 +250,7 @@ class LoginFragment: Fragment() { Log.d(TAG, "call startBiometricPrompt()") BiometricPrompt.auth(this.requireActivity()) { when (it) { - BiometricPrompt.Result.Success -> onSuccessBiometricAuth() + BiometricPrompt.Result.Success -> onSuccessAuth() BiometricPrompt.Result.UnsupportedHardware -> onFailureAuthBiometricPrompt(R.string.auth_biometric_unsupported_hardware) BiometricPrompt.Result.NotHasBiometricsOnHardware -> onFailureAuthBiometricPrompt(R.string.auth_biometric_not_has_biometrics_on_hardware) BiometricPrompt.Result.Cancel -> onFailureAuthBiometricPrompt(R.string.auth_biometric_cancel) @@ -252,9 +259,9 @@ class LoginFragment: Fragment() { } } - private fun onSuccessBiometricAuth() { - // 生体認証に成功した場合、トークンを更新 - Log.d(TAG, "call onSuccessBiometricAuth()") + private fun onSuccessAuth() { + // トークンを更新 + Log.d(TAG, "call onBiometricAuth()") mOAuthService.performAction(AuthState.AuthStateAction() { accessToken, _, ex -> if (ex != null) {