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

Commit b8bdc721 authored by Neil Fuller's avatar Neil Fuller Committed by Gerrit Code Review
Browse files

Merge "Migrate telephony code away from Time"

parents 08b928e8 c18b91b3
Loading
Loading
Loading
Loading
+17 −14
Original line number Diff line number Diff line
@@ -18,10 +18,11 @@ package android.telephony;

import android.os.Parcel;
import android.os.Parcelable;
import android.text.format.Time;

import com.android.internal.telephony.uicc.IccUtils;

import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.Arrays;

/**
@@ -165,19 +166,21 @@ public class SmsCbEtwsInfo implements Parcelable {
        int timezoneOffset = IccUtils.gsmBcdByteToInt((byte) (tzByte & (~0x08)));

        timezoneOffset = ((tzByte & 0x08) == 0) ? timezoneOffset : -timezoneOffset;
        // timezoneOffset is in quarter hours.
        int timeZoneOffsetSeconds = timezoneOffset * 15 * 60;

        Time time = new Time(Time.TIMEZONE_UTC);

        LocalDateTime localDateTime = LocalDateTime.of(
                // We only need to support years above 2000.
        time.year = year + 2000;
        time.month = month - 1;
        time.monthDay = day;
        time.hour = hour;
        time.minute = minute;
        time.second = second;

        // Timezone offset is in quarter hours.
        return time.toMillis(true) - timezoneOffset * 15 * 60 * 1000;
                year + 2000,
                month /* 1-12 */,
                day,
                hour,
                minute,
                second);

        long epochSeconds = localDateTime.toEpochSecond(ZoneOffset.UTC) - timeZoneOffsetSeconds;
        // Convert to milliseconds, ignore overflow.
        return epochSeconds * 1000;
    }

    /**
+26 −4
Original line number Diff line number Diff line
@@ -20,7 +20,6 @@ import android.content.res.Resources;
import android.telephony.SmsCbCmasInfo;
import android.telephony.cdma.CdmaSmsCbProgramData;
import android.telephony.cdma.CdmaSmsCbProgramResults;
import android.text.format.Time;
import android.telephony.Rlog;

import com.android.internal.telephony.GsmAlphabet;
@@ -32,8 +31,10 @@ import com.android.internal.telephony.uicc.IccUtils;
import com.android.internal.util.BitwiseInputStream;
import com.android.internal.util.BitwiseOutputStream;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.TimeZone;

/**
 * An object to encode and decode CDMA SMS bearer data.
@@ -228,10 +229,23 @@ public final class BearerData {
    /**
     * 6-byte-field, see 3GPP2 C.S0015-B, v2, 4.5.4
     */
    public static class TimeStamp extends Time {
    public static class TimeStamp {

        public int second;
        public int minute;
        public int hour;
        public int monthDay;

        /** Month [0-11] */
        public int month;

        /** Full year. For example, 1970. */
        public int year;

        private ZoneId mZoneId;

        public TimeStamp() {
            super(TimeZone.getDefault().getID());   // 3GPP2 timestamps use the local timezone
            mZoneId = ZoneId.systemDefault();   // 3GPP2 timestamps use the local timezone
        }

        public static TimeStamp fromByteArray(byte[] data) {
@@ -258,6 +272,14 @@ public final class BearerData {
            return ts;
        }

        public long toMillis() {
            LocalDateTime localDateTime =
                    LocalDateTime.of(year, month + 1, monthDay, hour, minute, second);
            Instant instant = localDateTime.toInstant(mZoneId.getRules().getOffset(localDateTime));
            return instant.toEpochMilli();
        }


        @Override
        public String toString() {
            StringBuilder builder = new StringBuilder();
+1 −1
Original line number Diff line number Diff line
@@ -718,7 +718,7 @@ public class SmsMessage extends SmsMessageBase {
        }

        if (mBearerData.msgCenterTimeStamp != null) {
            mScTimeMillis = mBearerData.msgCenterTimeStamp.toMillis(true);
            mScTimeMillis = mBearerData.msgCenterTimeStamp.toMillis();
        }

        if (VDBG) Rlog.d(LOG_TAG, "SMS SC timestamp: " + mScTimeMillis);
+15 −12
Original line number Diff line number Diff line
@@ -17,7 +17,6 @@
package com.android.internal.telephony.gsm;

import android.telephony.PhoneNumberUtils;
import android.text.format.Time;
import android.telephony.Rlog;
import android.content.res.Resources;
import android.text.TextUtils;
@@ -33,6 +32,8 @@ import com.android.internal.telephony.Sms7BitEncodingTranslator;
import java.io.ByteArrayOutputStream;
import java.io.UnsupportedEncodingException;
import java.text.ParseException;
import java.time.LocalDateTime;
import java.time.ZoneOffset;

import static com.android.internal.telephony.SmsConstants.MessageClass;
import static com.android.internal.telephony.SmsConstants.ENCODING_UNKNOWN;
@@ -722,19 +723,21 @@ public class SmsMessage extends SmsMessageBase {
            int timezoneOffset = IccUtils.gsmBcdByteToInt((byte) (tzByte & (~0x08)));

            timezoneOffset = ((tzByte & 0x08) == 0) ? timezoneOffset : -timezoneOffset;

            Time time = new Time(Time.TIMEZONE_UTC);
            // timezoneOffset is in quarter hours.
            int timeZoneOffsetSeconds = timezoneOffset * 15 * 60;

            // It's 2006.  Should I really support years < 2000?
            time.year = year >= 90 ? year + 1900 : year + 2000;
            time.month = month - 1;
            time.monthDay = day;
            time.hour = hour;
            time.minute = minute;
            time.second = second;

            // Timezone offset is in quarter hours.
            return time.toMillis(true) - (timezoneOffset * 15 * 60 * 1000);
            int fullYear = year >= 90 ? year + 1900 : year + 2000;
            LocalDateTime localDateTime = LocalDateTime.of(
                    fullYear,
                    month /* 1-12 */,
                    day,
                    hour,
                    minute,
                    second);
            long epochSeconds = localDateTime.toEpochSecond(ZoneOffset.UTC) - timeZoneOffsetSeconds;
            // Convert to milliseconds.
            return epochSeconds * 1000;
        }

        /**