| 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 android.annotation.Nullable; |
| 20 |
import android.app.ActivityThread; |
| 21 |
import android.content.Context; |
| 22 |
import android.os.RemoteException; |
| 23 |
import android.os.ServiceManager; |
| 24 |
import android.os.ServiceManager.ServiceNotFoundException; |
| 25 |
import android.util.Log; |
| 26 |
import android.util.proto.ProtoOutputStream; |
| 27 |
import android.view.inputmethod.InputMethodManager; |
| 28 |
|
| 29 |
import com.android.internal.view.IInputMethodManager; |
| 30 |
|
| 31 |
import java.io.PrintWriter; |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
public abstract class ImeTracing { |
| 40 |
|
| 41 |
static final String TAG = "imeTracing"; |
| 42 |
public static final String PROTO_ARG = "--proto-com-android-imetracing"; |
| 43 |
|
| 44 |
|
| 45 |
public static final int IME_TRACING_FROM_CLIENT = 0; |
| 46 |
public static final int IME_TRACING_FROM_IMS = 1; |
| 47 |
public static final int IME_TRACING_FROM_IMMS = 2; |
| 48 |
|
| 49 |
private static ImeTracing sInstance; |
| 50 |
static boolean sEnabled = false; |
| 51 |
IInputMethodManager mService; |
| 52 |
|
| 53 |
protected boolean mDumpInProgress; |
| 54 |
protected final Object mDumpInProgressLock = new Object(); |
| 55 |
|
| 56 |
ImeTracing() throws ServiceNotFoundException { |
| 57 |
mService = IInputMethodManager.Stub.asInterface( |
| 58 |
ServiceManager.getServiceOrThrow(Context.INPUT_METHOD_SERVICE)); |
| 59 |
} |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
public static ImeTracing getInstance() { |
| 69 |
if (sInstance == null) { |
| 70 |
try { |
| 71 |
sInstance = isSystemProcess() |
| 72 |
? new ImeTracingServerImpl() : new ImeTracingClientImpl(); |
| 73 |
} catch (RemoteException | ServiceNotFoundException e) { |
| 74 |
Log.e(TAG, "Exception while creating ImeTracing instance", e); |
| 75 |
} |
| 76 |
} |
| 77 |
return sInstance; |
| 78 |
} |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
public void sendToService(byte[] protoDump, int source, String where) throws RemoteException { |
| 90 |
mService.startProtoDump(protoDump, source, where); |
| 91 |
} |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
public final void startImeTrace() { |
| 97 |
try { |
| 98 |
mService.startImeTrace(); |
| 99 |
} catch (RemoteException e) { |
| 100 |
Log.e(TAG, "Could not start ime trace." + e); |
| 101 |
} |
| 102 |
} |
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
public final void stopImeTrace() { |
| 108 |
try { |
| 109 |
mService.stopImeTrace(); |
| 110 |
} catch (RemoteException e) { |
| 111 |
Log.e(TAG, "Could not stop ime trace." + e); |
| 112 |
} |
| 113 |
} |
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
public abstract void addToBuffer(ProtoOutputStream proto, int source); |
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
public abstract void triggerClientDump(String where, InputMethodManager immInstance, |
| 128 |
@Nullable byte[] icProto); |
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
@FunctionalInterface |
| 134 |
public interface ServiceDumper { |
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
void dumpToProto(ProtoOutputStream proto, @Nullable byte[] icProto); |
| 143 |
} |
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
public abstract void triggerServiceDump(String where, ServiceDumper dumper, |
| 154 |
@Nullable byte[] icProto); |
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
public abstract void triggerManagerServiceDump(String where); |
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
public void saveForBugreport(@Nullable PrintWriter pw) { |
| 170 |
|
| 171 |
} |
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
public void setEnabled(boolean enabled) { |
| 179 |
sEnabled = enabled; |
| 180 |
} |
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
public boolean isEnabled() { |
| 186 |
return sEnabled; |
| 187 |
} |
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
public boolean isAvailable() { |
| 193 |
return mService != null; |
| 194 |
} |
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
public abstract void startTrace(@Nullable PrintWriter pw); |
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
public abstract void stopTrace(@Nullable PrintWriter pw); |
| 209 |
|
| 210 |
private static boolean isSystemProcess() { |
| 211 |
return ActivityThread.isSystem(); |
| 212 |
} |
| 213 |
|
| 214 |
protected void logAndPrintln(@Nullable PrintWriter pw, String msg) { |
| 215 |
Log.i(TAG, msg); |
| 216 |
if (pw != null) { |
| 217 |
pw.println(msg); |
| 218 |
pw.flush(); |
| 219 |
} |
| 220 |
} |
| 221 |
|
| 222 |
} |