<commit_before>package com.frozendevs.cache.cleaner.helper;

import android.content.pm.ApplicationInfo;
import android.content.pm.IPackageDataObserver;
import android.content.pm.IPackageStatsObserver;
import android.content.pm.PackageManager;
import android.content.pm.PackageStats;
import android.os.AsyncTask;
import android.os.Environment;
import android.os.Handler;
import android.os.Looper;
import android.os.RemoteException;
import android.os.StatFs;

import com.frozendevs.cache.cleaner.model.AppsListItem;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CountDownLatch;

public class CacheManager {

    private PackageManager mPackageManager;
    private Method mGetPackageSizeInfoMethod, mFreeStorageAndNotifyMethod;
    private OnActionListener mOnActionListener = null;
    private boolean mIsScanning = false;
    private boolean mIsCleaning = false;
    private long mCacheSize = 0;

    public static interface OnActionListener {
        public void onScanStarted(int appsCount);

        public void onScanProgressUpdated(int current, int max);

        public void onScanCompleted(List<AppsListItem> apps);

        public void onCleanStarted();

        public void onCleanCompleted(long cacheSize);
    }

    private class TaskScan extends AsyncTask<Void, Integer, List<AppsListItem>> {

        private int mAppCount = 0;

        @Override
        protected List<AppsListItem> doInBackground(Void... params) {
            mCacheSize = 0;

            final List<ApplicationInfo> packages = mPackageManager.getInstalledApplications(
                    PackageManager.GET_META_DATA);

            if (mOnActionListener != null) {
                final CountDownLatch countDownLatch = new CountDownLatch(1);

                new Handler(Looper.getMainLooper()).post(new Runnable() {
                    @Override
                    public void run() {
                        mOnActionListener.onScanStarted(packages.size());

                        countDownLatch.countDown();
                    }
                });

                try {
                    countDownLatch.await();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }

            final CountDownLatch countDownLatch = new CountDownLatch(packages.size());

            final List<AppsListItem> apps = new ArrayList<AppsListItem>();

            try {<commit_msg>CacheManager: Do onScanStarted() in onPreExecute() instead of doInBackground()<commit_after>package com.frozendevs.cache.cleaner.helper;

import android.content.pm.ApplicationInfo;
import android.content.pm.IPackageDataObserver;
import android.content.pm.IPackageStatsObserver;
import android.content.pm.PackageManager;
import android.content.pm.PackageStats;
import android.os.AsyncTask;
import android.os.Environment;
import android.os.RemoteException;
import android.os.StatFs;

import com.frozendevs.cache.cleaner.model.AppsListItem;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CountDownLatch;

public class CacheManager {

    private PackageManager mPackageManager;
    private Method mGetPackageSizeInfoMethod, mFreeStorageAndNotifyMethod;
    private OnActionListener mOnActionListener = null;
    private boolean mIsScanning = false;
    private boolean mIsCleaning = false;
    private long mCacheSize = 0;

    public static interface OnActionListener {
        public void onScanStarted(int appsCount);

        public void onScanProgressUpdated(int current, int max);

        public void onScanCompleted(List<AppsListItem> apps);

        public void onCleanStarted();

        public void onCleanCompleted(long cacheSize);
    }

    private class TaskScan extends AsyncTask<Void, Integer, List<AppsListItem>> {

        private int mAppCount = 0;

        @Override
        protected void onPreExecute() {
            if (mOnActionListener != null) {
                mOnActionListener.onScanStarted(0);
            }
        }

        @Override
        protected List<AppsListItem> doInBackground(Void... params) {
            mCacheSize = 0;

            final List<ApplicationInfo> packages = mPackageManager.getInstalledApplications(
                    PackageManager.GET_META_DATA);

            publishProgress(0, packages.size());

            final CountDownLatch countDownLatch = new CountDownLatch(packages.size());

            final List<AppsListItem> apps = new ArrayList<AppsListItem>();

            try {
{'fraction_non_alphanumeric': 0.07826456826882178, 'fraction_numerical': 0.0019140791152700979, 'mean_word_length': 2.975486052409129, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '422159', 'n_tokens_mistral': 1272, 'n_tokens_neox': 1213, 'n_words': 278}