ResourceUsageAnalyzer { @VisibleForTesting boolean isResourceClass(@NonNull String name) { if (mResourceObfuscation.containsKey(name)) { return true; } assert name.endsWith(DOT_CLASS) : name; int index = name.lastIndexOf('/'); if (index != -1 && name.startsWith("R$", index + 1)) { String typeName = name.substring(index + 3, name.length() - DOT_CLASS.length()); return ResourceType.getEnum(typeName) != null; } return false; } ResourceUsageAnalyzer(
            @NonNull File rDir,
            @NonNull File classes,
            @NonNull File manifest,
            @Nullable File mapping,
            @NonNull File resources,
            @Nullable File reportFile); void dispose(); void analyze(); boolean isDryRun(); void setDryRun(boolean dryRun); boolean isVerbose(); void setVerbose(boolean verbose); boolean isDebug(); void setDebug(boolean verbose); void rewriteResourceZip(@NonNull File source, @NonNull File dest); void removeUnused(@Nullable File destination); int getUnusedResourceCount(); static final boolean REPLACE_DELETED_WITH_EMPTY; @SuppressWarnings("SpellCheckingInspection") // arsc
    static final boolean TWO_PASS_AAPT; static final byte[] TINY_PNG; static final long TINY_PNG_CRC; static final byte[] TINY_9PNG; static final long TINY_9PNG_CRC; static final byte[] TINY_XML; static final long TINY_XML_CRC; }
@Test public void testIsResourceClass() throws Exception { File dummy = new File("dummy"); File mappingFile = createMappingFile(Files.createTempDir()); ResourceUsageAnalyzer analyzer = new ResourceUsageAnalyzer(dummy, dummy, dummy, mappingFile, dummy, null); analyzer.getModel().addDeclaredResource(ResourceType.LAYOUT, "structure_status_view", null, true); analyzer.recordMapping(mappingFile); assertTrue(analyzer.isResourceClass("android/support/v7/appcompat/R$attr.class")); assertTrue(analyzer.isResourceClass("android/support/v7/appcompat/R$attr.class")); assertTrue(analyzer.isResourceClass("android/support/v7/appcompat/R$bool.class")); assertFalse(analyzer.isResourceClass("android/support/v7/appcompat/R.class")); assertFalse(analyzer.isResourceClass("com/google/samples/apps/iosched/ui/BrowseSessionsActivity.class")); assertFalse(analyzer.isResourceClass("android/support/annotation/FloatRange.class")); assertTrue(analyzer.isResourceClass("com/foo/bar/t.class")); assertTrue(analyzer.isResourceClass("com/foo/bar/t")); Resource resource = analyzer.getResourceFromCode("com/foo/bar/t", "f"); assertNotNull(resource); assertEquals("structure_status_view", resource.name); assertEquals(ResourceType.LAYOUT, resource.type); assertNull(analyzer.getResourceFromCode("android/support/annotation/FloatRange", "fromInclusive")); }