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.POST_NOTIFICATIONS" />
|
||||||
<uses-permission android:name="android.permission.READ_APP_SPECIFIC_LOCALES" />
|
<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.QUERY_ADMIN_POLICY" />
|
||||||
|
<uses-permission android:name="android.permission.READ_SAFETY_CENTER_STATUS" />
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:name=".SettingsApplication"
|
android:name=".SettingsApplication"
|
||||||
|
@@ -33,7 +33,7 @@ import com.android.settings.enterprise.EnterprisePrivacySettings;
|
|||||||
import com.android.settings.network.SubscriptionUtil;
|
import com.android.settings.network.SubscriptionUtil;
|
||||||
import com.android.settings.network.telephony.MobileNetworkUtils;
|
import com.android.settings.network.telephony.MobileNetworkUtils;
|
||||||
import com.android.settings.overlay.FeatureFactory;
|
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.android.settings.security.SecuritySettingsFeatureProvider;
|
||||||
|
|
||||||
import com.google.android.setupdesign.util.ThemeHelper;
|
import com.google.android.setupdesign.util.ThemeHelper;
|
||||||
@@ -152,7 +152,7 @@ public class Settings extends SettingsActivity {
|
|||||||
/** Redirects to SafetyCenter if enabled. */
|
/** Redirects to SafetyCenter if enabled. */
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
public void handleSafetyCenterRedirection() {
|
public void handleSafetyCenterRedirection() {
|
||||||
if (SafetyCenterStatus.isEnabled()) {
|
if (SafetyCenterStatusHolder.get().isEnabled(this)) {
|
||||||
try {
|
try {
|
||||||
startActivity(new Intent(Intent.ACTION_SAFETY_CENTER));
|
startActivity(new Intent(Intent.ACTION_SAFETY_CENTER));
|
||||||
finish();
|
finish();
|
||||||
@@ -213,7 +213,7 @@ public class Settings extends SettingsActivity {
|
|||||||
/** Redirects to SafetyCenter if enabled. */
|
/** Redirects to SafetyCenter if enabled. */
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
public void handleSafetyCenterRedirection() {
|
public void handleSafetyCenterRedirection() {
|
||||||
if (SafetyCenterStatus.isEnabled()) {
|
if (SafetyCenterStatusHolder.get().isEnabled(this)) {
|
||||||
try {
|
try {
|
||||||
startActivity(new Intent(Intent.ACTION_SAFETY_CENTER));
|
startActivity(new Intent(Intent.ACTION_SAFETY_CENTER));
|
||||||
finish();
|
finish();
|
||||||
|
@@ -22,7 +22,7 @@ import android.content.Context;
|
|||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.dashboard.DashboardFragment;
|
import com.android.settings.dashboard.DashboardFragment;
|
||||||
import com.android.settings.notification.LockScreenNotificationPreferenceController;
|
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.settings.search.BaseSearchIndexProvider;
|
||||||
import com.android.settingslib.core.AbstractPreferenceController;
|
import com.android.settingslib.core.AbstractPreferenceController;
|
||||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||||
@@ -93,7 +93,7 @@ public class PrivacyDashboardFragment extends DashboardFragment {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean isPageSearchEnabled(Context context) {
|
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 android.content.Context;
|
||||||
|
|
||||||
import com.android.settings.core.BasePreferenceController;
|
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. */
|
/** The preference controller for the top level privacy tile. */
|
||||||
public class TopLevelPrivacyEntryPreferenceController extends BasePreferenceController {
|
public class TopLevelPrivacyEntryPreferenceController extends BasePreferenceController {
|
||||||
@@ -31,7 +31,7 @@ public class TopLevelPrivacyEntryPreferenceController extends BasePreferenceCon
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getAvailabilityStatus() {
|
public int getAvailabilityStatus() {
|
||||||
if (!SafetyCenterStatus.isEnabled()) {
|
if (!SafetyCenterStatusHolder.get().isEnabled(mContext)) {
|
||||||
return AVAILABLE;
|
return AVAILABLE;
|
||||||
}
|
}
|
||||||
return CONDITIONALLY_UNAVAILABLE;
|
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
|
@Override
|
||||||
public int getAvailabilityStatus() {
|
public int getAvailabilityStatus() {
|
||||||
if (SafetyCenterStatus.isEnabled()) {
|
if (SafetyCenterStatusHolder.get().isEnabled(mContext)) {
|
||||||
return AVAILABLE;
|
return AVAILABLE;
|
||||||
}
|
}
|
||||||
return CONDITIONALLY_UNAVAILABLE;
|
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.biometrics.fingerprint.FingerprintProfileStatusPreferenceController;
|
||||||
import com.android.settings.dashboard.DashboardFragment;
|
import com.android.settings.dashboard.DashboardFragment;
|
||||||
import com.android.settings.overlay.FeatureFactory;
|
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.search.BaseSearchIndexProvider;
|
||||||
import com.android.settings.security.trustagent.TrustAgentListPreferenceController;
|
import com.android.settings.security.trustagent.TrustAgentListPreferenceController;
|
||||||
import com.android.settings.widget.PreferenceCategoryController;
|
import com.android.settings.widget.PreferenceCategoryController;
|
||||||
@@ -60,11 +60,14 @@ public class SecurityAdvancedSettings extends DashboardFragment {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getCategoryKey() {
|
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;
|
return CategoryKey.CATEGORY_SECURITY_ADVANCED_SETTINGS;
|
||||||
} else {
|
} else {
|
||||||
final SecuritySettingsFeatureProvider securitySettingsFeatureProvider =
|
final SecuritySettingsFeatureProvider securitySettingsFeatureProvider =
|
||||||
FeatureFactory.getFactory(getContext())
|
FeatureFactory.getFactory(context)
|
||||||
.getSecuritySettingsFeatureProvider();
|
.getSecuritySettingsFeatureProvider();
|
||||||
|
|
||||||
if (securitySettingsFeatureProvider.hasAlternativeSecuritySettingsFragment()) {
|
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.biometrics.fingerprint.FingerprintStatusPreferenceController;
|
||||||
import com.android.settings.dashboard.DashboardFragment;
|
import com.android.settings.dashboard.DashboardFragment;
|
||||||
import com.android.settings.overlay.FeatureFactory;
|
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.search.BaseSearchIndexProvider;
|
||||||
import com.android.settings.security.trustagent.TrustAgentListPreferenceController;
|
import com.android.settings.security.trustagent.TrustAgentListPreferenceController;
|
||||||
import com.android.settings.widget.PreferenceCategoryController;
|
import com.android.settings.widget.PreferenceCategoryController;
|
||||||
@@ -129,7 +129,7 @@ public class SecuritySettings extends DashboardFragment {
|
|||||||
protected boolean isPageSearchEnabled(Context context) {
|
protected boolean isPageSearchEnabled(Context context) {
|
||||||
return !FeatureFactory.getFactory(context).getSecuritySettingsFeatureProvider()
|
return !FeatureFactory.getFactory(context).getSecuritySettingsFeatureProvider()
|
||||||
.hasAlternativeSecuritySettingsFragment()
|
.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.BasePreferenceController;
|
||||||
import com.android.settings.core.SubSettingLauncher;
|
import com.android.settings.core.SubSettingLauncher;
|
||||||
import com.android.settings.overlay.FeatureFactory;
|
import com.android.settings.overlay.FeatureFactory;
|
||||||
import com.android.settings.safetycenter.SafetyCenterStatus;
|
import com.android.settings.safetycenter.SafetyCenterStatusHolder;
|
||||||
|
|
||||||
public class TopLevelSecurityEntryPreferenceController extends BasePreferenceController {
|
public class TopLevelSecurityEntryPreferenceController extends BasePreferenceController {
|
||||||
|
|
||||||
@@ -38,7 +38,7 @@ public class TopLevelSecurityEntryPreferenceController extends BasePreferenceCon
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getAvailabilityStatus() {
|
public int getAvailabilityStatus() {
|
||||||
if (!SafetyCenterStatus.isEnabled()) {
|
if (!SafetyCenterStatusHolder.get().isEnabled(mContext)) {
|
||||||
return AVAILABLE;
|
return AVAILABLE;
|
||||||
}
|
}
|
||||||
return CONDITIONALLY_UNAVAILABLE;
|
return CONDITIONALLY_UNAVAILABLE;
|
||||||
|
@@ -23,34 +23,39 @@ import static org.mockito.Mockito.doNothing;
|
|||||||
import static org.mockito.Mockito.spy;
|
import static org.mockito.Mockito.spy;
|
||||||
import static org.mockito.Mockito.times;
|
import static org.mockito.Mockito.times;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.provider.DeviceConfig;
|
|
||||||
|
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||||
import androidx.test.platform.app.InstrumentationRegistry;
|
import androidx.test.platform.app.InstrumentationRegistry;
|
||||||
|
|
||||||
import com.android.settings.Settings;
|
import com.android.settings.Settings;
|
||||||
import com.android.settings.SettingsActivity;
|
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.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.ArgumentCaptor;
|
import org.mockito.ArgumentCaptor;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.MockitoAnnotations;
|
||||||
|
|
||||||
@RunWith(AndroidJUnit4.class)
|
@RunWith(AndroidJUnit4.class)
|
||||||
public class PrivacyDashboardActivityTest {
|
public class PrivacyDashboardActivityTest {
|
||||||
|
|
||||||
private static final String DEFAULT_FRAGMENT_CLASSNAME = "DefaultFragmentClassname";
|
private static final String DEFAULT_FRAGMENT_CLASSNAME = "DefaultFragmentClassname";
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private SafetyCenterStatusHolder mSafetyCenterStatusHolder;
|
||||||
private Settings.PrivacyDashboardActivity mActivity;
|
private Settings.PrivacyDashboardActivity mActivity;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() throws Exception {
|
||||||
DeviceConfig.resetToDefaults(android.provider.Settings.RESET_MODE_PACKAGE_DEFAULTS,
|
MockitoAnnotations.initMocks(this);
|
||||||
DeviceConfig.NAMESPACE_PRIVACY);
|
|
||||||
|
SafetyCenterStatusHolder.sInstance = mSafetyCenterStatusHolder;
|
||||||
final Intent intent = new Intent();
|
final Intent intent = new Intent();
|
||||||
intent.setAction(android.provider.Settings.ACTION_PRIVACY_SETTINGS);
|
intent.setAction(android.provider.Settings.ACTION_PRIVACY_SETTINGS);
|
||||||
intent.setClass(InstrumentationRegistry.getInstrumentation().getTargetContext(),
|
intent.setClass(InstrumentationRegistry.getInstrumentation().getTargetContext(),
|
||||||
@@ -71,19 +76,9 @@ public class PrivacyDashboardActivityTest {
|
|||||||
doNothing().when(mActivity).startActivity(any(Intent.class));
|
doNothing().when(mActivity).startActivity(any(Intent.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
|
||||||
public void tearDown() {
|
|
||||||
DeviceConfig.resetToDefaults(android.provider.Settings.RESET_MODE_PACKAGE_DEFAULTS,
|
|
||||||
DeviceConfig.NAMESPACE_PRIVACY);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onCreate_whenSafetyCenterEnabled_redirectsToSafetyCenter() {
|
public void onCreate_whenSafetyCenterEnabled_redirectsToSafetyCenter() {
|
||||||
DeviceConfig.setProperty(
|
when(mSafetyCenterStatusHolder.isEnabled(any(Context.class))).thenReturn(true);
|
||||||
DeviceConfig.NAMESPACE_PRIVACY,
|
|
||||||
SafetyCenterStatus.SAFETY_CENTER_IS_ENABLED,
|
|
||||||
/* value = */ Boolean.toString(true),
|
|
||||||
/* makeDefault = */ false);
|
|
||||||
final ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
|
final ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
|
||||||
|
|
||||||
mActivity.handleSafetyCenterRedirection();
|
mActivity.handleSafetyCenterRedirection();
|
||||||
@@ -94,12 +89,7 @@ public class PrivacyDashboardActivityTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onCreate_whenSafetyCenterDisabled_doesntRedirectToSafetyCenter() {
|
public void onCreate_whenSafetyCenterDisabled_doesntRedirectToSafetyCenter() {
|
||||||
DeviceConfig.setProperty(
|
when(mSafetyCenterStatusHolder.isEnabled(any(Context.class))).thenReturn(false);
|
||||||
DeviceConfig.NAMESPACE_PRIVACY,
|
|
||||||
SafetyCenterStatus.SAFETY_CENTER_IS_ENABLED,
|
|
||||||
/* value = */ Boolean.toString(false),
|
|
||||||
/* makeDefault = */ false);
|
|
||||||
|
|
||||||
mActivity.handleSafetyCenterRedirection();
|
mActivity.handleSafetyCenterRedirection();
|
||||||
|
|
||||||
verify(mActivity, times(0)).startActivity(any());
|
verify(mActivity, times(0)).startActivity(any());
|
||||||
|
@@ -18,20 +18,22 @@ package com.android.settings.privacy;
|
|||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import android.content.Context;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import android.provider.DeviceConfig;
|
import static org.mockito.Mockito.when;
|
||||||
import android.provider.Settings;
|
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
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 com.android.settings.security.TopLevelSecurityEntryPreferenceController;
|
||||||
|
|
||||||
import org.junit.After;
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.MockitoAnnotations;
|
||||||
|
|
||||||
@RunWith(AndroidJUnit4.class)
|
@RunWith(AndroidJUnit4.class)
|
||||||
public class TopLevelPrivacyEntryPreferenceControllerTest {
|
public class TopLevelPrivacyEntryPreferenceControllerTest {
|
||||||
@@ -41,30 +43,21 @@ public class TopLevelPrivacyEntryPreferenceControllerTest {
|
|||||||
private TopLevelPrivacyEntryPreferenceController mTopLevelPrivacyEntryPreferenceController;
|
private TopLevelPrivacyEntryPreferenceController mTopLevelPrivacyEntryPreferenceController;
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private Context mContext;
|
private SafetyCenterStatusHolder mSafetyCenterStatusHolder;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
DeviceConfig.resetToDefaults(Settings.RESET_MODE_PACKAGE_DEFAULTS,
|
MockitoAnnotations.initMocks(this);
|
||||||
DeviceConfig.NAMESPACE_PRIVACY);
|
SafetyCenterStatusHolder.sInstance = mSafetyCenterStatusHolder;
|
||||||
|
|
||||||
mTopLevelPrivacyEntryPreferenceController =
|
mTopLevelPrivacyEntryPreferenceController =
|
||||||
new TopLevelPrivacyEntryPreferenceController(mContext, PREFERENCE_KEY);
|
new TopLevelPrivacyEntryPreferenceController(
|
||||||
}
|
ApplicationProvider.getApplicationContext(), PREFERENCE_KEY);
|
||||||
|
|
||||||
@After
|
|
||||||
public void tearDown() {
|
|
||||||
DeviceConfig.resetToDefaults(Settings.RESET_MODE_PACKAGE_DEFAULTS,
|
|
||||||
DeviceConfig.NAMESPACE_PRIVACY);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getAvailabilityStatus_whenSafetyCenterEnabled_returnsUnavailable() {
|
public void getAvailabilityStatus_whenSafetyCenterEnabled_returnsUnavailable() {
|
||||||
DeviceConfig.setProperty(
|
when(mSafetyCenterStatusHolder.isEnabled(any(Context.class))).thenReturn(true);
|
||||||
DeviceConfig.NAMESPACE_PRIVACY,
|
|
||||||
SafetyCenterStatus.SAFETY_CENTER_IS_ENABLED,
|
|
||||||
/* value = */ Boolean.toString(true),
|
|
||||||
/* makeDefault = */ false);
|
|
||||||
|
|
||||||
assertThat(mTopLevelPrivacyEntryPreferenceController.getAvailabilityStatus())
|
assertThat(mTopLevelPrivacyEntryPreferenceController.getAvailabilityStatus())
|
||||||
.isEqualTo(TopLevelSecurityEntryPreferenceController.CONDITIONALLY_UNAVAILABLE);
|
.isEqualTo(TopLevelSecurityEntryPreferenceController.CONDITIONALLY_UNAVAILABLE);
|
||||||
@@ -72,11 +65,7 @@ public class TopLevelPrivacyEntryPreferenceControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getAvailabilityStatus_whenSafetyCenterDisabled_returnsAvailable() {
|
public void getAvailabilityStatus_whenSafetyCenterDisabled_returnsAvailable() {
|
||||||
DeviceConfig.setProperty(
|
when(mSafetyCenterStatusHolder.isEnabled(any(Context.class))).thenReturn(false);
|
||||||
DeviceConfig.NAMESPACE_PRIVACY,
|
|
||||||
SafetyCenterStatus.SAFETY_CENTER_IS_ENABLED,
|
|
||||||
/* value = */ Boolean.toString(false),
|
|
||||||
/* makeDefault = */ false);
|
|
||||||
|
|
||||||
assertThat(mTopLevelPrivacyEntryPreferenceController.getAvailabilityStatus())
|
assertThat(mTopLevelPrivacyEntryPreferenceController.getAvailabilityStatus())
|
||||||
.isEqualTo(TopLevelSecurityEntryPreferenceController.AVAILABLE);
|
.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.doNothing;
|
||||||
import static org.mockito.Mockito.doThrow;
|
import static org.mockito.Mockito.doThrow;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import android.content.ActivityNotFoundException;
|
import android.content.ActivityNotFoundException;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.provider.DeviceConfig;
|
|
||||||
import android.provider.Settings;
|
|
||||||
|
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
import androidx.test.core.app.ApplicationProvider;
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||||
|
|
||||||
import org.junit.After;
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
@@ -50,12 +48,16 @@ public class TopLevelSafetyCenterEntryPreferenceControllerTest {
|
|||||||
mTopLevelSafetyCenterEntryPreferenceController;
|
mTopLevelSafetyCenterEntryPreferenceController;
|
||||||
private Preference mPreference;
|
private Preference mPreference;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private SafetyCenterStatusHolder mSafetyCenterStatusHolder;
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
|
SafetyCenterStatusHolder.sInstance = mSafetyCenterStatusHolder;
|
||||||
|
|
||||||
mPreference = new Preference(ApplicationProvider.getApplicationContext());
|
mPreference = new Preference(ApplicationProvider.getApplicationContext());
|
||||||
mPreference.setKey(PREFERENCE_KEY);
|
mPreference.setKey(PREFERENCE_KEY);
|
||||||
@@ -63,14 +65,6 @@ public class TopLevelSafetyCenterEntryPreferenceControllerTest {
|
|||||||
doNothing().when(mContext).startActivity(any(Intent.class));
|
doNothing().when(mContext).startActivity(any(Intent.class));
|
||||||
mTopLevelSafetyCenterEntryPreferenceController =
|
mTopLevelSafetyCenterEntryPreferenceController =
|
||||||
new TopLevelSafetyCenterEntryPreferenceController(mContext, PREFERENCE_KEY);
|
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
|
@Test
|
||||||
@@ -110,11 +104,7 @@ public class TopLevelSafetyCenterEntryPreferenceControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getAvailabilityStatus_whenSafetyCenterDisabled_returnsUnavailable() {
|
public void getAvailabilityStatus_whenSafetyCenterDisabled_returnsUnavailable() {
|
||||||
DeviceConfig.setProperty(
|
when(mSafetyCenterStatusHolder.isEnabled(any(Context.class))).thenReturn(false);
|
||||||
DeviceConfig.NAMESPACE_PRIVACY,
|
|
||||||
SafetyCenterStatus.SAFETY_CENTER_IS_ENABLED,
|
|
||||||
/* value = */ Boolean.toString(false),
|
|
||||||
/* makeDefault = */ false);
|
|
||||||
|
|
||||||
assertThat(mTopLevelSafetyCenterEntryPreferenceController.getAvailabilityStatus())
|
assertThat(mTopLevelSafetyCenterEntryPreferenceController.getAvailabilityStatus())
|
||||||
.isEqualTo(TopLevelSafetyCenterEntryPreferenceController.CONDITIONALLY_UNAVAILABLE);
|
.isEqualTo(TopLevelSafetyCenterEntryPreferenceController.CONDITIONALLY_UNAVAILABLE);
|
||||||
@@ -122,11 +112,7 @@ public class TopLevelSafetyCenterEntryPreferenceControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getAvailabilityStatus_whenSafetyCenterEnabled_returnsAvailable() {
|
public void getAvailabilityStatus_whenSafetyCenterEnabled_returnsAvailable() {
|
||||||
DeviceConfig.setProperty(
|
when(mSafetyCenterStatusHolder.isEnabled(any(Context.class))).thenReturn(true);
|
||||||
DeviceConfig.NAMESPACE_PRIVACY,
|
|
||||||
SafetyCenterStatus.SAFETY_CENTER_IS_ENABLED,
|
|
||||||
/* value = */ Boolean.toString(true),
|
|
||||||
/* makeDefault = */ false);
|
|
||||||
|
|
||||||
assertThat(mTopLevelSafetyCenterEntryPreferenceController.getAvailabilityStatus())
|
assertThat(mTopLevelSafetyCenterEntryPreferenceController.getAvailabilityStatus())
|
||||||
.isEqualTo(TopLevelSafetyCenterEntryPreferenceController.AVAILABLE);
|
.isEqualTo(TopLevelSafetyCenterEntryPreferenceController.AVAILABLE);
|
||||||
|
@@ -18,17 +18,18 @@ package com.android.settings.security;
|
|||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
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 static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
import android.provider.DeviceConfig;
|
|
||||||
|
|
||||||
import androidx.test.annotation.UiThreadTest;
|
import androidx.test.annotation.UiThreadTest;
|
||||||
import androidx.test.core.app.ApplicationProvider;
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
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.FakeFeatureFactory;
|
||||||
import com.android.settings.testutils.ResourcesUtils;
|
import com.android.settings.testutils.ResourcesUtils;
|
||||||
import com.android.settingslib.drawer.CategoryKey;
|
import com.android.settingslib.drawer.CategoryKey;
|
||||||
@@ -36,6 +37,8 @@ import com.android.settingslib.drawer.CategoryKey;
|
|||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.MockitoAnnotations;
|
||||||
|
|
||||||
@RunWith(AndroidJUnit4.class)
|
@RunWith(AndroidJUnit4.class)
|
||||||
public class SecurityAdvancedSettingsTest {
|
public class SecurityAdvancedSettingsTest {
|
||||||
@@ -47,16 +50,22 @@ public class SecurityAdvancedSettingsTest {
|
|||||||
private Context mContext;
|
private Context mContext;
|
||||||
private SecurityAdvancedSettings mSecurityAdvancedSettings;
|
private SecurityAdvancedSettings mSecurityAdvancedSettings;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private SafetyCenterStatusHolder mSafetyCenterStatusHolder;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
@UiThreadTest
|
@UiThreadTest
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
|
MockitoAnnotations.initMocks(this);
|
||||||
if (Looper.myLooper() == null) {
|
if (Looper.myLooper() == null) {
|
||||||
Looper.prepare();
|
Looper.prepare();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SafetyCenterStatusHolder.sInstance = mSafetyCenterStatusHolder;
|
||||||
mContext = ApplicationProvider.getApplicationContext();
|
mContext = ApplicationProvider.getApplicationContext();
|
||||||
|
|
||||||
mSecurityAdvancedSettings = new SecurityAdvancedSettings();
|
mSecurityAdvancedSettings = spy(new SecurityAdvancedSettings());
|
||||||
|
when(mSecurityAdvancedSettings.getContext()).thenReturn(mContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -67,7 +76,7 @@ public class SecurityAdvancedSettingsTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getCategoryKey_whenSafetyCenterIsEnabled_returnsSecurity() {
|
public void getCategoryKey_whenSafetyCenterIsEnabled_returnsSecurity() {
|
||||||
setSafetyCenterEnabled(true);
|
when(mSafetyCenterStatusHolder.isEnabled(any())).thenReturn(true);
|
||||||
|
|
||||||
assertThat(mSecurityAdvancedSettings.getCategoryKey())
|
assertThat(mSecurityAdvancedSettings.getCategoryKey())
|
||||||
.isEqualTo(CategoryKey.CATEGORY_SECURITY_ADVANCED_SETTINGS);
|
.isEqualTo(CategoryKey.CATEGORY_SECURITY_ADVANCED_SETTINGS);
|
||||||
@@ -75,7 +84,7 @@ public class SecurityAdvancedSettingsTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getCategoryKey_whenAlternativeFragmentPresented_returnsAlternative() {
|
public void getCategoryKey_whenAlternativeFragmentPresented_returnsAlternative() {
|
||||||
setSafetyCenterEnabled(false);
|
when(mSafetyCenterStatusHolder.isEnabled(any(Context.class))).thenReturn(false);
|
||||||
setupAlternativeFragment(true, ALTERNATIVE_CATEGORY_KEY);
|
setupAlternativeFragment(true, ALTERNATIVE_CATEGORY_KEY);
|
||||||
|
|
||||||
assertThat(mSecurityAdvancedSettings.getCategoryKey())
|
assertThat(mSecurityAdvancedSettings.getCategoryKey())
|
||||||
@@ -84,7 +93,7 @@ public class SecurityAdvancedSettingsTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getCategoryKey_whenNoAlternativeFragmentPresented_returnsLegacy() {
|
public void getCategoryKey_whenNoAlternativeFragmentPresented_returnsLegacy() {
|
||||||
setSafetyCenterEnabled(false);
|
when(mSafetyCenterStatusHolder.isEnabled(any(Context.class))).thenReturn(false);
|
||||||
setupAlternativeFragment(false, null);
|
setupAlternativeFragment(false, null);
|
||||||
|
|
||||||
assertThat(mSecurityAdvancedSettings.getCategoryKey())
|
assertThat(mSecurityAdvancedSettings.getCategoryKey())
|
||||||
@@ -95,14 +104,6 @@ public class SecurityAdvancedSettingsTest {
|
|||||||
return ResourcesUtils.getResourcesId(mContext, "xml", resName);
|
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,
|
private void setupAlternativeFragment(boolean hasAlternativeFragment,
|
||||||
String alternativeCategoryKey) {
|
String alternativeCategoryKey) {
|
||||||
final FakeFeatureFactory fakeFeatureFactory = FakeFeatureFactory.setupForTest();
|
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.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.provider.DeviceConfig;
|
|
||||||
|
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||||
import androidx.test.platform.app.InstrumentationRegistry;
|
import androidx.test.platform.app.InstrumentationRegistry;
|
||||||
|
|
||||||
import com.android.settings.Settings;
|
import com.android.settings.Settings;
|
||||||
import com.android.settings.SettingsActivity;
|
import com.android.settings.SettingsActivity;
|
||||||
import com.android.settings.safetycenter.SafetyCenterStatus;
|
import com.android.settings.safetycenter.SafetyCenterStatusHolder;
|
||||||
import com.android.settings.testutils.FakeFeatureFactory;
|
import com.android.settings.testutils.FakeFeatureFactory;
|
||||||
|
|
||||||
import org.junit.After;
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.ArgumentCaptor;
|
import org.mockito.ArgumentCaptor;
|
||||||
|
import org.mockito.Mock;
|
||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.MockitoAnnotations;
|
||||||
|
|
||||||
@RunWith(AndroidJUnit4.class)
|
@RunWith(AndroidJUnit4.class)
|
||||||
@@ -52,13 +52,16 @@ public class SecurityDashboardActivityTest {
|
|||||||
private Settings.SecurityDashboardActivity mActivity;
|
private Settings.SecurityDashboardActivity mActivity;
|
||||||
private Intent mDefaultIntent;
|
private Intent mDefaultIntent;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private SafetyCenterStatusHolder mSafetyCenterStatusHolder;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
FakeFeatureFactory mFeatureFactory = FakeFeatureFactory.setupForTest();
|
FakeFeatureFactory mFeatureFactory = FakeFeatureFactory.setupForTest();
|
||||||
mSecuritySettingsFeatureProvider = mFeatureFactory.getSecuritySettingsFeatureProvider();
|
mSecuritySettingsFeatureProvider = mFeatureFactory.getSecuritySettingsFeatureProvider();
|
||||||
DeviceConfig.resetToDefaults(android.provider.Settings.RESET_MODE_PACKAGE_DEFAULTS,
|
SafetyCenterStatusHolder.sInstance = mSafetyCenterStatusHolder;
|
||||||
DeviceConfig.NAMESPACE_PRIVACY);
|
|
||||||
mDefaultIntent = new Intent();
|
mDefaultIntent = new Intent();
|
||||||
mDefaultIntent.setAction(android.provider.Settings.ACTION_SECURITY_SETTINGS);
|
mDefaultIntent.setAction(android.provider.Settings.ACTION_SECURITY_SETTINGS);
|
||||||
mDefaultIntent.setClass(InstrumentationRegistry.getInstrumentation().getTargetContext(),
|
mDefaultIntent.setClass(InstrumentationRegistry.getInstrumentation().getTargetContext(),
|
||||||
@@ -79,12 +82,6 @@ public class SecurityDashboardActivityTest {
|
|||||||
doNothing().when(mActivity).startActivity(any(Intent.class));
|
doNothing().when(mActivity).startActivity(any(Intent.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
|
||||||
public void tearDown() {
|
|
||||||
DeviceConfig.resetToDefaults(android.provider.Settings.RESET_MODE_PACKAGE_DEFAULTS,
|
|
||||||
DeviceConfig.NAMESPACE_PRIVACY);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void noAvailableAlternativeFragmentAvailable_defaultFragmentSet() {
|
public void noAvailableAlternativeFragmentAvailable_defaultFragmentSet() {
|
||||||
when(mSecuritySettingsFeatureProvider.hasAlternativeSecuritySettingsFragment())
|
when(mSecuritySettingsFeatureProvider.hasAlternativeSecuritySettingsFragment())
|
||||||
@@ -125,11 +122,7 @@ public class SecurityDashboardActivityTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onCreate_whenSafetyCenterEnabled_redirectsToSafetyCenter() {
|
public void onCreate_whenSafetyCenterEnabled_redirectsToSafetyCenter() {
|
||||||
DeviceConfig.setProperty(
|
when(mSafetyCenterStatusHolder.isEnabled(any(Context.class))).thenReturn(true);
|
||||||
DeviceConfig.NAMESPACE_PRIVACY,
|
|
||||||
SafetyCenterStatus.SAFETY_CENTER_IS_ENABLED,
|
|
||||||
/* value = */ Boolean.toString(true),
|
|
||||||
/* makeDefault = */ false);
|
|
||||||
final ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
|
final ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
|
||||||
|
|
||||||
mActivity.handleSafetyCenterRedirection();
|
mActivity.handleSafetyCenterRedirection();
|
||||||
@@ -140,11 +133,7 @@ public class SecurityDashboardActivityTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onCreate_whenSafetyCenterDisabled_doesntRedirectToSafetyCenter() {
|
public void onCreate_whenSafetyCenterDisabled_doesntRedirectToSafetyCenter() {
|
||||||
DeviceConfig.setProperty(
|
when(mSafetyCenterStatusHolder.isEnabled(any(Context.class))).thenReturn(false);
|
||||||
DeviceConfig.NAMESPACE_PRIVACY,
|
|
||||||
SafetyCenterStatus.SAFETY_CENTER_IS_ENABLED,
|
|
||||||
/* value = */ Boolean.toString(false),
|
|
||||||
/* makeDefault = */ false);
|
|
||||||
|
|
||||||
mActivity.handleSafetyCenterRedirection();
|
mActivity.handleSafetyCenterRedirection();
|
||||||
|
|
||||||
|
@@ -25,18 +25,15 @@ import static org.mockito.Mockito.when;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.provider.DeviceConfig;
|
|
||||||
import android.provider.Settings;
|
|
||||||
|
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
import androidx.test.core.app.ApplicationProvider;
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||||
|
|
||||||
import com.android.settings.SettingsActivity;
|
import com.android.settings.SettingsActivity;
|
||||||
import com.android.settings.safetycenter.SafetyCenterStatus;
|
import com.android.settings.safetycenter.SafetyCenterStatusHolder;
|
||||||
import com.android.settings.testutils.FakeFeatureFactory;
|
import com.android.settings.testutils.FakeFeatureFactory;
|
||||||
|
|
||||||
import org.junit.After;
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
@@ -57,15 +54,15 @@ public class TopLevelSecurityEntryPreferenceControllerTest {
|
|||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
|
@Mock
|
||||||
|
private SafetyCenterStatusHolder mSafetyCenterStatusHolder;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
mFeatureFactory = FakeFeatureFactory.setupForTest();
|
mFeatureFactory = FakeFeatureFactory.setupForTest();
|
||||||
mSecuritySettingsFeatureProvider = mFeatureFactory.getSecuritySettingsFeatureProvider();
|
mSecuritySettingsFeatureProvider = mFeatureFactory.getSecuritySettingsFeatureProvider();
|
||||||
|
SafetyCenterStatusHolder.sInstance = mSafetyCenterStatusHolder;
|
||||||
DeviceConfig.resetToDefaults(Settings.RESET_MODE_PACKAGE_DEFAULTS,
|
|
||||||
DeviceConfig.NAMESPACE_PRIVACY);
|
|
||||||
|
|
||||||
mPreference = new Preference(ApplicationProvider.getApplicationContext());
|
mPreference = new Preference(ApplicationProvider.getApplicationContext());
|
||||||
mPreference.setKey(PREFERENCE_KEY);
|
mPreference.setKey(PREFERENCE_KEY);
|
||||||
@@ -75,12 +72,6 @@ public class TopLevelSecurityEntryPreferenceControllerTest {
|
|||||||
new TopLevelSecurityEntryPreferenceController(mContext, PREFERENCE_KEY);
|
new TopLevelSecurityEntryPreferenceController(mContext, PREFERENCE_KEY);
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
|
||||||
public void tearDown() {
|
|
||||||
DeviceConfig.resetToDefaults(Settings.RESET_MODE_PACKAGE_DEFAULTS,
|
|
||||||
DeviceConfig.NAMESPACE_PRIVACY);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void handlePreferenceTreeClick_forDifferentPreferenceKey_isNotHandled() {
|
public void handlePreferenceTreeClick_forDifferentPreferenceKey_isNotHandled() {
|
||||||
Preference preference = new Preference(ApplicationProvider.getApplicationContext());
|
Preference preference = new Preference(ApplicationProvider.getApplicationContext());
|
||||||
@@ -137,11 +128,7 @@ public class TopLevelSecurityEntryPreferenceControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getAvailabilityStatus_whenSafetyCenterEnabled_returnsUnavailable() {
|
public void getAvailabilityStatus_whenSafetyCenterEnabled_returnsUnavailable() {
|
||||||
DeviceConfig.setProperty(
|
when(mSafetyCenterStatusHolder.isEnabled(any(Context.class))).thenReturn(true);
|
||||||
DeviceConfig.NAMESPACE_PRIVACY,
|
|
||||||
SafetyCenterStatus.SAFETY_CENTER_IS_ENABLED,
|
|
||||||
/* value = */ Boolean.toString(true),
|
|
||||||
/* makeDefault = */ false);
|
|
||||||
|
|
||||||
assertThat(mTopLevelSecurityEntryPreferenceController.getAvailabilityStatus())
|
assertThat(mTopLevelSecurityEntryPreferenceController.getAvailabilityStatus())
|
||||||
.isEqualTo(TopLevelSecurityEntryPreferenceController.CONDITIONALLY_UNAVAILABLE);
|
.isEqualTo(TopLevelSecurityEntryPreferenceController.CONDITIONALLY_UNAVAILABLE);
|
||||||
@@ -149,11 +136,7 @@ public class TopLevelSecurityEntryPreferenceControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getAvailabilityStatus_whenSafetyCenterDisabled_returnsAvailable() {
|
public void getAvailabilityStatus_whenSafetyCenterDisabled_returnsAvailable() {
|
||||||
DeviceConfig.setProperty(
|
when(mSafetyCenterStatusHolder.isEnabled(any(Context.class))).thenReturn(false);
|
||||||
DeviceConfig.NAMESPACE_PRIVACY,
|
|
||||||
SafetyCenterStatus.SAFETY_CENTER_IS_ENABLED,
|
|
||||||
/* value = */ Boolean.toString(false),
|
|
||||||
/* makeDefault = */ false);
|
|
||||||
|
|
||||||
assertThat(mTopLevelSecurityEntryPreferenceController.getAvailabilityStatus())
|
assertThat(mTopLevelSecurityEntryPreferenceController.getAvailabilityStatus())
|
||||||
.isEqualTo(TopLevelSecurityEntryPreferenceController.AVAILABLE);
|
.isEqualTo(TopLevelSecurityEntryPreferenceController.AVAILABLE);
|
||||||
|
Reference in New Issue
Block a user