DO NOT MERGE. Port "respond via SMS message" feature to new Telecomm. (3/4)

Bug: 15275904
Bug: 15196474
Change-Id: I519386dd6ace0a2c4737e5c972b96cd4a87a7d0e
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 8af1758..c0d67e4 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -500,15 +500,6 @@
                 android:excludeFromRecents="true">
         </activity>
 
-        <activity android:name="RespondViaSmsManager$Settings"
-                android:label="@string/respond_via_sms_setting_title"
-                android:configChanges="orientation|screenSize|keyboardHidden"
-                android:theme="@style/SettingsLight">
-            <intent-filter>
-                <action android:name="android.intent.action.MAIN" />
-            </intent-filter>
-        </activity>
-
         <activity android:name="ErrorDialogActivity"
                 android:configChanges="orientation|screenSize|keyboardHidden"
                 android:excludeFromRecents="true"
diff --git a/res/menu/respond_via_message_settings_menu.xml b/res/menu/respond_via_message_settings_menu.xml
deleted file mode 100644
index 6f5e246..0000000
--- a/res/menu/respond_via_message_settings_menu.xml
+++ /dev/null
@@ -1,21 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2012 Google Inc.
-
-     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.
--->
-
-<!-- Menu for Respond-via-Message settings screen. -->
-<menu xmlns:android="http://schemas.android.com/apk/res/android">
-    <item android:id="@+id/respond_via_message_reset"
-          android:title="@string/respond_via_sms_menu_reset_default_activity" />
-</menu>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 7e51e97..188b284 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -1327,31 +1327,10 @@
          on this device. [CHAR LIMIT=40] -->
     <string name="not_voice_capable">Voice calling not supported</string>
 
-    <!-- Canned response for the "Respond via SMS" feature for incoming calls. [CHAR LIMIT=35] -->
-    <string name="respond_via_sms_canned_response_1">Can\'t talk now. What\'s up?</string>
-    <!-- Canned response for the "Respond via SMS" feature for incoming calls. [CHAR LIMIT=35] -->
-    <string name="respond_via_sms_canned_response_2">I\'ll call you right back.</string>
-    <!-- Canned response for the "Respond via SMS" feature for incoming calls. [CHAR LIMIT=35] -->
-    <string name="respond_via_sms_canned_response_3">I\'ll call you later.</string>
-    <!-- Canned response for the "Respond via SMS" feature for incoming calls. [CHAR LIMIT=35] -->
-    <string name="respond_via_sms_canned_response_4">Can\'t talk now. Call me later?</string>
-
     <!-- Title of settings screen for managing the "Respond via SMS" feature. [CHAR LIMIT=30] -->
     <string name="respond_via_sms_setting_title">Quick responses</string>
-    <!-- Slightly more verbose title of settings screen for managing the
-         "Respond via SMS" feature. [CHAR LIMIT=30] -->
-    <string name="respond_via_sms_setting_title_2">Edit quick responses</string>
     <!-- Settings summary string for the "Respond via SMS" feature. [CHAR LIMIT=40] -->
     <string name="respond_via_sms_setting_summary"></string>
-    <!-- Dialog title when changing a string for the "Respond via SMS" feature. [CHAR LIMIT=30] -->
-    <string name="respond_via_sms_edittext_dialog_title">Quick response</string>
-    <!-- Menu option in  "Respond via SMS" that allows user to reset the default
-         activity used to handle "Respond via SMS" [CHAR LIMIT=30] -->
-    <string name="respond_via_sms_menu_reset_default_activity">Reset default app</string>
-
-    <!-- "Respond via SMS": Confirmation message shown after sending
-         a text response. [CHAR LIMIT=40] -->
-    <string name="respond_via_sms_confirmation_format">Message sent to <xliff:g id="phone_number">%s</xliff:g>.</string>
 
     <!-- String describing the image on ImageButton one
 
diff --git a/res/xml/call_feature_setting.xml b/res/xml/call_feature_setting.xml
index 0ac8769..f8dd2f1 100644
--- a/res/xml/call_feature_setting.xml
+++ b/res/xml/call_feature_setting.xml
@@ -107,8 +107,8 @@
       android:persistent="false">
       <intent
           android:action="android.intent.action.MAIN"
-          android:targetPackage="com.android.phone"
-          android:targetClass="com.android.phone.RespondViaSmsManager$Settings" />
+          android:targetPackage="com.android.telecomm"
+          android:targetClass="com.android.telecomm.RespondViaSmsSettings$Settings" />
   </PreferenceScreen>
 
   <PreferenceScreen
diff --git a/res/xml/respond_via_sms_settings.xml b/res/xml/respond_via_sms_settings.xml
deleted file mode 100644
index 739673c..0000000
--- a/res/xml/respond_via_sms_settings.xml
+++ /dev/null
@@ -1,58 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2011 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.
--->
-
-<!-- Settings screen that lets the user manage the canned responses
-     for the "Respond via SMS" feature; see RespondViaSmsManager.java -->
-<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
-     android:title="@string/respond_via_sms_setting_title_2">
-
-    <!-- Ultra-simple implementation for now: just provide 4 fixed slots
-         with customizable strings. -->
-
-    <!-- TODO: Potential UI improvements:
-         (1) Allow editing the strings in place, rather than having to tap
-             each one and edit it via the popup dialog.
-         (2) Allow reordering the strings by drag-and-drop.
-         (3) Provide an "Add new string..." option? -->
-
-    <!-- The defaultValues here must agree with the values used with
-         prefs.getString() in RespondViaSmsManager.loadCannedResponses(). -->
-
-    <!-- Use MultiLineTitleEditTextPreference instead of the standard
-         EditTextPreference here, to allow the preference "title" to wrap
-         onto multiple lines if the customized messages are long enough. -->
-
-    <com.android.phone.MultiLineTitleEditTextPreference
-        android:key="canned_response_pref_1"
-        android:defaultValue="@string/respond_via_sms_canned_response_1"
-        android:dialogTitle="@string/respond_via_sms_edittext_dialog_title" />
-
-    <com.android.phone.MultiLineTitleEditTextPreference
-        android:key="canned_response_pref_2"
-        android:defaultValue="@string/respond_via_sms_canned_response_2"
-        android:dialogTitle="@string/respond_via_sms_edittext_dialog_title" />
-
-    <com.android.phone.MultiLineTitleEditTextPreference
-        android:key="canned_response_pref_3"
-        android:defaultValue="@string/respond_via_sms_canned_response_3"
-        android:dialogTitle="@string/respond_via_sms_edittext_dialog_title" />
-
-    <com.android.phone.MultiLineTitleEditTextPreference
-        android:key="canned_response_pref_4"
-        android:defaultValue="@string/respond_via_sms_canned_response_4"
-        android:dialogTitle="@string/respond_via_sms_edittext_dialog_title" />
-
-</PreferenceScreen>
diff --git a/src/com/android/phone/CallCommandService.java b/src/com/android/phone/CallCommandService.java
index 1668891..36981ee 100644
--- a/src/com/android/phone/CallCommandService.java
+++ b/src/com/android/phone/CallCommandService.java
@@ -90,7 +90,7 @@
             }
 
             if (rejectWithMessage && !phoneNumber.isEmpty()) {
-                RejectWithTextMessageManager.rejectCallWithMessage(phoneNumber, message);
+                // RejectWithTextMessageManager.rejectCallWithMessage(phoneNumber, message);
             }
         } catch (Exception e) {
             Log.e(TAG, "Error during rejectCall().", e);
diff --git a/src/com/android/phone/CallHandlerServiceProxy.java b/src/com/android/phone/CallHandlerServiceProxy.java
index f5b6116..28921b3 100644
--- a/src/com/android/phone/CallHandlerServiceProxy.java
+++ b/src/com/android/phone/CallHandlerServiceProxy.java
@@ -188,7 +188,7 @@
             synchronized (mServiceAndQueueLock) {
                 if (mCallHandlerServiceGuarded != null) {
                     mCallHandlerServiceGuarded.onIncoming(call,
-                            RejectWithTextMessageManager.loadCannedResponses());
+                            null /* RejectWithTextMessageManager.loadCannedResponses() */);
                 }
             }
         } catch (Exception e) {
diff --git a/src/com/android/phone/CallModeler.java b/src/com/android/phone/CallModeler.java
index 0b1cd0e..1aeba93 100644
--- a/src/com/android/phone/CallModeler.java
+++ b/src/com/android/phone/CallModeler.java
@@ -682,8 +682,8 @@
             canMute = callIsActive;
         }
 
-        canRespondViaText = RejectWithTextMessageManager.allowRespondViaSmsForCall(call,
-                connection);
+        canRespondViaText = false /* RejectWithTextMessageManager.allowRespondViaSmsForCall(call,
+                connection) */;
 
         // special rules section!
         // CDMA always has Add
diff --git a/src/com/android/phone/MultiLineTitleEditTextPreference.java b/src/com/android/phone/MultiLineTitleEditTextPreference.java
deleted file mode 100644
index 58d79f8..0000000
--- a/src/com/android/phone/MultiLineTitleEditTextPreference.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * Copyright (C) 2011 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.phone;
-
-import android.content.Context;
-import android.preference.EditTextPreference;
-import android.util.AttributeSet;
-import android.view.View;
-import android.widget.TextView;
-
-/**
- * Ultra-simple subclass of EditTextPreference that allows the "title" to wrap
- * onto multiple lines.
- *
- * (By default, the title of an EditTextPreference is singleLine="true"; see
- * preference_holo.xml under frameworks/base.  But in the "Respond via SMS"
- * settings UI we want titles to be multi-line, since the customized messages
- * might be fairly long, and should be able to wrap.)
- *
- * TODO: This is pretty cumbersome; it would be nicer for the framework to
- * either allow modifying the title's attributes in XML, or at least provide
- * some way from Java (given an EditTextPreference) to reach inside and get a
- * handle to the "title" TextView.
- *
- * TODO: Also, it would reduce clutter if this could be an inner class in
- * RespondViaSmsManager.java, but then there would be no way to reference the
- * class from XML.  That's because
- *    <com.android.phone.RespondViaSmsManager$MultiLineTitleEditTextPreference ... />
- * isn't valid XML syntax due to the "$" character.  And Preference
- * elements don't have a "class" attribute, so you can't do something like
- * <view class="com.android.phone.Foo$Bar"> as you can with regular views.
- */
-public class MultiLineTitleEditTextPreference extends EditTextPreference {
-    public MultiLineTitleEditTextPreference(Context context, AttributeSet attrs, int defStyle) {
-        super(context, attrs, defStyle);
-    }
-
-    public MultiLineTitleEditTextPreference(Context context, AttributeSet attrs) {
-        super(context, attrs);
-    }
-
-    public MultiLineTitleEditTextPreference(Context context) {
-        super(context);
-    }
-
-    // The "title" TextView inside an EditTextPreference defaults to
-    // singleLine="true" (see preference_holo.xml under frameworks/base.)
-    // We override onBindView() purely to look up that TextView and call
-    // setSingleLine(false) on it.
-    @Override
-    protected void onBindView(View view) {
-        super.onBindView(view);
-
-        TextView textView = (TextView) view.findViewById(com.android.internal.R.id.title);
-        if (textView != null) {
-            textView.setSingleLine(false);
-        }
-    }
-}
diff --git a/src/com/android/phone/RejectWithTextMessageManager.java b/src/com/android/phone/RejectWithTextMessageManager.java
deleted file mode 100644
index dd4fe17..0000000
--- a/src/com/android/phone/RejectWithTextMessageManager.java
+++ /dev/null
@@ -1,257 +0,0 @@
-/*
- * Copyright (C) 2011 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.phone;
-
-import android.content.ComponentName;
-import android.content.Context;
-import android.content.Intent;
-import android.content.SharedPreferences;
-import android.content.res.Resources;
-import android.net.Uri;
-import android.os.Handler;
-import android.os.Looper;
-import android.os.Message;
-import android.telephony.PhoneNumberUtils;
-import android.telephony.TelephonyManager;
-import android.text.TextUtils;
-import android.util.Log;
-import android.widget.Toast;
-
-import com.android.internal.telephony.Call;
-import com.android.internal.telephony.Connection;
-import com.android.internal.telephony.PhoneConstants;
-import com.android.internal.telephony.SmsApplication;
-
-import java.util.ArrayList;
-
-/**
- * Helper class to manage the "Respond via Message" feature for incoming calls.
- *
- * @see com.android.phone.InCallScreen.internalRespondViaSms()
- */
-public class RejectWithTextMessageManager {
-    private static final String TAG = RejectWithTextMessageManager.class.getSimpleName();
-    private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
-
-    /** SharedPreferences file name for our persistent settings. */
-    private static final String SHARED_PREFERENCES_NAME = "respond_via_sms_prefs";
-
-    // Preference keys for the 4 "canned responses"; see RespondViaSmsManager$Settings.
-    // Since (for now at least) the number of messages is fixed at 4, and since
-    // SharedPreferences can't deal with arrays anyway, just store the messages
-    // as 4 separate strings.
-    private static final int NUM_CANNED_RESPONSES = 4;
-    private static final String KEY_CANNED_RESPONSE_PREF_1 = "canned_response_pref_1";
-    private static final String KEY_CANNED_RESPONSE_PREF_2 = "canned_response_pref_2";
-    private static final String KEY_CANNED_RESPONSE_PREF_3 = "canned_response_pref_3";
-    private static final String KEY_CANNED_RESPONSE_PREF_4 = "canned_response_pref_4";
-
-    /**
-     * Read the (customizable) canned responses from SharedPreferences,
-     * or from defaults if the user has never actually brought up
-     * the Settings UI.
-     *
-     * This method does disk I/O (reading the SharedPreferences file)
-     * so don't call it from the main thread.
-     *
-     * @see com.android.phone.RejectWithTextMessageManager.Settings
-     */
-    public static ArrayList<String> loadCannedResponses() {
-        if (DBG) log("loadCannedResponses()...");
-
-        final SharedPreferences prefs = PhoneGlobals.getInstance().getSharedPreferences(
-                SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
-        final Resources res = PhoneGlobals.getInstance().getResources();
-
-        final ArrayList<String> responses = new ArrayList<String>(NUM_CANNED_RESPONSES);
-
-        // Note the default values here must agree with the corresponding
-        // android:defaultValue attributes in respond_via_sms_settings.xml.
-
-        responses.add(0, prefs.getString(KEY_CANNED_RESPONSE_PREF_1,
-                                       res.getString(R.string.respond_via_sms_canned_response_1)));
-        responses.add(1, prefs.getString(KEY_CANNED_RESPONSE_PREF_2,
-                                       res.getString(R.string.respond_via_sms_canned_response_2)));
-        responses.add(2, prefs.getString(KEY_CANNED_RESPONSE_PREF_3,
-                                       res.getString(R.string.respond_via_sms_canned_response_3)));
-        responses.add(3, prefs.getString(KEY_CANNED_RESPONSE_PREF_4,
-                                       res.getString(R.string.respond_via_sms_canned_response_4)));
-        return responses;
-    }
-
-    private static void showMessageSentToast(final String phoneNumber) {
-        // ...and show a brief confirmation to the user (since
-        // otherwise it's hard to be sure that anything actually
-        // happened.)
-        // Ugly hack to show a toaster from a service.
-        (new Thread(new Runnable() {
-            @Override
-            public void run() {
-                Looper.prepare();
-                Handler innerHandler = new Handler() {
-                    @Override
-                    public void handleMessage(Message message) {
-                        final Resources res = PhoneGlobals.getInstance().getResources();
-                        final String formatString = res.getString(
-                                R.string.respond_via_sms_confirmation_format);
-                        final String confirmationMsg = String.format(formatString, phoneNumber);
-                        Toast.makeText(PhoneGlobals.getInstance(), confirmationMsg,
-                                Toast.LENGTH_LONG).show();
-                    }
-
-                    @Override
-                    public void dispatchMessage(Message message) {
-                        handleMessage(message);
-                    }
-                };
-
-                Message message = innerHandler.obtainMessage();
-                innerHandler.dispatchMessage(message);
-                Looper.loop();
-            }
-        })).start();
-
-        // TODO: If the device is locked, this toast won't actually ever
-        // be visible!  (That's because we're about to dismiss the call
-        // screen, which means that the device will return to the
-        // keyguard.  But toasts aren't visible on top of the keyguard.)
-        // Possible fixes:
-        // (1) Is it possible to allow a specific Toast to be visible
-        //     on top of the keyguard?
-        // (2) Artificially delay the dismissCallScreen() call by 3
-        //     seconds to allow the toast to be seen?
-        // (3) Don't use a toast at all; instead use a transient state
-        //     of the InCallScreen (perhaps via the InCallUiState
-        //     progressIndication feature), and have that state be
-        //     visible for 3 seconds before calling dismissCallScreen().
-    }
-
-    /**
-     * Reject the call with the specified message. If message is null this call is ignored.
-     */
-    public static void rejectCallWithMessage(String phoneNumber, String message) {
-        if (message != null) {
-            final ComponentName component =
-                    SmsApplication.getDefaultRespondViaMessageApplication(
-                            PhoneGlobals.getInstance(), true /*updateIfNeeded*/);
-            if (component != null) {
-                // Build and send the intent
-                final Uri uri = Uri.fromParts(Constants.SCHEME_SMSTO, phoneNumber, null);
-                final Intent intent = new Intent(TelephonyManager.ACTION_RESPOND_VIA_MESSAGE, uri);
-                intent.putExtra(Intent.EXTRA_TEXT, message);
-                showMessageSentToast(phoneNumber);
-                intent.setComponent(component);
-                PhoneGlobals.getInstance().startService(intent);
-            }
-        }
-    }
-
-    /**
-     * @return true if the "Respond via SMS" feature should be enabled
-     * for the specified incoming call.
-     *
-     * The general rule is that we *do* allow "Respond via SMS" except for
-     * the few (relatively rare) cases where we know for sure it won't
-     * work, namely:
-     *   - a bogus or blank incoming number
-     *   - a call from a SIP address
-     *   - a "call presentation" that doesn't allow the number to be revealed
-     *
-     * In all other cases, we allow the user to respond via SMS.
-     *
-     * Note that this behavior isn't perfect; for example we have no way
-     * to detect whether the incoming call is from a landline (with most
-     * networks at least), so we still enable this feature even though
-     * SMSes to that number will silently fail.
-     */
-    public static boolean allowRespondViaSmsForCall(
-            com.android.services.telephony.common.Call call, Connection conn) {
-        if (DBG) log("allowRespondViaSmsForCall(" + call + ")...");
-
-        // First some basic sanity checks:
-        if (call == null) {
-            Log.w(TAG, "allowRespondViaSmsForCall: null ringingCall!");
-            return false;
-        }
-        if (!(call.getState() == com.android.services.telephony.common.Call.State.INCOMING) &&
-                !(call.getState() ==
-                        com.android.services.telephony.common.Call.State.CALL_WAITING)) {
-            // The call is in some state other than INCOMING or WAITING!
-            // (This should almost never happen, but it *could*
-            // conceivably happen if the ringing call got disconnected by
-            // the network just *after* we got it from the CallManager.)
-            Log.w(TAG, "allowRespondViaSmsForCall: ringingCall not ringing! state = "
-                    + call.getState());
-            return false;
-        }
-
-        if (conn == null) {
-            // The call doesn't have any connections! (Again, this can
-            // happen if the ringing call disconnects at the exact right
-            // moment, but should almost never happen in practice.)
-            Log.w(TAG, "allowRespondViaSmsForCall: null Connection!");
-            return false;
-        }
-
-        // Check the incoming number:
-        final String number = conn.getAddress();
-        if (DBG) log("- number: '" + number + "'");
-        if (TextUtils.isEmpty(number)) {
-            Log.w(TAG, "allowRespondViaSmsForCall: no incoming number!");
-            return false;
-        }
-        if (PhoneNumberUtils.isUriNumber(number)) {
-            // The incoming number is actually a URI (i.e. a SIP address),
-            // not a regular PSTN phone number, and we can't send SMSes to
-            // SIP addresses.
-            // (TODO: That might still be possible eventually, though. Is
-            // there some SIP-specific equivalent to sending a text message?)
-            Log.i(TAG, "allowRespondViaSmsForCall: incoming 'number' is a SIP address.");
-            return false;
-        }
-
-        // Finally, check the "call presentation":
-        int presentation = conn.getNumberPresentation();
-        if (DBG) log("- presentation: " + presentation);
-        if (presentation == PhoneConstants.PRESENTATION_RESTRICTED) {
-            // PRESENTATION_RESTRICTED means "caller-id blocked".
-            // The user isn't allowed to see the number in the first
-            // place, so obviously we can't let you send an SMS to it.
-            Log.i(TAG, "allowRespondViaSmsForCall: PRESENTATION_RESTRICTED.");
-            return false;
-        }
-
-        // Is there a valid SMS application on the phone?
-        if (SmsApplication.getDefaultRespondViaMessageApplication(PhoneGlobals.getInstance(),
-                true /*updateIfNeeded*/) == null) {
-            return false;
-        }
-
-        // TODO: with some carriers (in certain countries) you *can* actually
-        // tell whether a given number is a mobile phone or not. So in that
-        // case we could potentially return false here if the incoming call is
-        // from a land line.
-
-        // If none of the above special cases apply, it's OK to enable the
-        // "Respond via SMS" feature.
-        return true;
-    }
-
-    private static void log(String msg) {
-        Log.d(TAG, msg);
-    }
-}
diff --git a/src/com/android/phone/RespondViaSmsManager.java b/src/com/android/phone/RespondViaSmsManager.java
deleted file mode 100644
index a842f34..0000000
--- a/src/com/android/phone/RespondViaSmsManager.java
+++ /dev/null
@@ -1,198 +0,0 @@
-/*
- * Copyright (C) 2011 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.phone;
-
-import android.app.ActivityManager;
-import android.app.ActionBar;
-import android.app.AlertDialog;
-import android.app.Dialog;
-import android.content.ComponentName;
-import android.content.Context;
-import android.content.DialogInterface;
-import android.content.Intent;
-import android.content.SharedPreferences;
-import android.content.pm.ApplicationInfo;
-import android.content.pm.PackageInfo;
-import android.content.pm.PackageManager;
-import android.content.pm.PackageManager;
-import android.content.pm.ResolveInfo;
-import android.content.pm.ServiceInfo;
-import android.content.res.Resources;
-import android.graphics.drawable.Drawable;
-import android.net.Uri;
-import android.os.Bundle;
-import android.os.SystemProperties;
-import android.preference.EditTextPreference;
-import android.preference.Preference;
-import android.preference.PreferenceActivity;
-import android.telephony.PhoneNumberUtils;
-import android.telephony.TelephonyManager;
-import android.text.TextUtils;
-import android.util.Log;
-import android.view.LayoutInflater;
-import android.view.Menu;
-import android.view.MenuItem;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.AdapterView;
-import android.widget.ArrayAdapter;
-import android.widget.BaseAdapter;
-import android.widget.CheckBox;
-import android.widget.CompoundButton;
-import android.widget.ImageView;
-import android.widget.ListView;
-import android.widget.TextView;
-import android.widget.Toast;
-
-import com.android.internal.telephony.Call;
-import com.android.internal.telephony.Connection;
-import com.android.internal.telephony.PhoneConstants;
-
-import com.google.android.collect.Lists;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-/**
- * Helper class to manage the "Respond via Message" feature for incoming calls.
- *
- * @see InCallScreen.internalRespondViaSms()
- */
-public class RespondViaSmsManager {
-    private static final String TAG = "RespondViaSmsManager";
-    private static final boolean DBG =
-            (PhoneGlobals.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1);
-    // Do not check in with VDBG = true, since that may write PII to the system log.
-    private static final boolean VDBG = false;
-
-    /** SharedPreferences file name for our persistent settings. */
-    private static final String SHARED_PREFERENCES_NAME = "respond_via_sms_prefs";
-
-    // Preference keys for the 4 "canned responses"; see RespondViaSmsManager$Settings.
-    // Since (for now at least) the number of messages is fixed at 4, and since
-    // SharedPreferences can't deal with arrays anyway, just store the messages
-    // as 4 separate strings.
-    private static final int NUM_CANNED_RESPONSES = 4;
-    private static final String KEY_CANNED_RESPONSE_PREF_1 = "canned_response_pref_1";
-    private static final String KEY_CANNED_RESPONSE_PREF_2 = "canned_response_pref_2";
-    private static final String KEY_CANNED_RESPONSE_PREF_3 = "canned_response_pref_3";
-    private static final String KEY_CANNED_RESPONSE_PREF_4 = "canned_response_pref_4";
-    private static final String KEY_PREFERRED_PACKAGE = "preferred_package_pref";
-    private static final String KEY_INSTANT_TEXT_DEFAULT_COMPONENT = "instant_text_def_component";
-
-    /**
-     * Settings activity under "Call settings" to let you manage the
-     * canned responses; see respond_via_sms_settings.xml
-     */
-    public static class Settings extends PreferenceActivity
-            implements Preference.OnPreferenceChangeListener {
-        @Override
-        protected void onCreate(Bundle icicle) {
-            super.onCreate(icicle);
-            if (DBG) log("Settings: onCreate()...");
-
-            getPreferenceManager().setSharedPreferencesName(SHARED_PREFERENCES_NAME);
-
-            // This preference screen is ultra-simple; it's just 4 plain
-            // <EditTextPreference>s, one for each of the 4 "canned responses".
-            //
-            // The only nontrivial thing we do here is copy the text value of
-            // each of those EditTextPreferences and use it as the preference's
-            // "title" as well, so that the user will immediately see all 4
-            // strings when they arrive here.
-            //
-            // Also, listen for change events (since we'll need to update the
-            // title any time the user edits one of the strings.)
-
-            addPreferencesFromResource(R.xml.respond_via_sms_settings);
-
-            EditTextPreference pref;
-            pref = (EditTextPreference) findPreference(KEY_CANNED_RESPONSE_PREF_1);
-            pref.setTitle(pref.getText());
-            pref.setOnPreferenceChangeListener(this);
-
-            pref = (EditTextPreference) findPreference(KEY_CANNED_RESPONSE_PREF_2);
-            pref.setTitle(pref.getText());
-            pref.setOnPreferenceChangeListener(this);
-
-            pref = (EditTextPreference) findPreference(KEY_CANNED_RESPONSE_PREF_3);
-            pref.setTitle(pref.getText());
-            pref.setOnPreferenceChangeListener(this);
-
-            pref = (EditTextPreference) findPreference(KEY_CANNED_RESPONSE_PREF_4);
-            pref.setTitle(pref.getText());
-            pref.setOnPreferenceChangeListener(this);
-
-            ActionBar actionBar = getActionBar();
-            if (actionBar != null) {
-                // android.R.id.home will be triggered in onOptionsItemSelected()
-                actionBar.setDisplayHomeAsUpEnabled(true);
-            }
-        }
-
-        // Preference.OnPreferenceChangeListener implementation
-        @Override
-        public boolean onPreferenceChange(Preference preference, Object newValue) {
-            if (DBG) log("onPreferenceChange: key = " + preference.getKey());
-            if (VDBG) log("  preference = '" + preference + "'");
-            if (VDBG) log("  newValue = '" + newValue + "'");
-
-            EditTextPreference pref = (EditTextPreference) preference;
-
-            // Copy the new text over to the title, just like in onCreate().
-            // (Watch out: onPreferenceChange() is called *before* the
-            // Preference itself gets updated, so we need to use newValue here
-            // rather than pref.getText().)
-            pref.setTitle((String) newValue);
-
-            return true;  // means it's OK to update the state of the Preference with the new value
-        }
-
-        @Override
-        public boolean onOptionsItemSelected(MenuItem item) {
-            final int itemId = item.getItemId();
-            switch (itemId) {
-                case android.R.id.home:
-                    // See ActionBar#setDisplayHomeAsUpEnabled()
-                    CallFeaturesSetting.goUpToTopLevelSetting(this);
-                    return true;
-                case R.id.respond_via_message_reset:
-                    // Reset the preferences settings
-                    SharedPreferences prefs = getSharedPreferences(
-                            SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
-                    SharedPreferences.Editor editor = prefs.edit();
-                    editor.remove(KEY_INSTANT_TEXT_DEFAULT_COMPONENT);
-                    editor.apply();
-
-                    return true;
-                default:
-            }
-            return super.onOptionsItemSelected(item);
-        }
-
-        @Override
-        public boolean onCreateOptionsMenu(Menu menu) {
-            getMenuInflater().inflate(R.menu.respond_via_message_settings_menu, menu);
-            return super.onCreateOptionsMenu(menu);
-        }
-    }
-
-    private static void log(String msg) {
-        Log.e(TAG, msg);
-    }
-}