From 6db04b369ec4a4d59315ba0207ecc53d8e8852cc Mon Sep 17 00:00:00 2001 From: Alex Klyubin Date: Mon, 20 Apr 2015 10:11:57 -0700 Subject: [PATCH] Make MediaPlayer fail fast on UnknownServiceException. This makes MediaPlayer's network streaming code fail fast when an UnknownServiceException is encountered. This currently occurs when the application declares that it does not perform cleartext network traffic and tries to load media over cleartext HTTP. Without this CL, MediaPlayer blocks for 30 seconds because it treats this error as recoverable and goes into a ten retry loop with a three second delay before each retry. The result at MediaPlayer client level is MediaPlayer.MEDIA_ERROR_UNKNOWN error. This error code is used for non-recoverable situations such as when an invalid redirect is encountered or the destination is unreachable. Bug: 20026006 Change-Id: I10f0dadb7740902f8c7c73d0df96cfff31f08ada --- media/java/android/media/MediaHTTPConnection.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/media/java/android/media/MediaHTTPConnection.java b/media/java/android/media/MediaHTTPConnection.java index b2886bb473b1b..541d871bd657f 100644 --- a/media/java/android/media/MediaHTTPConnection.java +++ b/media/java/android/media/MediaHTTPConnection.java @@ -32,6 +32,7 @@ import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.NoRouteToHostException; import java.net.ProtocolException; +import java.net.UnknownServiceException; import java.util.HashMap; import java.util.Map; @@ -337,7 +338,10 @@ public class MediaHTTPConnection extends IMediaHTTPConnection.Stub { } catch (NoRouteToHostException e) { Log.w(TAG, "readAt " + offset + " / " + size + " => " + e); return MEDIA_ERROR_UNSUPPORTED; - } catch (IOException e) { + } catch (UnknownServiceException e) { + Log.w(TAG, "readAt " + offset + " / " + size + " => " + e); + return MEDIA_ERROR_UNSUPPORTED; + }catch (IOException e) { if (VERBOSE) { Log.d(TAG, "readAt " + offset + " / " + size + " => -1"); }