Pull out library needed for Notification CTS test.

Bug: 152031499
Test: atest NotificationManagerServiceTest
Change-Id: I6292482b3650709149ff06249ba4a3704289ee46
diff --git a/services/core/java/com/android/server/notification/NotificationChannelLogger.java b/services/core/java/com/android/server/notification/NotificationChannelLogger.java
index 83f4ebb..a7b1877 100644
--- a/services/core/java/com/android/server/notification/NotificationChannelLogger.java
+++ b/services/core/java/com/android/server/notification/NotificationChannelLogger.java
@@ -184,14 +184,14 @@
      * @return Small hash of the channel ID, if present, or 0 otherwise.
      */
     static int getIdHash(@NonNull NotificationChannel channel) {
-        return NotificationRecordLogger.smallHash(channel.getId());
+        return SmallHash.hash(channel.getId());
     }
 
     /**
      * @return Small hash of the channel ID, if present, or 0 otherwise.
      */
     static int getIdHash(@NonNull NotificationChannelGroup group) {
-        return NotificationRecordLogger.smallHash(group.getId());
+        return SmallHash.hash(group.getId());
     }
 
     /**
diff --git a/services/core/java/com/android/server/notification/NotificationRecordLogger.java b/services/core/java/com/android/server/notification/NotificationRecordLogger.java
index 6c833f9..eba5730 100644
--- a/services/core/java/com/android/server/notification/NotificationRecordLogger.java
+++ b/services/core/java/com/android/server/notification/NotificationRecordLogger.java
@@ -359,43 +359,24 @@
          * @return Small hash of the notification ID, and tag (if present).
          */
         int getNotificationIdHash() {
-            return smallHash(Objects.hashCode(r.getSbn().getTag()) ^ r.getSbn().getId());
+            return SmallHash.hash(Objects.hashCode(r.getSbn().getTag()) ^ r.getSbn().getId());
         }
 
         /**
          * @return Small hash of the channel ID, if present, or 0 otherwise.
          */
         int getChannelIdHash() {
-            return smallHash(r.getSbn().getNotification().getChannelId());
+            return SmallHash.hash(r.getSbn().getNotification().getChannelId());
         }
 
         /**
          * @return Small hash of the group ID, respecting group override if present. 0 otherwise.
          */
         int getGroupIdHash() {
-            return smallHash(r.getSbn().getGroup());
+            return SmallHash.hash(r.getSbn().getGroup());
         }
 
     }
 
-    // "Small" hashes will be in the range [0, MAX_HASH).
-    int MAX_HASH = (1 << 13);
-
-    /**
-     * Maps in to the range [0, MAX_HASH), keeping similar values distinct.
-     * @param in An arbitrary integer.
-     * @return in mod MAX_HASH, signs chosen to stay in the range [0, MAX_HASH).
-     */
-    static int smallHash(int in) {
-        return Math.floorMod(in, MAX_HASH);
-    }
-
-    /**
-     * @return Small hash of the string, if non-null, or 0 otherwise.
-     */
-    static int smallHash(@Nullable String in) {
-        return smallHash(Objects.hashCode(in));
-    }
-
 
 }
diff --git a/services/core/java/com/android/server/notification/SmallHash.java b/services/core/java/com/android/server/notification/SmallHash.java
new file mode 100644
index 0000000..4483a5b
--- /dev/null
+++ b/services/core/java/com/android/server/notification/SmallHash.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2020 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.server.notification;
+
+import java.util.Objects;
+
+/**
+ * A simple hash function for use in privacy-sensitive logging.  Few bits = lots of collisions.
+ * See {@link NotificationRecordLogger}.
+ */
+public class SmallHash {
+    // Hashes will be in the range [0, MAX_HASH).
+    public static final int MAX_HASH = (1 << 13);
+
+    /**
+     * @return Small hash of the string, if non-null, or 0 otherwise.
+     */
+    public static int hash(String in) {
+        return hash(Objects.hashCode(in));
+    }
+
+    /**
+     * Maps in to the range [0, MAX_HASH), keeping similar values distinct.
+     * @param in An arbitrary integer.
+     * @return in mod MAX_HASH, signs chosen to stay in the range [0, MAX_HASH).
+     */
+    public static int hash(int in) {
+        return Math.floorMod(in, MAX_HASH);
+    }
+}