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

Commit 8448c33e authored by Ryan Mitchell's avatar Ryan Mitchell
Browse files

Revert "OMS: replace OMSImpl.OverlayChangeListener with return v..."

Revert submission 1507500-oms-transactional-api

Reason for revert: b/177065099
Reverted Changes:
Ie5344c53d:OMS: add tests for the OMS transactional API
I8f54e1532:Push OverlayDeviceTests onto /system
I63df58510:OMS: add transactional API
Idacc0c67e:OverlayDeviceTests: add missing TEST_MAPPING
I2452f789a:OMS: block until settings are persisted
If58d5e9dd:OMS: replace OMSImpl.OverlayChangeListener with re...

Change-Id: I9e7d79d767b2474ecea78907e98c86b244055bac
parent b8c651c9
Loading
Loading
Loading
Loading
+49 −119
Original line number Diff line number Diff line
@@ -29,8 +29,6 @@ import static android.os.Trace.TRACE_TAG_RRO;
import static android.os.Trace.traceBegin;
import static android.os.Trace.traceEnd;

import static com.android.server.om.OverlayManagerServiceImpl.OperationFailedException;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.ActivityManager;
@@ -90,7 +88,6 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Consumer;

/**
 * Service to manage asset overlays.
@@ -241,10 +238,6 @@ public final class OverlayManagerService extends SystemService {

    private final AtomicBoolean mPersistSettingsScheduled = new AtomicBoolean(false);

    private final Consumer<PackageAndUser> mOnOverlaysChanged = (pair) -> {
        onOverlaysChanged(pair.packageName, pair.userId);
    };

    public OverlayManagerService(@NonNull final Context context) {
        super(context);
        try {
@@ -256,7 +249,8 @@ public final class OverlayManagerService extends SystemService {
            IdmapManager im = new IdmapManager(IdmapDaemon.getInstance(), mPackageManager);
            mSettings = new OverlayManagerSettings();
            mImpl = new OverlayManagerServiceImpl(mPackageManager, im, mSettings,
                    OverlayConfig.getSystemInstance(), getDefaultOverlayPackages());
                    OverlayConfig.getSystemInstance(), getDefaultOverlayPackages(),
                    new OverlayChangeListener());
            mActorEnforcer = new OverlayActorEnforcer(mPackageManager);

            final IntentFilter packageFilter = new IntentFilter();
@@ -402,17 +396,10 @@ public final class OverlayManagerService extends SystemService {
                                false);
                        if (pi != null && !pi.applicationInfo.isInstantApp()) {
                            mPackageManager.cachePackageInfo(packageName, userId, pi);

                            try {
                            if (pi.isOverlayPackage()) {
                                    mImpl.onOverlayPackageAdded(packageName, userId)
                                        .ifPresent(mOnOverlaysChanged);
                                mImpl.onOverlayPackageAdded(packageName, userId);
                            } else {
                                    mImpl.onTargetPackageAdded(packageName, userId)
                                        .ifPresent(mOnOverlaysChanged);
                                }
                            } catch (OperationFailedException e) {
                                Slog.e(TAG, "onPackageAdded internal error", e);
                                mImpl.onTargetPackageAdded(packageName, userId);
                            }
                        }
                    }
@@ -432,17 +419,10 @@ public final class OverlayManagerService extends SystemService {
                                false);
                        if (pi != null && pi.applicationInfo.isInstantApp()) {
                            mPackageManager.cachePackageInfo(packageName, userId, pi);

                            try {
                            if (pi.isOverlayPackage()) {
                                    mImpl.onOverlayPackageChanged(packageName, userId)
                                        .ifPresent(mOnOverlaysChanged);
                                mImpl.onOverlayPackageChanged(packageName, userId);
                            }  else {
                                    mImpl.onTargetPackageChanged(packageName, userId)
                                        .ifPresent(mOnOverlaysChanged);
                                }
                            } catch (OperationFailedException e) {
                                Slog.e(TAG, "onPackageChanged internal error", e);
                                mImpl.onTargetPackageChanged(packageName, userId);
                            }
                        }
                    }
@@ -461,12 +441,7 @@ public final class OverlayManagerService extends SystemService {
                        mPackageManager.forgetPackageInfo(packageName, userId);
                        final OverlayInfo oi = mImpl.getOverlayInfo(packageName, userId);
                        if (oi != null) {
                            try {
                                mImpl.onOverlayPackageReplacing(packageName, userId)
                                    .ifPresent(mOnOverlaysChanged);
                            } catch (OperationFailedException e) {
                                Slog.e(TAG, "onPackageReplacing internal error", e);
                            }
                            mImpl.onOverlayPackageReplacing(packageName, userId);
                        }
                    }
                }
@@ -485,16 +460,10 @@ public final class OverlayManagerService extends SystemService {
                                false);
                        if (pi != null && !pi.applicationInfo.isInstantApp()) {
                            mPackageManager.cachePackageInfo(packageName, userId, pi);
                            try {
                            if (pi.isOverlayPackage()) {
                                    mImpl.onOverlayPackageReplaced(packageName, userId)
                                        .ifPresent(mOnOverlaysChanged);
                                mImpl.onOverlayPackageReplaced(packageName, userId);
                            } else {
                                    mImpl.onTargetPackageReplaced(packageName, userId)
                                        .ifPresent(mOnOverlaysChanged);
                                }
                            } catch (OperationFailedException e) {
                                Slog.e(TAG, "onPackageReplaced internal error", e);
                                mImpl.onTargetPackageReplaced(packageName, userId);
                            }
                        }
                    }
@@ -512,17 +481,10 @@ public final class OverlayManagerService extends SystemService {
                    synchronized (mLock) {
                        mPackageManager.forgetPackageInfo(packageName, userId);
                        final OverlayInfo oi = mImpl.getOverlayInfo(packageName, userId);

                        try {
                        if (oi != null) {
                                mImpl.onOverlayPackageRemoved(packageName, userId)
                                    .ifPresent(mOnOverlaysChanged);
                            mImpl.onOverlayPackageRemoved(packageName, userId);
                        } else {
                                mImpl.onTargetPackageRemoved(packageName, userId)
                                    .ifPresent(mOnOverlaysChanged);
                            }
                        } catch (OperationFailedException e) {
                            Slog.e(TAG, "onPackageRemoved internal error", e);
                            mImpl.onTargetPackageRemoved(packageName, userId);
                        }
                    }
                }
@@ -640,13 +602,7 @@ public final class OverlayManagerService extends SystemService {
                final long ident = Binder.clearCallingIdentity();
                try {
                    synchronized (mLock) {
                        try {
                            mImpl.setEnabled(packageName, enable, realUserId)
                                .ifPresent(mOnOverlaysChanged);
                            return true;
                        } catch (OperationFailedException e) {
                            return false;
                        }
                        return mImpl.setEnabled(packageName, enable, realUserId);
                    }
                } finally {
                    Binder.restoreCallingIdentity(ident);
@@ -671,14 +627,8 @@ public final class OverlayManagerService extends SystemService {
                final long ident = Binder.clearCallingIdentity();
                try {
                    synchronized (mLock) {
                        try {
                            mImpl.setEnabledExclusive(packageName,
                                    false /* withinCategory */, realUserId)
                                .ifPresent(mOnOverlaysChanged);
                            return true;
                        } catch (OperationFailedException e) {
                            return false;
                        }
                        return mImpl.setEnabledExclusive(packageName, false /* withinCategory */,
                                realUserId);
                    }
                } finally {
                    Binder.restoreCallingIdentity(ident);
@@ -704,14 +654,8 @@ public final class OverlayManagerService extends SystemService {
                final long ident = Binder.clearCallingIdentity();
                try {
                    synchronized (mLock) {
                        try {
                            mImpl.setEnabledExclusive(packageName,
                                    true /* withinCategory */, realUserId)
                                .ifPresent(mOnOverlaysChanged);
                            return true;
                        } catch (OperationFailedException e) {
                            return false;
                        }
                        return mImpl.setEnabledExclusive(packageName, true /* withinCategory */,
                                realUserId);
                    }
                } finally {
                    Binder.restoreCallingIdentity(ident);
@@ -737,13 +681,7 @@ public final class OverlayManagerService extends SystemService {
                final long ident = Binder.clearCallingIdentity();
                try {
                    synchronized (mLock) {
                        try {
                            mImpl.setPriority(packageName, parentPackageName, realUserId)
                                .ifPresent(mOnOverlaysChanged);
                            return true;
                        } catch (OperationFailedException e) {
                            return false;
                        }
                        return mImpl.setPriority(packageName, parentPackageName, realUserId);
                    }
                } finally {
                    Binder.restoreCallingIdentity(ident);
@@ -767,13 +705,7 @@ public final class OverlayManagerService extends SystemService {
                final long ident = Binder.clearCallingIdentity();
                try {
                    synchronized (mLock) {
                        try {
                            mImpl.setHighestPriority(packageName, realUserId)
                                .ifPresent(mOnOverlaysChanged);
                            return true;
                        } catch (OperationFailedException e) {
                            return false;
                        }
                        return mImpl.setHighestPriority(packageName, realUserId);
                    }
                } finally {
                    Binder.restoreCallingIdentity(ident);
@@ -797,13 +729,7 @@ public final class OverlayManagerService extends SystemService {
                final long ident = Binder.clearCallingIdentity();
                try {
                    synchronized (mLock) {
                        try {
                            mImpl.setLowestPriority(packageName, realUserId)
                                .ifPresent(mOnOverlaysChanged);
                            return true;
                        } catch (OperationFailedException e) {
                            return false;
                        }
                        return mImpl.setLowestPriority(packageName, realUserId);
                    }
                } finally {
                    Binder.restoreCallingIdentity(ident);
@@ -972,7 +898,10 @@ public final class OverlayManagerService extends SystemService {
        }
    };

    private void onOverlaysChanged(@NonNull final String targetPackageName, final int userId) {
    private final class OverlayChangeListener
            implements OverlayManagerServiceImpl.OverlayChangeListener {
        @Override
        public void onOverlaysChanged(@NonNull final String targetPackageName, final int userId) {
            schedulePersistSettings();
            FgThread.getHandler().post(() -> {
                updateAssets(userId, targetPackageName);
@@ -986,14 +915,15 @@ public final class OverlayManagerService extends SystemService {
                }

                try {
                ActivityManager.getService().broadcastIntent(null, intent, null, null, 0,
                        null, null, null, android.app.AppOpsManager.OP_NONE, null, false, false,
                        userId);
                    ActivityManager.getService().broadcastIntentWithFeature(null, null, intent,
                            null, null, 0, null, null, null, android.app.AppOpsManager.OP_NONE,
                            null, false, false, userId);
                } catch (RemoteException e) {
                    // Intentionally left empty.
                }
            });
        }
    }

    /**
     * Updates the target packages' set of enabled overlays in PackageManager.
+74 −98

File changed.

Preview size limit exceeded, changes collapsed.

+0 −57
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.server.om;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.UserIdInt;

final class PackageAndUser {
    public final @NonNull String packageName;
    public final @UserIdInt int userId;

    PackageAndUser(@NonNull String packageName, @UserIdInt int userId) {
        this.packageName = packageName;
        this.userId = userId;
    }

    @Override
    public boolean equals(@Nullable Object obj) {
        if (this == obj) {
            return true;
        }
        if (!(obj instanceof PackageAndUser)) {
            return false;
        }
        PackageAndUser other = (PackageAndUser) obj;
        return packageName.equals(other.packageName) && userId == other.userId;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + packageName.hashCode();
        result = prime * result + userId;
        return result;
    }

    @Override
    public String toString() {
        return String.format("PackageAndUser{packageName=%s, userId=%d}", packageName, userId);
    }
}
+5 −5
Original line number Diff line number Diff line
@@ -78,7 +78,7 @@ public class OverlayManagerServiceImplRebootTests extends OverlayManagerServiceI
    }

    @Test
    public void testImmutableEnabledChange() throws Exception {
    public void testImmutableEnabledChange() {
        final OverlayManagerServiceImpl impl = getImpl();
        installNewPackage(target(TARGET), USER);
        installNewPackage(overlay(OVERLAY, TARGET), USER);
@@ -106,7 +106,7 @@ public class OverlayManagerServiceImplRebootTests extends OverlayManagerServiceI
    }

    @Test
    public void testMutableEnabledChangeHasNoEffect() throws Exception {
    public void testMutableEnabledChangeHasNoEffect() {
        final OverlayManagerServiceImpl impl = getImpl();
        installNewPackage(target(TARGET), USER);
        installNewPackage(overlay(OVERLAY, TARGET), USER);
@@ -134,7 +134,7 @@ public class OverlayManagerServiceImplRebootTests extends OverlayManagerServiceI
    }

    @Test
    public void testMutableEnabledToImmutableEnabled() throws Exception {
    public void testMutableEnabledToImmutableEnabled() {
        final OverlayManagerServiceImpl impl = getImpl();
        installNewPackage(target(TARGET), USER);
        installNewPackage(overlay(OVERLAY, TARGET), USER);
@@ -178,7 +178,7 @@ public class OverlayManagerServiceImplRebootTests extends OverlayManagerServiceI
    }

    @Test
    public void testMutablePriorityChange() throws Exception {
    public void testMutablePriorityChange() {
        final OverlayManagerServiceImpl impl = getImpl();
        installNewPackage(target(TARGET), USER);
        installNewPackage(overlay(OVERLAY, TARGET), USER);
@@ -218,7 +218,7 @@ public class OverlayManagerServiceImplRebootTests extends OverlayManagerServiceI
    }

    @Test
    public void testImmutablePriorityChange() throws Exception {
    public void testImmutablePriorityChange() {
        final OverlayManagerServiceImpl impl = getImpl();
        installNewPackage(target(TARGET), USER);
        installNewPackage(overlay(OVERLAY, TARGET), USER);
+39 −37
Original line number Diff line number Diff line
@@ -22,14 +22,11 @@ import static android.content.om.OverlayInfo.STATE_MISSING_TARGET;
import static android.os.OverlayablePolicy.CONFIG_SIGNATURE;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.testng.Assert.assertThrows;

import android.content.om.OverlayInfo;
import android.util.Pair;

import androidx.test.runner.AndroidJUnit4;

@@ -38,7 +35,6 @@ import org.junit.runner.RunWith;

import java.util.List;
import java.util.Map;
import java.util.Optional;

@RunWith(AndroidJUnit4.class)
public class OverlayManagerServiceImplTests extends OverlayManagerServiceImplTestsBase {
@@ -59,7 +55,7 @@ public class OverlayManagerServiceImplTests extends OverlayManagerServiceImplTes
    private static final String CERT_CONFIG_NOK = "config_certificate_nok";

    @Test
    public void testGetOverlayInfo() throws Exception {
    public void testGetOverlayInfo() {
        installNewPackage(overlay(OVERLAY, TARGET), USER);

        final OverlayManagerServiceImpl impl = getImpl();
@@ -71,7 +67,7 @@ public class OverlayManagerServiceImplTests extends OverlayManagerServiceImplTes
    }

    @Test
    public void testGetOverlayInfosForTarget() throws Exception {
    public void testGetOverlayInfosForTarget() {
        installNewPackage(overlay(OVERLAY, TARGET), USER);
        installNewPackage(overlay(OVERLAY2, TARGET), USER);
        installNewPackage(overlay(OVERLAY3, TARGET), USER2);
@@ -96,7 +92,7 @@ public class OverlayManagerServiceImplTests extends OverlayManagerServiceImplTes
    }

    @Test
    public void testGetOverlayInfosForUser() throws Exception {
    public void testGetOverlayInfosForUser() {
        installNewPackage(target(TARGET), USER);
        installNewPackage(overlay(OVERLAY, TARGET), USER);
        installNewPackage(overlay(OVERLAY2, TARGET), USER);
@@ -123,7 +119,7 @@ public class OverlayManagerServiceImplTests extends OverlayManagerServiceImplTes
    }

    @Test
    public void testPriority() throws Exception {
    public void testPriority() {
        installNewPackage(overlay(OVERLAY, TARGET), USER);
        installNewPackage(overlay(OVERLAY2, TARGET), USER);
        installNewPackage(overlay(OVERLAY3, TARGET), USER);
@@ -135,21 +131,18 @@ public class OverlayManagerServiceImplTests extends OverlayManagerServiceImplTes

        assertOverlayInfoForTarget(TARGET, USER, o1, o2, o3);

        assertEquals(impl.setLowestPriority(OVERLAY3, USER),
                Optional.of(new PackageAndUser(TARGET, USER)));
        assertTrue(impl.setLowestPriority(OVERLAY3, USER));
        assertOverlayInfoForTarget(TARGET, USER, o3, o1, o2);

        assertEquals(impl.setHighestPriority(OVERLAY3, USER),
                Optional.of(new PackageAndUser(TARGET, USER)));
        assertTrue(impl.setHighestPriority(OVERLAY3, USER));
        assertOverlayInfoForTarget(TARGET, USER, o1, o2, o3);

        assertEquals(impl.setPriority(OVERLAY, OVERLAY2, USER),
                Optional.of(new PackageAndUser(TARGET, USER)));
        assertTrue(impl.setPriority(OVERLAY, OVERLAY2, USER));
        assertOverlayInfoForTarget(TARGET, USER, o2, o1, o3);
    }

    @Test
    public void testOverlayInfoStateTransitions() throws Exception {
    public void testOverlayInfoStateTransitions() {
        final OverlayManagerServiceImpl impl = getImpl();
        assertNull(impl.getOverlayInfo(OVERLAY, USER));

@@ -160,8 +153,7 @@ public class OverlayManagerServiceImplTests extends OverlayManagerServiceImplTes
        installNewPackage(target, USER);
        assertState(STATE_DISABLED, OVERLAY, USER);

        assertEquals(impl.setEnabled(OVERLAY, true, USER),
                Optional.of(new PackageAndUser(TARGET, USER)));
        impl.setEnabled(OVERLAY, true, USER);
        assertState(STATE_ENABLED, OVERLAY, USER);

        // target upgrades do not change the state of the overlay
@@ -176,40 +168,50 @@ public class OverlayManagerServiceImplTests extends OverlayManagerServiceImplTes
    }

    @Test
    public void testOnOverlayPackageUpgraded() throws Exception {
    public void testOnOverlayPackageUpgraded() {
        final FakeListener listener = getListener();
        final FakeDeviceState.PackageBuilder target = target(TARGET);
        final FakeDeviceState.PackageBuilder overlay = overlay(OVERLAY, TARGET);
        installNewPackage(target, USER);
        installNewPackage(overlay, USER);
        listener.count = 0;
        upgradePackage(overlay, USER);
        assertEquals(2, listener.count);

        // upgrade to a version where the overlay has changed its target
        // expect once for the old target package, once for the new target package
        listener.count = 0;
        final FakeDeviceState.PackageBuilder overlay2 = overlay(OVERLAY, "some.other.target");
        final Pair<Optional<PackageAndUser>, Optional<PackageAndUser>> pair =
        upgradePackage(overlay2, USER);
        assertEquals(pair.first, Optional.of(new PackageAndUser(TARGET, USER)));
        assertEquals(pair.second, Optional.of(new PackageAndUser("some.other.target", USER)));
        assertEquals(3, listener.count);

        listener.count = 0;
        upgradePackage(overlay2, USER);
        assertEquals(2, listener.count);
    }

    @Test
    public void testSetEnabledAtVariousConditions() throws Exception {
    public void testListener() {
        final OverlayManagerServiceImpl impl = getImpl();
        assertThrows(OverlayManagerServiceImpl.OperationFailedException.class,
                () -> impl.setEnabled(OVERLAY, true, USER));
        final FakeListener listener = getListener();
        installNewPackage(overlay(OVERLAY, TARGET), USER);
        assertEquals(1, listener.count);
        listener.count = 0;

        // request succeeded, and there was a change that needs to be
        // propagated to the rest of the system
        installNewPackage(target(TARGET), USER);
        installNewPackage(overlay(OVERLAY, TARGET), USER);
        assertEquals(impl.setEnabled(OVERLAY, true, USER),
                Optional.of(new PackageAndUser(TARGET, USER)));
        assertEquals(1, listener.count);
        listener.count = 0;

        impl.setEnabled(OVERLAY, true, USER);
        assertEquals(1, listener.count);
        listener.count = 0;

        // request succeeded, but nothing changed
        assertFalse(impl.setEnabled(OVERLAY, true, USER).isPresent());
        impl.setEnabled(OVERLAY, true, USER);
        assertEquals(0, listener.count);
    }

    @Test
    public void testConfigSignaturePolicyOk() throws Exception {
    public void testConfigSignaturePolicyOk() {
        setConfigSignaturePackageName(CONFIG_SIGNATURE_REFERENCE_PKG);
        reinitializeImpl();

@@ -227,7 +229,7 @@ public class OverlayManagerServiceImplTests extends OverlayManagerServiceImplTes
    }

    @Test
    public void testConfigSignaturePolicyCertNok() throws Exception {
    public void testConfigSignaturePolicyCertNok() {
        setConfigSignaturePackageName(CONFIG_SIGNATURE_REFERENCE_PKG);
        reinitializeImpl();

@@ -245,7 +247,7 @@ public class OverlayManagerServiceImplTests extends OverlayManagerServiceImplTes
    }

    @Test
    public void testConfigSignaturePolicyNoConfig() throws Exception {
    public void testConfigSignaturePolicyNoConfig() {
        addPackage(target(CONFIG_SIGNATURE_REFERENCE_PKG).setCertificate(CERT_CONFIG_OK), USER);
        installNewPackage(target(TARGET), USER);
        installNewPackage(overlay(OVERLAY, TARGET).setCertificate(CERT_CONFIG_NOK), USER);
@@ -260,7 +262,7 @@ public class OverlayManagerServiceImplTests extends OverlayManagerServiceImplTes
    }

    @Test
    public void testConfigSignaturePolicyNoRefPkg() throws Exception {
    public void testConfigSignaturePolicyNoRefPkg() {
        installNewPackage(target(TARGET), USER);
        installNewPackage(overlay(OVERLAY, TARGET).setCertificate(CERT_CONFIG_NOK), USER);

@@ -274,7 +276,7 @@ public class OverlayManagerServiceImplTests extends OverlayManagerServiceImplTes
    }

    @Test
    public void testConfigSignaturePolicyRefPkgNotSystem() throws Exception {
    public void testConfigSignaturePolicyRefPkgNotSystem() {
        setConfigSignaturePackageName(CONFIG_SIGNATURE_REFERENCE_PKG);
        reinitializeImpl();

Loading