/*
 * Copyright 2015 Google Inc. All rights reserved.
 *
 * 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
 *
 *      http://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.samples.apps.iosched;

import android.app.Application;
import android.content.Intent;
import android.support.multidex.MultiDex;

import com.firebase.client.Firebase;
import com.google.android.gms.security.ProviderInstaller;
import com.google.samples.apps.iosched.settings.SettingsUtils;
import com.google.samples.apps.iosched.util.AnalyticsHelper;
import com.google.samples.apps.iosched.util.TimeUtils;

import static com.google.samples.apps.iosched.util.LogUtils.LOGE;
import static com.google.samples.apps.iosched.util.LogUtils.LOGW;
import static com.google.samples.apps.iosched.util.LogUtils.makeLogTag;

/**
 * {@link android.app.Application} used to initialize Analytics. Code initialized in Application
 * classes is rare since this code will be run any time a ContentProvider, Activity, or Service is
 * used by the user or system. Analytics, dependency injection, and multi-dex frameworks are in this
 * very small set of use cases.
 */
public class AppApplication extends Application {

    private static final String TAG = makeLogTag(AppApplication.class);

    @Override
    public void onCreate() {
        super.onCreate();
        TimeUtils.setAppStartTime(getApplicationContext(), System.currentTimeMillis());
        MultiDex.install(this);

        // Initialize the Firebase library with an Android context.
        Firebase.setAndroidContext(this);

        AnalyticsHelper.prepareAnalytics(getApplicationContext());
        SettingsUtils.markDeclinedWifiSetup(getApplicationContext(), false);

        // Ensure an updated security provider is installed into the system when a new one is
        // available via Google Play services.
        try {
            ProviderInstaller.installIfNeededAsync(getApplicationContext(),
                    new ProviderInstaller.ProviderInstallListener() {
                        @Override
                        public void onProviderInstalled() {
                            LOGW(TAG, "New security provider installed.");
                        }

                        @Override
                        public void onProviderInstallFailed(int errorCode, Intent intent) {
                            LOGE(TAG, "New security provider install failed.");
                            // No notification shown there is no user intervention needed.
                        }
                    });
        } catch (Exception ignorable) {
            LOGE(TAG, "Unknown issue trying to install a new security provider.", ignorable);
        }
    }
}

@@ -668,31 +668,31 @@
 android.
-app.Application
+content.Context
 ;%0Aimport
@@ -757,16 +757,69 @@
 ultiDex;
+%0Aimport android.support.multidex.MultiDexApplication;
 %0A%0Aimport
@@ -1665,16 +1665,24 @@
 extends 
+MultiDex
 Applicat
@@ -1921,40 +1921,8 @@
 ());
-%0A        MultiDex.install(this);
 %0A%0A  
@@ -3153,16 +3153,16 @@
 rable);%0A
-
         
@@ -3168,11 +3168,156 @@
  %7D%0A    %7D
+%0A%0A    @Override%0A    protected void attachBaseContext(Context base) %7B%0A        super.attachBaseContext(base);%0A        MultiDex.install(this);%0A    %7D
 %0A%7D%0A

Fix for multidex crash on Dalvik