Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5d1a0c39 authored by Fred Quintana's avatar Fred Quintana
Browse files

Make the AbstractAccountAuthenticator return an error to the AccountManagerService

if it detects a RuntimeException.

Bug: 4726899
Change-Id: I5c478464cd0d426722257b2c5c75f964cd839ea6
parent 58b86841
Loading
Loading
Loading
Loading
+45 −73
Original line number Original line Diff line number Diff line
@@ -24,7 +24,6 @@ import android.content.pm.PackageManager;
import android.content.Context;
import android.content.Context;
import android.content.Intent;
import android.content.Intent;
import android.Manifest;
import android.Manifest;
import android.text.TextUtils;
import android.util.Log;
import android.util.Log;


import java.util.Arrays;
import java.util.Arrays;
@@ -136,17 +135,8 @@ public abstract class AbstractAccountAuthenticator {
                if (result != null) {
                if (result != null) {
                    response.onResult(result);
                    response.onResult(result);
                }
                }
            } catch (NetworkErrorException e) {
            } catch (Exception e) {
                if (Log.isLoggable(TAG, Log.VERBOSE)) {
                handleException(response, "addAccount", accountType, e);
                    Log.v(TAG, "addAccount", e);
                }
                response.onError(AccountManager.ERROR_CODE_NETWORK_ERROR, e.getMessage());
            } catch (UnsupportedOperationException e) {
                if (Log.isLoggable(TAG, Log.VERBOSE)) {
                    Log.v(TAG, "addAccount", e);
                }
                response.onError(AccountManager.ERROR_CODE_UNSUPPORTED_OPERATION,
                        "addAccount not supported");
            }
            }
        }
        }


@@ -167,17 +157,8 @@ public abstract class AbstractAccountAuthenticator {
                if (result != null) {
                if (result != null) {
                    response.onResult(result);
                    response.onResult(result);
                }
                }
            } catch (NetworkErrorException e) {
            } catch (Exception e) {
                if (Log.isLoggable(TAG, Log.VERBOSE)) {
                handleException(response, "confirmCredentials", account.toString(), e);
                    Log.v(TAG, "confirmCredentials", e);
                }
                response.onError(AccountManager.ERROR_CODE_NETWORK_ERROR, e.getMessage());
            } catch (UnsupportedOperationException e) {
                if (Log.isLoggable(TAG, Log.VERBOSE)) {
                    Log.v(TAG, "confirmCredentials", e);
                }
                response.onError(AccountManager.ERROR_CODE_UNSUPPORTED_OPERATION,
                        "confirmCredentials not supported");
            }
            }
        }
        }


@@ -197,21 +178,9 @@ public abstract class AbstractAccountAuthenticator {
                    Log.v(TAG, "getAuthTokenLabel: result "
                    Log.v(TAG, "getAuthTokenLabel: result "
                            + AccountManager.sanitizeResult(result));
                            + AccountManager.sanitizeResult(result));
                }
                }
                if (result != null) {
                response.onResult(result);
                response.onResult(result);
                }
            } catch (Exception e) {
            } catch (IllegalArgumentException e) {
                handleException(response, "getAuthTokenLabel", authTokenType, e);
                if (Log.isLoggable(TAG, Log.VERBOSE)) {
                    Log.v(TAG, "getAuthTokenLabel", e);
                }
                response.onError(AccountManager.ERROR_CODE_BAD_ARGUMENTS,
                        "unknown authTokenType");
            } catch (UnsupportedOperationException e) {
                if (Log.isLoggable(TAG, Log.VERBOSE)) {
                    Log.v(TAG, "getAuthTokenLabel", e);
                }
                response.onError(AccountManager.ERROR_CODE_UNSUPPORTED_OPERATION,
                        "getAuthTokenTypeLabel not supported");
            }
            }
        }
        }


@@ -234,17 +203,9 @@ public abstract class AbstractAccountAuthenticator {
                if (result != null) {
                if (result != null) {
                    response.onResult(result);
                    response.onResult(result);
                }
                }
            } catch (UnsupportedOperationException e) {
            } catch (Exception e) {
                if (Log.isLoggable(TAG, Log.VERBOSE)) {
                handleException(response, "getAuthToken",
                    Log.v(TAG, "getAuthToken", e);
                        account.toString() + "," + authTokenType, e);
                }
                response.onError(AccountManager.ERROR_CODE_UNSUPPORTED_OPERATION,
                        "getAuthToken not supported");
            } catch (NetworkErrorException e) {
                if (Log.isLoggable(TAG, Log.VERBOSE)) {
                    Log.v(TAG, "getAuthToken", e);
                }
                response.onError(AccountManager.ERROR_CODE_NETWORK_ERROR, e.getMessage());
            }
            }
        }
        }


@@ -267,17 +228,9 @@ public abstract class AbstractAccountAuthenticator {
                if (result != null) {
                if (result != null) {
                    response.onResult(result);
                    response.onResult(result);
                }
                }
            } catch (NetworkErrorException e) {
            } catch (Exception e) {
                if (Log.isLoggable(TAG, Log.VERBOSE)) {
                handleException(response, "updateCredentials",
                    Log.v(TAG, "updateCredentials", e);
                        account.toString() + "," + authTokenType, e);
                }
                response.onError(AccountManager.ERROR_CODE_NETWORK_ERROR, e.getMessage());
            } catch (UnsupportedOperationException e) {
                if (Log.isLoggable(TAG, Log.VERBOSE)) {
                    Log.v(TAG, "updateCredentials", e);
                }
                response.onError(AccountManager.ERROR_CODE_UNSUPPORTED_OPERATION,
                        "updateCredentials not supported");
            }
            }
        }
        }


@@ -290,9 +243,8 @@ public abstract class AbstractAccountAuthenticator {
                if (result != null) {
                if (result != null) {
                    response.onResult(result);
                    response.onResult(result);
                }
                }
            } catch (UnsupportedOperationException e) {
            } catch (Exception e) {
                response.onError(AccountManager.ERROR_CODE_UNSUPPORTED_OPERATION,
                handleException(response, "editProperties", accountType, e);
                        "editProperties not supported");
            }
            }
        }
        }


@@ -305,11 +257,8 @@ public abstract class AbstractAccountAuthenticator {
                if (result != null) {
                if (result != null) {
                    response.onResult(result);
                    response.onResult(result);
                }
                }
            } catch (UnsupportedOperationException e) {
            } catch (Exception e) {
                response.onError(AccountManager.ERROR_CODE_UNSUPPORTED_OPERATION,
                handleException(response, "hasFeatures", account.toString(), e);
                        "hasFeatures not supported");
            } catch (NetworkErrorException e) {
                response.onError(AccountManager.ERROR_CODE_NETWORK_ERROR, e.getMessage());
            }
            }
        }
        }


@@ -322,12 +271,35 @@ public abstract class AbstractAccountAuthenticator {
                if (result != null) {
                if (result != null) {
                    response.onResult(result);
                    response.onResult(result);
                }
                }
            } catch (UnsupportedOperationException e) {
            } catch (Exception e) {
                response.onError(AccountManager.ERROR_CODE_UNSUPPORTED_OPERATION,
                handleException(response, "getAccountRemovalAllowed", account.toString(), e);
                        "getAccountRemovalAllowed not supported");
            }
            } catch (NetworkErrorException e) {
        }
    }

    private void handleException(IAccountAuthenticatorResponse response, String method,
            String data, Exception e) throws RemoteException {
        if (e instanceof NetworkErrorException) {
            if (Log.isLoggable(TAG, Log.VERBOSE)) {
                Log.v(TAG, method + "(" + data + ")", e);
            }
            response.onError(AccountManager.ERROR_CODE_NETWORK_ERROR, e.getMessage());
            response.onError(AccountManager.ERROR_CODE_NETWORK_ERROR, e.getMessage());
        } else if (e instanceof UnsupportedOperationException) {
            if (Log.isLoggable(TAG, Log.VERBOSE)) {
                Log.v(TAG, method + "(" + data + ")", e);
            }
            }
            response.onError(AccountManager.ERROR_CODE_UNSUPPORTED_OPERATION,
                    method + " not supported");
        } else if (e instanceof IllegalArgumentException) {
            if (Log.isLoggable(TAG, Log.VERBOSE)) {
                Log.v(TAG, method + "(" + data + ")", e);
            }
            response.onError(AccountManager.ERROR_CODE_BAD_ARGUMENTS,
                    method + " not supported");
        } else {
            Log.w(TAG, method + "(" + data + ")", e);
            response.onError(AccountManager.ERROR_CODE_REMOTE_EXCEPTION,
                    method + " failed");
        }
        }
    }
    }