diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainPresenter.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainPresenter.java index 1534b0c654..ebd43513ab 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainPresenter.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainPresenter.java @@ -19,12 +19,12 @@ import org.dolphinemu.dolphinemu.model.GameFileCache; import org.dolphinemu.dolphinemu.services.GameFileCacheService; import org.dolphinemu.dolphinemu.utils.AfterDirectoryInitializationRunner; import org.dolphinemu.dolphinemu.utils.BooleanSupplier; +import org.dolphinemu.dolphinemu.utils.CompletableFuture; import org.dolphinemu.dolphinemu.utils.ContentHandler; import org.dolphinemu.dolphinemu.utils.FileBrowserHelper; import org.dolphinemu.dolphinemu.utils.WiiUtils; import java.util.Arrays; -import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; import java.util.function.Supplier; @@ -171,9 +171,6 @@ public final class MainPresenter public void importWiiSave(String path) { - if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.N) - return; // TODO - final Activity mainPresenterActivity = (Activity) mContext; CompletableFuture canOverwriteFuture = new CompletableFuture<>(); diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/CompletableFuture.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/CompletableFuture.java new file mode 100644 index 0000000000..bdd1b02faf --- /dev/null +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/CompletableFuture.java @@ -0,0 +1,95 @@ +package org.dolphinemu.dolphinemu.utils; + +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; +import java.util.concurrent.locks.Condition; +import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.ReentrantLock; + +/** + * Simplified re-implementation of a subset of {@link java.util.concurrent.CompletableFuture}. + * Replace this class with that class once we have full Java 8 support (once we require API 24). + */ +public class CompletableFuture implements Future +{ + private final Lock lock = new ReentrantLock(); + private final Condition done = lock.newCondition(); + + private boolean isDone = false; + private T result = null; + + @Override + public boolean cancel(boolean mayInterruptIfRunning) + { + throw new UnsupportedOperationException(); + } + + @Override + public boolean isCancelled() + { + return false; + } + + @Override + public boolean isDone() + { + return isDone; + } + + @Override + public T get() throws ExecutionException, InterruptedException + { + lock.lock(); + try + { + while (!isDone) + done.await(); + + return result; + } + finally + { + lock.unlock(); + } + } + + @Override + public T get(long timeout, TimeUnit unit) + throws ExecutionException, InterruptedException, TimeoutException + { + lock.lock(); + try + { + while (!isDone) + { + if (!done.await(timeout, unit)) + throw new TimeoutException(); + } + + return result; + } + finally + { + lock.unlock(); + } + } + + public boolean complete(T value) + { + lock.lock(); + try + { + boolean wasDone = isDone; + result = value; + isDone = true; + done.signalAll(); + return !wasDone; + } + finally + { + lock.unlock(); + } + } +}