Fix: Crash on HTML response in EventRepository and others

- Fixed: Value <! DOCTYPE cannot be converted to JSONArray in EventRepository
- Fixed: Added HTML validation in UpdateManager and DeviceRegistry
- Fixed: Improved HTTP error handling in StreamUrlResolver
- Improved: Error messages in PlayerActivity
- Bumped version to 9.4.3
This commit is contained in:
renato97
2026-01-26 21:44:07 +01:00
parent 05625ffe50
commit bac564eb4f
8 changed files with 343 additions and 26 deletions

View File

@@ -8,8 +8,8 @@ android {
applicationId "com.streamplayer"
minSdk 21
targetSdk 33
versionCode 100000
versionName "10.0"
versionCode 100100
versionName "10.0.1"
buildConfigField "String", "DEVICE_REGISTRY_URL", '"http://194.163.191.200:4000"'
}

View File

@@ -81,6 +81,15 @@ public class DeviceRegistry {
throw new IOException("HTTP " + response.code());
}
String responseText = response.body().string();
// Validar que no sea HTML antes de parsear
if (responseText != null) {
String trimmed = responseText.trim();
if (trimmed.startsWith("<!") || trimmed.startsWith("<html")) {
throw new IOException("El servidor devolvió HTML en lugar de JSON");
}
}
JSONObject json = new JSONObject(responseText);
JSONObject deviceJson = json.optJSONObject("device");
JSONObject verificationJson = json.optJSONObject("verification");

View File

@@ -79,19 +79,51 @@ public class EventRepository {
connection.setConnectTimeout(15000);
connection.setReadTimeout(15000);
connection.setRequestMethod("GET");
try (BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), StandardCharsets.UTF_8))) {
StringBuilder builder = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
builder.append(line);
connection.setRequestProperty("Accept", "application/json");
connection.setRequestProperty("User-Agent", "StreamPlayer/1.0");
try {
int responseCode = connection.getResponseCode();
if (responseCode != HttpURLConnection.HTTP_OK) {
throw new IOException("Error HTTP " + responseCode + ": " + connection.getResponseMessage());
}
String contentType = connection.getContentType();
if (contentType != null && !contentType.contains("json")) {
throw new IOException("El servidor devolvió " + contentType + " en lugar de JSON. Verifica que la URL sea correcta.");
}
try (BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), StandardCharsets.UTF_8))) {
StringBuilder builder = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
builder.append(line);
}
String response = builder.toString();
// Validar que no sea HTML
if (response.trim().startsWith("<!") || response.trim().startsWith("<html")) {
throw new IOException("El servidor devolvió HTML en lugar de JSON. La URL del endpoint puede estar incorrecta o el servidor tiene problemas.");
}
return response;
}
return builder.toString();
} finally {
connection.disconnect();
}
}
private List<EventItem> parseEvents(String json) throws JSONException {
if (json == null || json.trim().isEmpty()) {
throw new JSONException("La respuesta está vacía");
}
// Validar que no sea HTML antes de parsear
String trimmed = json.trim();
if (trimmed.startsWith("<!") || trimmed.startsWith("<html")) {
throw new JSONException("Se recibió HTML en lugar de JSON");
}
JSONArray array = new JSONArray(json);
List<EventItem> events = new ArrayList<>();
for (int i = 0; i < array.length(); i++) {

View File

@@ -22,6 +22,7 @@ import com.google.android.exoplayer2.source.hls.HlsMediaSource;
import com.google.android.exoplayer2.ui.PlayerView;
import com.google.android.exoplayer2.util.Util;
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.HashMap;
@@ -100,8 +101,10 @@ public class PlayerActivity extends AppCompatActivity {
try {
String resolvedUrl = StreamUrlResolver.resolve(channelUrl);
runOnUiThread(() -> startPlayback(resolvedUrl));
} catch (IOException e) {
runOnUiThread(() -> showError("No se pudo conectar con el canal: " + e.getMessage()));
} catch (Exception e) {
runOnUiThread(() -> showError("Error al obtener stream: " + e.getMessage()));
runOnUiThread(() -> showError("Error inesperado: " + e.getMessage()));
}
}).start();
}

View File

@@ -61,15 +61,32 @@ public final class StreamUrlResolver {
connection.setReadTimeout(15000);
connection.setRequestProperty("User-Agent", USER_AGENT);
connection.setRequestProperty("Accept", "text/html,application/xhtml+xml");
connection.connect();
try (BufferedReader reader = new BufferedReader(
new InputStreamReader(connection.getInputStream(), StandardCharsets.UTF_8))) {
StringBuilder builder = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
builder.append(line);
try {
int responseCode = connection.getResponseCode();
if (responseCode != HttpURLConnection.HTTP_OK) {
throw new IOException("Error HTTP " + responseCode + " al cargar la página del stream");
}
String contentType = connection.getContentType();
// Validar que sea contenido web (HTML)
if (contentType != null && !contentType.contains("html") && !contentType.contains("text")) {
// A veces puede venir sin content type o application/octet-stream,
// pero si es explícitamente una imagen o algo así, abortamos.
if (contentType.startsWith("image/") || contentType.startsWith("video/") || contentType.startsWith("audio/")) {
throw new IOException("El servidor devolvió " + contentType + " en lugar de HTML");
}
}
try (BufferedReader reader = new BufferedReader(
new InputStreamReader(connection.getInputStream(), StandardCharsets.UTF_8))) {
StringBuilder builder = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
builder.append(line);
}
return builder.toString();
}
return builder.toString();
} finally {
connection.disconnect();
}

View File

@@ -172,6 +172,16 @@ public class UpdateManager {
}
private UpdateInfo parseRelease(String responseBody) throws JSONException, IOException {
if (responseBody == null || responseBody.trim().isEmpty()) {
throw new JSONException("La respuesta está vacía");
}
// Validar que no sea HTML antes de parsear
String trimmed = responseBody.trim();
if (trimmed.startsWith("<!") || trimmed.startsWith("<html")) {
throw new JSONException("Se recibió HTML en lugar de JSON");
}
JSONObject releaseJson = new JSONObject(responseBody);
String tagName = releaseJson.optString("tag_name", "");
String versionName = deriveVersionName(tagName, releaseJson.optString("name"));
@@ -244,6 +254,11 @@ public class UpdateManager {
}
String json = response.body().string();
if (!TextUtils.isEmpty(json)) {
// Validar que no sea HTML antes de parsear
String trimmed = json.trim();
if (trimmed.startsWith("<!") || trimmed.startsWith("<html")) {
continue;
}
return new JSONObject(json);
}
}

View File

@@ -6,13 +6,13 @@
"model": "SM-S928B",
"manufacturer": "Samsung",
"osVersion": "16 (API 36)",
"appVersionName": "9.4.1",
"appVersionCode": 94100,
"appVersionName": "9.4.2",
"appVersionCode": 94200,
"firstSeen": "2025-11-23T22:31:13.359Z",
"lastSeen": "2025-11-23T23:11:07.215Z",
"lastSeen": "2025-11-25T19:07:38.445Z",
"blocked": false,
"notes": "",
"installs": 7,
"installs": 22,
"ip": "181.23.253.20",
"country": "AR",
"verification": {
@@ -22,5 +22,246 @@
"createdAt": "2025-11-23T22:31:13.359Z",
"verifiedAt": "2025-11-23T22:33:11.942Z"
}
},
{
"deviceId": "c8ee9361c07a3245",
"alias": "",
"deviceName": "23113RKC6G",
"model": "23113RKC6G",
"manufacturer": "Xiaomi",
"osVersion": "15 (API 35)",
"appVersionName": "9.4.2",
"appVersionCode": 94200,
"firstSeen": "2025-11-23T23:19:29.464Z",
"lastSeen": "2025-11-23T23:21:02.377Z",
"blocked": false,
"notes": "",
"installs": 3,
"ip": "181.23.253.20",
"country": "AR",
"verification": {
"clientPart": "f7d5a364822457da",
"adminPart": "b4acb7da77b11ce9",
"status": "verified",
"createdAt": "2025-11-23T23:19:29.464Z",
"verifiedAt": "2025-11-23T23:20:49.579Z"
}
},
{
"deviceId": "c874876530da8f76",
"alias": "",
"deviceName": "2020/2021 UHD Android TV",
"model": "2020/2021 UHD Android TV",
"manufacturer": "TPV",
"osVersion": "11 (API 30)",
"appVersionName": "9.4.2",
"appVersionCode": 94200,
"firstSeen": "2025-11-24T18:53:40.668Z",
"lastSeen": "2025-11-25T01:33:56.790Z",
"blocked": false,
"notes": "",
"installs": 3,
"ip": "181.23.253.20",
"country": "AR",
"verification": {
"clientPart": "76139a364baeda9b",
"adminPart": "86601e7089416b57",
"status": "verified",
"createdAt": "2025-11-24T18:53:40.668Z",
"verifiedAt": "2025-11-24T18:54:52.788Z"
}
},
{
"deviceId": "879fe5ad6ac80e2d",
"alias": "",
"deviceName": "SM-S928B",
"model": "SM-S928B",
"manufacturer": "Samsung",
"osVersion": "16 (API 36)",
"appVersionName": "9.4.6",
"appVersionCode": 94600,
"firstSeen": "2025-11-25T19:08:38.948Z",
"lastSeen": "2025-12-23T20:41:59.972Z",
"blocked": false,
"notes": "",
"installs": 9,
"ip": "181.23.228.93",
"country": "AR",
"verification": {
"clientPart": "e512eb7d5c026e85",
"adminPart": "1891c4eec608a722",
"status": "verified",
"createdAt": "2025-11-25T19:08:38.948Z",
"verifiedAt": "2025-11-25T19:08:56.806Z"
}
},
{
"deviceId": "97a5c320c47e17ad",
"alias": "",
"deviceName": "Chromecast",
"model": "Chromecast",
"manufacturer": "Google",
"osVersion": "14 (API 34)",
"appVersionName": "9.4.6",
"appVersionCode": 94600,
"firstSeen": "2025-11-25T19:10:27.358Z",
"lastSeen": "2025-12-29T23:21:36.891Z",
"blocked": false,
"notes": "",
"installs": 26,
"ip": "181.23.228.93",
"country": "AR",
"verification": {
"clientPart": "f35ae98e27e9877c",
"adminPart": "e421a660ff38fc67",
"status": "verified",
"createdAt": "2025-11-25T19:10:27.358Z",
"verifiedAt": "2025-11-25T19:10:54.592Z"
}
},
{
"deviceId": "79a556d89cd9f783",
"alias": "",
"deviceName": "motorola edge 30",
"model": "motorola edge 30",
"manufacturer": "Motorola",
"osVersion": "13 (API 33)",
"appVersionName": "9.4.6",
"appVersionCode": 94600,
"firstSeen": "2025-11-25T19:29:17.916Z",
"lastSeen": "2025-12-14T20:26:50.664Z",
"blocked": false,
"notes": "",
"installs": 5,
"ip": "181.25.52.139",
"country": "AR",
"verification": {
"clientPart": "4aec5b0e2e1c782a",
"adminPart": "7a4bb228e3b5048c",
"status": "verified",
"createdAt": "2025-11-25T19:29:17.916Z",
"verifiedAt": "2025-11-25T19:30:11.849Z"
}
},
{
"deviceId": "309f9f56550fc16bf047d636",
"alias": "",
"deviceName": "WIN-J7S53EBK2BG",
"model": "Microsoft Windows 10.0.26100",
"manufacturer": "Microsoft",
"osVersion": "Microsoft Windows NT 10.0.26100.0",
"appVersionName": "9.4.6",
"appVersionCode": 94600,
"firstSeen": "2025-12-17T18:37:45.562Z",
"lastSeen": "2025-12-17T19:28:44.530Z",
"blocked": false,
"notes": "por boludo",
"installs": 21,
"ip": "181.25.52.139",
"country": "AR",
"verification": {
"clientPart": "60989c16f0ed61d9",
"adminPart": "c1befd758b4cd459",
"status": "verified",
"createdAt": "2025-12-17T18:37:45.562Z",
"verifiedAt": "2025-12-17T18:38:24.129Z"
},
"blockedAt": "2025-12-17T19:14:30.701Z"
},
{
"deviceId": "12c96524b10b1e15f5611b0a",
"alias": "",
"deviceName": "WIN-1F1PBAQI7PR",
"model": "Microsoft Windows 10.0.26100",
"manufacturer": "Microsoft",
"osVersion": "Microsoft Windows NT 10.0.26100.0",
"appVersionName": "9.4.6",
"appVersionCode": 94600,
"firstSeen": "2025-12-17T19:35:44.810Z",
"lastSeen": "2025-12-17T19:38:12.510Z",
"blocked": false,
"notes": "",
"installs": 2,
"ip": "181.25.52.139",
"country": "AR",
"verification": {
"clientPart": "d41b6a6bc639fe77",
"adminPart": "dab1fa74da2edab2",
"status": "verified",
"createdAt": "2025-12-17T19:35:44.810Z",
"verifiedAt": "2025-12-17T19:37:59.152Z"
}
},
{
"deviceId": "6623a19316ebbbc1570b31e2",
"alias": "",
"deviceName": "DESKTOP-TF8OENP",
"model": "Microsoft Windows 10.0.19045",
"manufacturer": "Microsoft",
"osVersion": "Microsoft Windows NT 10.0.19045.0",
"appVersionName": "9.4.6",
"appVersionCode": 94600,
"firstSeen": "2025-12-17T19:53:20.007Z",
"lastSeen": "2025-12-17T19:56:52.028Z",
"blocked": false,
"notes": "",
"installs": 4,
"ip": "190.55.131.98",
"country": "AR",
"verification": {
"clientPart": "e5ed2a5989a8e44a",
"adminPart": "21e79e6e83e662cf",
"status": "verified",
"createdAt": "2025-12-17T19:53:20.007Z",
"verifiedAt": "2025-12-17T19:53:43.017Z"
}
},
{
"deviceId": "8678935B-0B7A-41B0-B6E3-AB205073BE7F",
"alias": "",
"deviceName": "iPhone 17 Pro",
"model": "iPhone",
"manufacturer": "Apple",
"osVersion": "iOS 26.2",
"appVersionName": "9.4.2",
"appVersionCode": 94200,
"firstSeen": "2025-12-29T22:27:06.203Z",
"lastSeen": "2025-12-29T22:36:32.797Z",
"blocked": false,
"notes": "",
"installs": 3,
"ip": "181.23.228.93",
"country": "AR",
"verification": {
"clientPart": "fac4063d6b67ce57",
"adminPart": "667b10f28d37b534",
"status": "verified",
"createdAt": "2025-12-29T22:27:06.203Z",
"verifiedAt": "2025-12-29T22:30:37.120Z"
}
},
{
"deviceId": "FB4B39C0-A766-4A01-980E-763ACE9118A2",
"alias": "",
"deviceName": "iPhone 17 Pro",
"model": "iPhone",
"manufacturer": "Apple",
"osVersion": "iOS 26.2",
"appVersionName": "9.4.2",
"appVersionCode": 94200,
"firstSeen": "2025-12-29T22:40:54.202Z",
"lastSeen": "2025-12-29T23:04:30.334Z",
"blocked": false,
"notes": "",
"installs": 4,
"ip": "181.23.228.93",
"country": "AR",
"verification": {
"clientPart": "353df62e6d1faee3",
"adminPart": "648bd37e530033f7",
"status": "verified",
"createdAt": "2025-12-29T22:40:54.202Z",
"verifiedAt": "2025-12-29T22:44:27.529Z"
}
}
]

View File

@@ -1,10 +1,10 @@
{
"versionCode": 100000,
"versionName": "10.0",
"versionCode": 100100,
"versionName": "10.0.1",
"minSupportedVersionCode": 91000,
"forceUpdate": false,
"downloadUrl": "https://gitea.cbcren.online/attachments/83b72799-b731-4a48-ad04-67b75eaa78a7",
"fileName": "StreamPlayer-v10.0.apk",
"fileName": "StreamPlayer-v10.0.1.apk",
"sizeBytes": 16674,
"notes": "StreamPlayer v10.0\n\nNueva versión mayor:\n\n- Actualización a versión 10.0\n- Versión estable con todas las características previas\n- Sistema de actualizaciones automáticas activado\n- Mejoras de rendimiento y estabilidad general\n\nEsta versión marca un hito importante en el desarrollo de StreamPlayer, consolidando todas las mejoras implementadas en versiones anteriores."
}
"notes": "StreamPlayer v10.0.1\n\nCorrecciones de errores:\n- Fix: Crash on HTML response in EventRepository\n- Fix: HTML validation in UpdateManager/DeviceRegistry\n- Fix: HTTP error handling in StreamUrlResolver\n\nVersión anterior v10.0:\n- Nueva versión mayor\n- Sistema de actualizaciones automáticas activado"
}