From acff20bda404f59ffba6035b18956d6aff7afcd8 Mon Sep 17 00:00:00 2001 From: Jeff Hamilton Date: Wed, 28 Oct 2009 14:14:54 -0500 Subject: [PATCH 1/8] Copy the selection args when creating a CPO since callers often reuse the passed in array. Bug: 2221947 Change-Id: I3b7d5cbef61777d76ca7fc0d7c91c44553e609a9 --- core/java/android/content/ContentProviderOperation.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/java/android/content/ContentProviderOperation.java b/core/java/android/content/ContentProviderOperation.java index 60b406d36467b..0467516b4b846 100644 --- a/core/java/android/content/ContentProviderOperation.java +++ b/core/java/android/content/ContentProviderOperation.java @@ -545,7 +545,8 @@ public class ContentProviderOperation implements Parcelable { "only updates, deletes, and asserts can have selections"); } mSelection = selection; - mSelectionArgs = selectionArgs; + mSelectionArgs = new String[selectionArgs.length]; + System.arraycopy(selectionArgs, 0, mSelectionArgs, 0, selectionArgs.length); return this; } From eab4c75b09aa81ea093c2b9fbb3dbc2016c9bd6e Mon Sep 17 00:00:00 2001 From: Jason Sams Date: Wed, 28 Oct 2009 17:40:13 -0700 Subject: [PATCH 2/8] Fix type in Java enums. Not currently used, easier to fix now than when apps are using it. --- graphics/java/android/renderscript/ProgramStore.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/graphics/java/android/renderscript/ProgramStore.java b/graphics/java/android/renderscript/ProgramStore.java index b7d987efbb1ad..5cbe1b29415a9 100644 --- a/graphics/java/android/renderscript/ProgramStore.java +++ b/graphics/java/android/renderscript/ProgramStore.java @@ -49,7 +49,7 @@ public class ProgramStore extends BaseObj { SRC_ALPHA (4), ONE_MINUS_SRC_ALPHA (5), DST_ALPHA (6), - ONE_MINUS_DST_ALPA (7), + ONE_MINUS_DST_ALPHA (7), SRC_ALPHA_SATURATE (8); int mID; @@ -66,7 +66,7 @@ public class ProgramStore extends BaseObj { SRC_ALPHA (4), ONE_MINUS_SRC_ALPHA (5), DST_ALPHA (6), - ONE_MINUS_DST_ALPA (7); + ONE_MINUS_DST_ALPHA (7); int mID; BlendDstFunc(int id) { From 4a943184544159a57ca749af53bab0f1a98435a1 Mon Sep 17 00:00:00 2001 From: Jack Palevich Date: Wed, 28 Oct 2009 19:38:05 -0700 Subject: [PATCH 3/8] Avoid trying to throw multiple exceptions at once. The typical usage pattern for the get_char helper function is: bool thrown = false; n = get_char(env, s, 0, 1000, &thrown); n += get_char(env, s, 1, 100, &thrown); n += get_char(env, s, 2, 10, &thrown); n += get_char(env, s, 3, 1, &thrown); if (thrown) return false; As you can see, get_char is called multiple times before the thrown flag is checked. If the input text contains multiple incorrect characters, then we have to guard against throwing the same exception multiple times. (Because doing so will cause the Dalvik runtime to abort.) The fix is simple: modify get_char to check if an exception has already been thrown before throwing a new exception. --- core/jni/android_text_format_Time.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/core/jni/android_text_format_Time.cpp b/core/jni/android_text_format_Time.cpp index 98f4e035c0c95..fde6ca6e2b2a1 100644 --- a/core/jni/android_text_format_Time.cpp +++ b/core/jni/android_text_format_Time.cpp @@ -367,10 +367,12 @@ static int get_char(JNIEnv* env, const jchar *s, int spos, int mul, if (c >= '0' && c <= '9') { return (c - '0') * mul; } else { - char msg[100]; - sprintf(msg, "Parse error at pos=%d", spos); - jniThrowException(env, "android/util/TimeFormatException", msg); - *thrown = true; + if (!*thrown) { + char msg[100]; + sprintf(msg, "Parse error at pos=%d", spos); + jniThrowException(env, "android/util/TimeFormatException", msg); + *thrown = true; + } return 0; } } From d6f158b3684acdf877ff6afb7208e1140afc4e12 Mon Sep 17 00:00:00 2001 From: Ed Heyl Date: Thu, 29 Oct 2009 10:18:45 -0700 Subject: [PATCH 4/8] Removed javadoc link to hidden class (temporary fix for build) --- core/java/android/accounts/AbstractAccountAuthenticator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/java/android/accounts/AbstractAccountAuthenticator.java b/core/java/android/accounts/AbstractAccountAuthenticator.java index 0efeb1d36a91b..be2bdbefb59d0 100644 --- a/core/java/android/accounts/AbstractAccountAuthenticator.java +++ b/core/java/android/accounts/AbstractAccountAuthenticator.java @@ -88,7 +88,7 @@ import android.Manifest; * The activity must then call {@link AccountAuthenticatorResponse#onResult} or * {@link AccountAuthenticatorResponse#onError} when it is complete. *
  • If the authenticator cannot synchronously process the request and return a result then it - * may choose to return null and then use the {@link AccountManagerResponse} to send the result + * may choose to return null and then use the AccountManagerResponse to send the result * when it has completed the request. * *

    From a5109a878eeff22e32ee5ce1b1cd15e8daad5234 Mon Sep 17 00:00:00 2001 From: San Mehat Date: Thu, 29 Oct 2009 11:48:50 -0700 Subject: [PATCH 5/8] process: Add debug code to log process group transitions Signed-off-by: San Mehat --- core/jni/android_util_Process.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/core/jni/android_util_Process.cpp b/core/jni/android_util_Process.cpp index 5b6c7ea13e8a6..7c627c1036f89 100644 --- a/core/jni/android_util_Process.cpp +++ b/core/jni/android_util_Process.cpp @@ -51,6 +51,8 @@ pid_t gettid() { return syscall(__NR_gettid);} #undef __KERNEL__ #endif +#define POLICY_DEBUG 1 + using namespace android; static void signalExceptionForPriorityError(JNIEnv* env, jobject obj, int err) @@ -212,6 +214,26 @@ void android_os_Process_setProcessGroup(JNIEnv* env, jobject clazz, int pid, jin return; } +#if POLICY_DEBUG + char cmdline[32]; + int fd; + + strcpy(cmdline, "unknown"); + + sprintf(proc_path, "/proc/%d/cmdline", pid); + fd = open(proc_path, O_RDONLY); + if (fd >= 0) { + int rc = read(fd, cmdline, sizeof(cmdline)-1); + cmdline[rc] = 0; + close(fd); + } + + if (grp == ANDROID_TGROUP_BG_NONINTERACT) { + LOGD("setProcessGroup: vvv pid %d (%s)", pid, cmdline); + } else { + LOGD("setProcessGroup: ^^^ pid %d (%s)", pid, cmdline); + } +#endif sprintf(proc_path, "/proc/%d/task", pid); if (!(d = opendir(proc_path))) { // If the process exited on us, don't generate an exception From 26a2d829b37d2658e5e037f1f8ce968bbd9f2164 Mon Sep 17 00:00:00 2001 From: Evan Millar Date: Thu, 29 Oct 2009 12:41:39 -0700 Subject: [PATCH 6/8] Add -P flag to ps in dumpstate --- cmds/dumpstate/dumpstate.c | 5 ++--- cmds/dumpstate/dumpstate.h | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/cmds/dumpstate/dumpstate.c b/cmds/dumpstate/dumpstate.c index ca8660c0ba927..642c943ffd368 100644 --- a/cmds/dumpstate/dumpstate.c +++ b/cmds/dumpstate/dumpstate.c @@ -86,9 +86,9 @@ static void dumpstate(int full) { DUMP("/proc/wakelocks"); PRINT(""); PRINT("------ PROCESSES ------"); - EXEC("ps"); + EXEC1("ps", "-P"); PRINT("------ PROCESSES AND THREADS ------"); - EXEC2("ps", "-t", "-p"); + EXEC3("ps", "-t", "-p", "-P"); PRINT("------ LIBRANK ------"); EXEC_XBIN("librank"); PRINT("------ BINDER FAILED TRANSACTION LOG ------"); @@ -362,4 +362,3 @@ static void dump_kernel_log(const char *path, const char *title) DUMP(path); } } - diff --git a/cmds/dumpstate/dumpstate.h b/cmds/dumpstate/dumpstate.h index 6862e5a3edb41..b99b6d792249a 100644 --- a/cmds/dumpstate/dumpstate.h +++ b/cmds/dumpstate/dumpstate.h @@ -61,6 +61,15 @@ run_command(&c, TIMEOUT); \ } +#define EXEC1(cmd, a1) \ +{ \ + static struct Command c = { \ + "/system/bin/" cmd, \ + { cmd, a1, 0 } \ + }; \ + run_command(&c, TIMEOUT); \ +} + #define EXEC2(cmd, a1, a2) \ { \ static struct Command c = { \ @@ -70,6 +79,15 @@ run_command(&c, TIMEOUT); \ } +#define EXEC3(cmd, a1, a2, a3) \ +{ \ + static struct Command c = { \ + "/system/bin/" cmd, \ + { cmd, a1, a2, a3, 0 } \ + }; \ + run_command(&c, TIMEOUT); \ +} + #define EXEC4(cmd, a1, a2, a3, a4) \ { \ static struct Command c = { \ From 88a211b148dd94df1f178338c94fdd7d01f53863 Mon Sep 17 00:00:00 2001 From: Costin Manolache Date: Thu, 29 Oct 2009 11:30:11 -0700 Subject: [PATCH 7/8] Revert the changes that introduced new exception that wouldn't have occured before, applications don't seem to be able to handle them and we get crashes. --- .../java/android/accounts/AccountManager.java | 38 +++++++---- .../accounts/AccountManagerService.java | 64 ------------------- 2 files changed, 26 insertions(+), 76 deletions(-) diff --git a/core/java/android/accounts/AccountManager.java b/core/java/android/accounts/AccountManager.java index 46dc895a826e8..9765496762c03 100644 --- a/core/java/android/accounts/AccountManager.java +++ b/core/java/android/accounts/AccountManager.java @@ -321,7 +321,8 @@ public class AccountManager { */ public String peekAuthToken(final Account account, final String authTokenType) { if (account == null) { - throw new IllegalArgumentException("the account must not be null"); + Log.e(TAG, "peekAuthToken: the account must not be null"); + return null; } if (authTokenType == null) { return null; @@ -346,7 +347,8 @@ public class AccountManager { */ public void setPassword(final Account account, final String password) { if (account == null) { - throw new IllegalArgumentException("the account must not be null"); + Log.e(TAG, "the account must not be null"); + return; } try { mService.setPassword(account, password); @@ -365,7 +367,8 @@ public class AccountManager { */ public void clearPassword(final Account account) { if (account == null) { - throw new IllegalArgumentException("the account must not be null"); + Log.e(TAG, "the account must not be null"); + return; } try { mService.clearPassword(account); @@ -388,10 +391,12 @@ public class AccountManager { */ public void setUserData(final Account account, final String key, final String value) { if (account == null) { - throw new IllegalArgumentException("the account must not be null"); + Log.e(TAG, "the account must not be null"); + return; } if (key == null) { - throw new IllegalArgumentException("the key must not be null"); + Log.e(TAG, "the key must not be null"); + return; } try { mService.setUserData(account, key, value); @@ -602,11 +607,14 @@ public class AccountManager { final String authTokenType, final String[] requiredFeatures, final Bundle addAccountOptions, final Activity activity, AccountManagerCallback callback, Handler handler) { - if (accountType == null) { - throw new IllegalArgumentException(); - } return new AmsTask(activity, handler, callback) { public void doWork() throws RemoteException { + if (accountType == null) { + Log.e(TAG, "the account must not be null"); + // to unblock caller waiting on Future.get() + set(new Bundle()); + return; + } mService.addAcount(mResponse, accountType, authTokenType, requiredFeatures, activity != null, addAccountOptions); } @@ -616,9 +624,13 @@ public class AccountManager { public AccountManagerFuture getAccountsByTypeAndFeatures( final String type, final String[] features, AccountManagerCallback callback, Handler handler) { - if (type == null) throw new IllegalArgumentException("type is null"); return new Future2Task(handler, callback) { public void doWork() throws RemoteException { + if (type == null) { + Log.e(TAG, "Type is null"); + set(new Account[0]); + return; + } mService.getAccountsByFeatures(mResponse, type, features); } public Account[] bundleToResult(Bundle bundle) throws AuthenticatorException { @@ -785,7 +797,7 @@ public class AccountManager { //noinspection ThrowableInstanceNeverThrow // Log.e(TAG, "calling this from your main thread can lead to deadlock and/or ANRs", // new Exception()); - // TODO(fredq) remove the log and throw this exception when the callers are fixed + // TODO remove the log and throw this exception when the callers are fixed // throw new IllegalStateException( // "calling this from your main thread can lead to deadlock"); } @@ -1338,11 +1350,13 @@ public class AccountManager { */ public void removeOnAccountsUpdatedListener(OnAccountsUpdateListener listener) { if (listener == null) { - throw new IllegalArgumentException("the listener is null"); + Log.e(TAG, "Missing listener"); + return; } synchronized (mAccountsUpdatedListeners) { if (!mAccountsUpdatedListeners.containsKey(listener)) { - throw new IllegalStateException("this listener was not previously added"); + Log.e(TAG, "Listener was not previously added"); + return; } mAccountsUpdatedListeners.remove(listener); if (mAccountsUpdatedListeners.isEmpty()) { diff --git a/core/java/android/accounts/AccountManagerService.java b/core/java/android/accounts/AccountManagerService.java index 9c60141336e63..4f59c4e67edde 100644 --- a/core/java/android/accounts/AccountManagerService.java +++ b/core/java/android/accounts/AccountManagerService.java @@ -429,14 +429,6 @@ public class AccountManagerService checkManageAccountsPermission(); long identityToken = clearCallingIdentity(); try { - if (account == null) { - try { - response.onError(AccountManager.ERROR_CODE_BAD_ARGUMENTS, "null account"); - } catch (RemoteException e) { - // it doesn't matter if we are unable to deliver this error - } - return; - } new RemoveAccountSession(response, account).bind(); } finally { restoreCallingIdentity(identityToken); @@ -706,22 +698,6 @@ public class AccountManagerService long identityToken = clearCallingIdentity(); try { - try { - if (account == null) { - response.onError(AccountManager.ERROR_CODE_BAD_ARGUMENTS, - "account is null"); - return; - } - if (authTokenType == null) { - response.onError(AccountManager.ERROR_CODE_BAD_ARGUMENTS, - "authTokenType is null"); - return; - } - } catch (RemoteException e) { - // it doesn't matter if we can't deliver this error - return; - } - // if the caller has permission, do the peek. otherwise go the more expensive // route of starting a Session if (permissionGranted) { @@ -887,16 +863,6 @@ public class AccountManagerService checkManageAccountsPermission(); long identityToken = clearCallingIdentity(); try { - try { - if (authTokenType == null) { - response.onError(AccountManager.ERROR_CODE_BAD_ARGUMENTS, - "authTokenType is null"); - return; - } - } catch (RemoteException e) { - // it doesn't matter if we can't deliver this error - return; - } new Session(response, accountType, expectActivityLaunch) { public void run() throws RemoteException { mAuthenticator.addAccount(this, mAccountType, authTokenType, requiredFeatures, @@ -922,16 +888,6 @@ public class AccountManagerService checkManageAccountsPermission(); long identityToken = clearCallingIdentity(); try { - try { - if (account == null) { - response.onError(AccountManager.ERROR_CODE_BAD_ARGUMENTS, - "account is null"); - return; - } - } catch (RemoteException e) { - // it doesn't matter if we can't deliver this error - return; - } new Session(response, account.type, expectActivityLaunch) { public void run() throws RemoteException { mAuthenticator.confirmCredentials(this, account, options); @@ -952,16 +908,6 @@ public class AccountManagerService checkManageAccountsPermission(); long identityToken = clearCallingIdentity(); try { - try { - if (account == null) { - response.onError(AccountManager.ERROR_CODE_BAD_ARGUMENTS, - "account is null"); - return; - } - } catch (RemoteException e) { - // it doesn't matter if we can't deliver this error - return; - } new Session(response, account.type, expectActivityLaunch) { public void run() throws RemoteException { mAuthenticator.updateCredentials(this, account, authTokenType, loginOptions); @@ -984,16 +930,6 @@ public class AccountManagerService checkManageAccountsPermission(); long identityToken = clearCallingIdentity(); try { - try { - if (accountType == null) { - response.onError(AccountManager.ERROR_CODE_BAD_ARGUMENTS, - "accountType is null"); - return; - } - } catch (RemoteException e) { - // it doesn't matter if we can't deliver this error - return; - } new Session(response, accountType, expectActivityLaunch) { public void run() throws RemoteException { mAuthenticator.editProperties(this, mAccountType); From 957e58670baad8c5995f1368e3b5280f0dbd891f Mon Sep 17 00:00:00 2001 From: San Mehat Date: Thu, 29 Oct 2009 13:56:49 -0700 Subject: [PATCH 8/8] process: Disable debugging Signed-off-by: San Mehat --- core/jni/android_util_Process.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/jni/android_util_Process.cpp b/core/jni/android_util_Process.cpp index 7c627c1036f89..d8c2234943e3d 100644 --- a/core/jni/android_util_Process.cpp +++ b/core/jni/android_util_Process.cpp @@ -51,7 +51,7 @@ pid_t gettid() { return syscall(__NR_gettid);} #undef __KERNEL__ #endif -#define POLICY_DEBUG 1 +#define POLICY_DEBUG 0 using namespace android;