Issue 1837610 Adding a Widget before Running the Associated App Causes a Force Close

We were not retrieving the shared libraries of an application when deliving a
broadcast to an explicit component.

Issue 1753079 loading class path of instrumented app into instrumentation may load wrong path when instrumented app shares process with other apps:

We were using the ApplicationInfo that was used to originally create the process, not the one that the
instrumentation is against.
This commit is contained in:
Dianne Hackborn
2009-05-08 14:29:01 -07:00
parent 5e1d8aed4a
commit 1655be46d2
3 changed files with 39 additions and 27 deletions

View File

@@ -171,6 +171,14 @@ public abstract class PackageManager {
*/ */
public static final int GET_SUPPORTS_DENSITIES = 0x00008000; public static final int GET_SUPPORTS_DENSITIES = 0x00008000;
/**
* Resolution and querying flag: if set, only filters that support the
* {@link android.content.Intent#CATEGORY_DEFAULT} will be considered for
* matching. This is a synonym for including the CATEGORY_DEFAULT in your
* supplied Intent.
*/
public static final int MATCH_DEFAULT_ONLY = 0x00010000;
/** /**
* Permission check result: this is returned by {@link #checkPermission} * Permission check result: this is returned by {@link #checkPermission}
* if the permission has been granted to the given package. * if the permission has been granted to the given package.
@@ -219,14 +227,6 @@ public abstract class PackageManager {
*/ */
public static final int SIGNATURE_UNKNOWN_PACKAGE = -4; public static final int SIGNATURE_UNKNOWN_PACKAGE = -4;
/**
* Resolution and querying flag: if set, only filters that support the
* {@link android.content.Intent#CATEGORY_DEFAULT} will be considered for
* matching. This is a synonym for including the CATEGORY_DEFAULT in your
* supplied Intent.
*/
public static final int MATCH_DEFAULT_ONLY = 0x00010000;
public static final int COMPONENT_ENABLED_STATE_DEFAULT = 0; public static final int COMPONENT_ENABLED_STATE_DEFAULT = 0;
public static final int COMPONENT_ENABLED_STATE_ENABLED = 1; public static final int COMPONENT_ENABLED_STATE_ENABLED = 1;
public static final int COMPONENT_ENABLED_STATE_DISABLED = 2; public static final int COMPONENT_ENABLED_STATE_DISABLED = 2;

View File

@@ -169,6 +169,10 @@ public final class ActivityManagerService extends ActivityManagerNative implemen
static final int LOG_BOOT_PROGRESS_AMS_READY = 3040; static final int LOG_BOOT_PROGRESS_AMS_READY = 3040;
static final int LOG_BOOT_PROGRESS_ENABLE_SCREEN = 3050; static final int LOG_BOOT_PROGRESS_ENABLE_SCREEN = 3050;
// The flags that are set for all calls we make to the package manager.
static final int STOCK_PM_FLAGS = PackageManager.GET_SHARED_LIBRARY_FILES
| PackageManager.GET_SUPPORTS_DENSITIES;
private static final String SYSTEM_SECURE = "ro.secure"; private static final String SYSTEM_SECURE = "ro.secure";
// This is the maximum number of application processes we would like // This is the maximum number of application processes we would like
@@ -1058,7 +1062,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen
ApplicationInfo info = ApplicationInfo info =
mSelf.mContext.getPackageManager().getApplicationInfo( mSelf.mContext.getPackageManager().getApplicationInfo(
"android", PackageManager.GET_SHARED_LIBRARY_FILES); "android", STOCK_PM_FLAGS);
synchronized (mSelf) { synchronized (mSelf) {
ProcessRecord app = mSelf.newProcessRecordLocked( ProcessRecord app = mSelf.newProcessRecordLocked(
mSystemThread.getApplicationThread(), info, mSystemThread.getApplicationThread(), info,
@@ -2224,7 +2228,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen
} }
ActivityInfo aInfo = ActivityInfo aInfo =
intent.resolveActivityInfo(mContext.getPackageManager(), intent.resolveActivityInfo(mContext.getPackageManager(),
PackageManager.GET_SHARED_LIBRARY_FILES); STOCK_PM_FLAGS);
if (aInfo != null) { if (aInfo != null) {
intent.setComponent(new ComponentName( intent.setComponent(new ComponentName(
aInfo.applicationInfo.packageName, aInfo.name)); aInfo.applicationInfo.packageName, aInfo.name));
@@ -3181,7 +3185,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen
ActivityThread.getPackageManager().resolveIntent( ActivityThread.getPackageManager().resolveIntent(
intent, resolvedType, intent, resolvedType,
PackageManager.MATCH_DEFAULT_ONLY PackageManager.MATCH_DEFAULT_ONLY
| PackageManager.GET_SHARED_LIBRARY_FILES); | STOCK_PM_FLAGS);
aInfo = rInfo != null ? rInfo.activityInfo : null; aInfo = rInfo != null ? rInfo.activityInfo : null;
} catch (RemoteException e) { } catch (RemoteException e) {
aInfo = null; aInfo = null;
@@ -3242,8 +3246,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen
List<ResolveInfo> resolves = List<ResolveInfo> resolves =
ActivityThread.getPackageManager().queryIntentActivities( ActivityThread.getPackageManager().queryIntentActivities(
intent, r.resolvedType, intent, r.resolvedType,
PackageManager.MATCH_DEFAULT_ONLY PackageManager.MATCH_DEFAULT_ONLY | STOCK_PM_FLAGS);
| PackageManager.GET_SHARED_LIBRARY_FILES);
// Look for the original activity in the list... // Look for the original activity in the list...
final int N = resolves != null ? resolves.size() : 0; final int N = resolves != null ? resolves.size() : 0;
@@ -3325,8 +3328,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen
ResolveInfo rInfo = ResolveInfo rInfo =
ActivityThread.getPackageManager().resolveIntent( ActivityThread.getPackageManager().resolveIntent(
intent, resolvedType, intent, resolvedType,
PackageManager.MATCH_DEFAULT_ONLY PackageManager.MATCH_DEFAULT_ONLY | STOCK_PM_FLAGS);
| PackageManager.GET_SHARED_LIBRARY_FILES);
aInfo = rInfo != null ? rInfo.activityInfo : null; aInfo = rInfo != null ? rInfo.activityInfo : null;
} catch (RemoteException e) { } catch (RemoteException e) {
aInfo = null; aInfo = null;
@@ -4608,7 +4610,8 @@ public final class ActivityManagerService extends ActivityManagerNative implemen
mWaitForDebugger = mOrigWaitForDebugger; mWaitForDebugger = mOrigWaitForDebugger;
} }
} }
thread.bindApplication(processName, app.info, providers, thread.bindApplication(processName, app.instrumentationInfo != null
? app.instrumentationInfo : app.info, providers,
app.instrumentationClass, app.instrumentationProfileFile, app.instrumentationClass, app.instrumentationProfileFile,
app.instrumentationArguments, app.instrumentationWatcher, testMode, app.instrumentationArguments, app.instrumentationWatcher, testMode,
mConfiguration, getCommonServicesLocked()); mConfiguration, getCommonServicesLocked());
@@ -6651,8 +6654,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen
try { try {
providers = ActivityThread.getPackageManager(). providers = ActivityThread.getPackageManager().
queryContentProviders(app.processName, app.info.uid, queryContentProviders(app.processName, app.info.uid,
PackageManager.GET_SHARED_LIBRARY_FILES STOCK_PM_FLAGS | PackageManager.GET_URI_PERMISSION_PATTERNS);
| PackageManager.GET_URI_PERMISSION_PATTERNS);
} catch (RemoteException ex) { } catch (RemoteException ex) {
} }
if (providers != null) { if (providers != null) {
@@ -6756,7 +6758,8 @@ public final class ActivityManagerService extends ActivityManagerNative implemen
} else { } else {
try { try {
cpi = ActivityThread.getPackageManager(). cpi = ActivityThread.getPackageManager().
resolveContentProvider(name, PackageManager.GET_URI_PERMISSION_PATTERNS); resolveContentProvider(name,
STOCK_PM_FLAGS | PackageManager.GET_URI_PERMISSION_PATTERNS);
} catch (RemoteException ex) { } catch (RemoteException ex) {
} }
if (cpi == null) { if (cpi == null) {
@@ -6777,7 +6780,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen
ActivityThread.getPackageManager(). ActivityThread.getPackageManager().
getApplicationInfo( getApplicationInfo(
cpi.applicationInfo.packageName, cpi.applicationInfo.packageName,
PackageManager.GET_SHARED_LIBRARY_FILES); STOCK_PM_FLAGS);
if (ai == null) { if (ai == null) {
Log.w(TAG, "No package info for content provider " Log.w(TAG, "No package info for content provider "
+ cpi.name); + cpi.name);
@@ -7513,7 +7516,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen
if (mFactoryTest == SystemServer.FACTORY_TEST_LOW_LEVEL) { if (mFactoryTest == SystemServer.FACTORY_TEST_LOW_LEVEL) {
ResolveInfo ri = mContext.getPackageManager() ResolveInfo ri = mContext.getPackageManager()
.resolveActivity(new Intent(Intent.ACTION_FACTORY_TEST), .resolveActivity(new Intent(Intent.ACTION_FACTORY_TEST),
0); STOCK_PM_FLAGS);
CharSequence errorMsg = null; CharSequence errorMsg = null;
if (ri != null) { if (ri != null) {
ActivityInfo ai = ri.activityInfo; ActivityInfo ai = ri.activityInfo;
@@ -7549,7 +7552,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen
if (mFactoryTest != SystemServer.FACTORY_TEST_LOW_LEVEL) { if (mFactoryTest != SystemServer.FACTORY_TEST_LOW_LEVEL) {
try { try {
List apps = ActivityThread.getPackageManager(). List apps = ActivityThread.getPackageManager().
getPersistentApplications(PackageManager.GET_SHARED_LIBRARY_FILES); getPersistentApplications(STOCK_PM_FLAGS);
if (apps != null) { if (apps != null) {
int N = apps.size(); int N = apps.size();
int i; int i;
@@ -8964,7 +8967,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen
try { try {
ResolveInfo rInfo = ResolveInfo rInfo =
ActivityThread.getPackageManager().resolveService( ActivityThread.getPackageManager().resolveService(
service, resolvedType, PackageManager.GET_SHARED_LIBRARY_FILES); service, resolvedType, STOCK_PM_FLAGS);
ServiceInfo sInfo = ServiceInfo sInfo =
rInfo != null ? rInfo.serviceInfo : null; rInfo != null ? rInfo.serviceInfo : null;
if (sInfo == null) { if (sInfo == null) {
@@ -10182,7 +10185,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen
if (intent.getComponent() != null) { if (intent.getComponent() != null) {
// Broadcast is going to one specific receiver class... // Broadcast is going to one specific receiver class...
ActivityInfo ai = ActivityThread.getPackageManager(). ActivityInfo ai = ActivityThread.getPackageManager().
getReceiverInfo(intent.getComponent(), 0); getReceiverInfo(intent.getComponent(), STOCK_PM_FLAGS);
if (ai != null) { if (ai != null) {
receivers = new ArrayList(); receivers = new ArrayList();
ResolveInfo ri = new ResolveInfo(); ResolveInfo ri = new ResolveInfo();
@@ -10195,7 +10198,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen
== 0) { == 0) {
receivers = receivers =
ActivityThread.getPackageManager().queryIntentReceivers( ActivityThread.getPackageManager().queryIntentReceivers(
intent, resolvedType, PackageManager.GET_SHARED_LIBRARY_FILES); intent, resolvedType, STOCK_PM_FLAGS);
} }
registeredReceivers = mReceiverResolver.queryIntent(resolver, registeredReceivers = mReceiverResolver.queryIntent(resolver,
intent, resolvedType, false); intent, resolvedType, false);
@@ -10932,9 +10935,9 @@ public final class ActivityManagerService extends ActivityManagerNative implemen
ApplicationInfo ai = null; ApplicationInfo ai = null;
try { try {
ii = mContext.getPackageManager().getInstrumentationInfo( ii = mContext.getPackageManager().getInstrumentationInfo(
className, 0); className, STOCK_PM_FLAGS);
ai = mContext.getPackageManager().getApplicationInfo( ai = mContext.getPackageManager().getApplicationInfo(
ii.targetPackage, PackageManager.GET_SHARED_LIBRARY_FILES); ii.targetPackage, STOCK_PM_FLAGS);
} catch (PackageManager.NameNotFoundException e) { } catch (PackageManager.NameNotFoundException e) {
} }
if (ii == null) { if (ii == null) {
@@ -10966,6 +10969,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen
uninstallPackageLocked(ii.targetPackage, -1, true); uninstallPackageLocked(ii.targetPackage, -1, true);
ProcessRecord app = addAppLocked(ai); ProcessRecord app = addAppLocked(ai);
app.instrumentationClass = className; app.instrumentationClass = className;
app.instrumentationInfo = ai;
app.instrumentationProfileFile = profileFile; app.instrumentationProfileFile = profileFile;
app.instrumentationArguments = arguments; app.instrumentationArguments = arguments;
app.instrumentationWatcher = watcher; app.instrumentationWatcher = watcher;
@@ -11013,6 +11017,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen
} }
app.instrumentationWatcher = null; app.instrumentationWatcher = null;
app.instrumentationClass = null; app.instrumentationClass = null;
app.instrumentationInfo = null;
app.instrumentationProfileFile = null; app.instrumentationProfileFile = null;
app.instrumentationArguments = null; app.instrumentationArguments = null;

View File

@@ -28,6 +28,7 @@ import android.content.pm.ApplicationInfo;
import android.os.Bundle; import android.os.Bundle;
import android.os.IBinder; import android.os.IBinder;
import android.os.RemoteException; import android.os.RemoteException;
import android.util.PrintWriterPrinter;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.util.ArrayList; import java.util.ArrayList;
@@ -62,6 +63,7 @@ class ProcessRecord implements Watchdog.PssRequestor {
IBinder forcingToForeground;// Token that is forcing this process to be foreground IBinder forcingToForeground;// Token that is forcing this process to be foreground
int adjSeq; // Sequence id for identifying repeated trav int adjSeq; // Sequence id for identifying repeated trav
ComponentName instrumentationClass;// class installed to instrument app ComponentName instrumentationClass;// class installed to instrument app
ApplicationInfo instrumentationInfo; // the application being instrumented
String instrumentationProfileFile; // where to save profiling String instrumentationProfileFile; // where to save profiling
IInstrumentationWatcher instrumentationWatcher; // who is waiting IInstrumentationWatcher instrumentationWatcher; // who is waiting
Bundle instrumentationArguments;// as given to us Bundle instrumentationArguments;// as given to us
@@ -125,6 +127,11 @@ class ProcessRecord implements Watchdog.PssRequestor {
pw.println(instrumentationProfileFile); pw.println(instrumentationProfileFile);
pw.print(prefix); pw.print("instrumentationArguments="); pw.print(prefix); pw.print("instrumentationArguments=");
pw.println(instrumentationArguments); pw.println(instrumentationArguments);
pw.print(prefix); pw.print("instrumentationInfo=");
pw.println(instrumentationInfo);
if (instrumentationInfo != null) {
instrumentationInfo.dump(new PrintWriterPrinter(pw), prefix + " ");
}
} }
pw.print(prefix); pw.print("thread="); pw.print(thread); pw.print(prefix); pw.print("thread="); pw.print(thread);
pw.print(" curReceiver="); pw.println(curReceiver); pw.print(" curReceiver="); pw.println(curReceiver);