TIF: Throw a more appropriate runtime exception when building TvInputInfo
Bug: 28775591
Change-Id: I934c8d7fed3dda356cdc3bafe51a79f585918ed0
diff --git a/api/current.txt b/api/current.txt
index c13c435..81d0f57 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -22881,7 +22881,7 @@
public static final class TvInputInfo.Builder {
ctor public TvInputInfo.Builder(android.content.Context, android.content.ComponentName);
- method public android.media.tv.TvInputInfo build() throws java.io.IOException, org.xmlpull.v1.XmlPullParserException;
+ method public android.media.tv.TvInputInfo build();
method public android.media.tv.TvInputInfo.Builder setCanRecord(boolean);
method public android.media.tv.TvInputInfo.Builder setExtras(android.os.Bundle);
method public android.media.tv.TvInputInfo.Builder setTunerCount(int);
diff --git a/api/system-current.txt b/api/system-current.txt
index 61cd00a..c1174ac 100644
--- a/api/system-current.txt
+++ b/api/system-current.txt
@@ -24583,7 +24583,7 @@
public static final class TvInputInfo.Builder {
ctor public TvInputInfo.Builder(android.content.Context, android.content.ComponentName);
- method public android.media.tv.TvInputInfo build() throws java.io.IOException, org.xmlpull.v1.XmlPullParserException;
+ method public android.media.tv.TvInputInfo build();
method public android.media.tv.TvInputInfo.Builder setCanRecord(boolean);
method public android.media.tv.TvInputInfo.Builder setExtras(android.os.Bundle);
method public android.media.tv.TvInputInfo.Builder setHdmiDeviceInfo(android.hardware.hdmi.HdmiDeviceInfo);
diff --git a/api/test-current.txt b/api/test-current.txt
index 9165cb0..d572c8d 100644
--- a/api/test-current.txt
+++ b/api/test-current.txt
@@ -22949,7 +22949,7 @@
public static final class TvInputInfo.Builder {
ctor public TvInputInfo.Builder(android.content.Context, android.content.ComponentName);
- method public android.media.tv.TvInputInfo build() throws java.io.IOException, org.xmlpull.v1.XmlPullParserException;
+ method public android.media.tv.TvInputInfo build();
method public android.media.tv.TvInputInfo.Builder setCanRecord(boolean);
method public android.media.tv.TvInputInfo.Builder setExtras(android.os.Bundle);
method public android.media.tv.TvInputInfo.Builder setTunerCount(int);
diff --git a/media/java/android/media/tv/TvInputInfo.java b/media/java/android/media/tv/TvInputInfo.java
index a33b219..3b74ee7 100644
--- a/media/java/android/media/tv/TvInputInfo.java
+++ b/media/java/android/media/tv/TvInputInfo.java
@@ -48,6 +48,7 @@
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
+import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.lang.annotation.Retention;
@@ -875,10 +876,8 @@
* for the {@link TvInputService} this TV input implements.
*
* @return TvInputInfo containing information about this TV input.
- * @throws IOException If there was an I/O error.
- * @throws XmlPullParserException If there was an XML parsing error.
*/
- public TvInputInfo build() throws IOException, XmlPullParserException {
+ public TvInputInfo build() {
ComponentName componentName = new ComponentName(mResolveInfo.serviceInfo.packageName,
mResolveInfo.serviceInfo.name);
String id;
@@ -925,15 +924,14 @@
+ tvInputHardwareInfo.getDeviceId();
}
- private void parseServiceMetadata(int inputType)
- throws XmlPullParserException, IOException {
+ private void parseServiceMetadata(int inputType) {
ServiceInfo si = mResolveInfo.serviceInfo;
PackageManager pm = mContext.getPackageManager();
try (XmlResourceParser parser =
si.loadXmlMetaData(pm, TvInputService.SERVICE_META_DATA)) {
if (parser == null) {
- throw new XmlPullParserException("No " + TvInputService.SERVICE_META_DATA
- + " meta-data for " + si.name);
+ throw new IllegalStateException("No " + TvInputService.SERVICE_META_DATA
+ + " meta-data found for " + si.name);
}
Resources res = pm.getResourcesForApplication(si.applicationInfo);
@@ -946,26 +944,19 @@
String nodeName = parser.getName();
if (!XML_START_TAG_NAME.equals(nodeName)) {
- throw new XmlPullParserException(
- "Meta-data does not start with tv-input-service tag in " + si.name);
+ throw new IllegalStateException("Meta-data does not start with "
+ + XML_START_TAG_NAME + " tag for " + si.name);
}
TypedArray sa = res.obtainAttributes(attrs,
com.android.internal.R.styleable.TvInputService);
mSetupActivity = sa.getString(
com.android.internal.R.styleable.TvInputService_setupActivity);
- if (DEBUG) {
- Log.d(TAG, "Setup activity loaded. [" + mSetupActivity + "] for " + si.name);
- }
if (inputType == TYPE_TUNER && TextUtils.isEmpty(mSetupActivity)) {
- throw new XmlPullParserException("Setup activity not found in " + si.name);
+ throw new IllegalStateException("Setup activity not found for " + si.name);
}
mSettingsActivity = sa.getString(
com.android.internal.R.styleable.TvInputService_settingsActivity);
- if (DEBUG) {
- Log.d(TAG, "Settings activity loaded. [" + mSettingsActivity + "] for "
- + si.name);
- }
if (mCanRecord == null) {
mCanRecord = sa.getBoolean(
com.android.internal.R.styleable.TvInputService_canRecord, false);
@@ -975,8 +966,10 @@
com.android.internal.R.styleable.TvInputService_tunerCount, 1);
}
sa.recycle();
+ } catch (IOException | XmlPullParserException e) {
+ throw new IllegalStateException("Failed reading meta-data for " + si.packageName, e);
} catch (NameNotFoundException e) {
- throw new XmlPullParserException("Unable to create context for: " + si.packageName);
+ throw new IllegalStateException("No resources found for " + si.packageName, e);
}
}
}
diff --git a/services/core/java/com/android/server/tv/TvInputManagerService.java b/services/core/java/com/android/server/tv/TvInputManagerService.java
index 2946bb5..b488297 100644
--- a/services/core/java/com/android/server/tv/TvInputManagerService.java
+++ b/services/core/java/com/android/server/tv/TvInputManagerService.java
@@ -331,7 +331,7 @@
try {
TvInputInfo info = new TvInputInfo.Builder(mContext, ri).build();
inputList.add(info);
- } catch (XmlPullParserException | IOException e) {
+ } catch (Exception e) {
Slog.e(TAG, "failed to load TV input " + si.name, e);
continue;
}