Sha256: 43dfad0d1753c86d5a2d849821a3cddb8bb3f0c5eaa9004da24e580cb4d29cd8

Contents?: true

Size: 1.85 KB

Versions: 85

Compression:

Stored size: 1.85 KB

Contents

package sh.calaba.instrumentationbackend;

import java.io.File;

import android.accounts.Account;
import android.accounts.AccountManager;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.test.InstrumentationTestRunner;


public class ClearAppData extends InstrumentationTestRunner {
	@Override
    public void onCreate(Bundle arguments) {
        if (externalCacheDir() != null) {
            delete(externalCacheDir().getParentFile());
        }
        if (cacheDir() != null) {
            delete(cacheDir().getParentFile());
        }
        try {
            final AccountManager manager = AccountManager.get(getTargetContext());
            final Account[] accounts = manager.getAccounts();

            for (Account account : accounts) {
                try {
                    manager.removeAccount(account, null, null);
                } catch (Exception e) {
                    System.out.println("Unable to remove " + account.name + " of type " + account.type);
                }
            }
        } catch (Exception e) {
            System.out.println("Error removing accounts");
        }
	}

    //If provided a file will delete it. 
    //If provided a directory will recursively delete files but preserve directories
    private void delete(File file_or_directory) {
        if (file_or_directory == null) {
            return;
        }

        if (file_or_directory.isDirectory()) {
            if (file_or_directory.listFiles() != null) {
                for(File f : file_or_directory.listFiles()) {
                    delete(f);
                }
            }
        } else {
            file_or_directory.delete();
        }
    }
    
	private File externalCacheDir() { 
        return getTargetContext().getExternalCacheDir();
    }

    private File cacheDir() {
        return getTargetContext().getCacheDir();
    }

}

Version data entries

85 entries across 85 versions & 2 rubygems

Version Path
testautoa-0.4.2 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/ClearAppData.java
calabash-android-0.4.3.pre2 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/ClearAppData.java
calabash-android-0.4.3.pre1 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/ClearAppData.java
testautoa-0.4.1 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/ClearAppData.java
calabash-android-0.4.2 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/ClearAppData.java
calabash-android-0.4.1 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/ClearAppData.java
calabash-android-0.4.0 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/ClearAppData.java
calabash-android-0.4.0.pre18 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/ClearAppData.java
testautoa-0.4.0.pre19 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/ClearAppData.java
testautoa-0.4.0.pre18 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/ClearAppData.java
testautoa-0.4.0.pre16 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/ClearAppData.java
calabash-android-0.4.0.pre17 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/ClearAppData.java
calabash-android-0.4.0.pre16 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/ClearAppData.java
calabash-android-0.4.0.pre15 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/ClearAppData.java
calabash-android-0.4.0.pre11 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/ClearAppData.java
calabash-android-0.4.0.pre10 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/ClearAppData.java
calabash-android-0.4.0.pre9 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/ClearAppData.java
calabash-android-0.4.0.pre8 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/ClearAppData.java
calabash-android-0.4.0.pre7 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/ClearAppData.java
calabash-android-0.4.0.pre6 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/ClearAppData.java