summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Tomljanovic <jtomljanovic@google.com>2021-04-27 20:58:12 +0100
committerJan Tomljanovic <jtomljanovic@google.com>2021-04-29 17:38:52 +0100
commit07bffff45407aabbd670742c7240eec830b08b10 (patch)
treef65001327a31778d708e1b7d9d1f42f361f5076d
parent6be940f396e22abc5f93c4652e9eee17c8f28803 (diff)
downloadpackages_apps_Settings-07bffff45407aabbd670742c7240eec830b08b10.tar.gz
packages_apps_Settings-07bffff45407aabbd670742c7240eec830b08b10.tar.bz2
packages_apps_Settings-07bffff45407aabbd670742c7240eec830b08b10.zip
Launch SecurityHub fragment on SECURITY_SETTINGS intent when available.
Test: atest SettingsUnitTests Test: adb shell am start -a android.settings.SECURITY_SETTINGS opens SecurityHub screen (when SecurityHub enabled) Test: assistant opens SecurityHub screen (when SecurityHub enabled) when given instrucion to "open security settings" Bug: 183930061 Change-Id: Ie8fcb2f2dce4cd0a2a84c6cd21a0a1c0b2b3665e
-rw-r--r--src/com/android/settings/Settings.java37
-rw-r--r--src/com/android/settings/SettingsActivity.java10
-rw-r--r--tests/unit/src/com/android/settings/security/SecurityDashboardActivityTest.java107
3 files changed, 151 insertions, 3 deletions
diff --git a/src/com/android/settings/Settings.java b/src/com/android/settings/Settings.java
index c89402cb2c..d28f86d079 100644
--- a/src/com/android/settings/Settings.java
+++ b/src/com/android/settings/Settings.java
@@ -19,11 +19,14 @@ package com.android.settings;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
+import android.text.TextUtils;
import android.util.FeatureFlagUtils;
+import com.android.internal.annotations.VisibleForTesting;
import com.android.settings.core.FeatureFlags;
import com.android.settings.enterprise.EnterprisePrivacySettings;
import com.android.settings.overlay.FeatureFactory;
+import com.android.settings.security.SecuritySettingsFeatureProvider;
/**
* Top-level Settings activity
@@ -118,7 +121,39 @@ public class Settings extends SettingsActivity {
* Activity for Reduce Bright Colors.
*/
public static class ReduceBrightColorsSettingsActivity extends SettingsActivity { /* empty */ }
- public static class SecurityDashboardActivity extends SettingsActivity { /* empty */ }
+ /** Activity for the security dashboard. */
+ public static class SecurityDashboardActivity extends SettingsActivity {
+
+ /** Whether the given fragment is allowed. */
+ @VisibleForTesting
+ @Override
+ public boolean isValidFragment(String fragmentName) {
+ return super.isValidFragment(fragmentName)
+ || (fragmentName != null
+ && TextUtils.equals(fragmentName, getAlternativeFragmentName()));
+ }
+
+ @Override
+ public String getInitialFragmentName(Intent intent) {
+ final String alternativeFragmentName = getAlternativeFragmentName();
+ if (alternativeFragmentName != null) {
+ return alternativeFragmentName;
+ }
+
+ return super.getInitialFragmentName(intent);
+ }
+
+ private String getAlternativeFragmentName() {
+ String alternativeFragmentClassname = null;
+ final SecuritySettingsFeatureProvider securitySettingsFeatureProvider =
+ FeatureFactory.getFactory(this).getSecuritySettingsFeatureProvider();
+ if (securitySettingsFeatureProvider.hasAlternativeSecuritySettingsFragment()) {
+ alternativeFragmentClassname = securitySettingsFeatureProvider
+ .getAlternativeSecuritySettingsFragmentClassname();
+ }
+ return alternativeFragmentClassname;
+ }
+ }
public static class UsageAccessSettingsActivity extends SettingsActivity { /* empty */ }
public static class AppUsageAccessSettingsActivity extends SettingsActivity { /* empty */ }
public static class LocationSettingsActivity extends SettingsActivity { /* empty */ }
diff --git a/src/com/android/settings/SettingsActivity.java b/src/com/android/settings/SettingsActivity.java
index b6729179d1..923c2bd719 100644
--- a/src/com/android/settings/SettingsActivity.java
+++ b/src/com/android/settings/SettingsActivity.java
@@ -219,7 +219,7 @@ public class SettingsActivity extends SettingsBaseActivity
private String getMetricsTag() {
String tag = null;
if (getIntent() != null && getIntent().hasExtra(EXTRA_SHOW_FRAGMENT)) {
- tag = getIntent().getStringExtra(EXTRA_SHOW_FRAGMENT);
+ tag = getInitialFragmentName(getIntent());
}
if (TextUtils.isEmpty(tag)) {
Log.w(LOG_TAG, "MetricsTag is invalid " + tag);
@@ -262,7 +262,7 @@ public class SettingsActivity extends SettingsBaseActivity
}
// Getting Intent properties can only be done after the super.onCreate(...)
- final String initialFragmentName = intent.getStringExtra(EXTRA_SHOW_FRAGMENT);
+ final String initialFragmentName = getInitialFragmentName(intent);
// This is a "Sub Settings" when:
// - this is a real SubSettings
@@ -363,6 +363,12 @@ public class SettingsActivity extends SettingsBaseActivity
}
}
+ /** Returns the initial fragment name that the activity will launch. */
+ @VisibleForTesting
+ public String getInitialFragmentName(Intent intent) {
+ return intent.getStringExtra(EXTRA_SHOW_FRAGMENT);
+ }
+
@Override
protected void onApplyThemeResource(Theme theme, int resid, boolean first) {
theme.applyStyle(R.style.SetupWizardPartnerResource, true);
diff --git a/tests/unit/src/com/android/settings/security/SecurityDashboardActivityTest.java b/tests/unit/src/com/android/settings/security/SecurityDashboardActivityTest.java
new file mode 100644
index 0000000000..3bda96e989
--- /dev/null
+++ b/tests/unit/src/com/android/settings/security/SecurityDashboardActivityTest.java
@@ -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.security;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.when;
+
+import android.content.Intent;
+
+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.testutils.FakeFeatureFactory;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.MockitoAnnotations;
+
+@RunWith(AndroidJUnit4.class)
+public class SecurityDashboardActivityTest {
+ private static final String ALTERNATIVE_FRAGMENT_CLASSNAME = "AlternativeFragmentClassname";
+ private static final String DEFAULT_FRAGMENT_CLASSNAME = "DefaultFragmentClassname";
+
+ private SecuritySettingsFeatureProvider mSecuritySettingsFeatureProvider;
+ private Settings.SecurityDashboardActivity mActivity;
+ private Intent mDefaultIntent;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ FakeFeatureFactory mFeatureFactory = FakeFeatureFactory.setupForTest();
+ mSecuritySettingsFeatureProvider = mFeatureFactory.getSecuritySettingsFeatureProvider();
+ mDefaultIntent = new Intent();
+ mDefaultIntent.setAction(android.provider.Settings.ACTION_SECURITY_SETTINGS);
+ mDefaultIntent.setClass(InstrumentationRegistry.getInstrumentation().getTargetContext(),
+ Settings.SecurityDashboardActivity.class);
+ mDefaultIntent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT, DEFAULT_FRAGMENT_CLASSNAME);
+ InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> {
+ try {
+ mActivity =
+ (Settings.SecurityDashboardActivity) InstrumentationRegistry
+ .getInstrumentation().newActivity(
+ getClass().getClassLoader(),
+ Settings.SecurityDashboardActivity.class.getName(),
+ mDefaultIntent);
+ } catch (Exception e) {
+ throw new RuntimeException(e); // nothing to do
+ }
+ });
+ }
+
+ @Test
+ public void noAvailableAlternativeFragmentAvailable_defaultFragmentSet() {
+ when(mSecuritySettingsFeatureProvider.hasAlternativeSecuritySettingsFragment())
+ .thenReturn(false);
+
+ assertThat(mActivity.getInitialFragmentName(mDefaultIntent))
+ .isEqualTo(DEFAULT_FRAGMENT_CLASSNAME);
+ }
+
+ @Test
+ public void alternativeFragmentAvailable_alternativeFragmentSet() {
+ when(mSecuritySettingsFeatureProvider.hasAlternativeSecuritySettingsFragment())
+ .thenReturn(true);
+ when(mSecuritySettingsFeatureProvider.getAlternativeSecuritySettingsFragmentClassname())
+ .thenReturn(ALTERNATIVE_FRAGMENT_CLASSNAME);
+
+ assertThat(mActivity.getInitialFragmentName(mDefaultIntent))
+ .isEqualTo(ALTERNATIVE_FRAGMENT_CLASSNAME);
+ }
+
+ @Test
+ public void noAvailableAlternativeFragmentAvailable_alternativeFragmentNotValid() {
+ when(mSecuritySettingsFeatureProvider.hasAlternativeSecuritySettingsFragment())
+ .thenReturn(false);
+
+ assertThat(mActivity.isValidFragment(ALTERNATIVE_FRAGMENT_CLASSNAME)).isFalse();
+ }
+
+ @Test
+ public void alternativeFragmentAvailable_alternativeFragmentIsValid() {
+ when(mSecuritySettingsFeatureProvider.hasAlternativeSecuritySettingsFragment())
+ .thenReturn(true);
+ when(mSecuritySettingsFeatureProvider.getAlternativeSecuritySettingsFragmentClassname())
+ .thenReturn(ALTERNATIVE_FRAGMENT_CLASSNAME);
+
+ assertThat(mActivity.isValidFragment(ALTERNATIVE_FRAGMENT_CLASSNAME)).isTrue();
+ }
+}