| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.app.servertransaction; |
| 18 |
|
| 19 |
import static android.app.ActivityThread.DEBUG_MEMORY_TRIM; |
| 20 |
|
| 21 |
import android.app.ActivityClient; |
| 22 |
import android.app.ActivityThread.ActivityClientRecord; |
| 23 |
import android.os.Build; |
| 24 |
import android.os.Bundle; |
| 25 |
import android.os.PersistableBundle; |
| 26 |
import android.os.TransactionTooLargeException; |
| 27 |
import android.util.Log; |
| 28 |
import android.util.Slog; |
| 29 |
|
| 30 |
import com.android.internal.util.IndentingPrintWriter; |
| 31 |
|
| 32 |
import java.io.StringWriter; |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
public class PendingTransactionActions { |
| 43 |
private boolean mRestoreInstanceState; |
| 44 |
private boolean mCallOnPostCreate; |
| 45 |
private Bundle mOldState; |
| 46 |
private StopInfo mStopInfo; |
| 47 |
private boolean mReportRelaunchToWM; |
| 48 |
|
| 49 |
public PendingTransactionActions() { |
| 50 |
clear(); |
| 51 |
} |
| 52 |
|
| 53 |
|
| 54 |
public void clear() { |
| 55 |
mRestoreInstanceState = false; |
| 56 |
mCallOnPostCreate = false; |
| 57 |
mOldState = null; |
| 58 |
mStopInfo = null; |
| 59 |
} |
| 60 |
|
| 61 |
|
| 62 |
public boolean shouldRestoreInstanceState() { |
| 63 |
return mRestoreInstanceState; |
| 64 |
} |
| 65 |
|
| 66 |
public void setRestoreInstanceState(boolean restoreInstanceState) { |
| 67 |
mRestoreInstanceState = restoreInstanceState; |
| 68 |
} |
| 69 |
|
| 70 |
|
| 71 |
public boolean shouldCallOnPostCreate() { |
| 72 |
return mCallOnPostCreate; |
| 73 |
} |
| 74 |
|
| 75 |
public void setCallOnPostCreate(boolean callOnPostCreate) { |
| 76 |
mCallOnPostCreate = callOnPostCreate; |
| 77 |
} |
| 78 |
|
| 79 |
public Bundle getOldState() { |
| 80 |
return mOldState; |
| 81 |
} |
| 82 |
|
| 83 |
public void setOldState(Bundle oldState) { |
| 84 |
mOldState = oldState; |
| 85 |
} |
| 86 |
|
| 87 |
public StopInfo getStopInfo() { |
| 88 |
return mStopInfo; |
| 89 |
} |
| 90 |
|
| 91 |
public void setStopInfo(StopInfo stopInfo) { |
| 92 |
mStopInfo = stopInfo; |
| 93 |
} |
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
public boolean shouldReportRelaunchToWindowManager() { |
| 101 |
return mReportRelaunchToWM; |
| 102 |
} |
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
public void setReportRelaunchToWindowManager(boolean reportToWm) { |
| 110 |
mReportRelaunchToWM = reportToWm; |
| 111 |
} |
| 112 |
|
| 113 |
|
| 114 |
public static class StopInfo implements Runnable { |
| 115 |
private static final String TAG = "ActivityStopInfo"; |
| 116 |
|
| 117 |
private ActivityClientRecord mActivity; |
| 118 |
private Bundle mState; |
| 119 |
private PersistableBundle mPersistentState; |
| 120 |
private CharSequence mDescription; |
| 121 |
|
| 122 |
public void setActivity(ActivityClientRecord activity) { |
| 123 |
mActivity = activity; |
| 124 |
} |
| 125 |
|
| 126 |
public void setState(Bundle state) { |
| 127 |
mState = state; |
| 128 |
} |
| 129 |
|
| 130 |
public void setPersistentState(PersistableBundle persistentState) { |
| 131 |
mPersistentState = persistentState; |
| 132 |
} |
| 133 |
|
| 134 |
public void setDescription(CharSequence description) { |
| 135 |
mDescription = description; |
| 136 |
} |
| 137 |
|
| 138 |
private String collectBundleStates() { |
| 139 |
final StringWriter writer = new StringWriter(); |
| 140 |
final IndentingPrintWriter pw = new IndentingPrintWriter(writer, " "); |
| 141 |
pw.println("Bundle stats:"); |
| 142 |
Bundle.dumpStats(pw, mState); |
| 143 |
pw.println("PersistableBundle stats:"); |
| 144 |
Bundle.dumpStats(pw, mPersistentState); |
| 145 |
return writer.toString().stripTrailing(); |
| 146 |
} |
| 147 |
|
| 148 |
@Override |
| 149 |
public void run() { |
| 150 |
|
| 151 |
try { |
| 152 |
if (DEBUG_MEMORY_TRIM) Slog.v(TAG, "Reporting activity stopped: " + mActivity); |
| 153 |
|
| 154 |
ActivityClient.getInstance().activityStopped( |
| 155 |
mActivity.token, mState, mPersistentState, mDescription); |
| 156 |
} catch (RuntimeException runtimeException) { |
| 157 |
|
| 158 |
final String bundleStats = collectBundleStates(); |
| 159 |
|
| 160 |
RuntimeException ex = runtimeException; |
| 161 |
if (ex.getCause() instanceof TransactionTooLargeException) { |
| 162 |
|
| 163 |
|
| 164 |
final String message = ex.getMessage() + "\n" + bundleStats; |
| 165 |
ex = new RuntimeException(message, ex.getCause()); |
| 166 |
if (mActivity.packageInfo.getTargetSdkVersion() < Build.VERSION_CODES.N) { |
| 167 |
Log.e(TAG, "App sent too much data in instance state, so it was ignored", |
| 168 |
ex); |
| 169 |
return; |
| 170 |
} |
| 171 |
} else { |
| 172 |
|
| 173 |
Log.w(TAG, bundleStats); |
| 174 |
} |
| 175 |
throw ex; |
| 176 |
} |
| 177 |
} |
| 178 |
} |
| 179 |
} |