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

Commit 5557dd75 authored by Jooyung Han's avatar Jooyung Han
Browse files

Handle apexd failures

Rethrowing RemoteException causes PackageManager crash. This happens
when a device shutting down (init kills apexd while it's being used by
PM).

Instead, apexd logs an error and returns a reasonable default value
(null or empty), except wrapping it in a PackageManagerException in a
few methods, which is handled by PM.

Bug: 370264486
Change-Id: Ie8aed22f16599f7e1769df2abd4a1e13013d9105
Test: ApexManagerTest
parent cce927d5
Loading
Loading
Loading
Loading
+9 −5
Original line number Diff line number Diff line
@@ -592,7 +592,7 @@ public abstract class ApexManager {
                return apexSessionInfo;
            } catch (RemoteException re) {
                Slog.e(TAG, "Unable to contact apexservice", re);
                throw new RuntimeException(re);
                return null;
            }
        }

@@ -607,7 +607,7 @@ public abstract class ApexManager {
                return result;
            } catch (RemoteException re) {
                Slog.e(TAG, "Unable to contact apexservice", re);
                throw new RuntimeException(re);
                return new SparseArray<>(0);
            }
        }

@@ -619,7 +619,9 @@ public abstract class ApexManager {
                return apexInfoList;
            } catch (RemoteException re) {
                Slog.e(TAG, "Unable to contact apexservice", re);
                throw new RuntimeException(re);
                throw new PackageManagerException(
                        PackageManager.INSTALL_FAILED_VERIFICATION_FAILURE,
                        "apexd verification failed : " + re.getMessage());
            } catch (Exception e) {
                throw new PackageManagerException(
                        PackageManager.INSTALL_FAILED_VERIFICATION_FAILURE,
@@ -633,7 +635,7 @@ public abstract class ApexManager {
                return waitForApexService().getStagedApexInfos(params);
            } catch (RemoteException re) {
                Slog.w(TAG, "Unable to contact apexservice" + re.getMessage());
                throw new RuntimeException(re);
                return new ApexInfo[0];
            } catch (Exception e) {
                Slog.w(TAG, "Failed to collect staged apex infos" + e.getMessage());
                return new ApexInfo[0];
@@ -646,7 +648,9 @@ public abstract class ApexManager {
                waitForApexService().markStagedSessionReady(sessionId);
            } catch (RemoteException re) {
                Slog.e(TAG, "Unable to contact apexservice", re);
                throw new RuntimeException(re);
                throw new PackageManagerException(
                        PackageManager.INSTALL_FAILED_VERIFICATION_FAILURE,
                        "Failed to mark apexd session as ready : " + re.getMessage());
            } catch (Exception e) {
                throw new PackageManagerException(
                        PackageManager.INSTALL_FAILED_VERIFICATION_FAILURE,
+8 −7
Original line number Diff line number Diff line
@@ -265,19 +265,19 @@ public class ApexManagerTest {
    }

    @Test
    public void testSubmitStagedSession_throwRunTimeException() throws RemoteException {
    public void testSubmitStagedSession_throwPackageManagerExceptionOnRemoteException()
             throws RemoteException {
        doThrow(RemoteException.class).when(mApexService).submitStagedSession(any(), any());

        assertThrows(RuntimeException.class,
        assertThrows(PackageManagerException.class,
                () -> mApexManager.submitStagedSession(testParamsWithChildren()));
    }

    @Test
    public void testGetStagedApexInfos_throwRunTimeException() throws RemoteException {
    public void testGetStagedApexInfos_returnsEmptyOnRemoteException() throws RemoteException {
        doThrow(RemoteException.class).when(mApexService).getStagedApexInfos(any());

        assertThrows(RuntimeException.class,
                () -> mApexManager.getStagedApexInfos(testParamsWithChildren()));
        assertThat(mApexManager.getStagedApexInfos(testParamsWithChildren())).hasLength(0);
    }

    @Test
@@ -298,10 +298,11 @@ public class ApexManagerTest {
    }

    @Test
    public void testMarkStagedSessionReady_throwRunTimeException() throws RemoteException {
    public void testMarkStagedSessionReady_throwPackageManagerExceptionOnRemoteException()
            throws RemoteException {
        doThrow(RemoteException.class).when(mApexService).markStagedSessionReady(anyInt());

        assertThrows(RuntimeException.class,
        assertThrows(PackageManagerException.class,
                () -> mApexManager.markStagedSessionReady(TEST_SESSION_ID));
    }