diff options
author | junyulai <junyulai@google.com> | 2021-01-29 20:35:10 +0800 |
---|---|---|
committer | junyulai <junyulai@google.com> | 2021-02-03 11:48:07 +0800 |
commit | 178bc96fdde27f8322d0e15581dd88132c912c0f (patch) | |
tree | 4a67a41b3559cf77b634efa72fd6f2da88475afe /common/framework | |
parent | b062f94b3b2eae39e8ce845aab12d5a9a0a71b48 (diff) | |
download | net-178bc96fdde27f8322d0e15581dd88132c912c0f.tar.gz |
[FUI21.1] Create NetworkIdentityUtils class
This patch creates a class in the static lib that contains utils
of NetworkIdentity.
Test: atest NetworkIdentityUtilsTest
Bug: 174123988
Change-Id: I6f0780190017b5eef3312b764107ac1f00e06833
Diffstat (limited to 'common/framework')
-rw-r--r-- | common/framework/com/android/net/module/util/NetworkIdentityUtils.java | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/common/framework/com/android/net/module/util/NetworkIdentityUtils.java b/common/framework/com/android/net/module/util/NetworkIdentityUtils.java new file mode 100644 index 00000000..94e60178 --- /dev/null +++ b/common/framework/com/android/net/module/util/NetworkIdentityUtils.java @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2021 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.net.module.util; + +import android.annotation.NonNull; +import android.annotation.Nullable; + +/** + * Utilities to examine {@link android.net.NetworkIdentity}. + */ +public class NetworkIdentityUtils { + /** + * Scrub given IMSI on production builds. + */ + @NonNull + public static String scrubSubscriberId(@Nullable String subscriberId) { + if (subscriberId != null) { + // TODO: parse this as MCC+MNC instead of hard-coding + return subscriberId.substring(0, Math.min(6, subscriberId.length())) + "..."; + } else { + return "null"; + } + } + + /** + * Scrub given IMSI on production builds. + */ + @Nullable + public static String[] scrubSubscriberIds(@Nullable String[] subscriberIds) { + if (subscriberIds == null) return null; + final String[] res = new String[subscriberIds.length]; + for (int i = 0; i < res.length; i++) { + res[i] = scrubSubscriberId(subscriberIds[i]); + } + return res; + } +} |