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

Commit d0fd1c5e authored by Rambo Wang's avatar Rambo Wang
Browse files

Support MockModem for secondary users

The CL fixes the MockModem connection failure in HSUM by switching from
bindService to bindServiceAsUser API call.

bindService works only for system user. For secondary users, calling
bindService to bind MockModem service will make the service invisible
for secondary users (including main user) and fail the connection.

The issue is fixed by calling bindServiceAsUser and passing current
user to make sure the MockModem service is launched and bound for the current user.

Bug: 353531688
Test: MockModem CTS tests with both HSUM on and off
Flag: com.android.internal.telephony.flags.support_phone_uid_check_for_multiuser
Change-Id: I3ffdb90b8a9692929c7abc1a21916ea1c4cd0800
parent 777165b5
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -24,12 +24,15 @@ import static android.telephony.TelephonyManager.HAL_SERVICE_NETWORK;
import static android.telephony.TelephonyManager.HAL_SERVICE_SIM;
import static android.telephony.TelephonyManager.HAL_SERVICE_VOICE;

import android.app.ActivityManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.IBinder;
import android.os.UserHandle;

import com.android.internal.telephony.flags.Flags;
import com.android.telephony.Rlog;

/** This class provides wrapper APIs for binding interfaces to mock service. */
@@ -158,7 +161,12 @@ public class MockModem {
        intent.setAction(actionName + phoneId);
        intent.putExtra(PHONE_ID, phoneId);

        if (Flags.supportPhoneUidCheckForMultiuser()) {
            status = mContext.bindServiceAsUser(intent, serviceConnection, Context.BIND_AUTO_CREATE,
                    UserHandle.of(ActivityManager.getCurrentUser()));
        } else {
            status = mContext.bindService(intent, serviceConnection, Context.BIND_AUTO_CREATE);
        }
        return status;
    }