Merge "Check config to decide if Smart Storage toggle should exist" into sc-dev
This commit is contained in:
@@ -522,4 +522,7 @@
|
||||
|
||||
<!-- Media Uri to view documents & other storage category. -->
|
||||
<string name="config_documents_and_other_storage_category_uri" translatable="false">content://com.android.providers.media.documents/root/documents_root</string>
|
||||
|
||||
<!-- Whether to show Smart Storage toggle -->
|
||||
<bool name="config_show_smart_storage_toggle">true</bool>
|
||||
</resources>
|
||||
|
@@ -42,7 +42,8 @@
|
||||
android:key="free_up_space"
|
||||
android:order="4"
|
||||
android:title="@string/storage_free_up_space_title"
|
||||
android:summary="@string/storage_free_up_space_summary"/>
|
||||
android:summary="@string/storage_free_up_space_summary"
|
||||
settings:allowDividerAbove="true"/>
|
||||
<!-- Preference order 100~200 are 'ONLY' for storage category preferences below. -->
|
||||
<Preference
|
||||
android:key="pref_public_storage"
|
||||
|
@@ -26,6 +26,7 @@ import androidx.annotation.VisibleForTesting;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.deletionhelper.ActivationWarningFragment;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
@@ -66,6 +67,9 @@ public class AutomaticStorageManagementSwitchPreferenceController extends
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
if (!mContext.getResources().getBoolean(R.bool.config_show_smart_storage_toggle)) {
|
||||
return UNSUPPORTED_ON_DEVICE;
|
||||
}
|
||||
return !ActivityManager.isLowRamDeviceStatic() ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
|
||||
}
|
||||
|
||||
@@ -108,4 +112,4 @@ public class AutomaticStorageManagementSwitchPreferenceController extends
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -22,12 +22,14 @@ import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.os.SystemProperties;
|
||||
import android.provider.Settings;
|
||||
|
||||
@@ -38,6 +40,7 @@ import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.internal.os.RoSystemProperties;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.deletionhelper.ActivationWarningFragment;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
@@ -67,13 +70,16 @@ public class AutomaticStorageManagementSwitchPreferenceControllerTest {
|
||||
private FragmentManager mFragmentManager;
|
||||
|
||||
private Context mContext;
|
||||
private Resources mResources;
|
||||
private AutomaticStorageManagementSwitchPreferenceController mController;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = RuntimeEnvironment.application.getApplicationContext();
|
||||
mContext = spy(RuntimeEnvironment.application.getApplicationContext());
|
||||
FeatureFactory.getFactory(mContext);
|
||||
mResources = spy(mContext.getResources());
|
||||
when(mContext.getResources()).thenReturn(mResources);
|
||||
|
||||
mController = new AutomaticStorageManagementSwitchPreferenceController(mContext, "testkey");
|
||||
mController.setFragmentManager(mFragmentManager);
|
||||
@@ -81,14 +87,27 @@ public class AutomaticStorageManagementSwitchPreferenceControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_shouldReturnTrue_forHighRamDevice() {
|
||||
public void getAvailabilityStatus_configFalse_shouldUnsupportedOnDevice() {
|
||||
when(mResources.getBoolean(R.bool.config_show_smart_storage_toggle)).thenReturn(false);
|
||||
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(
|
||||
BasePreferenceController.UNSUPPORTED_ON_DEVICE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_forHighRamDevice_shouldAvailable() {
|
||||
when(mResources.getBoolean(R.bool.config_show_smart_storage_toggle)).thenReturn(true);
|
||||
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(
|
||||
BasePreferenceController.AVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_shouldAlwaysReturnFalse_forLowRamDevice() {
|
||||
public void getAvailabilityStatus_forLowRamDevice_shouldUnsupportedOnDevice() {
|
||||
when(mResources.getBoolean(R.bool.config_show_smart_storage_toggle)).thenReturn(true);
|
||||
|
||||
ReflectionHelpers.setStaticField(RoSystemProperties.class, "CONFIG_LOW_RAM", true);
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(
|
||||
|
Reference in New Issue
Block a user