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:
committed by
Michael Bestas
parent
d8a0bf022d
commit
96ef363da8
@@ -18,6 +18,7 @@ package com.android.messaging.ui;
|
||||
import android.app.Activity;
|
||||
import android.app.Fragment;
|
||||
import android.app.PendingIntent;
|
||||
import android.app.role.RoleManager;
|
||||
import android.appwidget.AppWidgetManager;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.ClipData;
|
||||
@@ -497,9 +498,8 @@ public class UIIntentsImpl extends UIIntents {
|
||||
|
||||
@Override
|
||||
public Intent getChangeDefaultSmsAppIntent(final Activity activity) {
|
||||
final Intent intent = new Intent(Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT);
|
||||
intent.putExtra(Telephony.Sms.Intents.EXTRA_PACKAGE_NAME, activity.getPackageName());
|
||||
return intent;
|
||||
RoleManager roleManager = activity.getSystemService(RoleManager.class);
|
||||
return roleManager.createRequestRoleIntent(RoleManager.ROLE_SMS);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -66,7 +66,7 @@ public class ChangeDefaultSmsAppHelper {
|
||||
|
||||
// Is the default sms app?
|
||||
} else if (!isDefaultSmsApp) {
|
||||
mChangeSmsAppSettingRunnable = new ChangeSmsAppSettingRunnable(activity, fragment);
|
||||
mChangeSmsAppSettingRunnable = new ChangeSmsAppSettingRunnable(activity);
|
||||
promptToChangeDefaultSmsApp(sending, runAfterMadeDefault,
|
||||
composeView, rootView, activity);
|
||||
}
|
||||
@@ -104,22 +104,16 @@ public class ChangeDefaultSmsAppHelper {
|
||||
|
||||
private class ChangeSmsAppSettingRunnable implements Runnable {
|
||||
private final Activity mActivity;
|
||||
private final Fragment mFragment;
|
||||
|
||||
public ChangeSmsAppSettingRunnable(final Activity activity, final Fragment fragment) {
|
||||
public ChangeSmsAppSettingRunnable(final Activity activity) {
|
||||
mActivity = activity;
|
||||
mFragment = fragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
final Intent intent = UIIntents.get().getChangeDefaultSmsAppIntent(mActivity);
|
||||
if (mFragment != null) {
|
||||
mFragment.startActivityForResult(intent, REQUEST_SET_DEFAULT_SMS_APP);
|
||||
} else {
|
||||
mActivity.startActivityForResult(intent, REQUEST_SET_DEFAULT_SMS_APP);
|
||||
}
|
||||
mActivity.startActivityForResult(intent, REQUEST_SET_DEFAULT_SMS_APP);
|
||||
} catch (final ActivityNotFoundException ex) {
|
||||
// We shouldn't get here, but the monkey on JB MR0 can trigger it.
|
||||
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;
|
||||
|
||||
import android.app.role.RoleManager;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
@@ -897,8 +898,9 @@ public abstract class PhoneUtils {
|
||||
*/
|
||||
public boolean isDefaultSmsApp() {
|
||||
if (OsUtil.isAtLeastKLP()) {
|
||||
final String configuredApplication = Telephony.Sms.getDefaultSmsPackage(mContext);
|
||||
return mContext.getPackageName().equals(configuredApplication);
|
||||
RoleManager roleManager = mContext.getSystemService(RoleManager.class);
|
||||
return roleManager.isRoleAvailable(RoleManager.ROLE_SMS)
|
||||
&& roleManager.isRoleHeld(RoleManager.ROLE_SMS);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user