• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.android.timezone.location.common;
17 
18 import androidx.annotation.NonNull;
19 import androidx.annotation.Nullable;
20 
21 /**
22  * An interface for objects that could contain user or other sensitive information. Implementers
23  * must ensure that {@link #toString()} can be used for the default / redacted / log-safe form, and
24  * {@link #toPiiString()} is provided for the form that can contains sensitive information.
25  *
26  * <p>The purpose of this interface is to ensure Java's default {@link #toString()} behavior is safe
27  * to use by default in logs, exception messages, etc. See {@link PiiLoggables} for support methods.
28  */
29 public interface PiiLoggable {
30 
31     /** Used for logs, should be implemented to be log-safe, not containing PII. */
32     @Override
toString()33     @NonNull String toString();
34 
35     /** Like {@link #toString()} but can include PII for debugging. */
toPiiString()36     @NonNull String toPiiString();
37 
38     /**
39      * Returns a string representation of {@code value}. Operates like {@link
40      * String#valueOf(Object)}} but calls {@link PiiLoggable#toPiiString()} instead of
41      * {@link Object#toString()}.
42      */
toPiiString(@ullable PiiLoggable value)43     static String toPiiString(@Nullable PiiLoggable value) {
44         return value == null ? PiiLoggables.NULL_STRING : value.toPiiString();
45     }
46 }
47