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

Commit 3f72604b authored by Przemyslaw Szczepaniak's avatar Przemyslaw Szczepaniak Committed by Narayan Kamath
Browse files

Use HexDump instead of java.lang.IntegralToString

java.lang.IntegralToString is being removed, replaced
all its usage by com.android.internal.util.HexDump.

Bug: 24932279
(cherry-picked from 15fc0548a536750110e159e06a39ba943eccdd81)

Change-Id: Id6ab88337af12d93cd73c41775b9d5baa1e61d96
parent 1f740d72
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package android.content.pm;

import com.android.internal.util.HexDump;

import android.annotation.SystemApi;
import android.os.Parcel;
import android.os.Parcelable;
@@ -118,7 +120,7 @@ public class ManifestDigest implements Parcelable {
        final int N = mDigest.length;
        for (int i = 0; i < N; i++) {
            final byte b = mDigest[i];
            IntegralToString.appendByteAsHex(sb, b, false);
            HexDump.appendByteAsHex(sb, b, false);
            sb.append(',');
        }
        sb.append('}');
+3 −1
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package android.net.http;

import com.android.internal.util.HexDump;

import android.content.Context;
import android.os.Bundle;
import android.text.format.DateFormat;
@@ -285,7 +287,7 @@ public class SslCertificate {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < bytes.length; i++) {
            byte b = bytes[i];
            IntegralToString.appendByteAsHex(sb, b, true);
            HexDump.appendByteAsHex(sb, b, true);
            if (i+1 != bytes.length) {
                sb.append(':');
            }
+48 −28
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.internal.util;
public class HexDump
{
    private final static char[] HEX_DIGITS = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
    private final static char[] HEX_LOWER_CASE_DIGITS = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };

    public static String dumpHexString(byte[] array)
    {
@@ -98,19 +99,30 @@ public class HexDump

    public static String toHexString(byte[] array)
    {
        return toHexString(array, 0, array.length);
        return toHexString(array, 0, array.length, true);
    }

    public static String toHexString(byte[] array, boolean upperCase)
    {
        return toHexString(array, 0, array.length, upperCase);
    }

    public static String toHexString(byte[] array, int offset, int length)
    {
        return toHexString(array, offset, length, true);
    }

    public static String toHexString(byte[] array, int offset, int length, boolean upperCase)
    {
        char[] digits = upperCase ? HEX_DIGITS : HEX_LOWER_CASE_DIGITS;
        char[] buf = new char[length * 2];

        int bufIndex = 0;
        for (int i = offset ; i < offset + length; i++)
        {
            byte b = array[i];
            buf[bufIndex++] = HEX_DIGITS[(b >>> 4) & 0x0F];
            buf[bufIndex++] = HEX_DIGITS[b & 0x0F];
            buf[bufIndex++] = digits[(b >>> 4) & 0x0F];
            buf[bufIndex++] = digits[b & 0x0F];
        }

        return new String(buf);
@@ -161,4 +173,12 @@ public class HexDump

        return buffer;
    }

    public static StringBuilder appendByteAsHex(StringBuilder sb, byte b, boolean upperCase) {
        char[] digits = upperCase ? HEX_DIGITS : HEX_LOWER_CASE_DIGITS;
        sb.append(digits[(b >> 4) & 0xf]);
        sb.append(digits[b & 0xf]);
        return sb;
    }

}
+28 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2011 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.util;

import junit.framework.TestCase;

public final class HexDumpTest extends TestCase {
    public void testBytesToHexString() {
        assertEquals("abcdef", HexDump.toHexString(
                new byte[] { (byte) 0xab, (byte) 0xcd, (byte) 0xef }, false));
        assertEquals("ABCDEF", HexDump.toHexString(
                new byte[] { (byte) 0xab, (byte) 0xcd, (byte) 0xef }, true));
    }
}
+2 −1
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.server.updates;

import com.android.server.EventLogTags;
import com.android.internal.util.HexDump;

import android.content.BroadcastReceiver;
import android.content.Context;
@@ -155,7 +156,7 @@ public class ConfigUpdateInstallReceiver extends BroadcastReceiver {
        try {
            MessageDigest dgst = MessageDigest.getInstance("SHA512");
            byte[] fingerprint = dgst.digest(content);
            return IntegralToString.bytesToHexString(fingerprint, false);
            return HexDump.toHexString(fingerprint, false);
        } catch (NoSuchAlgorithmException e) {
            throw new AssertionError(e);
        }
Loading