Merge "Stop processing on IOException." into udc-dev

This commit is contained in:
Alex Buynytskyy
2023-03-03 01:26:57 +00:00
committed by Android (Google) Code Review
5 changed files with 18 additions and 0 deletions

View File

@@ -2048,6 +2048,9 @@ class ShortcutPackage extends ShortcutPackageItem {
shortcutUser.getUserId(), fromBackup);
// Don't use addShortcut(), we don't need to save the icon.
ret.mShortcuts.put(si.getId(), si);
} catch (IOException e) {
// Don't ignore IO exceptions.
throw e;
} catch (Exception e) {
// b/246540168 malformed shortcuts should be ignored
Slog.e(TAG, "Failed parsing shortcut.", e);

View File

@@ -115,6 +115,7 @@ android_test {
":StubTestApp",
":SuspendTestApp",
":MediaButtonReceiverHolderTestHelperApp",
"data/broken_shortcut.xml",
],
java_resources: [

View File

@@ -21,6 +21,8 @@
<option name="cleanup" value="true" />
<option name="push-file" key="SimpleServiceTestApp3.apk"
value="/data/local/tmp/cts/content/SimpleServiceTestApp3.apk" />
<option name="push-file" key="broken_shortcut.xml"
value="/data/local/tmp/cts/content/broken_shortcut.xml" />
</target_preparer>
<target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">

Binary file not shown.

View File

@@ -4007,6 +4007,18 @@ public class ShortcutManagerTest1 extends BaseShortcutManagerTest {
// TODO Check all other fields
}
public void testLoadCorruptedShortcuts() throws Exception {
initService();
addPackage("com.android.chrome", 0, 0);
ShortcutUser user = new ShortcutUser(mService, 0);
File corruptedShortcutPackage = new File("/data/local/tmp/cts/content/",
"broken_shortcut.xml");
assertNull(ShortcutPackage.loadFromFile(mService, user, corruptedShortcutPackage, false));
}
public void testSaveCorruptAndLoadUser() throws Exception {
// First, create some shortcuts and save.
runWithCaller(CALLING_PACKAGE_1, UserHandle.USER_SYSTEM, () -> {