mirror of
https://github.com/TeamVanced/VancedMicroG
synced 2025-02-02 22:17:31 +01:00
Properly implement status details
This commit is contained in:
parent
5e8494c11a
commit
c61a147de2
@ -16,14 +16,19 @@
|
|||||||
|
|
||||||
package com.google.android.gms.common.api;
|
package com.google.android.gms.common.api;
|
||||||
|
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
|
||||||
import org.microg.gms.common.PublicApi;
|
import org.microg.gms.common.PublicApi;
|
||||||
|
|
||||||
@PublicApi
|
@PublicApi
|
||||||
public class CommonStatusCodes {
|
public class CommonStatusCodes {
|
||||||
public static final int SUCCESS_CACHE = -1;
|
public static final int SUCCESS_CACHE = -1;
|
||||||
public static final int SUCCESS = 0;
|
public static final int SUCCESS = 0;
|
||||||
|
@Deprecated
|
||||||
public static final int SERVICE_MISSING = 1;
|
public static final int SERVICE_MISSING = 1;
|
||||||
|
@Deprecated
|
||||||
public static final int SERVICE_VERSION_UPDATE_REQUIRED = 2;
|
public static final int SERVICE_VERSION_UPDATE_REQUIRED = 2;
|
||||||
|
@Deprecated
|
||||||
public static final int SERVICE_DISABLED = 3;
|
public static final int SERVICE_DISABLED = 3;
|
||||||
public static final int SIGN_IN_REQUIRED = 4;
|
public static final int SIGN_IN_REQUIRED = 4;
|
||||||
public static final int INVALID_ACCOUNT = 5;
|
public static final int INVALID_ACCOUNT = 5;
|
||||||
@ -37,4 +42,50 @@ public class CommonStatusCodes {
|
|||||||
public static final int INTERRUPTED = 14;
|
public static final int INTERRUPTED = 14;
|
||||||
public static final int TIMEOUT = 15;
|
public static final int TIMEOUT = 15;
|
||||||
public static final int CANCELED = 16;
|
public static final int CANCELED = 16;
|
||||||
|
public static final int API_NOT_CONNECTED = 17;
|
||||||
|
public static final int DEAD_CLIENT = 18;
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
public static String getStatusCodeString(int statusCode) {
|
||||||
|
switch (statusCode) {
|
||||||
|
case SUCCESS_CACHE:
|
||||||
|
return "SUCCESS_CACHE";
|
||||||
|
case SUCCESS:
|
||||||
|
return "SUCCESS";
|
||||||
|
case SERVICE_VERSION_UPDATE_REQUIRED:
|
||||||
|
return "SERVICE_VERSION_UPDATE_REQUIRED";
|
||||||
|
case SERVICE_DISABLED:
|
||||||
|
return "SERVICE_DISABLED";
|
||||||
|
case SIGN_IN_REQUIRED:
|
||||||
|
return "SIGN_IN_REQUIRED";
|
||||||
|
case INVALID_ACCOUNT:
|
||||||
|
return "INVALID_ACCOUNT";
|
||||||
|
case RESOLUTION_REQUIRED:
|
||||||
|
return "RESOLUTION_REQUIRED";
|
||||||
|
case NETWORK_ERROR:
|
||||||
|
return "NETWORK_ERROR";
|
||||||
|
case INTERNAL_ERROR:
|
||||||
|
return "INTERNAL_ERROR";
|
||||||
|
case SERVICE_INVALID:
|
||||||
|
return "SERVICE_INVALID";
|
||||||
|
case DEVELOPER_ERROR:
|
||||||
|
return "DEVELOPER_ERROR";
|
||||||
|
case LICENSE_CHECK_FAILED:
|
||||||
|
return "LICENSE_CHECK_FAILED";
|
||||||
|
case ERROR:
|
||||||
|
return "ERROR";
|
||||||
|
case INTERRUPTED:
|
||||||
|
return "INTERRUPTED";
|
||||||
|
case TIMEOUT:
|
||||||
|
return "TIMEOUT";
|
||||||
|
case CANCELED:
|
||||||
|
return "CANCELED";
|
||||||
|
case API_NOT_CONNECTED:
|
||||||
|
return "API_NOT_CONNECTED";
|
||||||
|
case DEAD_CLIENT:
|
||||||
|
return "DEAD_CLIENT";
|
||||||
|
default:
|
||||||
|
return "unknown status code: " + statusCode;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,30 +16,38 @@
|
|||||||
|
|
||||||
package com.google.android.gms.common.api;
|
package com.google.android.gms.common.api;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.IntentSender;
|
||||||
|
import android.content.IntentSender.SendIntentException;
|
||||||
|
|
||||||
import org.microg.gms.common.PublicApi;
|
import org.microg.gms.common.PublicApi;
|
||||||
import org.microg.safeparcel.AutoSafeParcelable;
|
import org.microg.safeparcel.AutoSafeParcelable;
|
||||||
|
import org.microg.safeparcel.SafeParceled;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents the results of work.
|
* Represents the results of work.
|
||||||
* <p/>
|
|
||||||
* TODO: Docs
|
|
||||||
*/
|
*/
|
||||||
@PublicApi
|
@PublicApi
|
||||||
public final class Status extends AutoSafeParcelable implements Result {
|
public final class Status extends AutoSafeParcelable implements Result {
|
||||||
private static final int STATUS_CODE_INTERNAL_ERROR = 8;
|
@PublicApi(exclude = true)
|
||||||
private static final int STATUS_CODE_INTERRUPTED = 14;
|
public static final Status INTERNAL_ERROR = new Status(CommonStatusCodes.INTERNAL_ERROR);
|
||||||
private static final int STATUS_CODE_CANCELED = 16;
|
@PublicApi(exclude = true)
|
||||||
|
public static final Status CANCELED = new Status(CommonStatusCodes.CANCELED);
|
||||||
public static final Status INTERNAL_ERROR = new Status(STATUS_CODE_INTERNAL_ERROR);
|
@PublicApi(exclude = true)
|
||||||
public static final Status INTERRUPTED = new Status(STATUS_CODE_INTERRUPTED);
|
public static final Status SUCCESS = new Status(CommonStatusCodes.SUCCESS);
|
||||||
public static final Status CANCELED = new Status(STATUS_CODE_CANCELED);
|
|
||||||
public static final Status SUCCESS = new Status(0);
|
|
||||||
|
|
||||||
|
@SafeParceled(1000)
|
||||||
private int versionCode = 1;
|
private int versionCode = 1;
|
||||||
|
|
||||||
|
@SafeParceled(1)
|
||||||
private final int statusCode;
|
private final int statusCode;
|
||||||
|
|
||||||
|
@SafeParceled(2)
|
||||||
private final String statusMessage;
|
private final String statusMessage;
|
||||||
|
|
||||||
|
@SafeParceled(3)
|
||||||
private final PendingIntent resolution;
|
private final PendingIntent resolution;
|
||||||
|
|
||||||
private Status() {
|
private Status() {
|
||||||
@ -48,24 +56,67 @@ public final class Status extends AutoSafeParcelable implements Result {
|
|||||||
resolution = null;
|
resolution = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a representation of the status resulting from a GoogleApiClient operation.
|
||||||
|
*
|
||||||
|
* @param statusCode The status code.
|
||||||
|
*/
|
||||||
public Status(int statusCode) {
|
public Status(int statusCode) {
|
||||||
this(statusCode, null);
|
this(statusCode, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a representation of the status resulting from a GoogleApiClient operation.
|
||||||
|
*
|
||||||
|
* @param statusCode The status code.
|
||||||
|
* @param statusMessage The message associated with this status, or null.
|
||||||
|
*/
|
||||||
public Status(int statusCode, String statusMessage) {
|
public Status(int statusCode, String statusMessage) {
|
||||||
this(statusCode, statusMessage, null);
|
this(statusCode, statusMessage, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a representation of the status resulting from a GoogleApiClient operation.
|
||||||
|
*
|
||||||
|
* @param statusCode The status code.
|
||||||
|
* @param statusMessage The message associated with this status, or null.
|
||||||
|
* @param resolution A pending intent that will resolve the issue when started, or null.
|
||||||
|
*/
|
||||||
public Status(int statusCode, String statusMessage, PendingIntent resolution) {
|
public Status(int statusCode, String statusMessage, PendingIntent resolution) {
|
||||||
this.statusCode = statusCode;
|
this.statusCode = statusCode;
|
||||||
this.statusMessage = statusMessage;
|
this.statusMessage = statusMessage;
|
||||||
this.resolution = resolution;
|
this.resolution = resolution;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A pending intent to resolve the failure. This intent can be started with
|
||||||
|
* {@link Activity#startIntentSenderForResult(IntentSender, int, Intent, int, int, int)} to
|
||||||
|
* present UI to solve the issue.
|
||||||
|
*
|
||||||
|
* @return The pending intent to resolve the failure.
|
||||||
|
*/
|
||||||
public PendingIntent getResolution() {
|
public PendingIntent getResolution() {
|
||||||
return resolution;
|
return resolution;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the status of this result. Use {@link #isSuccess()} to determine whether the call
|
||||||
|
* was successful, and {@link #getStatusCode()} to determine what the error cause was.
|
||||||
|
* <p>
|
||||||
|
* Certain errors are due to failures that can be resolved by launching a particular intent.
|
||||||
|
* The resolution intent is available via {@link #getResolution()}.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Status getStatus() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates the status of the operation.
|
||||||
|
*
|
||||||
|
* @return Status code resulting from the operation. The value is one of the constants in
|
||||||
|
* {@link CommonStatusCodes} or specific to the APIs added to the GoogleApiClient.
|
||||||
|
*/
|
||||||
public int getStatusCode() {
|
public int getStatusCode() {
|
||||||
return statusCode;
|
return statusCode;
|
||||||
}
|
}
|
||||||
@ -74,25 +125,55 @@ public final class Status extends AutoSafeParcelable implements Result {
|
|||||||
return statusMessage;
|
return statusMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if calling {@link #startResolutionForResult(Activity, int)} will start any
|
||||||
|
* intents requiring user interaction.
|
||||||
|
*
|
||||||
|
* @return true if there is a resolution that can be started.
|
||||||
|
*/
|
||||||
public boolean hasResolution() {
|
public boolean hasResolution() {
|
||||||
return resolution != null;
|
return resolution != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if the operation was canceled.
|
||||||
|
*/
|
||||||
public boolean isCanceled() {
|
public boolean isCanceled() {
|
||||||
return statusCode == STATUS_CODE_CANCELED;
|
return statusCode == CommonStatusCodes.CANCELED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if the operation was interrupted.
|
||||||
|
*/
|
||||||
public boolean isInterrupted() {
|
public boolean isInterrupted() {
|
||||||
return statusCode == STATUS_CODE_INTERRUPTED;
|
return statusCode == CommonStatusCodes.INTERRUPTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if the operation was successful.
|
||||||
|
*
|
||||||
|
* @return true if the operation was successful, false if there was an error.
|
||||||
|
*/
|
||||||
public boolean isSuccess() {
|
public boolean isSuccess() {
|
||||||
return statusCode <= 0;
|
return statusCode <= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
/**
|
||||||
public Status getStatus() {
|
* Resolves an error by starting any intents requiring user interaction. See
|
||||||
return this;
|
* {@link CommonStatusCodes#SIGN_IN_REQUIRED}, and {@link CommonStatusCodes#RESOLUTION_REQUIRED}.
|
||||||
|
*
|
||||||
|
* @param activity An Activity context to use to resolve the issue. The activity's
|
||||||
|
* onActivityResult method will be invoked after the user is done. If the
|
||||||
|
* resultCode is {@link Activity#RESULT_OK}, the application should try to
|
||||||
|
* connect again.
|
||||||
|
* @param requestCode The request code to pass to onActivityResult.
|
||||||
|
* @throws SendIntentException If the resolution intent has been canceled or is no longer able
|
||||||
|
* to execute the request.
|
||||||
|
*/
|
||||||
|
public void startResolutionForResult(Activity activity, int requestCode) throws SendIntentException {
|
||||||
|
if (hasResolution()) {
|
||||||
|
activity.startIntentSenderForResult(resolution.getIntentSender(), requestCode, null, 0, 0, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final Creator<Status> CREATOR = new AutoCreator<Status>(Status.class);
|
public static final Creator<Status> CREATOR = new AutoCreator<Status>(Status.class);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user