/*
 * Copyright 2018 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.google.android.gnd;

import android.app.Activity;
import android.support.multidex.MultiDexApplication;
import com.akaita.java.rxjava2debug.RxJava2Debug;
import com.google.android.gnd.repository.GndDataRepository;
import dagger.android.AndroidInjector;
import dagger.android.DispatchingAndroidInjector;
import dagger.android.HasActivityInjector;
import javax.inject.Inject;

// TODO: When implementing background data sync service, we'll need to inject a Service here; we
// should then extend DaggerApplication instead. If MultiDex is still needed, we can install it
// without extending MultiDexApplication.
public class GndApplication extends MultiDexApplication implements HasActivityInjector {

  @Inject GndDataRepository dataRepository;
  @Inject DispatchingAndroidInjector<Activity> activityInjector;

  @Override
  public void onCreate() {
    super.onCreate();
    // Root of dependency injection.
    DaggerGndApplicationComponent.builder().create(this).inject(this);

    // Enable RxJava assembly stack collection for more useful stack traces.
    RxJava2Debug.enableRxJava2AssemblyTracking(new String[] {getClass().getPackage().getName()});

    // TODO: Implement GndDataRepository as LifecycleObserver.
    dataRepository.onCreate();
  }

  @Override
  public AndroidInjector<Activity> activityInjector() {
    return activityInjector;
  }
}

@@ -651,16 +651,46 @@
 tivity;%0A
+import android.os.StrictMode;%0A
 import a
@@ -734,16 +734,41 @@
 cation;%0A
+import android.util.Log;%0A
 import c
@@ -1353,16 +1353,90 @@
 jector %7B
+%0A  private static final String TAG = GndApplication.class.getSimpleName();
 %0A%0A  @Inj
@@ -1574,24 +1574,154 @@
 nCreate() %7B%0A
+    if (BuildConfig.DEBUG) %7B%0A      Log.d(TAG, %22DEBUG build config active; enabling debug tooling%22);%0A      setStrictMode();%0A    %7D%0A%0A
     super.on
@@ -1726,24 +1726,25 @@
 onCreate();%0A
+%0A
     // Root 
@@ -2179,24 +2179,24 @@
 njector() %7B%0A
-
     return a
@@ -2215,11 +2215,332 @@
 tor;%0A  %7D
+%0A%0A  private void setStrictMode() %7B%0A    StrictMode.setThreadPolicy(%0A      new StrictMode.ThreadPolicy.Builder().detectAll().penaltyLog().build());%0A%0A    StrictMode.setVmPolicy(%0A      new StrictMode.VmPolicy.Builder()%0A        .detectLeakedSqlLiteObjects()%0A        .penaltyLog()%0A        .penaltyDeath()%0A        .build());%0A  %7D
 %0A%7D%0A

Add debug tooling.