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
This commit is contained in:
@@ -56,13 +56,13 @@ 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;
|
||||
}
|
||||
}
|
||||
|
||||
// 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()
|
||||
|
@@ -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());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user