Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 77f5ad5c authored by wayneyang's avatar wayneyang
Browse files

Fix "Send feedback about this device" option is missing issue.

When device restart & launching "Feedback" from lock screen,
the "send feedback" option will be missing. It's because
the report package cannot be found by calling from lock screen.
Update the option visibility after updatestate and add test case.

Bug: 74076963
Test: Manual test and RunSettingsRoboTests:FeedbackPreferenceControllerTest
Change-Id: I105d6f90da499423b6881f2ba808e69bd2e8595d
parent cbf9300c
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ public class FeedbackPreferenceController extends AbstractPreferenceController i
        intent = new Intent("android.intent.action.BUG_REPORT");
    }

    @Override
    public boolean isAvailable() {
        return !TextUtils.isEmpty(DeviceInfoUtils.getFeedbackReporterPackage(mContext));
    }
@@ -47,6 +48,15 @@ public class FeedbackPreferenceController extends AbstractPreferenceController i
        super.updateState(preference);
        intent.setPackage(DeviceInfoUtils.getFeedbackReporterPackage(mContext));
        preference.setIntent(intent);

        // In some cases, cannot retrieve the report package from package manager,
        // For example, launched from lock screen.
        // Update this preference visibility after updateState.
        if (isAvailable() && !preference.isVisible()) {
            preference.setVisible(true);
        } else if (!isAvailable() && preference.isVisible()){
            preference.setVisible(false);
        }
    }

    public String getPreferenceKey() {
+15 −0
Original line number Diff line number Diff line
@@ -21,6 +21,8 @@ import static org.mockito.Mockito.when;

import android.app.Fragment;
import android.content.Context;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;

import com.android.settings.testutils.SettingsRobolectricTestRunner;

@@ -38,12 +40,19 @@ public class FeedbackPreferenceControllerTest {
    private Fragment mFragment;
    @Mock(answer = Answers.RETURNS_DEEP_STUBS)
    private Context mContext;
    @Mock
    private Preference mPreference;
    @Mock
    private PreferenceScreen mScreen;

    private FeedbackPreferenceController mController;

    @Before
    public void setUp() {
        MockitoAnnotations.initMocks(this);
        mController = new FeedbackPreferenceController(mFragment, mContext);
        final String prefKey = mController.getPreferenceKey();
        when(mScreen.findPreference(prefKey)).thenReturn(mPreference);
    }

    @Test
@@ -51,4 +60,10 @@ public class FeedbackPreferenceControllerTest {
        when(mContext.getResources().getString(anyInt())).thenReturn("");
        assertThat(mController.isAvailable()).isFalse();
    }

    @Test
    public void isVisible_afterUpdateState_shouldBeSameAsIsAvailable() {
        mController.updateState(mPreference);
        assertThat(mPreference.isVisible()).isEqualTo(mController.isAvailable());
    }
}