Merge "Fix issue #10378741: configupdater needs to be explicit when it calls startService()" into klp-dev

This commit is contained in:
Dianne Hackborn
2013-10-03 17:44:38 +00:00
committed by Android (Google) Code Review
2 changed files with 48 additions and 27 deletions

View File

@@ -1461,29 +1461,39 @@ class ContextImpl extends Context {
}
}
private void validateServiceIntent(Intent service) {
if (service.getComponent() == null && service.getPackage() == null) {
if (true || getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.KITKAT) {
Log.w(TAG, "Implicit intents with startService are not safe: " + service
+ " " + Debug.getCallers(2, 3));
//IllegalArgumentException ex = new IllegalArgumentException(
// "Service Intent must be explicit: " + service);
//Log.e(TAG, "This will become an error", ex);
//throw ex;
}
}
}
@Override
public ComponentName startService(Intent service) {
warnIfCallingFromSystemProcess();
return startServiceAsUser(service, mUser);
return startServiceCommon(service, mUser);
}
@Override
public boolean stopService(Intent service) {
warnIfCallingFromSystemProcess();
return stopServiceAsUser(service, mUser);
return stopServiceCommon(service, mUser);
}
@Override
public ComponentName startServiceAsUser(Intent service, UserHandle user) {
return startServiceCommon(service, user);
}
private ComponentName startServiceCommon(Intent service, UserHandle user) {
try {
if (service.getComponent() == null && service.getPackage() == null) {
if (getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.KITKAT) {
IllegalArgumentException ex = new IllegalArgumentException(
"Service Intent must be explicit: " + service);
Log.e(TAG, "This will become an error", ex);
//throw ex;
}
}
validateServiceIntent(service);
service.prepareToLeaveProcess();
ComponentName cn = ActivityManagerNative.getDefault().startService(
mMainThread.getApplicationThread(), service,
@@ -1507,15 +1517,12 @@ class ContextImpl extends Context {
@Override
public boolean stopServiceAsUser(Intent service, UserHandle user) {
return stopServiceCommon(service, user);
}
private boolean stopServiceCommon(Intent service, UserHandle user) {
try {
if (service.getComponent() == null && service.getPackage() == null) {
if (getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.KITKAT) {
IllegalArgumentException ex = new IllegalArgumentException(
"Service Intent must be explicit: " + service);
Log.e(TAG, "This will become an error", ex);
//throw ex;
}
}
validateServiceIntent(service);
service.prepareToLeaveProcess();
int res = ActivityManagerNative.getDefault().stopService(
mMainThread.getApplicationThread(), service,
@@ -1534,13 +1541,18 @@ class ContextImpl extends Context {
public boolean bindService(Intent service, ServiceConnection conn,
int flags) {
warnIfCallingFromSystemProcess();
return bindServiceAsUser(service, conn, flags, Process.myUserHandle());
return bindServiceCommon(service, conn, flags, Process.myUserHandle());
}
/** @hide */
@Override
public boolean bindServiceAsUser(Intent service, ServiceConnection conn, int flags,
UserHandle user) {
return bindServiceCommon(service, conn, flags, user);
}
private boolean bindServiceCommon(Intent service, ServiceConnection conn, int flags,
UserHandle user) {
IServiceConnection sd;
if (conn == null) {
throw new IllegalArgumentException("connection is null");
@@ -1551,14 +1563,7 @@ class ContextImpl extends Context {
} else {
throw new RuntimeException("Not supported in system context");
}
if (service.getComponent() == null && service.getPackage() == null) {
if (getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.KITKAT) {
IllegalArgumentException ex = new IllegalArgumentException(
"Service Intent must be explicit: " + service);
Log.e(TAG, "This will become an error", ex);
//throw ex;
}
}
validateServiceIntent(service);
try {
IBinder token = getActivityToken();
if (token == null && (flags&BIND_AUTO_CREATE) == 0 && mPackageInfo != null

View File

@@ -1581,6 +1581,22 @@ href="{@docRoot}guide/developing/tools/traceview.html">Traceview: A Graphical Lo
return sb.toString();
}
/**
* Return a string consisting of methods and locations at multiple call stack levels.
* @param depth the number of levels to return, starting with the immediate caller.
* @return a string describing the call stack.
* {@hide}
*/
public static String getCallers(final int start, int depth) {
final StackTraceElement[] callStack = Thread.currentThread().getStackTrace();
StringBuffer sb = new StringBuffer();
depth += start;
for (int i = start; i < depth; i++) {
sb.append(getCaller(callStack, i)).append(" ");
}
return sb.toString();
}
/**
* Like {@link #getCallers(int)}, but each location is append to the string
* as a new line with <var>linePrefix</var> in front of it.