<commit_before>package com.audacious_software.passive_data_kit.activities.generators;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;

import com.audacious_software.passive_data_kit.generators.services.GoogleFit;
import com.google.android.gms.auth.api.signin.GoogleSignIn;
import com.google.android.gms.fitness.FitnessOptions;
import com.google.android.gms.fitness.data.DataType;

public class RequestPermissionActivity extends Activity
{
    public static final String PERMISSION = "com.audacious_software.passive_data_kit.activities.generators.RequestPermissionActivity.PERMISSION";

    private static final int GOOGLE_FIT_PERMISSIONS_REQUEST_CODE = 86753;

    protected void onResume()
    {
        super.onResume();

        Bundle extras = this.getIntent().getExtras();

        String permission = extras.getString(RequestPermissionActivity.PERMISSION);

        if (GoogleFit.GOOGLE_FIT_PERMISSIONS.equals(permission)) {
            FitnessOptions.Builder builder = FitnessOptions.builder();

            for (DataType type : GoogleFit.getInstance(this).allDataTypes()) {
                if (extras.getBoolean(type.getName(), false)) {
                    builder.addDataType(type, FitnessOptions.ACCESS_READ);
                }
            }

            FitnessOptions options = builder.build();

            GoogleSignIn.requestPermissions(this, RequestPermissionActivity.GOOGLE_FIT_PERMISSIONS_REQUEST_CODE, GoogleSignIn.getLastSignedInAccount(this), options);
        } else {
            ActivityCompat.requestPermissions(this, new String[]{permission}, 0);
        }
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[], @NonNull int[] grantResults) {
        this.finish();
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (resultCode == Activity.RESULT_OK) {
            if (requestCode == GOOGLE_FIT_PERMISSIONS_REQUEST_CODE) {
                GoogleFit.stop(this);
                GoogleFit.start(this);

                this.finish();
            }
        }
    }
}
<commit_msg>Debugging Google Fit permission issues<commit_after>package com.audacious_software.passive_data_kit.activities.generators;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;
import android.util.Log;

import com.audacious_software.passive_data_kit.generators.services.GoogleFit;
import com.google.android.gms.auth.api.signin.GoogleSignIn;
import com.google.android.gms.fitness.FitnessOptions;
import com.google.android.gms.fitness.data.DataType;

public class RequestPermissionActivity extends Activity
{
    public static final String PERMISSION = "com.audacious_software.passive_data_kit.activities.generators.RequestPermissionActivity.PERMISSION";

    private static final int GOOGLE_FIT_PERMISSIONS_REQUEST_CODE = 86753;

    private boolean mIsRequesting = false;

    protected void onCreate(Bundle data) {
        super.onCreate(data);

        this.mIsRequesting = false;
    }

    protected void onResume() {
        super.onResume();

        if (this.mIsRequesting == false) {
            this.mIsRequesting = true;

            Bundle extras = this.getIntent().getExtras();

            String permission = extras.getString(RequestPermissionActivity.PERMISSION);

            if (GoogleFit.GOOGLE_FIT_PERMISSIONS.equals(permission)) {
                FitnessOptions.Builder builder = FitnessOptions.builder();

                for (DataType type : GoogleFit.getInstance(this).allDataTypes()) {
                    if (extras.getBoolean(type.getName(), false)) {
                        builder.addDataType(type, FitnessOptions.ACCESS_READ);
                    }
                }

                FitnessOptions options = builder.build();

                GoogleSignIn.requestPermissions(this, RequestPermissionActivity.GOOGLE_FIT_PERMISSIONS_REQUEST_CODE, GoogleSignIn.getLastSignedInAccount(this), options);
            } else {
                ActivityCompat.requestPermissions(this, new String[]{permission}, 0);
            }
        }
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[], @NonNull int[] grantResults) {
        this.finish();
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        Log.e("PDK", "REQUEST CODE: " + requestCode + " -- " + resultCode + " DATA: " + data);

        if (resultCode == Activity.RESULT_OK) {
            if (requestCode == GOOGLE_FIT_PERMISSIONS_REQUEST_CODE) {
                GoogleFit.stop(this);
                GoogleFit.start(this);

                this.finish();

                return;
            }
        }

        final RequestPermissionActivity me = this;

        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("Google Fit Permission Failed");
        builder.setMessage("Report to <EMAIL>:\n\nRequest Code: " + requestCode + "\nResult Code: " + resultCode);

        builder.setPositiveButton("Close", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                me.finish();
            }
        });

        builder.create().show();
    }
}

{'fraction_non_alphanumeric': 0.09227839335180055, 'fraction_numerical': 0.0024238227146814403, 'mean_word_length': 2.644794952681388, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, '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': '6821566', 'n_tokens_mistral': 1618, 'n_tokens_neox': 1500, 'n_words': 272}