Add entrypoint for Learn More in PS settings & Setup intro
Screenshots:
go/ss/RXhN57DSuSj7aQf.png
go/ss/5xcbx3mWeo2sZ37.png
Bug: 326059389
Test: atest PrivateSpaceFooterPreferenceControllerTest
Change-Id: I72beb1a04ea11909643dd6b455575478cfb5d87c
diff --git a/res/layout/private_space_education_screen.xml b/res/layout/private_space_education_screen.xml
index 8fb486e..6b65103 100644
--- a/res/layout/private_space_education_screen.xml
+++ b/res/layout/private_space_education_screen.xml
@@ -93,10 +93,19 @@
android:layout_height="18dp"
android:src="@drawable/ic_info_outline_24dp" />
<TextView
+ android:id="@+id/info"
style="@style/PrivateSpaceBulletPointTextFontStyle"
android:textSize = "14sp"
android:layout_toRightOf="@+id/infoIcon"
android:text="@string/private_space_apps_permission_text"/>
+ <TextView
+ android:id="@+id/learn_more"
+ style="@style/PrivateSpaceSetupSubHeaderStyle"
+ android:layout_below="@id/info"
+ android:layout_alignLeft="@+id/info"
+ android:paddingTop="24dp"
+ android:paddingLeft="16dp"
+ android:text="@string/private_space_learn_more_text"/>
</RelativeLayout>
</LinearLayout>
</ScrollView>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index f26939e..42d425f 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -1311,6 +1311,9 @@
<string name="private_space_install_apps_text"><b>Install apps</b>\nYour private space has its own Play Store so you can install apps easily.</string>
<!-- This is info text to help explain in private space setup screen that the permissions granted to private space apps will not be shown in settings when private space is locked. [CHAR LIMIT=NONE] -->
<string name="private_space_apps_permission_text">Apps in your private space won\'t appear in permission manager, privacy dashboard, and other settings when your private space is locked.\n\nYour private space can\'t be moved to a new device. You\'ll need to set up another private space if you want to use it on another device.\n\nAnyone that connects your device to a computer or installs harmful apps on your device may be able to access your private space.</string>
+ <!-- Private space footer link content description [CHAR LIMIT=40] -->
+ <string name="private_space_learn_more_text">Learn more about private space</string>
+ <string name="private_space_learn_more_url" translatable="false">https://support.google.com/android?p=private_space</string>
<!-- Text shown at the bottom in private space auto advancing screens. [CHAR LIMIT=60] -->
<string name="private_space_setting_up_text">Setting up private space\u2026</string>
<!-- Title for private space setup in auto advancing screen informing private space notifications are hidden when locked. [CHAR LIMIT=NONE] -->
diff --git a/res/xml/private_space_settings.xml b/res/xml/private_space_settings.xml
index 93c016b..86537cc 100644
--- a/res/xml/private_space_settings.xml
+++ b/res/xml/private_space_settings.xml
@@ -81,10 +81,12 @@
</PreferenceCategory>
- <com.android.settings.accessibility.AccessibilityFooterPreference
+ <com.android.settingslib.widget.FooterPreference
android:key="private_space_footer"
android:title="@string/private_space_apps_permission_text"
android:selectable="false"
- settings:searchable="false"/>
+ settings:searchable="false"
+ settings:controller="com.android.settings.privatespace.PrivateSpaceFooterPreferenceController"/>
+
</PreferenceScreen>
diff --git a/src/com/android/settings/privatespace/PrivateSpaceEducation.java b/src/com/android/settings/privatespace/PrivateSpaceEducation.java
index cf22895..a21aac3 100644
--- a/src/com/android/settings/privatespace/PrivateSpaceEducation.java
+++ b/src/com/android/settings/privatespace/PrivateSpaceEducation.java
@@ -19,10 +19,12 @@
import android.app.Activity;
import android.app.settings.SettingsEnums;
import android.os.Bundle;
+import android.text.util.Linkify;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
+import android.widget.TextView;
import androidx.annotation.Nullable;
import androidx.navigation.fragment.NavHostFragment;
@@ -34,6 +36,8 @@
import com.google.android.setupcompat.template.FooterButton;
import com.google.android.setupdesign.GlifLayout;
+import java.util.regex.Pattern;
+
/** Fragment educating about the usage of Private Space. */
public class PrivateSpaceEducation extends InstrumentedFragment {
private static final String TAG = "PrivateSpaceEducation";
@@ -66,6 +70,13 @@
.setTheme(com.google.android.setupdesign.R.style.SudGlifButton_Secondary)
.build());
+ TextView infoTextView = rootView.findViewById(R.id.learn_more);
+ Pattern pattern = Pattern.compile(infoTextView.getText().toString());
+ Linkify.addLinks(
+ infoTextView,
+ pattern,
+ getContext().getString(R.string.private_space_learn_more_url));
+
return rootView;
}
diff --git a/src/com/android/settings/privatespace/PrivateSpaceFooterPreferenceController.java b/src/com/android/settings/privatespace/PrivateSpaceFooterPreferenceController.java
new file mode 100644
index 0000000..71139ba
--- /dev/null
+++ b/src/com/android/settings/privatespace/PrivateSpaceFooterPreferenceController.java
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2024 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.privatespace;
+
+import android.content.Context;
+import android.text.TextUtils;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.VisibleForTesting;
+import androidx.preference.PreferenceScreen;
+
+import com.android.settings.R;
+import com.android.settings.core.BasePreferenceController;
+import com.android.settingslib.HelpUtils;
+import com.android.settingslib.widget.FooterPreference;
+
+/** Preference controller for private space settings footer. */
+public class PrivateSpaceFooterPreferenceController extends BasePreferenceController {
+ public PrivateSpaceFooterPreferenceController(
+ @NonNull Context context, @NonNull String preferenceKey) {
+ super(context, preferenceKey);
+ }
+
+ @Override
+ public void displayPreference(@NonNull PreferenceScreen screen) {
+ super.displayPreference(screen);
+ FooterPreference preference = screen.findPreference(getPreferenceKey());
+ setupFooter(preference);
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ return android.multiuser.Flags.enablePrivateSpaceFeatures()
+ ? AVAILABLE
+ : UNSUPPORTED_ON_DEVICE;
+ }
+
+ @VisibleForTesting
+ void setupFooter(FooterPreference preference) {
+ final String helpUri = mContext.getString(R.string.private_space_learn_more_url);
+ if (!TextUtils.isEmpty(helpUri) && preference != null) {
+ preference.setLearnMoreAction(
+ v -> {
+ mContext.startActivity(
+ HelpUtils.getHelpIntent(
+ mContext, helpUri, /* backupContext= */ ""));
+ });
+ preference.setLearnMoreText(mContext.getString(R.string.private_space_learn_more_text));
+ }
+ }
+}
diff --git a/tests/unit/src/com/android/settings/privatespace/PrivateSpaceFooterPreferenceControllerTest.java b/tests/unit/src/com/android/settings/privatespace/PrivateSpaceFooterPreferenceControllerTest.java
new file mode 100644
index 0000000..30215da
--- /dev/null
+++ b/tests/unit/src/com/android/settings/privatespace/PrivateSpaceFooterPreferenceControllerTest.java
@@ -0,0 +1,80 @@
+/*
+ * Copyright (C) 2024 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.privatespace;
+
+import static com.android.settings.core.BasePreferenceController.AVAILABLE;
+import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.verify;
+
+import android.content.Context;
+import android.platform.test.flag.junit.SetFlagsRule;
+
+import androidx.test.core.app.ApplicationProvider;
+import androidx.test.ext.junit.runners.AndroidJUnit4;
+
+import com.android.settingslib.widget.FooterPreference;
+
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+
+@RunWith(AndroidJUnit4.class)
+public class PrivateSpaceFooterPreferenceControllerTest {
+ @Mock private Context mContext;
+ @Mock FooterPreference mFooterPreference;
+ @Rule public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
+ private PrivateSpaceFooterPreferenceController mController;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mContext = ApplicationProvider.getApplicationContext();
+ final String preferenceKey = "private_space_footer";
+
+ mController = new PrivateSpaceFooterPreferenceController(mContext, preferenceKey);
+ }
+
+ @Test
+ public void getAvailabilityStatus_whenFlagsEnabled_returnsAvailable() {
+ mSetFlagsRule.enableFlags(android.multiuser.Flags.FLAG_ENABLE_PRIVATE_SPACE_FEATURES);
+
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
+ }
+
+ @Test
+ public void getAvailabilityStatus_whenFlagsDisabled_returnsUnsupportedOnDevice() {
+ mSetFlagsRule.disableFlags(android.multiuser.Flags.FLAG_ENABLE_PRIVATE_SPACE_FEATURES);
+
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
+ }
+
+ @Test
+ public void setUpFooter_setsLearnMoreTextAndAction() {
+ mSetFlagsRule.enableFlags(android.multiuser.Flags.FLAG_ENABLE_PRIVATE_SPACE_FEATURES);
+
+ mController.setupFooter(mFooterPreference);
+ verify(mFooterPreference).setLearnMoreAction(any());
+ verify(mFooterPreference).setLearnMoreText("Learn more about private space");
+ }
+}