<commit_before>package com.google.flutter.plugins.audiofileplayer;

import android.app.Activity;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.media.AudioManager;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.media.MediaBrowserCompat;
import android.support.v4.media.MediaMetadataCompat;
import android.support.v4.media.session.MediaSessionCompat;
import android.support.v4.media.session.PlaybackStateCompat;
import android.util.Log;
import android.view.KeyEvent;
import androidx.annotation.RequiresApi;
import androidx.core.app.NotificationCompat;
import androidx.media.MediaBrowserServiceCompat;
import androidx.media.app.NotificationCompat.MediaStyle;
import androidx.media.session.MediaButtonReceiver;
import java.util.List;

public class AudiofileplayerService extends MediaBrowserServiceCompat
    implements AudioManager.OnAudioFocusChangeListener {
  private static final String TAG = AudiofileplayerService.class.getSimpleName();
  private static final String MEDIA_ROOT_ID = "root";
  private static final String CHANNEL_ID = AudiofileplayerService.class.getName();
  private static final int NOTIFICATION_ID = 54321;

  static AudiofileplayerService instance;

  private AudiofileplayerService.ServiceListener listener;

  private MediaSessionCompat mediaSession;
  private MediaSessionCallback mediaSessionCallback;
  private MediaMetadataCompat metadata;
  private List<NotificationCompat.Action> notificationActions;
  private int[] compactNotificationActionIndices;

  private long playbackStateActions = 0;
  private int playbackStateState = PlaybackStateCompat.STATE_NONE;
  private long playbackStatePosition = 0;
  private float playbackStateSpeed = 0;

  public interface ServiceListener {
    void onMediaButtonClick(int keyCode);

    void onCustomMediaButtonClick(String eventId);

    void onSeekTo(long positionMs);
  }

  @Override
  public void onCreate() {
    super.onCreate();
    Log.i(TAG, "onCreate");
    instance = this;

    mediaSession = new MediaSessionCompat(this, TAG);
    mediaSession.setFlags(
        MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS
            | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);
    PlaybackStateCompat.Builder stateBuilder =
        new PlaybackStateCompat.Builder()
            .setActions(PlaybackStateCompat.ACTION_PLAY | PlaybackStateCompat.ACTION_PLAY_PAUSE);
    mediaSession.setPlaybackState(stateBuilder.build());

    mediaSessionCallback = new MediaSessionCallback(); // Do i need this as ivar?
    mediaSession.setCallback(mediaSessionCallback);

    setSessionToken(mediaSession.getSessionToken());
  }

  @Override
  public BrowserRoot onGetRoot(String clientPackageName, int clientUid, Bundle rootHints) {
    Log.i(TAG, "onGetRoot");
    return new BrowserRoot(MEDIA_ROOT_ID, null);
  }

  @Override
  public void onLoadChildren(
      final String parentMediaId, final Result<List<MediaBrowserCompat.MediaItem>> result) {
    Log.i(TAG, "onLoadChildren");
    result.sendResult(null);
  }

  @Override
  public int onStartCommand(final Intent intent, int flags, int startId) {
    Log.i(TAG, "onStartCommand");
    if (Intent.ACTION_MEDIA_BUTTON.equals(intent.getAction())
        && intent.hasExtra(AudiofileplayerPlugin.CUSTOM_MEDIA_BUTTON_EXTRA_KEY)) {
      // Check for custom button intent.
      handleCustomButtonIntent(intent);
    } else {
      // If there is a KeyEvent in the intent, send it to the MediaButtonReceiver to pass to
      // its callbacks.
      MediaButtonReceiver.handleIntent(mediaSession, intent);
    }
    return super.onStartCommand(intent, flags, startId);
  }

  @Override
  public void onDestroy() {
    Log.i(TAG, "onDestroy");
    instance = null;
    mediaSession.release();
    super.onDestroy();
  }
<commit_msg>Null pointer fix onStartCommand (#75)<commit_after>package com.google.flutter.plugins.audiofileplayer;

import android.app.Activity;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.media.AudioManager;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.media.MediaBrowserCompat;
import android.support.v4.media.MediaMetadataCompat;
import android.support.v4.media.session.MediaSessionCompat;
import android.support.v4.media.session.PlaybackStateCompat;
import android.util.Log;
import android.view.KeyEvent;
import androidx.annotation.RequiresApi;
import androidx.core.app.NotificationCompat;
import androidx.media.MediaBrowserServiceCompat;
import androidx.media.app.NotificationCompat.MediaStyle;
import androidx.media.session.MediaButtonReceiver;
import java.util.List;

public class AudiofileplayerService extends MediaBrowserServiceCompat
    implements AudioManager.OnAudioFocusChangeListener {
  private static final String TAG = AudiofileplayerService.class.getSimpleName();
  private static final String MEDIA_ROOT_ID = "root";
  private static final String CHANNEL_ID = AudiofileplayerService.class.getName();
  private static final int NOTIFICATION_ID = 54321;

  static AudiofileplayerService instance;

  private AudiofileplayerService.ServiceListener listener;

  private MediaSessionCompat mediaSession;
  private MediaSessionCallback mediaSessionCallback;
  private MediaMetadataCompat metadata;
  private List<NotificationCompat.Action> notificationActions;
  private int[] compactNotificationActionIndices;

  private long playbackStateActions = 0;
  private int playbackStateState = PlaybackStateCompat.STATE_NONE;
  private long playbackStatePosition = 0;
  private float playbackStateSpeed = 0;

  public interface ServiceListener {
    void onMediaButtonClick(int keyCode);

    void onCustomMediaButtonClick(String eventId);

    void onSeekTo(long positionMs);
  }

  @Override
  public void onCreate() {
    super.onCreate();
    Log.i(TAG, "onCreate");
    instance = this;

    mediaSession = new MediaSessionCompat(this, TAG);
    mediaSession.setFlags(
        MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS
            | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);
    PlaybackStateCompat.Builder stateBuilder =
        new PlaybackStateCompat.Builder()
            .setActions(PlaybackStateCompat.ACTION_PLAY | PlaybackStateCompat.ACTION_PLAY_PAUSE);
    mediaSession.setPlaybackState(stateBuilder.build());

    mediaSessionCallback = new MediaSessionCallback(); // Do i need this as ivar?
    mediaSession.setCallback(mediaSessionCallback);

    setSessionToken(mediaSession.getSessionToken());
  }

  @Override
  public BrowserRoot onGetRoot(String clientPackageName, int clientUid, Bundle rootHints) {
    Log.i(TAG, "onGetRoot");
    return new BrowserRoot(MEDIA_ROOT_ID, null);
  }

  @Override
  public void onLoadChildren(
      final String parentMediaId, final Result<List<MediaBrowserCompat.MediaItem>> result) {
    Log.i(TAG, "onLoadChildren");
    result.sendResult(null);
  }

  @Override
  public int onStartCommand(final Intent intent, int flags, int startId) {
    Log.i(TAG, "onStartCommand");
    if (intent != null){
      if (Intent.ACTION_MEDIA_BUTTON.equals(intent.getAction())
              && intent.hasExtra(AudiofileplayerPlugin.CUSTOM_MEDIA_BUTTON_EXTRA_KEY)) {
        // Check for custom button intent.
        handleCustomButtonIntent(intent);
      } else {
        // If there is a KeyEvent in the intent, send it to the MediaButtonReceiver to pass to
        // its callbacks.
        if (mediaSession != null){
          MediaButtonReceiver.handleIntent(mediaSession, intent);
        }
      }
    }
    return super.onStartCommand(intent, flags, startId);
  }

  @Override
  public void onDestroy() {
    Log.i(TAG, "onDestroy");
    instance = null;
    mediaSession.release();
    super.onDestroy();
  }

{'fraction_non_alphanumeric': 0.08297101449275363, 'fraction_numerical': 0.003140096618357488, 'mean_word_length': 4.844036697247707, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '3027189', 'n_tokens_mistral': 2298, 'n_tokens_neox': 2236, 'n_words': 510}