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

Commit 3ee14a32 authored by Matías Hernández's avatar Matías Hernández
Browse files

Remove dead code from ZenModeController

While we should move away from ZenModeController altogether, some parts of it are already unused (and if we get closer to deleting getConfig and its callback, we can save a lot of Binder traffic).

More deletions will be possible when MODES_UI is inlined.

Bug: 308591859
Test: build
Flag: EXEMPT Removing dead code
Change-Id: I97b59392a8c50b0a25ff07890b068e4e03140887
parent 354e3282
Loading
Loading
Loading
Loading
+0 −11
Original line number Diff line number Diff line
@@ -36,7 +36,6 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.internal.statusbar.StatusBarIcon
import com.android.settingslib.notification.modes.TestModeBuilder
import com.android.systemui.Flags
import com.android.systemui.SysuiTestCase
import com.android.systemui.broadcast.BroadcastDispatcher
import com.android.systemui.display.domain.interactor.ConnectedDisplayInteractor
@@ -480,8 +479,6 @@ class PhoneStatusBarPolicyTest : SysuiTestCase() {

        override fun getZen(): Int = zen

        override fun getManualRule(): ZenModeConfig.ZenRule = throw NotImplementedError()

        override fun getConfig(): ZenModeConfig = throw NotImplementedError()

        override fun getConsolidatedPolicy(): NotificationManager.Policy = consolidatedPolicy
@@ -490,14 +487,6 @@ class PhoneStatusBarPolicyTest : SysuiTestCase() {

        override fun isZenAvailable() = throw NotImplementedError()

        override fun getEffectsSuppressor() = throw NotImplementedError()

        override fun isCountdownConditionSupported() = throw NotImplementedError()

        override fun getCurrentUser() = throw NotImplementedError()

        override fun isVolumeRestricted() = throw NotImplementedError()

        override fun areNotificationsHiddenInShade() = throw NotImplementedError()
    }
}
+0 −39
Original line number Diff line number Diff line
@@ -90,45 +90,6 @@ class ZenModeControllerImplTest : SysuiTestCase() {
        Mockito.verify(mockCallback).onConfigChanged(ArgumentMatchers.eq(config))
    }

    @Test
    fun testAreNotificationsHiddenInShade_zenOffShadeSuppressed() {
        config.suppressedVisualEffects =
            NotificationManager.Policy.SUPPRESSED_EFFECT_NOTIFICATION_LIST
        controller.updateZenMode(Settings.Global.ZEN_MODE_OFF)
        controller.updateZenModeConfig()
        assertThat(controller.areNotificationsHiddenInShade()).isFalse()
    }

    @Test
    fun testAreNotificationsHiddenInShade_zenOnShadeNotSuppressed() {
        val policy =
            NotificationManager.Policy(
                0,
                0,
                0,
                NotificationManager.Policy.SUPPRESSED_EFFECT_STATUS_BAR,
            )
        whenever(mNm.consolidatedNotificationPolicy).thenReturn(policy)
        controller.updateConsolidatedNotificationPolicy()
        controller.updateZenMode(Settings.Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS)
        assertThat(controller.areNotificationsHiddenInShade()).isFalse()
    }

    @Test
    fun testAreNotificationsHiddenInShade_zenOnShadeSuppressed() {
        val policy =
            NotificationManager.Policy(
                0,
                0,
                0,
                NotificationManager.Policy.SUPPRESSED_EFFECT_NOTIFICATION_LIST,
            )
        whenever(mNm.consolidatedNotificationPolicy).thenReturn(policy)
        controller.updateConsolidatedNotificationPolicy()
        controller.updateZenMode(Settings.Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS)
        assertThat(controller.areNotificationsHiddenInShade()).isTrue()
    }

    @Test
    fun testModeChange() =
        testScope.runTest {
+0 −11
Original line number Diff line number Diff line
@@ -17,11 +17,8 @@
package com.android.systemui.statusbar.policy;

import android.app.NotificationManager;
import android.content.ComponentName;
import android.net.Uri;
import android.service.notification.Condition;
import android.service.notification.ZenModeConfig;
import android.service.notification.ZenModeConfig.ZenRule;

import com.android.systemui.statusbar.policy.ZenModeController.Callback;
import com.android.systemui.statusbar.policy.domain.interactor.ZenModeInteractor;
@@ -35,25 +32,17 @@ import com.android.systemui.statusbar.policy.domain.interactor.ZenModeInteractor
public interface ZenModeController extends CallbackController<Callback> {
    void setZen(int zen, Uri conditionId, String reason);
    int getZen();
    ZenRule getManualRule();
    ZenModeConfig getConfig();
    /** Gets consolidated zen policy that will apply when DND is on in priority only mode */
    NotificationManager.Policy getConsolidatedPolicy();
    long getNextAlarm();
    boolean isZenAvailable();
    ComponentName getEffectsSuppressor();
    boolean isCountdownConditionSupported();
    int getCurrentUser();
    boolean isVolumeRestricted();
    boolean areNotificationsHiddenInShade();

    public static interface Callback {
        default void onZenChanged(int zen) {}
        default void onConditionsChanged(Condition[] conditions) {}
        default void onNextAlarmChanged() {}
        default void onZenAvailableChanged(boolean available) {}
        default void onEffectsSupressorChanged() {}
        default void onManualRuleChanged(ZenRule rule) {}
        default void onConfigChanged(ZenModeConfig config) {}
        /** Called when the consolidated zen policy changes */
        default void onConsolidatedPolicyChanged(NotificationManager.Policy policy) {}
+0 −51
Original line number Diff line number Diff line
@@ -20,7 +20,6 @@ import android.app.AlarmManager;
import android.app.Flags;
import android.app.NotificationManager;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
@@ -35,7 +34,6 @@ import android.os.UserManager;
import android.provider.Settings.Global;
import android.provider.Settings.Secure;
import android.service.notification.ZenModeConfig;
import android.service.notification.ZenModeConfig.ZenRule;
import android.text.format.DateFormat;
import android.util.Log;

@@ -92,7 +90,6 @@ public class ZenModeControllerImpl implements ZenModeController, Dumpable {
                    }
                    final IntentFilter filter = new IntentFilter(
                            AlarmManager.ACTION_NEXT_ALARM_CLOCK_CHANGED);
                    filter.addAction(NotificationManager.ACTION_EFFECTS_SUPPRESSOR_CHANGED);
                    mBroadcastDispatcher.registerReceiver(mReceiver, filter, null,
                            UserHandle.of(mUserId));
                    mRegistered = true;
@@ -155,21 +152,6 @@ public class ZenModeControllerImpl implements ZenModeController, Dumpable {
        return mGlobalSettings.getInt(Global.ZEN_MODE, /* default */ Global.ZEN_MODE_OFF);
    }

    @Override
    public boolean isVolumeRestricted() {
        return mUserManager.hasUserRestriction(UserManager.DISALLOW_ADJUST_VOLUME,
                UserHandle.of(mUserId));
    }

    @Override
    public boolean areNotificationsHiddenInShade() {
        if (mZenMode != Global.ZEN_MODE_OFF) {
            return (mConsolidatedNotificationPolicy.suppressedVisualEffects
                    & NotificationManager.Policy.SUPPRESSED_EFFECT_NOTIFICATION_LIST) != 0;
        }
        return false;
    }

    @Override
    public void addCallback(@NonNull Callback callback) {
        synchronized (mCallbacksLock) {
@@ -205,11 +187,6 @@ public class ZenModeControllerImpl implements ZenModeController, Dumpable {
        return mSetupObserver.isDeviceProvisioned() && mSetupObserver.isUserSetup();
    }

    @Override
    public ZenRule getManualRule() {
        return mConfig == null ? null : mConfig.manualRule;
    }

    @Override
    public ZenModeConfig getConfig() {
        return mConfig;
@@ -227,17 +204,6 @@ public class ZenModeControllerImpl implements ZenModeController, Dumpable {
        return info != null ? info.getTriggerTime() : 0;
    }

    @Override
    public ComponentName getEffectsSuppressor() {
        return NotificationManager.from(mContext).getEffectsSuppressor();
    }

    @Override
    public boolean isCountdownConditionSupported() {
        return NotificationManager.from(mContext)
                .isSystemConditionProviderEnabled(ZenModeConfig.COUNTDOWN_PATH);
    }

    @Override
    public int getCurrentUser() {
        return mUserTracker.getUserId();
@@ -247,10 +213,6 @@ public class ZenModeControllerImpl implements ZenModeController, Dumpable {
        fireSafeChange(Callback::onNextAlarmChanged);
    }

    private void fireEffectsSuppressorChanged() {
        fireSafeChange(Callback::onEffectsSupressorChanged);
    }

    private void fireZenChanged(int zen) {
        fireSafeChange(c -> c.onZenChanged(zen));
    }
@@ -259,10 +221,6 @@ public class ZenModeControllerImpl implements ZenModeController, Dumpable {
        fireSafeChange(c -> c.onZenAvailableChanged(available));
    }

    private void fireManualRuleChanged(ZenRule rule) {
        fireSafeChange(c -> c.onManualRuleChanged(rule));
    }

    private void fireConsolidatedPolicyChanged(NotificationManager.Policy policy) {
        fireSafeChange(c -> c.onConsolidatedPolicyChanged(policy));
    }
@@ -302,16 +260,10 @@ public class ZenModeControllerImpl implements ZenModeController, Dumpable {
    protected void updateZenModeConfig() {
        final ZenModeConfig config = mNoMan.getZenModeConfig();
        if (Objects.equals(config, mConfig)) return;
        final ZenRule oldRule = mConfig != null ? mConfig.manualRule : null;
        mConfig = config;
        mZenUpdateTime = System.currentTimeMillis();
        fireConfigChanged(config);

        final ZenRule newRule = config != null ? config.manualRule : null;
        if (!Objects.equals(oldRule, newRule)) {
            fireManualRuleChanged(newRule);
        }

        final NotificationManager.Policy consolidatedPolicy =
                mNoMan.getConsolidatedNotificationPolicy();
        if (!Objects.equals(consolidatedPolicy, mConsolidatedNotificationPolicy)) {
@@ -327,9 +279,6 @@ public class ZenModeControllerImpl implements ZenModeController, Dumpable {
            if (AlarmManager.ACTION_NEXT_ALARM_CLOCK_CHANGED.equals(intent.getAction())) {
                fireNextAlarmChanged();
            }
            if (NotificationManager.ACTION_EFFECTS_SUPPRESSOR_CHANGED.equals(intent.getAction())) {
                fireEffectsSuppressorChanged();
            }
        }
    };

+0 −27
Original line number Diff line number Diff line
@@ -15,10 +15,8 @@
package com.android.systemui.utils.leaks;

import android.app.NotificationManager;
import android.content.ComponentName;
import android.net.Uri;
import android.service.notification.ZenModeConfig;
import android.service.notification.ZenModeConfig.ZenRule;
import android.testing.LeakCheck;

import com.android.systemui.statusbar.policy.ZenModeController;
@@ -39,11 +37,6 @@ public class FakeZenModeController extends BaseLeakChecker<Callback> implements
        return 0;
    }

    @Override
    public ZenRule getManualRule() {
        return null;
    }

    @Override
    public ZenModeConfig getConfig() {
        return null;
@@ -64,28 +57,8 @@ public class FakeZenModeController extends BaseLeakChecker<Callback> implements
        return false;
    }

    @Override
    public ComponentName getEffectsSuppressor() {
        return null;
    }

    @Override
    public boolean isCountdownConditionSupported() {
        return false;
    }

    @Override
    public int getCurrentUser() {
        return 0;
    }

    @Override
    public boolean isVolumeRestricted() {
        return false;
    }

    @Override
    public boolean areNotificationsHiddenInShade() {
        return false;
    }
}