Skip to content

Commit

Permalink
Fix a metric tonne of lint warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
mrober committed Oct 30, 2023
1 parent 5ed4a64 commit 86d6033
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package com.google.firebase.testing.sessions
import android.app.ActivityManager
import android.app.ActivityManager.RunningAppProcessInfo
import android.app.Application
import android.os.Build
import android.os.Bundle
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
Expand Down Expand Up @@ -63,7 +64,12 @@ open class BaseActivity : AppCompatActivity() {
return processInfo.importance
}

private fun getProcessName(): String = Application.getProcessName()
private fun getProcessName(): String =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
Application.getProcessName()
} else {
""
}

companion object {
val TAG = "BaseActivity"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import android.appwidget.AppWidgetProvider
import android.content.Context
import android.content.Intent
import android.icu.text.SimpleDateFormat
import android.os.Build
import android.widget.RemoteViews
import com.google.firebase.FirebaseApp
import java.util.Date
Expand All @@ -43,7 +44,9 @@ class CrashWidgetProvider : AppWidgetProvider() {
val views: RemoteViews =
RemoteViews(context.packageName, R.layout.crash_widget).apply {
setOnClickPendingIntent(R.id.widgetCrashButton, getPendingCrashIntent(context))
setTextViewText(R.id.widgetTimeText, DATE_FMT.format(Date()))
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
setTextViewText(R.id.widgetTimeText, DATE_FMT?.format(Date()) ?: "")
}
}

// Tell the AppWidgetManager to perform an update on the current
Expand Down Expand Up @@ -73,6 +76,11 @@ class CrashWidgetProvider : AppWidgetProvider() {

companion object {
val CRASH_BUTTON_CLICK = "widgetCrashButtonClick"
val DATE_FMT = SimpleDateFormat("HH:mm:ss", Locale.getDefault())
val DATE_FMT =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
SimpleDateFormat("HH:mm:ss", Locale.US)
} else {
null
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import android.content.Intent
import android.content.Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT
import android.content.Intent.FLAG_ACTIVITY_NEW_TASK
import android.icu.text.SimpleDateFormat
import android.os.Build
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
Expand Down Expand Up @@ -65,10 +66,12 @@ class FirstFragment : Fragment() {
}
binding.buttonForegroundProcess.setOnClickListener {
if (binding.buttonForegroundProcess.getText().startsWith("Start")) {
ForegroundService.startService(
getContext()!!,
"Starting service at ${DATE_FMT.format(Date())}"
)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
ForegroundService.startService(
getContext()!!,
"Starting service at ${DATE_FMT?.format(Date()) ?: ""}"
)
}
binding.buttonForegroundProcess.setText("Stop foreground service")
} else {
ForegroundService.stopService(getContext()!!)
Expand Down Expand Up @@ -98,6 +101,11 @@ class FirstFragment : Fragment() {
}

companion object {
val DATE_FMT = SimpleDateFormat("HH:mm:ss", Locale.getDefault())
val DATE_FMT =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
SimpleDateFormat("HH:mm:ss", Locale.getDefault())
} else {
null
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class ForegroundService : Service() {
}

companion object {
val TAG = "CrashWidgetForegroundService"
val TAG = "CrashWidgetForeServ"

fun startService(context: Context, message: String) {
Log.i(TAG, "Starting foreground serice")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package com.google.firebase.testing.sessions
import android.app.ActivityManager
import android.content.Intent
import android.content.Intent.FLAG_ACTIVITY_NEW_TASK
import android.os.Build
import android.os.Bundle
import android.widget.Button

Expand All @@ -34,8 +35,10 @@ class SecondActivity : BaseActivity() {
startActivity(intent)
}
findViewById<Button>(R.id.kill_background_processes).setOnClickListener {
getSystemService(ActivityManager::class.java)
.killBackgroundProcesses("com.google.firebase.testing.sessions")
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
getSystemService(ActivityManager::class.java)
.killBackgroundProcesses("com.google.firebase.testing.sessions")
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright 2023 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
~
~ 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.
-->

<resources>

<style name="Theme.Widget_test_app" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/purple_200</item>
<item name="colorPrimaryVariant">@color/purple_700</item>
<item name="colorOnPrimary">@color/black</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">@color/teal_200</item>
<item name="colorSecondaryVariant">@color/teal_200</item>
<item name="colorOnSecondary">@color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
</style>
</resources>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf8"?><!--
<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright 2023 Google LLC
~
~ Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -25,8 +25,6 @@
<item name="colorSecondary">@color/teal_200</item>
<item name="colorSecondaryVariant">@color/teal_200</item>
<item name="colorOnSecondary">@color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
</style>
</resources>
2 changes: 1 addition & 1 deletion firebase-sessions/test-app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf8"?><!--
<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright 2023 Google LLC
~
~ Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
4 changes: 1 addition & 3 deletions firebase-sessions/test-app/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf8"?><!--
<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright 2023 Google LLC
~
~ Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -25,8 +25,6 @@
<item name="colorSecondary">@color/teal_200</item>
<item name="colorSecondaryVariant">@color/teal_700</item>
<item name="colorOnSecondary">@color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
</style>

Expand Down

0 comments on commit 86d6033

Please sign in to comment.