-
-
Notifications
You must be signed in to change notification settings - Fork 671
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add authentication to widget buttons (#2798)
- Loading branch information
Showing
10 changed files
with
825 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
...in/java/io/homeassistant/companion/android/widgets/common/WidgetAuthenticationActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package io.homeassistant.companion.android.widgets.common | ||
|
||
import android.appwidget.AppWidgetManager | ||
import android.content.Intent | ||
import android.os.Bundle | ||
import android.util.Log | ||
import android.widget.Toast | ||
import androidx.appcompat.app.AppCompatActivity | ||
import io.homeassistant.companion.android.authenticator.Authenticator | ||
import io.homeassistant.companion.android.common.R | ||
import io.homeassistant.companion.android.widgets.button.ButtonWidget | ||
|
||
class WidgetAuthenticationActivity : AppCompatActivity() { | ||
companion object { | ||
private const val TAG = "WidgetAuthenticationA" | ||
} | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
Log.d(TAG, "onCreate in WidgetAuthenticationActivity called") | ||
|
||
val authenticator = Authenticator(this, this, ::authenticationResult) | ||
authenticator.authenticate(getString(R.string.biometric_set_title)) | ||
} | ||
|
||
private fun authenticationResult(result: Int) { | ||
when (result) { | ||
Authenticator.SUCCESS -> { | ||
Log.d(TAG, "Authentication successful, calling requested service") | ||
val appWidgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) | ||
if (appWidgetId > -1) { | ||
val intent = Intent(applicationContext, ButtonWidget::class.java).apply { | ||
action = ButtonWidget.CALL_SERVICE | ||
putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId) | ||
} | ||
sendBroadcast(intent) | ||
} | ||
finishAffinity() | ||
} | ||
Authenticator.CANCELED -> { | ||
Log.d(TAG, "Authentication canceled by user, closing activity") | ||
finishAffinity() | ||
} | ||
else -> { | ||
Log.d(TAG, "Authentication failed, retry attempts allowed") | ||
Toast.makeText(applicationContext, getString(R.string.widget_error_authenticating), Toast.LENGTH_LONG).show() | ||
finishAffinity() | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.