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

Commit 8852905b authored by Jason Monk's avatar Jason Monk
Browse files

Unit testing for fragments.

Set up a base class for testing fragments that will generate the host
and run the fragment through some lifecycle checks to make sure it
does ok with standard lifecycle.

Fragment tests will also automatically check for any sort of leaks
related to bindings, receivers, or other callbacks in sysui. This
requires changing the statusbar.policy classes with callbacks to
have a common interface.

Lastly also fixes a few lifecycle bugs in QS found from the above
tests.

Bug: 32609190
Test: runtest systemui
Change-Id: I52007c696c2fd41914bba4ba9d8055f2b564a7d8
parent f4e019aa
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -32,7 +32,6 @@ import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Handler;
import android.os.Looper;
import android.provider.Settings;
import com.android.systemui.statusbar.policy.BatteryController;

@@ -182,13 +181,13 @@ public class BatteryMeterDrawable extends Drawable implements
        mContext.getContentResolver().registerContentObserver(
                Settings.System.getUriFor(SHOW_PERCENT_SETTING), false, mSettingObserver);
        updateShowPercent();
        mBatteryController.addStateChangedCallback(this);
        mBatteryController.addCallback(this);
    }

    public void stopListening() {
        mListening = false;
        mContext.getContentResolver().unregisterContentObserver(mSettingObserver);
        mBatteryController.removeStateChangedCallback(this);
        mBatteryController.removeCallback(this);
    }

    public void disableShowPercent() {
+2 −3
Original line number Diff line number Diff line
@@ -17,7 +17,6 @@ package com.android.systemui;

import android.content.Context;
import android.content.res.TypedArray;
import android.os.Handler;
import android.util.ArraySet;
import android.util.AttributeSet;
import android.view.View;
@@ -73,7 +72,7 @@ public class BatteryMeterView extends ImageView implements
    @Override
    public void onAttachedToWindow() {
        super.onAttachedToWindow();
        mBatteryController.addStateChangedCallback(this);
        mBatteryController.addCallback(this);
        mDrawable.startListening();
        TunerService.get(getContext()).addTunable(this, StatusBarIconController.ICON_BLACKLIST);
    }
@@ -81,7 +80,7 @@ public class BatteryMeterView extends ImageView implements
    @Override
    public void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        mBatteryController.removeStateChangedCallback(this);
        mBatteryController.removeCallback(this);
        mDrawable.stopListening();
        TunerService.get(getContext()).removeTunable(this);
    }
+1 −0
Original line number Diff line number Diff line
@@ -143,6 +143,7 @@ public class TileServiceManager {
    }

    public void handleDestroy() {
        setBindAllowed(false);
        mServices.getContext().unregisterReceiver(mUninstallReceiver);
        mStateManager.handleDestroy();
    }
+5 −0
Original line number Diff line number Diff line
@@ -306,6 +306,11 @@ public class TileServices extends IQSService.Stub {
        }
    }

    public void destroy() {
        mServices.values().forEach(service -> service.handleDestroy());
        mContext.unregisterReceiver(mRequestListeningReceiver);
    }

    private final BroadcastReceiver mRequestListeningReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
+2 −2
Original line number Diff line number Diff line
@@ -78,9 +78,9 @@ public class BatteryTile extends QSTile<QSTile.State> implements BatteryControll
    @Override
    public void setListening(boolean listening) {
        if (listening) {
            mBatteryController.addStateChangedCallback(this);
            mBatteryController.addCallback(this);
        } else {
            mBatteryController.removeStateChangedCallback(this);
            mBatteryController.removeCallback(this);
        }
    }

Loading