import android.service.settings.suggestions.ISuggestionService;
import android.service.settings.suggestions.Suggestion;
import android.support.annotation.VisibleForTesting;
+import android.util.FeatureFlagUtils;
import android.util.Log;
import com.android.settingslib.core.lifecycle.Lifecycle;
*/
public class SuggestionControllerMixin implements LifecycleObserver, OnStart, OnStop {
+ @VisibleForTesting
+ static final String FEATURE_FLAG = "new_settings_suggestion";
private static final String TAG = "SuggestionCtrlMixin";
private static final boolean DEBUG = false;
private ISuggestionService mRemoteService;
+ public static boolean isEnabled() {
+ return FeatureFlagUtils.isEnabled(FEATURE_FLAG);
+ }
+
public SuggestionControllerMixin(Context context, Lifecycle lifecycle) {
mContext = context.getApplicationContext();
mServiceIntent = new Intent().setComponent(
}
}
- public boolean isEnabled() {
- // TODO: Set up feature flag
- return true;
- }
-
/**
* Get setting suggestions.
*/
import static org.mockito.Mockito.when;
import android.content.Context;
-import android.os.RemoteException;
import android.service.settings.suggestions.ISuggestionService;
+import android.util.FeatureFlagUtils;
import com.android.settings.TestConfig;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settings.testutils.shadow.SettingsShadowSystemProperties;
import com.android.settingslib.core.lifecycle.Lifecycle;
+import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.util.ReflectionHelpers;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
+ shadows = {
+ SettingsShadowSystemProperties.class
+ })
public class SuggestionControllerMixinTest {
@Mock
when(mContext.getApplicationContext()).thenReturn(mContext);
}
+ @After
+ public void tearDown() {
+ SettingsShadowSystemProperties.clear();
+ }
+
@Test
- public void verifyIsEnabled() {
- mMixin = new SuggestionControllerMixin(mContext, mLifecycle);
- assertThat(mMixin.isEnabled()).isTrue();
+ public void systemPropertySet_verifyIsEnabled() {
+ SettingsShadowSystemProperties.set(
+ FeatureFlagUtils.FFLAG_PREFIX + SuggestionControllerMixin.FEATURE_FLAG, "true");
+ assertThat(SuggestionControllerMixin.isEnabled()).isTrue();
+ }
+
+ @Test
+ public void systemPropertyNotSet_verifyIsDisabled() {
+ SettingsShadowSystemProperties.set(
+ FeatureFlagUtils.FFLAG_PREFIX + SuggestionControllerMixin.FEATURE_FLAG, "false");
+ assertThat(SuggestionControllerMixin.isEnabled()).isFalse();
}
@Test