Replace smart reply boolean setting with key-value list
This patch replaces the recently introduced
Settings.Global.ENABLE_SMART_REPLIES_IN_NOTIFICATIONS boolean setting
with a new Settings.Global.SMART_REPLIES_IN_NOTIFICATIONS_FLAGS
key-value list.
Rationale: This will allow us to add and tweak smart reply parameters
without polluting the global settings namespace.
Bug: 67765414
Test: atest SmartReplyConstantsTest
Change-Id: I284bb6b31618a234c4772d16ad6190a713035f1b
diff --git a/packages/SystemUI/src/com/android/systemui/SystemUIFactory.java b/packages/SystemUI/src/com/android/systemui/SystemUIFactory.java
index 0f3daf5..d1834e9 100644
--- a/packages/SystemUI/src/com/android/systemui/SystemUIFactory.java
+++ b/packages/SystemUI/src/com/android/systemui/SystemUIFactory.java
@@ -52,6 +52,7 @@
import com.android.systemui.statusbar.phone.StatusBarIconController;
import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager;
import com.android.systemui.statusbar.policy.DeviceProvisionedController;
+import com.android.systemui.statusbar.policy.SmartReplyConstants;
import java.util.function.Consumer;
@@ -130,6 +131,8 @@
providers.put(NotificationGutsManager.class, () -> new NotificationGutsManager(context));
providers.put(NotificationRemoteInputManager.class,
() -> new NotificationRemoteInputManager(context));
+ providers.put(SmartReplyConstants.class,
+ () -> new SmartReplyConstants(Dependency.get(Dependency.MAIN_HANDLER), context));
providers.put(NotificationListener.class, () -> new NotificationListener(context));
providers.put(NotificationLogger.class, NotificationLogger::new);
providers.put(NotificationViewHierarchyManager.class,
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationContentView.java b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationContentView.java
index e811ed3..c4d0b79 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationContentView.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationContentView.java
@@ -22,7 +22,6 @@
import android.content.Context;
import android.graphics.Rect;
import android.os.Build;
-import android.provider.Settings;
import android.service.notification.StatusBarNotification;
import android.util.AttributeSet;
import android.util.Log;
@@ -36,6 +35,7 @@
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.util.NotificationColorUtil;
+import com.android.systemui.Dependency;
import com.android.systemui.R;
import com.android.systemui.statusbar.notification.HybridGroupManager;
import com.android.systemui.statusbar.notification.HybridNotificationView;
@@ -44,6 +44,7 @@
import com.android.systemui.statusbar.notification.NotificationViewWrapper;
import com.android.systemui.statusbar.phone.NotificationGroupManager;
import com.android.systemui.statusbar.policy.RemoteInputView;
+import com.android.systemui.statusbar.policy.SmartReplyConstants;
import com.android.systemui.statusbar.policy.SmartReplyView;
/**
@@ -75,6 +76,8 @@
private RemoteInputView mExpandedRemoteInput;
private RemoteInputView mHeadsUpRemoteInput;
+
+ private SmartReplyConstants mSmartReplyConstants;
private SmartReplyView mExpandedSmartReplyView;
private NotificationViewWrapper mContractedWrapper;
@@ -145,6 +148,7 @@
public NotificationContentView(Context context, AttributeSet attrs) {
super(context, attrs);
mHybridGroupManager = new HybridGroupManager(getContext(), this);
+ mSmartReplyConstants = Dependency.get(SmartReplyConstants.class);
initView();
}
@@ -1166,8 +1170,7 @@
return;
}
- boolean enableSmartReplies = Settings.Global.getInt(mContext.getContentResolver(),
- Settings.Global.ENABLE_SMART_REPLIES_IN_NOTIFICATIONS, 0) != 0;
+ boolean enableSmartReplies = mSmartReplyConstants.isEnabled();
boolean hasRemoteInput = false;
RemoteInput remoteInputWithChoices = null;
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/SmartReplyConstants.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/SmartReplyConstants.java
new file mode 100644
index 0000000..c5067a6
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/SmartReplyConstants.java
@@ -0,0 +1,95 @@
+/*
+ * Copyright (C) 2018 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.policy;
+
+import android.content.ContentResolver;
+import android.content.Context;
+import android.content.res.Resources;
+import android.database.ContentObserver;
+import android.net.Uri;
+import android.os.Handler;
+import android.provider.Settings;
+import android.util.KeyValueListParser;
+import android.util.Log;
+
+import com.android.systemui.R;
+
+public final class SmartReplyConstants extends ContentObserver {
+
+ private static final String TAG = "SmartReplyConstants";
+
+ private static final String KEY_ENABLED = "enabled";
+ private static final String KEY_MAX_SQUEEZE_REMEASURE_ATTEMPTS =
+ "max_squeeze_remeasure_attempts";
+
+ private final boolean mDefaultEnabled;
+ private final int mDefaultMaxSqueezeRemeasureAttempts;
+
+ private boolean mEnabled;
+ private int mMaxSqueezeRemeasureAttempts;
+
+ private final Context mContext;
+ private final KeyValueListParser mParser = new KeyValueListParser(',');
+
+ public SmartReplyConstants(Handler handler, Context context) {
+ super(handler);
+
+ mContext = context;
+ final Resources resources = mContext.getResources();
+ mDefaultEnabled = resources.getBoolean(
+ R.bool.config_smart_replies_in_notifications_enabled);
+ mDefaultMaxSqueezeRemeasureAttempts = resources.getInteger(
+ R.integer.config_smart_replies_in_notifications_max_squeeze_remeasure_attempts);
+
+ mContext.getContentResolver().registerContentObserver(
+ Settings.Global.getUriFor(Settings.Global.SMART_REPLIES_IN_NOTIFICATIONS_FLAGS),
+ false, this);
+ updateConstants();
+ }
+
+ @Override
+ public void onChange(boolean selfChange, Uri uri) {
+ updateConstants();
+ }
+
+ private void updateConstants() {
+ synchronized (SmartReplyConstants.this) {
+ try {
+ mParser.setString(Settings.Global.getString(mContext.getContentResolver(),
+ Settings.Global.SMART_REPLIES_IN_NOTIFICATIONS_FLAGS));
+ } catch (IllegalArgumentException e) {
+ Log.e(TAG, "Bad smart reply constants", e);
+ }
+ mEnabled = mParser.getBoolean(KEY_ENABLED, mDefaultEnabled);
+ mMaxSqueezeRemeasureAttempts = mParser.getInt(
+ KEY_MAX_SQUEEZE_REMEASURE_ATTEMPTS, mDefaultMaxSqueezeRemeasureAttempts);
+ }
+ }
+
+ /** Returns whether smart replies in notifications are enabled. */
+ public boolean isEnabled() {
+ return mEnabled;
+ }
+
+ /**
+ * Returns the maximum number of times {@link SmartReplyView#onMeasure(int, int)} will try to
+ * find a better (narrower) line-break for a double-line smart reply button.
+ */
+ public int getMaxSqueezeRemeasureAttempts() {
+ return mMaxSqueezeRemeasureAttempts;
+ }
+}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/SmartReplyView.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/SmartReplyView.java
index 2d829af..57fc03c 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/SmartReplyView.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/SmartReplyView.java
@@ -12,6 +12,7 @@
import android.widget.Button;
import android.widget.LinearLayout;
+import com.android.systemui.Dependency;
import com.android.systemui.R;
/** View which displays smart reply buttons in notifications. */
@@ -19,8 +20,11 @@
private static final String TAG = "SmartReplyView";
+ private final SmartReplyConstants mConstants;
+
public SmartReplyView(Context context, AttributeSet attrs) {
super(context, attrs);
+ mConstants = Dependency.get(SmartReplyConstants.class);
}
public void setRepliesFromRemoteInput(RemoteInput remoteInput, PendingIntent pendingIntent) {