Some ActivityThread/ActivityManager cleanup.

- Move PackageInfo out of ActivityThread, renaming to LoadedApk.
- Rename some of the other PacakgeInfo inner classes to better
  represent what they are.
- Rename HistoryRecord to ActivityRecord.
- Introduce AppGlobals, to eventually let ActivityThread become
  package scoped.

Change-Id: Ib714c54ceb3cdbb525dce3db9505f31042e88cf0
This commit is contained in:
Dianne Hackborn
2010-06-24 15:07:24 -07:00
parent 7b5b27ada1
commit 01e4cfc47d
16 changed files with 1678 additions and 1576 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,49 @@
/*
* Copyright (C) 2010 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.app;
import android.content.pm.IPackageManager;
/**
* Special private access for certain globals related to a process.
* @hide
*/
public class AppGlobals {
/**
* Return the first Application object made in the process.
* NOTE: Only works on the main thread.
*/
public static Application getInitialApplication() {
return ActivityThread.currentApplication();
}
/**
* Return the package name of the first .apk loaded into the process.
* NOTE: Only works on the main thread.
*/
public static String getInitialPackage() {
return ActivityThread.currentPackageName();
}
/**
* Return the raw interface to the package manager.
* @return
*/
public static IPackageManager getPackageManager() {
return ActivityThread.getPackageManager();
}
}

View File

@@ -173,7 +173,7 @@ class ContextImpl extends Context {
new HashMap<File, SharedPreferencesImpl>(); new HashMap<File, SharedPreferencesImpl>();
private AudioManager mAudioManager; private AudioManager mAudioManager;
/*package*/ ActivityThread.PackageInfo mPackageInfo; /*package*/ LoadedApk mPackageInfo;
private Resources mResources; private Resources mResources;
/*package*/ ActivityThread mMainThread; /*package*/ ActivityThread mMainThread;
private Context mOuterContext; private Context mOuterContext;
@@ -696,7 +696,7 @@ class ContextImpl extends Context {
if (scheduler == null) { if (scheduler == null) {
scheduler = mMainThread.getHandler(); scheduler = mMainThread.getHandler();
} }
rd = new ActivityThread.PackageInfo.ReceiverDispatcher( rd = new LoadedApk.ReceiverDispatcher(
resultReceiver, getOuterContext(), scheduler, null, false).getIIntentReceiver(); resultReceiver, getOuterContext(), scheduler, null, false).getIIntentReceiver();
} }
} }
@@ -739,7 +739,7 @@ class ContextImpl extends Context {
if (scheduler == null) { if (scheduler == null) {
scheduler = mMainThread.getHandler(); scheduler = mMainThread.getHandler();
} }
rd = new ActivityThread.PackageInfo.ReceiverDispatcher( rd = new LoadedApk.ReceiverDispatcher(
resultReceiver, getOuterContext(), scheduler, null, false).getIIntentReceiver(); resultReceiver, getOuterContext(), scheduler, null, false).getIIntentReceiver();
} }
} }
@@ -795,7 +795,7 @@ class ContextImpl extends Context {
if (scheduler == null) { if (scheduler == null) {
scheduler = mMainThread.getHandler(); scheduler = mMainThread.getHandler();
} }
rd = new ActivityThread.PackageInfo.ReceiverDispatcher( rd = new LoadedApk.ReceiverDispatcher(
receiver, context, scheduler, null, true).getIIntentReceiver(); receiver, context, scheduler, null, true).getIIntentReceiver();
} }
} }
@@ -1425,7 +1425,7 @@ class ContextImpl extends Context {
return new ContextImpl(mMainThread.getSystemContext()); return new ContextImpl(mMainThread.getSystemContext());
} }
ActivityThread.PackageInfo pi = LoadedApk pi =
mMainThread.getPackageInfo(packageName, flags); mMainThread.getPackageInfo(packageName, flags);
if (pi != null) { if (pi != null) {
ContextImpl c = new ContextImpl(); ContextImpl c = new ContextImpl();
@@ -1492,12 +1492,12 @@ class ContextImpl extends Context {
mOuterContext = this; mOuterContext = this;
} }
final void init(ActivityThread.PackageInfo packageInfo, final void init(LoadedApk packageInfo,
IBinder activityToken, ActivityThread mainThread) { IBinder activityToken, ActivityThread mainThread) {
init(packageInfo, activityToken, mainThread, null); init(packageInfo, activityToken, mainThread, null);
} }
final void init(ActivityThread.PackageInfo packageInfo, final void init(LoadedApk packageInfo,
IBinder activityToken, ActivityThread mainThread, IBinder activityToken, ActivityThread mainThread,
Resources container) { Resources container) {
mPackageInfo = packageInfo; mPackageInfo = packageInfo;

File diff suppressed because it is too large Load Diff

View File

@@ -18,6 +18,7 @@ package android.content;
import android.accounts.Account; import android.accounts.Account;
import android.app.ActivityThread; import android.app.ActivityThread;
import android.app.AppGlobals;
import android.content.pm.PackageManager.NameNotFoundException; import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.AssetFileDescriptor; import android.content.res.AssetFileDescriptor;
import android.content.res.Resources; import android.content.res.Resources;
@@ -1306,7 +1307,7 @@ public abstract class ContentResolver {
// ActivityThread.currentPackageName() only returns non-null if the // ActivityThread.currentPackageName() only returns non-null if the
// current thread is an application main thread. This parameter tells // current thread is an application main thread. This parameter tells
// us whether an event loop is blocked, and if so, which app it is. // us whether an event loop is blocked, and if so, which app it is.
String blockingPackage = ActivityThread.currentPackageName(); String blockingPackage = AppGlobals.getInitialPackage();
EventLog.writeEvent( EventLog.writeEvent(
EventLogTags.CONTENT_QUERY_SAMPLE, EventLogTags.CONTENT_QUERY_SAMPLE,
@@ -1329,7 +1330,7 @@ public abstract class ContentResolver {
} }
} }
} }
String blockingPackage = ActivityThread.currentPackageName(); String blockingPackage = AppGlobals.getInitialPackage();
EventLog.writeEvent( EventLog.writeEvent(
EventLogTags.CONTENT_UPDATE_SAMPLE, EventLogTags.CONTENT_UPDATE_SAMPLE,
uri.toString(), uri.toString(),

View File

@@ -19,6 +19,7 @@ package android.database.sqlite;
import com.google.android.collect.Maps; import com.google.android.collect.Maps;
import android.app.ActivityThread; import android.app.ActivityThread;
import android.app.AppGlobals;
import android.content.ContentValues; import android.content.ContentValues;
import android.database.Cursor; import android.database.Cursor;
import android.database.DatabaseUtils; import android.database.DatabaseUtils;
@@ -1921,7 +1922,7 @@ public class SQLiteDatabase extends SQLiteClosable {
// main thread, or when we are invoked via Binder (e.g. ContentProvider). // main thread, or when we are invoked via Binder (e.g. ContentProvider).
// Hopefully the full path to the database will be informative enough. // Hopefully the full path to the database will be informative enough.
String blockingPackage = ActivityThread.currentPackageName(); String blockingPackage = AppGlobals.getInitialPackage();
if (blockingPackage == null) blockingPackage = ""; if (blockingPackage == null) blockingPackage = "";
EventLog.writeEvent( EventLog.writeEvent(

View File

@@ -19,7 +19,7 @@
package com.google.android.gles_jni; package com.google.android.gles_jni;
import android.app.ActivityThread; import android.app.AppGlobals;
import android.content.pm.ApplicationInfo; import android.content.pm.ApplicationInfo;
import android.content.pm.IPackageManager; import android.content.pm.IPackageManager;
import android.os.Build; import android.os.Build;
@@ -65,7 +65,7 @@ public class GLImpl implements GL10, GL10Ext, GL11, GL11Ext, GL11ExtensionPack {
private static boolean allowIndirectBuffers(String appName) { private static boolean allowIndirectBuffers(String appName) {
boolean result = false; boolean result = false;
int version = 0; int version = 0;
IPackageManager pm = ActivityThread.getPackageManager(); IPackageManager pm = AppGlobals.getPackageManager();
try { try {
ApplicationInfo applicationInfo = pm.getApplicationInfo(appName, 0); ApplicationInfo applicationInfo = pm.getApplicationInfo(appName, 0);
if (applicationInfo != null) { if (applicationInfo != null) {

View File

@@ -17,8 +17,8 @@
package com.android.server; package com.android.server;
import android.app.ActivityManagerNative; import android.app.ActivityManagerNative;
import android.app.ActivityThread;
import android.app.AlarmManager; import android.app.AlarmManager;
import android.app.AppGlobals;
import android.app.IActivityManager; import android.app.IActivityManager;
import android.app.IApplicationThread; import android.app.IApplicationThread;
import android.app.IBackupAgent; import android.app.IBackupAgent;
@@ -399,7 +399,7 @@ class BackupManagerService extends IBackupManager.Stub {
public BackupManagerService(Context context) { public BackupManagerService(Context context) {
mContext = context; mContext = context;
mPackageManager = context.getPackageManager(); mPackageManager = context.getPackageManager();
mPackageManagerBinder = ActivityThread.getPackageManager(); mPackageManagerBinder = AppGlobals.getPackageManager();
mActivityManager = ActivityManagerNative.getDefault(); mActivityManager = ActivityManagerNative.getDefault();
mAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); mAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);

View File

@@ -42,7 +42,7 @@ import java.util.HashSet;
/** /**
* An entry in the history stack, representing an activity. * An entry in the history stack, representing an activity.
*/ */
class HistoryRecord extends IApplicationToken.Stub { class ActivityRecord extends IApplicationToken.Stub {
final ActivityManagerService service; // owner final ActivityManagerService service; // owner
final ActivityInfo info; // all about me final ActivityInfo info; // all about me
final int launchedFromUid; // always the uid who started the activity. final int launchedFromUid; // always the uid who started the activity.
@@ -68,7 +68,7 @@ class HistoryRecord extends IApplicationToken.Stub {
long startTime; // when we starting launching this activity long startTime; // when we starting launching this activity
long cpuTimeAtResume; // the cpu time of host process at the time of resuming activity long cpuTimeAtResume; // the cpu time of host process at the time of resuming activity
Configuration configuration; // configuration activity was last running in Configuration configuration; // configuration activity was last running in
HistoryRecord resultTo; // who started this entry, so will get our reply ActivityRecord resultTo; // who started this entry, so will get our reply
final String resultWho; // additional identifier for use by resultTo. final String resultWho; // additional identifier for use by resultTo.
final int requestCode; // code given by requester (resultTo) final int requestCode; // code given by requester (resultTo)
ArrayList results; // pending ActivityResult objs we have received ArrayList results; // pending ActivityResult objs we have received
@@ -175,10 +175,10 @@ class HistoryRecord extends IApplicationToken.Stub {
} }
} }
HistoryRecord(ActivityManagerService _service, ProcessRecord _caller, ActivityRecord(ActivityManagerService _service, ProcessRecord _caller,
int _launchedFromUid, Intent _intent, String _resolvedType, int _launchedFromUid, Intent _intent, String _resolvedType,
ActivityInfo aInfo, Configuration _configuration, ActivityInfo aInfo, Configuration _configuration,
HistoryRecord _resultTo, String _resultWho, int _reqCode, ActivityRecord _resultTo, String _resultWho, int _reqCode,
boolean _componentSpecified) { boolean _componentSpecified) {
service = _service; service = _service;
info = aInfo; info = aInfo;
@@ -297,7 +297,7 @@ class HistoryRecord extends IApplicationToken.Stub {
} }
} }
void addResultLocked(HistoryRecord from, String resultWho, void addResultLocked(ActivityRecord from, String resultWho,
int requestCode, int resultCode, int requestCode, int resultCode,
Intent resultData) { Intent resultData) {
ActivityResult r = new ActivityResult(from, resultWho, ActivityResult r = new ActivityResult(from, resultWho,
@@ -308,7 +308,7 @@ class HistoryRecord extends IApplicationToken.Stub {
results.add(r); results.add(r);
} }
void removeResultsLocked(HistoryRecord from, String resultWho, void removeResultsLocked(ActivityRecord from, String resultWho,
int requestCode) { int requestCode) {
if (results != null) { if (results != null) {
for (int i=results.size()-1; i>=0; i--) { for (int i=results.size()-1; i>=0; i--) {
@@ -418,7 +418,7 @@ class HistoryRecord extends IApplicationToken.Stub {
final int N = service.mWaitingVisibleActivities.size(); final int N = service.mWaitingVisibleActivities.size();
if (N > 0) { if (N > 0) {
for (int i=0; i<N; i++) { for (int i=0; i<N; i++) {
HistoryRecord r = (HistoryRecord) ActivityRecord r = (ActivityRecord)
service.mWaitingVisibleActivities.get(i); service.mWaitingVisibleActivities.get(i);
r.waitingVisible = false; r.waitingVisible = false;
if (ActivityManagerService.DEBUG_SWITCH) Log.v( if (ActivityManagerService.DEBUG_SWITCH) Log.v(
@@ -442,11 +442,11 @@ class HistoryRecord extends IApplicationToken.Stub {
nowVisible = false; nowVisible = false;
} }
private HistoryRecord getWaitingHistoryRecordLocked() { private ActivityRecord getWaitingHistoryRecordLocked() {
// First find the real culprit... if we are waiting // First find the real culprit... if we are waiting
// for another app to start, then we have paused dispatching // for another app to start, then we have paused dispatching
// for this activity. // for this activity.
HistoryRecord r = this; ActivityRecord r = this;
if (r.waitingVisible) { if (r.waitingVisible) {
// Hmmm, who might we be waiting for? // Hmmm, who might we be waiting for?
r = service.mResumedActivity; r = service.mResumedActivity;
@@ -463,7 +463,7 @@ class HistoryRecord extends IApplicationToken.Stub {
} }
public boolean keyDispatchingTimedOut() { public boolean keyDispatchingTimedOut() {
HistoryRecord r; ActivityRecord r;
ProcessRecord anrApp = null; ProcessRecord anrApp = null;
synchronized(service) { synchronized(service) {
r = getWaitingHistoryRecordLocked(); r = getWaitingHistoryRecordLocked();
@@ -501,7 +501,7 @@ class HistoryRecord extends IApplicationToken.Stub {
/** Returns the key dispatching timeout for this application token. */ /** Returns the key dispatching timeout for this application token. */
public long getKeyDispatchingTimeout() { public long getKeyDispatchingTimeout() {
synchronized(service) { synchronized(service) {
HistoryRecord r = getWaitingHistoryRecordLocked(); ActivityRecord r = getWaitingHistoryRecordLocked();
if (r == null || r.app == null if (r == null || r.app == null
|| r.app.instrumentationClass == null) { || r.app.instrumentationClass == null) {
return ActivityManagerService.KEY_DISPATCHING_TIMEOUT; return ActivityManagerService.KEY_DISPATCHING_TIMEOUT;

View File

@@ -24,9 +24,9 @@ import android.os.Bundle;
* Pending result information to send back to an activity. * Pending result information to send back to an activity.
*/ */
class ActivityResult extends ResultInfo { class ActivityResult extends ResultInfo {
final HistoryRecord mFrom; final ActivityRecord mFrom;
public ActivityResult(HistoryRecord from, String resultWho, public ActivityResult(ActivityRecord from, String resultWho,
int requestCode, int resultCode, Intent data) { int requestCode, int resultCode, Intent data) {
super(resultWho, requestCode, resultCode, data); super(resultWho, requestCode, resultCode, data);
mFrom = from; mFrom = from;

View File

@@ -40,7 +40,7 @@ class AppNotRespondingDialog extends BaseErrorDialog {
private final ProcessRecord mProc; private final ProcessRecord mProc;
public AppNotRespondingDialog(ActivityManagerService service, Context context, public AppNotRespondingDialog(ActivityManagerService service, Context context,
ProcessRecord app, HistoryRecord activity) { ProcessRecord app, ActivityRecord activity) {
super(context); super(context);
mService = service; mService = service;

View File

@@ -26,7 +26,7 @@ import java.io.PrintWriter;
*/ */
class ConnectionRecord { class ConnectionRecord {
final AppBindRecord binding; // The application/service binding. final AppBindRecord binding; // The application/service binding.
final HistoryRecord activity; // If non-null, the owning activity. final ActivityRecord activity; // If non-null, the owning activity.
final IServiceConnection conn; // The client connection. final IServiceConnection conn; // The client connection.
final int flags; // Binding options. final int flags; // Binding options.
final int clientLabel; // String resource labeling this client. final int clientLabel; // String resource labeling this client.
@@ -42,7 +42,7 @@ class ConnectionRecord {
+ " flags=0x" + Integer.toHexString(flags)); + " flags=0x" + Integer.toHexString(flags));
} }
ConnectionRecord(AppBindRecord _binding, HistoryRecord _activity, ConnectionRecord(AppBindRecord _binding, ActivityRecord _activity,
IServiceConnection _conn, int _flags, IServiceConnection _conn, int _flags,
int _clientLabel, PendingIntent _clientIntent) { int _clientLabel, PendingIntent _clientIntent) {
binding = _binding; binding = _binding;

View File

@@ -42,7 +42,7 @@ class PendingIntentRecord extends IIntentSender.Stub {
final static class Key { final static class Key {
final int type; final int type;
final String packageName; final String packageName;
final HistoryRecord activity; final ActivityRecord activity;
final String who; final String who;
final int requestCode; final int requestCode;
final Intent requestIntent; final Intent requestIntent;
@@ -52,7 +52,7 @@ class PendingIntentRecord extends IIntentSender.Stub {
private static final int ODD_PRIME_NUMBER = 37; private static final int ODD_PRIME_NUMBER = 37;
Key(int _t, String _p, HistoryRecord _a, String _w, Key(int _t, String _p, ActivityRecord _a, String _w,
int _r, Intent _i, String _it, int _f) { int _r, Intent _i, String _it, int _f) {
type = _t; type = _t;
packageName = _p; packageName = _p;

View File

@@ -86,7 +86,7 @@ class ProcessRecord implements Watchdog.PssRequestor {
Object adjTarget; // Debugging: target component impacting oom_adj. Object adjTarget; // Debugging: target component impacting oom_adj.
// contains HistoryRecord objects // contains HistoryRecord objects
final ArrayList<HistoryRecord> activities = new ArrayList<HistoryRecord>(); final ArrayList<ActivityRecord> activities = new ArrayList<ActivityRecord>();
// all ServiceRecord running in this process // all ServiceRecord running in this process
final HashSet<ServiceRecord> services = new HashSet<ServiceRecord>(); final HashSet<ServiceRecord> services = new HashSet<ServiceRecord>();
// services that are currently executing code (need to remain foreground). // services that are currently executing code (need to remain foreground).
@@ -248,7 +248,7 @@ class ProcessRecord implements Watchdog.PssRequestor {
public boolean isInterestingToUserLocked() { public boolean isInterestingToUserLocked() {
final int size = activities.size(); final int size = activities.size();
for (int i = 0 ; i < size ; i++) { for (int i = 0 ; i < size ; i++) {
HistoryRecord r = activities.get(i); ActivityRecord r = activities.get(i);
if (r.isInterestingToUserLocked()) { if (r.isInterestingToUserLocked()) {
return true; return true;
} }

View File

@@ -27,8 +27,8 @@ class UriPermission {
final Uri uri; final Uri uri;
int modeFlags = 0; int modeFlags = 0;
int globalModeFlags = 0; int globalModeFlags = 0;
final HashSet<HistoryRecord> readActivities = new HashSet<HistoryRecord>(); final HashSet<ActivityRecord> readActivities = new HashSet<ActivityRecord>();
final HashSet<HistoryRecord> writeActivities = new HashSet<HistoryRecord>(); final HashSet<ActivityRecord> writeActivities = new HashSet<ActivityRecord>();
String stringName; String stringName;
@@ -42,7 +42,7 @@ class UriPermission {
globalModeFlags &= ~Intent.FLAG_GRANT_READ_URI_PERMISSION; globalModeFlags &= ~Intent.FLAG_GRANT_READ_URI_PERMISSION;
modeFlags &= ~Intent.FLAG_GRANT_READ_URI_PERMISSION; modeFlags &= ~Intent.FLAG_GRANT_READ_URI_PERMISSION;
if (readActivities.size() > 0) { if (readActivities.size() > 0) {
for (HistoryRecord r : readActivities) { for (ActivityRecord r : readActivities) {
r.readUriPermissions.remove(this); r.readUriPermissions.remove(this);
if (r.readUriPermissions.size() == 0) { if (r.readUriPermissions.size() == 0) {
r.readUriPermissions = null; r.readUriPermissions = null;
@@ -55,7 +55,7 @@ class UriPermission {
globalModeFlags &= ~Intent.FLAG_GRANT_WRITE_URI_PERMISSION; globalModeFlags &= ~Intent.FLAG_GRANT_WRITE_URI_PERMISSION;
modeFlags &= ~Intent.FLAG_GRANT_WRITE_URI_PERMISSION; modeFlags &= ~Intent.FLAG_GRANT_WRITE_URI_PERMISSION;
if (readActivities.size() > 0) { if (readActivities.size() > 0) {
for (HistoryRecord r : readActivities) { for (ActivityRecord r : readActivities) {
r.writeUriPermissions.remove(this); r.writeUriPermissions.remove(this);
if (r.writeUriPermissions.size() == 0) { if (r.writeUriPermissions.size() == 0) {
r.writeUriPermissions = null; r.writeUriPermissions = null;