am fa4d547d: Merge "Improve reporting to apps of transaction too large failures." into mnc-dev

* commit 'fa4d547d5813a8f5c298efd089890b5b502df76d':
  Improve reporting to apps of transaction too large failures.
This commit is contained in:
Dianne Hackborn
2015-05-22 19:04:43 +00:00
committed by Android Git Automerger
8 changed files with 52 additions and 13 deletions

View File

@@ -23578,6 +23578,7 @@ package android.os {
public class TransactionTooLargeException extends android.os.RemoteException { public class TransactionTooLargeException extends android.os.RemoteException {
ctor public TransactionTooLargeException(); ctor public TransactionTooLargeException();
ctor public TransactionTooLargeException(java.lang.String);
} }
public final class UserHandle implements android.os.Parcelable { public final class UserHandle implements android.os.Parcelable {

View File

@@ -25500,6 +25500,7 @@ package android.os {
public class TransactionTooLargeException extends android.os.RemoteException { public class TransactionTooLargeException extends android.os.RemoteException {
ctor public TransactionTooLargeException(); ctor public TransactionTooLargeException();
ctor public TransactionTooLargeException(java.lang.String);
} }
public final class UserHandle implements android.os.Parcelable { public final class UserHandle implements android.os.Parcelable {

View File

@@ -689,7 +689,8 @@ class ContextImpl extends Context {
intent.resolveTypeIfNeeded(getContentResolver()), intent.resolveTypeIfNeeded(getContentResolver()),
null, null, 0, Intent.FLAG_ACTIVITY_NEW_TASK, null, options, null, null, 0, Intent.FLAG_ACTIVITY_NEW_TASK, null, options,
user.getIdentifier()); user.getIdentifier());
} catch (RemoteException re) { } catch (RemoteException e) {
throw new RuntimeException("Failure from system", e);
} }
} }
@@ -754,6 +755,7 @@ class ContextImpl extends Context {
} }
Instrumentation.checkStartActivityResult(result, null); Instrumentation.checkStartActivityResult(result, null);
} catch (RemoteException e) { } catch (RemoteException e) {
throw new RuntimeException("Failure from system", e);
} }
} }
@@ -768,6 +770,7 @@ class ContextImpl extends Context {
Activity.RESULT_OK, null, null, null, AppOpsManager.OP_NONE, false, false, Activity.RESULT_OK, null, null, null, AppOpsManager.OP_NONE, false, false,
getUserId()); getUserId());
} catch (RemoteException e) { } catch (RemoteException e) {
throw new RuntimeException("Failure from system", e);
} }
} }
@@ -782,6 +785,7 @@ class ContextImpl extends Context {
Activity.RESULT_OK, null, null, receiverPermission, AppOpsManager.OP_NONE, Activity.RESULT_OK, null, null, receiverPermission, AppOpsManager.OP_NONE,
false, false, getUserId()); false, false, getUserId());
} catch (RemoteException e) { } catch (RemoteException e) {
throw new RuntimeException("Failure from system", e);
} }
} }
@@ -796,6 +800,7 @@ class ContextImpl extends Context {
Activity.RESULT_OK, null, null, receiverPermission, appOp, false, false, Activity.RESULT_OK, null, null, receiverPermission, appOp, false, false,
getUserId()); getUserId());
} catch (RemoteException e) { } catch (RemoteException e) {
throw new RuntimeException("Failure from system", e);
} }
} }
@@ -811,6 +816,7 @@ class ContextImpl extends Context {
Activity.RESULT_OK, null, null, receiverPermission, AppOpsManager.OP_NONE, true, false, Activity.RESULT_OK, null, null, receiverPermission, AppOpsManager.OP_NONE, true, false,
getUserId()); getUserId());
} catch (RemoteException e) { } catch (RemoteException e) {
throw new RuntimeException("Failure from system", e);
} }
} }
@@ -854,6 +860,7 @@ class ContextImpl extends Context {
initialCode, initialData, initialExtras, receiverPermission, appOp, initialCode, initialData, initialExtras, receiverPermission, appOp,
true, false, getUserId()); true, false, getUserId());
} catch (RemoteException e) { } catch (RemoteException e) {
throw new RuntimeException("Failure from system", e);
} }
} }
@@ -866,6 +873,7 @@ class ContextImpl extends Context {
intent, resolvedType, null, Activity.RESULT_OK, null, null, null, intent, resolvedType, null, Activity.RESULT_OK, null, null, null,
AppOpsManager.OP_NONE, false, false, user.getIdentifier()); AppOpsManager.OP_NONE, false, false, user.getIdentifier());
} catch (RemoteException e) { } catch (RemoteException e) {
throw new RuntimeException("Failure from system", e);
} }
} }
@@ -886,6 +894,7 @@ class ContextImpl extends Context {
Activity.RESULT_OK, null, null, receiverPermission, appOp, false, false, Activity.RESULT_OK, null, null, receiverPermission, appOp, false, false,
user.getIdentifier()); user.getIdentifier());
} catch (RemoteException e) { } catch (RemoteException e) {
throw new RuntimeException("Failure from system", e);
} }
} }
@@ -927,6 +936,7 @@ class ContextImpl extends Context {
initialCode, initialData, initialExtras, receiverPermission, initialCode, initialData, initialExtras, receiverPermission,
appOp, true, false, user.getIdentifier()); appOp, true, false, user.getIdentifier());
} catch (RemoteException e) { } catch (RemoteException e) {
throw new RuntimeException("Failure from system", e);
} }
} }
@@ -942,6 +952,7 @@ class ContextImpl extends Context {
Activity.RESULT_OK, null, null, null, AppOpsManager.OP_NONE, false, true, Activity.RESULT_OK, null, null, null, AppOpsManager.OP_NONE, false, true,
getUserId()); getUserId());
} catch (RemoteException e) { } catch (RemoteException e) {
throw new RuntimeException("Failure from system", e);
} }
} }
@@ -977,6 +988,7 @@ class ContextImpl extends Context {
initialCode, initialData, initialExtras, null, initialCode, initialData, initialExtras, null,
AppOpsManager.OP_NONE, true, true, getUserId()); AppOpsManager.OP_NONE, true, true, getUserId());
} catch (RemoteException e) { } catch (RemoteException e) {
throw new RuntimeException("Failure from system", e);
} }
} }
@@ -993,6 +1005,7 @@ class ContextImpl extends Context {
ActivityManagerNative.getDefault().unbroadcastIntent( ActivityManagerNative.getDefault().unbroadcastIntent(
mMainThread.getApplicationThread(), intent, getUserId()); mMainThread.getApplicationThread(), intent, getUserId());
} catch (RemoteException e) { } catch (RemoteException e) {
throw new RuntimeException("Failure from system", e);
} }
} }
@@ -1006,6 +1019,7 @@ class ContextImpl extends Context {
mMainThread.getApplicationThread(), intent, resolvedType, null, mMainThread.getApplicationThread(), intent, resolvedType, null,
Activity.RESULT_OK, null, null, null, AppOpsManager.OP_NONE, false, true, user.getIdentifier()); Activity.RESULT_OK, null, null, null, AppOpsManager.OP_NONE, false, true, user.getIdentifier());
} catch (RemoteException e) { } catch (RemoteException e) {
throw new RuntimeException("Failure from system", e);
} }
} }
@@ -1040,6 +1054,7 @@ class ContextImpl extends Context {
initialCode, initialData, initialExtras, null, initialCode, initialData, initialExtras, null,
AppOpsManager.OP_NONE, true, true, user.getIdentifier()); AppOpsManager.OP_NONE, true, true, user.getIdentifier());
} catch (RemoteException e) { } catch (RemoteException e) {
throw new RuntimeException("Failure from system", e);
} }
} }
@@ -1056,6 +1071,7 @@ class ContextImpl extends Context {
ActivityManagerNative.getDefault().unbroadcastIntent( ActivityManagerNative.getDefault().unbroadcastIntent(
mMainThread.getApplicationThread(), intent, user.getIdentifier()); mMainThread.getApplicationThread(), intent, user.getIdentifier());
} catch (RemoteException e) { } catch (RemoteException e) {
throw new RuntimeException("Failure from system", e);
} }
} }
@@ -1171,7 +1187,7 @@ class ContextImpl extends Context {
} }
return cn; return cn;
} catch (RemoteException e) { } catch (RemoteException e) {
return null; throw new RuntimeException("Failure from system", e);
} }
} }
@@ -1193,7 +1209,7 @@ class ContextImpl extends Context {
} }
return res != 0; return res != 0;
} catch (RemoteException e) { } catch (RemoteException e) {
return false; throw new RuntimeException("Failure from system", e);
} }
} }
@@ -1242,7 +1258,7 @@ class ContextImpl extends Context {
} }
return res != 0; return res != 0;
} catch (RemoteException e) { } catch (RemoteException e) {
return false; throw new RuntimeException("Failure from system", e);
} }
} }
@@ -1274,9 +1290,8 @@ class ContextImpl extends Context {
className, profileFile, 0, arguments, null, null, getUserId(), className, profileFile, 0, arguments, null, null, getUserId(),
null /* ABI override */); null /* ABI override */);
} catch (RemoteException e) { } catch (RemoteException e) {
// System has crashed, nothing we can do. throw new RuntimeException("Failure from system", e);
} }
return false;
} }
@Override @Override

View File

@@ -1506,6 +1506,7 @@ public class Instrumentation {
requestCode, 0, null, options); requestCode, 0, null, options);
checkStartActivityResult(result, intent); checkStartActivityResult(result, intent);
} catch (RemoteException e) { } catch (RemoteException e) {
throw new RuntimeException("Failure from system", e);
} }
return null; return null;
} }
@@ -1563,6 +1564,7 @@ public class Instrumentation {
token, options, userId); token, options, userId);
checkStartActivityResult(result, intents[0]); checkStartActivityResult(result, intents[0]);
} catch (RemoteException e) { } catch (RemoteException e) {
throw new RuntimeException("Failure from system", e);
} }
} }
@@ -1622,6 +1624,7 @@ public class Instrumentation {
token, target, requestCode, 0, null, options); token, target, requestCode, 0, null, options);
checkStartActivityResult(result, intent); checkStartActivityResult(result, intent);
} catch (RemoteException e) { } catch (RemoteException e) {
throw new RuntimeException("Failure from system", e);
} }
return null; return null;
} }
@@ -1682,6 +1685,7 @@ public class Instrumentation {
requestCode, 0, null, options, user.getIdentifier()); requestCode, 0, null, options, user.getIdentifier());
checkStartActivityResult(result, intent); checkStartActivityResult(result, intent);
} catch (RemoteException e) { } catch (RemoteException e) {
throw new RuntimeException("Failure from system", e);
} }
return null; return null;
} }
@@ -1719,6 +1723,7 @@ public class Instrumentation {
requestCode, 0, null, options, userId); requestCode, 0, null, options, userId);
checkStartActivityResult(result, intent); checkStartActivityResult(result, intent);
} catch (RemoteException e) { } catch (RemoteException e) {
throw new RuntimeException("Failure from system", e);
} }
return null; return null;
} }
@@ -1753,6 +1758,7 @@ public class Instrumentation {
intent, intent.resolveTypeIfNeeded(who.getContentResolver()), options); intent, intent.resolveTypeIfNeeded(who.getContentResolver()), options);
checkStartActivityResult(result, intent); checkStartActivityResult(result, intent);
} catch (RemoteException e) { } catch (RemoteException e) {
throw new RuntimeException("Failure from system", e);
} }
return; return;
} }

View File

@@ -56,4 +56,8 @@ public class TransactionTooLargeException extends RemoteException {
public TransactionTooLargeException() { public TransactionTooLargeException() {
super(); super();
} }
public TransactionTooLargeException(String msg) {
super(msg);
}
} }

View File

@@ -635,7 +635,7 @@ void set_dalvik_blockguard_policy(JNIEnv* env, jint strict_policy)
} }
void signalExceptionForError(JNIEnv* env, jobject obj, status_t err, void signalExceptionForError(JNIEnv* env, jobject obj, status_t err,
bool canThrowRemoteException) bool canThrowRemoteException, int parcelSize)
{ {
switch (err) { switch (err) {
case UNKNOWN_ERROR: case UNKNOWN_ERROR:
@@ -680,8 +680,10 @@ void signalExceptionForError(JNIEnv* env, jobject obj, status_t err,
case UNKNOWN_TRANSACTION: case UNKNOWN_TRANSACTION:
jniThrowException(env, "java/lang/RuntimeException", "Unknown transaction code"); jniThrowException(env, "java/lang/RuntimeException", "Unknown transaction code");
break; break;
case FAILED_TRANSACTION: case FAILED_TRANSACTION: {
ALOGE("!!! FAILED BINDER TRANSACTION !!!"); ALOGE("!!! FAILED BINDER TRANSACTION !!! (parcel size = %d)", parcelSize);
char msg[128];
snprintf(msg, sizeof(msg)-1, "data parcel size %d bytes", parcelSize);
// TransactionTooLargeException is a checked exception, only throw from certain methods. // TransactionTooLargeException is a checked exception, only throw from certain methods.
// FIXME: Transaction too large is the most common reason for FAILED_TRANSACTION // FIXME: Transaction too large is the most common reason for FAILED_TRANSACTION
// but it is not the only one. The Binder driver can return BR_FAILED_REPLY // but it is not the only one. The Binder driver can return BR_FAILED_REPLY
@@ -690,8 +692,9 @@ void signalExceptionForError(JNIEnv* env, jobject obj, status_t err,
// to enable us to distinguish these cases in the future. // to enable us to distinguish these cases in the future.
jniThrowException(env, canThrowRemoteException jniThrowException(env, canThrowRemoteException
? "android/os/TransactionTooLargeException" ? "android/os/TransactionTooLargeException"
: "java/lang/RuntimeException", NULL); : "java/lang/RuntimeException",
break; parcelSize > 0 ? msg : NULL);
} break;
case FDS_NOT_ALLOWED: case FDS_NOT_ALLOWED:
jniThrowException(env, "java/lang/RuntimeException", jniThrowException(env, "java/lang/RuntimeException",
"Not allowed to write file descriptors here"); "Not allowed to write file descriptors here");
@@ -1121,7 +1124,7 @@ static jboolean android_os_BinderProxy_transact(JNIEnv* env, jobject obj,
return JNI_FALSE; return JNI_FALSE;
} }
signalExceptionForError(env, obj, err, true /*canThrowRemoteException*/); signalExceptionForError(env, obj, err, true /*canThrowRemoteException*/, data->dataSize());
return JNI_FALSE; return JNI_FALSE;
} }

View File

@@ -33,7 +33,7 @@ extern jobject newParcelFileDescriptor(JNIEnv* env, jobject fileDesc);
extern void set_dalvik_blockguard_policy(JNIEnv* env, jint strict_policy); extern void set_dalvik_blockguard_policy(JNIEnv* env, jint strict_policy);
extern void signalExceptionForError(JNIEnv* env, jobject obj, status_t err, extern void signalExceptionForError(JNIEnv* env, jobject obj, status_t err,
bool canThrowRemoteException = false); bool canThrowRemoteException = false, int parcelSize = 0);
} }

View File

@@ -427,6 +427,15 @@ public class ActivityTestMain extends Activity {
return true; return true;
} }
}); });
menu.add("Transaction fail").setOnMenuItemClickListener(
new MenuItem.OnMenuItemClickListener() {
@Override public boolean onMenuItemClick(MenuItem item) {
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.putExtra("gulp", new int[1024*1024]);
startActivity(intent);
return true;
}
});
return true; return true;
} }