public static boolean isFileNameValid(String fileName) {

    // Trim the trailing slash if there is one.
    if (fileName.endsWith("/")) fileName = fileName.substring(0, fileName.lastIndexOf('/') - 1);
    // Trim the leading slashes if there is any.
    if (fileName.contains("/")) fileName = fileName.substring(fileName.lastIndexOf('/') + 1);

    return !TextUtils.isEmpty(fileName)
        && !(fileName.contains(ASTERISK)
            || fileName.contains(BACKWARD_SLASH)
            || fileName.contains(COLON)
            || fileName.contains(FOREWARD_SLASH)
            || fileName.contains(GREATER_THAN)
            || fileName.contains(LESS_THAN)
            || fileName.contains(QUESTION_MARK)
            || fileName.contains(QUOTE));
  }
@Test
  public void testIsFileNameValid() {
    assertTrue(Operations.isFileNameValid("file.txt"));
    assertTrue(Operations.isFileNameValid("/storage/emulated/0/Documents/file.txt"));
    assertTrue(Operations.isFileNameValid("/system/etc/file.txt"));
    assertTrue(Operations.isFileNameValid("smb://127.0.0.1/trancelove/file.txt"));
    assertTrue(Operations.isFileNameValid("ssh://127.0.0.1:54225/home/trancelove/file.txt"));
    assertTrue(Operations.isFileNameValid("ftp://127.0.0.1:3721/pub/Incoming/file.txt"));
    assertTrue(
        Operations.isFileNameValid(
            "content://com.amaze.filemanager/storage_root/storage/emulated/0/Documents/file.txt"));
  }