@Test public void shouldParseRegularPermissions() throws Exception { URL testDexResourceUrl = this.getClass().getResource("/app-debug.apk"); String testDexFile = testDexResourceUrl.getFile(); File file = new File(testDexFile); ApplicationInfo applicationInfo = ApplicationInfoFactory.parseFromFile(file); assertThat(applicationInfo.getPermissions(), containsInAnyOrder( samePermissionAs("android.permission.RECORD_AUDIO"), samePermissionAs("android.permission.GET_ACCOUNTS", 1, 22), samePermissionAs("com.shazam.forktest.A_TEST_PERMISSION", 23, 24) )); }
@Nonnull public static ApplicationInfo parseFromFile(File apkTestFile) { InputStream is = null; try { ZipFile zip = new ZipFile(apkTestFile); ZipEntry entry = zip.getEntry("AndroidManifest.xml"); is = zip.getInputStream(entry); AXMLParser parser = new AXMLParser(is); int eventType = parser.getType(); List<Permission> permissions = new ArrayList<>(); while (eventType != AXMLParser.END_DOCUMENT) { if (eventType == AXMLParser.START_TAG) { String parserName = parser.getName(); boolean isPermission = parserName.startsWith("uses-permission"); if (isPermission) { parsePermission(parser, permissions); } } eventType = parser.next(); } return new ApplicationInfo(permissions); } catch (IOException e) { throw new RuntimeException("Unable to parse test app AndroidManifest.xml.", e); } finally { IOUtils.closeQuietly(is); } }
ApplicationInfoFactory { @Nonnull public static ApplicationInfo parseFromFile(File apkTestFile) { InputStream is = null; try { ZipFile zip = new ZipFile(apkTestFile); ZipEntry entry = zip.getEntry("AndroidManifest.xml"); is = zip.getInputStream(entry); AXMLParser parser = new AXMLParser(is); int eventType = parser.getType(); List<Permission> permissions = new ArrayList<>(); while (eventType != AXMLParser.END_DOCUMENT) { if (eventType == AXMLParser.START_TAG) { String parserName = parser.getName(); boolean isPermission = parserName.startsWith("uses-permission"); if (isPermission) { parsePermission(parser, permissions); } } eventType = parser.next(); } return new ApplicationInfo(permissions); } catch (IOException e) { throw new RuntimeException("Unable to parse test app AndroidManifest.xml.", e); } finally { IOUtils.closeQuietly(is); } } }
ApplicationInfoFactory { @Nonnull public static ApplicationInfo parseFromFile(File apkTestFile) { InputStream is = null; try { ZipFile zip = new ZipFile(apkTestFile); ZipEntry entry = zip.getEntry("AndroidManifest.xml"); is = zip.getInputStream(entry); AXMLParser parser = new AXMLParser(is); int eventType = parser.getType(); List<Permission> permissions = new ArrayList<>(); while (eventType != AXMLParser.END_DOCUMENT) { if (eventType == AXMLParser.START_TAG) { String parserName = parser.getName(); boolean isPermission = parserName.startsWith("uses-permission"); if (isPermission) { parsePermission(parser, permissions); } } eventType = parser.next(); } return new ApplicationInfo(permissions); } catch (IOException e) { throw new RuntimeException("Unable to parse test app AndroidManifest.xml.", e); } finally { IOUtils.closeQuietly(is); } } private  ApplicationInfoFactory(); }
ApplicationInfoFactory { @Nonnull public static ApplicationInfo parseFromFile(File apkTestFile) { InputStream is = null; try { ZipFile zip = new ZipFile(apkTestFile); ZipEntry entry = zip.getEntry("AndroidManifest.xml"); is = zip.getInputStream(entry); AXMLParser parser = new AXMLParser(is); int eventType = parser.getType(); List<Permission> permissions = new ArrayList<>(); while (eventType != AXMLParser.END_DOCUMENT) { if (eventType == AXMLParser.START_TAG) { String parserName = parser.getName(); boolean isPermission = parserName.startsWith("uses-permission"); if (isPermission) { parsePermission(parser, permissions); } } eventType = parser.next(); } return new ApplicationInfo(permissions); } catch (IOException e) { throw new RuntimeException("Unable to parse test app AndroidManifest.xml.", e); } finally { IOUtils.closeQuietly(is); } } private  ApplicationInfoFactory(); @Nonnull static ApplicationInfo parseFromFile(File apkTestFile); }
ApplicationInfoFactory { @Nonnull public static ApplicationInfo parseFromFile(File apkTestFile) { InputStream is = null; try { ZipFile zip = new ZipFile(apkTestFile); ZipEntry entry = zip.getEntry("AndroidManifest.xml"); is = zip.getInputStream(entry); AXMLParser parser = new AXMLParser(is); int eventType = parser.getType(); List<Permission> permissions = new ArrayList<>(); while (eventType != AXMLParser.END_DOCUMENT) { if (eventType == AXMLParser.START_TAG) { String parserName = parser.getName(); boolean isPermission = parserName.startsWith("uses-permission"); if (isPermission) { parsePermission(parser, permissions); } } eventType = parser.next(); } return new ApplicationInfo(permissions); } catch (IOException e) { throw new RuntimeException("Unable to parse test app AndroidManifest.xml.", e); } finally { IOUtils.closeQuietly(is); } } private  ApplicationInfoFactory(); @Nonnull static ApplicationInfo parseFromFile(File apkTestFile);  }