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

Commit fcabf21b authored by qing's avatar qing Committed by Qing Zhong
Browse files

Let external calls be logged for wearable devices

This is a manual CP of ag/22976617

Test: unit test and manual test
Bug: 292600751
Change-Id: Ic6d2aae5dabac67e2704287ee5572ca9f4430135
parent 525dc1a7
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ aconfig_declarations {
      "telecom_incallservice_flags.aconfig",
      "telecom_default_phone_account_flags.aconfig",
      "telecom_callaudioroutestatemachine_flags.aconfig",
      "telecom_calllog_flags.aconfig",
      "telecom_resolve_hidden_dependencies.aconfig"
    ],
}
+8 −0
Original line number Diff line number Diff line
package: "com.android.server.telecom.flags"

flag {
  name: "telecom_log_external_wearable_calls"
  namespace: "telecom"
  description: "log external call if current device is a wearable one"
  bug: "292600751"
}
 No newline at end of file
+12 −4
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import android.annotation.Nullable;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.location.Country;
import android.location.CountryDetector;
@@ -50,6 +51,7 @@ import android.util.Pair;

import com.android.internal.annotations.VisibleForTesting;
import com.android.server.telecom.callfiltering.CallFilteringResult;
import com.android.server.telecom.flags.FeatureFlags;

import java.util.Arrays;
import java.util.Locale;
@@ -117,8 +119,11 @@ public final class CallLogManager extends CallsManagerListenerBase {
    private Object mLock;
    private String mCurrentCountryIso;

    private final FeatureFlags mFeatureFlags;

    public CallLogManager(Context context, PhoneAccountRegistrar phoneAccountRegistrar,
            MissedCallNotifier missedCallNotifier, AnomalyReporterAdapter anomalyReporterAdapter) {
            MissedCallNotifier missedCallNotifier, AnomalyReporterAdapter anomalyReporterAdapter,
            FeatureFlags featureFlags) {
        mContext = context;
        mCarrierConfigManager = (CarrierConfigManager) mContext
                .getSystemService(Context.CARRIER_CONFIG_SERVICE);
@@ -126,6 +131,7 @@ public final class CallLogManager extends CallsManagerListenerBase {
        mMissedCallNotifier = missedCallNotifier;
        mAnomalyReporterAdapter = anomalyReporterAdapter;
        mLock = new Object();
        mFeatureFlags = featureFlags;
    }

    @Override
@@ -166,7 +172,7 @@ public final class CallLogManager extends CallsManagerListenerBase {
     * Call is NOT a child call from a conference which was remotely hosted.
     * Call is NOT simulating a single party conference.
     * Call was NOT explicitly canceled, except for disconnecting from a conference.
     * Call is NOT an external call
     * Call is NOT an external call or an external call on watch.
     * Call is NOT disconnected because of merging into a conference.
     * Call is NOT a self-managed call OR call is a self-managed call which has indicated it
     * should be logged in its PhoneAccount
@@ -215,8 +221,10 @@ public final class CallLogManager extends CallsManagerListenerBase {
                    & Connection.CAPABILITY_DISCONNECT_FROM_CONFERENCE)
                    == Connection.CAPABILITY_DISCONNECT_FROM_CONFERENCE;
        }
        // An external call
        if (call.isExternalCall()) {
        // An external and non-watch call
        if (call.isExternalCall() && (!mContext.getPackageManager().hasSystemFeature(
                PackageManager.FEATURE_WATCH)
                || !mFeatureFlags.telecomLogExternalWearableCalls())) {
            return false;
        }

+1 −1
Original line number Diff line number Diff line
@@ -665,7 +665,7 @@ public class CallsManager extends Call.ListenerBase
        mProximitySensorManager = proximitySensorManagerFactory.create(context, this);
        mPhoneStateBroadcaster = new PhoneStateBroadcaster(this);
        mCallLogManager = new CallLogManager(context, phoneAccountRegistrar, mMissedCallNotifier,
                mAnomalyReporter);
                mAnomalyReporter, featureFlags);
        mConnectionServiceRepository =
                new ConnectionServiceRepository(mPhoneAccountRegistrar, mContext, mLock, this);
        mInCallWakeLockController = inCallWakeLockControllerFactory.create(context, this);
+37 −1
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ import android.content.ContentProvider;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
import android.content.pm.PackageManager;
import android.content.pm.UserInfo;
import android.content.res.Resources;
import android.location.Country;
@@ -73,6 +74,7 @@ import com.android.server.telecom.HandoverState;
import com.android.server.telecom.MissedCallNotifier;
import com.android.server.telecom.PhoneAccountRegistrar;
import com.android.server.telecom.TelephonyUtil;
import com.android.server.telecom.flags.FeatureFlags;

import org.junit.After;
import org.junit.Before;
@@ -127,13 +129,16 @@ public class CallLogManagerTest extends TelecomTestCase {
    @Mock
    AnomalyReporterAdapter mAnomalyReporterAdapter;

    @Mock
    FeatureFlags mFeatureFlags;

    @Override
    @Before
    public void setUp() throws Exception {
        super.setUp();
        mContext = mComponentContextFixture.getTestDouble().getApplicationContext();
        mCallLogManager = new CallLogManager(mContext, mMockPhoneAccountRegistrar,
                mMissedCallNotifier, mAnomalyReporterAdapter);
                mMissedCallNotifier, mAnomalyReporterAdapter, mFeatureFlags);
        mDefaultAccountHandle = new PhoneAccountHandle(
                new ComponentName("com.android.server.telecom.tests", "CallLogManagerTest"),
                TEST_PHONE_ACCOUNT_ID,
@@ -184,6 +189,9 @@ public class CallLogManagerTest extends TelecomTestCase {
        when(userManager.getUserInfo(eq(CURRENT_USER_ID))).thenReturn(userInfo);
        when(userManager.getUserInfo(eq(OTHER_USER_ID))).thenReturn(otherUserInfo);
        when(userManager.getUserInfo(eq(MANAGED_USER_ID))).thenReturn(managedProfileUserInfo);
        PackageManager packageManager = mContext.getPackageManager();
        when(packageManager.hasSystemFeature(PackageManager.FEATURE_WATCH)).thenReturn(false);
        when(mFeatureFlags.telecomLogExternalWearableCalls()).thenReturn(false);
    }

    @Override
@@ -791,6 +799,34 @@ public class CallLogManagerTest extends TelecomTestCase {
        assertEquals(1, insertedValues.getAsInteger(Calls.IS_READ).intValue());
    }

    @Test
    public void testLogCallWhenExternalCallOnWatch() {
        when(mMockPhoneAccountRegistrar.getPhoneAccountUnchecked(any(PhoneAccountHandle.class)))
                .thenReturn(makeFakePhoneAccount(mDefaultAccountHandle, CURRENT_USER_ID));
        PackageManager packageManager = mContext.getPackageManager();
        when(packageManager.hasSystemFeature(PackageManager.FEATURE_WATCH)).thenReturn(true);
        when(mFeatureFlags.telecomLogExternalWearableCalls()).thenReturn(true);
        Call fakeMissedCall = makeFakeCall(
                DisconnectCause.REJECTED, // disconnectCauseCode
                false, // isConference
                true, // isIncoming
                1L, // creationTimeMillis
                1000L, // ageMillis
                TEL_PHONEHANDLE, // callHandle
                mDefaultAccountHandle, // phoneAccountHandle
                NO_VIDEO_STATE, // callVideoState
                POST_DIAL_STRING, // postDialDigits
                VIA_NUMBER_STRING, // viaNumber
                null
        );
        when(fakeMissedCall.isExternalCall()).thenReturn(true);

        mCallLogManager.onCallStateChanged(fakeMissedCall, CallState.ACTIVE,
                CallState.DISCONNECTED);
        verifyInsertionWithCapture(CURRENT_USER_ID);
    }


    @SmallTest
    @Test
    public void testCountryIso_setCache() {