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

Commit 7c6b9c3b authored by Grace Jia's avatar Grace Jia Committed by Android (Google) Code Review
Browse files

Merge "Implement gathering missed information about ringing." into tm-dev

parents 4a6a4bff 457f356b
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -4138,8 +4138,8 @@ public class Call implements CreateConnectionResponse, EventManager.Loggable,
        return mStartRingTime;
    }

    public void setStartRingTime(long startRingTime) {
        mStartRingTime = startRingTime;
    public void setStartRingTime() {
        mStartRingTime = mClockProxy.elapsedRealtime();
    }

    public CharSequence getCallScreeningAppName() {
+5 −1
Original line number Diff line number Diff line
@@ -468,8 +468,12 @@ public class CallAudioManager extends CallsManagerListenerBase {
    @VisibleForTesting
    public boolean startRinging() {
        synchronized (mCallsManager.getLock()) {
            return mRinger.startRinging(mForegroundCall,
            boolean result = mRinger.startRinging(mForegroundCall,
                    mCallAudioRouteStateMachine.isHfpDeviceAvailable());
            if (result) {
                mForegroundCall.setStartRingTime();
            }
            return result;
        }
    }

+25 −0
Original line number Diff line number Diff line
@@ -17,6 +17,10 @@
package com.android.server.telecom;

import static android.provider.CallLog.Calls.MISSED_REASON_NOT_MISSED;
import static android.provider.CallLog.Calls.SHORT_RING_THRESHOLD;
import static android.provider.CallLog.Calls.USER_MISSED_NEVER_RANG;
import static android.provider.CallLog.Calls.USER_MISSED_NO_ANSWER;
import static android.provider.CallLog.Calls.USER_MISSED_SHORT_RING;
import static android.telecom.TelecomManager.ACTION_POST_CALL;
import static android.telecom.TelecomManager.DURATION_LONG;
import static android.telecom.TelecomManager.DURATION_MEDIUM;
@@ -3142,6 +3146,22 @@ public class CallsManager extends Call.ListenerBase
            // be marked as missed.
            call.setOverrideDisconnectCauseCode(new DisconnectCause(DisconnectCause.MISSED));
        }
        if (call.getState() == CallState.NEW
                && disconnectCause.getCode() == DisconnectCause.MISSED) {
            Log.i(this, "markCallAsDisconnected: missed call never rang ", call.getId());
            call.setMissedReason(USER_MISSED_NEVER_RANG);
        }
        if (call.getState() == CallState.RINGING
                || call.getState() == CallState.SIMULATED_RINGING) {
            if (call.getStartRingTime() > 0
                    && (mClockProxy.elapsedRealtime() - call.getStartRingTime())
                    < SHORT_RING_THRESHOLD) {
                Log.i(this, "markCallAsDisconnected; callid=%s, short ring.", call.getId());
                call.setUserMissed(USER_MISSED_SHORT_RING);
            } else if (call.getStartRingTime() > 0) {
                call.setUserMissed(USER_MISSED_NO_ANSWER);
            }
        }

        // If a call diagnostic service is in use, we will log the original telephony-provided
        // disconnect cause, inform the CDS of the disconnection, and then chain the update of the
@@ -5608,4 +5628,9 @@ public class CallsManager extends Call.ListenerBase
        mCalls.forEach(c -> Log.addEvent(c, LogUtils.Events.USER_LOG_MARK, message));
        Log.addEvent(null /* global */, LogUtils.Events.USER_LOG_MARK, message);
    }

    @VisibleForTesting
    public Ringer getRinger() {
        return mRinger;
    }
}
+30 −2
Original line number Diff line number Diff line
@@ -16,6 +16,10 @@

package com.android.server.telecom;

import static android.provider.CallLog.Calls.USER_MISSED_DND_MODE;
import static android.provider.CallLog.Calls.USER_MISSED_LOW_RING_VOLUME;
import static android.provider.CallLog.Calls.USER_MISSED_NO_VIBRATE;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.Person;
@@ -38,6 +42,7 @@ import com.android.server.telecom.LogUtils.EventTimer;

import java.util.ArrayList;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
@@ -59,6 +64,9 @@ public class Ringer {
    @VisibleForTesting
    public VibrationEffect mDefaultVibrationEffect;

    // Used for test to notify the completion of RingerAttributes
    private CountDownLatch mAttributesLatch;

    private static final long[] PULSE_PRIMING_PATTERN = {0,12,250,12,500}; // priming  + interval

    private static final int[] PULSE_PRIMING_AMPLITUDE = {0,255,0,255,0};  // priming  + interval
@@ -193,7 +201,6 @@ public class Ringer {
        mRingtoneFactory = ringtoneFactory;
        mInCallController = inCallController;
        mVibrationEffectProxy = vibrationEffectProxy;
        mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);

        if (mContext.getResources().getBoolean(R.bool.use_simple_vibration_pattern)) {
            mDefaultVibrationEffect = mVibrationEffectProxy.createWaveform(SIMPLE_VIBRATION_PATTERN,
@@ -236,6 +243,7 @@ public class Ringer {

        RingerAttributes attributes = null;
        try {
            mAttributesLatch = new CountDownLatch(1);
            attributes = ringerAttributesFuture.get(
                    RINGER_ATTRIBUTES_TIMEOUT, TimeUnit.MILLISECONDS);
        } catch (ExecutionException | InterruptedException | TimeoutException e) {
@@ -351,6 +359,7 @@ public class Ringer {
    private void maybeStartVibration(Call foregroundCall, boolean shouldRingForContact,
        VibrationEffect effect, boolean isVibrationEnabled, boolean isRingerAudible) {
        synchronized (mLock) {
            mAudioManager = mContext.getSystemService(AudioManager.class);
            if (isVibrationEnabled
                    && !mIsVibrating && shouldRingForContact) {
                Log.addEvent(foregroundCall, LogUtils.Events.START_VIBRATOR,
@@ -367,12 +376,12 @@ public class Ringer {
                mIsVibrating = true;
                mVibrator.vibrate(effect, VIBRATION_ATTRIBUTES);
            } else {
                foregroundCall.setUserMissed(USER_MISSED_NO_VIBRATE);
                Log.addEvent(foregroundCall, LogUtils.Events.SKIP_VIBRATION,
                        "hasVibrator=%b, userRequestsVibrate=%b, ringerMode=%d, isVibrating=%b",
                        mVibrator.hasVibrator(),
                        mSystemSettingsUtil.canVibrateWhenRinging(mContext),
                        mAudioManager.getRingerModeInternal(), mIsVibrating);
                Log.addEvent(foregroundCall, LogUtils.Events.SKIP_VIBRATION, "already vibrating");
            }
        }
    }
@@ -516,6 +525,7 @@ public class Ringer {
    }

    private RingerAttributes getRingerAttributes(Call call, boolean isHfpDeviceAttached) {
        mAudioManager = mContext.getSystemService(AudioManager.class);
        RingerAttributes.Builder builder = new RingerAttributes.Builder();

        LogUtils.EventTimer timer = new EventTimer();
@@ -567,6 +577,15 @@ public class Ringer {
        boolean shouldAcquireAudioFocus =
                isRingerAudible || (isHfpDeviceAttached && shouldRingForContact) || isSelfManaged;

        // Set missed reason according to attributes
        if (!isVolumeOverZero) {
            call.setUserMissed(USER_MISSED_LOW_RING_VOLUME);
        }
        if (!shouldRingForContact) {
            call.setUserMissed(USER_MISSED_DND_MODE);
        }

        mAttributesLatch.countDown();
        return builder.setEndEarly(endEarly)
                .setLetDialerHandleRinging(letDialerHandleRinging)
                .setAcquireAudioFocus(shouldAcquireAudioFocus)
@@ -585,4 +604,13 @@ public class Ringer {
        }
        return mHandler;
    }

    @VisibleForTesting
    public boolean waitForAttributesCompletion() throws InterruptedException {
        if (mAttributesLatch != null) {
            return mAttributesLatch.await(RINGER_ATTRIBUTES_TIMEOUT, TimeUnit.MILLISECONDS);
        } else {
            return false;
        }
    }
}
+3 −1
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.server.telecom.tests;

import static android.provider.CallLog.Calls.MISSED_REASON_NOT_MISSED;
import static android.provider.CallLog.Calls.USER_MISSED_CALL_FILTERS_TIMEOUT;
import static android.provider.CallLog.Calls.USER_MISSED_NO_VIBRATE;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -209,7 +210,8 @@ public class AnalyticsTests extends TelecomSystemTest {
        assertEquals(0, callAnalytics2.endTime);
        long missedReason1 = callAnalytics1.missedReason;
        assertTrue(missedReason1 == MISSED_REASON_NOT_MISSED
                || missedReason1 == USER_MISSED_CALL_FILTERS_TIMEOUT);
                || ((missedReason1 & USER_MISSED_CALL_FILTERS_TIMEOUT) > 0)
                || ((missedReason1 & USER_MISSED_NO_VIBRATE) > 0));
        assertEquals(MISSED_REASON_NOT_MISSED, callAnalytics2.missedReason);

        assertEquals(Analytics.INCOMING_DIRECTION, callAnalytics1.callDirection);
Loading