// Copyright 2018 The Bazel Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//    http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.devtools.build.android.desugar.runtime;

import android.telephony.AvailableNetworkInfo;
import android.telephony.TelephonyManager;
import java.util.List;
import java.util.concurrent.Executor;
import java.util.function.Consumer;

/**
 * Conversion from desugared to built-in {@link Consumer} for calling built-in Android APIs (see
 * b/128638076).
 */
// TODO(b/74087778): Unnecessary when j$.u.f.Consumer becomes subtype of built-in j.u.f.Consumer
@SuppressWarnings("AndroidJdkLibsChecker")
public final class ConsumerWrapper<T> implements Consumer<T> {

  private final j$.util.function.Consumer<T> wrapped;

  private ConsumerWrapper(j$.util.function.Consumer<T> wrapped) {
    this.wrapped = wrapped;
  }

  @Override
  public void accept(T t) {
    wrapped.accept(t);
  }

  public static void setPreferredOpportunisticDataSubscription(
      TelephonyManager receiver,
      int subId,
      boolean needValidation,
      Executor executor,
      j$.util.function.Consumer<Integer> callback) {
    receiver.setPreferredOpportunisticDataSubscription(
        subId,
        needValidation,
        executor,
        callback != null ? new ConsumerWrapper<Integer>(callback) : null);
  }

  public static void updateAvailableNetworks(
      TelephonyManager receiver,
      List<AvailableNetworkInfo> availableNetworks,
      Executor executor,
      j$.util.function.Consumer<Integer> callback) {
    receiver.updateAvailableNetworks(
        availableNetworks,
        executor,
        callback != null ? new ConsumerWrapper<Integer>(callback) : null);
  }
}

@@ -668,16 +668,167 @@
 ntime;%0A%0A
+import android.app.DirectAction;%0Aimport android.os.Bundle;%0Aimport android.os.CancellationSignal;%0Aimport android.service.voice.VoiceInteractionSession;%0A
 import a
@@ -2340,11 +2340,957 @@
 ll);%0A  %7D
+%0A%0A  public static void performDirectAction(%0A      VoiceInteractionSession receiver,%0A      DirectAction action,%0A      Bundle extras,%0A      CancellationSignal cancellationSignal,%0A      Executor resultExecutor,%0A      j$.util.function.Consumer%3CBundle%3E resultListener) %7B%0A    receiver.performDirectAction(%0A        action,%0A        extras,%0A        cancellationSignal,%0A        resultExecutor,%0A        resultListener != null ? new ConsumerWrapper%3CBundle%3E(resultListener) : null);%0A  %7D%0A%0A  public final void requestDirectActions(%0A      VoiceInteractionSession receiver,%0A      VoiceInteractionSession.ActivityId activityId,%0A      CancellationSignal cancellationSignal,%0A      Executor resultExecutor,%0A      j$.util.function.Consumer%3CList%3CDirectAction%3E%3E callback) %7B%0A    receiver.requestDirectActions(%0A        activityId,%0A        cancellationSignal,%0A        resultExecutor,%0A        callback != null ? new ConsumerWrapper%3CList%3CDirectAction%3E%3E(callback) : null);%0A  %7D
 %0A%7D%0A

Support VoiceInteractionSession.{requestDirectActions,performDirectAction} with Java 8 library desugaring.