Debian Codegraph @

core/java/android/view/selectiontoolbar/SelectionToolbarManager.java

raw symbols SCIP
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
17 package android.view.selectiontoolbar;
18
19 import android.annotation.NonNull;
20 import android.annotation.SystemService;
21 import android.content.Context;
22 import android.os.RemoteException;
23 import android.provider.DeviceConfig;
24
25 import java.util.Objects;
26
27 /**
28 * The {@link SelectionToolbarManager} class provides ways for apps to control the
29 * selection toolbar.
30 *
31 * @hide
32 */
33 @SystemService(Context.SELECTION_TOOLBAR_SERVICE)
34 public final class SelectionToolbarManager {
35
36 private static final String TAG = "SelectionToolbar";
37
38 /**
39 * The tag which uses for enabling debug log dump. To enable it, we can use command "adb shell
40 * setprop log.tag.UiTranslation DEBUG".
41 */
42 public static final String LOG_TAG = "SelectionToolbar";
43
44 /**
45 * Whether system selection toolbar is enabled.
46 */
47 private static final String REMOTE_SELECTION_TOOLBAR_ENABLED =
48 "remote_selection_toolbar_enabled";
49
50 /**
51 * Used to mark a toolbar that has no toolbar token id.
52 */
53 public static final long NO_TOOLBAR_ID = 0;
54
55 /**
56 * The error code that do not allow to create multiple toolbar.
57 */
58 public static final int ERROR_DO_NOT_ALLOW_MULTIPLE_TOOL_BAR = 1;
59
60 @NonNull
61 private final Context mContext;
62 private final ISelectionToolbarManager mService;
63
64 public SelectionToolbarManager(@NonNull Context context,
65 @NonNull ISelectionToolbarManager service) {
66 mContext = Objects.requireNonNull(context);
67 mService = service;
68 }
69
70 /**
71 * Request to show selection toolbar for a given View.
72 */
73 public void showToolbar(@NonNull ShowInfo showInfo,
74 @NonNull ISelectionToolbarCallback callback) {
75 try {
76 Objects.requireNonNull(showInfo);
77 Objects.requireNonNull(callback);
78 mService.showToolbar(showInfo, callback, mContext.getUserId());
79 } catch (RemoteException e) {
80 throw e.rethrowFromSystemServer();
81 }
82 }
83
84 /**
85 * Request to hide selection toolbar.
86 */
87 public void hideToolbar(long widgetToken) {
88 try {
89 mService.hideToolbar(widgetToken, mContext.getUserId());
90 } catch (RemoteException e) {
91 throw e.rethrowFromSystemServer();
92 }
93 }
94
95 /**
96 * Dismiss to dismiss selection toolbar.
97 */
98 public void dismissToolbar(long widgetToken) {
99 try {
100 mService.dismissToolbar(widgetToken, mContext.getUserId());
101 } catch (RemoteException e) {
102 throw e.rethrowFromSystemServer();
103 }
104 }
105
106 private boolean isRemoteSelectionToolbarEnabled() {
107 return DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_SELECTION_TOOLBAR,
108 REMOTE_SELECTION_TOOLBAR_ENABLED, false);
109 }
110
111 /**
112 * Returns {@code true} if remote render selection toolbar enabled, otherwise
113 * returns {@code false}.
114 */
115 public static boolean isRemoteSelectionToolbarEnabled(Context context) {
116 SelectionToolbarManager manager = context.getSystemService(SelectionToolbarManager.class);
117 if (manager != null) {
118 return manager.isRemoteSelectionToolbarEnabled();
119 }
120 return false;
121 }
122 }