docs: private SQLiteConnection waitForConnection(String sql, int connectionFlags,
              CancellationSignal cancellationSignal) {
          final boolean wantPrimaryConnection =
                  (connectionFlags & CONNECTION_FLAG_PRIMARY_CONNECTION_AFFINITY) != 0;
  
          final ConnectionWaiter waiter;
          final int nonce;
          synchronized (mLock) {
              throwIfClosedLocked();
  
              // Abort if canceled.
              if (cancellationSignal != null) {
                  cancellationSignal.throwIfCanceled();
              }
  
              // Try to acquire a connection.
              SQLiteConnection connection = null;
              if (!wantPrimaryConnection) {
                  connection = tryAcquireNonPrimaryConnectionLocked(
                          sql, connectionFlags); // might throw
              }
              if (connection == null) {
                  connection = tryAcquirePrimaryConnectionLocked(connectionFlags); // might throw
              }
              if (connection != null) {
                  return connection;
              }
  
              // No connections available.  Enqueue a waiter in priority order.
              final int priority = getPriority(connectionFlags);
              final long startTime = SystemClock.uptimeMillis();
              waiter = obtainConnectionWaiterLocked(Thread.currentThread(), startTime,
                      priority, wantPrimaryConnection, sql, connectionFlags);
              ConnectionWaiter predecessor = null;
              ConnectionWaiter successor = mConnectionWaiterQueue;
              while (successor != null) {
                  if (priority > successor.mPriority) {
                      waiter.mNext = successor;
                      break;
                  }
                  predecessor = successor;
                  successor = successor.mNext;
              }
              if (predecessor != null) {
                  predecessor.mNext = waiter;
              } else {
                  mConnectionWaiterQueue = waiter;
              }
  
              nonce = waiter.mNonce;
          }
  
          // Set up the cancellation listener.
          if (cancellationSignal != null) {
              cancellationSignal.setOnCancelListener(new CancellationSignal.OnCancelListener() {
                  @Override
                  public void onCancel() {
                      synchronized (mLock) {
                          if (waiter.mNonce == nonce) {
                              cancelConnectionWaiterLocked(waiter);
                          }
                      }
                  }
              });
          }
          try {
              // Park the thread until a connection is assigned or the pool is closed.
              // Rethrow an exception from the wait, if we got one.
              long busyTimeoutMillis = CONNECTION_POOL_BUSY_MILLIS;
              long nextBusyTimeoutTime = waiter.mStartTime + busyTimeoutMillis;
              for (;;) {
                  // Detect and recover from connection leaks.
                  if (mConnectionLeaked.compareAndSet(true, false)) {
                      synchronized (mLock) {
                          wakeConnectionWaitersLocked();
                      }
                  }
  
                  // Wait to be unparked (may already have happened), a timeout, or interruption.
                  LockSupport.parkNanos(this, busyTimeoutMillis * 1000000L);
  
                  // Clear the interrupted flag, just in case.
                  Thread.interrupted();
  
                  // Check whether we are done waiting yet.
                  synchronized (mLock) {
                      throwIfClosedLocked();
  
                      final SQLiteConnection connection = waiter.mAssignedConnection;
                      final RuntimeException ex = waiter.mException;
                      if (connection != null || ex != null) {
                          recycleConnectionWaiterLocked(waiter);
                          if (connection != null) {
                              return connection;
                          }
                          throw ex; // rethrow!
                      }
  
                      final long now = SystemClock.uptimeMillis();
                      if (now < nextBusyTimeoutTime) {
                          busyTimeoutMillis = now - nextBusyTimeoutTime;
                      } else {
                          logConnectionPoolBusyLocked(now - waiter.mStartTime, connectionFlags);
                          busyTimeoutMillis = CONNECTION_POOL_BUSY_MILLIS;
                          nextBusyTimeoutTime = now + busyTimeoutMillis;
                      }
                  }
              }
          } finally {
              // Remove the cancellation listener.
              if (cancellationSignal != null) {
                  cancellationSignal.setOnCancelListener(null);
              }
          }
      }