public static Uri getUriForBaseFile(
      @NonNull Context context, @NonNull HybridFileParcelable baseFile) {
    switch (baseFile.getMode()) {
      case FILE:
      case ROOT:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
          return FileProvider.getUriForFile(
              context, context.getPackageName(), new File(baseFile.getPath()));
        } else {
          return Uri.fromFile(new File(baseFile.getPath()));
        }
      case OTG:
        return OTGUtil.getDocumentFile(baseFile.getPath(), context, true).getUri();
      case SMB:
      case DROPBOX:
      case GDRIVE:
      case ONEDRIVE:
      case BOX:
        Toast.makeText(context, context.getString(R.string.smb_launch_error), Toast.LENGTH_LONG)
            .show();
        return null;
      default:
        return null;
    }
  }
@Test
  public void testGetUriForBaseFile() {
    HybridFileParcelable file = new HybridFileParcelable("/storage/emulated/0/test.txt");
    for (OpenMode m : new OpenMode[] {OpenMode.FILE, OpenMode.ROOT}) {
      file.setMode(m);
      Uri uri = Utils.getUriForBaseFile(ApplicationProvider.getApplicationContext(), file);
      if (Build.VERSION.SDK_INT < N) {
        assertEquals("file:///storage/emulated/0/test.txt", uri.toString());
      } else {
        assertEquals(
            "content://"
                + ApplicationProvider.getApplicationContext().getPackageName()
                + "/storage_root/storage/emulated/0/test.txt",
            uri.toString());
      }
    }

    for (OpenMode m :
        new OpenMode[] {
          OpenMode.DROPBOX, OpenMode.GDRIVE, OpenMode.ONEDRIVE, OpenMode.SMB, OpenMode.BOX
        }) {
      file = new HybridFileParcelable("/foo/bar/test.txt");
      file.setMode(m);
      assertNull(Utils.getUriForBaseFile(ApplicationProvider.getApplicationContext(), file));
      assertEquals(
          ApplicationProvider.getApplicationContext().getString(R.string.smb_launch_error),
          ShadowToast.getTextOfLatestToast());
    }

    file.setMode(OpenMode.CUSTOM);
    assertNull(Utils.getUriForBaseFile(ApplicationProvider.getApplicationContext(), file));
  }