override fun doInBackground()

in facebook-common/src/main/java/com/facebook/internal/WebDialog.kt [699:755]


    override fun doInBackground(vararg p0: Void): Array<String?>? {
      val params = parameters.getStringArray(ShareConstants.WEB_DIALOG_PARAM_MEDIA) ?: return null
      val results = arrayOfNulls<String>(params.size)
      exceptions = arrayOfNulls(params.size)
      val latch = CountDownLatch(params.size)
      val tasks = ConcurrentLinkedQueue<GraphRequestAsyncTask>()
      val accessToken = getCurrentAccessToken()
      try {
        for (i in params.indices) {
          if (isCancelled) {
            for (task in tasks) {
              task.cancel(true)
            }
            return null
          }
          val uri = Uri.parse(params[i])
          if (isWebUri(uri)) {
            results[i] = uri.toString()
            latch.countDown()
            continue
          }
          val callback =
              GraphRequest.Callback { response ->
                try {
                  val error = response.error
                  if (error != null) {
                    var message = error.errorMessage
                    if (message == null) {
                      message = "Error staging photo."
                    }
                    throw FacebookGraphResponseException(response, message)
                  }
                  val data =
                      response.getJSONObject() ?: throw FacebookException("Error staging photo.")
                  val stagedImageUri =
                      data.optString("uri") ?: throw FacebookException("Error staging photo.")
                  results[i] = stagedImageUri
                } catch (e: Exception) {
                  exceptions[i] = e
                }
                latch.countDown()
              }
          val task =
              ShareInternalUtility.newUploadStagingResourceWithImageRequest(
                      accessToken, uri, callback)
                  .executeAsync()
          tasks.add(task)
        }
        latch.await()
      } catch (e: Exception) {
        for (task in tasks) {
          task.cancel(true)
        }
        return null
      }
      return results
    }