<commit_before>/*Copyright (C) 2010-2012 Institute for Software Integrated Systems (ISIS)
This software was developed by the Institute for Software Integrated
Systems (ISIS) at Vanderbilt University, Tennessee, USA for the 
Transformative Apps program under DARPA, Contract # HR011-10-C-0175.
The United States Government has unlimited rights to this software. 
The US government has the right to use, modify, reproduce, release, 
perform, display, or disclose computer software or computer software 
documentation in whole or in part, in any manner and for any 
purpose whatsoever, and to have or authorize others to do so.
 */

package edu.vu.isis.ammo.core.provider;

import java.io.FileNotFoundException;
import java.util.concurrent.atomic.AtomicReference;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import android.content.ComponentName;
import android.content.ContentProvider;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.content.UriMatcher;
import android.database.Cursor;
import android.net.Uri;
import android.os.IBinder;
import android.os.ParcelFileDescriptor;
import edu.vu.isis.ammo.core.AmmoService;
import edu.vu.isis.ammo.core.distributor.DistributorDataStore;
import edu.vu.isis.ammo.core.distributor.store.RelationsHelper;
import edu.vu.isis.ammo.util.Genealogist;

public class DistributorProvider extends ContentProvider {
    // =================================
    // Constants
    // =================================

    public static final String DATABASE_NAME = DistributorDataStore.SQLITE_NAME;

    private static final UriMatcher uriMatcher;
    private static final UriMatcher garbageMatcher;
    /**
     * ordinal values are returned by the uri which may then be used to retrieve
     * the relation enum.
     */
    static {
        uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
        garbageMatcher = new UriMatcher(UriMatcher.NO_MATCH);
        for (final Relations table : Relations.values()) {
            uriMatcher.addURI(DistributorSchema.AUTHORITY, table.n, table.ordinal());
            garbageMatcher.addURI(DistributorSchema.AUTHORITY, table.n + "/garbage",
                    table.ordinal());
        }
    }

    // =================================
    // Fields
    // =================================
    private static final Logger logger = LoggerFactory.getLogger("provider.dist");

    // =================================
    // setup
    // =================================

    private DistributorDataStore dds;
    private static final Intent AMMO_SERVICE;
    static {
        AMMO_SERVICE = new Intent();
        final ComponentName serviceComponent =
                new ComponentName(AmmoService.class.getPackage().getName(),
                        AmmoService.class.getCanonicalName());
        AMMO_SERVICE.setComponent(serviceComponent);
    }

    final AtomicReference<ServiceConnection> conn = new AtomicReference<ServiceConnection>();
    public boolean isBound = false;

    /**
     * Make a local binding to the AmmoService and get the DDS.
     */
    @Override
    public boolean onCreate() {
        if (!this.conn.equals(null))
            return true;

        this.dds = null;
        conn.set(new ServiceConnection() {
            final DistributorProvider parent = DistributorProvider.this;

            @Override
            public void onServiceConnected(ComponentName name, IBinder binder) {
                if (!(binder instanceof AmmoService.DistributorServiceAidl)) {
                    logger.error("service connected type=[{}]", Genealogist.getAncestry(binder));
                    return;
                }
                final AmmoService.DistributorServiceAidl proxy = (AmmoService.DistributorServiceAidl) binder;
                final AmmoService service = proxy.getService();

                parent.dds = service.store();
                parent.isBound = true;
            }

            @Override
            public void onServiceDisconnected(ComponentName name) {
                parent.isBound = false;
                return;
            }
        });
        final boolean isBindable = this.getContext().bindService(AMMO_SERVICE, conn.get(),
                Context.BIND_AUTO_CREATE);
        return isBindable;
    }
<commit_msg>allow the creation of the distributor content provider<commit_after>/*Copyright (C) 2010-2012 Institute for Software Integrated Systems (ISIS)
This software was developed by the Institute for Software Integrated
Systems (ISIS) at Vanderbilt University, Tennessee, USA for the 
Transformative Apps program under DARPA, Contract # HR011-10-C-0175.
The United States Government has unlimited rights to this software. 
The US government has the right to use, modify, reproduce, release, 
perform, display, or disclose computer software or computer software 
documentation in whole or in part, in any manner and for any 
purpose whatsoever, and to have or authorize others to do so.
 */

package edu.vu.isis.ammo.core.provider;

import java.io.FileNotFoundException;
import java.util.concurrent.atomic.AtomicReference;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import android.content.ComponentName;
import android.content.ContentProvider;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.content.UriMatcher;
import android.database.Cursor;
import android.net.Uri;
import android.os.IBinder;
import android.os.ParcelFileDescriptor;
import edu.vu.isis.ammo.core.AmmoService;
import edu.vu.isis.ammo.core.distributor.DistributorDataStore;
import edu.vu.isis.ammo.core.distributor.store.RelationsHelper;
import edu.vu.isis.ammo.util.Genealogist;

public class DistributorProvider extends ContentProvider {
    // =================================
    // Constants
    // =================================

    public static final String DATABASE_NAME = DistributorDataStore.SQLITE_NAME;

    private static final UriMatcher uriMatcher;
    private static final UriMatcher garbageMatcher;
    /**
     * ordinal values are returned by the uri which may then be used to retrieve
     * the relation enum.
     */
    static {
        uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
        garbageMatcher = new UriMatcher(UriMatcher.NO_MATCH);
        for (final Relations table : Relations.values()) {
            uriMatcher.addURI(DistributorSchema.AUTHORITY, table.n, table.ordinal());
            garbageMatcher.addURI(DistributorSchema.AUTHORITY, table.n + "/garbage",
                    table.ordinal());
        }
    }

    // =================================
    // Fields
    // =================================
    private static final Logger logger = LoggerFactory.getLogger("provider.dist");

    // =================================
    // setup
    // =================================

    private DistributorDataStore dds;
    private static final Intent AMMO_SERVICE;
    static {
        AMMO_SERVICE = new Intent();
        final ComponentName serviceComponent =
                new ComponentName(AmmoService.class.getPackage().getName(),
                        AmmoService.class.getCanonicalName());
        AMMO_SERVICE.setComponent(serviceComponent);
    }

    final AtomicReference<ServiceConnection> conn = new AtomicReference<ServiceConnection>();
    public boolean isBound = false;

    /**
     * Make a local binding to the AmmoService and get the DDS.
     */
    @Override
    public boolean onCreate() {
        if (this.conn.get() != null)
            return true;

        this.dds = null;
        conn.set(new ServiceConnection() {
            final DistributorProvider parent = DistributorProvider.this;

            @Override
            public void onServiceConnected(ComponentName name, IBinder binder) {
                if (!(binder instanceof AmmoService.DistributorServiceAidl)) {
                    logger.error("service connected type=[{}]", Genealogist.getAncestry(binder));
                    return;
                }
                final AmmoService.DistributorServiceAidl proxy = (AmmoService.DistributorServiceAidl) binder;
                final AmmoService service = proxy.getService();

                parent.dds = service.store();
                parent.isBound = true;
            }

            @Override
            public void onServiceDisconnected(ComponentName name) {
                parent.isBound = false;
                return;
            }
        });
        final boolean isBindable = this.getContext().bindService(AMMO_SERVICE, conn.get(),
                Context.BIND_AUTO_CREATE);
        return isBindable;
    }

{'fraction_non_alphanumeric': 0.12353409996584311, 'fraction_numerical': 0.004326539906637823, 'mean_word_length': 2.9567567567567568, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '829629', 'n_tokens_mistral': 2358, 'n_tokens_neox': 2198, 'n_words': 596}