From 09fc78920c3ffc594f0825dd2c94f74eeaece0e6 Mon Sep 17 00:00:00 2001 From: Blackchai Date: Fri, 3 Apr 2020 14:48:31 -0600 Subject: [PATCH] [Teacher][RC 1.10] Fix for backgrounding after qr login (#687) * [Teacher][RC 1.10] Fix for backgrounding after qr login * more bug fixes --- apps/teacher/src/main/AndroidManifest.xml | 1 - .../com/instructure/teacher/activities/LoginActivity.kt | 5 ++--- .../teacher/activities/RouteValidatorActivity.kt | 8 +++++++- .../main/java/com/instructure/pandautils/utils/Const.java | 1 + 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/apps/teacher/src/main/AndroidManifest.xml b/apps/teacher/src/main/AndroidManifest.xml index 49880b0578..489764a242 100644 --- a/apps/teacher/src/main/AndroidManifest.xml +++ b/apps/teacher/src/main/AndroidManifest.xml @@ -49,7 +49,6 @@ diff --git a/apps/teacher/src/main/java/com/instructure/teacher/activities/LoginActivity.kt b/apps/teacher/src/main/java/com/instructure/teacher/activities/LoginActivity.kt index 771fe33253..da7c6caa2b 100644 --- a/apps/teacher/src/main/java/com/instructure/teacher/activities/LoginActivity.kt +++ b/apps/teacher/src/main/java/com/instructure/teacher/activities/LoginActivity.kt @@ -27,6 +27,7 @@ import com.instructure.loginapi.login.activities.BaseLoginInitActivity import com.instructure.loginapi.login.util.QRLogin import com.instructure.pandautils.services.PushNotificationRegistrationService import com.instructure.pandautils.utils.ColorKeeper +import com.instructure.pandautils.utils.Const import com.instructure.pandautils.utils.ThemePrefs import com.instructure.pandautils.utils.Utils import com.instructure.teacher.BuildConfig @@ -80,9 +81,7 @@ class LoginActivity : BaseLoginInitActivity() { return BuildConfig.IS_TESTING } - override fun userAgent(): String { - return "androidTeacher" - } + override fun userAgent(): String = Const.TEACHER_USER_AGENT /** * ONLY USE FOR UI TESTING diff --git a/apps/teacher/src/main/java/com/instructure/teacher/activities/RouteValidatorActivity.kt b/apps/teacher/src/main/java/com/instructure/teacher/activities/RouteValidatorActivity.kt index 7b2a279e3e..b139d77cd7 100644 --- a/apps/teacher/src/main/java/com/instructure/teacher/activities/RouteValidatorActivity.kt +++ b/apps/teacher/src/main/java/com/instructure/teacher/activities/RouteValidatorActivity.kt @@ -35,6 +35,7 @@ import com.instructure.loginapi.login.tasks.LogoutTask import com.instructure.loginapi.login.util.QRLogin import com.instructure.loginapi.login.util.QRLogin.verifySSOLoginUri import com.instructure.pandautils.utils.Const +import com.instructure.pandautils.utils.Utils import com.instructure.teacher.R import com.instructure.teacher.fragments.FileListFragment import com.instructure.teacher.router.RouteMatcher @@ -78,6 +79,11 @@ class RouteValidatorActivity : FragmentActivity() { return@tryWeave } + // Mobile verify requires a user agent be set, multiple attempts/failures can clear this out + if(ApiPrefs.userAgent == "") { + ApiPrefs.userAgent = Utils.generateUserAgent(this@RouteValidatorActivity, Const.TEACHER_USER_AGENT) + } + val tokenResponse = QRLogin.performSSOLogin(data, this@RouteValidatorActivity, true) // If we have a real user, this is a QR code from a masquerading web user @@ -94,7 +100,7 @@ class RouteValidatorActivity : FragmentActivity() { intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_NEW_TASK) startActivity(intent) - finish() + finishAffinity() return@tryWeave } catch (e: Throwable) { // If the user wasn't already signed in, let's clear the prefs in case it was a partial success diff --git a/libs/pandautils/src/main/java/com/instructure/pandautils/utils/Const.java b/libs/pandautils/src/main/java/com/instructure/pandautils/utils/Const.java index 046db0d7d9..b4f3b0edc4 100644 --- a/libs/pandautils/src/main/java/com/instructure/pandautils/utils/Const.java +++ b/libs/pandautils/src/main/java/com/instructure/pandautils/utils/Const.java @@ -325,4 +325,5 @@ public class Const { // Intent String for QR Code Masquerading public static final String QR_CODE_MASQUERADE_ID = "qrCodeMasqueradeId"; + public static final String TEACHER_USER_AGENT = "androidTeacher"; }