diff options
| author | 2021-07-21 18:24:28 +0100 | |
|---|---|---|
| committer | 2021-08-18 12:02:34 +0100 | |
| commit | 43d5b8b3f7c8da668f9e21d96c93f7e9dfba1b10 (patch) | |
| tree | f71675ff551067870c197f8311a3440511a98314 | |
| parent | efc036801c9538ce9e33bcc36248a0f419f1339d (diff) | |
Connect the new API from ApexService to ApexManager
Bug: 187444679
Test: atest ApexManagerTest
Change-Id: I60482a180d873a5f65887d0a5bb4230f75cb55df
Merged-In: I60482a180d873a5f65887d0a5bb4230f75cb55df
(cherry picked from commit 2bcdaf91d59cec2b007e211bd4e0107c7ec07147)
| -rw-r--r-- | services/core/java/com/android/server/pm/ApexManager.java | 26 | ||||
| -rw-r--r-- | services/tests/servicestests/src/com/android/server/pm/ApexManagerTest.java | 16 |
2 files changed, 42 insertions, 0 deletions
diff --git a/services/core/java/com/android/server/pm/ApexManager.java b/services/core/java/com/android/server/pm/ApexManager.java index 378405ffdb4a..f6f3db3d55a4 100644 --- a/services/core/java/com/android/server/pm/ApexManager.java +++ b/services/core/java/com/android/server/pm/ApexManager.java @@ -238,6 +238,14 @@ public abstract class ApexManager { throws PackageManagerException; /** + * Returns {@code ApeInfo} about apex sessions that have been marked ready via + * {@link #markStagedSessionReady(int)} + * + * Returns empty array if there is no staged apex session or if there is any error. + */ + abstract ApexInfo[] getStagedApexInfos(ApexSessionParams params); + + /** * Mark a staged session previously submitted using {@code submitStagedSession} as ready to be * applied at next reboot. * @@ -707,6 +715,19 @@ public abstract class ApexManager { } @Override + ApexInfo[] getStagedApexInfos(ApexSessionParams params) { + try { + return waitForApexService().getStagedApexInfos(params); + } catch (RemoteException re) { + Slog.w(TAG, "Unable to contact apexservice" + re.getMessage()); + throw new RuntimeException(re); + } catch (Exception e) { + Slog.w(TAG, "Failed to collect staged apex infos" + e.getMessage()); + return new ApexInfo[0]; + } + } + + @Override void markStagedSessionReady(int sessionId) throws PackageManagerException { try { waitForApexService().markStagedSessionReady(sessionId); @@ -1100,6 +1121,11 @@ public abstract class ApexManager { } @Override + ApexInfo[] getStagedApexInfos(ApexSessionParams params) { + throw new UnsupportedOperationException(); + } + + @Override void markStagedSessionReady(int sessionId) { throw new UnsupportedOperationException(); } diff --git a/services/tests/servicestests/src/com/android/server/pm/ApexManagerTest.java b/services/tests/servicestests/src/com/android/server/pm/ApexManagerTest.java index 72afca0300cd..b6f79221cead 100644 --- a/services/tests/servicestests/src/com/android/server/pm/ApexManagerTest.java +++ b/services/tests/servicestests/src/com/android/server/pm/ApexManagerTest.java @@ -37,6 +37,7 @@ import android.apex.IApexService; import android.content.Context; import android.content.pm.PackageInfo; import android.os.RemoteException; +import android.os.ServiceSpecificException; import android.platform.test.annotations.Presubmit; import androidx.test.filters.SmallTest; @@ -228,6 +229,21 @@ public class ApexManagerTest { } @Test + public void testGetStagedApexInfos_throwRunTimeException() throws RemoteException { + doThrow(RemoteException.class).when(mApexService).getStagedApexInfos(any()); + + assertThrows(RuntimeException.class, + () -> mApexManager.getStagedApexInfos(testParamsWithChildren())); + } + + @Test + public void testGetStagedApexInfos_returnsEmptyArrayOnError() throws RemoteException { + doThrow(ServiceSpecificException.class).when(mApexService).getStagedApexInfos(any()); + + assertThat(mApexManager.getStagedApexInfos(testParamsWithChildren())).hasLength(0); + } + + @Test public void testMarkStagedSessionReady_throwPackageManagerException() throws RemoteException { doAnswer(invocation -> { throw new Exception(); |