yashsingh1/xdaforums huggingface dataset:
[Android Software/Hacking General [Developers Only]] llrraa2010:
start of Activity--start of MainActivity--Step 5

Step 5. ActivityManagerProxy.startActivity

frameworks/base/core/java/android/app/ActivityManagerNative.java

class ActivityManagerProxy implements IActivityManager
{

......

public int startActivity(IApplicationThread caller, Intent intent,
String resolvedType, Uri[] grantedUriPermissions, int grantedMode,
IBinder resultTo, String resultWho,
int requestCode, boolean onlyIfNeeded,
boolean debug) throws RemoteException {
Parcel data = Parcel.obtain();
Parcel reply = Parcel.obtain();
data.writeInterfaceToken(IActivityManager.descriptor);
data.writeStrongBinder(caller != null ? caller.asBinder() : null);
intent.writeToParcel(data, 0);
data.writeString(resolvedType);
data.writeTypedArray(grantedUriPermissions, 0);
data.writeInt(grantedMode);
data.writeStrongBinder(resultTo);
data.writeString(resultWho);
data.writeInt(requestCode);
data.writeInt(onlyIfNeeded ? 1 : 0);
data.writeInt(debug ? 1 : 0);
mRemote.transact(START_ACTIVITY_TRANSACTION, data, reply, 0);
reply.readException();
int result = reply.readInt();
reply.recycle();
data.recycle();
return result;
}

......

}
[Android Software/Hacking General [Developers Only]] llrraa2010:
start of Activity--start of MainActivity--Step 6

Step 6. ActivityManagerService.startActivity

frameworks/base/services/java/com/android/server/am/ActivityManagerService.java

public final class ActivityManagerService extends ActivityManagerNative
implements Watchdog.Monitor, BatteryStatsImpl.BatteryCallback {

......

public final int startActivity(IApplicationThread caller,
Intent intent, String resolvedType, Uri[] grantedUriPermissions,
int grantedMode, IBinder resultTo,
String resultWho, int requestCode, boolean onlyIfNeeded,
boolean debug) {
return mMainStack.startActivityMayWait(caller, intent, resolvedType,
grantedUriPermissions, grantedMode, resultTo, resultWho,
requestCode, onlyIfNeeded, debug, null, null);
}

......

}
[Android Software/Hacking General [Developers Only]] llrraa2010:
start of Activity--start of MainActivity--Step 7

Step 7. ActivityStack.startActivityMayWait

frameworks/base/services/java/com/android/server/am/ActivityStack.java

public class ActivityStack {

......

final int startActivityMayWait(IApplicationThread caller,
Intent intent, String resolvedType, Uri[] grantedUriPermissions,
int grantedMode, IBinder resultTo,
String resultWho, int requestCode, boolean onlyIfNeeded,
boolean debug, WaitResult outResult, Configuration config) {

......

boolean componentSpecified = intent.getComponent() != null;

// Don't modify the client's object!
intent = new Intent(intent);

// Collect information about the target of the Intent.
ActivityInfo aInfo;
try {
ResolveInfo rInfo =
AppGlobals.getPackageManager().resolveIntent(
intent, resolvedType,
PackageManager.MATCH_DEFAULT_ONLY
| ActivityManagerService.STOCK_PM_FLAGS);
aInfo = rInfo != null ? rInfo.activityInfo : null;
} catch (RemoteException e) {
......
}

if (aInfo != null) {
// Store the found target back into the intent, because now that
// we have it we never want to do this again. For example, if the
// user navigates back to this point in the history, we should
// always restart the exact same activity.
intent.setComponent(new ComponentName(
aInfo.applicationInfo.packageName, aInfo.name));
......
}

synchronized (mService) {
int callingPid;
int callingUid;
if (caller == null) {
......
} else {
callingPid = callingUid = -1;
}

mConfigWillChange = config != null
&& mService.mConfiguration.diff(config) != 0;

......

if (mMainStack && aInfo != null &&
(aInfo.applicationInfo.flags&ApplicationInfo.FLAG_CANT_SAVE_STATE) != 0) {

......

}

int res = startActivityLocked(caller, intent, resolvedType,
grantedUriPermissions, grantedMode, aInfo,
resultTo, resultWho, requestCode, callingPid, callingUid,
onlyIfNeeded, componentSpecified);

if (mConfigWillChange && mMainStack) {
......
}

......

if (outResult != null) {
......
}

return res;
}

}

......

}
[Android Software/Hacking General [Developers Only]] llrraa2010:
start of Activity--start of MainActivity--Step 8

Step 8. ActivityStack.startActivityLocked

frameworks/base/services/java/com/android/server/am/ActivityStack.java

public class ActivityStack {

......

final int startActivityLocked(IApplicationThread caller,
Intent intent, String resolvedType,
Uri[] grantedUriPermissions,
int grantedMode, ActivityInfo aInfo, IBinder resultTo,
String resultWho, int requestCode,
int callingPid, int callingUid, boolean onlyIfNeeded,
boolean componentSpecified) {
int err = START_SUCCESS;

ProcessRecord callerApp = null;
if (caller != null) {
callerApp = mService.getRecordForAppLocked(caller);
if (callerApp != null) {
callingPid = callerApp.pid;
callingUid = callerApp.info.uid;
} else {
......
}
}

......

ActivityRecord sourceRecord = null;
ActivityRecord resultRecord = null;
if (resultTo != null) {
int index = indexOfTokenLocked(resultTo);

......

if (index >= 0) {
sourceRecord = (ActivityRecord)mHistory.get(index);
if (requestCode >= 0 && !sourceRecord.finishing) {
......
}
}
}

int launchFlags = intent.getFlags();

if ((launchFlags&Intent.FLAG_ACTIVITY_FORWARD_RESULT) != 0
&& sourceRecord != null) {
......
}

if (err == START_SUCCESS && intent.getComponent() == null) {
......
}

if (err == START_SUCCESS && aInfo == null) {
......
}

if (err != START_SUCCESS) {
......
}

......

ActivityRecord r = new ActivityRecord(mService, this, callerApp, callingUid,
intent, resolvedType, aInfo, mService.mConfiguration,
resultRecord, resultWho, requestCode, componentSpecified);

......

return startActivityUncheckedLocked(r, sourceRecord,
grantedUriPermissions, grantedMode, onlyIfNeeded, true);
}

......

}
[Android Software/Hacking General [Developers Only]] llrraa2010:
start of Activity--start of MainActivity--Step 10

Step 10. Activity.resumeTopActivityLocked

frameworks/base/services/java/com/android/server/am/ActivityStack.java

public class ActivityStack {

......

/**
* Ensure that the top activity in the stack is resumed.
*
* [MENTION=955119]param[/MENTION] prev The previously resumed activity, for when in the process
* of pausing; can be null to call from elsewhere.
*
* [MENTION=2056652]return[/MENTION] Returns true if something is being resumed, or false if
* nothing happened.
*/
final boolean resumeTopActivityLocked(ActivityRecord prev) {
// Find the first activity that is not finishing.
ActivityRecord next = topRunningActivityLocked(null);

// Remember how we'll process this pause/resume situation, and ensure
// that the state is reset however we wind up proceeding.
final boolean userLeaving = mUserLeaving;
mUserLeaving = false;

if (next == null) {
......
}

next.delayedResume = false;

// If the top activity is the resumed one, nothing to do.
if (mResumedActivity == next && next.state == ActivityState.RESUMED) {
......
}

// If we are sleeping, and there is no resumed activity, and the top
// activity is paused, well that is the state we want.
if ((mService.mSleeping || mService.mShuttingDown)
&& mLastPausedActivity == next && next.state == ActivityState.PAUSED) {
......
}

......

// If we are currently pausing an activity, then don't do anything
// until that is done.
if (mPausingActivity != null) {
......
}

......

// We need to start pausing the current activity so the top one
// can be resumed...
if (mResumedActivity != null) {
......
startPausingLocked(userLeaving, false);
return true;
}

......
}

......

}
[Android Software/Hacking General [Developers Only]] llrraa2010:
start of Activity--start of MainActivity--Step 11

Step 11. ActivityStack.startPausingLocked

frameworks/base/services/java/com/android/server/am/ActivityStack.java

public class ActivityStack {

......

private final void startPausingLocked(boolean userLeaving, boolean uiSleeping) {
if (mPausingActivity != null) {
......
}
ActivityRecord prev = mResumedActivity;
if (prev == null) {
......
}
......
mResumedActivity = null;
mPausingActivity = prev;
mLastPausedActivity = prev;
prev.state = ActivityState.PAUSING;
......

if (prev.app != null && prev.app.thread != null) {
......
try {
......
prev.app.thread.schedulePauseActivity(prev, prev.finishing, userLeaving,
prev.configChangeFlags);
......
} catch (Exception e) {
......
}
} else {
......
}

......

}

......

}
[Android Software/Hacking General [Developers Only]] llrraa2010:
start of Activity--start of MainActivity--Step 12

Step 12. ApplicationThreadProxy.schedulePauseActivity

frameworks/base/core/java/android/app/ApplicationThreadNative.java

class ApplicationThreadProxy implements IApplicationThread {

......

public final void schedulePauseActivity(IBinder token, boolean finished,
boolean userLeaving, int configChanges) throws RemoteException {
Parcel data = Parcel.obtain();
data.writeInterfaceToken(IApplicationThread.descriptor);
data.writeStrongBinder(token);
data.writeInt(finished ? 1 : 0);
data.writeInt(userLeaving ? 1 :0);
data.writeInt(configChanges);
mRemote.transact(SCHEDULE_PAUSE_ACTIVITY_TRANSACTION, data, null,
IBinder.FLAG_ONEWAY);
data.recycle();
}

......

}
[Android Software/Hacking General [Developers Only]] llrraa2010:
start of Activity--start of MainActivity--Step 13

Step 13. ApplicationThread.schedulePauseActivity

frameworks/base/core/java/android/app/ActivityThread.java

public final class ActivityThread {

......

private final class ApplicationThread extends ApplicationThreadNative {

......

public final void schedulePauseActivity(IBinder token, boolean finished,
boolean userLeaving, int configChanges) {
queueOrSendMessage(
finished ? H.PAUSE_ACTIVITY_FINISHING : H.PAUSE_ACTIVITY,
token,
(userLeaving ? 1 : 0),
configChanges);
}

......

}

......

}
[Android Software/Hacking General [Developers Only]] llrraa2010:
start of Activity--start of MainActivity--Step 14

Step 14. ActivityThread.queueOrSendMessage

frameworks/base/core/java/android/app/ActivityThread.java

public final class ActivityThread {

......

private final void queueOrSendMessage(int what, Object obj, int arg1) {
queueOrSendMessage(what, obj, arg1, 0);
}

private final void queueOrSendMessage(int what, Object obj, int arg1, int arg2) {
synchronized (this) {
......
Message msg = Message.obtain();
msg.what = what;
msg.obj = obj;
msg.arg1 = arg1;
msg.arg2 = arg2;
mH.sendMessage(msg);
}
}

......

}
[Android Software/Hacking General [Developers Only]] llrraa2010:
start of Activity--start of MainActivity--Step 15

Step 15. H.handleMessage

frameworks/base/core/java/android/app/ActivityThread.java

public final class ActivityThread {

......

private final class H extends Handler {

......

public void handleMessage(Message msg) {

......

switch (msg.what) {

......

case PAUSE_ACTIVITY:

handlePauseActivity((IBinder)msg.obj, false, msg.arg1 != 0, msg.arg2);

maybeSnapshot();

break;

......

}

......

}

......

}
[Android Software/Hacking General [Developers Only]] llrraa2010:
start of Activity--start of MainActivity--Step 16

Step 16. ActivityThread.handlePauseActivity

frameworks/base/core/java/android/app/ActivityThread.java

public final class ActivityThread {

......

private final void handlePauseActivity(IBinder token, boolean finished,

boolean userLeaving, int configChanges) {

ActivityClientRecord r = mActivities.get(token);

if (r != null) {

//Slog.v(TAG, "userLeaving=" + userLeaving + " handling pause of " + r);

if (userLeaving) {

performUserLeavingActivity(r);

}

r.activity.mConfigChangeFlags |= configChanges;

Bundle state = performPauseActivity(token, finished, true);

// Make sure any pending writes are now committed.

QueuedWork.waitToFinish();

// Tell the activity manager we have paused.

try {

ActivityManagerNative.getDefault().activityPaused(token, state);

} catch (RemoteException ex) {

}

}

}

......

}
[Android Software/Hacking General [Developers Only]] llrraa2010:
start of Activity--start of MainActivity--Step 17

Step 17. ActivityManagerProxy.activityPaused

frameworks/base/core/java/android/app/ActivityManagerNative.java

class ActivityManagerProxy implements IActivityManager

{

......

public void activityPaused(IBinder token, Bundle state) throws RemoteException

{

Parcel data = Parcel.obtain();

Parcel reply = Parcel.obtain();

data.writeInterfaceToken(IActivityManager.descriptor);

data.writeStrongBinder(token);

data.writeBundle(state);

mRemote.transact(ACTIVITY_PAUSED_TRANSACTION, data, reply, 0);

reply.readException();

data.recycle();

reply.recycle();

}

......

}
[Android Software/Hacking General [Developers Only]] llrraa2010:
start of Activity--start of MainActivity--Step 18

Step 18. ActivityManagerService.activityPaused

frameworks/base/services/java/com/android/server/am/ActivityManagerService.java

public final class ActivityManagerService extends ActivityManagerNative

implements Watchdog.Monitor, BatteryStatsImpl.BatteryCallback {

......

public final void activityPaused(IBinder token, Bundle icicle) {

......

final long origId = Binder.clearCallingIdentity();

mMainStack.activityPaused(token, icicle, false);

......

}

......

}
[Android Software/Hacking General [Developers Only]] llrraa2010:
start of Activity--start of MainActivity--Step 19

Step 19. ActivityStack.activityPaused

frameworks/base/services/java/com/android/server/am/ActivityStack.java

public class ActivityStack {

......

final void activityPaused(IBinder token, Bundle icicle, boolean timeout) {

......

ActivityRecord r = null;

synchronized (mService) {

int index = indexOfTokenLocked(token);

if (index >= 0) {

r = (ActivityRecord)mHistory.get(index);

if (!timeout) {

r.icicle = icicle;

r.haveState = true;

}

mHandler.removeMessages(PAUSE_TIMEOUT_MSG, r);

if (mPausingActivity == r) {

r.state = ActivityState.PAUSED;

completePauseLocked();

} else {

......

}

}

}

}

......

}
[Android Software/Hacking General [Developers Only]] llrraa2010:
start of Activity--start of MainActivity--Step 20

Step 20. ActivityStack.completePauseLocked

frameworks/base/services/java/com/android/server/am/ActivityStack.java

public class ActivityStack {

......

private final void completePauseLocked() {

ActivityRecord prev = mPausingActivity;

......

if (prev != null) {

......

mPausingActivity = null;

}

if (!mService.mSleeping && !mService.mShuttingDown) {

resumeTopActivityLocked(prev);

} else {

......

}

......

}

......

}
[Android Software/Hacking General [Developers Only]] llrraa2010:
start of Activity--start of MainActivity--Step 21

Step 21. ActivityStack.resumeTopActivityLokced

frameworks/base/services/java/com/android/server/am/ActivityStack.java

public class ActivityStack {

......

final boolean resumeTopActivityLocked(ActivityRecord prev) {

......

// Find the first activity that is not finishing.

ActivityRecord next = topRunningActivityLocked(null);

// Remember how we'll process this pause/resume situation, and ensure

// that the state is reset however we wind up proceeding.

final boolean userLeaving = mUserLeaving;

mUserLeaving = false;

......

next.delayedResume = false;

// If the top activity is the resumed one, nothing to do.

if (mResumedActivity == next && next.state == ActivityState.RESUMED) {

......

return false;

}

// If we are sleeping, and there is no resumed activity, and the top

// activity is paused, well that is the state we want.

if ((mService.mSleeping || mService.mShuttingDown)

&& mLastPausedActivity == next && next.state == ActivityState.PAUSED) {

......

return false;

}

.......

// We need to start pausing the current activity so the top one

// can be resumed...

if (mResumedActivity != null) {

......

return true;

}

......

if (next.app != null && next.app.thread != null) {

......

} else {

......

startSpecificActivityLocked(next, true, true);

}

return true;

}

......

}
[Android Software/Hacking General [Developers Only]] llrraa2010:
start of Activity--start of MainActivity--Step 22

Step 22. ActivityStack.startSpecificActivityLocked

frameworks/base/services/java/com/android/server/am/ActivityStack.java

public class ActivityStack {

......

private final void startSpecificActivityLocked(ActivityRecord r,

boolean andResume, boolean checkConfig) {

// Is this activity's application already running?

ProcessRecord app = mService.getProcessRecordLocked(r.processName,

r.info.applicationInfo.uid);

......

if (app != null && app.thread != null) {

try {

realStartActivityLocked(r, app, andResume, checkConfig);

return;

} catch (RemoteException e) {

......

}

}

mService.startProcessLocked(r.processName, r.info.applicationInfo, true, 0,

"activity", r.intent.getComponent(), false);

}

......

}
[Android Software/Hacking General [Developers Only]] llrraa2010:
start of Activity--start of MainActivity--Step 23

Step 23. ActivityManagerService.startProcessLocked

frameworks/base/services/java/com/android/server/am/ActivityManagerService.java

public final class ActivityManagerService extends ActivityManagerNative

implements Watchdog.Monitor, BatteryStatsImpl.BatteryCallback {

......

final ProcessRecord startProcessLocked(String processName,

ApplicationInfo info, boolean knownToBeDead, int intentFlags,

String hostingType, ComponentName hostingName, boolean allowWhileBooting) {

ProcessRecord app = getProcessRecordLocked(processName, info.uid);

......

String hostingNameStr = hostingName != null

? hostingName.flattenToShortString() : null;

......

if (app == null) {

app = new ProcessRecordLocked(null, info, processName);

mProcessNames.put(processName, info.uid, app);

} else {

// If this is a new package in the process, add the package to the list

app.addPackage(info.packageName);

}

......

startProcessLocked(app, hostingType, hostingNameStr);

return (app.pid != 0) ? app : null;

}

......

}
[Android Software/Hacking General [Developers Only]] llrraa2010:
start of Activity--start of MainActivity--Step 24

Step 24. ActivityThread.main

frameworks/base/core/java/android/app/ActivityThread.java

public final class ActivityThread {

......

private final void attach(boolean system) {

......

mSystemThread = system;

if (!system) {

......

IActivityManager mgr = ActivityManagerNative.getDefault();

try {

mgr.attachApplication(mAppThread);

} catch (RemoteException ex) {

}

} else {

......

}

}

......

public static final void main(String[] args) {

.......

ActivityThread thread = new ActivityThread();

thread.attach(false);

......

Looper.loop();

.......

thread.detach();

......

}

}
[Android Software/Hacking General [Developers Only]] llrraa2010:
start of Activity--start of MainActivity--Step 25

Step 25. ActivityManagerProxy.attachApplication

frameworks/base/core/java/android/app/ActivityManagerNative.java

class ActivityManagerProxy implements IActivityManager

{

......

public void attachApplication(IApplicationThread app) throws RemoteException

{

Parcel data = Parcel.obtain();

Parcel reply = Parcel.obtain();

data.writeInterfaceToken(IActivityManager.descriptor);

data.writeStrongBinder(app.asBinder());

mRemote.transact(ATTACH_APPLICATION_TRANSACTION, data, reply, 0);

reply.readException();

data.recycle();

reply.recycle();

}

......

}
[Android Software/Hacking General [Developers Only]] llrraa2010:
start of Activity--start of MainActivity--Step 26

Step 26. ActivityManagerService.attachApplication

frameworks/base/services/java/com/android/server/am/ActivityManagerService.java

public final class ActivityManagerService extends ActivityManagerNative

implements Watchdog.Monitor, BatteryStatsImpl.BatteryCallback {

......

public final void attachApplication(IApplicationThread thread) {

synchronized (this) {

int callingPid = Binder.getCallingPid();

final long origId = Binder.clearCallingIdentity();

attachApplicationLocked(thread, callingPid);

Binder.restoreCallingIdentity(origId);

}

}

......

}
[Android Software/Hacking General [Developers Only]] llrraa2010:
start of Activity--start of MainActivity--Step 27

Step 27. ActivityManagerService.attachApplicationLocked

frameworks/base/services/java/com/android/server/am/ActivityManagerService.java

public final class ActivityManagerService extends ActivityManagerNative

implements Watchdog.Monitor, BatteryStatsImpl.BatteryCallback {

......

private final boolean attachApplicationLocked(IApplicationThread thread,

int pid) {

// Find the application record that is being attached... either via

// the pid if we are running in multiple processes, or just pull the

// next app record if we are emulating process with anonymous threads.

ProcessRecord app;

if (pid != MY_PID && pid >= 0) {

synchronized (mPidsSelfLocked) {

app = mPidsSelfLocked.get(pid);

}

} else if (mStartingProcesses.size() > 0) {

......

} else {

......

}

if (app == null) {

......

return false;

}

......

String processName = app.processName;

try {

thread.asBinder().linkToDeath(new AppDeathRecipient(

app, pid, thread), 0);

} catch (RemoteException e) {

......

return false;

}

......

app.thread = thread;

app.curAdj = app.setAdj = -100;

app.curSchedGroup = Process.THREAD_GROUP_DEFAULT;

app.setSchedGroup = Process.THREAD_GROUP_BG_NONINTERACTIVE;

app.forcingToForeground = null;

app.foregroundServices = false;

app.debugging = false;

......

boolean normalMode = mProcessesReady || isAllowedWhileBooting(app.info);

......

boolean badApp = false;

boolean didSomething = false;

// See if the top visible activity is waiting to run in this process...

ActivityRecord hr = mMainStack.topRunningActivityLocked(null);

if (hr != null && normalMode) {

if (hr.app == null && app.info.uid == hr.info.applicationInfo.uid

&& processName.equals(hr.processName)) {

try {

if (mMainStack.realStartActivityLocked(hr, app, true, true)) {

didSomething = true;

}

} catch (Exception e) {

......

}

} else {

......

}

}

......

return true;

}

......

}
[Android Software/Hacking General [Developers Only]] llrraa2010:
start of Activity--start of MainActivity--Step 28

Step 28. ActivityStack.realStartActivityLocked

frameworks/base/services/java/com/android/server/am/ActivityStack.java

public class ActivityStack {

......

final boolean realStartActivityLocked(ActivityRecord r,

ProcessRecord app, boolean andResume, boolean checkConfig)

throws RemoteException {

......

r.app = app;

......

int idx = app.activities.indexOf(r);

if (idx < 0) {

app.activities.add(r);

}

......

try {

......

List<ResultInfo> results = null;

List<Intent> newIntents = null;

if (andResume) {

results = r.results;

newIntents = r.newIntents;

}

......

app.thread.scheduleLaunchActivity(new Intent(r.intent), r,

System.identityHashCode(r),

r.info, r.icicle, results, newIntents, !andResume,

mService.isNextTransitionForward());

......

} catch (RemoteException e) {

......

}

......

return true;

}

......

}
[Android Software/Hacking General [Developers Only]] llrraa2010:
start of Activity--start of MainActivity--Step 29

Step 29. ApplicationThreadProxy.scheduleLaunchActivity

frameworks/base/core/java/android/app/ApplicationThreadNative.java

class ApplicationThreadProxy implements IApplicationThread {

......

public final void scheduleLaunchActivity(Intent intent, IBinder token, int ident,

ActivityInfo info, Bundle state, List<ResultInfo> pendingResults,

List<Intent> pendingNewIntents, boolean notResumed, boolean isForward)

throws RemoteException {

Parcel data = Parcel.obtain();

data.writeInterfaceToken(IApplicationThread.descriptor);

intent.writeToParcel(data, 0);

data.writeStrongBinder(token);

data.writeInt(ident);

info.writeToParcel(data, 0);

data.writeBundle(state);

data.writeTypedList(pendingResults);

data.writeTypedList(pendingNewIntents);

data.writeInt(notResumed ? 1 : 0);

data.writeInt(isForward ? 1 : 0);

mRemote.transact(SCHEDULE_LAUNCH_ACTIVITY_TRANSACTION, data, null,

IBinder.FLAG_ONEWAY);

data.recycle();

}

......

}