Merge "Controls - Remove support for mock" into rvc-dev am: 1667d235ea am: 40b6657698 am: 81bb5b48ce am: ad7eb9d0bc
Change-Id: Ib7fe413902b74371c2f13874a3e6fcfa0e82d00c
This commit is contained in:
@@ -1,7 +0,0 @@
|
||||
package android.service.controls;
|
||||
|
||||
/** @hide */
|
||||
interface TokenProvider {
|
||||
void setAuthToken(String token);
|
||||
String getAccountName();
|
||||
}
|
||||
@@ -16,19 +16,14 @@
|
||||
|
||||
package com.android.systemui.controls.ui
|
||||
|
||||
import android.accounts.Account
|
||||
import android.accounts.AccountManager
|
||||
import android.app.Dialog
|
||||
import android.content.ComponentName
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.ServiceConnection
|
||||
import android.content.SharedPreferences
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.graphics.drawable.LayerDrawable
|
||||
import android.os.IBinder
|
||||
import android.service.controls.Control
|
||||
import android.service.controls.TokenProvider
|
||||
import android.service.controls.actions.ControlAction
|
||||
import android.util.Log
|
||||
import android.view.ContextThemeWrapper
|
||||
@@ -61,68 +56,6 @@ import java.text.Collator
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
// TEMP CODE for MOCK
|
||||
private const val TOKEN = "https://www.googleapis.com/auth/assistant"
|
||||
private const val SCOPE = "oauth2:" + TOKEN
|
||||
private var tokenProviderConnection: TokenProviderConnection? = null
|
||||
class TokenProviderConnection(
|
||||
val cc: ControlsController,
|
||||
val context: Context,
|
||||
val structure: StructureInfo?
|
||||
) : ServiceConnection {
|
||||
private var mTokenProvider: TokenProvider? = null
|
||||
|
||||
override fun onServiceConnected(cName: ComponentName, binder: IBinder) {
|
||||
Thread({
|
||||
Log.i(ControlsUiController.TAG, "TokenProviderConnection connected")
|
||||
mTokenProvider = TokenProvider.Stub.asInterface(binder)
|
||||
|
||||
val mLastAccountName = mTokenProvider?.getAccountName()
|
||||
|
||||
if (mLastAccountName == null || mLastAccountName.isEmpty()) {
|
||||
Log.e(ControlsUiController.TAG, "NO ACCOUNT IS SET. Open HomeMock app")
|
||||
} else {
|
||||
mTokenProvider?.setAuthToken(getAuthToken(mLastAccountName))
|
||||
structure?.let {
|
||||
cc.subscribeToFavorites(it)
|
||||
}
|
||||
}
|
||||
}, "TokenProviderThread").start()
|
||||
}
|
||||
|
||||
override fun onServiceDisconnected(cName: ComponentName) {
|
||||
mTokenProvider = null
|
||||
}
|
||||
|
||||
fun getAuthToken(accountName: String): String? {
|
||||
val am = AccountManager.get(context)
|
||||
val accounts = am.getAccountsByType("com.google")
|
||||
if (accounts == null || accounts.size == 0) {
|
||||
Log.w(ControlsUiController.TAG, "No com.google accounts found")
|
||||
return null
|
||||
}
|
||||
|
||||
var account: Account? = null
|
||||
for (a in accounts) {
|
||||
if (a.name.equals(accountName)) {
|
||||
account = a
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if (account == null) {
|
||||
account = accounts[0]
|
||||
}
|
||||
|
||||
try {
|
||||
return am.blockingGetAuthToken(account!!, SCOPE, true)
|
||||
} catch (e: Throwable) {
|
||||
Log.e(ControlsUiController.TAG, "Error getting auth token", e)
|
||||
return null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private data class ControlKey(val componentName: ComponentName, val controlId: String)
|
||||
|
||||
@Singleton
|
||||
@@ -215,21 +148,10 @@ class ControlsUiControllerImpl @Inject constructor (
|
||||
ControlKey(selectedStructure.componentName, it.ci.controlId)
|
||||
}
|
||||
listingCallback = createCallback(::showControlsView)
|
||||
controlsController.get().subscribeToFavorites(selectedStructure)
|
||||
}
|
||||
|
||||
controlsListingController.get().addCallback(listingCallback)
|
||||
|
||||
// Temp code to pass auth
|
||||
tokenProviderConnection = TokenProviderConnection(controlsController.get(), context,
|
||||
selectedStructure)
|
||||
|
||||
val serviceIntent = Intent()
|
||||
serviceIntent.setComponent(ComponentName("com.android.systemui.home.mock",
|
||||
"com.android.systemui.home.mock.AuthService"))
|
||||
if (!context.bindService(serviceIntent, tokenProviderConnection!!,
|
||||
Context.BIND_AUTO_CREATE)) {
|
||||
controlsController.get().subscribeToFavorites(selectedStructure)
|
||||
}
|
||||
}
|
||||
|
||||
private fun showInitialSetupView(items: List<SelectionItem>) {
|
||||
@@ -393,8 +315,6 @@ class ControlsUiControllerImpl @Inject constructor (
|
||||
activeDialog?.dismiss()
|
||||
|
||||
controlsController.get().unsubscribe()
|
||||
context.unbindService(tokenProviderConnection)
|
||||
tokenProviderConnection = null
|
||||
|
||||
parent.removeAllViews()
|
||||
controlsById.clear()
|
||||
|
||||
Reference in New Issue
Block a user