Add ApiException and use it in EN client impl

This commit is contained in:
Christian Grigis 2020-09-11 17:12:10 +02:00 committed by Marvin W
parent bd20634bd9
commit 832ee232ea
2 changed files with 65 additions and 7 deletions

View File

@ -0,0 +1,57 @@
package com.google.android.gms.common.api;
import com.google.android.gms.common.api.Status;
import org.microg.gms.common.PublicApi;
/**
* Exception to be returned by a Task when a call to Google Play services has failed.
*/
@PublicApi
public class ApiException extends Exception {
/**
* @deprecated use {@link #getStatus()} instead
*/
@PublicApi
protected final Status mStatus;
/**
* Create an ApiException from a {@link com.google.android.gms.common.api.Status}.
* @param status the Status instance containing a message and code.
*/
@PublicApi
public ApiException(Status status) {
mStatus = status;
}
/**
* Returns the status of the operation.
*/
@PublicApi
public Status getStatus() {
return mStatus;
}
/**
* Indicates the status of the operation.
* @return Status code resulting from the operation.
* The value is one of the constants in {@link com.google.android.gms.common.api.CommonStatusCodes} or specific to the API in use.
*/
@PublicApi
public int getStatusCode() {
return mStatus.getStatusCode();
}
/**
* @deprecated use {@link #getMessage()} for a summary of the cause.
*/
@PublicApi
public String getStatusMessage() {
return getMessage();
}
@Override
public String getMessage() {
return mStatus.getStatusMessage();
}
}

View File

@ -10,6 +10,7 @@ import android.os.ParcelFileDescriptor;
import android.util.Log;
import com.google.android.gms.common.api.Api;
import com.google.android.gms.common.api.ApiException;
import com.google.android.gms.common.api.GoogleApi;
import com.google.android.gms.common.api.Status;
import com.google.android.gms.common.api.internal.ApiKey;
@ -58,7 +59,7 @@ public class ExposureNotificationClientImpl extends GoogleApi<Api.ApiOptions.NoO
if (status == Status.SUCCESS) {
completionSource.setResult(null);
} else {
completionSource.setException(new RuntimeException("Status: " + status));
completionSource.setException(new ApiException(status));
}
}
});
@ -79,7 +80,7 @@ public class ExposureNotificationClientImpl extends GoogleApi<Api.ApiOptions.NoO
if (status == Status.SUCCESS) {
completionSource.setResult(null);
} else {
completionSource.setException(new RuntimeException("Status: " + status));
completionSource.setException(new ApiException(status));
}
}
});
@ -100,7 +101,7 @@ public class ExposureNotificationClientImpl extends GoogleApi<Api.ApiOptions.NoO
if (status == Status.SUCCESS) {
completionSource.setResult(result);
} else {
completionSource.setException(new RuntimeException("Status: " + status));
completionSource.setException(new ApiException(status));
}
}
});
@ -121,7 +122,7 @@ public class ExposureNotificationClientImpl extends GoogleApi<Api.ApiOptions.NoO
if (status == Status.SUCCESS) {
completionSource.setResult(result);
} else {
completionSource.setException(new RuntimeException("Status: " + status));
completionSource.setException(new ApiException(status));
}
}
});
@ -161,7 +162,7 @@ public class ExposureNotificationClientImpl extends GoogleApi<Api.ApiOptions.NoO
if (status == Status.SUCCESS) {
completionSource.setResult(null);
} else {
completionSource.setException(new RuntimeException("Status: " + status));
completionSource.setException(new ApiException(status));
}
}
}, fds, configuration, token);
@ -182,7 +183,7 @@ public class ExposureNotificationClientImpl extends GoogleApi<Api.ApiOptions.NoO
if (status == Status.SUCCESS) {
completionSource.setResult(result);
} else {
completionSource.setException(new RuntimeException("Status: " + status));
completionSource.setException(new ApiException(status));
}
}
}, token);
@ -203,7 +204,7 @@ public class ExposureNotificationClientImpl extends GoogleApi<Api.ApiOptions.NoO
if (status == Status.SUCCESS) {
completionSource.setResult(result);
} else {
completionSource.setException(new RuntimeException("Status: " + status));
completionSource.setException(new ApiException(status));
}
}
}, token);