<commit_before>//
//  ActivityHandler.java
//  AdjustIo
//
//  Created by <NAME> on 2013-06-25.
//  Copyright (c) 2013 adeven. All rights reserved.
//  See the file MIT-LICENSE for copying permission.
//

package com.adeven.adjustio;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.NotSerializableException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OptionalDataException;
import java.lang.ref.WeakReference;
import java.util.Date;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Looper;
import android.os.Message;

public class ActivityHandler extends HandlerThread {
    private static final String SESSION_STATE_FILENAME = "AdjustIoActivityState";

    private static final long TIMER_INTERVAL      = 1000 * 60 * 1;  // 1 minute
    private static final long SESSION_INTERVAL    = 1000 * 60 * 30; // 30 minutes
    private static final long SUBSESSION_INTERVAL = 1000 * 1;       // one second

    private InternalHandler internalHandler;
    private PackageHandler packageHandler;
    private ActivityState activityState;
    private static ScheduledExecutorService timer;
    private Context context;

    private String appToken;
    private String macSha1;
    private String macShortMd5;
    private String androidId;       // everything else here could be persisted
    private String fbAttributionId;
    private String userAgent;       // changes, should be updated periodically
    private String clientSdk;

    protected ActivityHandler(String appToken, Context context) {
        super(Logger.LOGTAG, MIN_PRIORITY);
        setDaemon(true);
        start();
        internalHandler = new InternalHandler(getLooper(), this);

        this.context = context;

        Message message = Message.obtain();
        message.arg1 = InternalHandler.INIT;
        message.obj = appToken;
        internalHandler.sendMessage(message);
    }

    protected void trackSubsessionStart() {
        Message message = Message.obtain();
        message.arg1 = InternalHandler.START;
        internalHandler.sendMessage(message);
    }

    protected void trackSubsessionEnd() {
        Message message = Message.obtain();<commit_msg>Use ApplicationContext instead of ActivityContext<commit_after>//
//  ActivityHandler.java
//  AdjustIo
//
//  Created by <NAME> on 2013-06-25.
//  Copyright (c) 2013 adeven. All rights reserved.
//  See the file MIT-LICENSE for copying permission.
//

package com.adeven.adjustio;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.NotSerializableException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OptionalDataException;
import java.lang.ref.WeakReference;
import java.util.Date;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

import android.app.Activity;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Looper;
import android.os.Message;

public class ActivityHandler extends HandlerThread {
    private static final String SESSION_STATE_FILENAME = "AdjustIoActivityState";

    private static final long TIMER_INTERVAL      = 1000 * 60 * 1;  // 1 minute
    private static final long SESSION_INTERVAL    = 1000 * 60 * 30; // 30 minutes
    private static final long SUBSESSION_INTERVAL = 1000 * 1;       // one second

    private InternalHandler internalHandler;
    private PackageHandler packageHandler;
    private ActivityState activityState;
    private static ScheduledExecutorService timer;
    private Context context;

    private String appToken;
    private String macSha1;
    private String macShortMd5;
    private String androidId;       // everything else here could be persisted
    private String fbAttributionId;
    private String userAgent;       // changes, should be updated periodically
    private String clientSdk;

    protected ActivityHandler(String appToken, Activity activity) {
        super(Logger.LOGTAG, MIN_PRIORITY);
        setDaemon(true);
        start();
        internalHandler = new InternalHandler(getLooper(), this);

        this.context = activity.getApplicationContext();

        Message message = Message.obtain();
        message.arg1 = InternalHandler.INIT;
        message.obj = appToken;
        internalHandler.sendMessage(message);
    }

    protected void trackSubsessionStart() {
        Message message = Message.obtain();
        message.arg1 = InternalHandler.START;
        internalHandler.sendMessage(message);
    }

    protected void trackSubsessionEnd() {
        Message message = Message.obtain();
{'fraction_non_alphanumeric': 0.08115183246073299, 'fraction_numerical': 0.014584891548242334, 'mean_word_length': 3.7252650176678443, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '5558593', 'n_tokens_mistral': 1483, 'n_tokens_neox': 1382, 'n_words': 397}