<commit_before>package com.github.hhyeg2016.mon.monitor;

import android.content.Context;
import android.app.usage.UsageEvents;
import android.app.usage.UsageStatsManager;
import android.util.Log;

import java.text.SimpleDateFormat;
import java.util.Calendar;

public class MonitorServiceThread extends Thread {
    private static Context context;

    private static int pingCount = 0;
    private static int REFRESH_RATE = 1000;

    public MonitorServiceThread() {}

    public MonitorServiceThread(Context context) {
        MonitorServiceThread.context = context;
    }


    public void run() {
        do {
            logUStats();
            pingCount++;
            try {
                Thread.sleep(REFRESH_RATE);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        } while (true);
    }

    public static void main(String args[]) {
        (new MonitorServiceThread()).start();
    }


    // Note user must enable permissions through "Settings > Security > Apps with usage access" first
    public static void logUStats(){
        SimpleDateFormat dateFormat = new SimpleDateFormat("M-d-yyyy HH:mm:ss");
        String TAG = "logUStats";

        UsageStatsManager usm = (UsageStatsManager) context.getSystemService(Context.USAGE_STATS_SERVICE);

        Calendar calendar = Calendar.getInstance();
        long endTime = calendar.getTimeInMillis();
        calendar.add(Calendar.MILLISECOND, -REFRESH_RATE);
        long startTime = calendar.getTimeInMillis();

        Log.d(TAG, "Range start:" + dateFormat.format(startTime) );
        Log.d(TAG, "Range end:" + dateFormat.format(endTime));

        UsageEvents uEvents = usm.queryEvents(startTime,endTime);
        while (uEvents.hasNextEvent()){
            UsageEvents.Event e = new UsageEvents.Event();
            uEvents.getNextEvent(e);

            if (e != null){
                Log.d(TAG, "Event: " + e.getPackageName() + "\t" +  e.getTimeStamp());
            }
        }
    }
}<commit_msg>Can get data on other apps running on the phone<commit_after>package com.github.hhyeg2016.mon.monitor;

import android.app.usage.UsageStats;
import android.content.Context;
import android.app.usage.UsageEvents;
import android.app.usage.UsageStatsManager;
import android.util.Log;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.List;

public class MonitorServiceThread extends Thread {
    private static Context context;

    private static int pingCount = 0;
    private static int REFRESH_RATE = 20000;

    public MonitorServiceThread() {}

    public MonitorServiceThread(Context context) {
        MonitorServiceThread.context = context;
    }


    public void run() {
        do {
            logUStats();
            pingCount++;
            try {
                Thread.sleep(REFRESH_RATE);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        } while (true);
    }

    public static void main(String args[]) {
        (new MonitorServiceThread()).start();
    }


    // Note user must enable permissions through "Settings > Security > Apps with usage access" first
    public static void logUStats(){
        SimpleDateFormat dateFormat = new SimpleDateFormat("M-d-yyyy HH:mm:ss");
        String TAG = "logUStats";

        UsageStatsManager usm = (UsageStatsManager) context.getSystemService(Context.USAGE_STATS_SERVICE);

        Calendar calendar = Calendar.getInstance();
        long endTime = calendar.getTimeInMillis();
        calendar.add(Calendar.MILLISECOND, -REFRESH_RATE);
        long startTime = calendar.getTimeInMillis();

        Log.d(TAG, "Range start:" + dateFormat.format(startTime) );
        Log.d(TAG, "Range end:" + dateFormat.format(endTime));

        // For now I have two ways of getting information from the UsageStatsManager
        // I can get the total foreground time of an app
        // I can also get the opening / closing events of an app

        List<UsageStats> list = usm.queryUsageStats(UsageStatsManager.INTERVAL_BEST, startTime, endTime);
        for(int i = 0; i < list.size(); i++) {
            Log.d(TAG, String.valueOf(list.get(i).getPackageName()) + " " + String.valueOf(list.get(i).getTotalTimeInForeground()));
            Log.d(TAG, String.valueOf(list.get(i).getLastTimeStamp() - list.get(i).getFirstTimeStamp()));
            Log.d(TAG, "");
        }

        UsageEvents events = usm.queryEvents(startTime, endTime);
        while (events.hasNextEvent()){
            UsageEvents.Event e = new UsageEvents.Event();
            events.getNextEvent(e);

            if (e != null){
                Log.d(TAG, "Event: " + e.getPackageName() + "\t" +  e.getTimeStamp() + "\t" + e.getEventType());
            }
        }
    }
}
{'fraction_non_alphanumeric': 0.11064891846921797, 'fraction_numerical': 0.004159733777038269, 'mean_word_length': 2.602247191011236, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 8, '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': '3112188', 'n_tokens_mistral': 1390, 'n_tokens_neox': 1318, 'n_words': 321}