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

Commit d94bba29 authored by Brad Ebinger's avatar Brad Ebinger
Browse files

Fix Telecom Test breakage due to Bluetooth permission change

BT code changed permissions to use Context#checkSelfPermission,
which caused Telecom unit tests to fail in setup() phase. This
caused a cascading issue where Logging sessions would be setup
bug never ended, causing Session recursion tests to fail when
the logging sessions were never previously cleaned up.

1) Fixed permission check mocking in tests.
2) Put bound on recursion in Session#toString to ensure we
do not hit this scenario.

Fixes: 186694546
Fixes: 186708966
Test: atest TelecomUnitTests
Merged-In: Ibb4e2a86cccc50f23511f20c32b59af181301246
Change-Id: Ibb4e2a86cccc50f23511f20c32b59af181301246
parent 9ee28de2
Loading
Loading
Loading
Loading
+194 −188
Original line number Diff line number Diff line
@@ -217,6 +217,7 @@ public class TelecomSystem {
                defaultDialerAdapter, roleManagerAdapter, mLock);

        Log.startSession("TS.init");
        try {
            mPhoneAccountRegistrar = new PhoneAccountRegistrar(mContext, defaultDialerCache,
                    packageName -> AppLabelProxy.Util.getAppLabel(
                            mContext.getPackageManager(), packageName));
@@ -241,8 +242,8 @@ public class TelecomSystem {
            SystemStateHelper systemStateHelper = new SystemStateHelper(mContext);

            mMissedCallNotifier = missedCallNotifierImplFactory
                .makeMissedCallNotifierImpl(mContext, mPhoneAccountRegistrar, defaultDialerCache,
                        deviceIdleControllerAdapter);
                    .makeMissedCallNotifierImpl(mContext, mPhoneAccountRegistrar,
                            defaultDialerCache, deviceIdleControllerAdapter);
            DisconnectedCallNotifier.Factory disconnectedCallNotifierFactory =
                    new DisconnectedCallNotifier.Default();

@@ -304,8 +305,8 @@ public class TelecomSystem {
            ToastFactory toastFactory = new ToastFactory() {
                @Override
                public Toast makeText(Context context, int resId, int duration) {
                return Toast.makeText(context, context.getMainLooper(), context.getString(resId),
                        duration);
                    return Toast.makeText(context, context.getMainLooper(),
                            context.getString(resId), duration);
                }

                @Override
@@ -378,14 +379,16 @@ public class TelecomSystem {
            mContext.registerReceiverAsUser(mBootCompletedReceiver, UserHandle.ALL,
                    BOOT_COMPLETE_FILTER, null, null);

        // Set current user explicitly since USER_SWITCHED_FILTER intent can be missed at startup
            // Set current user explicitly since USER_SWITCHED_FILTER intent can be missed at
            // startup
            synchronized (mLock) {
                UserHandle currentUserHandle = UserHandle.of(ActivityManager.getCurrentUser());
                mPhoneAccountRegistrar.setCurrentUserHandle(currentUserHandle);
                mCallsManager.onUserSwitch(currentUserHandle);
            }

        mCallIntentProcessor = new CallIntentProcessor(mContext, mCallsManager, defaultDialerCache);
            mCallIntentProcessor = new CallIntentProcessor(mContext, mCallsManager,
                    defaultDialerCache);
            mTelecomBroadcastIntentProcessor = new TelecomBroadcastIntentProcessor(
                    mContext, mCallsManager);

@@ -401,7 +404,8 @@ public class TelecomSystem {
                    new CallIntentProcessor.AdapterImpl(defaultDialerCache),
                    new UserCallIntentProcessorFactory() {
                        @Override
                    public UserCallIntentProcessor create(Context context, UserHandle userHandle) {
                        public UserCallIntentProcessor create(Context context,
                                UserHandle userHandle) {
                            return new UserCallIntentProcessor(context, userHandle);
                        }
                    },
@@ -409,8 +413,10 @@ public class TelecomSystem {
                    new TelecomServiceImpl.SubscriptionManagerAdapterImpl(),
                    new TelecomServiceImpl.SettingsSecureAdapterImpl(),
                    mLock);
        } finally {
            Log.endSession();
        }
    }

    @VisibleForTesting
    public PhoneAccountRegistrar getPhoneAccountRegistrar() {
+5 −0
Original line number Diff line number Diff line
@@ -359,6 +359,11 @@ public class ComponentContextFixture implements TestFixture<Context> {
            return PackageManager.PERMISSION_GRANTED;
        }

        @Override
        public int checkSelfPermission(String permission) {
            return PackageManager.PERMISSION_GRANTED;
        }

        @Override
        public void enforceCallingOrSelfPermission(String permission, String message) {
            // Don't bother enforcing anything in mock.
+30 −0
Original line number Diff line number Diff line
@@ -172,6 +172,36 @@ public class SessionTest extends TelecomTestCase {
        }
    }

    /**
     * Ensure creating two sessions and setting the child as the parent to itself doesn't cause a
     * crash due to infinite recursion.
     */
    @SmallTest
    @Test
    public void testRecursion_toString_childCircDep() {
        Log.startSession("testParent");
        // Running in the same thread, so mark as invisible subsession
        Session childSession = Log.getSessionManager()
                .createSubsession(true /*isStartedFromActiveSession*/);
        Log.continueSession(childSession, "child");
        Session parentSession = childSession.getParentSession();
        // Create a circular dependency and ensure we do not crash
        childSession.setParentSession(childSession);

        // Make sure calling these methods does not result in a crash
        try {
            parentSession.toString();
            childSession.toString();
        } catch (Exception e) {
            fail("Exception: " + e.getMessage());
        } finally {
            // End child
            Log.endSession();
            // End parent
            Log.endSession();
        }
    }

    /**
     * Ensure creating two sessions that are parent/child of each other does not lead to a crash
     * or infinite recursion when using Session#getInfo.
+4 −6
Original line number Diff line number Diff line
@@ -365,7 +365,7 @@ public class TelecomSystemTest extends TelecomTestCase {

        // Next, create the TelecomSystem, our system under test
        setupTelecomSystem();
        // Need to reset teseting tag here
        // Need to reset testing tag here
        Log.setTag(TESTING_TAG);

        // Finally, register the ConnectionServices with the PhoneAccountRegistrar of the
@@ -401,11 +401,9 @@ public class TelecomSystemTest extends TelecomTestCase {
        mConnectionServiceFixtureA.waitForHandlerToClear();
        mConnectionServiceFixtureB.waitForHandlerToClear();

        // Print out any incomplete sessions for debugging tests
        String sessions = Log.getSessionManager().printActiveSessions();
        if (!TextUtils.isEmpty(sessions)) {
            Log.w(this, "Active Sessions:\n" + sessions);
        }
        // Forcefully clean all sessions at the end of the test, which will also log any stale
        // sessions for debugging.
        Log.getSessionManager().cleanupStaleSessions(0);

        mTelecomSystem = null;
        super.tearDown();