/** Like {@link LintUtils#isBitmapFile(File)} but (a) operates on Strings instead * of files and (b) also considers XML drawables as images */ public static boolean isDrawableFile(String name) { // endsWith(name, DOT_PNG) is also true for endsWith(name, DOT_9PNG) return endsWith(name, DOT_PNG)|| endsWith(name, DOT_JPG) || endsWith(name, DOT_GIF) || endsWith(name, DOT_XML) || endsWith(name, DOT_JPEG) || endsWith(name, DOT_WEBP); }
/** Like {@link LintUtils#isBitmapFile(File)} but (a) operates on Strings instead * of files and (b) also considers XML drawables as images */ private static boolean isDrawableFile(String name) { // endsWith(name, DOT_PNG) is also true for endsWith(name, DOT_9PNG) return endsWith(name, DOT_PNG)|| endsWith(name, DOT_JPG) || endsWith(name, DOT_GIF) || endsWith(name, DOT_XML) || endsWith(name, DOT_JPEG) || endsWith(name, DOT_WEBP); }
/** * Returns true if the given file represents a bitmap drawable file * * @param file the file to be checked * @return true if the given file is an xml file */ public static boolean isBitmapFile(@NonNull File file) { String path = file.getPath(); // endsWith(name, DOT_PNG) is also true for endsWith(name, DOT_9PNG) return endsWith(path, DOT_PNG) || endsWith(path, DOT_JPG) || endsWith(path, DOT_GIF) || endsWith(path, DOT_JPEG) || endsWith(path, DOT_WEBP); }
private String getDrawableResource(File drawableFile) { String resource = drawableFile.getName(); if (endsWith(resource, DOT_XML)) { resource = resource.substring(0, resource.length() - DOT_XML.length()); } return DRAWABLE_RESOURCE_PREFIX + resource; }
private static String getDrawableResource(File drawableFile) { String resource = drawableFile.getName(); if (endsWith(resource, DOT_XML)) { resource = resource.substring(0, resource.length() - DOT_XML.length()); } return DRAWABLE_PREFIX + resource; }
private static String getDrawableResource(File drawableFile) { String resource = drawableFile.getName(); if (endsWith(resource, DOT_XML)) { resource = resource.substring(0, resource.length() - DOT_XML.length()); } return DRAWABLE_PREFIX + resource; }
private static boolean isPrivateKeyFile(File file) { if (!file.isFile() || (!LintUtils.endsWith(file.getPath(), "pem") && //NON-NLS-1$ !LintUtils.endsWith(file.getPath(), "key"))) { //NON-NLS-1$ return false; } try { String firstLine = Files.readFirstLine(file, Charsets.US_ASCII); return firstLine != null && firstLine.startsWith("---") && //NON-NLS-1$ firstLine.contains("PRIVATE KEY"); //NON-NLS-1$ } catch (IOException ex) { // Don't care } return false; }
private static boolean isPrivateKeyFile(File file) { if (!file.isFile() || (!LintUtils.endsWith(file.getPath(), "pem") && !LintUtils.endsWith(file.getPath(), "key"))) { return false; } try { String firstLine = Files.readFirstLine(file, Charsets.US_ASCII); return firstLine != null && firstLine.startsWith("---") && firstLine.contains("PRIVATE KEY"); } catch (IOException ex) { // Don't care } return false; }
@Override public void beforeCheckFile(Context context) { File file = context.file; String fileName = file.getName(); if (LintUtils.endsWith(fileName, DOT_XML)) { String parentName = file.getParentFile().getName(); int dash = parentName.indexOf('-'); String typeName = parentName.substring(0, dash == -1 ? parentName.length() : dash); ResourceType type = ResourceType.getEnum(typeName); if (type != null && LintUtils.isFileBasedResourceType(type)) { String baseName = fileName.substring(0, fileName.length() - DOT_XML.length()); String resource = R_PREFIX + typeName + '.' + baseName; mDeclarations.add(resource); mDeclarationToFile.put(resource, file); } } }
@Override public void beforeCheckFile(Context context) { if (endsWith(context.file.getName(), DOT_XML)) { // Drawable XML files should not be considered for overdraw, except for <bitmap>'s. // The bitmap elements are handled in the scanBitmap() method; it will clear // out anything added by this method. File parent = context.file.getParentFile(); ResourceFolderType type = ResourceFolderType.getFolderType(parent.getName()); if (type == ResourceFolderType.DRAWABLE) { if (mValidDrawables == null) { mValidDrawables = new ArrayList<String>(); } String resource = getDrawableResource(context.file); mValidDrawables.add(resource); } } }
@VisibleForTesting @NonNull static String getCacheFileName(@NonNull String xmlFileName, @Nullable String platformVersion) { if (LintUtils.endsWith(xmlFileName, DOT_XML)) { xmlFileName = xmlFileName.substring(0, xmlFileName.length() - DOT_XML.length()); } StringBuilder sb = new StringBuilder(100); sb.append(xmlFileName); // Incorporate version number in the filename to avoid upgrade filename // conflicts on Windows (such as issue #26663) sb.append('-').append(BINARY_FORMAT_VERSION); if (platformVersion != null) { sb.append('-').append(platformVersion); } sb.append(".bin"); return sb.toString(); }
@VisibleForTesting @NonNull static String getCacheFileName(@NonNull String xmlFileName, @Nullable String platformVersion) { if (LintUtils.endsWith(xmlFileName, DOT_XML)) { xmlFileName = xmlFileName.substring(0, xmlFileName.length() - DOT_XML.length()); } StringBuilder sb = new StringBuilder(100); sb.append(xmlFileName); // Incorporate version number in the filename to avoid upgrade filename // conflicts on Windows (such as issue #26663) sb.append('-').append(BINARY_FORMAT_VERSION); if (platformVersion != null) { sb.append('-').append(platformVersion); } sb.append(".bin"); return sb.toString(); }
@VisibleForTesting @NonNull static String getCacheFileName(@NonNull String xmlFileName, @Nullable String platformVersion) { if (LintUtils.endsWith(xmlFileName, DOT_XML)) { xmlFileName = xmlFileName.substring(0, xmlFileName.length() - DOT_XML.length()); } StringBuilder sb = new StringBuilder(100); sb.append(xmlFileName); // Incorporate version number in the filename to avoid upgrade filename // conflicts on Windows (such as issue #26663) sb.append('-').append(BINARY_FORMAT_VERSION); if (platformVersion != null) { sb.append('-').append(platformVersion); } sb.append(".bin"); //$NON-NLS-1$ return sb.toString(); }
@Override public void beforeCheckFile(@NonNull Context context) { if (endsWith(context.file.getName(), DOT_XML)) { // Drawable XML files should not be considered for overdraw, except for <bitmap>'s. // The bitmap elements are handled in the scanBitmap() method; it will clear // out anything added by this method. File parent = context.file.getParentFile(); ResourceFolderType type = ResourceFolderType.getFolderType(parent.getName()); if (type == ResourceFolderType.DRAWABLE) { if (mValidDrawables == null) { mValidDrawables = new ArrayList<>(); } String resource = getDrawableResource(context.file); mValidDrawables.add(resource); } } }
@Override public void beforeCheckFile(@NonNull Context context) { if (endsWith(context.file.getName(), DOT_XML)) { // Drawable XML files should not be considered for overdraw, except for <bitmap>'s. // The bitmap elements are handled in the scanBitmap() method; it will clear // out anything added by this method. File parent = context.file.getParentFile(); ResourceFolderType type = ResourceFolderType.getFolderType(parent.getName()); if (type == ResourceFolderType.DRAWABLE) { if (mValidDrawables == null) { mValidDrawables = new ArrayList<String>(); } String resource = getDrawableResource(context.file); mValidDrawables.add(resource); } } }
@Override public boolean appliesTo(@NonNull Context context, @NonNull File file) { if (LintUtils.endsWith(file.getName(), DOT_JAVA)) { return mFormatStrings != null; } return super.appliesTo(context, file); }
@Override public boolean appliesTo(@NonNull Context context, @NonNull File file) { return LintUtils.isXmlFile(file) || LintUtils.endsWith(file.getName(), DOT_JAVA); }
@Override public boolean appliesTo(@NonNull Context context, @NonNull File file) { return LintUtils.isXmlFile(file) || LintUtils.endsWith(file.getName(), DOT_JAVA); }
private static void checkFile(@NonNull Context context, @NonNull File file) { if (isNativeCode(file)) { if (LintUtils.endsWith(file.getPath(), DOT_NATIVE_LIBS)) { context.report(UNSAFE_NATIVE_CODE_LOCATION, Location.create(file), "Shared libraries should not be placed in the res or assets " + "directories. Please use the features of your development " + "environment to place shared libraries in the lib directory of " + "the compiled APK."); } else { context.report(UNSAFE_NATIVE_CODE_LOCATION, Location.create(file), "Embedding non-shared library native executables into applications " + "should be avoided when possible, as there is an increased risk that " + "the executables could be tampered with after installation. Instead, " + "native code should be placed in a shared library, and the features of " + "the development environment should be used to place the shared library " + "in the lib directory of the compiled APK."); } } } }