Skip to content

Commit 73d6a82

Browse files
author
Dianne Hackborn
committed
Work on issue #17656716: Unhandled exception in Window Manager
Remove the checks for large parcel sizes. Those were triggering, and identifyng the area of the problem, but also cause a lot of trouble by making the unsafe deadlocky code there much more likely to deadlock. Add logging for strict mode IPCs, since those seem to be the problem. Only log when things look bad. Also add a log when battery stats are reset, to diagnose why they are getting reset when they shouldn't be. Change-Id: I588c858fb8d8c45f3c9c164ae2de9ae01547b304
1 parent 9eef5bf commit 73d6a82

4 files changed

Lines changed: 37 additions & 1 deletion

File tree

core/java/android/app/ApplicationErrorReport.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import android.os.SystemProperties;
2828
import android.provider.Settings;
2929
import android.util.Printer;
30+
import android.util.Slog;
3031
import com.android.internal.util.FastPrintWriter;
3132

3233
import java.io.PrintWriter;
@@ -378,13 +379,24 @@ public CrashInfo(Parcel in) {
378379
* Save a CrashInfo instance to a parcel.
379380
*/
380381
public void writeToParcel(Parcel dest, int flags) {
382+
int start = dest.dataPosition();
381383
dest.writeString(exceptionClassName);
382384
dest.writeString(exceptionMessage);
383385
dest.writeString(throwFileName);
384386
dest.writeString(throwClassName);
385387
dest.writeString(throwMethodName);
386388
dest.writeInt(throwLineNumber);
387389
dest.writeString(stackTrace);
390+
int total = dest.dataPosition()-start;
391+
if (total > 100*1024) {
392+
Slog.d("Error", "ERR: exClass=" + exceptionClassName);
393+
Slog.d("Error", "ERR: exMsg=" + exceptionMessage);
394+
Slog.d("Error", "ERR: file=" + throwFileName);
395+
Slog.d("Error", "ERR: class=" + throwClassName);
396+
Slog.d("Error", "ERR: method=" + throwMethodName + " line=" + throwLineNumber);
397+
Slog.d("Error", "ERR: stack=" + stackTrace);
398+
Slog.d("Error", "ERR: TOTAL BYTES WRITTEN: " + (dest.dataPosition()-start));
399+
}
388400
}
389401

390402
/**

core/java/android/os/Binder.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public class Binder implements IBinder {
4949
* of classes can potentially create leaks.
5050
*/
5151
private static final boolean FIND_POTENTIAL_LEAKS = false;
52+
private static final boolean CHECK_PARCEL_SIZE = false;
5253
static final String TAG = "Binder";
5354

5455
/**
@@ -388,7 +389,7 @@ protected void finalize() throws Throwable {
388389
}
389390

390391
static void checkParcel(IBinder obj, int code, Parcel parcel, String msg) {
391-
if (parcel.dataSize() >= 800*1024) {
392+
if (CHECK_PARCEL_SIZE && parcel.dataSize() >= 800*1024) {
392393
// Trying to send > 800k, this is way too much
393394
StringBuilder sb = new StringBuilder();
394395
sb.append(msg);

core/java/android/os/StrictMode.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import android.util.Log;
2929
import android.util.Printer;
3030
import android.util.Singleton;
31+
import android.util.Slog;
3132
import android.view.IWindowManager;
3233

3334
import com.android.internal.os.RuntimeInit;
@@ -40,6 +41,7 @@
4041
import java.io.PrintWriter;
4142
import java.io.StringWriter;
4243
import java.util.ArrayList;
44+
import java.util.Arrays;
4345
import java.util.HashMap;
4446
import java.util.Map;
4547
import java.util.concurrent.atomic.AtomicInteger;
@@ -1688,7 +1690,13 @@ public static void onVmPolicyViolation(String message, Throwable originStack) {
16881690
} else {
16891691
p.writeInt(violations.size());
16901692
for (int i = 0; i < violations.size(); ++i) {
1693+
int start = p.dataPosition();
16911694
violations.get(i).writeToParcel(p, 0 /* unused flags? */);
1695+
int size = p.dataPosition()-start;
1696+
if (size > 100*1024) {
1697+
Slog.d(TAG, "Wrote violation #" + i + " of " + violations.size() + ": "
1698+
+ (p.dataPosition()-start) + " bytes");
1699+
}
16921700
}
16931701
if (LOG_V) Log.d(TAG, "wrote violations to response parcel; num=" + violations.size());
16941702
violations.clear(); // somewhat redundant, as we're about to null the threadlocal
@@ -2176,6 +2184,7 @@ public ViolationInfo(Parcel in, boolean unsetGatheringBit) {
21762184
*/
21772185
public void writeToParcel(Parcel dest, int flags) {
21782186
crashInfo.writeToParcel(dest, flags);
2187+
int start = dest.dataPosition();
21792188
dest.writeInt(policy);
21802189
dest.writeInt(durationMillis);
21812190
dest.writeInt(violationNumThisLoop);
@@ -2184,6 +2193,17 @@ public void writeToParcel(Parcel dest, int flags) {
21842193
dest.writeLong(numInstances);
21852194
dest.writeString(broadcastIntentAction);
21862195
dest.writeStringArray(tags);
2196+
int total = dest.dataPosition()-start;
2197+
if (total > 100*1024) {
2198+
Slog.d(TAG, "VIO: policy=" + policy + " dur=" + durationMillis
2199+
+ " numLoop=" + violationNumThisLoop
2200+
+ " anim=" + numAnimationsRunning
2201+
+ " uptime=" + violationUptimeMillis
2202+
+ " numInst=" + numInstances);
2203+
Slog.d(TAG, "VIO: action=" + broadcastIntentAction);
2204+
Slog.d(TAG, "VIO: tags=" + Arrays.toString(tags));
2205+
Slog.d(TAG, "VIO: TOTAL BYTES WRITTEN: " + (dest.dataPosition()-start));
2206+
}
21872207
}
21882208

21892209

core/java/com/android/internal/os/BatteryStatsImpl.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6748,6 +6748,9 @@ void setOnBatteryLocked(final long mSecRealtime, final long mSecUptime, final bo
67486748
|| getLowDischargeAmountSinceCharge() >= 60)
67496749
|| (getHighDischargeAmountSinceCharge() >= 60
67506750
&& mHistoryBuffer.dataSize() >= MAX_HISTORY_BUFFER)) {
6751+
Slog.i(TAG, "Resetting battery stats: level=" + level + " status=" + oldStatus
6752+
+ " lowAmount=" + getLowDischargeAmountSinceCharge()
6753+
+ " highAmount=" + getHighDischargeAmountSinceCharge());
67516754
// Before we write, collect a snapshot of the final aggregated
67526755
// stats to be reported in the next checkin. Only do this if we have
67536756
// a sufficient amount of data to make it interesting.

0 commit comments

Comments
 (0)