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

Commit 50b5bae5 authored by Manish Singh's avatar Manish Singh
Browse files

Don't send data for non-main users

This is a regression caused by ag/26661827

Fix: 333872544
Test: manual
Test: atest PrivateSpaceSafetySourceTest
Change-Id: I0465899af3745fa39eab8806dbceb347d70b0aa3
parent 30a03c4e
Loading
Loading
Loading
Loading
+7 −7
Original line number Diff line number Diff line
@@ -56,14 +56,14 @@ public final class PrivateSpaceSafetySource {
                Log.i(TAG, "Private Space not allowed for user " + context.getUser());
                return;
            }
        } else {
        }

        // Check the profile type - we don't want to show this for anything other than primary
        // user.
        if (userManager != null && !userManager.isMainUser()) {
            Log.i(TAG, "setSafetySourceData not main user");
            return;
        }
        }

        if (!Flags.allowPrivateProfile()
                || !android.multiuser.Flags.enablePrivateSpaceFeatures()) {
+20 −0
Original line number Diff line number Diff line
@@ -26,11 +26,13 @@ import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import android.content.Context;
import android.os.Flags;
import android.os.UserManager;
import android.platform.test.flag.junit.SetFlagsRule;
import android.safetycenter.SafetyEvent;
import android.safetycenter.SafetySourceData;
@@ -55,7 +57,9 @@ public class PrivateSpaceSafetySourceTest {
    private static final SafetyEvent EVENT_TYPE_DEVICE_REBOOTED =
            new SafetyEvent.Builder(SAFETY_EVENT_TYPE_DEVICE_REBOOTED).build();
    private Context mContext = ApplicationProvider.getApplicationContext();
    private Context mMockContext;
    @Mock private SafetyCenterManagerWrapper mSafetyCenterManagerWrapper;
    @Mock private UserManager mUserManager;
    @Rule public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();

    /** Required setup before a test. */
@@ -147,4 +151,20 @@ public class PrivateSpaceSafetySourceTest {
        assertThat(safetySourceStatus.getPendingIntent().getIntent().getIdentifier())
                .isEqualTo(SAFETY_SOURCE_ID);
    }

    /** Tests that setSafetySourceData sets the source status enabled. */
    @Test
    public void setSafetySourceData_whenNonMainUser_doesNotSendData() {
        mSetFlagsRule.enableFlags(Flags.FLAG_ALLOW_PRIVATE_PROFILE,
                android.multiuser.Flags.FLAG_ENABLE_PRIVATE_SPACE_FEATURES);
        mMockContext = spy(mContext);
        when(mSafetyCenterManagerWrapper.isEnabled(mMockContext)).thenReturn(true);
        when(mMockContext.getSystemService(UserManager.class)).thenReturn(mUserManager);
        when(mUserManager.isMainUser()).thenReturn(false);

        PrivateSpaceSafetySource.setSafetySourceData(mMockContext, EVENT_TYPE_DEVICE_REBOOTED);

        verify(mSafetyCenterManagerWrapper, never()).setSafetySourceData(
                any(), any(), any(), any());
    }
}