Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0a98e4b6 authored by Eugene Susla's avatar Eugene Susla Committed by Android (Google) Code Review
Browse files

Merge "Fix sms app changed broadcast" into qt-dev

parents 660c234e 0fa8049f
Loading
Loading
Loading
Loading
+14 −3
Original line number Diff line number Diff line
@@ -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
+4 −3
Original line number Diff line number Diff line
@@ -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);
    }
}
+57 −36
Original line number Diff line number Diff line
@@ -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,18 +663,37 @@ public final class SmsApplication {
            }

            defaultSmsAppChanged(context);
        }
    }

    /**
     * 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);

        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(Telephony.Sms.Intents.ACTION_DEFAULT_SMS_PACKAGE_CHANGED);
                    new Intent(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);
            oldAppIntent.putExtra(Intents.EXTRA_IS_DEFAULT_SMS_APP, false);
            if (DEBUG_MULTIUSER) {
                Log.i(LOG_TAG, "setDefaultApplicationInternal old=" + oldAppData.mPackageName);
            }
@@ -685,15 +705,15 @@ public final class SmsApplication {
            Log.i(LOG_TAG, "setDefaultApplicationInternal new applicationData=" +
                    applicationData);
        }
            if (applicationData.mSmsAppChangedReceiverClass != null) {
        if (applicationData != null && applicationData.mSmsAppChangedReceiverClass != null) {
            final Intent intent =
                        new Intent(Telephony.Sms.Intents.ACTION_DEFAULT_SMS_PACKAGE_CHANGED);
                    new Intent(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);
            intent.putExtra(Intents.EXTRA_IS_DEFAULT_SMS_APP, true);
            if (DEBUG_MULTIUSER) {
                    Log.i(LOG_TAG, "setDefaultApplicationInternal new=" + packageName);
                Log.i(LOG_TAG, "setDefaultApplicationInternal new=" + applicationData.mPackageName);
            }
            context.sendBroadcastAsUser(intent, userHandle);
        }
@@ -701,10 +721,11 @@ public final class SmsApplication {
        // Send an implicit broadcast for the system server.
        // (or anyone with MONITOR_DEFAULT_SMS_PACKAGE, really.)
        final Intent intent =
                    new Intent(Telephony.Sms.Intents.ACTION_DEFAULT_SMS_PACKAGE_CHANGED_INTERNAL);
                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);
        }