Adds 'App info' button on accessibility service + activity pages.
This launches the existing app info page for the a11y feature's owning package. Features without a valid component (framework features) do not have this button. This is also not shown in Setup Wizard which does not support the App Info page. This helps users find more info about the app that provided an accessibility feature. Screenshot: https://screenshot.googleplex.com/B9FXLoomxFjLBv8.png Flag: accessibility com.android.settings.flags.accessibility_show_app_info_button Bug: 277378550 Test: atest ToggleFeaturePreferenceFragmentTest (robotest) Test: Open and interact with the button, ensure it opens the app info page for the correct app. Change-Id: I2041c09077ce5fadc72117dc0c72409dd33ef60b
This commit is contained in:
@@ -32,7 +32,12 @@ import android.content.ComponentName;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Bundle;
|
||||
import android.platform.test.annotations.RequiresFlagsEnabled;
|
||||
import android.platform.test.flag.junit.CheckFlagsRule;
|
||||
import android.platform.test.flag.junit.DeviceFlagsValueProvider;
|
||||
import android.provider.Settings;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
@@ -42,6 +47,7 @@ import android.widget.PopupWindow;
|
||||
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceManager;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
@@ -50,10 +56,12 @@ import com.android.settings.R;
|
||||
import com.android.settings.accessibility.AccessibilityDialogUtils.DialogType;
|
||||
import com.android.settings.accessibility.AccessibilityUtil.QuickSettingsTooltipType;
|
||||
import com.android.settings.accessibility.AccessibilityUtil.UserShortcutType;
|
||||
import com.android.settings.flags.Flags;
|
||||
import com.android.settings.testutils.shadow.ShadowFragment;
|
||||
import com.android.settingslib.widget.TopIntroPreference;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Answers;
|
||||
@@ -74,6 +82,9 @@ import org.robolectric.shadows.ShadowApplication;
|
||||
})
|
||||
public class ToggleFeaturePreferenceFragmentTest {
|
||||
|
||||
@Rule
|
||||
public final CheckFlagsRule mCheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule();
|
||||
|
||||
private static final String PLACEHOLDER_PACKAGE_NAME = "com.placeholder.example";
|
||||
private static final String PLACEHOLDER_CLASS_NAME = PLACEHOLDER_PACKAGE_NAME + ".placeholder";
|
||||
private static final ComponentName PLACEHOLDER_COMPONENT_NAME = new ComponentName(
|
||||
@@ -105,6 +116,8 @@ public class ToggleFeaturePreferenceFragmentTest {
|
||||
private FragmentActivity mActivity;
|
||||
@Mock
|
||||
private ContentResolver mContentResolver;
|
||||
@Mock
|
||||
private PackageManager mPackageManager;
|
||||
|
||||
@Before
|
||||
public void setUpTestFragment() {
|
||||
@@ -116,6 +129,7 @@ public class ToggleFeaturePreferenceFragmentTest {
|
||||
when(mFragment.getContext()).thenReturn(mContext);
|
||||
when(mFragment.getActivity()).thenReturn(mActivity);
|
||||
when(mActivity.getContentResolver()).thenReturn(mContentResolver);
|
||||
when(mContext.getPackageManager()).thenReturn(mPackageManager);
|
||||
final PreferenceScreen screen = spy(new PreferenceScreen(mContext, null));
|
||||
when(screen.getPreferenceManager()).thenReturn(mPreferenceManager);
|
||||
doReturn(screen).when(mFragment).getPreferenceScreen();
|
||||
@@ -317,6 +331,53 @@ public class ToggleFeaturePreferenceFragmentTest {
|
||||
assertThat(mFragment.getPreferenceScreen().getPreferenceCount()).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@RequiresFlagsEnabled(Flags.FLAG_ACCESSIBILITY_SHOW_APP_INFO_BUTTON)
|
||||
public void createAppInfoPreference_withValidComponentName() {
|
||||
when(mPackageManager.isPackageAvailable(PLACEHOLDER_PACKAGE_NAME)).thenReturn(true);
|
||||
mFragment.mComponentName = PLACEHOLDER_COMPONENT_NAME;
|
||||
|
||||
final Preference preference = mFragment.createAppInfoPreference();
|
||||
|
||||
assertThat(preference).isNotNull();
|
||||
final Intent appInfoIntent = preference.getIntent();
|
||||
assertThat(appInfoIntent.getAction())
|
||||
.isEqualTo(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
|
||||
assertThat(appInfoIntent.getDataString()).isEqualTo("package:" + PLACEHOLDER_PACKAGE_NAME);
|
||||
}
|
||||
|
||||
@Test
|
||||
@RequiresFlagsEnabled(Flags.FLAG_ACCESSIBILITY_SHOW_APP_INFO_BUTTON)
|
||||
public void createAppInfoPreference_noComponentName_shouldBeNull() {
|
||||
mFragment.mComponentName = null;
|
||||
|
||||
final Preference preference = mFragment.createAppInfoPreference();
|
||||
|
||||
assertThat(preference).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@RequiresFlagsEnabled(Flags.FLAG_ACCESSIBILITY_SHOW_APP_INFO_BUTTON)
|
||||
public void createAppInfoPreference_withUnavailablePackage_shouldBeNull() {
|
||||
when(mPackageManager.isPackageAvailable(PLACEHOLDER_PACKAGE_NAME)).thenReturn(false);
|
||||
mFragment.mComponentName = PLACEHOLDER_COMPONENT_NAME;
|
||||
|
||||
final Preference preference = mFragment.createAppInfoPreference();
|
||||
|
||||
assertThat(preference).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@RequiresFlagsEnabled(Flags.FLAG_ACCESSIBILITY_SHOW_APP_INFO_BUTTON)
|
||||
public void createAppInfoPreference_inSetupWizard_shouldBeNull() {
|
||||
when(mFragment.isAnySetupWizard()).thenReturn(true);
|
||||
mFragment.mComponentName = PLACEHOLDER_COMPONENT_NAME;
|
||||
|
||||
final Preference preference = mFragment.createAppInfoPreference();
|
||||
|
||||
assertThat(preference).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createFooterPreference_shouldSetAsExpectedValue() {
|
||||
mFragment.createFooterPreference(mFragment.getPreferenceScreen(),
|
||||
|
Reference in New Issue
Block a user