+ * To create a {@link CancellationToken}, create a {@link CancellationTokenSource} first and then call {@link #getToken()} to get the {@link CancellationToken} for this {@link CancellationTokenSource}.
+ *
+ * @see CancellationToken
+ */
+@PublicApi
+public class CancellationTokenSource {
+ private CancellationTokenImpl token = new CancellationTokenImpl();
+
+ /**
+ * Creates a new {@link CancellationTokenSource} instance.
+ */
+ public CancellationTokenSource() {
+ }
+
+ /**
+ * Cancels the {@link CancellationToken} if cancellation has not been requested yet.
+ */
+ public void cancel() {
+ token.cancel();
+ }
+
+ /**
+ * Gets the {@link CancellationToken} for this {@link CancellationTokenSource}.
+ *
+ * @return the {@link CancellationToken} that can be passed to asynchronous {@link Task} to cancel the Task.
+ */
+ public CancellationToken getToken() {
+ return token;
+ }
+}
diff --git a/play-services-tasks/src/main/java/com/google/android/gms/tasks/Continuation.java b/play-services-tasks/src/main/java/com/google/android/gms/tasks/Continuation.java
index 26b69a81..7057ca71 100644
--- a/play-services-tasks/src/main/java/com/google/android/gms/tasks/Continuation.java
+++ b/play-services-tasks/src/main/java/com/google/android/gms/tasks/Continuation.java
@@ -1,17 +1,9 @@
/*
- * Copyright (C) 2013-2017 microG Project Team
- *
- * 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.
+ * SPDX-FileCopyrightText: 2016, microG Project Team
+ * SPDX-License-Identifier: Apache-2.0 AND CC-BY-4.0
+ * Notice: Portions of this file are reproduced from work created and shared by Google and used
+ * according to terms described in the Creative Commons 4.0 Attribution License.
+ * See https://developers.google.com/readme/policies for details.
*/
package com.google.android.gms.tasks;
diff --git a/play-services-tasks/src/main/java/com/google/android/gms/tasks/DuplicateTaskCompletionException.java b/play-services-tasks/src/main/java/com/google/android/gms/tasks/DuplicateTaskCompletionException.java
new file mode 100644
index 00000000..81eaa700
--- /dev/null
+++ b/play-services-tasks/src/main/java/com/google/android/gms/tasks/DuplicateTaskCompletionException.java
@@ -0,0 +1,32 @@
+/*
+ * SPDX-FileCopyrightText: 2020, microG Project Team
+ * SPDX-License-Identifier: Apache-2.0 AND CC-BY-4.0
+ * Notice: Portions of this file are reproduced from work created and shared by Google and used
+ * according to terms described in the Creative Commons 4.0 Attribution License.
+ * See https://developers.google.com/readme/policies for details.
+ */
+
+package com.google.android.gms.tasks;
+
+import org.microg.gms.common.PublicApi;
+
+/**
+ * An exception indicating that something attempted to set a result, exception, or cancellation on a {@link Task} that was already completed.
+ */
+@PublicApi
+public class DuplicateTaskCompletionException extends IllegalStateException {
+
+ private DuplicateTaskCompletionException(String s) {
+ super(s);
+ }
+
+ /**
+ * Creates a DuplicateTaskCompletionException from a {@link Task}.
+ *
+ * The {@link Task} must be complete.
+ */
+ public static DuplicateTaskCompletionException of(Task> task) {
+ if (!task.isComplete()) throw new IllegalStateException("Task is not yet completed");
+ return new DuplicateTaskCompletionException("Task is already completed");
+ }
+}
diff --git a/play-services-tasks/src/main/java/com/google/android/gms/tasks/OnCanceledListener.java b/play-services-tasks/src/main/java/com/google/android/gms/tasks/OnCanceledListener.java
new file mode 100644
index 00000000..32fd7b0f
--- /dev/null
+++ b/play-services-tasks/src/main/java/com/google/android/gms/tasks/OnCanceledListener.java
@@ -0,0 +1,22 @@
+/*
+ * SPDX-FileCopyrightText: 2020, microG Project Team
+ * SPDX-License-Identifier: Apache-2.0 AND CC-BY-4.0
+ * Notice: Portions of this file are reproduced from work created and shared by Google and used
+ * according to terms described in the Creative Commons 4.0 Attribution License.
+ * See https://developers.google.com/readme/policies for details.
+ */
+
+package com.google.android.gms.tasks;
+
+import org.microg.gms.common.PublicApi;
+
+/**
+ * Listener called when a {@link Task} is canceled.
+ */
+@PublicApi
+public interface OnCanceledListener {
+ /**
+ * Called when the Task is canceled successfully.
+ */
+ public abstract void onCanceled();
+}
diff --git a/play-services-tasks/src/main/java/com/google/android/gms/tasks/OnCompleteListener.java b/play-services-tasks/src/main/java/com/google/android/gms/tasks/OnCompleteListener.java
index 2035472c..7cff8dcf 100644
--- a/play-services-tasks/src/main/java/com/google/android/gms/tasks/OnCompleteListener.java
+++ b/play-services-tasks/src/main/java/com/google/android/gms/tasks/OnCompleteListener.java
@@ -1,17 +1,9 @@
/*
- * Copyright (C) 2013-2017 microG Project Team
- *
- * 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.
+ * SPDX-FileCopyrightText: 2016, microG Project Team
+ * SPDX-License-Identifier: Apache-2.0 AND CC-BY-4.0
+ * Notice: Portions of this file are reproduced from work created and shared by Google and used
+ * according to terms described in the Creative Commons 4.0 Attribution License.
+ * See https://developers.google.com/readme/policies for details.
*/
package com.google.android.gms.tasks;
diff --git a/play-services-tasks/src/main/java/com/google/android/gms/tasks/OnFailureListener.java b/play-services-tasks/src/main/java/com/google/android/gms/tasks/OnFailureListener.java
index c6e1124b..e9391531 100644
--- a/play-services-tasks/src/main/java/com/google/android/gms/tasks/OnFailureListener.java
+++ b/play-services-tasks/src/main/java/com/google/android/gms/tasks/OnFailureListener.java
@@ -1,17 +1,9 @@
/*
- * Copyright (C) 2013-2017 microG Project Team
- *
- * 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.
+ * SPDX-FileCopyrightText: 2016, microG Project Team
+ * SPDX-License-Identifier: Apache-2.0 AND CC-BY-4.0
+ * Notice: Portions of this file are reproduced from work created and shared by Google and used
+ * according to terms described in the Creative Commons 4.0 Attribution License.
+ * See https://developers.google.com/readme/policies for details.
*/
package com.google.android.gms.tasks;
diff --git a/play-services-tasks/src/main/java/com/google/android/gms/tasks/OnSuccessListener.java b/play-services-tasks/src/main/java/com/google/android/gms/tasks/OnSuccessListener.java
index f6e6fbdd..5460c0a9 100644
--- a/play-services-tasks/src/main/java/com/google/android/gms/tasks/OnSuccessListener.java
+++ b/play-services-tasks/src/main/java/com/google/android/gms/tasks/OnSuccessListener.java
@@ -1,17 +1,9 @@
/*
- * Copyright (C) 2013-2017 microG Project Team
- *
- * 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.
+ * SPDX-FileCopyrightText: 2016, microG Project Team
+ * SPDX-License-Identifier: Apache-2.0 AND CC-BY-4.0
+ * Notice: Portions of this file are reproduced from work created and shared by Google and used
+ * according to terms described in the Creative Commons 4.0 Attribution License.
+ * See https://developers.google.com/readme/policies for details.
*/
package com.google.android.gms.tasks;
diff --git a/play-services-tasks/src/main/java/com/google/android/gms/tasks/OnTokenCanceledListener.java b/play-services-tasks/src/main/java/com/google/android/gms/tasks/OnTokenCanceledListener.java
new file mode 100644
index 00000000..0ad2d686
--- /dev/null
+++ b/play-services-tasks/src/main/java/com/google/android/gms/tasks/OnTokenCanceledListener.java
@@ -0,0 +1,24 @@
+/*
+ * SPDX-FileCopyrightText: 2020, microG Project Team
+ * SPDX-License-Identifier: Apache-2.0 AND CC-BY-4.0
+ * Notice: Portions of this file are reproduced from work created and shared by Google and used
+ * according to terms described in the Creative Commons 4.0 Attribution License.
+ * See https://developers.google.com/readme/policies for details.
+ */
+
+package com.google.android.gms.tasks;
+
+import org.microg.gms.common.PublicApi;
+
+/**
+ * Listener called when a {@link CancellationToken} is canceled successfully.
+ *
+ * @see CancellationToken#onCanceledRequested(OnTokenCanceledListener)
+ */
+@PublicApi
+public interface OnTokenCanceledListener {
+ /**
+ * Called when the {@link CancellationToken} is canceled successfully.
+ */
+ void onCanceled();
+}
diff --git a/play-services-tasks/src/main/java/com/google/android/gms/tasks/RuntimeExecutionException.java b/play-services-tasks/src/main/java/com/google/android/gms/tasks/RuntimeExecutionException.java
index 99482115..a15dfbe3 100644
--- a/play-services-tasks/src/main/java/com/google/android/gms/tasks/RuntimeExecutionException.java
+++ b/play-services-tasks/src/main/java/com/google/android/gms/tasks/RuntimeExecutionException.java
@@ -1,17 +1,9 @@
/*
- * Copyright (C) 2013-2017 microG Project Team
- *
- * 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.
+ * SPDX-FileCopyrightText: 2016, microG Project Team
+ * SPDX-License-Identifier: Apache-2.0 AND CC-BY-4.0
+ * Notice: Portions of this file are reproduced from work created and shared by Google and used
+ * according to terms described in the Creative Commons 4.0 Attribution License.
+ * See https://developers.google.com/readme/policies for details.
*/
package com.google.android.gms.tasks;
diff --git a/play-services-tasks/src/main/java/com/google/android/gms/tasks/SuccessContinuation.java b/play-services-tasks/src/main/java/com/google/android/gms/tasks/SuccessContinuation.java
new file mode 100644
index 00000000..3feb598e
--- /dev/null
+++ b/play-services-tasks/src/main/java/com/google/android/gms/tasks/SuccessContinuation.java
@@ -0,0 +1,28 @@
+/*
+ * SPDX-FileCopyrightText: 2020, microG Project Team
+ * SPDX-License-Identifier: Apache-2.0 AND CC-BY-4.0
+ * Notice: Portions of this file are reproduced from work created and shared by Google and used
+ * according to terms described in the Creative Commons 4.0 Attribution License.
+ * See https://developers.google.com/readme/policies for details.
+ */
+
+package com.google.android.gms.tasks;
+
+import org.microg.gms.common.PublicApi;
+
+/**
+ * A function that is called to continue execution then a {@link Task} succeeds.
+ * @see Task#onSuccessTask
+ */
+@PublicApi
+public interface SuccessContinuation
+ * The SuccessContinuation only happens then the Task is successful. If the previous Task fails, the onSuccessTask continuation will be skipped and failure listeners will be invoked.
+ *
+ * @param result the result of completed Task
+ * @throws Exception if the result couldn't be produced
+ */
+ Task
+ * The listener will be called on main application thread. If the Task has already been canceled, a call to the listener will be immediately scheduled. If multiple listeners are added, they will be called in the order in which they were added.
+ *
+ * @return this Task
+ */
+ public Task
+ * If the Task has already been canceled, a call to the listener will be immediately scheduled. If multiple listeners are added, they will be called in the order in which they were added.
+ *
+ * @param executor the executor to use to call the listener
+ * @return this Task
+ */
+ public Task
+ * The listener will be called on main application thread. If the Task has already been canceled, a call to the listener will be immediately scheduled. If multiple listeners are added, they will be called in the order in which they were added.
+ *
+ * The listener will be automatically removed during {@link Activity#onStop()}.
+ *
+ * @return this Task
+ */
+ public Task
+ * The SuccessContinuation will be called on the main application thread.
+ *
+ * If the previous Task is canceled, the returned Task will also be canceled and the SuccessContinuation would not execute.
+ *
+ * @see SuccessContinuation#then
+ */
+ public
+ * If the previous Task is canceled, the returned Task will also be canceled and the SuccessContinuation would not execute.
+ *
+ * @param executor the executor to use to call the SuccessContinuation
+ * @see SuccessContinuation#then
+ */
+ public