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

Commit 71750064 authored by Justin Weir's avatar Justin Weir Committed by Automerger Merge Worker
Browse files

Merge "Add settings observing for vibrate icon to Keyguard" into tm-dev am: 25402935

parents 2dec1607 25402935
Loading
Loading
Loading
Loading
+58 −7
Original line number Original line Diff line number Diff line
@@ -23,12 +23,16 @@ import android.animation.AnimatorListenerAdapter;
import android.animation.ValueAnimator;
import android.animation.ValueAnimator;
import android.content.res.Configuration;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.content.res.Resources;
import android.database.ContentObserver;
import android.hardware.biometrics.BiometricSourceType;
import android.hardware.biometrics.BiometricSourceType;
import android.os.UserHandle;
import android.os.UserManager;
import android.os.UserManager;
import android.provider.Settings;
import android.util.MathUtils;
import android.util.MathUtils;
import android.view.View;
import android.view.View;


import androidx.annotation.NonNull;
import androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting;


import com.android.keyguard.CarrierTextController;
import com.android.keyguard.CarrierTextController;
import com.android.keyguard.KeyguardUpdateMonitor;
import com.android.keyguard.KeyguardUpdateMonitor;
@@ -36,6 +40,7 @@ import com.android.keyguard.KeyguardUpdateMonitorCallback;
import com.android.systemui.R;
import com.android.systemui.R;
import com.android.systemui.animation.Interpolators;
import com.android.systemui.animation.Interpolators;
import com.android.systemui.battery.BatteryMeterViewController;
import com.android.systemui.battery.BatteryMeterViewController;
import com.android.systemui.dagger.qualifiers.Main;
import com.android.systemui.plugins.statusbar.StatusBarStateController;
import com.android.systemui.plugins.statusbar.StatusBarStateController;
import com.android.systemui.statusbar.StatusBarState;
import com.android.systemui.statusbar.StatusBarState;
import com.android.systemui.statusbar.SysuiStatusBarStateController;
import com.android.systemui.statusbar.SysuiStatusBarStateController;
@@ -45,6 +50,7 @@ import com.android.systemui.statusbar.notification.AnimatableProperty;
import com.android.systemui.statusbar.notification.PropertyAnimator;
import com.android.systemui.statusbar.notification.PropertyAnimator;
import com.android.systemui.statusbar.notification.stack.AnimationProperties;
import com.android.systemui.statusbar.notification.stack.AnimationProperties;
import com.android.systemui.statusbar.notification.stack.StackStateAnimator;
import com.android.systemui.statusbar.notification.stack.StackStateAnimator;
import com.android.systemui.statusbar.phone.fragment.StatusBarIconBlocklistKt;
import com.android.systemui.statusbar.phone.fragment.StatusBarSystemEventAnimator;
import com.android.systemui.statusbar.phone.fragment.StatusBarSystemEventAnimator;
import com.android.systemui.statusbar.phone.userswitcher.StatusBarUserInfoTracker;
import com.android.systemui.statusbar.phone.userswitcher.StatusBarUserInfoTracker;
import com.android.systemui.statusbar.phone.userswitcher.StatusBarUserSwitcherController;
import com.android.systemui.statusbar.phone.userswitcher.StatusBarUserSwitcherController;
@@ -54,10 +60,12 @@ import com.android.systemui.statusbar.policy.ConfigurationController;
import com.android.systemui.statusbar.policy.KeyguardStateController;
import com.android.systemui.statusbar.policy.KeyguardStateController;
import com.android.systemui.statusbar.policy.UserInfoController;
import com.android.systemui.statusbar.policy.UserInfoController;
import com.android.systemui.util.ViewController;
import com.android.systemui.util.ViewController;
import com.android.systemui.util.settings.SecureSettings;


import java.io.PrintWriter;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.List;
import java.util.List;
import java.util.concurrent.Executor;


import javax.inject.Inject;
import javax.inject.Inject;


@@ -98,6 +106,9 @@ public class KeyguardStatusBarViewController extends ViewController<KeyguardStat
    private final StatusBarUserSwitcherFeatureController mFeatureController;
    private final StatusBarUserSwitcherFeatureController mFeatureController;
    private final StatusBarUserSwitcherController mUserSwitcherController;
    private final StatusBarUserSwitcherController mUserSwitcherController;
    private final StatusBarUserInfoTracker mStatusBarUserInfoTracker;
    private final StatusBarUserInfoTracker mStatusBarUserInfoTracker;
    private final SecureSettings mSecureSettings;
    private final Executor mMainExecutor;
    private final Object mLock = new Object();


    private final ConfigurationController.ConfigurationListener mConfigurationListener =
    private final ConfigurationController.ConfigurationListener mConfigurationListener =
            new ConfigurationController.ConfigurationListener() {
            new ConfigurationController.ConfigurationListener() {
@@ -206,7 +217,7 @@ public class KeyguardStatusBarViewController extends ViewController<KeyguardStat
                }
                }
            };
            };


    private final List<String> mBlockedIcons;
    private final List<String> mBlockedIcons = new ArrayList<>();
    private final int mNotificationsHeaderCollideDistance;
    private final int mNotificationsHeaderCollideDistance;


    private boolean mBatteryListening;
    private boolean mBatteryListening;
@@ -255,7 +266,9 @@ public class KeyguardStatusBarViewController extends ViewController<KeyguardStat
            UserManager userManager,
            UserManager userManager,
            StatusBarUserSwitcherFeatureController featureController,
            StatusBarUserSwitcherFeatureController featureController,
            StatusBarUserSwitcherController userSwitcherController,
            StatusBarUserSwitcherController userSwitcherController,
            StatusBarUserInfoTracker statusBarUserInfoTracker
            StatusBarUserInfoTracker statusBarUserInfoTracker,
            SecureSettings secureSettings,
            @Main Executor mainExecutor
    ) {
    ) {
        super(view);
        super(view);
        mCarrierTextController = carrierTextController;
        mCarrierTextController = carrierTextController;
@@ -277,6 +290,8 @@ public class KeyguardStatusBarViewController extends ViewController<KeyguardStat
        mFeatureController = featureController;
        mFeatureController = featureController;
        mUserSwitcherController = userSwitcherController;
        mUserSwitcherController = userSwitcherController;
        mStatusBarUserInfoTracker = statusBarUserInfoTracker;
        mStatusBarUserInfoTracker = statusBarUserInfoTracker;
        mSecureSettings = secureSettings;
        mMainExecutor = mainExecutor;


        mFirstBypassAttempt = mKeyguardBypassController.getBypassEnabled();
        mFirstBypassAttempt = mKeyguardBypassController.getBypassEnabled();
        mKeyguardStateController.addCallback(
        mKeyguardStateController.addCallback(
@@ -292,8 +307,7 @@ public class KeyguardStatusBarViewController extends ViewController<KeyguardStat
        );
        );


        Resources r = getResources();
        Resources r = getResources();
        mBlockedIcons = Arrays.asList(r.getStringArray(
        updateBlockedIcons();
                R.array.config_keyguard_statusbar_icon_blocklist));
        mNotificationsHeaderCollideDistance = r.getDimensionPixelSize(
        mNotificationsHeaderCollideDistance = r.getDimensionPixelSize(
                R.dimen.header_notifications_collide_distance);
                R.dimen.header_notifications_collide_distance);


@@ -321,11 +335,16 @@ public class KeyguardStatusBarViewController extends ViewController<KeyguardStat
        if (mTintedIconManager == null) {
        if (mTintedIconManager == null) {
            mTintedIconManager =
            mTintedIconManager =
                    mTintedIconManagerFactory.create(mView.findViewById(R.id.statusIcons));
                    mTintedIconManagerFactory.create(mView.findViewById(R.id.statusIcons));
            mTintedIconManager.setBlockList(mBlockedIcons);
            mTintedIconManager.setBlockList(getBlockedIcons());
            mStatusBarIconController.addIconGroup(mTintedIconManager);
            mStatusBarIconController.addIconGroup(mTintedIconManager);
        }
        }
        mView.setOnApplyWindowInsetsListener(
        mView.setOnApplyWindowInsetsListener(
                (view, windowInsets) -> mView.updateWindowInsets(windowInsets, mInsetsProvider));
                (view, windowInsets) -> mView.updateWindowInsets(windowInsets, mInsetsProvider));
        mSecureSettings.registerContentObserverForUser(
                Settings.Secure.getUriFor(Settings.Secure.STATUS_BAR_SHOW_VIBRATE_ICON),
                false,
                mVolumeSettingObserver,
                UserHandle.USER_ALL);
        updateUserSwitcher();
        updateUserSwitcher();
        onThemeChanged();
        onThemeChanged();
    }
    }
@@ -337,6 +356,7 @@ public class KeyguardStatusBarViewController extends ViewController<KeyguardStat
        mUserInfoController.removeCallback(mOnUserInfoChangedListener);
        mUserInfoController.removeCallback(mOnUserInfoChangedListener);
        mStatusBarStateController.removeCallback(mStatusBarStateListener);
        mStatusBarStateController.removeCallback(mStatusBarStateListener);
        mKeyguardUpdateMonitor.removeCallback(mKeyguardUpdateMonitorCallback);
        mKeyguardUpdateMonitor.removeCallback(mKeyguardUpdateMonitorCallback);
        mSecureSettings.unregisterContentObserver(mVolumeSettingObserver);
        if (mTintedIconManager != null) {
        if (mTintedIconManager != null) {
            mStatusBarIconController.removeIconGroup(mTintedIconManager);
            mStatusBarIconController.removeIconGroup(mTintedIconManager);
        }
        }
@@ -486,8 +506,32 @@ public class KeyguardStatusBarViewController extends ViewController<KeyguardStat
                R.bool.qs_show_user_switcher_for_single_user)));
                R.bool.qs_show_user_switcher_for_single_user)));
    }
    }


    @VisibleForTesting
    void updateBlockedIcons() {
        List<String> newBlockList = StatusBarIconBlocklistKt
                .getStatusBarIconBlocklist(getResources(), mSecureSettings);

        synchronized (mLock) {
            mBlockedIcons.clear();
            mBlockedIcons.addAll(newBlockList);
        }

        mMainExecutor.execute(() -> {
            if (mTintedIconManager != null) {
                mTintedIconManager.setBlockList(getBlockedIcons());
            }
        });
    }

    @VisibleForTesting
    List<String> getBlockedIcons() {
        synchronized (mLock) {
            return new ArrayList<>(mBlockedIcons);
        }
    }

    /**
    /**
     * Update {@link KeyguardStatusBarView}'s visibility based on whether keyguard is showing and
      Update {@link KeyguardStatusBarView}'s visibility based on whether keyguard is showing and
     * whether heads up is visible.
     * whether heads up is visible.
     */
     */
    public void updateForHeadsUp() {
    public void updateForHeadsUp() {
@@ -533,4 +577,11 @@ public class KeyguardStatusBarViewController extends ViewController<KeyguardStat
        mExplicitAlpha = alpha;
        mExplicitAlpha = alpha;
        updateViewState();
        updateViewState();
    }
    }

    private final ContentObserver mVolumeSettingObserver = new ContentObserver(null) {
        @Override
        public void onChange(boolean selfChange) {
            updateBlockedIcons();
        }
    };
}
}
+52 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.android.systemui.statusbar.phone.fragment

import android.content.res.Resources
import android.os.UserHandle
import android.provider.Settings
import com.android.internal.R
import com.android.systemui.util.settings.SecureSettings

/**
 * Centralize the logic for the status bar / keyguard status bar icon blocklist. The default is
 * loaded from the config, and we currently support a system setting for the vibrate icon. It's
 * pretty likely that we would end up supporting more user-configurable settings in the future, so
 * breaking this out into its own file for now.
 *
 * Note for the future: it might be reasonable to turn this into its own class that can listen to
 * the system setting and execute a callback when it changes instead of having multiple content
 * observers.
 */
fun getStatusBarIconBlocklist(
    res: Resources,
    settings: SecureSettings
): List<String> {
    // Load the default blocklist from res
    val blocklist = res.getStringArray(
            com.android.systemui.R.array.config_collapsed_statusbar_icon_blocklist).toList()

    val vibrateIconSlot: String = res.getString(R.string.status_bar_volume)
    val showVibrateIcon = settings.getIntForUser(
            Settings.Secure.STATUS_BAR_SHOW_VIBRATE_ICON,
            0,
            UserHandle.USER_CURRENT) == 0

    // Filter out vibrate icon from the blocklist if the setting is on
    return blocklist.filter { icon ->
        !icon.equals(vibrateIconSlot) || showVibrateIcon
    }
}
 No newline at end of file
+45 −1
Original line number Original line Diff line number Diff line
@@ -22,6 +22,8 @@ import static com.android.systemui.statusbar.StatusBarState.SHADE;


import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertThat;


import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.Mockito.clearInvocations;
import static org.mockito.Mockito.clearInvocations;
@@ -29,7 +31,9 @@ import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.when;


import android.os.UserHandle;
import android.os.UserManager;
import android.os.UserManager;
import android.provider.Settings;
import android.testing.AndroidTestingRunner;
import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper;
import android.testing.TestableLooper;
import android.view.LayoutInflater;
import android.view.LayoutInflater;
@@ -55,6 +59,9 @@ import com.android.systemui.statusbar.policy.ConfigurationController;
import com.android.systemui.statusbar.policy.ConfigurationController.ConfigurationListener;
import com.android.systemui.statusbar.policy.ConfigurationController.ConfigurationListener;
import com.android.systemui.statusbar.policy.KeyguardStateController;
import com.android.systemui.statusbar.policy.KeyguardStateController;
import com.android.systemui.statusbar.policy.UserInfoController;
import com.android.systemui.statusbar.policy.UserInfoController;
import com.android.systemui.util.concurrency.FakeExecutor;
import com.android.systemui.util.settings.SecureSettings;
import com.android.systemui.util.time.FakeSystemClock;


import org.junit.Before;
import org.junit.Before;
import org.junit.Test;
import org.junit.Test;
@@ -108,10 +115,12 @@ public class KeyguardStatusBarViewControllerTest extends SysuiTestCase {
    private StatusBarUserSwitcherController mStatusBarUserSwitcherController;
    private StatusBarUserSwitcherController mStatusBarUserSwitcherController;
    @Mock
    @Mock
    private StatusBarUserInfoTracker mStatusBarUserInfoTracker;
    private StatusBarUserInfoTracker mStatusBarUserInfoTracker;
    @Mock private SecureSettings mSecureSettings;


    private TestNotificationPanelViewStateProvider mNotificationPanelViewStateProvider;
    private TestNotificationPanelViewStateProvider mNotificationPanelViewStateProvider;
    private KeyguardStatusBarView mKeyguardStatusBarView;
    private KeyguardStatusBarView mKeyguardStatusBarView;
    private KeyguardStatusBarViewController mController;
    private KeyguardStatusBarViewController mController;
    private FakeExecutor mFakeExecutor = new FakeExecutor(new FakeSystemClock());


    @Before
    @Before
    public void setup() throws Exception {
    public void setup() throws Exception {
@@ -150,7 +159,9 @@ public class KeyguardStatusBarViewControllerTest extends SysuiTestCase {
                mUserManager,
                mUserManager,
                mStatusBarUserSwitcherFeatureController,
                mStatusBarUserSwitcherFeatureController,
                mStatusBarUserSwitcherController,
                mStatusBarUserSwitcherController,
                mStatusBarUserInfoTracker
                mStatusBarUserInfoTracker,
                mSecureSettings,
                mFakeExecutor
        );
        );
    }
    }


@@ -420,6 +431,39 @@ public class KeyguardStatusBarViewControllerTest extends SysuiTestCase {
        assertThat(mKeyguardStatusBarView.isKeyguardUserAvatarEnabled()).isTrue();
        assertThat(mKeyguardStatusBarView.isKeyguardUserAvatarEnabled()).isTrue();
    }
    }


    @Test
    public void testBlockedIcons_obeysSettingForVibrateIcon_settingOff() {
        String str = mContext.getString(com.android.internal.R.string.status_bar_volume);

        // GIVEN the setting is off
        when(mSecureSettings.getInt(Settings.Secure.STATUS_BAR_SHOW_VIBRATE_ICON, 0))
                .thenReturn(0);

        // WHEN CollapsedStatusBarFragment builds the blocklist
        mController.updateBlockedIcons();

        // THEN status_bar_volume SHOULD be present in the list
        boolean contains = mController.getBlockedIcons().contains(str);
        assertTrue(contains);
    }

    @Test
    public void testBlockedIcons_obeysSettingForVibrateIcon_settingOn() {
        String str = mContext.getString(com.android.internal.R.string.status_bar_volume);

        // GIVEN the setting is ON
        when(mSecureSettings.getIntForUser(Settings.Secure.STATUS_BAR_SHOW_VIBRATE_ICON, 0,
                UserHandle.USER_CURRENT))
                .thenReturn(1);

        // WHEN CollapsedStatusBarFragment builds the blocklist
        mController.updateBlockedIcons();

        // THEN status_bar_volume SHOULD NOT be present in the list
        boolean contains = mController.getBlockedIcons().contains(str);
        assertFalse(contains);
    }

    private void updateStateToNotKeyguard() {
    private void updateStateToNotKeyguard() {
        updateStatusBarState(SHADE);
        updateStatusBarState(SHADE);
    }
    }