Loading core/java/com/android/internal/net/NetworkUtilsInternal.java +0 −31 Original line number Diff line number Diff line Loading @@ -74,35 +74,4 @@ public class NetworkUtilsInternal { return true; } /** * Safely multiple a value by a rational. * <p> * Internally it uses integer-based math whenever possible, but switches * over to double-based math if values would overflow. * @hide */ public static long multiplySafeByRational(long value, long num, long den) { if (den == 0) { throw new ArithmeticException("Invalid Denominator"); } long x = value; long y = num; // Logic shamelessly borrowed from Math.multiplyExact() long r = x * y; long ax = Math.abs(x); long ay = Math.abs(y); if (((ax | ay) >>> 31 != 0)) { // Some bits greater than 2^31 that might cause overflow // Check the result using the divide operator // and check for the special case of Long.MIN_VALUE * -1 if (((y != 0) && (r / y != x)) || (x == Long.MIN_VALUE && y == -1)) { // Use double math to avoid overflowing return (long) (((double) num / den) * value); } } return r / den; } } packages/ConnectivityT/framework-t/src/android/net/NetworkStats.java +1 −1 Original line number Diff line number Diff line Loading @@ -16,7 +16,7 @@ package android.net; import static com.android.internal.net.NetworkUtilsInternal.multiplySafeByRational; import static com.android.net.module.util.NetworkStatsUtils.multiplySafeByRational; import android.annotation.IntDef; import android.annotation.NonNull; Loading packages/ConnectivityT/framework-t/src/android/net/NetworkStatsCollection.java +1 −1 Original line number Diff line number Diff line Loading @@ -30,7 +30,7 @@ import static android.net.NetworkStats.UID_ALL; import static android.net.TrafficStats.UID_REMOVED; import static android.text.format.DateUtils.WEEK_IN_MILLIS; import static com.android.internal.net.NetworkUtilsInternal.multiplySafeByRational; import static com.android.net.module.util.NetworkStatsUtils.multiplySafeByRational; import android.os.Binder; import android.service.NetworkStatsCollectionKeyProto; Loading packages/ConnectivityT/framework-t/src/android/net/NetworkStatsHistory.java +1 −1 Original line number Diff line number Diff line Loading @@ -28,8 +28,8 @@ import static android.net.NetworkStatsHistory.ParcelUtils.readLongArray; import static android.net.NetworkStatsHistory.ParcelUtils.writeLongArray; import static android.text.format.DateUtils.SECOND_IN_MILLIS; import static com.android.internal.net.NetworkUtilsInternal.multiplySafeByRational; import static com.android.internal.util.ArrayUtils.total; import static com.android.net.module.util.NetworkStatsUtils.multiplySafeByRational; import android.compat.annotation.UnsupportedAppUsage; import android.os.Build; Loading Loading
core/java/com/android/internal/net/NetworkUtilsInternal.java +0 −31 Original line number Diff line number Diff line Loading @@ -74,35 +74,4 @@ public class NetworkUtilsInternal { return true; } /** * Safely multiple a value by a rational. * <p> * Internally it uses integer-based math whenever possible, but switches * over to double-based math if values would overflow. * @hide */ public static long multiplySafeByRational(long value, long num, long den) { if (den == 0) { throw new ArithmeticException("Invalid Denominator"); } long x = value; long y = num; // Logic shamelessly borrowed from Math.multiplyExact() long r = x * y; long ax = Math.abs(x); long ay = Math.abs(y); if (((ax | ay) >>> 31 != 0)) { // Some bits greater than 2^31 that might cause overflow // Check the result using the divide operator // and check for the special case of Long.MIN_VALUE * -1 if (((y != 0) && (r / y != x)) || (x == Long.MIN_VALUE && y == -1)) { // Use double math to avoid overflowing return (long) (((double) num / den) * value); } } return r / den; } }
packages/ConnectivityT/framework-t/src/android/net/NetworkStats.java +1 −1 Original line number Diff line number Diff line Loading @@ -16,7 +16,7 @@ package android.net; import static com.android.internal.net.NetworkUtilsInternal.multiplySafeByRational; import static com.android.net.module.util.NetworkStatsUtils.multiplySafeByRational; import android.annotation.IntDef; import android.annotation.NonNull; Loading
packages/ConnectivityT/framework-t/src/android/net/NetworkStatsCollection.java +1 −1 Original line number Diff line number Diff line Loading @@ -30,7 +30,7 @@ import static android.net.NetworkStats.UID_ALL; import static android.net.TrafficStats.UID_REMOVED; import static android.text.format.DateUtils.WEEK_IN_MILLIS; import static com.android.internal.net.NetworkUtilsInternal.multiplySafeByRational; import static com.android.net.module.util.NetworkStatsUtils.multiplySafeByRational; import android.os.Binder; import android.service.NetworkStatsCollectionKeyProto; Loading
packages/ConnectivityT/framework-t/src/android/net/NetworkStatsHistory.java +1 −1 Original line number Diff line number Diff line Loading @@ -28,8 +28,8 @@ import static android.net.NetworkStatsHistory.ParcelUtils.readLongArray; import static android.net.NetworkStatsHistory.ParcelUtils.writeLongArray; import static android.text.format.DateUtils.SECOND_IN_MILLIS; import static com.android.internal.net.NetworkUtilsInternal.multiplySafeByRational; import static com.android.internal.util.ArrayUtils.total; import static com.android.net.module.util.NetworkStatsUtils.multiplySafeByRational; import android.compat.annotation.UnsupportedAppUsage; import android.os.Build; Loading