Fix Security Error

Fix JSON Error on register
This commit is contained in:
Schoumi 2024-05-29 01:31:49 +02:00
parent 9e82b24cf5
commit bc0886a4ee
2 changed files with 29 additions and 8 deletions

View File

@ -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)
}

View File

@ -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
}