Loading src/java/com/android/internal/telephony/RatRatcheter.java +41 −6 Original line number Diff line number Diff line Loading @@ -22,11 +22,13 @@ import android.content.IntentFilter; import android.os.PersistableBundle; import android.os.UserHandle; import android.telephony.CarrierConfigManager; import android.telephony.ServiceState; import android.telephony.Rlog; import android.telephony.ServiceState; import android.util.SparseArray; import android.util.SparseIntArray; import java.util.Arrays; /** * This class loads configuration from CarrierConfig and uses it to determine * what RATs are within a ratcheting family. For example all the HSPA/HSDPA/HSUPA RATs. Loading @@ -46,10 +48,31 @@ public class RatRatcheter { private final SparseArray<SparseIntArray> mRatFamilyMap = new SparseArray<>(); private final Phone mPhone; private boolean mVoiceRatchetEnabled = true; private boolean mDataRatchetEnabled = true; /** * Updates the ServiceState with a new set of cell bandwidths IFF the new bandwidth list has a * higher aggregate bandwidth. * * @return Whether the bandwidths were updated. */ public static boolean updateBandwidths(int[] bandwidths, ServiceState serviceState) { if (bandwidths == null) { return false; } int ssAggregateBandwidth = Arrays.stream(serviceState.getCellBandwidths()).sum(); int newAggregateBandwidth = Arrays.stream(bandwidths).sum(); if (newAggregateBandwidth > ssAggregateBandwidth) { serviceState.setCellBandwidths(bandwidths); return true; } return false; } /** Constructor */ public RatRatcheter(Phone phone) { mPhone = phone; Loading @@ -61,7 +84,7 @@ public class RatRatcheter { resetRatFamilyMap(); } public int ratchetRat(int oldRat, int newRat) { private int ratchetRat(int oldRat, int newRat) { synchronized (mRatFamilyMap) { final SparseIntArray oldFamily = mRatFamilyMap.get(oldRat); if (oldFamily == null) return newRat; Loading @@ -76,7 +99,11 @@ public class RatRatcheter { } } public void ratchetRat(ServiceState oldSS, ServiceState newSS, boolean locationChange) { /** Ratchets RATs and cell bandwidths if oldSS and newSS have the same RAT family. */ public void ratchet(ServiceState oldSS, ServiceState newSS, boolean locationChange) { if (isSameRatFamily(oldSS, newSS)) { updateBandwidths(oldSS.getCellBandwidths(), newSS); } // temporarily disable rat ratchet on location change. if (locationChange) { mVoiceRatchetEnabled = false; Loading @@ -101,11 +128,19 @@ public class RatRatcheter { mVoiceRatchetEnabled = true; } boolean newUsingCA = oldSS.isUsingCarrierAggregation() || newSS.isUsingCarrierAggregation(); boolean newUsingCA = oldSS.isUsingCarrierAggregation() || newSS.isUsingCarrierAggregation() || newSS.getCellBandwidths().length > 1; newSS.setIsUsingCarrierAggregation(newUsingCA); } private boolean isSameRatFamily(ServiceState ss1, ServiceState ss2) { synchronized (mRatFamilyMap) { return mRatFamilyMap.get(ss1.getRilDataRadioTechnology()) == mRatFamilyMap.get(ss2.getRilDataRadioTechnology()); } } private BroadcastReceiver mConfigChangedReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { Loading src/java/com/android/internal/telephony/ServiceStateTracker.java +16 −3 Original line number Diff line number Diff line Loading @@ -1432,6 +1432,11 @@ public class ServiceStateTracker extends Handler { + list); } mPhone.notifyPhysicalChannelConfiguration(list); // only notify if bandwidths changed if (RatRatcheter.updateBandwidths(getBandwidthsFromConfigs(list), mSS)) { mPhone.notifyServiceStateChanged(mSS); } } break; Loading @@ -1441,6 +1446,13 @@ public class ServiceStateTracker extends Handler { } } private int[] getBandwidthsFromConfigs(List<PhysicalChannelConfig> list) { return list.stream() .map(PhysicalChannelConfig::getCellBandwidthDownlink) .mapToInt(Integer::intValue) .toArray(); } protected boolean isSidsAllZeros() { if (mHomeSystemId != null) { for (int i=0; i < mHomeSystemId.length; i++) { Loading Loading @@ -2646,11 +2658,12 @@ public class ServiceStateTracker extends Handler { boolean hasLocationChanged = !mNewCellLoc.equals(mCellLoc); // ratchet the new tech up through it's rat family but don't drop back down // ratchet the new tech up through its rat family but don't drop back down // until cell change or device is OOS boolean isDataInService = mNewSS.getDataRegState() == ServiceState.STATE_IN_SERVICE; if (isDataInService) { mRatRatcheter.ratchetRat(mSS, mNewSS, hasLocationChanged); if (!hasLocationChanged && isDataInService) { mRatRatcheter.ratchet(mSS, mNewSS, hasLocationChanged); } boolean hasRilVoiceRadioTechnologyChanged = Loading tests/telephonytests/src/com/android/internal/telephony/RatRatcheterTest.java 0 → 100644 +71 −0 Original line number Diff line number Diff line /* * Copyright (C) 2018 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.internal.telephony; import static junit.framework.Assert.assertFalse; import static junit.framework.Assert.assertTrue; import android.telephony.ServiceState; import org.junit.Before; import org.junit.Test; import java.util.Arrays; /** Tests for RatRatcheter. */ public class RatRatcheterTest { private ServiceState mServiceState; @Before public void setUp() { mServiceState = new ServiceState(); } @Test public void testUpdateBandwidthsSuccess() { int[] bandwidths = new int[] {1400, 5000}; mServiceState.setCellBandwidths(new int[] {5000}); boolean updated = RatRatcheter.updateBandwidths(bandwidths, mServiceState); assertTrue(updated); assertTrue(Arrays.equals(mServiceState.getCellBandwidths(), bandwidths)); } @Test public void testUpdateBandwidthsFailure() { int[] originalBandwidths = {5000, 10000}; int[] newBandwidths = {1400, 5000}; mServiceState.setCellBandwidths(originalBandwidths); boolean updated = RatRatcheter.updateBandwidths(newBandwidths, mServiceState); assertFalse(updated); assertTrue(Arrays.equals(mServiceState.getCellBandwidths(), originalBandwidths)); } @Test public void testUpdateBandwidthsNull() { int[] originalBandwidths = {5000, 10000}; mServiceState.setCellBandwidths(originalBandwidths); boolean updated = RatRatcheter.updateBandwidths(null, mServiceState); assertFalse(updated); assertTrue(Arrays.equals(mServiceState.getCellBandwidths(), originalBandwidths)); } } Loading
src/java/com/android/internal/telephony/RatRatcheter.java +41 −6 Original line number Diff line number Diff line Loading @@ -22,11 +22,13 @@ import android.content.IntentFilter; import android.os.PersistableBundle; import android.os.UserHandle; import android.telephony.CarrierConfigManager; import android.telephony.ServiceState; import android.telephony.Rlog; import android.telephony.ServiceState; import android.util.SparseArray; import android.util.SparseIntArray; import java.util.Arrays; /** * This class loads configuration from CarrierConfig and uses it to determine * what RATs are within a ratcheting family. For example all the HSPA/HSDPA/HSUPA RATs. Loading @@ -46,10 +48,31 @@ public class RatRatcheter { private final SparseArray<SparseIntArray> mRatFamilyMap = new SparseArray<>(); private final Phone mPhone; private boolean mVoiceRatchetEnabled = true; private boolean mDataRatchetEnabled = true; /** * Updates the ServiceState with a new set of cell bandwidths IFF the new bandwidth list has a * higher aggregate bandwidth. * * @return Whether the bandwidths were updated. */ public static boolean updateBandwidths(int[] bandwidths, ServiceState serviceState) { if (bandwidths == null) { return false; } int ssAggregateBandwidth = Arrays.stream(serviceState.getCellBandwidths()).sum(); int newAggregateBandwidth = Arrays.stream(bandwidths).sum(); if (newAggregateBandwidth > ssAggregateBandwidth) { serviceState.setCellBandwidths(bandwidths); return true; } return false; } /** Constructor */ public RatRatcheter(Phone phone) { mPhone = phone; Loading @@ -61,7 +84,7 @@ public class RatRatcheter { resetRatFamilyMap(); } public int ratchetRat(int oldRat, int newRat) { private int ratchetRat(int oldRat, int newRat) { synchronized (mRatFamilyMap) { final SparseIntArray oldFamily = mRatFamilyMap.get(oldRat); if (oldFamily == null) return newRat; Loading @@ -76,7 +99,11 @@ public class RatRatcheter { } } public void ratchetRat(ServiceState oldSS, ServiceState newSS, boolean locationChange) { /** Ratchets RATs and cell bandwidths if oldSS and newSS have the same RAT family. */ public void ratchet(ServiceState oldSS, ServiceState newSS, boolean locationChange) { if (isSameRatFamily(oldSS, newSS)) { updateBandwidths(oldSS.getCellBandwidths(), newSS); } // temporarily disable rat ratchet on location change. if (locationChange) { mVoiceRatchetEnabled = false; Loading @@ -101,11 +128,19 @@ public class RatRatcheter { mVoiceRatchetEnabled = true; } boolean newUsingCA = oldSS.isUsingCarrierAggregation() || newSS.isUsingCarrierAggregation(); boolean newUsingCA = oldSS.isUsingCarrierAggregation() || newSS.isUsingCarrierAggregation() || newSS.getCellBandwidths().length > 1; newSS.setIsUsingCarrierAggregation(newUsingCA); } private boolean isSameRatFamily(ServiceState ss1, ServiceState ss2) { synchronized (mRatFamilyMap) { return mRatFamilyMap.get(ss1.getRilDataRadioTechnology()) == mRatFamilyMap.get(ss2.getRilDataRadioTechnology()); } } private BroadcastReceiver mConfigChangedReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { Loading
src/java/com/android/internal/telephony/ServiceStateTracker.java +16 −3 Original line number Diff line number Diff line Loading @@ -1432,6 +1432,11 @@ public class ServiceStateTracker extends Handler { + list); } mPhone.notifyPhysicalChannelConfiguration(list); // only notify if bandwidths changed if (RatRatcheter.updateBandwidths(getBandwidthsFromConfigs(list), mSS)) { mPhone.notifyServiceStateChanged(mSS); } } break; Loading @@ -1441,6 +1446,13 @@ public class ServiceStateTracker extends Handler { } } private int[] getBandwidthsFromConfigs(List<PhysicalChannelConfig> list) { return list.stream() .map(PhysicalChannelConfig::getCellBandwidthDownlink) .mapToInt(Integer::intValue) .toArray(); } protected boolean isSidsAllZeros() { if (mHomeSystemId != null) { for (int i=0; i < mHomeSystemId.length; i++) { Loading Loading @@ -2646,11 +2658,12 @@ public class ServiceStateTracker extends Handler { boolean hasLocationChanged = !mNewCellLoc.equals(mCellLoc); // ratchet the new tech up through it's rat family but don't drop back down // ratchet the new tech up through its rat family but don't drop back down // until cell change or device is OOS boolean isDataInService = mNewSS.getDataRegState() == ServiceState.STATE_IN_SERVICE; if (isDataInService) { mRatRatcheter.ratchetRat(mSS, mNewSS, hasLocationChanged); if (!hasLocationChanged && isDataInService) { mRatRatcheter.ratchet(mSS, mNewSS, hasLocationChanged); } boolean hasRilVoiceRadioTechnologyChanged = Loading
tests/telephonytests/src/com/android/internal/telephony/RatRatcheterTest.java 0 → 100644 +71 −0 Original line number Diff line number Diff line /* * Copyright (C) 2018 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.internal.telephony; import static junit.framework.Assert.assertFalse; import static junit.framework.Assert.assertTrue; import android.telephony.ServiceState; import org.junit.Before; import org.junit.Test; import java.util.Arrays; /** Tests for RatRatcheter. */ public class RatRatcheterTest { private ServiceState mServiceState; @Before public void setUp() { mServiceState = new ServiceState(); } @Test public void testUpdateBandwidthsSuccess() { int[] bandwidths = new int[] {1400, 5000}; mServiceState.setCellBandwidths(new int[] {5000}); boolean updated = RatRatcheter.updateBandwidths(bandwidths, mServiceState); assertTrue(updated); assertTrue(Arrays.equals(mServiceState.getCellBandwidths(), bandwidths)); } @Test public void testUpdateBandwidthsFailure() { int[] originalBandwidths = {5000, 10000}; int[] newBandwidths = {1400, 5000}; mServiceState.setCellBandwidths(originalBandwidths); boolean updated = RatRatcheter.updateBandwidths(newBandwidths, mServiceState); assertFalse(updated); assertTrue(Arrays.equals(mServiceState.getCellBandwidths(), originalBandwidths)); } @Test public void testUpdateBandwidthsNull() { int[] originalBandwidths = {5000, 10000}; mServiceState.setCellBandwidths(originalBandwidths); boolean updated = RatRatcheter.updateBandwidths(null, mServiceState); assertFalse(updated); assertTrue(Arrays.equals(mServiceState.getCellBandwidths(), originalBandwidths)); } }