Makke DONE button close activity on readonly group editor

Bug 5142181

Change-Id: I5b300b150113b77800de698dbb7bdd40c35b15f4
diff --git a/src/com/android/contacts/activities/GroupEditorActivity.java b/src/com/android/contacts/activities/GroupEditorActivity.java
index 80653d2..79360f7 100644
--- a/src/com/android/contacts/activities/GroupEditorActivity.java
+++ b/src/com/android/contacts/activities/GroupEditorActivity.java
@@ -71,7 +71,7 @@
             saveMenuItem.setOnClickListener(new OnClickListener() {
                 @Override
                 public void onClick(View v) {
-                    mFragment.doSaveAction();
+                    mFragment.onDoneClicked();
                 }
             });
             // Show the custom action bar but hide the home icon and title
diff --git a/src/com/android/contacts/group/GroupEditorFragment.java b/src/com/android/contacts/group/GroupEditorFragment.java
index f62a671..d593352 100644
--- a/src/com/android/contacts/group/GroupEditorFragment.java
+++ b/src/com/android/contacts/group/GroupEditorFragment.java
@@ -359,13 +359,27 @@
         }
     }
 
+    private AccountType getAccountType() {
+        return AccountTypeManager.getInstance(mContext).getAccountType(mAccountType, mDataSet);
+    }
+
+    /**
+     * @return true if the group membership is editable on this account type.  false otherwise,
+     *         or account is not set yet.
+     */
+    private boolean isGroupMembershipEditable() {
+        if (mAccountType == null) {
+            return false;
+        }
+        return getAccountType().isGroupMembershipEditable();
+    }
+
     /**
      * Sets up the editor based on the group's account name and type.
      */
     private void setupEditorForAccount() {
-        final AccountTypeManager accountTypeManager = AccountTypeManager.getInstance(mContext);
-        final AccountType accountType = accountTypeManager.getAccountType(mAccountType, mDataSet);
-        final boolean editable = accountType.isGroupMembershipEditable();
+        final AccountType accountType = getAccountType();
+        final boolean editable = isGroupMembershipEditable();
         mMemberListAdapter.setIsGroupMembershipEditable(editable);
 
         View editorView = mLayoutInflater.inflate(editable ?
@@ -463,8 +477,13 @@
         mListener = value;
     }
 
-    public void doSaveAction() {
-        save(SaveMode.CLOSE);
+    public void onDoneClicked() {
+        if (isGroupMembershipEditable()) {
+            save(SaveMode.CLOSE);
+        } else {
+            // Just revert it.
+            doRevertAction();
+        }
     }
 
     @Override