Messaging: Fix handling of default SMS app
Use RoleManager to Launch the correct activity and check the default app Get rid of deprecated methods used here to do the same Also add queries in manifest to allow the former method to work as well Change-Id: I4702aaa4b35a994e225e63534da8fb4975b9717a
This commit is contained in:
@@ -56,6 +56,13 @@
|
|||||||
<uses-feature android:name="android.hardware.microphone" android:required="false" />
|
<uses-feature android:name="android.hardware.microphone" android:required="false" />
|
||||||
<uses-feature android:name="android.hardware.screen.portrait" android:required="false" />
|
<uses-feature android:name="android.hardware.screen.portrait" android:required="false" />
|
||||||
|
|
||||||
|
<queries>
|
||||||
|
<intent>
|
||||||
|
<action android:name="android.intent.action.SENDTO"/>
|
||||||
|
<data android:scheme="smsto" android:host="*" />
|
||||||
|
</intent>
|
||||||
|
</queries>
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:name="com.android.messaging.BugleApplication"
|
android:name="com.android.messaging.BugleApplication"
|
||||||
android:allowBackup="false"
|
android:allowBackup="false"
|
||||||
@@ -390,6 +397,7 @@
|
|||||||
android:permission="android.permission.BROADCAST_SMS">
|
android:permission="android.permission.BROADCAST_SMS">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.provider.Telephony.SMS_DELIVER" />
|
<action android:name="android.provider.Telephony.SMS_DELIVER" />
|
||||||
|
<category android:name="android.intent.category.DEFAULT"/>
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</receiver>
|
</receiver>
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ package com.android.messaging.ui;
|
|||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.Fragment;
|
import android.app.Fragment;
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
|
import android.app.role.RoleManager;
|
||||||
import android.appwidget.AppWidgetManager;
|
import android.appwidget.AppWidgetManager;
|
||||||
import android.content.ActivityNotFoundException;
|
import android.content.ActivityNotFoundException;
|
||||||
import android.content.ClipData;
|
import android.content.ClipData;
|
||||||
@@ -497,9 +498,8 @@ public class UIIntentsImpl extends UIIntents {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Intent getChangeDefaultSmsAppIntent(final Activity activity) {
|
public Intent getChangeDefaultSmsAppIntent(final Activity activity) {
|
||||||
final Intent intent = new Intent(Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT);
|
RoleManager roleManager = activity.getSystemService(RoleManager.class);
|
||||||
intent.putExtra(Telephony.Sms.Intents.EXTRA_PACKAGE_NAME, activity.getPackageName());
|
return roleManager.createRequestRoleIntent(RoleManager.ROLE_SMS);
|
||||||
return intent;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ public class ChangeDefaultSmsAppHelper {
|
|||||||
|
|
||||||
// Is the default sms app?
|
// Is the default sms app?
|
||||||
} else if (!isDefaultSmsApp) {
|
} else if (!isDefaultSmsApp) {
|
||||||
mChangeSmsAppSettingRunnable = new ChangeSmsAppSettingRunnable(activity, fragment);
|
mChangeSmsAppSettingRunnable = new ChangeSmsAppSettingRunnable(activity);
|
||||||
promptToChangeDefaultSmsApp(sending, runAfterMadeDefault,
|
promptToChangeDefaultSmsApp(sending, runAfterMadeDefault,
|
||||||
composeView, rootView, activity);
|
composeView, rootView, activity);
|
||||||
}
|
}
|
||||||
@@ -104,22 +104,16 @@ public class ChangeDefaultSmsAppHelper {
|
|||||||
|
|
||||||
private class ChangeSmsAppSettingRunnable implements Runnable {
|
private class ChangeSmsAppSettingRunnable implements Runnable {
|
||||||
private final Activity mActivity;
|
private final Activity mActivity;
|
||||||
private final Fragment mFragment;
|
|
||||||
|
|
||||||
public ChangeSmsAppSettingRunnable(final Activity activity, final Fragment fragment) {
|
public ChangeSmsAppSettingRunnable(final Activity activity) {
|
||||||
mActivity = activity;
|
mActivity = activity;
|
||||||
mFragment = fragment;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
final Intent intent = UIIntents.get().getChangeDefaultSmsAppIntent(mActivity);
|
final Intent intent = UIIntents.get().getChangeDefaultSmsAppIntent(mActivity);
|
||||||
if (mFragment != null) {
|
mActivity.startActivityForResult(intent, REQUEST_SET_DEFAULT_SMS_APP);
|
||||||
mFragment.startActivityForResult(intent, REQUEST_SET_DEFAULT_SMS_APP);
|
|
||||||
} else {
|
|
||||||
mActivity.startActivityForResult(intent, REQUEST_SET_DEFAULT_SMS_APP);
|
|
||||||
}
|
|
||||||
} catch (final ActivityNotFoundException ex) {
|
} catch (final ActivityNotFoundException ex) {
|
||||||
// We shouldn't get here, but the monkey on JB MR0 can trigger it.
|
// We shouldn't get here, but the monkey on JB MR0 can trigger it.
|
||||||
LogUtil.w(LogUtil.BUGLE_TAG, "Couldn't find activity:", ex);
|
LogUtil.w(LogUtil.BUGLE_TAG, "Couldn't find activity:", ex);
|
||||||
@@ -153,5 +147,3 @@ public class ChangeDefaultSmsAppHelper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package com.android.messaging.util;
|
package com.android.messaging.util;
|
||||||
|
|
||||||
|
import android.app.role.RoleManager;
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
@@ -897,8 +898,9 @@ public abstract class PhoneUtils {
|
|||||||
*/
|
*/
|
||||||
public boolean isDefaultSmsApp() {
|
public boolean isDefaultSmsApp() {
|
||||||
if (OsUtil.isAtLeastKLP()) {
|
if (OsUtil.isAtLeastKLP()) {
|
||||||
final String configuredApplication = Telephony.Sms.getDefaultSmsPackage(mContext);
|
RoleManager roleManager = mContext.getSystemService(RoleManager.class);
|
||||||
return mContext.getPackageName().equals(configuredApplication);
|
return roleManager.isRoleAvailable(RoleManager.ROLE_SMS)
|
||||||
|
&& roleManager.isRoleHeld(RoleManager.ROLE_SMS);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user