/*
 * Copyright 2020 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.android.tv.reference

import android.app.Application
import timber.log.Timber

/**
 * Initializes libraries, such as Timber, and sets up application wide settings.
 */
class TvReferenceApplication : Application() {

    override fun onCreate() {
        super.onCreate()

        // TODO(b/162013888): Plant a timber tree for non-debug builds.
        if (BuildConfig.DEBUG) {
            Timber.plant(Timber.DebugTree())
        }
    }
}

/*
 * Copyright 2020 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.android.tv.reference

import android.app.Application
import android.os.StrictMode
import timber.log.Timber

/**
 * Initializes libraries, such as Timber, and sets up application wide settings.
 */
class TvReferenceApplication : Application() {

    override fun onCreate() {
        super.onCreate()

        if (BuildConfig.DEBUG) {
            enableStrictMode()
        }

        // TODO(b/162013888): Plant a timber tree for non-debug builds.
        if (BuildConfig.DEBUG) {
            Timber.plant(Timber.DebugTree())
        }
    }

    private fun enableStrictMode() {
        StrictMode.setThreadPolicy(
            StrictMode.ThreadPolicy.Builder()
                .detectDiskReads()
                .detectDiskWrites()
                .detectNetwork()
                .penaltyLog()
                .build()
        )
    }
}

Enable StrictMode for debug builds
Enable StrictMode for debug builds

The penalty is only set to log so this should not prevent development yet still give developers a way to easily spot/find the violation.

Bug: 162035725
Change-Id: Id518dda3076c395a8f2721dd780fc5c3a6e8f60c

android/tv-samples,android/tv-samples,android/tv-samples,android/tv-samples,android/tv-samples,android/tv-samples,android/tv-samples