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

Commit d0f5ee6c authored by Po-Chien Hsueh's avatar Po-Chien Hsueh Committed by Android (Google) Code Review
Browse files

Merge "Pass exception detail to API user"

parents 2f662e64 a5bd084a
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -5668,7 +5668,7 @@ package android.os.image {
  }
  public static interface DynamicSystemClient.OnStatusChangedListener {
    method public void onStatusChanged(int, int, long);
    method public void onStatusChanged(int, int, long, @Nullable Throwable);
  }
}
+19 −5
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ import android.annotation.BytesLong;
import android.annotation.CallbackExecutor;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.RequiresPermission;
import android.annotation.SystemApi;
import android.content.ComponentName;
@@ -31,6 +32,7 @@ import android.os.IBinder;
import android.os.Looper;
import android.os.Message;
import android.os.Messenger;
import android.os.ParcelableException;
import android.os.RemoteException;
import android.util.Slog;

@@ -100,9 +102,10 @@ public class DynamicSystemClient {
         * @param status status code, also defined in {@code DynamicSystemClient}.
         * @param cause cause code, also defined in {@code DynamicSystemClient}.
         * @param progress number of bytes installed.
         * @param detail additional detail about the error if available, otherwise null.
         */
        void onStatusChanged(@InstallationStatus int status, @StatusChangedCause int cause,
                @BytesLong long progress);
                @BytesLong long progress, @Nullable Throwable detail);
    }

    /*
@@ -177,6 +180,12 @@ public class DynamicSystemClient {
     */
    public static final String KEY_INSTALLED_SIZE = "KEY_INSTALLED_SIZE";

    /**
     * Message key, used when the service is sending exception detail to the client.
     * @hide
     */
    public static final String KEY_EXCEPTION_DETAIL = "KEY_EXCEPTION_DETAIL";

    /*
     * Intent Actions
     */
@@ -248,7 +257,7 @@ public class DynamicSystemClient {
            } catch (RemoteException e) {
                Slog.e(TAG, "Unable to get status from installation service");
                mExecutor.execute(() -> {
                    mListener.onStatusChanged(STATUS_UNKNOWN, CAUSE_ERROR_IPC, 0);
                    mListener.onStatusChanged(STATUS_UNKNOWN, CAUSE_ERROR_IPC, 0, e);
                });
            }
        }
@@ -396,14 +405,19 @@ public class DynamicSystemClient {
                int status = msg.arg1;
                int cause = msg.arg2;
                // obj is non-null
                long progress = ((Bundle) msg.obj).getLong(KEY_INSTALLED_SIZE);
                Bundle bundle = (Bundle) msg.obj;
                long progress = bundle.getLong(KEY_INSTALLED_SIZE);
                ParcelableException t = (ParcelableException) bundle.getSerializable(
                        KEY_EXCEPTION_DETAIL);

                Throwable detail = t == null ? null : t.getCause();

                if (mExecutor != null) {
                    mExecutor.execute(() -> {
                        mListener.onStatusChanged(status, cause, progress);
                        mListener.onStatusChanged(status, cause, progress, detail);
                    });
                } else {
                    mListener.onStatusChanged(status, cause, progress);
                    mListener.onStatusChanged(status, cause, progress, detail);
                }
                break;
            default:
+19 −12
Original line number Diff line number Diff line
@@ -49,6 +49,7 @@ import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import android.os.Messenger;
import android.os.ParcelableException;
import android.os.PowerManager;
import android.os.RemoteException;
import android.os.image.DynamicSystemClient;
@@ -170,13 +171,13 @@ public class DynamicSystemInstallationService extends Service
    @Override
    public void onProgressUpdate(long installedSize) {
        mInstalledSize = installedSize;
        postStatus(STATUS_IN_PROGRESS, CAUSE_NOT_SPECIFIED);
        postStatus(STATUS_IN_PROGRESS, CAUSE_NOT_SPECIFIED, null);
    }

    @Override
    public void onResult(int result) {
    public void onResult(int result, Throwable detail) {
        if (result == RESULT_OK) {
            postStatus(STATUS_READY, CAUSE_INSTALL_COMPLETED);
            postStatus(STATUS_READY, CAUSE_INSTALL_COMPLETED, null);
            return;
        }

@@ -185,15 +186,15 @@ public class DynamicSystemInstallationService extends Service

        switch (result) {
            case RESULT_ERROR_IO:
                postStatus(STATUS_NOT_STARTED, CAUSE_ERROR_IO);
                postStatus(STATUS_NOT_STARTED, CAUSE_ERROR_IO, detail);
                break;

            case RESULT_ERROR_INVALID_URL:
                postStatus(STATUS_NOT_STARTED, CAUSE_ERROR_INVALID_URL);
                postStatus(STATUS_NOT_STARTED, CAUSE_ERROR_INVALID_URL, detail);
                break;

            case RESULT_ERROR_EXCEPTION:
                postStatus(STATUS_NOT_STARTED, CAUSE_ERROR_EXCEPTION);
                postStatus(STATUS_NOT_STARTED, CAUSE_ERROR_EXCEPTION, detail);
                break;
        }
    }
@@ -201,7 +202,7 @@ public class DynamicSystemInstallationService extends Service
    @Override
    public void onCancelled() {
        resetTaskAndStop();
        postStatus(STATUS_NOT_STARTED, CAUSE_INSTALL_CANCELLED);
        postStatus(STATUS_NOT_STARTED, CAUSE_INSTALL_CANCELLED, null);
    }

    private void executeInstallCommand(Intent intent) {
@@ -266,7 +267,7 @@ public class DynamicSystemInstallationService extends Service
                Toast.LENGTH_LONG).show();

        resetTaskAndStop();
        postStatus(STATUS_NOT_STARTED, CAUSE_INSTALL_CANCELLED);
        postStatus(STATUS_NOT_STARTED, CAUSE_INSTALL_CANCELLED, null);

        mDynSystem.remove();
    }
@@ -414,7 +415,7 @@ public class DynamicSystemInstallationService extends Service
        return VerificationActivity.isVerified(url);
    }

    private void postStatus(int status, int cause) {
    private void postStatus(int status, int cause, Throwable detail) {
        Log.d(TAG, "postStatus(): statusCode=" + status + ", causeCode=" + cause);

        boolean notifyOnNotificationBar = true;
@@ -433,18 +434,24 @@ public class DynamicSystemInstallationService extends Service

        for (int i = mClients.size() - 1; i >= 0; i--) {
            try {
                notifyOneClient(mClients.get(i), status, cause);
                notifyOneClient(mClients.get(i), status, cause, detail);
            } catch (RemoteException e) {
                mClients.remove(i);
            }
        }
    }

    private void notifyOneClient(Messenger client, int status, int cause) throws RemoteException {
    private void notifyOneClient(Messenger client, int status, int cause, Throwable detail)
            throws RemoteException {
        Bundle bundle = new Bundle();

        bundle.putLong(DynamicSystemClient.KEY_INSTALLED_SIZE, mInstalledSize);

        if (detail != null) {
            bundle.putSerializable(DynamicSystemClient.KEY_EXCEPTION_DETAIL,
                    new ParcelableException(detail));
        }

        client.send(Message.obtain(null,
                  DynamicSystemClient.MSG_POST_STATUS, status, cause, bundle));
    }
@@ -496,7 +503,7 @@ public class DynamicSystemInstallationService extends Service
                    int status = getStatus();

                    // tell just registered client my status, but do not specify cause
                    notifyOneClient(client, status, CAUSE_NOT_SPECIFIED);
                    notifyOneClient(client, status, CAUSE_NOT_SPECIFIED, null);

                    mClients.add(client);
                } catch (RemoteException e) {
+19 −26
Original line number Diff line number Diff line
@@ -31,7 +31,7 @@ import java.util.Locale;
import java.util.zip.GZIPInputStream;


class InstallationAsyncTask extends AsyncTask<String, Long, Integer> {
class InstallationAsyncTask extends AsyncTask<String, Long, Throwable> {

    private static final String TAG = "InstallationAsyncTask";

@@ -43,7 +43,6 @@ class InstallationAsyncTask extends AsyncTask<String, Long, Integer> {
        }
    }


    /** Not completed, including being cancelled */
    static final int NO_RESULT = 0;
    static final int RESULT_OK = 1;
@@ -53,7 +52,7 @@ class InstallationAsyncTask extends AsyncTask<String, Long, Integer> {

    interface InstallStatusListener {
        void onProgressUpdate(long installedSize);
        void onResult(int resultCode);
        void onResult(int resultCode, Throwable detail);
        void onCancelled();
    }

@@ -84,7 +83,7 @@ class InstallationAsyncTask extends AsyncTask<String, Long, Integer> {
    }

    @Override
    protected Integer doInBackground(String... voids) {
    protected Throwable doInBackground(String... voids) {
        Log.d(TAG, "Start doInBackground(), URL: " + mUrl);

        try {
@@ -108,7 +107,7 @@ class InstallationAsyncTask extends AsyncTask<String, Long, Integer> {
                if (isCancelled()) {
                    boolean aborted = mDynSystem.abort();
                    Log.d(TAG, "Called DynamicSystemManager.abort(), result = " + aborted);
                    return RESULT_OK;
                    return null;
                }

                GsiProgress progress = mDynSystem.getInstallationProgress();
@@ -124,10 +123,8 @@ class InstallationAsyncTask extends AsyncTask<String, Long, Integer> {


            if (mInstallationSession == null) {
                Log.e(TAG, "Failed to start installation with requested size: "
                throw new IOException("Failed to start installation with requested size: "
                        + (mSystemSize + mUserdataSize));

                return RESULT_ERROR_IO;
            }

            installedSize = mUserdataSize;
@@ -157,20 +154,11 @@ class InstallationAsyncTask extends AsyncTask<String, Long, Integer> {
                }
            }

            return RESULT_OK;

        } catch (IOException e) {
            e.printStackTrace();
            return RESULT_ERROR_IO;

        } catch (InvalidImageUrlException e) {
            e.printStackTrace();
            return RESULT_ERROR_INVALID_URL;
            return null;

        } catch (Exception e) {
            e.printStackTrace();
            return RESULT_ERROR_EXCEPTION;

            return e;
        } finally {
            close();
        }
@@ -180,19 +168,24 @@ class InstallationAsyncTask extends AsyncTask<String, Long, Integer> {
    protected void onCancelled() {
        Log.d(TAG, "onCancelled(), URL: " + mUrl);

        close();

        mListener.onCancelled();
    }

    @Override
    protected void onPostExecute(Integer result) {
        Log.d(TAG, "onPostExecute(), URL: " + mUrl + ", result: " + result);
    protected void onPostExecute(Throwable detail) {
        if (detail == null) {
            mResult = RESULT_OK;
        } else if (detail instanceof IOException) {
            mResult = RESULT_ERROR_IO;
        } else if (detail instanceof InvalidImageUrlException) {
            mResult = RESULT_ERROR_INVALID_URL;
        } else {
            mResult = RESULT_ERROR_EXCEPTION;
        }

        close();
        Log.d(TAG, "onPostExecute(), URL: " + mUrl + ", result: " + mResult);

        mResult = result;
        mListener.onResult(mResult);
        mListener.onResult(mResult, detail);
    }

    @Override