Merge "Redirect intents leading to Security and Privacy pages"
This commit is contained in:
committed by
Android (Google) Code Review
commit
14bbac9424
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package com.android.settings;
|
package com.android.settings;
|
||||||
|
|
||||||
|
import android.content.ActivityNotFoundException;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@@ -24,6 +25,7 @@ import android.telephony.SubscriptionManager;
|
|||||||
import android.telephony.ims.ImsRcsManager;
|
import android.telephony.ims.ImsRcsManager;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.FeatureFlagUtils;
|
import android.util.FeatureFlagUtils;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
import com.android.internal.annotations.VisibleForTesting;
|
import com.android.internal.annotations.VisibleForTesting;
|
||||||
import com.android.settings.core.FeatureFlags;
|
import com.android.settings.core.FeatureFlags;
|
||||||
@@ -31,6 +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.security.SecuritySettingsFeatureProvider;
|
import com.android.settings.security.SecuritySettingsFeatureProvider;
|
||||||
|
|
||||||
import com.google.android.setupdesign.util.ThemeHelper;
|
import com.google.android.setupdesign.util.ThemeHelper;
|
||||||
@@ -136,6 +139,27 @@ public class Settings extends SettingsActivity {
|
|||||||
/** Activity for the security dashboard. */
|
/** Activity for the security dashboard. */
|
||||||
public static class SecurityDashboardActivity extends SettingsActivity {
|
public static class SecurityDashboardActivity extends SettingsActivity {
|
||||||
|
|
||||||
|
private static final String TAG = "SecurityDashboardActivity";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedState) {
|
||||||
|
super.onCreate(savedState);
|
||||||
|
handleSafetyCenterRedirection();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Redirects to SafetyCenter if enabled. */
|
||||||
|
@VisibleForTesting
|
||||||
|
public void handleSafetyCenterRedirection() {
|
||||||
|
if (SafetyCenterStatus.isEnabled()) {
|
||||||
|
try {
|
||||||
|
startActivity(new Intent(Intent.ACTION_SAFETY_CENTER));
|
||||||
|
finish();
|
||||||
|
} catch (ActivityNotFoundException e) {
|
||||||
|
Log.e(TAG, "Unable to open safety center", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** Whether the given fragment is allowed. */
|
/** Whether the given fragment is allowed. */
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
@Override
|
@Override
|
||||||
@@ -171,7 +195,30 @@ public class Settings extends SettingsActivity {
|
|||||||
public static class LocationSettingsActivity extends SettingsActivity { /* empty */ }
|
public static class LocationSettingsActivity extends SettingsActivity { /* empty */ }
|
||||||
public static class ScanningSettingsActivity extends SettingsActivity { /* empty */ }
|
public static class ScanningSettingsActivity extends SettingsActivity { /* empty */ }
|
||||||
public static class WifiScanningSettingsActivity extends SettingsActivity { /* empty */ }
|
public static class WifiScanningSettingsActivity extends SettingsActivity { /* empty */ }
|
||||||
public static class PrivacyDashboardActivity extends SettingsActivity { /* empty */ }
|
/** Activity for the privacy dashboard. */
|
||||||
|
public static class PrivacyDashboardActivity extends SettingsActivity {
|
||||||
|
|
||||||
|
private static final String TAG = "PrivacyDashboardActivity";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedState) {
|
||||||
|
super.onCreate(savedState);
|
||||||
|
handleSafetyCenterRedirection();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Redirects to SafetyCenter if enabled. */
|
||||||
|
@VisibleForTesting
|
||||||
|
public void handleSafetyCenterRedirection() {
|
||||||
|
if (SafetyCenterStatus.isEnabled()) {
|
||||||
|
try {
|
||||||
|
startActivity(new Intent(Intent.ACTION_SAFETY_CENTER));
|
||||||
|
finish();
|
||||||
|
} catch (ActivityNotFoundException e) {
|
||||||
|
Log.e(TAG, "Unable to open safety center", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
public static class PrivacySettingsActivity extends SettingsActivity { /* empty */ }
|
public static class PrivacySettingsActivity extends SettingsActivity { /* empty */ }
|
||||||
public static class FactoryResetActivity extends SettingsActivity {
|
public static class FactoryResetActivity extends SettingsActivity {
|
||||||
@Override
|
@Override
|
||||||
|
@@ -0,0 +1,107 @@
|
|||||||
|
/*
|
||||||
|
* 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.privacy;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
|
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 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 org.junit.After;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.ArgumentCaptor;
|
||||||
|
|
||||||
|
@RunWith(AndroidJUnit4.class)
|
||||||
|
public class PrivacyDashboardActivityTest {
|
||||||
|
|
||||||
|
private static final String DEFAULT_FRAGMENT_CLASSNAME = "DefaultFragmentClassname";
|
||||||
|
|
||||||
|
private Settings.PrivacyDashboardActivity mActivity;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
DeviceConfig.resetToDefaults(android.provider.Settings.RESET_MODE_PACKAGE_DEFAULTS,
|
||||||
|
DeviceConfig.NAMESPACE_PRIVACY);
|
||||||
|
final Intent intent = new Intent();
|
||||||
|
intent.setAction(android.provider.Settings.ACTION_PRIVACY_SETTINGS);
|
||||||
|
intent.setClass(InstrumentationRegistry.getInstrumentation().getTargetContext(),
|
||||||
|
Settings.PrivacyDashboardActivity.class);
|
||||||
|
intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT, DEFAULT_FRAGMENT_CLASSNAME);
|
||||||
|
InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> {
|
||||||
|
try {
|
||||||
|
mActivity =
|
||||||
|
spy((Settings.PrivacyDashboardActivity) InstrumentationRegistry
|
||||||
|
.getInstrumentation().newActivity(
|
||||||
|
getClass().getClassLoader(),
|
||||||
|
Settings.PrivacyDashboardActivity.class.getName(),
|
||||||
|
intent));
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e); // nothing to do
|
||||||
|
}
|
||||||
|
});
|
||||||
|
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);
|
||||||
|
final ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
|
||||||
|
|
||||||
|
mActivity.handleSafetyCenterRedirection();
|
||||||
|
|
||||||
|
verify(mActivity).startActivity(intentCaptor.capture());
|
||||||
|
assertThat(intentCaptor.getValue().getAction()).isEqualTo(Intent.ACTION_SAFETY_CENTER);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onCreate_whenSafetyCenterDisabled_doesntRedirectToSafetyCenter() {
|
||||||
|
DeviceConfig.setProperty(
|
||||||
|
DeviceConfig.NAMESPACE_PRIVACY,
|
||||||
|
SafetyCenterStatus.SAFETY_CENTER_IS_ENABLED,
|
||||||
|
/* value = */ Boolean.toString(false),
|
||||||
|
/* makeDefault = */ false);
|
||||||
|
|
||||||
|
mActivity.handleSafetyCenterRedirection();
|
||||||
|
|
||||||
|
verify(mActivity, times(0)).startActivity(any());
|
||||||
|
}
|
||||||
|
}
|
@@ -18,20 +18,29 @@ 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.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 static org.mockito.Mockito.when;
|
||||||
|
|
||||||
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.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.MockitoAnnotations;
|
import org.mockito.MockitoAnnotations;
|
||||||
|
|
||||||
@RunWith(AndroidJUnit4.class)
|
@RunWith(AndroidJUnit4.class)
|
||||||
@@ -48,6 +57,8 @@ public class SecurityDashboardActivityTest {
|
|||||||
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,
|
||||||
|
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(),
|
||||||
@@ -56,15 +67,22 @@ public class SecurityDashboardActivityTest {
|
|||||||
InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> {
|
InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> {
|
||||||
try {
|
try {
|
||||||
mActivity =
|
mActivity =
|
||||||
(Settings.SecurityDashboardActivity) InstrumentationRegistry
|
spy((Settings.SecurityDashboardActivity) InstrumentationRegistry
|
||||||
.getInstrumentation().newActivity(
|
.getInstrumentation().newActivity(
|
||||||
getClass().getClassLoader(),
|
getClass().getClassLoader(),
|
||||||
Settings.SecurityDashboardActivity.class.getName(),
|
Settings.SecurityDashboardActivity.class.getName(),
|
||||||
mDefaultIntent);
|
mDefaultIntent));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(e); // nothing to do
|
throw new RuntimeException(e); // nothing to do
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
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
|
||||||
@@ -104,4 +122,32 @@ public class SecurityDashboardActivityTest {
|
|||||||
|
|
||||||
assertThat(mActivity.isValidFragment(ALTERNATIVE_FRAGMENT_CLASSNAME)).isTrue();
|
assertThat(mActivity.isValidFragment(ALTERNATIVE_FRAGMENT_CLASSNAME)).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onCreate_whenSafetyCenterEnabled_redirectsToSafetyCenter() {
|
||||||
|
DeviceConfig.setProperty(
|
||||||
|
DeviceConfig.NAMESPACE_PRIVACY,
|
||||||
|
SafetyCenterStatus.SAFETY_CENTER_IS_ENABLED,
|
||||||
|
/* value = */ Boolean.toString(true),
|
||||||
|
/* makeDefault = */ false);
|
||||||
|
final ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
|
||||||
|
|
||||||
|
mActivity.handleSafetyCenterRedirection();
|
||||||
|
|
||||||
|
verify(mActivity).startActivity(intentCaptor.capture());
|
||||||
|
assertThat(intentCaptor.getValue().getAction()).isEqualTo(Intent.ACTION_SAFETY_CENTER);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onCreate_whenSafetyCenterDisabled_doesntRedirectToSafetyCenter() {
|
||||||
|
DeviceConfig.setProperty(
|
||||||
|
DeviceConfig.NAMESPACE_PRIVACY,
|
||||||
|
SafetyCenterStatus.SAFETY_CENTER_IS_ENABLED,
|
||||||
|
/* value = */ Boolean.toString(false),
|
||||||
|
/* makeDefault = */ false);
|
||||||
|
|
||||||
|
mActivity.handleSafetyCenterRedirection();
|
||||||
|
|
||||||
|
verify(mActivity, times(0)).startActivity(any());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user