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

Commit 6decc5b3 authored by Tyler Gunn's avatar Tyler Gunn
Browse files

Telecom fixes related to RoleManager

- fix setState method so you can't transition from ANSWERED to ACTIVE
state.  I found a case when running some of the CTS where this was
flaking because the CTS test runs quickly enough that it was possible for
some of the Telecom answer call code to try setting a call to answered
when the underlying CS has already set it active.  ANSWERED is the
intermediate state before it becomes active.
- factor access to RoleManager for getting dialer role into the
RoleManagerAdapter.
- add ability to set an override default dialer via command line for CTS
test purposes since the RoleManager is too trigger happy when switching
the default dialer.
- change DefaultDialerCache to always refresh default dialer cache when
queried; this is an interim step until we can get the RoleManager to tell
us when the role filler for Dialer is changed.

Test: Run the CTS tests over, and over, and over, and over....
Bug: 131065482
AOSP: infeasible for now; will refactor-cherry-pick into aosp but it'll be
messy.
Change-Id: Id42b6157c338dc0a96a7db0372a5bc2df3f4d2c7
(cherry picked from commit bb4b46ee)
parent 8acd3e21
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@
    <uses-permission android:name="android.permission.INTERACT_ACROSS_USERS" />
    <uses-permission android:name="android.permission.INTERACT_ACROSS_USERS_FULL" />
    <uses-permission android:name="android.permission.MANAGE_USERS" />
    <uses-permission android:name="android.permission.MANAGE_ROLE_HOLDERS" />
    <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
    <!-- Required to determine source of ongoing audio recordings. -->
    <uses-permission android:name="android.permission.MODIFY_AUDIO_ROUTING" />
+6 −1
Original line number Diff line number Diff line
@@ -891,12 +891,17 @@ public class Call implements CreateConnectionResponse, EventManager.Loggable,
     */
    public boolean setState(int newState, String tag) {
        if (mState != newState) {
            Log.v(this, "setState %s -> %s", mState, newState);
            Log.v(this, "setState %s -> %s", CallState.toString(mState),
                    CallState.toString(newState));

            if (newState == CallState.DISCONNECTED && shouldContinueProcessingAfterDisconnect()) {
                Log.w(this, "continuing processing disconnected call with another service");
                mCreateConnectionProcessor.continueProcessingIfPossible(this, mDisconnectCause);
                return false;
            } else if (newState == CallState.ANSWERED && mState == CallState.ACTIVE) {
                Log.w(this, "setState %s -> %s; call already active.", CallState.toString(mState),
                        CallState.toString(newState));
                return false;
            }

            updateVideoHistoryViaState(mState, newState);
+13 −7
Original line number Diff line number Diff line
@@ -133,13 +133,16 @@ public class DefaultDialerCache {
    private final DefaultDialerManagerAdapter mDefaultDialerManagerAdapter;
    private final TelecomSystem.SyncRoot mLock;
    private final String mSystemDialerName;
    private final RoleManagerAdapter mRoleManagerAdapter;
    private SparseArray<String> mCurrentDefaultDialerPerUser = new SparseArray<>();

    public DefaultDialerCache(Context context,
            DefaultDialerManagerAdapter defaultDialerManagerAdapter,
            RoleManagerAdapter roleManagerAdapter,
            TelecomSystem.SyncRoot lock) {
        mContext = context;
        mDefaultDialerManagerAdapter = defaultDialerManagerAdapter;
        mRoleManagerAdapter = roleManagerAdapter;
        mLock = lock;
        mSystemDialerName = TelecomServiceImpl.getSystemDialerPackage(mContext);

@@ -173,12 +176,15 @@ public class DefaultDialerCache {
            return null;
        }

        synchronized (mLock) {
            String defaultDialer = mCurrentDefaultDialerPerUser.get(userId);
            if (defaultDialer != null) {
                return defaultDialer;
            }
        }
        // TODO: Re-enable this when we are able to use the cache once more.  RoleManager does not
        // provide a means for being informed when the role holder changes at the current time.
        //
        //synchronized (mLock) {
        //    String defaultDialer = mCurrentDefaultDialerPerUser.get(userId);
        //    if (defaultDialer != null) {
        //        return defaultDialer;
        //    }
        //}
        return refreshCacheForUser(userId);
    }

@@ -206,7 +212,7 @@ public class DefaultDialerCache {

    private String refreshCacheForUser(int userId) {
        String currentDefaultDialer =
                mDefaultDialerManagerAdapter.getDefaultDialerApplication(mContext, userId);
                mRoleManagerAdapter.getDefaultDialerApp(userId);
        synchronized (mLock) {
            mCurrentDefaultDialerPerUser.put(userId, currentDefaultDialer);
        }
+15 −0
Original line number Diff line number Diff line
@@ -64,6 +64,21 @@ public interface RoleManagerAdapter {
     */
    void setTestDefaultCallScreeningApp(String packageName);

    /**
     * Returns the package name of the app which fills the {@link android.app.role.RoleManager}
     * {@link android.app.role.RoleManager#ROLE_DIALER} role.
     * @return the package name of the app filling the role, {@code null} otherwise}.
     */
    String getDefaultDialerApp(int user);

    /**
     * Override the {@link android.app.role.RoleManager} default dialer app with another value.
     * Used for testing purposes only.
     * @param packageName Package name of the app to fill the default dialer role.  Where
     *                    {@code null}, the override is removed.
     */
    void setTestDefaultDialer(String packageName);

    /**
     * @return List of package names of companion apps, or empty list if there are none.
     */
+24 −0
Original line number Diff line number Diff line
@@ -32,10 +32,12 @@ import java.util.stream.Collectors;
public class RoleManagerAdapterImpl implements RoleManagerAdapter {
    private static final String ROLE_CALL_REDIRECTION_APP = RoleManager.ROLE_CALL_REDIRECTION;
    private static final String ROLE_CALL_SCREENING = RoleManager.ROLE_CALL_SCREENING;
    private static final String ROLE_DIALER = RoleManager.ROLE_DIALER;

    private String mOverrideDefaultCallRedirectionApp = null;
    private String mOverrideDefaultCallScreeningApp = null;
    private String mOverrideDefaultCarModeApp = null;
    private String mOverrideDefaultDialerApp = null;
    private List<String> mOverrideCallCompanionApps = new ArrayList<>();
    private Context mContext;
    private RoleManager mRoleManager;
@@ -72,6 +74,19 @@ public class RoleManagerAdapterImpl implements RoleManagerAdapter {
        mOverrideDefaultCallScreeningApp = packageName;
    }

    @Override
    public String getDefaultDialerApp(int user) {
        if (mOverrideDefaultDialerApp != null) {
            return mOverrideDefaultDialerApp;
        }
        return getRoleManagerDefaultDialerApp(user);
    }

    @Override
    public void setTestDefaultDialer(String packageName) {
        mOverrideDefaultDialerApp = packageName;
    }

    @Override
    public List<String> getCallCompanionApps() {
        List<String> callCompanionApps = new ArrayList<>();
@@ -115,6 +130,15 @@ public class RoleManagerAdapterImpl implements RoleManagerAdapter {
        return roleHolders.get(0);
    }

    private String getRoleManagerDefaultDialerApp(int user) {
        List<String> roleHolders = mRoleManager.getRoleHoldersAsUser(ROLE_DIALER,
                new UserHandle(user));
        if (roleHolders == null || roleHolders.isEmpty()) {
            return null;
        }
        return roleHolders.get(0);
    }

    // TODO in R: query and return car mode apps
    private String getRoleManagerCarModeDialerApp() {
        return null;
Loading