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

Commit 9da5fbf6 authored by Rambo Wang's avatar Rambo Wang
Browse files

Enable SignalThreshold with consideration of both system and apps

With "Triggered Signal Strength reporting" feature introduced
in b/164432835, SignalThreshold enableness is not only determined
by system for sysUI policy, but also by signal update request
from privileged apps.

For specific RAN with signal measurement type, the corresponding
threshold will be enabled if system and/or app request to enable it.

The enablenss of the system threshold also determines if it should
be involved in the thresholds consolidation. Only it is enabled and
honored (either in high power mode or app explicitly request it in idle)
when it should be included.

Bug: 176961228
Test: com.android.internal.telephony.GsmCdmaPhoneTest
Test: com.android.internal.telephony.ServiceStateTrackerTest
Change-Id: Ie699e009aa99dc6d01c78192f2c0132236883c6d
Merged-In: Ie699e009aa99dc6d01c78192f2c0132236883c6d
(cherry picked from commit 008d069f)
parent e19471e5
Loading
Loading
Loading
Loading
+10 −4
Original line number Diff line number Diff line
@@ -4068,13 +4068,19 @@ public class GsmCdmaPhone extends Phone {
    }

    @Override
    public void setSignalStrengthReportingCriteria(
            int signalStrengthMeasure, int[] thresholds, int ran, boolean isEnabled) {
    public void setSignalStrengthReportingCriteria(int signalStrengthMeasure,
            int[] systemThresholds, int ran, boolean isEnabledForSystem) {
        int[] consolidatedThresholds = mSST.getConsolidatedSignalThresholds(
                ran,
                signalStrengthMeasure,
                mSST.shouldHonorSystemThresholds() ? thresholds : new int[]{},
                isEnabledForSystem && mSST.shouldHonorSystemThresholds() ? systemThresholds
                        : new int[]{},
                REPORTING_HYSTERESIS_DB);
        boolean isEnabledForAppRequest = mSST.shouldEnableSignalThresholdForAppRequest(
                ran,
                signalStrengthMeasure,
                getSubId(),
                isDeviceIdle());
        mCi.setSignalStrengthReportingCriteria(
                new SignalThresholdInfo.Builder()
                        .setRadioAccessNetworkType(ran)
@@ -4082,7 +4088,7 @@ public class GsmCdmaPhone extends Phone {
                        .setHysteresisMs(REPORTING_HYSTERESIS_MILLIS)
                        .setHysteresisDb(REPORTING_HYSTERESIS_DB)
                        .setThresholds(consolidatedThresholds, true /*isSystem*/)
                        .setIsEnabled(isEnabled)
                        .setIsEnabled(isEnabledForSystem || isEnabledForAppRequest)
                        .build(),
                ran, null);
    }
+35 −5
Original line number Diff line number Diff line
@@ -6320,8 +6320,7 @@ public class ServiceStateTracker extends Handler {
                continue;
            }
            for (SignalThresholdInfo info : record.mRequest.getSignalThresholdInfos()) {
                if (ran == info.getRadioAccessNetworkType()
                        && measurement == info.getSignalMeasurementType()) {
                if (isRanAndSignalMeasurementTypeMatch(ran, measurement, info)) {
                    for (int appThreshold : info.getThresholds()) {
                        target.add(appThreshold);
                    }
@@ -6352,12 +6351,44 @@ public class ServiceStateTracker extends Handler {
        sendMessage(obtainMessage(EVENT_ON_DEVICE_IDLE_STATE_CHANGED, isDeviceIdle));
    }

    boolean shouldEnableSignalThresholdForAppRequest(
            @AccessNetworkConstants.RadioAccessNetworkType int ran,
            @SignalThresholdInfo.SignalMeasurementType int measurement,
            int subId,
            boolean isDeviceIdle) {
        for (SignalRequestRecord record : mSignalRequestRecords) {
            if (subId != record.mSubId) {
                continue;
            }
            for (SignalThresholdInfo info : record.mRequest.getSignalThresholdInfos()) {
                if (isRanAndSignalMeasurementTypeMatch(ran, measurement, info)
                        && (!isDeviceIdle || isSignalReportRequestedWhileIdle(record.mRequest))) {
                    return true;
                }
            }
        }
        return false;
    }

    private static boolean isRanAndSignalMeasurementTypeMatch(
            @AccessNetworkConstants.RadioAccessNetworkType int ran,
            @SignalThresholdInfo.SignalMeasurementType int measurement,
            SignalThresholdInfo info) {
        return ran == info.getRadioAccessNetworkType()
                && measurement == info.getSignalMeasurementType();
    }

    private static boolean isSignalReportRequestedWhileIdle(SignalStrengthUpdateRequest request) {
        return request.isSystemThresholdReportingRequestedWhileIdle()
                || request.isReportingRequestedWhileIdle();
    }

    private class SignalRequestRecord implements IBinder.DeathRecipient {
        final int mSubId; // subId the request originally applied to
        final int mCallingUid;
        final SignalStrengthUpdateRequest mRequest;

        SignalRequestRecord(int subId, int uid, SignalStrengthUpdateRequest request) {
        SignalRequestRecord(int subId, int uid, @NonNull SignalStrengthUpdateRequest request) {
            this.mCallingUid = uid;
            this.mSubId = subId;
            this.mRequest = request;
@@ -6372,8 +6403,7 @@ public class ServiceStateTracker extends Handler {
    private void updateAlwaysReportSignalStrength() {
        final int curSubId = mPhone.getSubId();
        boolean alwaysReport = mSignalRequestRecords.stream().anyMatch(
                srr -> srr.mSubId == curSubId && (srr.mRequest.isReportingRequestedWhileIdle()
                        || srr.mRequest.isSystemThresholdReportingRequestedWhileIdle()));
                srr -> srr.mSubId == curSubId && isSignalReportRequestedWhileIdle(srr.mRequest));

        // TODO(b/177924721): TM#setAlwaysReportSignalStrength will be removed and we will not
        // worry about unset flag which was set by other client.