Merge "Fix Learn more link placement is wrong problem" into sc-dev
diff --git a/src/com/android/settings/accounts/EnterpriseDisclosurePreferenceController.java b/src/com/android/settings/accounts/EnterpriseDisclosurePreferenceController.java
index b4dbf3d..238e937 100644
--- a/src/com/android/settings/accounts/EnterpriseDisclosurePreferenceController.java
+++ b/src/com/android/settings/accounts/EnterpriseDisclosurePreferenceController.java
@@ -17,16 +17,19 @@
package com.android.settings.accounts;
import android.content.Context;
+import android.content.Intent;
+import android.provider.Settings;
import androidx.annotation.VisibleForTesting;
-import androidx.preference.Preference;
+import androidx.preference.PreferenceScreen;
+import com.android.settings.R;
import com.android.settings.core.BasePreferenceController;
import com.android.settings.enterprise.EnterprisePrivacyFeatureProvider;
import com.android.settings.overlay.FeatureFactory;
+import com.android.settingslib.widget.FooterPreference;
public class EnterpriseDisclosurePreferenceController extends BasePreferenceController {
-
private final EnterprisePrivacyFeatureProvider mFeatureProvider;
public EnterpriseDisclosurePreferenceController(Context context, String key) {
@@ -37,6 +40,16 @@
}
@Override
+ public void displayPreference(PreferenceScreen screen) {
+ super.displayPreference(screen);
+ final CharSequence disclosure = getDisclosure();
+ if (disclosure == null) {
+ return;
+ }
+ updateFooterPreference(screen, disclosure);
+ }
+
+ @Override
public int getAvailabilityStatus() {
if (getDisclosure() == null) {
return UNSUPPORTED_ON_DEVICE;
@@ -49,12 +62,18 @@
return mFeatureProvider.getDeviceOwnerDisclosure();
}
- @Override
- public void updateState(Preference preference) {
- final CharSequence disclosure = getDisclosure();
- if (disclosure == null) {
- return;
- }
- preference.setTitle(disclosure);
+ void updateFooterPreference(PreferenceScreen screen, CharSequence disclosure) {
+ final FooterPreference footerPreference = screen.findPreference(getPreferenceKey());
+ footerPreference.setTitle(disclosure);
+ footerPreference.setLearnMoreAction(view -> {
+ mContext.startActivity(new Intent(Settings.ACTION_ENTERPRISE_PRIVACY_SETTINGS));
+ });
+ final String learnMoreContentDescription = mContext.getString(
+ R.string.footer_learn_more_content_description, getLabelName());
+ footerPreference.setLearnMoreContentDescription(learnMoreContentDescription);
+ }
+
+ private String getLabelName() {
+ return mContext.getString(R.string.header_add_an_account);
}
}
diff --git a/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImpl.java b/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImpl.java
index f461fe1..7d722fc 100644
--- a/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImpl.java
+++ b/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImpl.java
@@ -100,9 +100,6 @@
} else {
disclosure.append(mResources.getString(R.string.do_disclosure_generic));
}
- disclosure.append(mResources.getString(R.string.do_disclosure_learn_more_separator));
- disclosure.append(mResources.getString(R.string.learn_more),
- new EnterprisePrivacySpan(mContext), 0);
return disclosure;
}
diff --git a/tests/robotests/src/com/android/settings/accounts/EnterpriseDisclosurePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/accounts/EnterpriseDisclosurePreferenceControllerTest.java
index b10a729..8860cfe 100644
--- a/tests/robotests/src/com/android/settings/accounts/EnterpriseDisclosurePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/accounts/EnterpriseDisclosurePreferenceControllerTest.java
@@ -19,20 +19,25 @@
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
import android.content.Context;
-import androidx.preference.Preference;
+import androidx.preference.PreferenceScreen;
import com.android.settings.core.BasePreferenceController;
+import com.android.settingslib.widget.FooterPreference;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
@@ -42,13 +47,18 @@
private Context mContext;
private EnterpriseDisclosurePreferenceController mController;
- private Preference mPreference;
+ private FooterPreference mPreference;
+
+ @Mock
+ private PreferenceScreen mPreferenceScreen;
@Before
public void setUp() {
+ MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
mController = spy(new EnterpriseDisclosurePreferenceController(mContext, "my_key"));
- mPreference = spy(new Preference(mContext));
+ mPreference = spy(new FooterPreference(mContext));
+ when(mPreferenceScreen.findPreference(anyString())).thenReturn(mPreference);
}
@Test
@@ -68,19 +78,19 @@
}
@Test
- public void updateState_hasDisclosure_shouldSetTitle() {
+ public void displayPreference_hasDisclosure_shouldSetTitle() {
doReturn(TEST_DISCLOSURE).when(mController).getDisclosure();
- mController.updateState(mPreference);
+ mController.displayPreference(mPreferenceScreen);
assertThat(mPreference.getTitle()).isEqualTo(TEST_DISCLOSURE);
}
@Test
- public void updateState_noDisclosure_shouldBeInvisible() {
+ public void displayPreference_noDisclosure_shouldBeInvisible() {
doReturn(null).when(mController).getDisclosure();
- mController.updateState(mPreference);
+ mController.displayPreference(mPreferenceScreen);
verify(mPreference, never()).setTitle(any());
}