summaryrefslogtreecommitdiff
path: root/core/java/android/util/ByteStringUtils.java
diff options
context:
space:
mode:
authorMark Rathjen <mrathjen@google.com>2017-01-11 18:49:56 -0800
committerMark Rathjen <mrathjen@google.com>2017-01-17 11:22:07 -0800
commit5514fb7aba781d8eabbbfc27a5d27a6b3a447b40 (patch)
tree59e6d86d0cb33b56576fd6bdb60d45cdb6207e00 /core/java/android/util/ByteStringUtils.java
parentb11f148145e9174e560face0ed5bee1cad69666e (diff)
SSAID Migration to be Per App/User Unique Values.
SSAID is currently shared across all applications for each user on the device, giving developers the ability to track users across multiple applications. Using SSAID for tracking is an abuse of the original intention of the SSAID and has inherent privacy concerns. This change will make the SSAID unique per application, per user on a device. To not affect applications installed prior to this change they will retain the legacy SSAID value until uninstalled and reinstalled again. Across subsequent installations the application will receive the same SSAID as long as the package name and signature remain consistent. Tested manually the following cases: - App retains the legacy sssaid after OTA. - App gets a new ssaid upon post-OTA installation. - App retrieves same ssaid across post-OTA unistall/reinstalls. - Different Apps receive different ssaids. - Factory reset removes ssaid data and generates a different ssaid after App install. - System retains legacy ssaid. Bug: 30979321 Test: CTS tests passed, Manual testing passed Change-Id: I4acc190c14ec249e6365e05e7943148ed6f17f71
Diffstat (limited to 'core/java/android/util/ByteStringUtils.java')
-rw-r--r--core/java/android/util/ByteStringUtils.java82
1 files changed, 82 insertions, 0 deletions
diff --git a/core/java/android/util/ByteStringUtils.java b/core/java/android/util/ByteStringUtils.java
new file mode 100644
index 000000000000..7103e6da0625
--- /dev/null
+++ b/core/java/android/util/ByteStringUtils.java
@@ -0,0 +1,82 @@
+/*
+ * Copyright (C) 2017 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 android.util;
+
+/**
+ * A utility class for common byte array to hex string operations and vise versa.
+ *
+ * @hide
+ */
+public final class ByteStringUtils {
+ private final static char[] HEX_ARRAY = "0123456789ABCDEF".toCharArray();
+
+ private ByteStringUtils() {
+ /* hide constructor */
+ }
+
+ /**
+ * Returns the hex encoded string representation of bytes.
+ * @param bytes Byte array to encode.
+ * @return Hex encoded string representation of bytes.
+ */
+ public static String toString(byte[] bytes) {
+ if (bytes == null || bytes.length == 0 || bytes.length % 2 != 0) {
+ return null;
+ }
+
+ final int byteLength = bytes.length;
+ final int charCount = 2 * byteLength;
+ final char[] chars = new char[charCount];
+
+ for (int i = 0; i < byteLength; i++) {
+ final int byteHex = bytes[i] & 0xFF;
+ chars[i * 2] = HEX_ARRAY[byteHex >>> 4];
+ chars[i * 2 + 1] = HEX_ARRAY[byteHex & 0x0F];
+ }
+ return new String(chars);
+ }
+
+ /**
+ * Returns the decoded byte array representation of str.
+ * @param str Hex encoded string to decode.
+ * @return Decoded byte array representation of str.
+ */
+ public static byte[] toByteArray(String str) {
+ if (str == null || str.length() == 0 || str.length() % 2 != 0) {
+ return null;
+ }
+
+ final char[] chars = str.toCharArray();
+ final int charLength = chars.length;
+ final byte[] bytes = new byte[charLength / 2];
+
+ for (int i = 0; i < bytes.length; i++) {
+ bytes[i] =
+ (byte)(((getIndex(chars[i * 2]) << 4) & 0xF0) | (getIndex(chars[i * 2 + 1]) & 0x0F));
+ }
+ return bytes;
+ }
+
+ private static int getIndex(char c) {
+ for (int i = 0; i < HEX_ARRAY.length; i++) {
+ if (HEX_ARRAY[i] == c) {
+ return i;
+ }
+ }
+ return -1;
+ }
+}