Messaging: update default SMS setting
call MANAGE_DEFAULT_APP intent with correct parameters
Change-Id: Iabe7589b7e13af9434dde85edcbd83facb96ea7a
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 336a80b..a3ca7ba 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -29,6 +29,7 @@
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
<uses-permission android:name="android.permission.RECEIVE_MMS"/>
<uses-permission android:name="android.permission.SEND_SMS"/>
+ <uses-permission android:name="android.permission.MANAGE_ROLE_HOLDERS" />
<!-- Application needs access to MMS network -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
diff --git a/res/values/custom_strings.xml b/res/values/custom_strings.xml
index b3a5200..b4fd6ca 100644
--- a/res/values/custom_strings.xml
+++ b/res/values/custom_strings.xml
@@ -24,4 +24,7 @@
<string name="swipe_to_delete_conversation_pref_title">Swipe to delete</string>
<string name="swipe_to_delete_conversation_pref_summary">Swipe to the right to delete a conversation</string>
+ <string name="value_yes">Yes</string>
+ <string name="value_no">No</string>
+
</resources>
diff --git a/res/xml-v21/preferences_application.xml b/res/xml-v21/preferences_application.xml
index d650489..3d2c3b6 100644
--- a/res/xml-v21/preferences_application.xml
+++ b/res/xml-v21/preferences_application.xml
@@ -17,24 +17,10 @@
<!-- Preference screen definition for Bugle's application-wide settings -->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
- <!-- KLP+ only -->
- <PreferenceScreen
- android:key="@string/sms_disabled_pref_key"
- android:title="@string/sms_disabled_pref_title"
- android:persistent="false">
- <intent
- android:action="android.provider.Telephony.ACTION_CHANGE_DEFAULT">
- <extra android:name="package" android:value="com.android.messaging" />
- </intent>
- </PreferenceScreen>
- <PreferenceScreen
+ <Preference
android:key="@string/sms_enabled_pref_key"
android:title="@string/sms_enabled_pref_title"
- android:persistent="false">
- <intent
- android:action="android.settings.WIRELESS_SETTINGS">
- </intent>
- </PreferenceScreen>
+ android:persistent="false"/>
<SwitchPreference
android:key="@string/send_sound_pref_key"
diff --git a/res/xml-v23/preferences_application.xml b/res/xml-v23/preferences_application.xml
index 7370c4a..3d2c3b6 100644
--- a/res/xml-v23/preferences_application.xml
+++ b/res/xml-v23/preferences_application.xml
@@ -17,25 +17,10 @@
<!-- Preference screen definition for Bugle's application-wide settings -->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
- <!-- KLP+ only -->
- <PreferenceScreen
- android:key="@string/sms_disabled_pref_key"
- android:title="@string/sms_disabled_pref_title"
- android:persistent="false">
- <intent
- android:action="android.provider.Telephony.ACTION_CHANGE_DEFAULT">
- <extra android:name="package" android:value="com.android.messaging" />
- </intent>
- </PreferenceScreen>
- <!-- MNC+ only -->
- <PreferenceScreen
+ <Preference
android:key="@string/sms_enabled_pref_key"
android:title="@string/sms_enabled_pref_title"
- android:persistent="false">
- <intent
- android:action="android.provider.Telephony.ACTION_CHANGE_DEFAULT">
- </intent>
- </PreferenceScreen>
+ android:persistent="false"/>
<SwitchPreference
android:key="@string/send_sound_pref_key"
diff --git a/res/xml/preferences_application.xml b/res/xml/preferences_application.xml
index 7ca8dd7..f47469c 100644
--- a/res/xml/preferences_application.xml
+++ b/res/xml/preferences_application.xml
@@ -17,24 +17,10 @@
<!-- Preference screen definition for Bugle's application-wide settings -->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
- <!-- KLP+ only -->
- <PreferenceScreen
- android:key="@string/sms_disabled_pref_key"
- android:title="@string/sms_disabled_pref_title"
- android:persistent="false">
- <intent
- android:action="android.provider.Telephony.ACTION_CHANGE_DEFAULT">
- <extra android:name="package" android:value="com.android.messaging" />
- </intent>
- </PreferenceScreen>
- <PreferenceScreen
+ <Preference
android:key="@string/sms_enabled_pref_key"
android:title="@string/sms_enabled_pref_title"
- android:persistent="false">
- <intent
- android:action="android.settings.WIRELESS_SETTINGS">
- </intent>
- </PreferenceScreen>
+ android:persistent="false"/>
<CheckBoxPreference
android:key="@string/send_sound_pref_key"
diff --git a/src/com/android/messaging/ui/appsettings/ApplicationSettingsActivity.java b/src/com/android/messaging/ui/appsettings/ApplicationSettingsActivity.java
index 19979a9..ac8e0b6 100644
--- a/src/com/android/messaging/ui/appsettings/ApplicationSettingsActivity.java
+++ b/src/com/android/messaging/ui/appsettings/ApplicationSettingsActivity.java
@@ -17,6 +17,7 @@
package com.android.messaging.ui.appsettings;
import android.app.FragmentTransaction;
+import android.app.role.RoleManager;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
@@ -83,11 +84,8 @@
private String mNotificationsPreferenceKey;
private Preference mNotificationsPreference;
- private String mSmsDisabledPrefKey;
- private Preference mSmsDisabledPreference;
private String mSmsEnabledPrefKey;
private Preference mSmsEnabledPreference;
- private boolean mIsSmsPreferenceClicked;
private String mSwipeRightToDeleteConversationkey;
private SwitchPreference mSwipeRightToDeleteConversationPreference;
@@ -105,15 +103,12 @@
mNotificationsPreferenceKey =
getString(R.string.notifications_pref_key);
mNotificationsPreference = findPreference(mNotificationsPreferenceKey);
- mSmsDisabledPrefKey = getString(R.string.sms_disabled_pref_key);
- mSmsDisabledPreference = findPreference(mSmsDisabledPrefKey);
mSmsEnabledPrefKey = getString(R.string.sms_enabled_pref_key);
mSmsEnabledPreference = findPreference(mSmsEnabledPrefKey);
mSwipeRightToDeleteConversationkey = getString(
R.string.swipe_right_deletes_conversation_key);
mSwipeRightToDeleteConversationPreference =
(SwitchPreference) findPreference(mSwipeRightToDeleteConversationkey);
- mIsSmsPreferenceClicked = false;
if (!DebugUtils.isDebugEnabled()) {
final Preference debugCategory = findPreference(getString(
@@ -142,46 +137,25 @@
Intent intent = new Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS);
intent.putExtra(Settings.EXTRA_APP_PACKAGE, getContext().getPackageName());
startActivity(intent);
- }
- if (preference.getKey() == mSmsDisabledPrefKey ||
- preference.getKey() == mSmsEnabledPrefKey) {
- mIsSmsPreferenceClicked = true;
+ return true;
+ } if (preference.getKey() == mSmsEnabledPrefKey) {
+ Intent intent = new Intent("android.intent.action.MANAGE_DEFAULT_APP");
+ intent.putExtra("android.intent.extra.ROLE_NAME", RoleManager.ROLE_SMS);
+ startActivity(intent);
+ return true;
}
return super.onPreferenceTreeClick(preferenceScreen, preference);
}
private void updateSmsEnabledPreferences() {
if (!OsUtil.isAtLeastKLP()) {
- getPreferenceScreen().removePreference(mSmsDisabledPreference);
getPreferenceScreen().removePreference(mSmsEnabledPreference);
} else {
final String defaultSmsAppLabel = getString(R.string.default_sms_app,
PhoneUtils.getDefault().getDefaultSmsAppLabel());
- boolean isSmsEnabledBeforeState;
- boolean isSmsEnabledCurrentState;
- if (PhoneUtils.getDefault().isDefaultSmsApp()) {
- if (getPreferenceScreen().findPreference(mSmsEnabledPrefKey) == null) {
- getPreferenceScreen().addPreference(mSmsEnabledPreference);
- isSmsEnabledBeforeState = false;
- } else {
- isSmsEnabledBeforeState = true;
- }
- isSmsEnabledCurrentState = true;
- getPreferenceScreen().removePreference(mSmsDisabledPreference);
- mSmsEnabledPreference.setSummary(defaultSmsAppLabel);
- } else {
- if (getPreferenceScreen().findPreference(mSmsDisabledPrefKey) == null) {
- getPreferenceScreen().addPreference(mSmsDisabledPreference);
- isSmsEnabledBeforeState = true;
- } else {
- isSmsEnabledBeforeState = false;
- }
- isSmsEnabledCurrentState = false;
- getPreferenceScreen().removePreference(mSmsEnabledPreference);
- mSmsDisabledPreference.setSummary(defaultSmsAppLabel);
- }
+ boolean isSmsEnabledCurrentState = PhoneUtils.getDefault().isDefaultSmsApp();
+ mSmsEnabledPreference.setSummary(isSmsEnabledCurrentState ? getString(R.string.value_yes) : getString(R.string.value_no));
}
- mIsSmsPreferenceClicked = false;
}
@Override