Debian Codegraph @

core/java/com/android/internal/widget/InlinePresentationStyleUtils.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2020 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
17 package com.android.internal.widget;
18
19 import android.annotation.NonNull;
20 import android.annotation.Nullable;
21 import android.os.Bundle;
22 import android.os.IBinder;
23
24 import java.util.Objects;
25 import java.util.Set;
26
27 /**
28 * Utility methods relating to inline presentation UI.
29 */
30 public final class InlinePresentationStyleUtils {
31
32 /**
33 * Returns true if the two bundles are deeply equal.
34 *
35 * Each input bundle may represent a UI style in the
36 * {@link android.widget.inline.InlinePresentationSpec} or the extra
37 * request info in the {@link android.view.inputmethod.InlineSuggestionsRequest}
38 *
39 * Note: this method should not be called in the framework process for security reasons.
40 */
41 public static boolean bundleEquals(@NonNull Bundle bundle1, @NonNull Bundle bundle2) {
42 if (bundle1 == bundle2) {
43 return true;
44 }
45 if (bundle1 == null || bundle2 == null) {
46 return false;
47 }
48 if (bundle1.size() != bundle2.size()) {
49 return false;
50 }
51 Set<String> keys = bundle1.keySet();
52 for (String key : keys) {
53 Object value1 = bundle1.get(key);
54 Object value2 = bundle2.get(key);
55 final boolean equal = value1 instanceof Bundle && value2 instanceof Bundle
56 ? bundleEquals((Bundle) value1, (Bundle) value2)
57 : Objects.equals(value1, value2);
58 if (!equal) {
59 return false;
60 }
61 }
62 return true;
63 }
64
65 /**
66 * Removes remote objects from the bundle.
67 */
68 public static void filterContentTypes(@Nullable Bundle bundle) {
69 if (bundle == null) {
70 return;
71 }
72
73 for (String key : bundle.keySet()) {
74 Object o = bundle.get(key);
75
76 if (o instanceof Bundle) {
77 filterContentTypes((Bundle) o);
78 } else if (o instanceof IBinder) {
79 bundle.remove(key);
80 }
81 }
82 }
83
84 /**
85 * Private ctor to avoid constructing the class.
86 */
87 private InlinePresentationStyleUtils() {
88 }
89 }