Search in sources :

Example 1 with ProfilerInfo

use of android.app.ProfilerInfo in project platform_frameworks_base by android.

the class Am method runStart.

private void runStart() throws Exception {
    Intent intent = makeIntent(UserHandle.USER_CURRENT);
    if (mUserId == UserHandle.USER_ALL) {
        System.err.println("Error: Can't start service with user 'all'");
        return;
    }
    String mimeType = intent.getType();
    if (mimeType == null && intent.getData() != null && "content".equals(intent.getData().getScheme())) {
        mimeType = mAm.getProviderMimeType(intent.getData(), mUserId);
    }
    do {
        if (mStopOption) {
            String packageName;
            if (intent.getComponent() != null) {
                packageName = intent.getComponent().getPackageName();
            } else {
                List<ResolveInfo> activities = mPm.queryIntentActivities(intent, mimeType, 0, mUserId).getList();
                if (activities == null || activities.size() <= 0) {
                    System.err.println("Error: Intent does not match any activities: " + intent);
                    return;
                } else if (activities.size() > 1) {
                    System.err.println("Error: Intent matches multiple activities; can't stop: " + intent);
                    return;
                }
                packageName = activities.get(0).activityInfo.packageName;
            }
            System.out.println("Stopping: " + packageName);
            mAm.forceStopPackage(packageName, mUserId);
            Thread.sleep(250);
        }
        System.out.println("Starting: " + intent);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        ParcelFileDescriptor fd = null;
        ProfilerInfo profilerInfo = null;
        if (mProfileFile != null) {
            try {
                fd = openForSystemServer(new File(mProfileFile), ParcelFileDescriptor.MODE_CREATE | ParcelFileDescriptor.MODE_TRUNCATE | ParcelFileDescriptor.MODE_WRITE_ONLY);
            } catch (FileNotFoundException e) {
                System.err.println("Error: Unable to open file: " + mProfileFile);
                System.err.println("Consider using a file under /data/local/tmp/");
                return;
            }
            profilerInfo = new ProfilerInfo(mProfileFile, fd, mSamplingInterval, mAutoStop, mStreaming);
        }
        IActivityManager.WaitResult result = null;
        int res;
        final long startTime = SystemClock.uptimeMillis();
        ActivityOptions options = null;
        if (mStackId != INVALID_STACK_ID) {
            options = ActivityOptions.makeBasic();
            options.setLaunchStackId(mStackId);
        }
        if (mWaitOption) {
            result = mAm.startActivityAndWait(null, null, intent, mimeType, null, null, 0, mStartFlags, profilerInfo, options != null ? options.toBundle() : null, mUserId);
            res = result.result;
        } else {
            res = mAm.startActivityAsUser(null, null, intent, mimeType, null, null, 0, mStartFlags, profilerInfo, options != null ? options.toBundle() : null, mUserId);
        }
        final long endTime = SystemClock.uptimeMillis();
        PrintStream out = mWaitOption ? System.out : System.err;
        boolean launched = false;
        switch(res) {
            case ActivityManager.START_SUCCESS:
                launched = true;
                break;
            case ActivityManager.START_SWITCHES_CANCELED:
                launched = true;
                out.println("Warning: Activity not started because the " + " current activity is being kept for the user.");
                break;
            case ActivityManager.START_DELIVERED_TO_TOP:
                launched = true;
                out.println("Warning: Activity not started, intent has " + "been delivered to currently running " + "top-most instance.");
                break;
            case ActivityManager.START_RETURN_INTENT_TO_CALLER:
                launched = true;
                out.println("Warning: Activity not started because intent " + "should be handled by the caller");
                break;
            case ActivityManager.START_TASK_TO_FRONT:
                launched = true;
                out.println("Warning: Activity not started, its current " + "task has been brought to the front");
                break;
            case ActivityManager.START_INTENT_NOT_RESOLVED:
                out.println("Error: Activity not started, unable to " + "resolve " + intent.toString());
                break;
            case ActivityManager.START_CLASS_NOT_FOUND:
                out.println(NO_CLASS_ERROR_CODE);
                out.println("Error: Activity class " + intent.getComponent().toShortString() + " does not exist.");
                break;
            case ActivityManager.START_FORWARD_AND_REQUEST_CONFLICT:
                out.println("Error: Activity not started, you requested to " + "both forward and receive its result");
                break;
            case ActivityManager.START_PERMISSION_DENIED:
                out.println("Error: Activity not started, you do not " + "have permission to access it.");
                break;
            case ActivityManager.START_NOT_VOICE_COMPATIBLE:
                out.println("Error: Activity not started, voice control not allowed for: " + intent);
                break;
            case ActivityManager.START_NOT_CURRENT_USER_ACTIVITY:
                out.println("Error: Not allowed to start background user activity" + " that shouldn't be displayed for all users.");
                break;
            default:
                out.println("Error: Activity not started, unknown error code " + res);
                break;
        }
        if (mWaitOption && launched) {
            if (result == null) {
                result = new IActivityManager.WaitResult();
                result.who = intent.getComponent();
            }
            System.out.println("Status: " + (result.timeout ? "timeout" : "ok"));
            if (result.who != null) {
                System.out.println("Activity: " + result.who.flattenToShortString());
            }
            if (result.thisTime >= 0) {
                System.out.println("ThisTime: " + result.thisTime);
            }
            if (result.totalTime >= 0) {
                System.out.println("TotalTime: " + result.totalTime);
            }
            System.out.println("WaitTime: " + (endTime - startTime));
            System.out.println("Complete");
        }
        mRepeat--;
        if (mRepeat > 0) {
            mAm.unhandledBack();
        }
    } while (mRepeat > 0);
}
Also used : ProfilerInfo(android.app.ProfilerInfo) PrintStream(java.io.PrintStream) FileNotFoundException(java.io.FileNotFoundException) Intent(android.content.Intent) ResolveInfo(android.content.pm.ResolveInfo) ParcelFileDescriptor(android.os.ParcelFileDescriptor) File(java.io.File) IActivityManager(android.app.IActivityManager) ActivityOptions(android.app.ActivityOptions)

Example 2 with ProfilerInfo

use of android.app.ProfilerInfo in project platform_frameworks_base by android.

the class Am method runProfile.

private void runProfile() throws Exception {
    String profileFile = null;
    boolean start = false;
    boolean wall = false;
    int userId = UserHandle.USER_CURRENT;
    int profileType = 0;
    mSamplingInterval = 0;
    mStreaming = false;
    String process = null;
    String cmd = nextArgRequired();
    if ("start".equals(cmd)) {
        start = true;
        String opt;
        while ((opt = nextOption()) != null) {
            if (opt.equals("--user")) {
                userId = parseUserArg(nextArgRequired());
            } else if (opt.equals("--wall")) {
                wall = true;
            } else if (opt.equals("--streaming")) {
                mStreaming = true;
            } else if (opt.equals("--sampling")) {
                mSamplingInterval = Integer.parseInt(nextArgRequired());
            } else {
                System.err.println("Error: Unknown option: " + opt);
                return;
            }
        }
        process = nextArgRequired();
    } else if ("stop".equals(cmd)) {
        String opt;
        while ((opt = nextOption()) != null) {
            if (opt.equals("--user")) {
                userId = parseUserArg(nextArgRequired());
            } else {
                System.err.println("Error: Unknown option: " + opt);
                return;
            }
        }
        process = nextArg();
    } else {
        // Compatibility with old syntax: process is specified first.
        process = cmd;
        cmd = nextArgRequired();
        if ("start".equals(cmd)) {
            start = true;
        } else if (!"stop".equals(cmd)) {
            throw new IllegalArgumentException("Profile command " + process + " not valid");
        }
    }
    if (userId == UserHandle.USER_ALL) {
        System.err.println("Error: Can't profile with user 'all'");
        return;
    }
    ParcelFileDescriptor fd = null;
    ProfilerInfo profilerInfo = null;
    if (start) {
        profileFile = nextArgRequired();
        try {
            fd = openForSystemServer(new File(profileFile), ParcelFileDescriptor.MODE_CREATE | ParcelFileDescriptor.MODE_TRUNCATE | ParcelFileDescriptor.MODE_WRITE_ONLY);
        } catch (FileNotFoundException e) {
            System.err.println("Error: Unable to open file: " + profileFile);
            System.err.println("Consider using a file under /data/local/tmp/");
            return;
        }
        profilerInfo = new ProfilerInfo(profileFile, fd, mSamplingInterval, false, mStreaming);
    }
    try {
        if (wall) {
            // XXX doesn't work -- this needs to be set before booting.
            String props = SystemProperties.get("dalvik.vm.extra-opts");
            if (props == null || !props.contains("-Xprofile:wallclock")) {
                props = props + " -Xprofile:wallclock";
            //SystemProperties.set("dalvik.vm.extra-opts", props);
            }
        } else if (start) {
        //removeWallOption();
        }
        if (!mAm.profileControl(process, userId, start, profilerInfo, profileType)) {
            wall = false;
            throw new AndroidException("PROFILE FAILED on process " + process);
        }
    } finally {
        if (!wall) {
        //removeWallOption();
        }
    }
}
Also used : ProfilerInfo(android.app.ProfilerInfo) AndroidException(android.util.AndroidException) ParcelFileDescriptor(android.os.ParcelFileDescriptor) FileNotFoundException(java.io.FileNotFoundException) File(java.io.File)

Example 3 with ProfilerInfo

use of android.app.ProfilerInfo in project platform_frameworks_base by android.

the class ActivityManagerService method attachApplicationLocked.

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 {
        app = null;
    }
    if (app == null) {
        Slog.w(TAG, "No pending application record for pid " + pid + " (IApplicationThread " + thread + "); dropping process");
        EventLog.writeEvent(EventLogTags.AM_DROP_PROCESS, pid);
        if (pid > 0 && pid != MY_PID) {
            Process.killProcessQuiet(pid);
        //TODO: killProcessGroup(app.info.uid, pid);
        } else {
            try {
                thread.scheduleExit();
            } catch (Exception e) {
            // Ignore exceptions.
            }
        }
        return false;
    }
    // process, clean it up now.
    if (app.thread != null) {
        handleAppDiedLocked(app, true, true);
    }
    if (DEBUG_ALL)
        Slog.v(TAG, "Binding process pid " + pid + " to record " + app);
    final String processName = app.processName;
    try {
        AppDeathRecipient adr = new AppDeathRecipient(app, pid, thread);
        thread.asBinder().linkToDeath(adr, 0);
        app.deathRecipient = adr;
    } catch (RemoteException e) {
        app.resetPackageList(mProcessStats);
        startProcessLocked(app, "link fail", processName);
        return false;
    }
    EventLog.writeEvent(EventLogTags.AM_PROC_BOUND, app.userId, app.pid, app.processName);
    app.makeActive(thread, mProcessStats);
    app.curAdj = app.setAdj = app.verifiedAdj = ProcessList.INVALID_ADJ;
    app.curSchedGroup = app.setSchedGroup = ProcessList.SCHED_GROUP_DEFAULT;
    app.forcingToForeground = null;
    updateProcessForegroundLocked(app, false, false);
    app.hasShownUi = false;
    app.debugging = false;
    app.cached = false;
    app.killedByAm = false;
    app.killed = false;
    // We carefully use the same state that PackageManager uses for
    // filtering, since we use this flag to decide if we need to install
    // providers when user is unlocked later
    app.unlocked = StorageManager.isUserKeyUnlocked(app.userId);
    mHandler.removeMessages(PROC_START_TIMEOUT_MSG, app);
    boolean normalMode = mProcessesReady || isAllowedWhileBooting(app.info);
    List<ProviderInfo> providers = normalMode ? generateApplicationProvidersLocked(app) : null;
    if (providers != null && checkAppInLaunchingProvidersLocked(app)) {
        Message msg = mHandler.obtainMessage(CONTENT_PROVIDER_PUBLISH_TIMEOUT_MSG);
        msg.obj = app;
        mHandler.sendMessageDelayed(msg, CONTENT_PROVIDER_PUBLISH_TIMEOUT);
    }
    if (!normalMode) {
        Slog.i(TAG, "Launching preboot mode app: " + app);
    }
    if (DEBUG_ALL)
        Slog.v(TAG, "New app record " + app + " thread=" + thread.asBinder() + " pid=" + pid);
    try {
        int testMode = IApplicationThread.DEBUG_OFF;
        if (mDebugApp != null && mDebugApp.equals(processName)) {
            testMode = mWaitForDebugger ? IApplicationThread.DEBUG_WAIT : IApplicationThread.DEBUG_ON;
            app.debugging = true;
            if (mDebugTransient) {
                mDebugApp = mOrigDebugApp;
                mWaitForDebugger = mOrigWaitForDebugger;
            }
        }
        String profileFile = app.instrumentationProfileFile;
        ParcelFileDescriptor profileFd = null;
        int samplingInterval = 0;
        boolean profileAutoStop = false;
        boolean profileStreamingOutput = false;
        if (mProfileApp != null && mProfileApp.equals(processName)) {
            mProfileProc = app;
            profileFile = mProfileFile;
            profileFd = mProfileFd;
            samplingInterval = mSamplingInterval;
            profileAutoStop = mAutoStopProfiler;
            profileStreamingOutput = mStreamingOutput;
        }
        boolean enableTrackAllocation = false;
        if (mTrackAllocationApp != null && mTrackAllocationApp.equals(processName)) {
            enableTrackAllocation = true;
            mTrackAllocationApp = null;
        }
        // If the app is being launched for restore or full backup, set it up specially
        boolean isRestrictedBackupMode = false;
        if (mBackupTarget != null && mBackupAppName.equals(processName)) {
            isRestrictedBackupMode = mBackupTarget.appInfo.uid >= Process.FIRST_APPLICATION_UID && ((mBackupTarget.backupMode == BackupRecord.RESTORE) || (mBackupTarget.backupMode == BackupRecord.RESTORE_FULL) || (mBackupTarget.backupMode == BackupRecord.BACKUP_FULL));
        }
        if (app.instrumentationClass != null) {
            notifyPackageUse(app.instrumentationClass.getPackageName(), PackageManager.NOTIFY_PACKAGE_USE_INSTRUMENTATION);
        }
        if (DEBUG_CONFIGURATION)
            Slog.v(TAG_CONFIGURATION, "Binding proc " + processName + " with config " + mConfiguration);
        ApplicationInfo appInfo = app.instrumentationInfo != null ? app.instrumentationInfo : app.info;
        app.compat = compatibilityInfoForPackageLocked(appInfo);
        if (profileFd != null) {
            profileFd = profileFd.dup();
        }
        ProfilerInfo profilerInfo = profileFile == null ? null : new ProfilerInfo(profileFile, profileFd, samplingInterval, profileAutoStop, profileStreamingOutput);
        thread.bindApplication(processName, appInfo, providers, app.instrumentationClass, profilerInfo, app.instrumentationArguments, app.instrumentationWatcher, app.instrumentationUiAutomationConnection, testMode, mBinderTransactionTrackingEnabled, enableTrackAllocation, isRestrictedBackupMode || !normalMode, app.persistent, new Configuration(mConfiguration), app.compat, getCommonServicesLocked(app.isolated), mCoreSettingsObserver.getCoreSettingsLocked());
        updateLruProcessLocked(app, false, null);
        app.lastRequestedGc = app.lastLowMemory = SystemClock.uptimeMillis();
    } catch (Exception e) {
        // todo: Yikes!  What should we do?  For now we will try to
        // start another process, but that could easily get us in
        // an infinite loop of restarting processes...
        Slog.wtf(TAG, "Exception thrown during bind of " + app, e);
        app.resetPackageList(mProcessStats);
        app.unlinkDeathRecipient();
        startProcessLocked(app, "bind fail", processName);
        return false;
    }
    // Remove this record from the list of starting applications.
    mPersistentStartingProcesses.remove(app);
    if (DEBUG_PROCESSES && mProcessesOnHold.contains(app))
        Slog.v(TAG_PROCESSES, "Attach application locked removing on hold: " + app);
    mProcessesOnHold.remove(app);
    boolean badApp = false;
    boolean didSomething = false;
    // See if the top visible activity is waiting to run in this process...
    if (normalMode) {
        try {
            if (mStackSupervisor.attachApplicationLocked(app)) {
                didSomething = true;
            }
        } catch (Exception e) {
            Slog.wtf(TAG, "Exception thrown launching activities in " + app, e);
            badApp = true;
        }
    }
    // Find any services that should be running in this process...
    if (!badApp) {
        try {
            didSomething |= mServices.attachApplicationLocked(app, processName);
        } catch (Exception e) {
            Slog.wtf(TAG, "Exception thrown starting services in " + app, e);
            badApp = true;
        }
    }
    // Check if a next-broadcast receiver is in this process...
    if (!badApp && isPendingBroadcastProcessLocked(pid)) {
        try {
            didSomething |= sendPendingBroadcastsLocked(app);
        } catch (Exception e) {
            // If the app died trying to launch the receiver we declare it 'bad'
            Slog.wtf(TAG, "Exception thrown dispatching broadcasts in " + app, e);
            badApp = true;
        }
    }
    // Check whether the next backup agent is in this process...
    if (!badApp && mBackupTarget != null && mBackupTarget.appInfo.uid == app.uid) {
        if (DEBUG_BACKUP)
            Slog.v(TAG_BACKUP, "New app is backup target, launching agent for " + app);
        notifyPackageUse(mBackupTarget.appInfo.packageName, PackageManager.NOTIFY_PACKAGE_USE_BACKUP);
        try {
            thread.scheduleCreateBackupAgent(mBackupTarget.appInfo, compatibilityInfoForPackageLocked(mBackupTarget.appInfo), mBackupTarget.backupMode);
        } catch (Exception e) {
            Slog.wtf(TAG, "Exception thrown creating backup agent in " + app, e);
            badApp = true;
        }
    }
    if (badApp) {
        app.kill("error during init", true);
        handleAppDiedLocked(app, false, true);
        return false;
    }
    if (!didSomething) {
        updateOomAdjLocked();
    }
    return true;
}
Also used : ProfilerInfo(android.app.ProfilerInfo) Message(android.os.Message) Configuration(android.content.res.Configuration) ApplicationInfo(android.content.pm.ApplicationInfo) RemoteException(android.os.RemoteException) IOException(java.io.IOException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) ActivityNotFoundException(android.content.ActivityNotFoundException) TransactionTooLargeException(android.os.TransactionTooLargeException) InstallerException(com.android.server.pm.Installer.InstallerException) FileNotFoundException(java.io.FileNotFoundException) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) Point(android.graphics.Point) ProviderInfo(android.content.pm.ProviderInfo) ParcelFileDescriptor(android.os.ParcelFileDescriptor) RemoteException(android.os.RemoteException)

Example 4 with ProfilerInfo

use of android.app.ProfilerInfo in project platform_frameworks_base by android.

the class ActivityStackSupervisor method realStartActivityLocked.

final boolean realStartActivityLocked(ActivityRecord r, ProcessRecord app, boolean andResume, boolean checkConfig) throws RemoteException {
    if (!allPausedActivitiesComplete()) {
        // the paused state because they will first be resumed then paused on the client side.
        if (DEBUG_SWITCH || DEBUG_PAUSE || DEBUG_STATES)
            Slog.v(TAG_PAUSE, "realStartActivityLocked: Skipping start of r=" + r + " some activities pausing...");
        return false;
    }
    if (andResume) {
        r.startFreezingScreenLocked(app, 0);
        mWindowManager.setAppVisibility(r.appToken, true);
        // schedule launch ticks to collect information about slow apps.
        r.startLaunchTickingLocked();
    }
    // just restarting it anyway.
    if (checkConfig) {
        Configuration config = mWindowManager.updateOrientationFromAppTokens(mService.mConfiguration, r.mayFreezeScreenLocked(app) ? r.appToken : null);
        // Deferring resume here because we're going to launch new activity shortly.
        // We don't want to perform a redundant launch of the same record while ensuring
        // configurations and trying to resume top activity of focused stack.
        mService.updateConfigurationLocked(config, r, false, true);
    }
    r.app = app;
    app.waitingToKill = null;
    r.launchCount++;
    r.lastLaunchTime = SystemClock.uptimeMillis();
    if (DEBUG_ALL)
        Slog.v(TAG, "Launching: " + r);
    int idx = app.activities.indexOf(r);
    if (idx < 0) {
        app.activities.add(r);
    }
    mService.updateLruProcessLocked(app, true, null);
    mService.updateOomAdjLocked();
    final TaskRecord task = r.task;
    if (task.mLockTaskAuth == LOCK_TASK_AUTH_LAUNCHABLE || task.mLockTaskAuth == LOCK_TASK_AUTH_LAUNCHABLE_PRIV) {
        setLockTaskModeLocked(task, LOCK_TASK_MODE_LOCKED, "mLockTaskAuth==LAUNCHABLE", false);
    }
    final ActivityStack stack = task.stack;
    try {
        if (app.thread == null) {
            throw new RemoteException();
        }
        List<ResultInfo> results = null;
        List<ReferrerIntent> newIntents = null;
        if (andResume) {
            results = r.results;
            newIntents = r.newIntents;
        }
        if (DEBUG_SWITCH)
            Slog.v(TAG_SWITCH, "Launching: " + r + " icicle=" + r.icicle + " with results=" + results + " newIntents=" + newIntents + " andResume=" + andResume);
        if (andResume) {
            EventLog.writeEvent(EventLogTags.AM_RESTART_ACTIVITY, r.userId, System.identityHashCode(r), task.taskId, r.shortComponentName);
        }
        if (r.isHomeActivity()) {
            // Home process is the root process of the task.
            mService.mHomeProcess = task.mActivities.get(0).app;
        }
        mService.notifyPackageUse(r.intent.getComponent().getPackageName(), PackageManager.NOTIFY_PACKAGE_USE_ACTIVITY);
        r.sleeping = false;
        r.forceNewConfig = false;
        mService.showUnsupportedZoomDialogIfNeededLocked(r);
        mService.showAskCompatModeDialogLocked(r);
        r.compat = mService.compatibilityInfoForPackageLocked(r.info.applicationInfo);
        ProfilerInfo profilerInfo = null;
        if (mService.mProfileApp != null && mService.mProfileApp.equals(app.processName)) {
            if (mService.mProfileProc == null || mService.mProfileProc == app) {
                mService.mProfileProc = app;
                final String profileFile = mService.mProfileFile;
                if (profileFile != null) {
                    ParcelFileDescriptor profileFd = mService.mProfileFd;
                    if (profileFd != null) {
                        try {
                            profileFd = profileFd.dup();
                        } catch (IOException e) {
                            if (profileFd != null) {
                                try {
                                    profileFd.close();
                                } catch (IOException o) {
                                }
                                profileFd = null;
                            }
                        }
                    }
                    profilerInfo = new ProfilerInfo(profileFile, profileFd, mService.mSamplingInterval, mService.mAutoStopProfiler, mService.mStreamingOutput);
                }
            }
        }
        if (andResume) {
            app.hasShownUi = true;
            app.pendingUiClean = true;
        }
        app.forceProcessStateUpTo(mService.mTopProcessState);
        app.thread.scheduleLaunchActivity(new Intent(r.intent), r.appToken, System.identityHashCode(r), r.info, new Configuration(mService.mConfiguration), new Configuration(task.mOverrideConfig), r.compat, r.launchedFromPackage, task.voiceInteractor, app.repProcState, r.icicle, r.persistentState, results, newIntents, !andResume, mService.isNextTransitionForward(), profilerInfo);
        if ((app.info.privateFlags & ApplicationInfo.PRIVATE_FLAG_CANT_SAVE_STATE) != 0) {
            // considered heavy-weight.
            if (app.processName.equals(app.info.packageName)) {
                if (mService.mHeavyWeightProcess != null && mService.mHeavyWeightProcess != app) {
                    Slog.w(TAG, "Starting new heavy weight process " + app + " when already running " + mService.mHeavyWeightProcess);
                }
                mService.mHeavyWeightProcess = app;
                Message msg = mService.mHandler.obtainMessage(ActivityManagerService.POST_HEAVY_NOTIFICATION_MSG);
                msg.obj = r;
                mService.mHandler.sendMessage(msg);
            }
        }
    } catch (RemoteException e) {
        if (r.launchFailed) {
            // This is the second time we failed -- finish activity
            // and give up.
            Slog.e(TAG, "Second failure launching " + r.intent.getComponent().flattenToShortString() + ", giving up", e);
            mService.appDiedLocked(app);
            stack.requestFinishActivityLocked(r.appToken, Activity.RESULT_CANCELED, null, "2nd-crash", false);
            return false;
        }
        // This is the first time we failed -- restart process and
        // retry.
        app.activities.remove(r);
        throw e;
    }
    r.launchFailed = false;
    if (stack.updateLRUListLocked(r)) {
        Slog.w(TAG, "Activity " + r + " being launched, but already in LRU list");
    }
    if (andResume) {
        // As part of the process of launching, ActivityThread also performs
        // a resume.
        stack.minimalResumeActivityLocked(r);
    } else {
        // current icicle and other state.
        if (DEBUG_STATES)
            Slog.v(TAG_STATES, "Moving to PAUSED: " + r + " (starting in paused state)");
        r.state = PAUSED;
    }
    // switch back to it faster and look better.
    if (isFocusedStack(stack)) {
        mService.startSetupActivityLocked();
    }
    // their client may have activities.
    if (r.app != null) {
        mService.mServices.updateServiceConnectionActivitiesLocked(r.app);
    }
    return true;
}
Also used : ProfilerInfo(android.app.ProfilerInfo) Configuration(android.content.res.Configuration) ReferrerIntent(com.android.internal.content.ReferrerIntent) Message(android.os.Message) ReferrerIntent(com.android.internal.content.ReferrerIntent) Intent(android.content.Intent) IOException(java.io.IOException) ParcelFileDescriptor(android.os.ParcelFileDescriptor) RemoteException(android.os.RemoteException) ResultInfo(android.app.ResultInfo)

Example 5 with ProfilerInfo

use of android.app.ProfilerInfo in project android_frameworks_base by DirtyUnicorns.

the class Am method runStart.

private void runStart() throws Exception {
    Intent intent = makeIntent(UserHandle.USER_CURRENT);
    if (mUserId == UserHandle.USER_ALL) {
        System.err.println("Error: Can't start service with user 'all'");
        return;
    }
    String mimeType = intent.getType();
    if (mimeType == null && intent.getData() != null && "content".equals(intent.getData().getScheme())) {
        mimeType = mAm.getProviderMimeType(intent.getData(), mUserId);
    }
    do {
        if (mStopOption) {
            String packageName;
            if (intent.getComponent() != null) {
                packageName = intent.getComponent().getPackageName();
            } else {
                List<ResolveInfo> activities = mPm.queryIntentActivities(intent, mimeType, 0, mUserId).getList();
                if (activities == null || activities.size() <= 0) {
                    System.err.println("Error: Intent does not match any activities: " + intent);
                    return;
                } else if (activities.size() > 1) {
                    System.err.println("Error: Intent matches multiple activities; can't stop: " + intent);
                    return;
                }
                packageName = activities.get(0).activityInfo.packageName;
            }
            System.out.println("Stopping: " + packageName);
            mAm.forceStopPackage(packageName, mUserId);
            Thread.sleep(250);
        }
        System.out.println("Starting: " + intent);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        ParcelFileDescriptor fd = null;
        ProfilerInfo profilerInfo = null;
        if (mProfileFile != null) {
            try {
                fd = openForSystemServer(new File(mProfileFile), ParcelFileDescriptor.MODE_CREATE | ParcelFileDescriptor.MODE_TRUNCATE | ParcelFileDescriptor.MODE_WRITE_ONLY);
            } catch (FileNotFoundException e) {
                System.err.println("Error: Unable to open file: " + mProfileFile);
                System.err.println("Consider using a file under /data/local/tmp/");
                return;
            }
            profilerInfo = new ProfilerInfo(mProfileFile, fd, mSamplingInterval, mAutoStop);
        }
        IActivityManager.WaitResult result = null;
        int res;
        final long startTime = SystemClock.uptimeMillis();
        ActivityOptions options = null;
        if (mStackId != INVALID_STACK_ID) {
            options = ActivityOptions.makeBasic();
            options.setLaunchStackId(mStackId);
        }
        if (mWaitOption) {
            result = mAm.startActivityAndWait(null, null, intent, mimeType, null, null, 0, mStartFlags, profilerInfo, options != null ? options.toBundle() : null, mUserId);
            res = result.result;
        } else {
            res = mAm.startActivityAsUser(null, null, intent, mimeType, null, null, 0, mStartFlags, profilerInfo, options != null ? options.toBundle() : null, mUserId);
        }
        final long endTime = SystemClock.uptimeMillis();
        PrintStream out = mWaitOption ? System.out : System.err;
        boolean launched = false;
        switch(res) {
            case ActivityManager.START_SUCCESS:
                launched = true;
                break;
            case ActivityManager.START_SWITCHES_CANCELED:
                launched = true;
                out.println("Warning: Activity not started because the " + " current activity is being kept for the user.");
                break;
            case ActivityManager.START_DELIVERED_TO_TOP:
                launched = true;
                out.println("Warning: Activity not started, intent has " + "been delivered to currently running " + "top-most instance.");
                break;
            case ActivityManager.START_RETURN_INTENT_TO_CALLER:
                launched = true;
                out.println("Warning: Activity not started because intent " + "should be handled by the caller");
                break;
            case ActivityManager.START_TASK_TO_FRONT:
                launched = true;
                out.println("Warning: Activity not started, its current " + "task has been brought to the front");
                break;
            case ActivityManager.START_INTENT_NOT_RESOLVED:
                out.println("Error: Activity not started, unable to " + "resolve " + intent.toString());
                break;
            case ActivityManager.START_CLASS_NOT_FOUND:
                out.println(NO_CLASS_ERROR_CODE);
                out.println("Error: Activity class " + intent.getComponent().toShortString() + " does not exist.");
                break;
            case ActivityManager.START_FORWARD_AND_REQUEST_CONFLICT:
                out.println("Error: Activity not started, you requested to " + "both forward and receive its result");
                break;
            case ActivityManager.START_PERMISSION_DENIED:
                out.println("Error: Activity not started, you do not " + "have permission to access it.");
                break;
            case ActivityManager.START_NOT_VOICE_COMPATIBLE:
                out.println("Error: Activity not started, voice control not allowed for: " + intent);
                break;
            case ActivityManager.START_NOT_CURRENT_USER_ACTIVITY:
                out.println("Error: Not allowed to start background user activity" + " that shouldn't be displayed for all users.");
                break;
            default:
                out.println("Error: Activity not started, unknown error code " + res);
                break;
        }
        if (mWaitOption && launched) {
            if (result == null) {
                result = new IActivityManager.WaitResult();
                result.who = intent.getComponent();
            }
            System.out.println("Status: " + (result.timeout ? "timeout" : "ok"));
            if (result.who != null) {
                System.out.println("Activity: " + result.who.flattenToShortString());
            }
            if (result.thisTime >= 0) {
                System.out.println("ThisTime: " + result.thisTime);
            }
            if (result.totalTime >= 0) {
                System.out.println("TotalTime: " + result.totalTime);
            }
            System.out.println("WaitTime: " + (endTime - startTime));
            System.out.println("Complete");
        }
        mRepeat--;
        if (mRepeat > 0) {
            mAm.unhandledBack();
        }
    } while (mRepeat > 0);
}
Also used : ProfilerInfo(android.app.ProfilerInfo) PrintStream(java.io.PrintStream) FileNotFoundException(java.io.FileNotFoundException) Intent(android.content.Intent) ResolveInfo(android.content.pm.ResolveInfo) ParcelFileDescriptor(android.os.ParcelFileDescriptor) File(java.io.File) IActivityManager(android.app.IActivityManager) ActivityOptions(android.app.ActivityOptions)

Aggregations

ProfilerInfo (android.app.ProfilerInfo)17 ParcelFileDescriptor (android.os.ParcelFileDescriptor)17 FileNotFoundException (java.io.FileNotFoundException)12 Intent (android.content.Intent)10 File (java.io.File)10 Configuration (android.content.res.Configuration)7 Message (android.os.Message)7 RemoteException (android.os.RemoteException)7 IOException (java.io.IOException)7 ActivityOptions (android.app.ActivityOptions)5 IActivityManager (android.app.IActivityManager)5 ResultInfo (android.app.ResultInfo)5 ResolveInfo (android.content.pm.ResolveInfo)5 AndroidException (android.util.AndroidException)5 ReferrerIntent (com.android.internal.content.ReferrerIntent)5 PrintStream (java.io.PrintStream)5 ActivityNotFoundException (android.content.ActivityNotFoundException)2 ApplicationInfo (android.content.pm.ApplicationInfo)2 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)2 ProviderInfo (android.content.pm.ProviderInfo)2