Search in sources :

Example 1 with InstrumentationTestRunner

use of android.test.InstrumentationTestRunner in project platform_frameworks_base by android.

the class AppLaunch method testMeasureStartUpTime.

public void testMeasureStartUpTime() throws RemoteException, NameNotFoundException, IOException, InterruptedException {
    InstrumentationTestRunner instrumentation = (InstrumentationTestRunner) getInstrumentation();
    Bundle args = instrumentation.getArguments();
    mAm = ActivityManagerNative.getDefault();
    String launchDirectory = args.getString(KEY_LAUNCH_DIRECTORY);
    mTraceDirectoryStr = args.getString(KEY_TRACE_DIRECTORY);
    mDropCache = Boolean.parseBoolean(args.getString(KEY_DROP_CACHE));
    mSimplePerfCmd = args.getString(KEY_SIMPLEPPERF_CMD);
    mLaunchOrder = args.getString(KEY_LAUNCH_ORDER, LAUNCH_ORDER_CYCLIC);
    createMappings();
    parseArgs(args);
    checkAccountSignIn();
    // Root directory for applaunch file to log the app launch output
    // Will be useful in case of simpleperf command is used
    File launchRootDir = null;
    if (null != launchDirectory && !launchDirectory.isEmpty()) {
        launchRootDir = new File(launchDirectory);
        if (!launchRootDir.exists() && !launchRootDir.mkdirs()) {
            throw new IOException("Unable to create the destination directory");
        }
    }
    try {
        File launchSubDir = new File(launchRootDir, LAUNCH_SUB_DIRECTORY);
        if (!launchSubDir.exists() && !launchSubDir.mkdirs()) {
            throw new IOException("Unable to create the lauch file sub directory");
        }
        mFile = new File(launchSubDir, LAUNCH_FILE);
        mOutputStream = new FileOutputStream(mFile);
        mBufferedWriter = new BufferedWriter(new OutputStreamWriter(mOutputStream));
        // Root directory for trace file during the launches
        File rootTrace = null;
        File rootTraceSubDir = null;
        int traceBufferSize = 0;
        int traceDumpInterval = 0;
        Set<String> traceCategoriesSet = null;
        if (null != mTraceDirectoryStr && !mTraceDirectoryStr.isEmpty()) {
            rootTrace = new File(mTraceDirectoryStr);
            if (!rootTrace.exists() && !rootTrace.mkdirs()) {
                throw new IOException("Unable to create the trace directory");
            }
            rootTraceSubDir = new File(rootTrace, TRACE_SUB_DIRECTORY);
            if (!rootTraceSubDir.exists() && !rootTraceSubDir.mkdirs()) {
                throw new IOException("Unable to create the trace sub directory");
            }
            assertNotNull("Trace iteration parameter is mandatory", args.getString(KEY_TRACE_ITERATIONS));
            mTraceLaunchCount = Integer.parseInt(args.getString(KEY_TRACE_ITERATIONS));
            String traceCategoriesStr = args.getString(KEY_TRACE_CATEGORY, DEFAULT_TRACE_CATEGORIES);
            traceBufferSize = Integer.parseInt(args.getString(KEY_TRACE_BUFFERSIZE, DEFAULT_TRACE_BUFFER_SIZE));
            traceDumpInterval = Integer.parseInt(args.getString(KEY_TRACE_DUMPINTERVAL, DEFAULT_TRACE_DUMP_INTERVAL));
            traceCategoriesSet = new HashSet<String>();
            if (!traceCategoriesStr.isEmpty()) {
                String[] traceCategoriesSplit = traceCategoriesStr.split(DELIMITER);
                for (int i = 0; i < traceCategoriesSplit.length; i++) {
                    traceCategoriesSet.add(traceCategoriesSplit[i]);
                }
            }
        }
        // Get the app launch order based on launch order, trial launch,
        // launch iterations and trace iterations
        setLaunchOrder();
        for (LaunchOrder launch : mLaunchOrderList) {
            // launch time calculations.
            if (launch.getLaunchReason().equals(TRIAL_LAUNCH)) {
                // In the "applaunch.txt" file, trail launches is referenced using
                // "TRIAL_LAUNCH"
                long launchTime = startApp(launch.getApp(), true, launch.getLaunchReason());
                if (launchTime < 0) {
                    List<Long> appLaunchList = new ArrayList<Long>();
                    appLaunchList.add(-1L);
                    mNameToLaunchTime.put(launch.getApp(), appLaunchList);
                    // error should have already been logged by startApp
                    continue;
                }
                sleep(INITIAL_LAUNCH_IDLE_TIMEOUT);
                closeApp(launch.getApp(), true);
                dropCache();
                sleep(BETWEEN_LAUNCH_SLEEP_TIMEOUT);
            }
            // App launch times used for final calculation
            if (launch.getLaunchReason().contains(LAUNCH_ITERATION_PREFIX)) {
                long launchTime = -1;
                if (null != mNameToLaunchTime.get(launch.getApp())) {
                    long firstLaunchTime = mNameToLaunchTime.get(launch.getApp()).get(0);
                    if (firstLaunchTime < 0) {
                        // skip if the app has failures while launched first
                        continue;
                    }
                }
                // In the "applaunch.txt" file app launches are referenced using
                // "LAUNCH_ITERATION - ITERATION NUM"
                launchTime = startApp(launch.getApp(), true, launch.getLaunchReason());
                if (launchTime < 0) {
                    // if it fails once, skip the rest of the launches
                    List<Long> appLaunchList = new ArrayList<Long>();
                    appLaunchList.add(-1L);
                    mNameToLaunchTime.put(launch.getApp(), appLaunchList);
                    continue;
                } else {
                    if (null != mNameToLaunchTime.get(launch.getApp())) {
                        mNameToLaunchTime.get(launch.getApp()).add(launchTime);
                    } else {
                        List<Long> appLaunchList = new ArrayList<Long>();
                        appLaunchList.add(launchTime);
                        mNameToLaunchTime.put(launch.getApp(), appLaunchList);
                    }
                }
                sleep(POST_LAUNCH_IDLE_TIMEOUT);
                closeApp(launch.getApp(), true);
                dropCache();
                sleep(BETWEEN_LAUNCH_SLEEP_TIMEOUT);
            }
            // launch time calculations.
            if (launch.getLaunchReason().contains(TRACE_ITERATION_PREFIX)) {
                AtraceLogger atraceLogger = AtraceLogger.getAtraceLoggerInstance(getInstrumentation());
                // Start the trace
                try {
                    atraceLogger.atraceStart(traceCategoriesSet, traceBufferSize, traceDumpInterval, rootTraceSubDir, String.format("%s-%s", launch.getApp(), launch.getLaunchReason()));
                    startApp(launch.getApp(), true, launch.getLaunchReason());
                    sleep(POST_LAUNCH_IDLE_TIMEOUT);
                } finally {
                    // Stop the trace
                    atraceLogger.atraceStop();
                    closeApp(launch.getApp(), true);
                    dropCache();
                    sleep(BETWEEN_LAUNCH_SLEEP_TIMEOUT);
                }
            }
        }
    } finally {
        if (null != mBufferedWriter) {
            mBufferedWriter.close();
        }
    }
    for (String app : mNameToResultKey.keySet()) {
        StringBuilder launchTimes = new StringBuilder();
        for (Long launch : mNameToLaunchTime.get(app)) {
            launchTimes.append(launch);
            launchTimes.append(",");
        }
        mResult.putString(mNameToResultKey.get(app), launchTimes.toString());
    }
    instrumentation.sendStatus(0, mResult);
}
Also used : Bundle(android.os.Bundle) ArrayList(java.util.ArrayList) IOException(java.io.IOException) BufferedWriter(java.io.BufferedWriter) AtraceLogger(android.support.test.rule.logging.AtraceLogger) InstrumentationTestRunner(android.test.InstrumentationTestRunner) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) File(java.io.File)

Example 2 with InstrumentationTestRunner

use of android.test.InstrumentationTestRunner in project android_frameworks_base by ResurrectionRemix.

the class AppLaunch method testMeasureStartUpTime.

public void testMeasureStartUpTime() throws RemoteException, NameNotFoundException, IOException, InterruptedException {
    InstrumentationTestRunner instrumentation = (InstrumentationTestRunner) getInstrumentation();
    Bundle args = instrumentation.getArguments();
    mAm = ActivityManagerNative.getDefault();
    String launchDirectory = args.getString(KEY_LAUNCH_DIRECTORY);
    mTraceDirectoryStr = args.getString(KEY_TRACE_DIRECTORY);
    mDropCache = Boolean.parseBoolean(args.getString(KEY_DROP_CACHE));
    mSimplePerfCmd = args.getString(KEY_SIMPLEPPERF_CMD);
    mLaunchOrder = args.getString(KEY_LAUNCH_ORDER, LAUNCH_ORDER_CYCLIC);
    createMappings();
    parseArgs(args);
    checkAccountSignIn();
    // Root directory for applaunch file to log the app launch output
    // Will be useful in case of simpleperf command is used
    File launchRootDir = null;
    if (null != launchDirectory && !launchDirectory.isEmpty()) {
        launchRootDir = new File(launchDirectory);
        if (!launchRootDir.exists() && !launchRootDir.mkdirs()) {
            throw new IOException("Unable to create the destination directory");
        }
    }
    try {
        File launchSubDir = new File(launchRootDir, LAUNCH_SUB_DIRECTORY);
        if (!launchSubDir.exists() && !launchSubDir.mkdirs()) {
            throw new IOException("Unable to create the lauch file sub directory");
        }
        mFile = new File(launchSubDir, LAUNCH_FILE);
        mOutputStream = new FileOutputStream(mFile);
        mBufferedWriter = new BufferedWriter(new OutputStreamWriter(mOutputStream));
        // Root directory for trace file during the launches
        File rootTrace = null;
        File rootTraceSubDir = null;
        int traceBufferSize = 0;
        int traceDumpInterval = 0;
        Set<String> traceCategoriesSet = null;
        if (null != mTraceDirectoryStr && !mTraceDirectoryStr.isEmpty()) {
            rootTrace = new File(mTraceDirectoryStr);
            if (!rootTrace.exists() && !rootTrace.mkdirs()) {
                throw new IOException("Unable to create the trace directory");
            }
            rootTraceSubDir = new File(rootTrace, TRACE_SUB_DIRECTORY);
            if (!rootTraceSubDir.exists() && !rootTraceSubDir.mkdirs()) {
                throw new IOException("Unable to create the trace sub directory");
            }
            assertNotNull("Trace iteration parameter is mandatory", args.getString(KEY_TRACE_ITERATIONS));
            mTraceLaunchCount = Integer.parseInt(args.getString(KEY_TRACE_ITERATIONS));
            String traceCategoriesStr = args.getString(KEY_TRACE_CATEGORY, DEFAULT_TRACE_CATEGORIES);
            traceBufferSize = Integer.parseInt(args.getString(KEY_TRACE_BUFFERSIZE, DEFAULT_TRACE_BUFFER_SIZE));
            traceDumpInterval = Integer.parseInt(args.getString(KEY_TRACE_DUMPINTERVAL, DEFAULT_TRACE_DUMP_INTERVAL));
            traceCategoriesSet = new HashSet<String>();
            if (!traceCategoriesStr.isEmpty()) {
                String[] traceCategoriesSplit = traceCategoriesStr.split(DELIMITER);
                for (int i = 0; i < traceCategoriesSplit.length; i++) {
                    traceCategoriesSet.add(traceCategoriesSplit[i]);
                }
            }
        }
        // Get the app launch order based on launch order, trial launch,
        // launch iterations and trace iterations
        setLaunchOrder();
        for (LaunchOrder launch : mLaunchOrderList) {
            // launch time calculations.
            if (launch.getLaunchReason().equals(TRIAL_LAUNCH)) {
                // In the "applaunch.txt" file, trail launches is referenced using
                // "TRIAL_LAUNCH"
                long launchTime = startApp(launch.getApp(), true, launch.getLaunchReason());
                if (launchTime < 0) {
                    List<Long> appLaunchList = new ArrayList<Long>();
                    appLaunchList.add(-1L);
                    mNameToLaunchTime.put(launch.getApp(), appLaunchList);
                    // error should have already been logged by startApp
                    continue;
                }
                sleep(INITIAL_LAUNCH_IDLE_TIMEOUT);
                closeApp(launch.getApp(), true);
                dropCache();
                sleep(BETWEEN_LAUNCH_SLEEP_TIMEOUT);
            }
            // App launch times used for final calculation
            if (launch.getLaunchReason().contains(LAUNCH_ITERATION_PREFIX)) {
                long launchTime = -1;
                if (null != mNameToLaunchTime.get(launch.getApp())) {
                    long firstLaunchTime = mNameToLaunchTime.get(launch.getApp()).get(0);
                    if (firstLaunchTime < 0) {
                        // skip if the app has failures while launched first
                        continue;
                    }
                }
                // In the "applaunch.txt" file app launches are referenced using
                // "LAUNCH_ITERATION - ITERATION NUM"
                launchTime = startApp(launch.getApp(), true, launch.getLaunchReason());
                if (launchTime < 0) {
                    // if it fails once, skip the rest of the launches
                    List<Long> appLaunchList = new ArrayList<Long>();
                    appLaunchList.add(-1L);
                    mNameToLaunchTime.put(launch.getApp(), appLaunchList);
                    continue;
                } else {
                    if (null != mNameToLaunchTime.get(launch.getApp())) {
                        mNameToLaunchTime.get(launch.getApp()).add(launchTime);
                    } else {
                        List<Long> appLaunchList = new ArrayList<Long>();
                        appLaunchList.add(launchTime);
                        mNameToLaunchTime.put(launch.getApp(), appLaunchList);
                    }
                }
                sleep(POST_LAUNCH_IDLE_TIMEOUT);
                closeApp(launch.getApp(), true);
                dropCache();
                sleep(BETWEEN_LAUNCH_SLEEP_TIMEOUT);
            }
            // launch time calculations.
            if (launch.getLaunchReason().contains(TRACE_ITERATION_PREFIX)) {
                AtraceLogger atraceLogger = AtraceLogger.getAtraceLoggerInstance(getInstrumentation());
                // Start the trace
                try {
                    atraceLogger.atraceStart(traceCategoriesSet, traceBufferSize, traceDumpInterval, rootTraceSubDir, String.format("%s-%s", launch.getApp(), launch.getLaunchReason()));
                    startApp(launch.getApp(), true, launch.getLaunchReason());
                    sleep(POST_LAUNCH_IDLE_TIMEOUT);
                } finally {
                    // Stop the trace
                    atraceLogger.atraceStop();
                    closeApp(launch.getApp(), true);
                    dropCache();
                    sleep(BETWEEN_LAUNCH_SLEEP_TIMEOUT);
                }
            }
        }
    } finally {
        if (null != mBufferedWriter) {
            mBufferedWriter.close();
        }
    }
    for (String app : mNameToResultKey.keySet()) {
        StringBuilder launchTimes = new StringBuilder();
        for (Long launch : mNameToLaunchTime.get(app)) {
            launchTimes.append(launch);
            launchTimes.append(",");
        }
        mResult.putString(mNameToResultKey.get(app), launchTimes.toString());
    }
    instrumentation.sendStatus(0, mResult);
}
Also used : Bundle(android.os.Bundle) ArrayList(java.util.ArrayList) IOException(java.io.IOException) BufferedWriter(java.io.BufferedWriter) AtraceLogger(android.support.test.rule.logging.AtraceLogger) InstrumentationTestRunner(android.test.InstrumentationTestRunner) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) File(java.io.File)

Example 3 with InstrumentationTestRunner

use of android.test.InstrumentationTestRunner in project android_frameworks_base by ParanoidAndroid.

the class AppLaunch method testMeasureStartUpTime.

public void testMeasureStartUpTime() throws RemoteException, NameNotFoundException {
    InstrumentationTestRunner instrumentation = (InstrumentationTestRunner) getInstrumentation();
    Bundle args = instrumentation.getArguments();
    mAm = ActivityManagerNative.getDefault();
    createMappings();
    parseArgs(args);
    checkAccountSignIn();
    // do initial app launch, without force stopping
    for (String app : mNameToResultKey.keySet()) {
        long launchTime = startApp(app, false);
        if (launchTime <= 0) {
            mNameToLaunchTime.put(app, -1L);
            // error should have already been logged by startApp
            continue;
        }
        sleep(INITIAL_LAUNCH_IDLE_TIMEOUT);
        closeApp(app, false);
        sleep(BETWEEN_LAUNCH_SLEEP_TIMEOUT);
    }
    // do the real app launch now
    for (int i = 0; i < mLaunchIterations; i++) {
        for (String app : mNameToResultKey.keySet()) {
            long totalLaunchTime = mNameToLaunchTime.get(app);
            long launchTime = 0;
            if (totalLaunchTime < 0) {
                // skip if the app has previous failures
                continue;
            }
            launchTime = startApp(app, true);
            if (launchTime <= 0) {
                // if it fails once, skip the rest of the launches
                mNameToLaunchTime.put(app, -1L);
                continue;
            }
            totalLaunchTime += launchTime;
            mNameToLaunchTime.put(app, totalLaunchTime);
            sleep(POST_LAUNCH_IDLE_TIMEOUT);
            closeApp(app, true);
            sleep(BETWEEN_LAUNCH_SLEEP_TIMEOUT);
        }
    }
    for (String app : mNameToResultKey.keySet()) {
        long totalLaunchTime = mNameToLaunchTime.get(app);
        if (totalLaunchTime != -1) {
            mResult.putDouble(mNameToResultKey.get(app), ((double) totalLaunchTime) / mLaunchIterations);
        }
    }
    instrumentation.sendStatus(0, mResult);
}
Also used : InstrumentationTestRunner(android.test.InstrumentationTestRunner) Bundle(android.os.Bundle)

Example 4 with InstrumentationTestRunner

use of android.test.InstrumentationTestRunner in project android_frameworks_base by DirtyUnicorns.

the class AppLaunch method testMeasureStartUpTime.

public void testMeasureStartUpTime() throws RemoteException, NameNotFoundException, IOException, InterruptedException {
    InstrumentationTestRunner instrumentation = (InstrumentationTestRunner) getInstrumentation();
    Bundle args = instrumentation.getArguments();
    mAm = ActivityManagerNative.getDefault();
    String launchDirectory = args.getString(KEY_LAUNCH_DIRECTORY);
    mTraceDirectoryStr = args.getString(KEY_TRACE_DIRECTORY);
    mDropCache = Boolean.parseBoolean(args.getString(KEY_DROP_CACHE));
    mSimplePerfCmd = args.getString(KEY_SIMPLEPPERF_CMD);
    mLaunchOrder = args.getString(KEY_LAUNCH_ORDER, LAUNCH_ORDER_CYCLIC);
    createMappings();
    parseArgs(args);
    checkAccountSignIn();
    // Root directory for applaunch file to log the app launch output
    // Will be useful in case of simpleperf command is used
    File launchRootDir = null;
    if (null != launchDirectory && !launchDirectory.isEmpty()) {
        launchRootDir = new File(launchDirectory);
        if (!launchRootDir.exists() && !launchRootDir.mkdirs()) {
            throw new IOException("Unable to create the destination directory");
        }
    }
    try {
        File launchSubDir = new File(launchRootDir, LAUNCH_SUB_DIRECTORY);
        if (!launchSubDir.exists() && !launchSubDir.mkdirs()) {
            throw new IOException("Unable to create the lauch file sub directory");
        }
        mFile = new File(launchSubDir, LAUNCH_FILE);
        mOutputStream = new FileOutputStream(mFile);
        mBufferedWriter = new BufferedWriter(new OutputStreamWriter(mOutputStream));
        // Root directory for trace file during the launches
        File rootTrace = null;
        File rootTraceSubDir = null;
        int traceBufferSize = 0;
        int traceDumpInterval = 0;
        Set<String> traceCategoriesSet = null;
        if (null != mTraceDirectoryStr && !mTraceDirectoryStr.isEmpty()) {
            rootTrace = new File(mTraceDirectoryStr);
            if (!rootTrace.exists() && !rootTrace.mkdirs()) {
                throw new IOException("Unable to create the trace directory");
            }
            rootTraceSubDir = new File(rootTrace, TRACE_SUB_DIRECTORY);
            if (!rootTraceSubDir.exists() && !rootTraceSubDir.mkdirs()) {
                throw new IOException("Unable to create the trace sub directory");
            }
            assertNotNull("Trace iteration parameter is mandatory", args.getString(KEY_TRACE_ITERATIONS));
            mTraceLaunchCount = Integer.parseInt(args.getString(KEY_TRACE_ITERATIONS));
            String traceCategoriesStr = args.getString(KEY_TRACE_CATEGORY, DEFAULT_TRACE_CATEGORIES);
            traceBufferSize = Integer.parseInt(args.getString(KEY_TRACE_BUFFERSIZE, DEFAULT_TRACE_BUFFER_SIZE));
            traceDumpInterval = Integer.parseInt(args.getString(KEY_TRACE_DUMPINTERVAL, DEFAULT_TRACE_DUMP_INTERVAL));
            traceCategoriesSet = new HashSet<String>();
            if (!traceCategoriesStr.isEmpty()) {
                String[] traceCategoriesSplit = traceCategoriesStr.split(DELIMITER);
                for (int i = 0; i < traceCategoriesSplit.length; i++) {
                    traceCategoriesSet.add(traceCategoriesSplit[i]);
                }
            }
        }
        // Get the app launch order based on launch order, trial launch,
        // launch iterations and trace iterations
        setLaunchOrder();
        for (LaunchOrder launch : mLaunchOrderList) {
            // launch time calculations.
            if (launch.getLaunchReason().equals(TRIAL_LAUNCH)) {
                // In the "applaunch.txt" file, trail launches is referenced using
                // "TRIAL_LAUNCH"
                long launchTime = startApp(launch.getApp(), true, launch.getLaunchReason());
                if (launchTime < 0) {
                    List<Long> appLaunchList = new ArrayList<Long>();
                    appLaunchList.add(-1L);
                    mNameToLaunchTime.put(launch.getApp(), appLaunchList);
                    // error should have already been logged by startApp
                    continue;
                }
                sleep(INITIAL_LAUNCH_IDLE_TIMEOUT);
                closeApp(launch.getApp(), true);
                dropCache();
                sleep(BETWEEN_LAUNCH_SLEEP_TIMEOUT);
            }
            // App launch times used for final calculation
            if (launch.getLaunchReason().contains(LAUNCH_ITERATION_PREFIX)) {
                long launchTime = -1;
                if (null != mNameToLaunchTime.get(launch.getApp())) {
                    long firstLaunchTime = mNameToLaunchTime.get(launch.getApp()).get(0);
                    if (firstLaunchTime < 0) {
                        // skip if the app has failures while launched first
                        continue;
                    }
                }
                // In the "applaunch.txt" file app launches are referenced using
                // "LAUNCH_ITERATION - ITERATION NUM"
                launchTime = startApp(launch.getApp(), true, launch.getLaunchReason());
                if (launchTime < 0) {
                    // if it fails once, skip the rest of the launches
                    List<Long> appLaunchList = new ArrayList<Long>();
                    appLaunchList.add(-1L);
                    mNameToLaunchTime.put(launch.getApp(), appLaunchList);
                    continue;
                } else {
                    if (null != mNameToLaunchTime.get(launch.getApp())) {
                        mNameToLaunchTime.get(launch.getApp()).add(launchTime);
                    } else {
                        List<Long> appLaunchList = new ArrayList<Long>();
                        appLaunchList.add(launchTime);
                        mNameToLaunchTime.put(launch.getApp(), appLaunchList);
                    }
                }
                sleep(POST_LAUNCH_IDLE_TIMEOUT);
                closeApp(launch.getApp(), true);
                dropCache();
                sleep(BETWEEN_LAUNCH_SLEEP_TIMEOUT);
            }
            // launch time calculations.
            if (launch.getLaunchReason().contains(TRACE_ITERATION_PREFIX)) {
                AtraceLogger atraceLogger = AtraceLogger.getAtraceLoggerInstance(getInstrumentation());
                // Start the trace
                try {
                    atraceLogger.atraceStart(traceCategoriesSet, traceBufferSize, traceDumpInterval, rootTraceSubDir, String.format("%s-%s", launch.getApp(), launch.getLaunchReason()));
                    startApp(launch.getApp(), true, launch.getLaunchReason());
                    sleep(POST_LAUNCH_IDLE_TIMEOUT);
                } finally {
                    // Stop the trace
                    atraceLogger.atraceStop();
                    closeApp(launch.getApp(), true);
                    dropCache();
                    sleep(BETWEEN_LAUNCH_SLEEP_TIMEOUT);
                }
            }
        }
    } finally {
        if (null != mBufferedWriter) {
            mBufferedWriter.close();
        }
    }
    for (String app : mNameToResultKey.keySet()) {
        StringBuilder launchTimes = new StringBuilder();
        for (Long launch : mNameToLaunchTime.get(app)) {
            launchTimes.append(launch);
            launchTimes.append(",");
        }
        mResult.putString(mNameToResultKey.get(app), launchTimes.toString());
    }
    instrumentation.sendStatus(0, mResult);
}
Also used : Bundle(android.os.Bundle) ArrayList(java.util.ArrayList) IOException(java.io.IOException) BufferedWriter(java.io.BufferedWriter) AtraceLogger(android.support.test.rule.logging.AtraceLogger) InstrumentationTestRunner(android.test.InstrumentationTestRunner) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) File(java.io.File)

Example 5 with InstrumentationTestRunner

use of android.test.InstrumentationTestRunner in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class VpnTests method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    InputStream in = null;
    InstrumentationTestRunner mRunner = (InstrumentationTestRunner) getInstrumentation();
    mContext = mRunner.getContext();
    Bundle arguments = mRunner.getArguments();
    String PROFILE_NAME = arguments.getString("profile");
    Assert.assertNotNull("Push profile to external storage and load with" + "'-e profile <filename>'", PROFILE_NAME);
    File profileFile = new File(Environment.getExternalStorageDirectory(), PROFILE_NAME);
    in = new FileInputStream(profileFile);
    mVpnInfoPool = VpnProfileParser.parse(in);
    Assert.assertNotNull("no VPN profiles are parsed", mVpnInfoPool);
    if (DEBUG) {
        Log.v(TAG, "print out the vpn profiles");
        for (Map.Entry<Integer, VpnInfo> profileEntrySet : mVpnInfoPool.entrySet()) {
            VpnInfo vpnInfo = profileEntrySet.getValue();
            printVpnProfile(vpnInfo.getVpnProfile());
            if (vpnInfo.getCertificateFile() != null) {
                Log.d(TAG, "certificate file for this vpn is " + vpnInfo.getCertificateFile());
            }
            if (vpnInfo.getPassword() != null) {
                Log.d(TAG, "password for the certificate file is: " + vpnInfo.getPassword());
            }
        }
    }
    // disconnect existing vpn if there is any
    LegacyVpnInfo oldVpn = mService.getLegacyVpnInfo(UserHandle.myUserId());
    if (oldVpn != null) {
        Log.v(TAG, "disconnect legacy VPN");
        disconnect();
        // wait till the legacy VPN is disconnected.
        int tries = 0;
        while (tries < MAX_DISCONNECTION_TRIES && mService.getLegacyVpnInfo(UserHandle.myUserId()) != null) {
            tries++;
            Thread.sleep(10 * 1000);
            Log.v(TAG, "Wait for legacy VPN to be disconnected.");
        }
        Assert.assertNull("Failed to disconect VPN", mService.getLegacyVpnInfo(UserHandle.myUserId()));
        // wait for 30 seconds after the previous VPN is disconnected.
        sleep(30 * 1000);
    }
    // Create CertInstallerHelper to initialize the keystore
    mCertHelper = new CertInstallerHelper();
}
Also used : LegacyVpnInfo(com.android.internal.net.LegacyVpnInfo) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Bundle(android.os.Bundle) FileInputStream(java.io.FileInputStream) InstrumentationTestRunner(android.test.InstrumentationTestRunner) LegacyVpnInfo(com.android.internal.net.LegacyVpnInfo) File(java.io.File) Map(java.util.Map)

Aggregations

Bundle (android.os.Bundle)6 InstrumentationTestRunner (android.test.InstrumentationTestRunner)6 File (java.io.File)5 AtraceLogger (android.support.test.rule.logging.AtraceLogger)4 BufferedWriter (java.io.BufferedWriter)4 FileOutputStream (java.io.FileOutputStream)4 IOException (java.io.IOException)4 OutputStreamWriter (java.io.OutputStreamWriter)4 ArrayList (java.util.ArrayList)4 LegacyVpnInfo (com.android.internal.net.LegacyVpnInfo)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 Map (java.util.Map)1