Remove ApexManagerFlattenedApex

"Flattened APEXes" are no longer supported.

Bug: 278826656
Test: atest ApexManagerTest
Change-Id: Id565986ab3e6a7114cbc4839f040243fccd3df40
This commit is contained in:
Jooyung Han
2023-07-07 10:42:31 +09:00
parent f9c1b071c8
commit 6e68a96c10
2 changed files with 2 additions and 217 deletions

View File

@@ -35,7 +35,6 @@ import android.os.Environment;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.Trace;
import android.sysprop.ApexProperties;
import android.text.TextUtils;
import android.util.ArrayMap;
import android.util.ArraySet;
@@ -82,18 +81,12 @@ public abstract class ApexManager {
new Singleton<ApexManager>() {
@Override
protected ApexManager create() {
if (ApexProperties.updatable().orElse(false)) {
return new ApexManagerImpl();
} else {
return new ApexManagerFlattenedApex();
}
return new ApexManagerImpl();
}
};
/**
* Returns an instance of either {@link ApexManagerImpl} or {@link ApexManagerFlattenedApex}
* depending on whether this device supports APEX, i.e. {@link ApexProperties#updatable()}
* evaluates to {@code true}.
* Returns an instance of {@link ApexManagerImpl}
* @hide
*/
public static ApexManager getInstance() {
@@ -991,203 +984,4 @@ public abstract class ApexManager {
}
}
}
/**
* An implementation of {@link ApexManager} that should be used in case device does not support
* updating APEX packages.
*/
@VisibleForTesting
static final class ApexManagerFlattenedApex extends ApexManager {
@Override
ApexInfo[] getAllApexInfos() {
return null;
}
@Override
void notifyScanResult(List<ScanResult> scanResults) {
// No-op
}
@Override
public List<ActiveApexInfo> getActiveApexInfos() {
// There is no apexd running in case of flattened apex
// We look up the /apex directory and identify the active APEX modules from there.
// As "preinstalled" path, we just report /system since in the case of flattened APEX
// the /apex directory is just a symlink to /system/apex.
List<ActiveApexInfo> result = new ArrayList<>();
File apexDir = Environment.getApexDirectory();
if (apexDir.isDirectory()) {
File[] files = apexDir.listFiles();
// listFiles might be null if system server doesn't have permission to read
// a directory.
if (files != null) {
for (File file : files) {
if (file.isDirectory() && !file.getName().contains("@")
// In flattened configuration, init special-cases the art directory
// and bind-mounts com.android.art.debug to com.android.art.
&& !file.getName().equals("com.android.art.debug")) {
result.add(
new ActiveApexInfo(file, Environment.getRootDirectory(), file));
}
}
}
}
return result;
}
@Override
@Nullable
public String getActiveApexPackageNameContainingPackage(
@NonNull String containedPackageName) {
Objects.requireNonNull(containedPackageName);
return null;
}
@Override
ApexSessionInfo getStagedSessionInfo(int sessionId) {
throw new UnsupportedOperationException();
}
@Override
SparseArray<ApexSessionInfo> getSessions() {
return new SparseArray<>(0);
}
@Override
ApexInfoList submitStagedSession(ApexSessionParams params)
throws PackageManagerException {
throw new PackageManagerException(PackageManager.INSTALL_FAILED_INTERNAL_ERROR,
"Device doesn't support updating APEX");
}
@Override
ApexInfo[] getStagedApexInfos(ApexSessionParams params) {
throw new UnsupportedOperationException();
}
@Override
void markStagedSessionReady(int sessionId) {
throw new UnsupportedOperationException();
}
@Override
void markStagedSessionSuccessful(int sessionId) {
throw new UnsupportedOperationException();
}
@Override
boolean isApexSupported() {
return false;
}
@Override
boolean revertActiveSessions() {
throw new UnsupportedOperationException();
}
@Override
boolean abortStagedSession(int sessionId) {
throw new UnsupportedOperationException();
}
@Override
boolean uninstallApex(String apexPackagePath) {
throw new UnsupportedOperationException();
}
@Override
void registerApkInApex(AndroidPackage pkg) {
// No-op
}
@Override
void reportErrorWithApkInApex(String scanDirPath, String errorMsg) {
// No-op
}
@Override
@Nullable
String getApkInApexInstallError(String apexPackageName) {
return null;
}
@Override
List<String> getApksInApex(String apexPackageName) {
return Collections.emptyList();
}
@Override
@Nullable
public String getApexModuleNameForPackageName(String apexPackageName) {
return null;
}
@Override
@Nullable
public String getActivePackageNameForApexModuleName(String apexModuleName) {
return null;
}
@Override
public boolean snapshotCeData(int userId, int rollbackId, String apexPackageName) {
throw new UnsupportedOperationException();
}
@Override
public boolean restoreCeData(int userId, int rollbackId, String apexPackageName) {
throw new UnsupportedOperationException();
}
@Override
public boolean destroyDeSnapshots(int rollbackId) {
throw new UnsupportedOperationException();
}
@Override
public boolean destroyCeSnapshots(int userId, int rollbackId) {
return true;
}
@Override
public boolean destroyCeSnapshotsNotSpecified(int userId, int[] retainRollbackIds) {
return true;
}
@Override
public void markBootCompleted() {
// No-op
}
@Override
public long calculateSizeForCompressedApex(CompressedApexInfoList infoList) {
throw new UnsupportedOperationException();
}
@Override
public void reserveSpaceForCompressedApex(CompressedApexInfoList infoList) {
throw new UnsupportedOperationException();
}
@Override
ApexInfo installPackage(File apexFile) {
throw new UnsupportedOperationException("APEX updates are not supported");
}
@Override
public List<ApexSystemServiceInfo> getApexSystemServices() {
// TODO(satayev): we can't really support flattened apex use case, and need to migrate
// the manifest entries into system's manifest asap.
return Collections.emptyList();
}
@Override
void dump(PrintWriter pw) {
}
@Override
public File getBackingApexFile(File file) {
return null;
}
}
}

View File

@@ -473,15 +473,6 @@ public class ApexManagerTest {
assertThat(mApexManager.getBackingApexFile(new File("/apex//"))).isNull();
}
@Test
public void testGetBackingApexFiles_flattenedApex() {
ApexManager flattenedApexManager = new ApexManager.ApexManagerFlattenedApex();
final File backingApexFile = flattenedApexManager.getBackingApexFile(
new File(mMockSystem.system().getApexDirectory(),
"com.android.apex.cts.shim/app/CtsShim/CtsShim.apk"));
assertThat(backingApexFile).isNull();
}
@Test
public void testActiveApexChanged() throws RemoteException {
ApexInfo apex1 = createApexInfo(