| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package com.android.internal.inputmethod; |
| 18 |
|
| 19 |
import static android.view.inputmethod.InputConnectionCallProto.GET_CURSOR_CAPS_MODE; |
| 20 |
import static android.view.inputmethod.InputConnectionCallProto.GET_EXTRACTED_TEXT; |
| 21 |
import static android.view.inputmethod.InputConnectionCallProto.GET_SELECTED_TEXT; |
| 22 |
import static android.view.inputmethod.InputConnectionCallProto.GET_SURROUNDING_TEXT; |
| 23 |
import static android.view.inputmethod.InputConnectionCallProto.GET_TEXT_AFTER_CURSOR; |
| 24 |
import static android.view.inputmethod.InputConnectionCallProto.GET_TEXT_BEFORE_CURSOR; |
| 25 |
import static android.view.inputmethod.InputConnectionCallProto.GetExtractedText.REQUEST; |
| 26 |
|
| 27 |
import android.annotation.IntRange; |
| 28 |
import android.annotation.NonNull; |
| 29 |
import android.annotation.Nullable; |
| 30 |
import android.util.proto.ProtoOutputStream; |
| 31 |
import android.view.inputmethod.ExtractedText; |
| 32 |
import android.view.inputmethod.ExtractedTextRequest; |
| 33 |
import android.view.inputmethod.InputConnectionCallProto.GetCursorCapsMode; |
| 34 |
import android.view.inputmethod.InputConnectionCallProto.GetExtractedText; |
| 35 |
import android.view.inputmethod.InputConnectionCallProto.GetSelectedText; |
| 36 |
import android.view.inputmethod.InputConnectionCallProto.GetSurroundingText; |
| 37 |
import android.view.inputmethod.InputConnectionCallProto.GetTextAfterCursor; |
| 38 |
import android.view.inputmethod.InputConnectionCallProto.GetTextBeforeCursor; |
| 39 |
import android.view.inputmethod.SurroundingText; |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
public final class InputConnectionProtoDumper { |
| 46 |
static final String TAG = "InputConnectionProtoDumper"; |
| 47 |
public static final boolean DUMP_TEXT = false; |
| 48 |
|
| 49 |
private InputConnectionProtoDumper() {} |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
@NonNull |
| 64 |
public static byte[] buildGetTextAfterCursorProto(@IntRange(from = 0) int length, int flags, |
| 65 |
@Nullable CharSequence result) { |
| 66 |
ProtoOutputStream proto = new ProtoOutputStream(); |
| 67 |
final long token = proto.start(GET_TEXT_AFTER_CURSOR); |
| 68 |
proto.write(GetTextAfterCursor.LENGTH, length); |
| 69 |
proto.write(GetTextAfterCursor.FLAGS, flags); |
| 70 |
if (result == null) { |
| 71 |
proto.write(GetTextAfterCursor.RESULT, "null result"); |
| 72 |
} else if (DUMP_TEXT) { |
| 73 |
proto.write(GetTextAfterCursor.RESULT, result.toString()); |
| 74 |
} |
| 75 |
proto.end(token); |
| 76 |
return proto.getBytes(); |
| 77 |
} |
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
@NonNull |
| 92 |
public static byte[] buildGetTextBeforeCursorProto(@IntRange(from = 0) int length, |
| 93 |
int flags, @Nullable CharSequence result) { |
| 94 |
ProtoOutputStream proto = new ProtoOutputStream(); |
| 95 |
final long token = proto.start(GET_TEXT_BEFORE_CURSOR); |
| 96 |
proto.write(GetTextBeforeCursor.LENGTH, length); |
| 97 |
proto.write(GetTextBeforeCursor.FLAGS, flags); |
| 98 |
if (result == null) { |
| 99 |
proto.write(GetTextBeforeCursor.RESULT, "null result"); |
| 100 |
} else if (DUMP_TEXT) { |
| 101 |
proto.write(GetTextBeforeCursor.RESULT, result.toString()); |
| 102 |
} |
| 103 |
proto.end(token); |
| 104 |
return proto.getBytes(); |
| 105 |
} |
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
@NonNull |
| 121 |
public static byte[] buildGetSelectedTextProto(int flags, @Nullable CharSequence result) { |
| 122 |
ProtoOutputStream proto = new ProtoOutputStream(); |
| 123 |
final long token = proto.start(GET_SELECTED_TEXT); |
| 124 |
proto.write(GetSelectedText.FLAGS, flags); |
| 125 |
if (result == null) { |
| 126 |
proto.write(GetSelectedText.RESULT, "null result"); |
| 127 |
} else if (DUMP_TEXT) { |
| 128 |
proto.write(GetSelectedText.RESULT, result.toString()); |
| 129 |
} |
| 130 |
proto.end(token); |
| 131 |
return proto.getBytes(); |
| 132 |
} |
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
@NonNull |
| 151 |
public static byte[] buildGetSurroundingTextProto(@IntRange(from = 0) int beforeLength, |
| 152 |
@IntRange(from = 0) int afterLength, int flags, @Nullable SurroundingText result) { |
| 153 |
ProtoOutputStream proto = new ProtoOutputStream(); |
| 154 |
final long token = proto.start(GET_SURROUNDING_TEXT); |
| 155 |
proto.write(GetSurroundingText.BEFORE_LENGTH, beforeLength); |
| 156 |
proto.write(GetSurroundingText.AFTER_LENGTH, afterLength); |
| 157 |
proto.write(GetSurroundingText.FLAGS, flags); |
| 158 |
if (result == null) { |
| 159 |
final long token_result = proto.start(GetSurroundingText.RESULT); |
| 160 |
proto.write(GetSurroundingText.SurroundingText.TEXT, "null result"); |
| 161 |
proto.end(token_result); |
| 162 |
} else if (DUMP_TEXT) { |
| 163 |
final long token_result = proto.start(GetSurroundingText.RESULT); |
| 164 |
proto.write(GetSurroundingText.SurroundingText.TEXT, result.getText().toString()); |
| 165 |
proto.write(GetSurroundingText.SurroundingText.SELECTION_START, |
| 166 |
result.getSelectionStart()); |
| 167 |
proto.write(GetSurroundingText.SurroundingText.SELECTION_END, |
| 168 |
result.getSelectionEnd()); |
| 169 |
proto.write(GetSurroundingText.SurroundingText.OFFSET, result.getOffset()); |
| 170 |
proto.end(token_result); |
| 171 |
} |
| 172 |
proto.end(token); |
| 173 |
return proto.getBytes(); |
| 174 |
} |
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
@NonNull |
| 187 |
public static byte[] buildGetCursorCapsModeProto(int reqModes, int result) { |
| 188 |
ProtoOutputStream proto = new ProtoOutputStream(); |
| 189 |
final long token = proto.start(GET_CURSOR_CAPS_MODE); |
| 190 |
proto.write(GetCursorCapsMode.REQ_MODES, reqModes); |
| 191 |
if (DUMP_TEXT) { |
| 192 |
proto.write(GetCursorCapsMode.RESULT, result); |
| 193 |
} |
| 194 |
proto.end(token); |
| 195 |
return proto.getBytes(); |
| 196 |
} |
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
@NonNull |
| 215 |
public static byte[] buildGetExtractedTextProto(@NonNull ExtractedTextRequest |
| 216 |
request, int flags, @Nullable ExtractedText result) { |
| 217 |
ProtoOutputStream proto = new ProtoOutputStream(); |
| 218 |
final long token = proto.start(GET_EXTRACTED_TEXT); |
| 219 |
final long token_request = proto.start(REQUEST); |
| 220 |
proto.write(GetExtractedText.ExtractedTextRequest.TOKEN, request.token); |
| 221 |
proto.write(GetExtractedText.ExtractedTextRequest.FLAGS, request.flags); |
| 222 |
proto.write(GetExtractedText.ExtractedTextRequest.HINT_MAX_LINES, request.hintMaxLines); |
| 223 |
proto.write(GetExtractedText.ExtractedTextRequest.HINT_MAX_CHARS, request.hintMaxChars); |
| 224 |
proto.end(token_request); |
| 225 |
proto.write(GetExtractedText.FLAGS, flags); |
| 226 |
if (result == null) { |
| 227 |
proto.write(GetExtractedText.RESULT, "null result"); |
| 228 |
} else if (DUMP_TEXT) { |
| 229 |
proto.write(GetExtractedText.RESULT, result.text.toString()); |
| 230 |
} |
| 231 |
proto.end(token); |
| 232 |
return proto.getBytes(); |
| 233 |
} |
| 234 |
} |