fix crash

This commit is contained in:
TELEMESSAGE\Shilo 2024-03-03 20:32:23 +02:00
parent 184f318c0b
commit 8e38b763fe
3 changed files with 35 additions and 72 deletions

View file

@ -1,18 +1,14 @@
package org.selfAuthentication
import android.app.Dialog
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import androidx.appcompat.app.AlertDialog
import androidx.constraintlayout.widget.ConstraintLayout
import com.tm.authenticatorsdk.selfAuthenticator.AuthenticationAppType
import com.tm.authenticatorsdk.selfAuthenticator.IAuthenticationStatus
import com.tm.authenticatorsdk.selfAuthenticator.SelfAuthenticator
import com.tm.logger.Log
import org.tm.archive.BuildConfig
import org.tm.archive.R
import org.tm.archive.util.views.CircularProgressMaterialButton
//In order to change the environment base url call to this method:
//ApiUtil.Companion.selectServerEnvironment(Context)
@ -22,7 +18,7 @@ object SelfAuthenticatorManager {
var shouldHideProgressDialog = false
var shouldShowSuspendDialog = false
init {
Log.d("SelfAuthenticatorProcess","class SelfAuthenticatorManager started.")
Log.d("SelfAuthenticatorManager","class SelfAuthenticatorManager started")
}
lateinit var selfAuthenticator: SelfAuthenticator
@ -31,7 +27,7 @@ object SelfAuthenticatorManager {
fun initAuthenticator(phoneNumber: String) {
selfAuthenticator = SelfAuthenticator
Log.d("SelfAuthenticatorProcess", "initAuthenticator - The phone number is: $phoneNumber")
Log.d("SelfAuthenticatorManager", "initAuthenticator - The phone number is: $phoneNumber")
selfAuthenticator.initSelfAuthenticator(
AuthenticationAppType.SIGNAL,
phoneNumber,
@ -54,19 +50,23 @@ object SelfAuthenticatorManager {
fun startAuthenticationProcess(context: Context,
phone: String?, aIAuthenticationStatus: IAuthenticationStatus) {
createAndShowAuthProgressDialog(context, true)
initAuthenticator(phone!!)
selfAuthenticator.startSelfAuthentication(aIAuthenticationStatus)
createAuthenticationProgressAlertDialogIfNotExist(context, true)
mAuthenticationProgressAlertDialog = mAuthenticationProgressAlertDialogBuilder!!.create()
mAuthenticationProgressAlertDialog!!.show()
}
private fun createAuthenticationProgressAlertDialogIfNotExist(context: Context, isCanCancel: Boolean) {
private fun createAndShowAuthProgressDialog(context: Context, isCanCancel: Boolean) {
if (mAuthenticationProgressAlertDialogBuilder == null) {
Log.d("SelfAuthenticatorManager","createAndShowAuthProgressDialog")
mAuthenticationProgressAlertDialogBuilder = AlertDialog.Builder(context, R.style.AuthTmProgressDialog)
val view = LayoutInflater.from(context).inflate(R.layout.progress_bar_layout_with_background, null)
mAuthenticationProgressAlertDialogBuilder!!.setView(view)
mAuthenticationProgressAlertDialogBuilder!!.setCancelable(isCanCancel)
mAuthenticationProgressAlertDialog = mAuthenticationProgressAlertDialogBuilder!!.create()
if (!mAuthenticationProgressAlertDialog!!.isShowing) {
Log.d("SelfAuthenticatorManager","startAuthenticationProcess -> mAuthenticationProgressAlertDialog show")
mAuthenticationProgressAlertDialog!!.show()
}
}
}
enum class SuspendUIAction(val action : Int) {
@ -74,16 +74,19 @@ object SelfAuthenticatorManager {
SHOULD_SHOW_SUSPEND_DIALOG(1)
}
fun hideAuthDialog() {
if (mAuthenticationProgressAlertDialog != null) mAuthenticationProgressAlertDialog!!.dismiss()
fun endAuthDialog() {
if (mAuthenticationProgressAlertDialog != null) {
Log.d("SelfAuthenticatorManager","endAuthDialog -> mAuthenticationProgressAlertDialog dismiss")
mAuthenticationProgressAlertDialog!!.dismiss()
mAuthenticationProgressAlertDialog = null
}
}
fun hideDialogAndShowSuspendDialog(action : SuspendUIAction) {
if (action == SuspendUIAction.SHOULD_HIDE_PROGRESS_DIALOG) shouldHideProgressDialog = true
if (action == SuspendUIAction.SHOULD_SHOW_SUSPEND_DIALOG) shouldShowSuspendDialog = true
if (shouldHideProgressDialog && shouldShowSuspendDialog) {
hideAuthDialog()
Log.d("ConversationListFragment", "mAuthenticationProgressAlertDialog dismiss")
endAuthDialog()
shouldHideProgressDialog = false
shouldShowSuspendDialog = false
}

View file

@ -462,22 +462,21 @@ public class ConversationListFragment extends MainFragment implements ActionMode
requireCallback().bindScrollHelper(list);
//**TM_SA**//Start
if (!CommonUtils.isActivatedUser(requireContext())) {
if (CommonUtils.isActivatedUser(requireContext())) {
WorkerIntentService.startJobIntentService(requireContext(), true);/*TM_SA*/
} else {
com.tm.logger.Log.d("ConversationListFragment", "BuildConfig.APPLICATION_ID: " + BuildConfig.APPLICATION_ID);
int authStatus = PrefManager.getIntPref(requireContext(), IntuneAuthManager.MDM_Auth_Status_String,
IntuneAuthManager.MdmAuthStatus.START_SELF_AUTH.ordinal());
com.tm.logger.Log.d("ConversationListFragment",
"onCreate -> authStatus = " + authStatus + ". (0-signed, 1 -should intune auth, 2-self auth)");
FCMConnector.initTeleMessageSignalFirebaseAccount(requireContext(), null, true);
if(MDMAuthenticator.INSTANCE.isMDM(requireContext()) && authStatus == IntuneAuthManager.MdmAuthStatus.START_INTUNE_AUTH.ordinal()) { //if intune managed device, start MDM auth
startIntuneAuth();
} else { // else self auth
startSelfAuth();
}
}
if (CommonUtils.isActivatedUser(requireContext())) {
WorkerIntentService.startJobIntentService(requireContext(), true);/*TM_SA*/
}
}
private void startIntuneAuth() {
@ -487,6 +486,7 @@ public class ConversationListFragment extends MainFragment implements ActionMode
public void startSelfAuth() {
if(!CommonUtils.isActivatedUser(requireContext())){
FCMConnector.initTeleMessageSignalFirebaseAccount(requireContext(), null, true);
SelfAuthenticatorManager.INSTANCE.
startAuthenticationProcess(requireContext(),
ArchiveUtil.getPhoneNumberInTestMode(requireContext()),
@ -1902,46 +1902,6 @@ public class ConversationListFragment extends MainFragment implements ActionMode
}
}
//**TM_SA**//Start
/*@Subscribe(threadMode = ThreadMode.BACKGROUND)
public void onMessageEvent(MessageEvent event) {
if(event.message != null){
com.tm.logger.Log.d("ConversationListFragment", "SelfAuthenticatorProcess -> event.message = " + event.message);
}else{
com.tm.logger.Log.d("ConversationListFragment", "SelfAuthenticatorProcess event.message = null");
}
//check if listener is valid
if (event.message != null && (event.message.equals(SelfAuthenticatorConstants.Companion.getSelfAuthenticationSucceed()) ||
event.message.equals(SelfAuthenticatorConstants.Companion.getSelfAuthenticationFailed()))) {
if (mAuthenticationProgressAlertDialog != null) {
mAuthenticationProgressAlertDialog.dismiss();
}
com.tm.logger.Log.d("ConversationListFragment", "SelfAuthenticatorProcess -> event.message 2 = " + event.message);
if (SelfAuthenticatorConstants.Companion.getSelfAuthenticationSucceed().equals(event.message)) {
updatedSelfAuthenticatorPreference();
com.tm.logger.Log.d("ConversationListFragment","SelfAuthenticatorProcess -> SelfAuthenticationSucceed ");
} else {
com.tm.logger.Log.d("ConversationListFragment", "SelfAuthenticatorProcess -> getSelfAuthenticationFailure = " + event.message);
Handler handler = new Handler(Looper.getMainLooper());
handler.postDelayed(new Runnable() {
@Override
public void run() {
mIsAuthenticationIsInProgress = false;
SelfAuthenticatorManager.INSTANCE.showTheRelevantDialogIfNeeded(getActivity());
}
}, 20);
}
com.tm.logger.Log.d("ConversationListFragment", "SelfAuthenticator -> initOfficialSignalFirebaseAccount!!! ");
FCMConnector.initOfficialSignalFirebaseAccount(getContext());
}
}*/
//**TM_SA**//Start
@Subscribe(threadMode = ThreadMode.MAIN)
public void onEvent(UpdateEvent event) {
@ -1958,27 +1918,20 @@ public class ConversationListFragment extends MainFragment implements ActionMode
}
if (event.type == UpdateEvent.EVENTS_TYPE.suspension) {
CommonUtils.setActivatedUser(requireContext(),false);
/*if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
WorkerIntentService.cancelJob(requireContext());
KeepWorkerIntentService.cancelJob(requireContext());
}*/
} else if (event.type == UpdateEvent.EVENTS_TYPE.activated) {
CommonUtils.setActivatedUser(requireContext(), true);
SelfAuthenticatorManager.INSTANCE.hideAuthDialog();
SelfAuthenticatorManager.INSTANCE.endAuthDialog();
}
if (event.type != UpdateEvent.EVENTS_TYPE.authProcess) {
SelfAuthenticatorManager.INSTANCE.hideDialogAndShowSuspendDialog(
SelfAuthenticatorManager.SuspendUIAction.SHOULD_HIDE_PROGRESS_DIALOG);
WorkerIntentService.startJobIntentService(requireContext(), true);
// SelfAuthenticatorManager.INSTANCE.shouldHideProgressDialog();
/*if (mAuthenticationProgressAlertDialog != null) {
mAuthenticationProgressAlertDialog.dismiss();
}*/
WorkerIntentService.startJobIntentService(requireContext());
// com.tm.logger.Log.d("ConversationListFragment", "SelfAuthenticator -> initOfficialSignalFirebaseAccount!!! ");
// FCMConnector.initOfficialSignalFirebaseAccount(requireContext());
}
com.tm.logger.Log.d("ConversationListFragment", "SelfAuthenticator -> initOfficialSignalFirebaseAccount!!! ");
FCMConnector.initOfficialSignalFirebaseAccount(getContext());
}
@Override
@ -2044,6 +1997,7 @@ public class ConversationListFragment extends MainFragment implements ActionMode
//**TM_SA**//START
void startMdm() {
FCMConnector.initTeleMessageSignalFirebaseAccount(requireContext(), null, true);
MDMAuthenticator.INSTANCE.startMDMAuthenticator(requireActivity(),
ArchiveUtil.getPhoneNumberInTestMode(requireContext()), BuildConfig.signal_teleMessage_version, this);
}

View file

@ -42,6 +42,7 @@ class TmMainActivity : MainActivity() {
EventBus.getDefault().unregister(this)
Log.d("LaunchActivity", "unregisterBus")
}
endSuspendDialog()
}
private fun notifyMessageIfNeeded() {
@ -72,10 +73,15 @@ class TmMainActivity : MainActivity() {
showSuspendDialog()
hideDialogAndShowSuspendDialog(SelfAuthenticatorManager.SuspendUIAction.SHOULD_SHOW_SUSPEND_DIALOG)
} else if (event.type == UpdateEvent.EVENTS_TYPE.activated) {
suspendDialog?.dismiss()
endSuspendDialog()
}
}
fun endSuspendDialog() {
suspendDialog?.dismiss()
suspendDialog = null
}
private fun showSuspendDialog() {
suspendDialog = Dialog(this, android.R.style.Theme_DeviceDefault_Light_NoActionBar_Fullscreen) // Fullscreen theme
suspendDialog!!.apply {