Remove rename automatic zen rule.

Use zen rule id as key when finding matching rule to update.

Bug: 22977552
Change-Id: I7beeb5688aabe409a9a72aaa3aa27932d590c489
diff --git a/core/java/android/app/INotificationManager.aidl b/core/java/android/app/INotificationManager.aidl
index 920fbe9..e95a35a 100644
--- a/core/java/android/app/INotificationManager.aidl
+++ b/core/java/android/app/INotificationManager.aidl
@@ -93,11 +93,11 @@
     String[] getPackagesRequestingNotificationPolicyAccess();
     boolean isNotificationPolicyAccessGrantedForPackage(String pkg);
     void setNotificationPolicyAccessGranted(String pkg, boolean granted);
-    AutomaticZenRule getAutomaticZenRule(String name);
+    AutomaticZenRule getAutomaticZenRule(String id);
     List<AutomaticZenRule> getAutomaticZenRules();
-    boolean addOrUpdateAutomaticZenRule(in AutomaticZenRule automaticZenRule);
-    boolean renameAutomaticZenRule(String oldName, String newName);
-    boolean removeAutomaticZenRule(String name);
+    AutomaticZenRule addAutomaticZenRule(in AutomaticZenRule automaticZenRule);
+    boolean updateAutomaticZenRule(in AutomaticZenRule automaticZenRule);
+    boolean removeAutomaticZenRule(String id);
 
     byte[] getBackupPayload(int user);
     void applyRestore(in byte[] payload, int user);
diff --git a/core/java/android/app/NotificationManager.java b/core/java/android/app/NotificationManager.java
index cbf198b..cb0ff33 100644
--- a/core/java/android/app/NotificationManager.java
+++ b/core/java/android/app/NotificationManager.java
@@ -436,48 +436,47 @@
     }
 
     /**
-     * Returns the AutomaticZenRule with the given name, if it exists and the caller has access.
+     * Returns the AutomaticZenRule with the given id, if it exists and the caller has access.
      *
      * <p>
      * Only available if policy access is granted to this package.
      * See {@link #isNotificationPolicyAccessGranted}.
      *
      * <p>
-     * Returns null if there are no zen rules that match the given name, or if the calling package
+     * Returns null if there are no zen rules that match the given id, or if the calling package
      * doesn't own the matching rule. See {@link AutomaticZenRule#getOwner}.
      */
-    public AutomaticZenRule getAutomaticZenRule(String name) {
+    public AutomaticZenRule getAutomaticZenRule(String id) {
         INotificationManager service = getService();
         try {
-            return service.getAutomaticZenRule(name);
+            return service.getAutomaticZenRule(id);
         } catch (RemoteException e) {
         }
         return null;
     }
 
     /**
-     * Creates or updates the given zen rule.
+     * Creates the given zen rule.
      *
      * <p>
      * Only available if policy access is granted to this package.
      * See {@link #isNotificationPolicyAccessGranted}.
      *
-     * <p>
-     * Callers can only update rules that they own. See {@link AutomaticZenRule#getOwner}.
-     * @param automaticZenRule the rule to create or update.
-     * @return Whether the rule was successfully created or updated.
+     * @param automaticZenRule the rule to create.
+     * @return A fully populated {@link AutomaticZenRule} if the rule was persisted successfully,
+     * null otherwise.
      */
-    public boolean addOrUpdateAutomaticZenRule(AutomaticZenRule automaticZenRule) {
+    public AutomaticZenRule addAutomaticZenRule(AutomaticZenRule automaticZenRule) {
         INotificationManager service = getService();
         try {
-            return service.addOrUpdateAutomaticZenRule(automaticZenRule);
+            return service.addAutomaticZenRule(automaticZenRule);
         } catch (RemoteException e) {
         }
-        return false;
+        return null;
     }
 
     /**
-     * Renames a zen rule.
+     * Updates the given zen rule.
      *
      * <p>
      * Only available if policy access is granted to this package.
@@ -485,21 +484,20 @@
      *
      * <p>
      * Callers can only update rules that they own. See {@link AutomaticZenRule#getOwner}.
-     * @param oldName The name of the rule to update.
-     * @param newName The new name for the rule.
+     * @param automaticZenRule the rule to update. 
      * @return Whether the rule was successfully updated.
      */
-    public boolean renameAutomaticZenRule(String oldName, String newName) {
+    public boolean updateAutomaticZenRule(AutomaticZenRule automaticZenRule) {
         INotificationManager service = getService();
         try {
-            return service.renameAutomaticZenRule(oldName, newName);
+            return service.updateAutomaticZenRule(automaticZenRule);
         } catch (RemoteException e) {
         }
         return false;
     }
 
     /**
-     * Deletes the automatic zen rule with the given name.
+     * Deletes the automatic zen rule with the given id.
      *
      * <p>
      * Only available if policy access is granted to this package.
@@ -507,13 +505,13 @@
      *
      * <p>
      * Callers can only delete rules that they own. See {@link AutomaticZenRule#getOwner}.
-     * @param name the name of the rule to delete.
+     * @param id the id of the rule to delete.
      * @return Whether the rule was successfully deleted.
      */
-    public boolean removeAutomaticZenRule(String name) {
+    public boolean removeAutomaticZenRule(String id) {
         INotificationManager service = getService();
         try {
-            return service.removeAutomaticZenRule(name);
+            return service.removeAutomaticZenRule(id);
         } catch (RemoteException e) {
         }
         return false;
diff --git a/core/java/android/service/notification/ConditionProviderService.java b/core/java/android/service/notification/ConditionProviderService.java
index 2a8fb2c..c679eda 100644
--- a/core/java/android/service/notification/ConditionProviderService.java
+++ b/core/java/android/service/notification/ConditionProviderService.java
@@ -35,8 +35,7 @@
  * the {@link android.Manifest.permission#BIND_CONDITION_PROVIDER_SERVICE} permission
  * and include an intent filter with the {@link #SERVICE_INTERFACE} action. If you want users to be
  * able to create and update conditions for this service to monitor, include the
- * {@link #META_DATA_RULE_TYPE}, {@link #META_DATA_DEFAULT_CONDITION_ID}, and
- * {@link #META_DATA_CONFIGURATION_ACTIVITY} tags. For example:</p>
+ * {@link #META_DATA_RULE_TYPE} and {@link #META_DATA_CONFIGURATION_ACTIVITY} tags. For example:</p>
  * <pre>
  * &lt;service android:name=".MyConditionProvider"
  *          android:label="&#64;string/service_name"
@@ -49,10 +48,6 @@
  *               android:value="@string/my_condition_rule">
  *           &lt;/meta-data>
  *           &lt;meta-data
- *               android:name="android.service.zen.automatic.defaultConditionId"
- *               android:value="condition://com.my.package/mycondition">
- *           &lt;/meta-data>
- *           &lt;meta-data
  *               android:name="android.service.zen.automatic.configurationActivity"
  *               android:value="com.my.package/.MyConditionConfigurationActivity">
  *           &lt;/meta-data>
@@ -82,13 +77,6 @@
     public static final String META_DATA_RULE_TYPE = "android.service.zen.automatic.ruleType";
 
     /**
-     * The name of the {@code meta-data} tag containing a default Condition {@link Uri} that can
-     * be parsed by this service.
-     */
-    public static final String META_DATA_DEFAULT_CONDITION_ID =
-            "android.service.zen.automatic.defaultConditionId";
-
-    /**
      * The name of the {@code meta-data} tag containing the {@link ComponentName} of an activity
      * that allows users to configure the conditions provided by this service.
      */
@@ -96,17 +84,9 @@
             "android.service.zen.automatic.configurationActivity";
 
     /**
-     * A condition {@link Uri} extra passed to {@link #META_DATA_CONFIGURATION_ACTIVITY}. If the
-     * condition Uri is modified by that activity, it must be included in the result Intent extras
-     * in order to be persisted.
+     * A String rule id extra passed to {@link #META_DATA_CONFIGURATION_ACTIVITY}.
      */
-    public static final String EXTRA_CONDITION_ID = "android.content.automatic.conditionId";
-
-    /**
-     * A String rule name extra passed to {@link #META_DATA_CONFIGURATION_ACTIVITY}. This extra is
-     * informative only, and will be ignored if included in the result Intent extras.
-     */
-    public static final String EXTRA_RULE_NAME = "android.content.automatic.ruleName";
+    public static final String EXTRA_RULE_ID = "android.content.automatic.ruleId";
 
     /**
      * Called when this service is connected.
diff --git a/core/java/android/service/notification/ZenModeConfig.java b/core/java/android/service/notification/ZenModeConfig.java
index 9a0f7fc..e054a61 100644
--- a/core/java/android/service/notification/ZenModeConfig.java
+++ b/core/java/android/service/notification/ZenModeConfig.java
@@ -896,7 +896,7 @@
         return Global.isValidZenMode(rt) ? rt : defValue;
     }
 
-    public String newRuleId() {
+    public static String newRuleId() {
         return UUID.randomUUID().toString().replace("-", "");
     }