Merge "Call system service API instead of checking the phenotype flag directly."
This commit is contained in:
committed by
Android (Google) Code Review
commit
1e81c40558
@@ -114,6 +114,7 @@
|
||||
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
||||
<uses-permission android:name="android.permission.READ_APP_SPECIFIC_LOCALES" />
|
||||
<uses-permission android:name="android.permission.QUERY_ADMIN_POLICY" />
|
||||
<uses-permission android:name="android.permission.READ_SAFETY_CENTER_STATUS" />
|
||||
|
||||
<application
|
||||
android:name=".SettingsApplication"
|
||||
|
@@ -33,7 +33,7 @@ import com.android.settings.enterprise.EnterprisePrivacySettings;
|
||||
import com.android.settings.network.SubscriptionUtil;
|
||||
import com.android.settings.network.telephony.MobileNetworkUtils;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settings.safetycenter.SafetyCenterStatus;
|
||||
import com.android.settings.safetycenter.SafetyCenterStatusHolder;
|
||||
import com.android.settings.security.SecuritySettingsFeatureProvider;
|
||||
|
||||
import com.google.android.setupdesign.util.ThemeHelper;
|
||||
@@ -152,7 +152,7 @@ public class Settings extends SettingsActivity {
|
||||
/** Redirects to SafetyCenter if enabled. */
|
||||
@VisibleForTesting
|
||||
public void handleSafetyCenterRedirection() {
|
||||
if (SafetyCenterStatus.isEnabled()) {
|
||||
if (SafetyCenterStatusHolder.get().isEnabled(this)) {
|
||||
try {
|
||||
startActivity(new Intent(Intent.ACTION_SAFETY_CENTER));
|
||||
finish();
|
||||
@@ -213,7 +213,7 @@ public class Settings extends SettingsActivity {
|
||||
/** Redirects to SafetyCenter if enabled. */
|
||||
@VisibleForTesting
|
||||
public void handleSafetyCenterRedirection() {
|
||||
if (SafetyCenterStatus.isEnabled()) {
|
||||
if (SafetyCenterStatusHolder.get().isEnabled(this)) {
|
||||
try {
|
||||
startActivity(new Intent(Intent.ACTION_SAFETY_CENTER));
|
||||
finish();
|
||||
|
@@ -22,7 +22,7 @@ import android.content.Context;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settings.notification.LockScreenNotificationPreferenceController;
|
||||
import com.android.settings.safetycenter.SafetyCenterStatus;
|
||||
import com.android.settings.safetycenter.SafetyCenterStatusHolder;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
@@ -93,7 +93,7 @@ public class PrivacyDashboardFragment extends DashboardFragment {
|
||||
|
||||
@Override
|
||||
protected boolean isPageSearchEnabled(Context context) {
|
||||
return !SafetyCenterStatus.isEnabled();
|
||||
return !SafetyCenterStatusHolder.get().isEnabled(context);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@@ -20,7 +20,7 @@ import android.annotation.NonNull;
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.safetycenter.SafetyCenterStatus;
|
||||
import com.android.settings.safetycenter.SafetyCenterStatusHolder;
|
||||
|
||||
/** The preference controller for the top level privacy tile. */
|
||||
public class TopLevelPrivacyEntryPreferenceController extends BasePreferenceController {
|
||||
@@ -31,7 +31,7 @@ public class TopLevelPrivacyEntryPreferenceController extends BasePreferenceCon
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
if (!SafetyCenterStatus.isEnabled()) {
|
||||
if (!SafetyCenterStatusHolder.get().isEnabled(mContext)) {
|
||||
return AVAILABLE;
|
||||
}
|
||||
return CONDITIONALLY_UNAVAILABLE;
|
||||
|
@@ -1,36 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2021 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.safetycenter;
|
||||
|
||||
import android.provider.DeviceConfig;
|
||||
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
|
||||
/** Knows whether safety center is enabled or disabled. */
|
||||
public class SafetyCenterStatus {
|
||||
|
||||
/** Whether SafetyCenter page is enabled. */
|
||||
@VisibleForTesting
|
||||
public static final String SAFETY_CENTER_IS_ENABLED = "safety_center_is_enabled";
|
||||
|
||||
/** Returns true is SafetyCenter page is enabled, false otherwise. */
|
||||
public static boolean isEnabled() {
|
||||
// TODO(b/208625216): use SafetyManager API instead
|
||||
return DeviceConfig.getBoolean(
|
||||
DeviceConfig.NAMESPACE_PRIVACY, SAFETY_CENTER_IS_ENABLED, false);
|
||||
}
|
||||
}
|
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright (C) 2022 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.safetycenter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.safetycenter.SafetyCenterManager;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
|
||||
/** Knows whether safety center is enabled or disabled. */
|
||||
public class SafetyCenterStatusHolder {
|
||||
|
||||
private static final String TAG = "SafetyCenterStatusHolder";
|
||||
|
||||
@VisibleForTesting
|
||||
public static SafetyCenterStatusHolder sInstance;
|
||||
|
||||
private SafetyCenterStatusHolder() {}
|
||||
|
||||
/** Returns an instance of {@link SafetyCenterStatusHolder}. */
|
||||
public static SafetyCenterStatusHolder get() {
|
||||
if (sInstance == null) {
|
||||
sInstance = new SafetyCenterStatusHolder();
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
/** Returns true is SafetyCenter page is enabled, false otherwise. */
|
||||
public boolean isEnabled(Context context) {
|
||||
if (context == null) {
|
||||
Log.e(TAG, "Context is null at SafetyCenterStatusHolder#isEnabled");
|
||||
return false;
|
||||
}
|
||||
SafetyCenterManager safetyCenterManager =
|
||||
context.getSystemService(SafetyCenterManager.class);
|
||||
if (safetyCenterManager == null) {
|
||||
Log.w(TAG, "System service SAFETY_CENTER_SERVICE (SafetyCenterManager) is null");
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
return safetyCenterManager.isSafetyCenterEnabled();
|
||||
} catch (RuntimeException e) {
|
||||
Log.e(TAG, "Calling isSafetyCenterEnabled failed.", e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@@ -37,7 +37,7 @@ public class TopLevelSafetyCenterEntryPreferenceController extends BasePreferenc
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
if (SafetyCenterStatus.isEnabled()) {
|
||||
if (SafetyCenterStatusHolder.get().isEnabled(mContext)) {
|
||||
return AVAILABLE;
|
||||
}
|
||||
return CONDITIONALLY_UNAVAILABLE;
|
||||
|
@@ -26,7 +26,7 @@ import com.android.settings.biometrics.face.FaceProfileStatusPreferenceControlle
|
||||
import com.android.settings.biometrics.fingerprint.FingerprintProfileStatusPreferenceController;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settings.safetycenter.SafetyCenterStatus;
|
||||
import com.android.settings.safetycenter.SafetyCenterStatusHolder;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settings.security.trustagent.TrustAgentListPreferenceController;
|
||||
import com.android.settings.widget.PreferenceCategoryController;
|
||||
@@ -60,11 +60,14 @@ public class SecurityAdvancedSettings extends DashboardFragment {
|
||||
|
||||
@Override
|
||||
public String getCategoryKey() {
|
||||
if (SafetyCenterStatus.isEnabled()) {
|
||||
final Context context = getContext();
|
||||
if (context == null) {
|
||||
return CATEGORY_SECURITY_LEGACY_ADVANCED_SETTINGS;
|
||||
} else if (SafetyCenterStatusHolder.get().isEnabled(context)) {
|
||||
return CategoryKey.CATEGORY_SECURITY_ADVANCED_SETTINGS;
|
||||
} else {
|
||||
final SecuritySettingsFeatureProvider securitySettingsFeatureProvider =
|
||||
FeatureFactory.getFactory(getContext())
|
||||
FeatureFactory.getFactory(context)
|
||||
.getSecuritySettingsFeatureProvider();
|
||||
|
||||
if (securitySettingsFeatureProvider.hasAlternativeSecuritySettingsFragment()) {
|
||||
|
@@ -25,7 +25,7 @@ import com.android.settings.biometrics.face.FaceStatusPreferenceController;
|
||||
import com.android.settings.biometrics.fingerprint.FingerprintStatusPreferenceController;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settings.safetycenter.SafetyCenterStatus;
|
||||
import com.android.settings.safetycenter.SafetyCenterStatusHolder;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settings.security.trustagent.TrustAgentListPreferenceController;
|
||||
import com.android.settings.widget.PreferenceCategoryController;
|
||||
@@ -129,7 +129,7 @@ public class SecuritySettings extends DashboardFragment {
|
||||
protected boolean isPageSearchEnabled(Context context) {
|
||||
return !FeatureFactory.getFactory(context).getSecuritySettingsFeatureProvider()
|
||||
.hasAlternativeSecuritySettingsFragment()
|
||||
&& !SafetyCenterStatus.isEnabled();
|
||||
&& !SafetyCenterStatusHolder.get().isEnabled(context);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@@ -24,7 +24,7 @@ import androidx.preference.Preference;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.core.SubSettingLauncher;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settings.safetycenter.SafetyCenterStatus;
|
||||
import com.android.settings.safetycenter.SafetyCenterStatusHolder;
|
||||
|
||||
public class TopLevelSecurityEntryPreferenceController extends BasePreferenceController {
|
||||
|
||||
@@ -38,7 +38,7 @@ public class TopLevelSecurityEntryPreferenceController extends BasePreferenceCon
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
if (!SafetyCenterStatus.isEnabled()) {
|
||||
if (!SafetyCenterStatusHolder.get().isEnabled(mContext)) {
|
||||
return AVAILABLE;
|
||||
}
|
||||
return CONDITIONALLY_UNAVAILABLE;
|
||||
|
@@ -23,34 +23,39 @@ import static org.mockito.Mockito.doNothing;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.provider.DeviceConfig;
|
||||
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
import androidx.test.platform.app.InstrumentationRegistry;
|
||||
|
||||
import com.android.settings.Settings;
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.safetycenter.SafetyCenterStatus;
|
||||
import com.android.settings.safetycenter.SafetyCenterStatusHolder;
|
||||
|
||||
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 PrivacyDashboardActivityTest {
|
||||
|
||||
private static final String DEFAULT_FRAGMENT_CLASSNAME = "DefaultFragmentClassname";
|
||||
|
||||
@Mock
|
||||
private SafetyCenterStatusHolder mSafetyCenterStatusHolder;
|
||||
private Settings.PrivacyDashboardActivity mActivity;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
DeviceConfig.resetToDefaults(android.provider.Settings.RESET_MODE_PACKAGE_DEFAULTS,
|
||||
DeviceConfig.NAMESPACE_PRIVACY);
|
||||
public void setUp() throws Exception {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
SafetyCenterStatusHolder.sInstance = mSafetyCenterStatusHolder;
|
||||
final Intent intent = new Intent();
|
||||
intent.setAction(android.provider.Settings.ACTION_PRIVACY_SETTINGS);
|
||||
intent.setClass(InstrumentationRegistry.getInstrumentation().getTargetContext(),
|
||||
@@ -71,19 +76,9 @@ public class PrivacyDashboardActivityTest {
|
||||
doNothing().when(mActivity).startActivity(any(Intent.class));
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
DeviceConfig.resetToDefaults(android.provider.Settings.RESET_MODE_PACKAGE_DEFAULTS,
|
||||
DeviceConfig.NAMESPACE_PRIVACY);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onCreate_whenSafetyCenterEnabled_redirectsToSafetyCenter() {
|
||||
DeviceConfig.setProperty(
|
||||
DeviceConfig.NAMESPACE_PRIVACY,
|
||||
SafetyCenterStatus.SAFETY_CENTER_IS_ENABLED,
|
||||
/* value = */ Boolean.toString(true),
|
||||
/* makeDefault = */ false);
|
||||
when(mSafetyCenterStatusHolder.isEnabled(any(Context.class))).thenReturn(true);
|
||||
final ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
|
||||
|
||||
mActivity.handleSafetyCenterRedirection();
|
||||
@@ -94,12 +89,7 @@ public class PrivacyDashboardActivityTest {
|
||||
|
||||
@Test
|
||||
public void onCreate_whenSafetyCenterDisabled_doesntRedirectToSafetyCenter() {
|
||||
DeviceConfig.setProperty(
|
||||
DeviceConfig.NAMESPACE_PRIVACY,
|
||||
SafetyCenterStatus.SAFETY_CENTER_IS_ENABLED,
|
||||
/* value = */ Boolean.toString(false),
|
||||
/* makeDefault = */ false);
|
||||
|
||||
when(mSafetyCenterStatusHolder.isEnabled(any(Context.class))).thenReturn(false);
|
||||
mActivity.handleSafetyCenterRedirection();
|
||||
|
||||
verify(mActivity, times(0)).startActivity(any());
|
||||
|
@@ -18,20 +18,22 @@ package com.android.settings.privacy;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.content.Context;
|
||||
import android.provider.DeviceConfig;
|
||||
import android.provider.Settings;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
import com.android.settings.safetycenter.SafetyCenterStatus;
|
||||
import com.android.settings.safetycenter.SafetyCenterStatusHolder;
|
||||
import com.android.settings.security.TopLevelSecurityEntryPreferenceController;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class TopLevelPrivacyEntryPreferenceControllerTest {
|
||||
@@ -41,30 +43,21 @@ public class TopLevelPrivacyEntryPreferenceControllerTest {
|
||||
private TopLevelPrivacyEntryPreferenceController mTopLevelPrivacyEntryPreferenceController;
|
||||
|
||||
@Mock
|
||||
private Context mContext;
|
||||
private SafetyCenterStatusHolder mSafetyCenterStatusHolder;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
DeviceConfig.resetToDefaults(Settings.RESET_MODE_PACKAGE_DEFAULTS,
|
||||
DeviceConfig.NAMESPACE_PRIVACY);
|
||||
MockitoAnnotations.initMocks(this);
|
||||
SafetyCenterStatusHolder.sInstance = mSafetyCenterStatusHolder;
|
||||
|
||||
mTopLevelPrivacyEntryPreferenceController =
|
||||
new TopLevelPrivacyEntryPreferenceController(mContext, PREFERENCE_KEY);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
DeviceConfig.resetToDefaults(Settings.RESET_MODE_PACKAGE_DEFAULTS,
|
||||
DeviceConfig.NAMESPACE_PRIVACY);
|
||||
new TopLevelPrivacyEntryPreferenceController(
|
||||
ApplicationProvider.getApplicationContext(), PREFERENCE_KEY);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_whenSafetyCenterEnabled_returnsUnavailable() {
|
||||
DeviceConfig.setProperty(
|
||||
DeviceConfig.NAMESPACE_PRIVACY,
|
||||
SafetyCenterStatus.SAFETY_CENTER_IS_ENABLED,
|
||||
/* value = */ Boolean.toString(true),
|
||||
/* makeDefault = */ false);
|
||||
when(mSafetyCenterStatusHolder.isEnabled(any(Context.class))).thenReturn(true);
|
||||
|
||||
assertThat(mTopLevelPrivacyEntryPreferenceController.getAvailabilityStatus())
|
||||
.isEqualTo(TopLevelSecurityEntryPreferenceController.CONDITIONALLY_UNAVAILABLE);
|
||||
@@ -72,11 +65,7 @@ public class TopLevelPrivacyEntryPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_whenSafetyCenterDisabled_returnsAvailable() {
|
||||
DeviceConfig.setProperty(
|
||||
DeviceConfig.NAMESPACE_PRIVACY,
|
||||
SafetyCenterStatus.SAFETY_CENTER_IS_ENABLED,
|
||||
/* value = */ Boolean.toString(false),
|
||||
/* makeDefault = */ false);
|
||||
when(mSafetyCenterStatusHolder.isEnabled(any(Context.class))).thenReturn(false);
|
||||
|
||||
assertThat(mTopLevelPrivacyEntryPreferenceController.getAvailabilityStatus())
|
||||
.isEqualTo(TopLevelSecurityEntryPreferenceController.AVAILABLE);
|
||||
|
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright (C) 2022 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.safetycenter;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.safetycenter.SafetyCenterManager;
|
||||
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class SafetyCenterStatusHolderTest {
|
||||
|
||||
@Mock
|
||||
private Context mContext;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isEnabled_whenContextNull_returnsFalse() {
|
||||
assertThat(SafetyCenterStatusHolder.get().isEnabled(null)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isEnabled_whenSystemServiceNull_returnsFalse() {
|
||||
when(mContext.getSystemService(SafetyCenterManager.class)).thenReturn(null);
|
||||
|
||||
assertThat(SafetyCenterStatusHolder.get().isEnabled(mContext)).isFalse();
|
||||
}
|
||||
}
|
@@ -1,67 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2021 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.safetycenter;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.provider.DeviceConfig;
|
||||
import android.provider.Settings;
|
||||
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class SafetyCenterStatusTest {
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
DeviceConfig.resetToDefaults(Settings.RESET_MODE_PACKAGE_DEFAULTS,
|
||||
DeviceConfig.NAMESPACE_PRIVACY);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
DeviceConfig.resetToDefaults(Settings.RESET_MODE_PACKAGE_DEFAULTS,
|
||||
DeviceConfig.NAMESPACE_PRIVACY);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isEnabled_whenFlagTrue_returnsTrue() {
|
||||
DeviceConfig.setProperty(
|
||||
DeviceConfig.NAMESPACE_PRIVACY,
|
||||
SafetyCenterStatus.SAFETY_CENTER_IS_ENABLED,
|
||||
/* value = */ Boolean.toString(true),
|
||||
/* makeDefault = */ false);
|
||||
|
||||
assertThat(SafetyCenterStatus.isEnabled()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isEnabled_whenFlagFalse_returnsFalse() {
|
||||
DeviceConfig.setProperty(
|
||||
DeviceConfig.NAMESPACE_PRIVACY,
|
||||
SafetyCenterStatus.SAFETY_CENTER_IS_ENABLED,
|
||||
/* value = */ Boolean.toString(false),
|
||||
/* makeDefault = */ false);
|
||||
|
||||
assertThat(SafetyCenterStatus.isEnabled()).isFalse();
|
||||
}
|
||||
}
|
@@ -22,18 +22,16 @@ import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.doNothing;
|
||||
import static org.mockito.Mockito.doThrow;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.provider.DeviceConfig;
|
||||
import android.provider.Settings;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -50,12 +48,16 @@ public class TopLevelSafetyCenterEntryPreferenceControllerTest {
|
||||
mTopLevelSafetyCenterEntryPreferenceController;
|
||||
private Preference mPreference;
|
||||
|
||||
@Mock
|
||||
private SafetyCenterStatusHolder mSafetyCenterStatusHolder;
|
||||
|
||||
@Mock
|
||||
private Context mContext;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
SafetyCenterStatusHolder.sInstance = mSafetyCenterStatusHolder;
|
||||
|
||||
mPreference = new Preference(ApplicationProvider.getApplicationContext());
|
||||
mPreference.setKey(PREFERENCE_KEY);
|
||||
@@ -63,14 +65,6 @@ public class TopLevelSafetyCenterEntryPreferenceControllerTest {
|
||||
doNothing().when(mContext).startActivity(any(Intent.class));
|
||||
mTopLevelSafetyCenterEntryPreferenceController =
|
||||
new TopLevelSafetyCenterEntryPreferenceController(mContext, PREFERENCE_KEY);
|
||||
DeviceConfig.resetToDefaults(Settings.RESET_MODE_PACKAGE_DEFAULTS,
|
||||
DeviceConfig.NAMESPACE_PRIVACY);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
DeviceConfig.resetToDefaults(Settings.RESET_MODE_PACKAGE_DEFAULTS,
|
||||
DeviceConfig.NAMESPACE_PRIVACY);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -110,11 +104,7 @@ public class TopLevelSafetyCenterEntryPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_whenSafetyCenterDisabled_returnsUnavailable() {
|
||||
DeviceConfig.setProperty(
|
||||
DeviceConfig.NAMESPACE_PRIVACY,
|
||||
SafetyCenterStatus.SAFETY_CENTER_IS_ENABLED,
|
||||
/* value = */ Boolean.toString(false),
|
||||
/* makeDefault = */ false);
|
||||
when(mSafetyCenterStatusHolder.isEnabled(any(Context.class))).thenReturn(false);
|
||||
|
||||
assertThat(mTopLevelSafetyCenterEntryPreferenceController.getAvailabilityStatus())
|
||||
.isEqualTo(TopLevelSafetyCenterEntryPreferenceController.CONDITIONALLY_UNAVAILABLE);
|
||||
@@ -122,11 +112,7 @@ public class TopLevelSafetyCenterEntryPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_whenSafetyCenterEnabled_returnsAvailable() {
|
||||
DeviceConfig.setProperty(
|
||||
DeviceConfig.NAMESPACE_PRIVACY,
|
||||
SafetyCenterStatus.SAFETY_CENTER_IS_ENABLED,
|
||||
/* value = */ Boolean.toString(true),
|
||||
/* makeDefault = */ false);
|
||||
when(mSafetyCenterStatusHolder.isEnabled(any(Context.class))).thenReturn(true);
|
||||
|
||||
assertThat(mTopLevelSafetyCenterEntryPreferenceController.getAvailabilityStatus())
|
||||
.isEqualTo(TopLevelSafetyCenterEntryPreferenceController.AVAILABLE);
|
||||
|
@@ -18,17 +18,18 @@ package com.android.settings.security;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Looper;
|
||||
import android.provider.DeviceConfig;
|
||||
|
||||
import androidx.test.annotation.UiThreadTest;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
import com.android.settings.safetycenter.SafetyCenterStatus;
|
||||
import com.android.settings.safetycenter.SafetyCenterStatusHolder;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.ResourcesUtils;
|
||||
import com.android.settingslib.drawer.CategoryKey;
|
||||
@@ -36,6 +37,8 @@ import com.android.settingslib.drawer.CategoryKey;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class SecurityAdvancedSettingsTest {
|
||||
@@ -47,16 +50,22 @@ public class SecurityAdvancedSettingsTest {
|
||||
private Context mContext;
|
||||
private SecurityAdvancedSettings mSecurityAdvancedSettings;
|
||||
|
||||
@Mock
|
||||
private SafetyCenterStatusHolder mSafetyCenterStatusHolder;
|
||||
|
||||
@Before
|
||||
@UiThreadTest
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
if (Looper.myLooper() == null) {
|
||||
Looper.prepare();
|
||||
}
|
||||
|
||||
SafetyCenterStatusHolder.sInstance = mSafetyCenterStatusHolder;
|
||||
mContext = ApplicationProvider.getApplicationContext();
|
||||
|
||||
mSecurityAdvancedSettings = new SecurityAdvancedSettings();
|
||||
mSecurityAdvancedSettings = spy(new SecurityAdvancedSettings());
|
||||
when(mSecurityAdvancedSettings.getContext()).thenReturn(mContext);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -67,7 +76,7 @@ public class SecurityAdvancedSettingsTest {
|
||||
|
||||
@Test
|
||||
public void getCategoryKey_whenSafetyCenterIsEnabled_returnsSecurity() {
|
||||
setSafetyCenterEnabled(true);
|
||||
when(mSafetyCenterStatusHolder.isEnabled(any())).thenReturn(true);
|
||||
|
||||
assertThat(mSecurityAdvancedSettings.getCategoryKey())
|
||||
.isEqualTo(CategoryKey.CATEGORY_SECURITY_ADVANCED_SETTINGS);
|
||||
@@ -75,7 +84,7 @@ public class SecurityAdvancedSettingsTest {
|
||||
|
||||
@Test
|
||||
public void getCategoryKey_whenAlternativeFragmentPresented_returnsAlternative() {
|
||||
setSafetyCenterEnabled(false);
|
||||
when(mSafetyCenterStatusHolder.isEnabled(any(Context.class))).thenReturn(false);
|
||||
setupAlternativeFragment(true, ALTERNATIVE_CATEGORY_KEY);
|
||||
|
||||
assertThat(mSecurityAdvancedSettings.getCategoryKey())
|
||||
@@ -84,7 +93,7 @@ public class SecurityAdvancedSettingsTest {
|
||||
|
||||
@Test
|
||||
public void getCategoryKey_whenNoAlternativeFragmentPresented_returnsLegacy() {
|
||||
setSafetyCenterEnabled(false);
|
||||
when(mSafetyCenterStatusHolder.isEnabled(any(Context.class))).thenReturn(false);
|
||||
setupAlternativeFragment(false, null);
|
||||
|
||||
assertThat(mSecurityAdvancedSettings.getCategoryKey())
|
||||
@@ -95,14 +104,6 @@ public class SecurityAdvancedSettingsTest {
|
||||
return ResourcesUtils.getResourcesId(mContext, "xml", resName);
|
||||
}
|
||||
|
||||
private void setSafetyCenterEnabled(boolean isEnabled) {
|
||||
DeviceConfig.setProperty(
|
||||
DeviceConfig.NAMESPACE_PRIVACY,
|
||||
SafetyCenterStatus.SAFETY_CENTER_IS_ENABLED,
|
||||
/* value = */ Boolean.toString(isEnabled),
|
||||
/* makeDefault = */ false);
|
||||
}
|
||||
|
||||
private void setupAlternativeFragment(boolean hasAlternativeFragment,
|
||||
String alternativeCategoryKey) {
|
||||
final FakeFeatureFactory fakeFeatureFactory = FakeFeatureFactory.setupForTest();
|
||||
|
@@ -25,22 +25,22 @@ import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.provider.DeviceConfig;
|
||||
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
import androidx.test.platform.app.InstrumentationRegistry;
|
||||
|
||||
import com.android.settings.Settings;
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.safetycenter.SafetyCenterStatus;
|
||||
import com.android.settings.safetycenter.SafetyCenterStatusHolder;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
|
||||
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)
|
||||
@@ -52,13 +52,16 @@ public class SecurityDashboardActivityTest {
|
||||
private Settings.SecurityDashboardActivity mActivity;
|
||||
private Intent mDefaultIntent;
|
||||
|
||||
@Mock
|
||||
private SafetyCenterStatusHolder mSafetyCenterStatusHolder;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
FakeFeatureFactory mFeatureFactory = FakeFeatureFactory.setupForTest();
|
||||
mSecuritySettingsFeatureProvider = mFeatureFactory.getSecuritySettingsFeatureProvider();
|
||||
DeviceConfig.resetToDefaults(android.provider.Settings.RESET_MODE_PACKAGE_DEFAULTS,
|
||||
DeviceConfig.NAMESPACE_PRIVACY);
|
||||
SafetyCenterStatusHolder.sInstance = mSafetyCenterStatusHolder;
|
||||
|
||||
mDefaultIntent = new Intent();
|
||||
mDefaultIntent.setAction(android.provider.Settings.ACTION_SECURITY_SETTINGS);
|
||||
mDefaultIntent.setClass(InstrumentationRegistry.getInstrumentation().getTargetContext(),
|
||||
@@ -79,12 +82,6 @@ public class SecurityDashboardActivityTest {
|
||||
doNothing().when(mActivity).startActivity(any(Intent.class));
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
DeviceConfig.resetToDefaults(android.provider.Settings.RESET_MODE_PACKAGE_DEFAULTS,
|
||||
DeviceConfig.NAMESPACE_PRIVACY);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void noAvailableAlternativeFragmentAvailable_defaultFragmentSet() {
|
||||
when(mSecuritySettingsFeatureProvider.hasAlternativeSecuritySettingsFragment())
|
||||
@@ -125,11 +122,7 @@ public class SecurityDashboardActivityTest {
|
||||
|
||||
@Test
|
||||
public void onCreate_whenSafetyCenterEnabled_redirectsToSafetyCenter() {
|
||||
DeviceConfig.setProperty(
|
||||
DeviceConfig.NAMESPACE_PRIVACY,
|
||||
SafetyCenterStatus.SAFETY_CENTER_IS_ENABLED,
|
||||
/* value = */ Boolean.toString(true),
|
||||
/* makeDefault = */ false);
|
||||
when(mSafetyCenterStatusHolder.isEnabled(any(Context.class))).thenReturn(true);
|
||||
final ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
|
||||
|
||||
mActivity.handleSafetyCenterRedirection();
|
||||
@@ -140,11 +133,7 @@ public class SecurityDashboardActivityTest {
|
||||
|
||||
@Test
|
||||
public void onCreate_whenSafetyCenterDisabled_doesntRedirectToSafetyCenter() {
|
||||
DeviceConfig.setProperty(
|
||||
DeviceConfig.NAMESPACE_PRIVACY,
|
||||
SafetyCenterStatus.SAFETY_CENTER_IS_ENABLED,
|
||||
/* value = */ Boolean.toString(false),
|
||||
/* makeDefault = */ false);
|
||||
when(mSafetyCenterStatusHolder.isEnabled(any(Context.class))).thenReturn(false);
|
||||
|
||||
mActivity.handleSafetyCenterRedirection();
|
||||
|
||||
|
@@ -25,18 +25,15 @@ import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.provider.DeviceConfig;
|
||||
import android.provider.Settings;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.safetycenter.SafetyCenterStatus;
|
||||
import com.android.settings.safetycenter.SafetyCenterStatusHolder;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -57,15 +54,15 @@ public class TopLevelSecurityEntryPreferenceControllerTest {
|
||||
|
||||
@Mock
|
||||
private Context mContext;
|
||||
@Mock
|
||||
private SafetyCenterStatusHolder mSafetyCenterStatusHolder;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mFeatureFactory = FakeFeatureFactory.setupForTest();
|
||||
mSecuritySettingsFeatureProvider = mFeatureFactory.getSecuritySettingsFeatureProvider();
|
||||
|
||||
DeviceConfig.resetToDefaults(Settings.RESET_MODE_PACKAGE_DEFAULTS,
|
||||
DeviceConfig.NAMESPACE_PRIVACY);
|
||||
SafetyCenterStatusHolder.sInstance = mSafetyCenterStatusHolder;
|
||||
|
||||
mPreference = new Preference(ApplicationProvider.getApplicationContext());
|
||||
mPreference.setKey(PREFERENCE_KEY);
|
||||
@@ -75,12 +72,6 @@ public class TopLevelSecurityEntryPreferenceControllerTest {
|
||||
new TopLevelSecurityEntryPreferenceController(mContext, PREFERENCE_KEY);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
DeviceConfig.resetToDefaults(Settings.RESET_MODE_PACKAGE_DEFAULTS,
|
||||
DeviceConfig.NAMESPACE_PRIVACY);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handlePreferenceTreeClick_forDifferentPreferenceKey_isNotHandled() {
|
||||
Preference preference = new Preference(ApplicationProvider.getApplicationContext());
|
||||
@@ -137,11 +128,7 @@ public class TopLevelSecurityEntryPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_whenSafetyCenterEnabled_returnsUnavailable() {
|
||||
DeviceConfig.setProperty(
|
||||
DeviceConfig.NAMESPACE_PRIVACY,
|
||||
SafetyCenterStatus.SAFETY_CENTER_IS_ENABLED,
|
||||
/* value = */ Boolean.toString(true),
|
||||
/* makeDefault = */ false);
|
||||
when(mSafetyCenterStatusHolder.isEnabled(any(Context.class))).thenReturn(true);
|
||||
|
||||
assertThat(mTopLevelSecurityEntryPreferenceController.getAvailabilityStatus())
|
||||
.isEqualTo(TopLevelSecurityEntryPreferenceController.CONDITIONALLY_UNAVAILABLE);
|
||||
@@ -149,11 +136,7 @@ public class TopLevelSecurityEntryPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_whenSafetyCenterDisabled_returnsAvailable() {
|
||||
DeviceConfig.setProperty(
|
||||
DeviceConfig.NAMESPACE_PRIVACY,
|
||||
SafetyCenterStatus.SAFETY_CENTER_IS_ENABLED,
|
||||
/* value = */ Boolean.toString(false),
|
||||
/* makeDefault = */ false);
|
||||
when(mSafetyCenterStatusHolder.isEnabled(any(Context.class))).thenReturn(false);
|
||||
|
||||
assertThat(mTopLevelSecurityEntryPreferenceController.getAvailabilityStatus())
|
||||
.isEqualTo(TopLevelSecurityEntryPreferenceController.AVAILABLE);
|
||||
|
Reference in New Issue
Block a user