OSDN Git Service

Add flag to control blocking Smart Replies for apps targeting an Android version...
authorRichard Ledley <rledley@google.com>
Mon, 26 Feb 2018 10:36:00 +0000 (10:36 +0000)
committerRichard Ledley <rledley@google.com>
Fri, 23 Mar 2018 21:14:27 +0000 (21:14 +0000)
Bug: 73802997

Test: atest SmartReplyConstantsTest

Change-Id: Id340cba09da7931ff6a4689802b3a5f594852a72
(cherry picked from commit 28944cbdcf15128b664ccdaed44c59d3fc64d1db)

core/java/android/provider/Settings.java
packages/SystemUI/res/values/config.xml
packages/SystemUI/src/com/android/systemui/statusbar/NotificationContentView.java
packages/SystemUI/src/com/android/systemui/statusbar/policy/SmartReplyConstants.java
packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/SmartReplyConstantsTest.java

index 18fd67e..a013d3d 100644 (file)
@@ -12427,6 +12427,7 @@ public final class Settings {
          *
          * <pre>
          * enabled                         (boolean)
+         * requires_targeting_p            (boolean)
          * max_squeeze_remeasure_attempts  (int)
          * </pre>
          * @see com.android.systemui.statusbar.policy.SmartReplyConstants
index 9ebf557..f76603b 100644 (file)
     <!-- Smart replies in notifications: Whether smart replies in notifications are enabled. -->
     <bool name="config_smart_replies_in_notifications_enabled">true</bool>
 
+    <!-- Smart replies in notifications: Whether we disable the feature unless the app targets P -->
+    <bool name="config_smart_replies_in_notifications_requires_targeting_p">true</bool>
+
     <!-- Smart replies in notifications: Maximum number of times SmartReplyView will try to find a
          better (narrower) line-break for a double-line smart reply button. -->
     <integer name="config_smart_replies_in_notifications_max_squeeze_remeasure_attempts">3</integer>
index f64b1bc..b81e9af 100644 (file)
@@ -1210,7 +1210,9 @@ public class NotificationContentView extends FrameLayout {
             return;
         }
 
-        boolean enableSmartReplies = mSmartReplyConstants.isEnabled();
+        boolean enableSmartReplies = (mSmartReplyConstants.isEnabled()
+                && (!mSmartReplyConstants.requiresTargetingP()
+                    || entry.targetSdk >= Build.VERSION_CODES.P));
 
         boolean hasRemoteInput = false;
         RemoteInput remoteInputWithChoices = null;
index c5067a6..7b0b800 100644 (file)
@@ -33,13 +33,16 @@ public final class SmartReplyConstants extends ContentObserver {
     private static final String TAG = "SmartReplyConstants";
 
     private static final String KEY_ENABLED = "enabled";
+    private static final String KEY_REQUIRES_TARGETING_P = "requires_targeting_p";
     private static final String KEY_MAX_SQUEEZE_REMEASURE_ATTEMPTS =
             "max_squeeze_remeasure_attempts";
 
     private final boolean mDefaultEnabled;
+    private final boolean mDefaultRequiresP;
     private final int mDefaultMaxSqueezeRemeasureAttempts;
 
     private boolean mEnabled;
+    private boolean mRequiresTargetingP;
     private int mMaxSqueezeRemeasureAttempts;
 
     private final Context mContext;
@@ -52,6 +55,8 @@ public final class SmartReplyConstants extends ContentObserver {
         final Resources resources = mContext.getResources();
         mDefaultEnabled = resources.getBoolean(
                 R.bool.config_smart_replies_in_notifications_enabled);
+        mDefaultRequiresP = resources.getBoolean(
+                R.bool.config_smart_replies_in_notifications_requires_targeting_p);
         mDefaultMaxSqueezeRemeasureAttempts = resources.getInteger(
                 R.integer.config_smart_replies_in_notifications_max_squeeze_remeasure_attempts);
 
@@ -75,6 +80,7 @@ public final class SmartReplyConstants extends ContentObserver {
                 Log.e(TAG, "Bad smart reply constants", e);
             }
             mEnabled = mParser.getBoolean(KEY_ENABLED, mDefaultEnabled);
+            mRequiresTargetingP = mParser.getBoolean(KEY_REQUIRES_TARGETING_P, mDefaultRequiresP);
             mMaxSqueezeRemeasureAttempts = mParser.getInt(
                     KEY_MAX_SQUEEZE_REMEASURE_ATTEMPTS, mDefaultMaxSqueezeRemeasureAttempts);
         }
@@ -86,6 +92,14 @@ public final class SmartReplyConstants extends ContentObserver {
     }
 
     /**
+     * Returns whether smart replies in notifications should be disabled when the app targets a
+     * version of Android older than P.
+     */
+    public boolean requiresTargetingP() {
+        return mRequiresTargetingP;
+    }
+
+    /**
      * 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.
      */
index 32a7cb9..aca7c9c 100644 (file)
@@ -74,6 +74,17 @@ public class SmartReplyConstantsTest extends SysuiTestCase {
     }
 
     @Test
+    public void testRequiresTargetingPConfig() {
+        overrideSetting("enabled=true,requires_targeting_p=false");
+        triggerConstantsOnChange();
+        assertEquals(false, mConstants.requiresTargetingP());
+
+        overrideSetting("enabled=true");
+        triggerConstantsOnChange();
+        assertEquals(true, mConstants.requiresTargetingP());
+    }
+
+    @Test
     public void testGetMaxSqueezeRemeasureAttemptsWithNoConfig() {
         assertTrue(mConstants.isEnabled());
         assertEquals(7, mConstants.getMaxSqueezeRemeasureAttempts());