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

Commit 86943a3d authored by Tianjie's avatar Tianjie
Browse files

Don't throw runtime exceptions in ResumeOnRebootServiceProvider

In the current code, these IllegalStateExceptions from
the ResumeOnRebootService will crash the system server. Since RoR
failures are not fatal, rethrow the runtime exceptions as
RemoteExceptions instead.

Bug: 172780686
Test: atest FrameworksServicesTests:RebootEscrowManagerTests
Change-Id: I3a9d78fc75212b0ea85d5be8e431b946abb1b4cc
parent 1d0752ee
Loading
Loading
Loading
Loading
+8 −10
Original line number Original line Diff line number Diff line
@@ -136,7 +136,7 @@ public class ResumeOnRebootServiceProvider {
        }
        }


        /** Bind to the service */
        /** Bind to the service */
        public void bindToService(long timeOut) throws TimeoutException {
        public void bindToService(long timeOut) throws RemoteException, TimeoutException {
            if (mBinder == null || !mBinder.asBinder().isBinderAlive()) {
            if (mBinder == null || !mBinder.asBinder().isBinderAlive()) {
                CountDownLatch connectionLatch = new CountDownLatch(1);
                CountDownLatch connectionLatch = new CountDownLatch(1);
                Intent intent = new Intent();
                Intent intent = new Intent();
@@ -210,27 +210,25 @@ public class ResumeOnRebootServiceProvider {


        private void throwTypedException(
        private void throwTypedException(
                ParcelableException exception)
                ParcelableException exception)
                throws IOException {
                throws IOException, RemoteException {
            if (exception.getCause() instanceof IOException) {
            if (exception != null && exception.getCause() instanceof IOException) {
                exception.maybeRethrow(IOException.class);
                exception.maybeRethrow(IOException.class);
            } else if (exception.getCause() instanceof IllegalStateException) {
                exception.maybeRethrow(IllegalStateException.class);
            } else {
            } else {
                // This should not happen. Wrap the cause in IllegalStateException so that it
                // Wrap the exception and throw it as a RemoteException.
                // doesn't disrupt the exception handling
                throw new RemoteException(TAG + " wrap/unwrap failed", exception,
                throw new IllegalStateException(exception.getCause());
                        true /* enableSuppression */, true /* writableStackTrace */);
            }
            }
        }
        }


        private void waitForLatch(CountDownLatch latch, String reason, long timeOut)
        private void waitForLatch(CountDownLatch latch, String reason, long timeOut)
                throws TimeoutException {
                throws RemoteException, TimeoutException {
            try {
            try {
                if (!latch.await(timeOut, TimeUnit.SECONDS)) {
                if (!latch.await(timeOut, TimeUnit.SECONDS)) {
                    throw new TimeoutException("Latch wait for " + reason + " elapsed");
                    throw new TimeoutException("Latch wait for " + reason + " elapsed");
                }
                }
            } catch (InterruptedException e) {
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
                Thread.currentThread().interrupt();
                throw new IllegalStateException("Latch wait for " + reason + " interrupted");
                throw new RemoteException("Latch wait for " + reason + " interrupted");
            }
            }
        }
        }
    }
    }