Merge "Fix sms app changed broadcast" into qt-dev am: 0a98e4b693 am: e5c5ec7316
am: 6e7bb1e7cf
Change-Id: I400f58f126c2baea99a5bef7a48a17ea9eef0ea0
This commit is contained in:
@@ -49,6 +49,7 @@ import android.os.ResultReceiver;
|
||||
import android.os.ShellCallback;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManagerInternal;
|
||||
import android.provider.Telephony;
|
||||
import android.service.sms.FinancialSmsService;
|
||||
import android.telephony.IFinancialSmsCallback;
|
||||
import android.text.TextUtils;
|
||||
@@ -60,6 +61,7 @@ import android.util.SparseArray;
|
||||
import android.util.proto.ProtoOutputStream;
|
||||
|
||||
import com.android.internal.annotations.GuardedBy;
|
||||
import com.android.internal.telephony.SmsApplication;
|
||||
import com.android.internal.util.ArrayUtils;
|
||||
import com.android.internal.util.BitUtils;
|
||||
import com.android.internal.util.CollectionUtils;
|
||||
@@ -377,13 +379,16 @@ public class RoleManagerService extends SystemService implements RoleUserState.C
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRoleHoldersChanged(@NonNull String roleName, @UserIdInt int userId) {
|
||||
public void onRoleHoldersChanged(@NonNull String roleName, @UserIdInt int userId,
|
||||
@Nullable String removedHolder, @Nullable String addedHolder) {
|
||||
mListenerHandler.sendMessage(PooledLambda.obtainMessage(
|
||||
RoleManagerService::notifyRoleHoldersChanged, this, roleName, userId));
|
||||
RoleManagerService::notifyRoleHoldersChanged, this, roleName, userId,
|
||||
removedHolder, addedHolder));
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
private void notifyRoleHoldersChanged(@NonNull String roleName, @UserIdInt int userId) {
|
||||
private void notifyRoleHoldersChanged(@NonNull String roleName, @UserIdInt int userId,
|
||||
@Nullable String removedHolder, @Nullable String addedHolder) {
|
||||
RemoteCallbackList<IOnRoleHoldersChangedListener> listeners = getListeners(userId);
|
||||
if (listeners != null) {
|
||||
notifyRoleHoldersChangedForListeners(listeners, roleName, userId);
|
||||
@@ -394,6 +399,12 @@ public class RoleManagerService extends SystemService implements RoleUserState.C
|
||||
if (allUsersListeners != null) {
|
||||
notifyRoleHoldersChangedForListeners(allUsersListeners, roleName, userId);
|
||||
}
|
||||
|
||||
// Legacy: sms app changed broadcasts
|
||||
if (RoleManager.ROLE_SMS.equals(roleName)) {
|
||||
SmsApplication.broadcastSmsAppChange(getContext(), UserHandle.of(userId),
|
||||
removedHolder, addedHolder);
|
||||
}
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
|
||||
@@ -294,7 +294,7 @@ public class RoleUserState {
|
||||
}
|
||||
|
||||
if (changed) {
|
||||
mCallback.onRoleHoldersChanged(roleName, mUserId);
|
||||
mCallback.onRoleHoldersChanged(roleName, mUserId, null, packageName);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -328,7 +328,7 @@ public class RoleUserState {
|
||||
}
|
||||
|
||||
if (changed) {
|
||||
mCallback.onRoleHoldersChanged(roleName, mUserId);
|
||||
mCallback.onRoleHoldersChanged(roleName, mUserId, packageName, null);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -632,6 +632,7 @@ public class RoleUserState {
|
||||
* @param roleName the name of the role whose holders are changed
|
||||
* @param userId the user id for this role holder change
|
||||
*/
|
||||
void onRoleHoldersChanged(@NonNull String roleName, @UserIdInt int userId);
|
||||
void onRoleHoldersChanged(@NonNull String roleName, @UserIdInt int userId,
|
||||
@Nullable String removedHolder, @Nullable String addedHolder);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package com.android.internal.telephony;
|
||||
|
||||
import android.Manifest.permission;
|
||||
import android.annotation.Nullable;
|
||||
import android.app.AppOpsManager;
|
||||
import android.app.role.RoleManager;
|
||||
import android.content.ComponentName;
|
||||
@@ -662,49 +663,69 @@ public final class SmsApplication {
|
||||
}
|
||||
|
||||
defaultSmsAppChanged(context);
|
||||
}
|
||||
}
|
||||
|
||||
if (DEBUG_MULTIUSER) {
|
||||
Log.i(LOG_TAG, "setDefaultApplicationInternal oldAppData=" + oldAppData);
|
||||
}
|
||||
if (oldAppData != null && oldAppData.mSmsAppChangedReceiverClass != null) {
|
||||
// Notify the old sms app that it's no longer the default
|
||||
final Intent oldAppIntent =
|
||||
new Intent(Telephony.Sms.Intents.ACTION_DEFAULT_SMS_PACKAGE_CHANGED);
|
||||
final ComponentName component = new ComponentName(oldAppData.mPackageName,
|
||||
oldAppData.mSmsAppChangedReceiverClass);
|
||||
oldAppIntent.setComponent(component);
|
||||
oldAppIntent.putExtra(Telephony.Sms.Intents.EXTRA_IS_DEFAULT_SMS_APP, false);
|
||||
if (DEBUG_MULTIUSER) {
|
||||
Log.i(LOG_TAG, "setDefaultApplicationInternal old=" + oldAppData.mPackageName);
|
||||
}
|
||||
context.sendBroadcastAsUser(oldAppIntent, userHandle);
|
||||
}
|
||||
// Notify the new sms app that it's now the default (if the new sms app has a receiver
|
||||
// to handle the changed default sms intent).
|
||||
if (DEBUG_MULTIUSER) {
|
||||
Log.i(LOG_TAG, "setDefaultApplicationInternal new applicationData=" +
|
||||
applicationData);
|
||||
}
|
||||
if (applicationData.mSmsAppChangedReceiverClass != null) {
|
||||
final Intent intent =
|
||||
new Intent(Telephony.Sms.Intents.ACTION_DEFAULT_SMS_PACKAGE_CHANGED);
|
||||
final ComponentName component = new ComponentName(applicationData.mPackageName,
|
||||
applicationData.mSmsAppChangedReceiverClass);
|
||||
intent.setComponent(component);
|
||||
intent.putExtra(Telephony.Sms.Intents.EXTRA_IS_DEFAULT_SMS_APP, true);
|
||||
if (DEBUG_MULTIUSER) {
|
||||
Log.i(LOG_TAG, "setDefaultApplicationInternal new=" + packageName);
|
||||
}
|
||||
context.sendBroadcastAsUser(intent, userHandle);
|
||||
}
|
||||
/**
|
||||
* Sends broadcasts on sms app change:
|
||||
* {@link Intent#ACTION_DEFAULT_SMS_PACKAGE_CHANGED}
|
||||
* {@link Intents.ACTION_DEFAULT_SMS_PACKAGE_CHANGED_INTERNAL}
|
||||
*/
|
||||
public static void broadcastSmsAppChange(Context context,
|
||||
UserHandle userHandle, @Nullable String oldPackage, @Nullable String newPackage) {
|
||||
Collection<SmsApplicationData> apps = getApplicationCollection(context);
|
||||
|
||||
// Send an implicit broadcast for the system server.
|
||||
// (or anyone with MONITOR_DEFAULT_SMS_PACKAGE, really.)
|
||||
broadcastSmsAppChange(context, userHandle,
|
||||
getApplicationForPackage(apps, oldPackage),
|
||||
getApplicationForPackage(apps, newPackage));
|
||||
}
|
||||
|
||||
private static void broadcastSmsAppChange(Context context, UserHandle userHandle,
|
||||
@Nullable SmsApplicationData oldAppData,
|
||||
@Nullable SmsApplicationData applicationData) {
|
||||
if (DEBUG_MULTIUSER) {
|
||||
Log.i(LOG_TAG, "setDefaultApplicationInternal oldAppData=" + oldAppData);
|
||||
}
|
||||
if (oldAppData != null && oldAppData.mSmsAppChangedReceiverClass != null) {
|
||||
// Notify the old sms app that it's no longer the default
|
||||
final Intent oldAppIntent =
|
||||
new Intent(Intents.ACTION_DEFAULT_SMS_PACKAGE_CHANGED);
|
||||
final ComponentName component = new ComponentName(oldAppData.mPackageName,
|
||||
oldAppData.mSmsAppChangedReceiverClass);
|
||||
oldAppIntent.setComponent(component);
|
||||
oldAppIntent.putExtra(Intents.EXTRA_IS_DEFAULT_SMS_APP, false);
|
||||
if (DEBUG_MULTIUSER) {
|
||||
Log.i(LOG_TAG, "setDefaultApplicationInternal old=" + oldAppData.mPackageName);
|
||||
}
|
||||
context.sendBroadcastAsUser(oldAppIntent, userHandle);
|
||||
}
|
||||
// Notify the new sms app that it's now the default (if the new sms app has a receiver
|
||||
// to handle the changed default sms intent).
|
||||
if (DEBUG_MULTIUSER) {
|
||||
Log.i(LOG_TAG, "setDefaultApplicationInternal new applicationData=" +
|
||||
applicationData);
|
||||
}
|
||||
if (applicationData != null && applicationData.mSmsAppChangedReceiverClass != null) {
|
||||
final Intent intent =
|
||||
new Intent(Telephony.Sms.Intents.ACTION_DEFAULT_SMS_PACKAGE_CHANGED_INTERNAL);
|
||||
context.sendBroadcastAsUser(intent, userHandle,
|
||||
permission.MONITOR_DEFAULT_SMS_PACKAGE);
|
||||
new Intent(Intents.ACTION_DEFAULT_SMS_PACKAGE_CHANGED);
|
||||
final ComponentName component = new ComponentName(applicationData.mPackageName,
|
||||
applicationData.mSmsAppChangedReceiverClass);
|
||||
intent.setComponent(component);
|
||||
intent.putExtra(Intents.EXTRA_IS_DEFAULT_SMS_APP, true);
|
||||
if (DEBUG_MULTIUSER) {
|
||||
Log.i(LOG_TAG, "setDefaultApplicationInternal new=" + applicationData.mPackageName);
|
||||
}
|
||||
context.sendBroadcastAsUser(intent, userHandle);
|
||||
}
|
||||
|
||||
// Send an implicit broadcast for the system server.
|
||||
// (or anyone with MONITOR_DEFAULT_SMS_PACKAGE, really.)
|
||||
final Intent intent =
|
||||
new Intent(Intents.ACTION_DEFAULT_SMS_PACKAGE_CHANGED_INTERNAL);
|
||||
context.sendBroadcastAsUser(intent, userHandle,
|
||||
permission.MONITOR_DEFAULT_SMS_PACKAGE);
|
||||
|
||||
if (applicationData != null) {
|
||||
MetricsLogger.action(context, MetricsEvent.ACTION_DEFAULT_SMS_APP_CHANGED,
|
||||
applicationData.mPackageName);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user