Connect the new API from ApexService to ApexManager am: 3d8b82ca08 am: a2a902f58d

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/15624279

Change-Id: I2dbd1899b5c25219c7b357295a07fc28aa57c684
This commit is contained in:
Samiul Islam
2021-08-26 22:56:58 +00:00
committed by Automerger Merge Worker
2 changed files with 42 additions and 0 deletions

View File

@@ -248,6 +248,14 @@ public abstract class ApexManager {
abstract ApexInfoList submitStagedSession(ApexSessionParams params)
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.
@@ -756,6 +764,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 {
@@ -1246,6 +1267,11 @@ public abstract class ApexManager {
"Device doesn't support updating APEX");
}
@Override
ApexInfo[] getStagedApexInfos(ApexSessionParams params) {
throw new UnsupportedOperationException();
}
@Override
void markStagedSessionReady(int sessionId) {
throw new UnsupportedOperationException();

View File

@@ -40,6 +40,7 @@ import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.os.RemoteException;
import android.os.ServiceSpecificException;
import android.platform.test.annotations.Presubmit;
import androidx.test.filters.SmallTest;
@@ -231,6 +232,21 @@ public class ApexManagerTest {
() -> mApexManager.submitStagedSession(testParamsWithChildren()));
}
@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 -> {