From 5ab8c632b6da63a057b90b54fae674c282f55fe1 Mon Sep 17 00:00:00 2001 From: Matt Pietal Date: Tue, 27 Apr 2021 15:12:43 -0400 Subject: [PATCH] Smartspace - Check sensitivity settings For both the current user and any managed profiles, check to see if sensitive smartspace content should be filtered out, based on the user settings. Bug: 183401939 Test: atest KeyguardClockSwitchControllerTest Change-Id: I5de56b1e3229629864304853c26dc45c98ef0114 --- .../KeyguardClockSwitchController.java | 102 ++++++++++++++++- .../KeyguardClockSwitchControllerTest.java | 108 +++++++++++++++++- 2 files changed, 206 insertions(+), 4 deletions(-) diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitchController.java b/packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitchController.java index 5b835516625b2..e92cae4506fc8 100644 --- a/packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitchController.java +++ b/packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitchController.java @@ -24,8 +24,16 @@ import android.app.WallpaperManager; import android.app.smartspace.SmartspaceConfig; import android.app.smartspace.SmartspaceManager; import android.app.smartspace.SmartspaceSession; +import android.app.smartspace.SmartspaceTarget; +import android.content.Context; import android.content.Intent; +import android.content.pm.UserInfo; import android.content.res.Resources; +import android.database.ContentObserver; +import android.net.Uri; +import android.os.Handler; +import android.os.UserHandle; +import android.provider.Settings; import android.text.TextUtils; import android.text.format.DateFormat; import android.view.View; @@ -47,6 +55,7 @@ import com.android.systemui.plugins.BcSmartspaceDataPlugin.IntentStarter; import com.android.systemui.plugins.ClockPlugin; import com.android.systemui.plugins.FalsingManager; import com.android.systemui.plugins.statusbar.StatusBarStateController; +import com.android.systemui.settings.UserTracker; import com.android.systemui.statusbar.FeatureFlags; import com.android.systemui.statusbar.notification.AnimatableProperty; import com.android.systemui.statusbar.notification.PropertyAnimator; @@ -57,6 +66,7 @@ import com.android.systemui.statusbar.phone.NotificationIconContainer; import com.android.systemui.statusbar.policy.BatteryController; import com.android.systemui.statusbar.policy.ConfigurationController; import com.android.systemui.util.ViewController; +import com.android.systemui.util.settings.SecureSettings; import java.util.Locale; import java.util.TimeZone; @@ -96,6 +106,14 @@ public class KeyguardClockSwitchController extends ViewController smartspaceDataPlugin.onTargetsAvailable(targets); + mSmartspaceCallback = targets -> { + targets.removeIf(this::filterSmartspaceTarget); + smartspaceDataPlugin.onTargetsAvailable(targets); + }; mSmartspaceSession.addOnTargetsAvailableListener(mUiExecutor, mSmartspaceCallback); - mSmartspaceSession.requestSmartspaceUpdate(); + mSettingsObserver = new ContentObserver(mHandler) { + @Override + public void onChange(boolean selfChange, Uri uri) { + reloadSmartspace(); + } + }; + + mUserTrackerCallback = new UserTracker.Callback() { + public void onUserChanged(int newUser, Context userContext) { + reloadSmartspace(); + } + }; + mUserTracker.addCallback(mUserTrackerCallback, mUiExecutor); + + getContext().getContentResolver().registerContentObserver( + Settings.Secure.getUriFor( + Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS), + true, mSettingsObserver, UserHandle.USER_ALL); + reloadSmartspace(); } float dozeAmount = mStatusBarStateController.getDozeAmount(); mStatusBarStateListener.onDozeAmountChanged(dozeAmount, dozeAmount); } + @VisibleForTesting + boolean filterSmartspaceTarget(SmartspaceTarget t) { + if (!t.isSensitive()) return false; + + if (t.getUserHandle().equals(mUserTracker.getUserHandle())) { + return !mShowSensitiveContentForCurrentUser; + } + if (t.getUserHandle().equals(mManagedUserHandle)) { + return !mShowSensitiveContentForManagedUser; + } + + return false; + } + + private void reloadSmartspace() { + mManagedUserHandle = getWorkProfileUser(); + final String setting = Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS; + + mShowSensitiveContentForCurrentUser = + mSecureSettings.getIntForUser(setting, 0, mUserTracker.getUserId()) == 1; + if (mManagedUserHandle != null) { + int id = mManagedUserHandle.getIdentifier(); + mShowSensitiveContentForManagedUser = + mSecureSettings.getIntForUser(setting, 0, id) == 1; + } + + mSmartspaceSession.requestSmartspaceUpdate(); + } + + private UserHandle getWorkProfileUser() { + for (UserInfo userInfo : mUserTracker.getUserProfiles()) { + if (userInfo.isManagedProfile()) { + return userInfo.getUserHandle(); + } + } + return null; + } + private void updateWallpaperColor() { if (mSmartspaceView != null) { int color = Utils.getColorAttrDefaultColor(getContext(), R.attr.wallpaperTextColor); @@ -289,6 +372,14 @@ public class KeyguardClockSwitchController extends ViewController