Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package com.example.appfunctions.agent.data

import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.Preferences
import androidx.datastore.preferences.core.booleanPreferencesKey
import androidx.datastore.preferences.core.edit
import androidx.datastore.preferences.core.stringPreferencesKey
import androidx.datastore.preferences.core.stringSetPreferencesKey
Expand All @@ -39,6 +40,7 @@ class DataStoreSettingsRepository
val SERVICE_TIER = stringPreferencesKey("service_tier")
val PINNED_APPS = stringSetPreferencesKey("pinned_apps")
val DISCONNECTED_APPS = stringSetPreferencesKey("disconnected_apps")
val APP_FUNCTION_DEBUGGING = booleanPreferencesKey("app_function_debugging")
}

override val geminiApiKey: Flow<String?> =
Expand Down Expand Up @@ -73,6 +75,11 @@ class DataStoreSettingsRepository
preferences[PreferencesKeys.DISCONNECTED_APPS] ?: emptySet()
}

override val appFunctionDebuggingEnabled: Flow<Boolean> =
dataStore.data.map { preferences ->
preferences[PreferencesKeys.APP_FUNCTION_DEBUGGING] ?: true
}

override suspend fun setGeminiApiKey(apiKey: String) {
dataStore.edit { preferences -> preferences[PreferencesKeys.GEMINI_API_KEY] = apiKey }
}
Expand Down Expand Up @@ -118,4 +125,10 @@ class DataStoreSettingsRepository
preferences[PreferencesKeys.DISCONNECTED_APPS] = newDisconnected
}
}

override suspend fun setAppFunctionDebuggingEnabled(enabled: Boolean) {
dataStore.edit { preferences ->
preferences[PreferencesKeys.APP_FUNCTION_DEBUGGING] = enabled
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,10 @@ interface SettingsRepository {
packageName: String,
connected: Boolean,
)

/** Flow of AppFunction debugging setting. */
val appFunctionDebuggingEnabled: Flow<Boolean>

/** Sets whether AppFunction debugging is enabled. */
suspend fun setAppFunctionDebuggingEnabled(enabled: Boolean)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright 2026 The Android Open Source Project
*
* 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.example.appfunctions.agent.ui.contracts

import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import com.example.appfunctions.agent.ui.screens.agentdemo.AgentUiEvent
import com.example.appfunctions.agent.ui.screens.agentdemo.AgentUiState

/**
* Mandatory interface contract for Agent Demo screen layouts.
* Both Mobile and TV implementations MUST conform to this contract.
*/
interface AgentDemoScreenLayout {
@Composable
fun Content(
uiState: AgentUiState,
onEvent: (AgentUiEvent) -> Unit,
initialSidePanelVisible: Boolean,
modifier: Modifier,
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright 2026 The Android Open Source Project
*
* 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.example.appfunctions.agent.ui.contracts

import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import com.example.appfunctions.agent.ui.screens.agentdemo.ConnectedAppsUiState

/**
* Mandatory interface contract for Connected Apps screen layouts.
* Both Mobile and TV implementations MUST conform to this contract.
*/
interface ConnectedAppsScreenLayout {
@Composable
fun Content(
uiState: ConnectedAppsUiState,
onBack: () -> Unit,
onToggleApp: (String, Boolean) -> Unit,
modifier: Modifier,
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright 2026 The Android Open Source Project
*
* 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.example.appfunctions.agent.ui.contracts

import android.app.PendingIntent
import androidx.appfunctions.metadata.AppFunctionMetadata
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import com.example.appfunctions.agent.domain.appfunction.AppInfo
import com.example.appfunctions.agent.ui.screens.debugging.DebuggingUiState

/**
* Mandatory interface contract for Debugging screen layouts.
* Both Mobile and TV implementations MUST conform to this contract.
*/
interface DebuggingScreenLayout {
@Composable
fun Content(
uiState: DebuggingUiState,
onSearchQueryChanged: (String) -> Unit,
onAppSelected: (AppInfo) -> Unit,
onClearSelectedApp: () -> Unit,
onFunctionInputsChange: (String, Map<String, Any>) -> Unit,
onInvoke: (AppFunctionMetadata) -> Unit,
onClearResult: () -> Unit,
onFunctionExpandedChange: (String, Boolean) -> Unit,
onLaunchPendingIntent: (PendingIntent) -> Unit,
onTogglePin: (AppInfo) -> Unit,
modifier: Modifier,
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright 2026 The Android Open Source Project
*
* 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.example.appfunctions.agent.ui.contracts

import androidx.compose.foundation.text.input.TextFieldState
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import com.example.appfunctions.agent.data.ServiceTier

/**
* Mandatory interface contract for Settings screen layouts.
* Both Mobile and TV implementations MUST conform to this contract.
*/
interface SettingsScreenLayout {
@Composable
fun Content(
geminiApiKeyState: TextFieldState,
serviceTier: ServiceTier,
onServiceTierSelected: (ServiceTier) -> Unit,
onOpenLicenses: () -> Unit,
onNavigateToConnectedApps: () -> Unit,
modifier: Modifier,
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright 2026 The Android Open Source Project
*
* 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.example.appfunctions.agent.ui.layout

import android.content.pm.PackageManager
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.platform.LocalContext

enum class FormFactor {
MOBILE,
TV,
WEAR,
AUTO,
XR,
}

@Composable
fun rememberFormFactor(): FormFactor {
val context = LocalContext.current
return remember(context) {
val pm = context.packageManager
when {
pm.hasSystemFeature(PackageManager.FEATURE_LEANBACK) -> FormFactor.TV
pm.hasSystemFeature(PackageManager.FEATURE_WATCH) -> FormFactor.WEAR
pm.hasSystemFeature(PackageManager.FEATURE_AUTOMOTIVE) -> FormFactor.AUTO
pm.hasSystemFeature("android.hardware.xr.display") -> FormFactor.XR
else -> FormFactor.MOBILE
}
}
}

@Composable
fun isTvFormFactor(): Boolean = rememberFormFactor() == FormFactor.TV
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright 2026 The Android Open Source Project
*
* 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.example.appfunctions.agent.ui.layout

import com.example.appfunctions.agent.ui.contracts.AgentDemoScreenLayout
import com.example.appfunctions.agent.ui.contracts.ConnectedAppsScreenLayout
import com.example.appfunctions.agent.ui.contracts.DebuggingScreenLayout
import com.example.appfunctions.agent.ui.contracts.SettingsScreenLayout
import com.example.appfunctions.agent.ui.mobile.agentdemo.MobileAgentDemoLayout
import com.example.appfunctions.agent.ui.mobile.agentdemo.MobileConnectedAppsLayout
import com.example.appfunctions.agent.ui.mobile.agentdemo.MobileSettingsLayout
import com.example.appfunctions.agent.ui.mobile.debugging.MobileDebuggingLayout

/**
* Centralized layout factory that resolves screen layout contracts for specific form factors.
* This pattern decouples screen routers from explicit form factor resolution conditionals,
* allowing new device form factors (e.g., Wear OS, Android XR, Auto) to be added cleanly.
*/
fun FormFactor.resolveAgentDemoLayout(): AgentDemoScreenLayout = MobileAgentDemoLayout

fun FormFactor.resolveConnectedAppsLayout(): ConnectedAppsScreenLayout = MobileConnectedAppsLayout

fun FormFactor.resolveSettingsLayout(): SettingsScreenLayout = MobileSettingsLayout

fun FormFactor.resolveDebuggingLayout(): DebuggingScreenLayout = MobileDebuggingLayout
Loading
Loading