OSDN Git Service

Show confirmation when turning on "Phone calls/sms"
authorFyodor Kupolov <fkupolov@google.com>
Mon, 29 Dec 2014 21:40:27 +0000 (13:40 -0800)
committerFyodor Kupolov <fkupolov@google.com>
Thu, 8 Jan 2015 19:21:26 +0000 (11:21 -0800)
Added confirmation dialog, when turning on "Phone calls and sms" setting for
secondary users and guests.

Bug:15761405
Change-Id: I39b2181f0b5460db9a964c6883f053a6c6336622

res/values/strings.xml
src/com/android/settings/Utils.java
src/com/android/settings/accounts/AccountSettings.java
src/com/android/settings/users/RestrictedProfileSettings.java
src/com/android/settings/users/UserDetailsSettings.java
src/com/android/settings/users/UserDialogs.java [new file with mode: 0644]
src/com/android/settings/users/UserSettings.java

index 2e1477a..6010e21 100644 (file)
     <string name="user_exit_guest_dialog_remove">Remove</string>
 
     <!-- Title of preference to enable calling[CHAR LIMIT=40] -->
-    <string name="user_enable_calling">Allow phone calls</string>
+    <string name="user_enable_calling">Turn on phone calls</string>
     <!-- Title of preference to enable calling and SMS [CHAR LIMIT=45] -->
-    <string name="user_enable_calling_sms">Allow phone calls and SMS</string>
+    <string name="user_enable_calling_sms">Turn on phone calls &amp; SMS</string>
     <!-- Title of preference to remove the user [CHAR LIMIT=35] -->
     <string name="user_remove_user">Remove user</string>
     <!-- Title for confirmation of turning on calls [CHAR LIMIT=40] -->
-    <string name="user_enable_calling_confirm_title">Allow phone calls?</string>
+    <string name="user_enable_calling_confirm_title">Turn on phone calls?</string>
     <!-- Message for confirmation of turning on calls [CHAR LIMIT=none] -->
     <string name="user_enable_calling_confirm_message">Call history will be shared with this user.</string>
     <!-- Title for confirmation of turning on calls and SMS [CHAR LIMIT=45] -->
-    <string name="user_enable_calling_sms_confirm_title">Allow phone calls and SMS?</string>
+    <string name="user_enable_calling_and_sms_confirm_title">Turn on phone calls &amp; SMS?</string>
     <!-- Message for confirmation of turning on calls and SMS [CHAR LIMIT=none] -->
-    <string name="user_enable_calling_sms_confirm_message">Call and SMS history will be shared with this user.</string>
+    <string name="user_enable_calling_and_sms_confirm_message">Call and SMS history will be shared with this user.</string>
 
     <!-- Application Restrictions screen title [CHAR LIMIT=45] -->
     <string name="application_restrictions">Allow apps and content</string>
index 6517ffe..a3dfddb 100644 (file)
@@ -846,43 +846,6 @@ public final class Utils {
                || um.getUserProfiles().contains(otherUser);
    }
 
-    /**
-     * Creates a dialog to confirm with the user if it's ok to remove the user
-     * and delete all the data.
-     *
-     * @param context a Context object
-     * @param removingUserId The userId of the user to remove
-     * @param onConfirmListener Callback object for positive action
-     * @return the created Dialog
-     */
-    public static Dialog createRemoveConfirmationDialog(Context context, int removingUserId,
-            DialogInterface.OnClickListener onConfirmListener) {
-        UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);
-        UserInfo userInfo = um.getUserInfo(removingUserId);
-        int titleResId;
-        int messageResId;
-        if (UserHandle.myUserId() == removingUserId) {
-            titleResId = R.string.user_confirm_remove_self_title;
-            messageResId = R.string.user_confirm_remove_self_message;
-        } else if (userInfo.isRestricted()) {
-            titleResId = R.string.user_profile_confirm_remove_title;
-            messageResId = R.string.user_profile_confirm_remove_message;
-        } else if (userInfo.isManagedProfile()) {
-            titleResId = R.string.work_profile_confirm_remove_title;
-            messageResId = R.string.work_profile_confirm_remove_message;
-        } else {
-            titleResId = R.string.user_confirm_remove_title;
-            messageResId = R.string.user_confirm_remove_message;
-        }
-        Dialog dlg = new AlertDialog.Builder(context)
-                .setTitle(titleResId)
-                .setMessage(messageResId)
-                .setPositiveButton(R.string.user_delete_button,
-                        onConfirmListener)
-                .setNegativeButton(android.R.string.cancel, null)
-                .create();
-        return dlg;
-    }
 
     /**
      * Returns whether or not this device is able to be OEM unlocked.
index ffcb3b8..017eb86 100644 (file)
@@ -49,6 +49,7 @@ import android.preference.PreferenceScreen;
 import com.android.settings.R;
 import com.android.settings.SettingsPreferenceFragment;
 import com.android.settings.Utils;
+import com.android.settings.users.UserDialogs;
 
 import java.util.ArrayList;
 import java.util.Collections;
@@ -203,7 +204,7 @@ public class AccountSettings extends SettingsPreferenceFragment
             }
             if (preference == profileData.removeWorkProfilePreference) {
                 final int userId = profileData.userInfo.id;
-                Utils.createRemoveConfirmationDialog(getActivity(), userId,
+                UserDialogs.createRemoveDialog(getActivity(), userId,
                         new DialogInterface.OnClickListener() {
                             @Override
                             public void onClick(DialogInterface dialog, int which) {
index c0e8cb7..82090d4 100644 (file)
@@ -22,7 +22,6 @@ import android.content.Intent;
 import android.content.pm.UserInfo;
 import android.graphics.drawable.Drawable;
 import android.os.Bundle;
-import android.os.UserHandle;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.widget.ImageView;
@@ -31,8 +30,6 @@ import android.widget.TextView;
 import com.android.settings.R;
 import com.android.settings.Utils;
 
-import java.util.List;
-
 public class RestrictedProfileSettings extends AppRestrictionsFragment
         implements EditUserInfoController.OnContentChangedCallback {
 
@@ -129,7 +126,7 @@ public class RestrictedProfileSettings extends AppRestrictionsFragment
                     this, mUser);
         } else if (dialogId == DIALOG_CONFIRM_REMOVE) {
             Dialog dlg =
-                    Utils.createRemoveConfirmationDialog(getActivity(), mUser.getIdentifier(),
+                    UserDialogs.createRemoveDialog(getActivity(), mUser.getIdentifier(),
                             new DialogInterface.OnClickListener() {
                                 public void onClick(DialogInterface dialog, int which) {
                                     removeUser();
index 366b628..d738dd6 100644 (file)
@@ -28,7 +28,6 @@ import android.preference.SwitchPreference;
 
 import com.android.settings.R;
 import com.android.settings.SettingsPreferenceFragment;
-import com.android.settings.Utils;
 
 import java.util.List;
 
@@ -55,7 +54,7 @@ public class UserDetailsSettings extends SettingsPreferenceFragment
 
     private static final int DIALOG_CONFIRM_REMOVE = 1;
     private static final int DIALOG_CONFIRM_ENABLE_CALLING = 2;
-    private static final int DIALOG_CONFIRM_ENABLE_CALLING_SMS = 3;
+    private static final int DIALOG_CONFIRM_ENABLE_CALLING_AND_SMS = 3;
 
     private UserManager mUserManager;
     private SwitchPreference mPhonePref;
@@ -117,10 +116,18 @@ public class UserDetailsSettings extends SettingsPreferenceFragment
 
     @Override
     public boolean onPreferenceChange(Preference preference, Object newValue) {
+        if (Boolean.TRUE.equals(newValue)) {
+            showDialog(mGuestUser? DIALOG_CONFIRM_ENABLE_CALLING : DIALOG_CONFIRM_ENABLE_CALLING_AND_SMS);
+            return false;
+        }
+        enableCallsAndSms(false);
+        return true;
+    }
+
+    void enableCallsAndSms(boolean enabled) {
+        mPhonePref.setChecked(enabled);
         if (mGuestUser) {
-            // TODO: Show confirmation dialog: b/15761405
-            mDefaultGuestRestrictions.putBoolean(UserManager.DISALLOW_OUTGOING_CALLS,
-                    !((Boolean) newValue));
+            mDefaultGuestRestrictions.putBoolean(UserManager.DISALLOW_OUTGOING_CALLS, !enabled);
             // SMS is always disabled for guest
             mDefaultGuestRestrictions.putBoolean(UserManager.DISALLOW_SMS, true);
             mUserManager.setDefaultGuestRestrictions(mDefaultGuestRestrictions);
@@ -135,14 +142,11 @@ public class UserDetailsSettings extends SettingsPreferenceFragment
                 }
             }
         } else {
-            // TODO: Show confirmation dialog: b/15761405
             UserHandle userHandle = new UserHandle(mUserInfo.id);
-            mUserManager.setUserRestriction(UserManager.DISALLOW_OUTGOING_CALLS,
-                    !((Boolean) newValue), userHandle);
-            mUserManager.setUserRestriction(UserManager.DISALLOW_SMS,
-                    !((Boolean) newValue), userHandle);
+            mUserManager.setUserRestriction(UserManager.DISALLOW_OUTGOING_CALLS, !enabled,
+                    userHandle);
+            mUserManager.setUserRestriction(UserManager.DISALLOW_SMS, !enabled, userHandle);
         }
-        return true;
     }
 
     @Override
@@ -150,20 +154,29 @@ public class UserDetailsSettings extends SettingsPreferenceFragment
         Context context = getActivity();
         if (context == null) return null;
         switch (dialogId) {
-            case DIALOG_CONFIRM_REMOVE: {
-                Dialog dlg = Utils.createRemoveConfirmationDialog(getActivity(), mUserInfo.id,
+            case DIALOG_CONFIRM_REMOVE:
+                return UserDialogs.createRemoveDialog(getActivity(), mUserInfo.id,
                         new DialogInterface.OnClickListener() {
                             public void onClick(DialogInterface dialog, int which) {
                                 removeUser();
                             }
                         });
-                return dlg;
-            }
             case DIALOG_CONFIRM_ENABLE_CALLING:
-            case DIALOG_CONFIRM_ENABLE_CALLING_SMS:
-                // TODO: b/15761405
+                return UserDialogs.createEnablePhoneCallsDialog(getActivity(),
+                        new DialogInterface.OnClickListener() {
+                            public void onClick(DialogInterface dialog, int which) {
+                                enableCallsAndSms(true);
+                            }
+                        });
+            case DIALOG_CONFIRM_ENABLE_CALLING_AND_SMS:
+                return UserDialogs.createEnablePhoneCallsAndSmsDialog(getActivity(),
+                        new DialogInterface.OnClickListener() {
+                            public void onClick(DialogInterface dialog, int which) {
+                                enableCallsAndSms(true);
+                            }
+                        });
         }
-        return null;
+        throw new IllegalArgumentException("Unsupported dialogId " + dialogId);
     }
 
     void removeUser() {
diff --git a/src/com/android/settings/users/UserDialogs.java b/src/com/android/settings/users/UserDialogs.java
new file mode 100644 (file)
index 0000000..2d92464
--- /dev/null
@@ -0,0 +1,99 @@
+/*
+ * Copyright (C) 2014 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.settings.users;
+
+import android.app.AlertDialog;
+import android.app.Dialog;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.content.pm.UserInfo;
+import android.os.UserHandle;
+import android.os.UserManager;
+
+import com.android.settings.R;
+
+/**
+ * Helper class for displaying dialogs related to user settings.
+ */
+public final class UserDialogs {
+
+    /**
+     * Creates a dialog to confirm with the user if it's ok to remove the user
+     * and delete all the data.
+     *
+     * @param context a Context object
+     * @param removingUserId The userId of the user to remove
+     * @param onConfirmListener Callback object for positive action
+     * @return the created Dialog
+     */
+    public static Dialog createRemoveDialog(Context context, int removingUserId,
+            DialogInterface.OnClickListener onConfirmListener) {
+        UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);
+        UserInfo userInfo = um.getUserInfo(removingUserId);
+        int titleResId;
+        int messageResId;
+        if (UserHandle.myUserId() == removingUserId) {
+            titleResId = R.string.user_confirm_remove_self_title;
+            messageResId = R.string.user_confirm_remove_self_message;
+        } else if (userInfo.isRestricted()) {
+            titleResId = R.string.user_profile_confirm_remove_title;
+            messageResId = R.string.user_profile_confirm_remove_message;
+        } else if (userInfo.isManagedProfile()) {
+            titleResId = R.string.work_profile_confirm_remove_title;
+            messageResId = R.string.work_profile_confirm_remove_message;
+        } else {
+            titleResId = R.string.user_confirm_remove_title;
+            messageResId = R.string.user_confirm_remove_message;
+        }
+        return new AlertDialog.Builder(context)
+                .setTitle(titleResId)
+                .setMessage(messageResId)
+                .setPositiveButton(R.string.user_delete_button, onConfirmListener)
+                .setNegativeButton(android.R.string.cancel, null)
+                .create();
+    }
+
+    /**
+     * Creates a dialog to confirm that the user is ok to enable phone calls and SMS.
+     *
+     * @param onConfirmListener Callback object for positive action
+     */
+    public static Dialog createEnablePhoneCallsAndSmsDialog(Context context,
+            DialogInterface.OnClickListener onConfirmListener) {
+        return new AlertDialog.Builder(context)
+                .setTitle(R.string.user_enable_calling_and_sms_confirm_title)
+                .setMessage(R.string.user_enable_calling_and_sms_confirm_message)
+                .setPositiveButton(R.string.okay, onConfirmListener)
+                .setNegativeButton(android.R.string.cancel, null)
+                .create();
+    }
+
+    /**
+     * Creates a dialog to confirm that the user is ok to enable phone calls (no SMS).
+     *
+     * @param onConfirmListener Callback object for positive action
+     */
+    public static Dialog createEnablePhoneCallsDialog(Context context,
+            DialogInterface.OnClickListener onConfirmListener) {
+        return new AlertDialog.Builder(context)
+                .setTitle(R.string.user_enable_calling_confirm_title)
+                .setMessage(R.string.user_enable_calling_confirm_message)
+                .setPositiveButton(R.string.okay, onConfirmListener)
+                .setNegativeButton(android.R.string.cancel, null)
+                .create();
+    }
+}
index 4ee5cf4..dbd0481 100644 (file)
@@ -502,7 +502,7 @@ public class UserSettings extends SettingsPreferenceFragment
         switch (dialogId) {
             case DIALOG_CONFIRM_REMOVE: {
                 Dialog dlg =
-                        Utils.createRemoveConfirmationDialog(getActivity(), mRemovingUserId,
+                        UserDialogs.createRemoveDialog(getActivity(), mRemovingUserId,
                                 new DialogInterface.OnClickListener() {
                                     public void onClick(DialogInterface dialog, int which) {
                                         removeUserNow();