Make Lockscreen Notification Content work for profiles

The settings for the Notification Content is user-dependent
and the correct values are used in the lock screen.

Bug: 26709332
Change-Id: I7acf94014771dacc2841da336bed645fdb948541
diff --git a/src/com/android/settings/ChooseLockPassword.java b/src/com/android/settings/ChooseLockPassword.java
index 2fd012e..7e45da1 100644
--- a/src/com/android/settings/ChooseLockPassword.java
+++ b/src/com/android/settings/ChooseLockPassword.java
@@ -399,7 +399,7 @@
         }
 
         protected Intent getRedactionInterstitialIntent(Context context) {
-            return RedactionInterstitial.createStartIntent(context);
+            return RedactionInterstitial.createStartIntent(context, mUserId);
         }
 
         protected void updateStage(Stage stage) {
diff --git a/src/com/android/settings/ChooseLockPattern.java b/src/com/android/settings/ChooseLockPattern.java
index 960ec1a..2c8fd20 100644
--- a/src/com/android/settings/ChooseLockPattern.java
+++ b/src/com/android/settings/ChooseLockPattern.java
@@ -465,7 +465,7 @@
         }
 
         protected Intent getRedactionInterstitialIntent(Context context) {
-            return RedactionInterstitial.createStartIntent(context);
+            return RedactionInterstitial.createStartIntent(context, mUserId);
         }
 
         public void handleLeftButton() {
diff --git a/src/com/android/settings/SetupRedactionInterstitial.java b/src/com/android/settings/SetupRedactionInterstitial.java
index 4939aea..e967297 100644
--- a/src/com/android/settings/SetupRedactionInterstitial.java
+++ b/src/com/android/settings/SetupRedactionInterstitial.java
@@ -21,6 +21,7 @@
 import android.content.Intent;
 import android.content.res.Resources;
 import android.os.Bundle;
+import android.os.UserHandle;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
@@ -39,7 +40,7 @@
 public class SetupRedactionInterstitial extends RedactionInterstitial {
 
     public static Intent createStartIntent(Context ctx) {
-        Intent startIntent = RedactionInterstitial.createStartIntent(ctx);
+        Intent startIntent = RedactionInterstitial.createStartIntent(ctx, UserHandle.myUserId());
         if (startIntent != null) {
             startIntent.setClass(ctx, SetupRedactionInterstitial.class);
             startIntent.putExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, false)
diff --git a/src/com/android/settings/fingerprint/FingerprintSettings.java b/src/com/android/settings/fingerprint/FingerprintSettings.java
index 07c0dfe..8b5da87 100644
--- a/src/com/android/settings/fingerprint/FingerprintSettings.java
+++ b/src/com/android/settings/fingerprint/FingerprintSettings.java
@@ -304,7 +304,7 @@
             TextView v = (TextView) LayoutInflater.from(view.getContext()).inflate(
                     R.layout.fingerprint_settings_footer, null);
             EnforcedAdmin admin = RestrictedLockUtils.checkIfKeyguardFeaturesDisabled(
-                    getActivity(), DevicePolicyManager.KEYGUARD_DISABLE_FINGERPRINT);
+                    getActivity(), DevicePolicyManager.KEYGUARD_DISABLE_FINGERPRINT, mUserId);
             v.setText(LearnMoreSpan.linkify(getText(admin != null
                             ? R.string.security_settings_fingerprint_enroll_disclaimer_lockscreen_disabled
                             : R.string.security_settings_fingerprint_enroll_disclaimer),
diff --git a/src/com/android/settings/notification/ConfigureNotificationSettings.java b/src/com/android/settings/notification/ConfigureNotificationSettings.java
index a81bb13..17571c9 100644
--- a/src/com/android/settings/notification/ConfigureNotificationSettings.java
+++ b/src/com/android/settings/notification/ConfigureNotificationSettings.java
@@ -192,7 +192,7 @@
     private void setRestrictedIfNotificationFeaturesDisabled(CharSequence entry,
             CharSequence entryValue, int keyguardNotificationFeatures) {
         EnforcedAdmin admin = RestrictedLockUtils.checkIfKeyguardFeaturesDisabled(
-                mContext, keyguardNotificationFeatures);
+                mContext, keyguardNotificationFeatures, UserHandle.myUserId());
         if (admin != null) {
             RestrictedItem item = new RestrictedItem(entry, entryValue, admin);
             mLockscreen.addRestrictedItem(item);
diff --git a/src/com/android/settings/notification/RedactionInterstitial.java b/src/com/android/settings/notification/RedactionInterstitial.java
index 2f871c4..bd1dfe8 100644
--- a/src/com/android/settings/notification/RedactionInterstitial.java
+++ b/src/com/android/settings/notification/RedactionInterstitial.java
@@ -19,18 +19,21 @@
 import android.content.Context;
 import android.content.Intent;
 import android.os.Bundle;
+import android.os.UserManager;
 import android.provider.Settings;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
 import android.widget.RadioButton;
 import android.widget.RadioGroup;
+import android.widget.TextView;
 
 import com.android.internal.logging.MetricsProto.MetricsEvent;
 import com.android.settings.R;
 import com.android.settings.RestrictedRadioButton;
 import com.android.settings.SettingsActivity;
 import com.android.settings.SettingsPreferenceFragment;
+import com.android.settings.Utils;
 import com.android.settingslib.RestrictedLockUtils;
 
 import static android.app.admin.DevicePolicyManager.KEYGUARD_DISABLE_SECURE_NOTIFICATIONS;
@@ -57,14 +60,17 @@
      * @return An intent to launch the activity is if is available, @null if the activity is not
      * available to be launched.
      */
-    public static Intent createStartIntent(Context ctx) {
+    public static Intent createStartIntent(Context ctx, int userId) {
         return new Intent(ctx, RedactionInterstitial.class)
                 .putExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, true)
                 .putExtra(EXTRA_PREFS_SET_BACK_TEXT, (String) null)
                 .putExtra(EXTRA_PREFS_SET_NEXT_TEXT, ctx.getString(
                         R.string.app_notifications_dialog_done))
                 .putExtra(EXTRA_SHOW_FRAGMENT_TITLE_RESID,
-                        R.string.lock_screen_notifications_interstitial_title);
+                        Utils.isManagedProfile(UserManager.get(ctx), userId)
+                            ? R.string.lock_screen_notifications_interstitial_title_profile
+                            : R.string.lock_screen_notifications_interstitial_title)
+                .putExtra(Intent.EXTRA_USER_ID, userId);
     }
 
     public static class RedactionInterstitialFragment extends SettingsPreferenceFragment
@@ -73,6 +79,7 @@
         private RadioGroup mRadioGroup;
         private RestrictedRadioButton mShowAllButton;
         private RestrictedRadioButton mRedactSensitiveButton;
+        private int mUserId;
 
         @Override
         protected int getMetricsCategory() {
@@ -90,9 +97,21 @@
             super.onViewCreated(view, savedInstanceState);
             mRadioGroup = (RadioGroup) view.findViewById(R.id.radio_group);
             mShowAllButton = (RestrictedRadioButton) view.findViewById(R.id.show_all);
-            mRedactSensitiveButton = (RestrictedRadioButton) view.findViewById(R.id.redact_sensitive);
+            mRedactSensitiveButton =
+                    (RestrictedRadioButton) view.findViewById(R.id.redact_sensitive);
 
             mRadioGroup.setOnCheckedChangeListener(this);
+            mUserId = Utils.getUserIdFromBundle(
+                    getContext(), getActivity().getIntent().getExtras());
+            if (Utils.isManagedProfile(UserManager.get(getContext()), mUserId)) {
+                ((TextView) view.findViewById(R.id.message))
+                    .setText(R.string.lock_screen_notifications_interstitial_message_profile);
+                mShowAllButton.setText(R.string.lock_screen_notifications_summary_show_profile);
+                mRedactSensitiveButton
+                    .setText(R.string.lock_screen_notifications_summary_hide_profile);
+                ((RadioButton) view.findViewById(R.id.hide_all))
+                    .setText(R.string.lock_screen_notifications_summary_disable_profile);
+            }
         }
 
         @Override
@@ -111,15 +130,15 @@
         private void checkNotificationFeaturesAndSetDisabled(RestrictedRadioButton button,
                 int keyguardNotifications) {
             EnforcedAdmin admin = RestrictedLockUtils.checkIfKeyguardFeaturesDisabled(
-                    getActivity(), keyguardNotifications);
+                    getActivity(), keyguardNotifications, mUserId);
             button.setDisabledByAdmin(admin);
         }
 
         private void loadFromSettings() {
-            final boolean enabled = Settings.Secure.getInt(getContentResolver(),
-                        Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, 0) != 0;
-            final boolean show = Settings.Secure.getInt(getContentResolver(),
-                        Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 1) != 0;
+            final boolean enabled = Settings.Secure.getIntForUser(getContentResolver(),
+                        Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, 0, mUserId) != 0;
+            final boolean show = Settings.Secure.getIntForUser(getContentResolver(),
+                        Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 1, mUserId) != 0;
 
             int checkedButtonId = R.id.hide_all;
             if (enabled) {
@@ -138,10 +157,10 @@
             final boolean show = (checkedId == R.id.show_all);
             final boolean enabled = (checkedId != R.id.hide_all);
 
-            Settings.Secure.putInt(getContentResolver(),
-                    Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, show ? 1 : 0);
-            Settings.Secure.putInt(getContentResolver(),
-                    Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, enabled ? 1 : 0);
+            Settings.Secure.putIntForUser(getContentResolver(),
+                    Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, show ? 1 : 0, mUserId);
+            Settings.Secure.putIntForUser(getContentResolver(),
+                    Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, enabled ? 1 : 0, mUserId);
         }
     }
 }