Support apply override feature in SupportPreferenceController
- Let SupportPreferenceController call SupportFeatureProvider#applyOverrides to override Support preference. Bug: 397691102 Change-Id: I16fefe3058d5f3f318ed4a5aa6aa4868012be505 Test: MANUAL Flag: EXEMPT no-op new APIs for partner override
This commit is contained in:
@@ -17,6 +17,10 @@
|
||||
package com.android.settings.overlay;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.preference.Preference;
|
||||
|
||||
/**
|
||||
* Feature provider for support tab.
|
||||
@@ -29,4 +33,13 @@ public interface SupportFeatureProvider {
|
||||
* @param activity Calling activity.
|
||||
*/
|
||||
void startSupport(Activity activity);
|
||||
|
||||
/**
|
||||
* Applies overrides to the support preference, if needed.
|
||||
*
|
||||
* @param context Preference controller context.
|
||||
* @param pref The support preference.
|
||||
*/
|
||||
default void applyOverrides(@NonNull Context context, @NonNull Preference pref) {
|
||||
}
|
||||
}
|
||||
|
@@ -21,6 +21,7 @@ import android.content.Context;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
@@ -56,4 +57,13 @@ public class SupportPreferenceController extends BasePreferenceController {
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
Preference pref = screen.findPreference(mPreferenceKey);
|
||||
if (pref != null && mSupportFeatureProvider != null) {
|
||||
mSupportFeatureProvider.applyOverrides(mContext, pref);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -22,16 +22,20 @@ import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.Activity;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.Robolectric;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.util.ReflectionHelpers;
|
||||
@@ -44,12 +48,16 @@ public class SupportPreferenceControllerTest {
|
||||
private FakeFeatureFactory mFeatureFactory;
|
||||
private Preference mPreference;
|
||||
|
||||
@Mock private PreferenceScreen mPreferenceScreen;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mActivity = Robolectric.setupActivity(Activity.class);
|
||||
mFeatureFactory = FakeFeatureFactory.setupForTest();
|
||||
mPreference = new Preference(mActivity);
|
||||
mPreference.setKey("test_key");
|
||||
when(mPreferenceScreen.findPreference(mPreference.getKey())).thenReturn(mPreference);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -74,4 +82,14 @@ public class SupportPreferenceControllerTest {
|
||||
assertThat(controller.handlePreferenceTreeClick(mPreference)).isTrue();
|
||||
verify(mFeatureFactory.supportFeatureProvider).startSupport(mActivity);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void displayPreference_shouldApplyOverrides() {
|
||||
final SupportPreferenceController controller = new SupportPreferenceController(mActivity,
|
||||
mPreference.getKey());
|
||||
controller.setActivity(mActivity);
|
||||
|
||||
controller.displayPreference(mPreferenceScreen);
|
||||
verify(mFeatureFactory.supportFeatureProvider).applyOverrides(mActivity, mPreference);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user