package com.android.settings.accounts;
import android.accounts.Account;
+import android.app.ActivityManager;
import android.app.settings.SettingsEnums;
import android.content.ContentResolver;
import android.content.Context;
private final Context mContext;
private final ImageView mAvatarView;
private final MutableLiveData<Bitmap> mAvatarImage;
+ private final ActivityManager mActivityManager;
private String mAccountName;
public AvatarViewMixin(SettingsHomepageActivity activity, ImageView avatarView) {
mContext = activity.getApplicationContext();
+ mActivityManager = mContext.getSystemService(ActivityManager.class);
mAvatarView = avatarView;
mAvatarView.setOnClickListener(v -> {
Intent intent;
@OnLifecycleEvent(Lifecycle.Event.ON_START)
public void onStart() {
if (!mContext.getResources().getBoolean(R.bool.config_show_avatar_in_homepage)) {
- Log.d(TAG, "Feature disabled. Skipping");
+ Log.d(TAG, "Feature disabled by config. Skipping");
+ return;
+ }
+ if (mActivityManager.isLowRamDevice()) {
+ Log.d(TAG, "Feature disabled on low ram device. Skipping");
return;
}
if (hasAccount()) {
package com.android.settings.homepage;
import android.animation.LayoutTransition;
+import android.app.ActivityManager;
import android.app.settings.SettingsEnums;
import android.os.Bundle;
import android.view.View;
final AvatarViewMixin avatarViewMixin = new AvatarViewMixin(this, avatarView);
getLifecycle().addObserver(avatarViewMixin);
- showFragment(new ContextualCardsFragment(), R.id.contextual_cards_content);
+ if (!getSystemService(ActivityManager.class).isLowRamDevice()) {
+ // Only allow contextual feature on high ram devices.
+ showFragment(new ContextualCardsFragment(), R.id.contextual_cards_content);
+ }
showFragment(new TopLevelSettings(), R.id.main_content);
((FrameLayout) findViewById(R.id.main_content))
.getLayoutTransition().enableTransitionType(LayoutTransition.CHANGING);
import static org.mockito.Mockito.verify;
import android.accounts.Account;
+import android.app.ActivityManager;
import android.content.ContentProvider;
import android.content.ContentResolver;
import android.content.Context;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
import org.robolectric.shadow.api.Shadow;
+import org.robolectric.shadows.ShadowActivityManager;
import org.robolectric.shadows.ShadowContentResolver;
import org.robolectric.shadows.ShadowPackageManager;
}
@Test
+ public void onStart_lowRamDevice_doNothing() {
+ final AvatarViewMixin mixin = spy(new AvatarViewMixin(mActivity, mImageView));
+
+ final ShadowActivityManager activityManager =
+ Shadow.extract(mContext.getSystemService(ActivityManager.class));
+ activityManager.setIsLowRamDevice(true);
+
+ mixin.onStart();
+
+ verify(mixin, never()).hasAccount();
+ }
+
+ @Test
@Config(qualifiers = "mcc999",
shadows = {
BatteryFixSliceTest.ShadowBatteryStatsHelperLoader.class,