From bc0886a4ee2054be845385b4352085ade6e9829a Mon Sep 17 00:00:00 2001 From: Schoumi Date: Wed, 29 May 2024 01:31:49 +0200 Subject: [PATCH] Fix Security Error Fix JSON Error on register --- .../peertubelive/activity/StreamActivity.kt | 7 ----- .../peertubelive/manager/OAuthManager.kt | 30 ++++++++++++++++++- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/fr/mobdev/peertubelive/activity/StreamActivity.kt b/app/src/main/java/fr/mobdev/peertubelive/activity/StreamActivity.kt index fdeec7e..0b6418f 100644 --- a/app/src/main/java/fr/mobdev/peertubelive/activity/StreamActivity.kt +++ b/app/src/main/java/fr/mobdev/peertubelive/activity/StreamActivity.kt @@ -148,17 +148,10 @@ class StreamActivity : AppCompatActivity() { if (intent?.action.equals(Intent.ACTION_SCREEN_OFF)){ setResult(LOCK) finish() - } else if (intent?.action.equals(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)){ - val reason = intent?.getStringExtra("reason") - if(reason.equals("homekey")){ - setResult(BACKGROUND) - finish() - } } } } val filter = IntentFilter(Intent.ACTION_SCREEN_OFF) - filter.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS) registerReceiver(lockReceiver, filter) } diff --git a/app/src/main/java/fr/mobdev/peertubelive/manager/OAuthManager.kt b/app/src/main/java/fr/mobdev/peertubelive/manager/OAuthManager.kt index 86e1301..9a41bb3 100644 --- a/app/src/main/java/fr/mobdev/peertubelive/manager/OAuthManager.kt +++ b/app/src/main/java/fr/mobdev/peertubelive/manager/OAuthManager.kt @@ -21,6 +21,7 @@ import android.os.Bundle import fr.mobdev.peertubelive.BuildConfig import fr.mobdev.peertubelive.R import fr.mobdev.peertubelive.objects.OAuthData +import org.json.JSONException import org.json.JSONObject import java.io.BufferedReader import java.io.InputStream @@ -177,6 +178,10 @@ class OAuthManager { return } catch (e : Exception) { e.printStackTrace() + if (connection.errorStream == null) { + message.listener?.onError(InstanceManager.INTERNAL_ERROR, message.context.getString(R.string.unknwon_error)) + return + } inputStream = connection.errorStream inError = true } @@ -184,7 +189,14 @@ class OAuthManager { val response = readInputStream(inputStream) if(!inError) { if(response.isNotEmpty()) { - val rootObj = JSONObject(response) + val rootObj: JSONObject + try { + rootObj = JSONObject(response) + } catch (e: JSONException) { + message.listener?.onError(InstanceManager.INTERNAL_ERROR, message.context.getString(R.string.json_error)) + return + } + val clientId = rootObj.getString("client_id") val clientSecret = rootObj.getString("client_secret") @@ -252,6 +264,10 @@ class OAuthManager { return } catch (e : Exception) { e.printStackTrace() + if (connection.errorStream == null) { + message.listener?.onError(InstanceManager.INTERNAL_ERROR, message.context.getString(R.string.unknwon_error)) + return + } inputStream = connection.errorStream inError = true } @@ -324,6 +340,10 @@ class OAuthManager { return } catch (e : Exception) { e.printStackTrace() + if (connection.errorStream == null) { + message.listener?.onError(InstanceManager.INTERNAL_ERROR, message.context.getString(R.string.unknwon_error)) + return + } inputStream = connection.errorStream inError = true } @@ -392,6 +412,10 @@ class OAuthManager { return } catch (e : Exception) { e.printStackTrace() + if (connection.errorStream == null) { + message.listener?.onError(InstanceManager.INTERNAL_ERROR, message.context.getString(R.string.unknwon_error)) + return + } inError = true inputStream = connection.errorStream } @@ -454,6 +478,10 @@ class OAuthManager { return } catch (e : Exception) { e.printStackTrace() + if (connection.errorStream == null) { + message.listener?.onError(InstanceManager.INTERNAL_ERROR, message.context.getString(R.string.unknwon_error)) + return + } inputStream = connection.errorStream inError = true }