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
calabash-android-0.4.20.1 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/ClearAppData.java
calabash-android-0.5.2 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/ClearAppData.java
calabash-android-0.5.2.pre1 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/ClearAppData.java
calabash-android-0.5.1 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/ClearAppData.java
calabash-android-0.5.0 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/ClearAppData.java
calabash-android-0.5.0.pre2 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/ClearAppData.java
calabash-android-0.5.0.pre1 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/ClearAppData.java
calabash-android-0.4.22.pre4 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/ClearAppData.java
calabash-android-0.4.22.pre3 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/ClearAppData.java
calabash-android-0.4.22.pre1 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/ClearAppData.java
calabash-android-0.4.21 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/ClearAppData.java
calabash-android-0.4.20 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/ClearAppData.java
calabash-android-0.4.19 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/ClearAppData.java
calabash-android-0.4.19.pre4 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/ClearAppData.java
calabash-android-0.4.19.pre3 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/ClearAppData.java
calabash-android-0.4.19.pre2 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/ClearAppData.java
calabash-android-0.4.19.pre1 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/ClearAppData.java
calabash-android-0.4.18 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/ClearAppData.java
calabash-android-0.4.16 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/ClearAppData.java
calabash-android-0.4.15.pre2 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/ClearAppData.java