Add Private Space settings page
This involves: 1. Adding a new page for PS settings under Security & Privacy 2. Integrating the PS safety source with SafetyCenter. Also, add the capability to create and delete PS from the page. Creation is temporary to help with prototyping, and will be removed finally. Screenshots: Private Space Entry point in Security & Privacy Settings: https://screenshot.googleplex.com/4VHxNekjhxZHJwF Private Space Settings page: https://screenshot.googleplex.com/3Raw4wuymTHTgtM Creating Private Space: https://screenshot.googleplex.com/3dvzAH6V4kQmuYf Private Space created: https://screenshot.googleplex.com/Aj7nnF9uuUCa9Q5 Design doc: https://docs.google.com/document/d/1CdjUjAE84-5ZEPRIfw5KYFjLVHtEZxc_sF0w95su8DA/edit?usp=sharing&resourcekey=0-dAACT9HRexY1IyoxMmkVlw Bug: 286539356 Bug: 293569406 Test: manual Test: atest DeletePrivateSpaceControllerTest Test: atest UseOneLockControllerTest Test: atest HidePrivateSpaceControllerTest Change-Id: I9caf8e04e7fb2df36e60f607225e2931988ee692
This commit is contained in:
@@ -0,0 +1,143 @@
|
||||
/*
|
||||
* Copyright (C) 2023 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.settings.privatespace;
|
||||
|
||||
|
||||
import static android.safetycenter.SafetyEvent.SAFETY_EVENT_TYPE_DEVICE_REBOOTED;
|
||||
import static com.android.settings.privatespace.PrivateSpaceSafetySource.SAFETY_SOURCE_ID;
|
||||
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.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.safetycenter.SafetyEvent;
|
||||
import android.safetycenter.SafetySourceData;
|
||||
import android.safetycenter.SafetySourceStatus;
|
||||
import android.util.FeatureFlagUtils;
|
||||
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
import com.android.settings.safetycenter.SafetyCenterManagerWrapper;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
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();
|
||||
@Mock private SafetyCenterManagerWrapper mSafetyCenterManagerWrapper;
|
||||
|
||||
/** Required setup before a test. */
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
SafetyCenterManagerWrapper.sInstance = mSafetyCenterManagerWrapper;
|
||||
|
||||
FeatureFlagUtils
|
||||
.setEnabled(mContext, FeatureFlagUtils.SETTINGS_PRIVATE_SPACE_SETTINGS, true);
|
||||
}
|
||||
|
||||
/** Required setup after a test. */
|
||||
@After
|
||||
public void tearDown() {
|
||||
SafetyCenterManagerWrapper.sInstance = null;
|
||||
}
|
||||
|
||||
/** Tests that when SC is disabled we don't set any data. */
|
||||
@Test
|
||||
public void onDeviceRebootedEvent_whenSafetyCenterDisabled_doesNotSetData() {
|
||||
when(mSafetyCenterManagerWrapper.isEnabled(mContext)).thenReturn(false);
|
||||
|
||||
PrivateSpaceSafetySource.setSafetySourceData(mContext, EVENT_TYPE_DEVICE_REBOOTED);
|
||||
|
||||
verify(mSafetyCenterManagerWrapper, never()).setSafetySourceData(
|
||||
any(), any(), any(), any());
|
||||
}
|
||||
|
||||
/** Tests that when SC is enabled we set data. */
|
||||
@Test
|
||||
public void onDeviceRebootedEvent_whenSafetyCenterEnabled_setsData() {
|
||||
when(mSafetyCenterManagerWrapper.isEnabled(mContext)).thenReturn(true);
|
||||
|
||||
PrivateSpaceSafetySource.setSafetySourceData(mContext, EVENT_TYPE_DEVICE_REBOOTED);
|
||||
|
||||
verify(mSafetyCenterManagerWrapper).setSafetySourceData(
|
||||
any(), eq(SAFETY_SOURCE_ID), any(), eq(EVENT_TYPE_DEVICE_REBOOTED));
|
||||
}
|
||||
|
||||
// TODO(b/295516544): Modify this test for the new trunk stable flag instead when available.
|
||||
/** Tests that when the feature is disabled null data is set. */
|
||||
@Test
|
||||
public void setSafetySourceData_whenFeatureDisabled_setsNullData() {
|
||||
when(mSafetyCenterManagerWrapper.isEnabled(mContext)).thenReturn(true);
|
||||
FeatureFlagUtils
|
||||
.setEnabled(mContext, FeatureFlagUtils.SETTINGS_PRIVATE_SPACE_SETTINGS, false);
|
||||
|
||||
PrivateSpaceSafetySource.setSafetySourceData(mContext, EVENT_TYPE_DEVICE_REBOOTED);
|
||||
|
||||
ArgumentCaptor<SafetySourceData> captor = ArgumentCaptor.forClass(SafetySourceData.class);
|
||||
verify(mSafetyCenterManagerWrapper).setSafetySourceData(
|
||||
any(), eq(SAFETY_SOURCE_ID), captor.capture(), eq(EVENT_TYPE_DEVICE_REBOOTED));
|
||||
SafetySourceData safetySourceData = captor.getValue();
|
||||
assertThat(safetySourceData).isNull();
|
||||
|
||||
FeatureFlagUtils
|
||||
.setEnabled(mContext, FeatureFlagUtils.SETTINGS_PRIVATE_SPACE_SETTINGS, true);
|
||||
}
|
||||
|
||||
/** Tests that setSafetySourceData sets the source status enabled. */
|
||||
@Test
|
||||
public void setSafetySourceData_setsEnabled() {
|
||||
when(mSafetyCenterManagerWrapper.isEnabled(mContext)).thenReturn(true);
|
||||
|
||||
PrivateSpaceSafetySource.setSafetySourceData(mContext, EVENT_TYPE_DEVICE_REBOOTED);
|
||||
|
||||
ArgumentCaptor<SafetySourceData> captor = ArgumentCaptor.forClass(SafetySourceData.class);
|
||||
verify(mSafetyCenterManagerWrapper).setSafetySourceData(
|
||||
any(), eq(SAFETY_SOURCE_ID), captor.capture(), eq(EVENT_TYPE_DEVICE_REBOOTED));
|
||||
SafetySourceData safetySourceData = captor.getValue();
|
||||
SafetySourceStatus safetySourceStatus = safetySourceData.getStatus();
|
||||
assertThat(safetySourceStatus.isEnabled()).isTrue();
|
||||
}
|
||||
|
||||
/** Tests that setSafetySourceData sets the PS settings page intent. */
|
||||
@Test
|
||||
public void setSafetySourceData_setsPsIntent() {
|
||||
when(mSafetyCenterManagerWrapper.isEnabled(mContext)).thenReturn(true);
|
||||
|
||||
PrivateSpaceSafetySource.setSafetySourceData(mContext, EVENT_TYPE_DEVICE_REBOOTED);
|
||||
|
||||
ArgumentCaptor<SafetySourceData> captor = ArgumentCaptor.forClass(SafetySourceData.class);
|
||||
verify(mSafetyCenterManagerWrapper).setSafetySourceData(
|
||||
any(), eq(SAFETY_SOURCE_ID), captor.capture(), eq(EVENT_TYPE_DEVICE_REBOOTED));
|
||||
SafetySourceData safetySourceData = captor.getValue();
|
||||
SafetySourceStatus safetySourceStatus = safetySourceData.getStatus();
|
||||
assertThat(safetySourceStatus.getPendingIntent().getIntent().getIdentifier())
|
||||
.isEqualTo(SAFETY_SOURCE_ID);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user