import static androidx.lifecycle.Lifecycle.Event.ON_STOP;
import android.app.Activity;
+import android.os.Build;
import android.view.Window;
import android.view.WindowManager;
+import androidx.annotation.VisibleForTesting;
import androidx.lifecycle.LifecycleObserver;
import androidx.lifecycle.OnLifecycleEvent;
mActivity = activity;
}
+ @VisibleForTesting
+ boolean isEnabled() {
+ return !Build.IS_DEBUGGABLE;
+ }
+
@OnLifecycleEvent(ON_START)
public void onStart() {
- if (mActivity == null) {
+ if (mActivity == null || !isEnabled()) {
return;
}
mActivity.getWindow().addSystemFlags(SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS);
@OnLifecycleEvent(ON_STOP)
public void onStop() {
- if (mActivity == null) {
+ if (mActivity == null || !isEnabled()) {
return;
}
final Window window = mActivity.getWindow();
package com.android.settings.development.featureflags;
import android.content.Context;
+import android.os.Build;
import android.util.FeatureFlagUtils;
import androidx.preference.PreferenceGroup;
@Override
public int getAvailabilityStatus() {
- return AVAILABLE;
+ return Build.IS_DEBUGGABLE ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
}
@Override
import static com.google.common.truth.Truth.assertThat;
+import android.os.Build;
import android.os.Bundle;
import android.view.WindowManager;
import org.junit.runner.RunWith;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
-import org.robolectric.RuntimeEnvironment;
import org.robolectric.android.controller.ActivityController;
+import org.robolectric.util.ReflectionHelpers;
@RunWith(RobolectricTestRunner.class)
public class HideNonSystemOverlayMixinTest {
@Before
public void setUp() {
- RuntimeEnvironment.application.setTheme(R.style.Theme_AppCompat);
mActivityController = Robolectric.buildActivity(TestActivity.class);
}
.isEqualTo(0);
}
+ @Test
+ public void isEnabled_debug_false() {
+ ReflectionHelpers.setStaticField(Build.class, "IS_DEBUGGABLE", true);
+
+ assertThat(new HideNonSystemOverlayMixin(null).isEnabled()).isFalse();
+ }
+
+ @Test
+ public void isEnabled_user_true() {
+ ReflectionHelpers.setStaticField(Build.class, "IS_DEBUGGABLE", false);
+
+ assertThat(new HideNonSystemOverlayMixin(null).isEnabled()).isTrue();
+ }
+
public static class TestActivity extends AppCompatActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
+ setTheme(R.style.Theme_AppCompat);
getLifecycle().addObserver(new HideNonSystemOverlayMixin(this));
}
}
package com.android.settings.development.featureflags;
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.Mockito.when;
import android.content.Context;
+import android.os.Build;
+import android.os.SystemProperties;
import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceScreen;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
+import org.robolectric.util.ReflectionHelpers;
@RunWith(RobolectricTestRunner.class)
public class FeatureFlagPreferenceControllerTest {
}
@Test
- public void getAvailability_available() {
+ public void getAvailability_debug_available() {
+ ReflectionHelpers.setStaticField(Build.class, "IS_DEBUGGABLE", true);
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
}
+
+ @Test
+ public void getAvailability_user_unavailable() {
+ ReflectionHelpers.setStaticField(Build.class, "IS_DEBUGGABLE", false);
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
+ }
+
@Test
public void onStart_shouldRefreshFeatureFlags() {
mController.onStart();