|
1 | 1 | package com.genymobile.scrcpy;
|
2 | 2 |
|
| 3 | +import com.genymobile.scrcpy.wrappers.ClipboardManager; |
3 | 4 | import com.genymobile.scrcpy.wrappers.ContentProvider;
|
4 | 5 | import com.genymobile.scrcpy.wrappers.InputManager;
|
5 | 6 | import com.genymobile.scrcpy.wrappers.ServiceManager;
|
@@ -80,23 +81,28 @@ public void onRotationChanged(int rotation) {
|
80 | 81 |
|
81 | 82 | if (options.getControl()) {
|
82 | 83 | // If control is enabled, synchronize Android clipboard to the computer automatically
|
83 |
| - serviceManager.getClipboardManager().addPrimaryClipChangedListener(new IOnPrimaryClipChangedListener.Stub() { |
84 |
| - @Override |
85 |
| - public void dispatchPrimaryClipChanged() { |
86 |
| - if (isSettingClipboard.get()) { |
87 |
| - // This is a notification for the change we are currently applying, ignore it |
88 |
| - return; |
89 |
| - } |
90 |
| - synchronized (Device.this) { |
91 |
| - if (clipboardListener != null) { |
92 |
| - String text = getClipboardText(); |
93 |
| - if (text != null) { |
94 |
| - clipboardListener.onClipboardTextChanged(text); |
| 84 | + ClipboardManager clipboardManager = serviceManager.getClipboardManager(); |
| 85 | + if (clipboardManager != null) { |
| 86 | + clipboardManager.addPrimaryClipChangedListener(new IOnPrimaryClipChangedListener.Stub() { |
| 87 | + @Override |
| 88 | + public void dispatchPrimaryClipChanged() { |
| 89 | + if (isSettingClipboard.get()) { |
| 90 | + // This is a notification for the change we are currently applying, ignore it |
| 91 | + return; |
| 92 | + } |
| 93 | + synchronized (Device.this) { |
| 94 | + if (clipboardListener != null) { |
| 95 | + String text = getClipboardText(); |
| 96 | + if (text != null) { |
| 97 | + clipboardListener.onClipboardTextChanged(text); |
| 98 | + } |
95 | 99 | }
|
96 | 100 | }
|
97 | 101 | }
|
98 |
| - } |
99 |
| - }); |
| 102 | + }); |
| 103 | + } else { |
| 104 | + Ln.w("No clipboard manager, copy-paste between device and computer will not work"); |
| 105 | + } |
100 | 106 | }
|
101 | 107 |
|
102 | 108 | if ((displayInfoFlags & DisplayInfo.FLAG_SUPPORTS_PROTECTED_BUFFERS) == 0) {
|
@@ -199,16 +205,24 @@ public void collapsePanels() {
|
199 | 205 | }
|
200 | 206 |
|
201 | 207 | public String getClipboardText() {
|
202 |
| - CharSequence s = serviceManager.getClipboardManager().getText(); |
| 208 | + ClipboardManager clipboardManager = serviceManager.getClipboardManager(); |
| 209 | + if (clipboardManager == null) { |
| 210 | + return null; |
| 211 | + } |
| 212 | + CharSequence s = clipboardManager.getText(); |
203 | 213 | if (s == null) {
|
204 | 214 | return null;
|
205 | 215 | }
|
206 | 216 | return s.toString();
|
207 | 217 | }
|
208 | 218 |
|
209 | 219 | public boolean setClipboardText(String text) {
|
| 220 | + ClipboardManager clipboardManager = serviceManager.getClipboardManager(); |
| 221 | + if (clipboardManager == null) { |
| 222 | + return false; |
| 223 | + } |
210 | 224 | isSettingClipboard.set(true);
|
211 |
| - boolean ok = serviceManager.getClipboardManager().setText(text); |
| 225 | + boolean ok = clipboardManager.setText(text); |
212 | 226 | isSettingClipboard.set(false);
|
213 | 227 | return ok;
|
214 | 228 | }
|
|
0 commit comments