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

Commit 142a9859 authored by satayev's avatar satayev
Browse files

Only consider active apexes for apex-system-service list.

ApexManager parses all apexes, however, we want to report only active
apexes for apex-system-service.

Fix: 218978879
Test: atest ApexManagerTest#testGetApexSystemServices
Change-Id: I070d98fb2057be4f637a04b8001d25577766d9e1
parent 274ad40f
Loading
Loading
Loading
Loading
+14 −10
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@ 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;
import android.util.PrintWriterPrinter;
@@ -606,19 +607,22 @@ public abstract class ApexManager {
                            continue;
                        }

                        if (ai.isActive) {
                            String name = service.getName();
                        for (ApexSystemServiceInfo info : mApexSystemServices) {
                            for (int j = 0; j < mApexSystemServices.size(); j++) {
                                ApexSystemServiceInfo info = mApexSystemServices.get(j);
                                if (info.getName().equals(name)) {
                                throw new IllegalStateException(String.format(
                                        "Duplicate apex-system-service %s from %s, %s",
                                        name, info.mJarPath, service.getJarPath()));
                                    throw new IllegalStateException(TextUtils.formatSimple(
                                            "Duplicate apex-system-service %s from %s, %s", name,
                                            info.mJarPath, service.getJarPath()));
                                }
                            }

                            ApexSystemServiceInfo info = new ApexSystemServiceInfo(
                                service.getName(), service.getJarPath(), service.getInitOrder());
                                    service.getName(), service.getJarPath(),
                                    service.getInitOrder());
                            mApexSystemServices.add(info);
                        }
                    }
                    Collections.sort(mApexSystemServices);
                    mPackageNameToApexModuleName.put(packageInfo.packageName, ai.moduleName);
                    if (ai.isActive) {
+12 −4
Original line number Diff line number Diff line
@@ -132,7 +132,12 @@ public class ApexManagerTest {

    @Test
    public void testGetApexSystemServices() throws RemoteException {
        when(mApexService.getAllPackages()).thenReturn(createApexInfoForTestPkg(true, false));
        when(mApexService.getAllPackages()).thenReturn(new ApexInfo[] {
                createApexInfoForTestPkg(false, true, 1),
                // only active apex reports apex-system-service
                createApexInfoForTestPkg(true, false, 2),
        });

        mApexManager.scanApexPackagesTraced(mPackageParser2,
                ParallelPackageParser.makeExecutorService());

@@ -484,17 +489,20 @@ public class ApexManagerTest {
        assertThat(e).hasMessageThat().contains("Failed to collect certificates from ");
    }

    private ApexInfo[] createApexInfoForTestPkg(boolean isActive, boolean isFactory) {
    private ApexInfo createApexInfoForTestPkg(boolean isActive, boolean isFactory, int version) {
        File apexFile = extractResource(TEST_APEX_PKG,  TEST_APEX_FILE_NAME);
        ApexInfo apexInfo = new ApexInfo();
        apexInfo.isActive = isActive;
        apexInfo.isFactory = isFactory;
        apexInfo.moduleName = TEST_APEX_PKG;
        apexInfo.modulePath = apexFile.getPath();
        apexInfo.versionCode = 191000070;
        apexInfo.versionCode = version;
        apexInfo.preinstalledModulePath = apexFile.getPath();
        return apexInfo;
    }

        return new ApexInfo[]{apexInfo};
    private ApexInfo[] createApexInfoForTestPkg(boolean isActive, boolean isFactory) {
        return new ApexInfo[]{createApexInfoForTestPkg(isActive, isFactory, 191000070)};
    }

    private ApexInfo createApexInfo(String moduleName, int versionCode, boolean isActive,