Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 72a162a1 authored by Lei Yu's avatar Lei Yu Committed by Android (Google) Code Review
Browse files

Merge "Move bitmap recycle to onDestroy()" into qt-dev

parents 125fe8ae 43503175
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ import com.android.settings.core.BasePreferenceController;
import com.android.settings.fuelgauge.BatteryMeterView;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import com.android.settingslib.core.lifecycle.LifecycleObserver;
import com.android.settingslib.core.lifecycle.events.OnDestroy;
import com.android.settingslib.core.lifecycle.events.OnStart;
import com.android.settingslib.core.lifecycle.events.OnStop;
import com.android.settingslib.utils.ThreadUtils;
@@ -54,7 +55,7 @@ import java.util.Map;
 * This class adds a header with device name and status (connected/disconnected, etc.).
 */
public class AdvancedBluetoothDetailsHeaderController extends BasePreferenceController implements
        LifecycleObserver, OnStart, OnStop, CachedBluetoothDevice.Callback {
        LifecycleObserver, OnStart, OnStop, OnDestroy, CachedBluetoothDevice.Callback {
    private static final String TAG = "AdvancedBtHeaderCtrl";

    @VisibleForTesting
@@ -118,7 +119,13 @@ public class AdvancedBluetoothDetailsHeaderController extends BasePreferenceCont
        }
        mCachedDevice.unregisterCallback(this::onDeviceAttributesChanged);
        mBluetoothAdapter.unregisterMetadataListener(mCachedDevice.getDevice());
    }

    @Override
    public void onDestroy() {
        if (!isAvailable()) {
            return;
        }
        // Destroy icon bitmap associated with this header
        for (Bitmap bitmap : mIconCache.values()) {
            if (bitmap != null) {
+12 −0
Original line number Diff line number Diff line
@@ -209,6 +209,18 @@ public class AdvancedBluetoothDetailsHeaderControllerTest{
        verify(mBluetoothAdapter, never()).unregisterMetadataListener(mBluetoothDevice);
    }

    @Test
    public void onDestroy_isAvailable_recycleBitmap() {
        when(mBluetoothDevice.getMetadata(BluetoothDevice.METADATA_IS_UNTHETHERED_HEADSET))
                .thenReturn("true");
        mController.mIconCache.put(ICON_URI, mBitmap);

        mController.onDestroy();

        assertThat(mController.mIconCache).isEmpty();
        verify(mBitmap).recycle();
    }

    private void assertBatteryLevel(LinearLayout linearLayout, int batteryLevel) {
        final TextView textView = linearLayout.findViewById(R.id.bt_battery_summary);
        assertThat(textView.getText().toString()).isEqualTo(