FileDocCategorySizeDatePackage
HistoryRecord.javaAPI DocAndroid 1.5 API20716Wed May 06 22:42:00 BST 2009com.android.server.am

HistoryRecord

public class HistoryRecord extends IApplicationToken.Stub
An entry in the history stack, representing an activity.

Fields Summary
final ActivityManagerService
service
final android.content.pm.ActivityInfo
info
final int
launchedFromUid
final android.content.Intent
intent
final android.content.ComponentName
realActivity
final String
shortComponentName
final String
resolvedType
final String
packageName
final String
processName
final String
taskAffinity
final boolean
stateNotNeeded
final boolean
fullscreen
final boolean
componentSpecified
final boolean
isHomeActivity
final String
baseDir
final String
resDir
final String
dataDir
CharSequence
nonLocalizedLabel
int
labelRes
int
icon
int
theme
TaskRecord
task
long
startTime
android.content.res.Configuration
configuration
HistoryRecord
resultTo
final String
resultWho
final int
requestCode
ArrayList
results
HashSet
pendingResults
ArrayList
newIntents
HashSet
connections
HashSet
readUriPermissions
HashSet
writeUriPermissions
ProcessRecord
app
android.graphics.Bitmap
thumbnail
CharSequence
description
com.android.server.am.ActivityManagerService.ActivityState
state
android.os.Bundle
icicle
boolean
frontOfTask
boolean
launchFailed
boolean
haveState
boolean
stopped
boolean
finishing
boolean
configDestroy
int
configChangeFlags
boolean
keysPaused
boolean
inHistory
boolean
persistent
int
launchMode
boolean
visible
boolean
waitingVisible
boolean
nowVisible
boolean
thumbnailNeeded
boolean
idle
boolean
hasBeenLaunched
boolean
frozenBeforeDestroy
Constructors Summary
HistoryRecord(ActivityManagerService _service, ProcessRecord _caller, int _launchedFromUid, android.content.Intent _intent, String _resolvedType, android.content.pm.ActivityInfo aInfo, android.content.res.Configuration _configuration, HistoryRecord _resultTo, String _resultWho, int _reqCode, boolean _componentSpecified)

        service = _service;
        info = aInfo;
        launchedFromUid = _launchedFromUid;
        intent = _intent;
        shortComponentName = _intent.getComponent().flattenToShortString();
        resolvedType = _resolvedType;
        componentSpecified = _componentSpecified;
        configuration = _configuration;
        resultTo = _resultTo;
        resultWho = _resultWho;
        requestCode = _reqCode;
        state = ActivityManagerService.ActivityState.INITIALIZING;
        frontOfTask = false;
        launchFailed = false;
        haveState = false;
        stopped = false;
        finishing = false;
        configDestroy = false;
        keysPaused = false;
        inHistory = false;
        persistent = false;
        visible = true;
        waitingVisible = false;
        nowVisible = false;
        thumbnailNeeded = false;
        idle = false;
        hasBeenLaunched = false;

        if (aInfo != null) {
            if (aInfo.targetActivity == null
                    || aInfo.launchMode == ActivityInfo.LAUNCH_MULTIPLE
                    || aInfo.launchMode == ActivityInfo.LAUNCH_SINGLE_TOP) {
                realActivity = _intent.getComponent();
            } else {
                realActivity = new ComponentName(aInfo.packageName,
                        aInfo.targetActivity);
            }
            taskAffinity = aInfo.taskAffinity;
            stateNotNeeded = (aInfo.flags&
                    ActivityInfo.FLAG_STATE_NOT_NEEDED) != 0;
            baseDir = aInfo.applicationInfo.sourceDir;
            resDir = aInfo.applicationInfo.publicSourceDir;
            dataDir = aInfo.applicationInfo.dataDir;
            nonLocalizedLabel = aInfo.nonLocalizedLabel;
            labelRes = aInfo.labelRes;
            if (nonLocalizedLabel == null && labelRes == 0) {
                ApplicationInfo app = aInfo.applicationInfo;
                nonLocalizedLabel = app.nonLocalizedLabel;
                labelRes = app.labelRes;
            }
            icon = aInfo.getIconResource();
            theme = aInfo.getThemeResource();
            if ((aInfo.flags&ActivityInfo.FLAG_MULTIPROCESS) != 0
                    && _caller != null
                    && (aInfo.applicationInfo.uid == Process.SYSTEM_UID
                            || aInfo.applicationInfo.uid == _caller.info.uid)) {
                processName = _caller.processName;
            } else {
                processName = aInfo.processName;
            }

            if (intent != null && (aInfo.flags & ActivityInfo.FLAG_EXCLUDE_FROM_RECENTS) != 0) {
                intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
            }
            
            packageName = aInfo.applicationInfo.packageName;
            launchMode = aInfo.launchMode;
            
            AttributeCache.Entry ent = AttributeCache.instance().get(packageName,
                    theme != 0 ? theme : android.R.style.Theme,
                    com.android.internal.R.styleable.Window);
            fullscreen = ent != null && !ent.array.getBoolean(
                    com.android.internal.R.styleable.Window_windowIsFloating, false)
                    && !ent.array.getBoolean(
                    com.android.internal.R.styleable.Window_windowIsTranslucent, false);
            
            if (!_componentSpecified || _launchedFromUid == Process.myUid()
                    || _launchedFromUid == 0) {
                // If we know the system has determined the component, then
                // we can consider this to be a home activity...
                if (Intent.ACTION_MAIN.equals(_intent.getAction()) &&
                        _intent.hasCategory(Intent.CATEGORY_HOME) &&
                        _intent.getCategories().size() == 1 &&
                        _intent.getData() == null &&
                        _intent.getType() == null &&
                        (intent.getFlags()&Intent.FLAG_ACTIVITY_NEW_TASK) != 0 &&
                        !"android".equals(realActivity.getClassName())) {
                    // This sure looks like a home activity!
                    // Note the last check is so we don't count the resolver
                    // activity as being home...  really, we don't care about
                    // doing anything special with something that comes from
                    // the core framework package.
                    isHomeActivity = true;
                } else {
                    isHomeActivity = false;
                }
            } else {
                isHomeActivity = false;
            }
        } else {
            realActivity = null;
            taskAffinity = null;
            stateNotNeeded = false;
            baseDir = null;
            resDir = null;
            dataDir = null;
            processName = null;
            packageName = null;
            fullscreen = true;
            isHomeActivity = false;
        }
    
Methods Summary
voidaddNewIntentLocked(android.content.Intent intent)

        if (newIntents == null) {
            newIntents = new ArrayList();
        }
        newIntents.add(intent);
    
voidaddResultLocked(com.android.server.am.HistoryRecord from, java.lang.String resultWho, int requestCode, int resultCode, android.content.Intent resultData)

        ActivityResult r = new ActivityResult(from, resultWho,
        		requestCode, resultCode, resultData);
        if (results == null) {
            results = new ArrayList();
        }
        results.add(r);
    
voiddump(java.io.PrintWriter pw, java.lang.String prefix)

        pw.println(prefix + this);
        pw.println(prefix + "packageName=" + packageName
              + " processName=" + processName);
        pw.println(prefix + "launchedFromUid=" + launchedFromUid
                + " app=" + app);
        pw.println(prefix + intent);
        pw.println(prefix + "frontOfTask=" + frontOfTask + " task=" + task);
        pw.println(prefix + "taskAffinity=" + taskAffinity);
        pw.println(prefix + "realActivity=" + realActivity);
        pw.println(prefix + "dir=" + baseDir + " res=" + resDir + " data=" + dataDir);
        pw.println(prefix + "labelRes=0x" + Integer.toHexString(labelRes)
                + " icon=0x" + Integer.toHexString(icon)
                + " theme=0x" + Integer.toHexString(theme));
        pw.println(prefix + "stateNotNeeded=" + stateNotNeeded
                + " componentSpecified=" + componentSpecified
                + " isHomeActivity=" + isHomeActivity);
        pw.println(prefix + "configuration=" + configuration);
        pw.println(prefix + "resultTo=" + resultTo
              + " resultWho=" + resultWho + " resultCode=" + requestCode);
        pw.println(prefix + "results=" + results);
        pw.println(prefix + "pendingResults=" + pendingResults);
        pw.println(prefix + "readUriPermissions=" + readUriPermissions);
        pw.println(prefix + "writeUriPermissions=" + writeUriPermissions);
        pw.println(prefix + "launchFailed=" + launchFailed
              + " haveState=" + haveState + " icicle=" + icicle);
        pw.println(prefix + "state=" + state
              + " stopped=" + stopped + " finishing=" + finishing);
        pw.println(prefix + "keysPaused=" + keysPaused
              + " inHistory=" + inHistory + " persistent=" + persistent
              + " launchMode=" + launchMode);
        pw.println(prefix + "fullscreen=" + fullscreen
              + " visible=" + visible
              + " frozenBeforeDestroy=" + frozenBeforeDestroy
              + " thumbnailNeeded=" + thumbnailNeeded + " idle=" + idle);
        pw.println(prefix + "waitingVisible=" + waitingVisible
              + " nowVisible=" + nowVisible);
        pw.println(prefix + "configDestroy=" + configDestroy
                + " configChangeFlags=" + Integer.toHexString(configChangeFlags));
        pw.println(prefix + "connections=" + connections);
    
public longgetKeyDispatchingTimeout()
Returns the key dispatching timeout for this application token.

        synchronized(service) {
            HistoryRecord r = getWaitingHistoryRecordLocked();
            if (r == null || r.app == null
                    || r.app.instrumentationClass == null) {
                return ActivityManagerService.KEY_DISPATCHING_TIMEOUT;
            }
            
            return ActivityManagerService.INSTRUMENTATION_KEY_DISPATCHING_TIMEOUT;
        }
    
private com.android.server.am.HistoryRecordgetWaitingHistoryRecordLocked()

        // First find the real culprit...  if we are waiting
        // for another app to start, then we have paused dispatching
        // for this activity.
        HistoryRecord r = this;
        if (r.waitingVisible) {
            // Hmmm, who might we be waiting for?
            r = service.mResumedActivity;
            if (r == null) {
                r = service.mPausingActivity;
            }
            // Both of those null?  Fall back to 'this' again
            if (r == null) {
                r = this;
            }
        }
        
        return r;
    
public booleanisInterestingToUserLocked()
This method will return true if the activity is either visible, is becoming visible, is currently pausing, or is resumed.

        return visible || nowVisible || state == ActivityState.PAUSING || 
                state == ActivityState.RESUMED;
     
public booleankeyDispatchingTimedOut()

        synchronized(service) {
            HistoryRecord r = getWaitingHistoryRecordLocked();
            if (r != null && r.app != null) {
                if (r.app.debugging) {
                    return false;
                }
                
                if (r.app.instrumentationClass == null) { 
                    service.appNotRespondingLocked(r.app, r, "keyDispatchingTimedOut");
                } else {
                    Bundle info = new Bundle();
                    info.putString("shortMsg", "keyDispatchingTimedOut");
                    info.putString("longMsg", "Timed out while dispatching key event");
                    service.finishInstrumentationLocked(
                            r.app, Activity.RESULT_CANCELED, info);
                }
            }
            return true;
        }
    
public booleanmayFreezeScreenLocked(ProcessRecord app)

        // Only freeze the screen if this activity is currently attached to
        // an application, and that application is not blocked or unresponding.
        // In any other case, we can't count on getting the screen unfrozen,
        // so it is best to leave as-is.
        return app == null || (!app.crashing && !app.notResponding);
    
voidpauseKeyDispatchingLocked()

        if (!keysPaused) {
            keysPaused = true;
            service.mWindowManager.pauseKeyDispatching(this);
        }
    
voidremoveResultsLocked(com.android.server.am.HistoryRecord from, java.lang.String resultWho, int requestCode)

        if (results != null) {
            for (int i=results.size()-1; i>=0; i--) {
                ActivityResult r = (ActivityResult)results.get(i);
                if (r.mFrom != from) continue;
                if (r.mResultWho == null) {
                    if (resultWho != null) continue;
                } else {
                    if (!r.mResultWho.equals(resultWho)) continue;
                }
                if (r.mRequestCode != requestCode) continue;

                results.remove(i);
            }
        }
    
voidresumeKeyDispatchingLocked()

        if (keysPaused) {
            keysPaused = false;
            service.mWindowManager.resumeKeyDispatching(this);
        }
    
public voidstartFreezingScreenLocked(ProcessRecord app, int configChanges)

        if (mayFreezeScreenLocked(app)) {
            service.mWindowManager.startAppFreezingScreen(this, configChanges);
        }
    
public voidstopFreezingScreenLocked(boolean force)

        if (force || frozenBeforeDestroy) {
            frozenBeforeDestroy = false;
            service.mWindowManager.stopAppFreezingScreen(this, force);
        }
    
public java.lang.StringtoString()

        return "HistoryRecord{"
            + Integer.toHexString(System.identityHashCode(this))
            + " " + intent.getComponent().toShortString() + "}";
    
public voidwindowsGone()

        if (ActivityManagerService.DEBUG_SWITCH) Log.v(
                ActivityManagerService.TAG, "windowsGone(): " + this);
        nowVisible = false;
    
public voidwindowsVisible()

        synchronized(service) {
            if (ActivityManagerService.SHOW_ACTIVITY_START_TIME
                    && startTime != 0) {
                long time = SystemClock.uptimeMillis() - startTime;
                EventLog.writeEvent(ActivityManagerService.LOG_ACTIVITY_LAUNCH_TIME,
                        System.identityHashCode(this), shortComponentName, time);
                Log.i(ActivityManagerService.TAG, "Displayed activity "
                        + shortComponentName
                        + ": " + time + " ms");
                startTime = 0;
            }
            if (ActivityManagerService.DEBUG_SWITCH) Log.v(
                    ActivityManagerService.TAG, "windowsVisible(): " + this);
            if (!nowVisible) {
                nowVisible = true;
                if (!idle) {
                    // Instead of doing the full stop routine here, let's just
                    // hide any activities we now can, and let them stop when
                    // the normal idle happens.
                    service.processStoppingActivitiesLocked(false);
                } else {
                    // If this activity was already idle, then we now need to
                    // make sure we perform the full stop of any activities
                    // that are waiting to do so.  This is because we won't
                    // do that while they are still waiting for this one to
                    // become visible.
                    final int N = service.mWaitingVisibleActivities.size();
                    if (N > 0) {
                        for (int i=0; i<N; i++) {
                            HistoryRecord r = (HistoryRecord)
                                service.mWaitingVisibleActivities.get(i);
                            r.waitingVisible = false;
                            if (ActivityManagerService.DEBUG_SWITCH) Log.v(
                                    ActivityManagerService.TAG,
                                    "Was waiting for visible: " + r);
                        }
                        service.mWaitingVisibleActivities.clear();
                        Message msg = Message.obtain();
                        msg.what = ActivityManagerService.IDLE_NOW_MSG;
                        service.mHandler.sendMessage(msg);
                    }
                }
                service.scheduleAppGcsLocked();
            }
        }