Skip to content
Merged
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
59 changes: 26 additions & 33 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,16 @@
plugins {
id 'com.android.application'
id 'com.google.android.gms.strict-version-matcher-plugin'
id 'kotlin-android'
id 'org.jetbrains.kotlin.plugin.compose' version "$kotlin_version"
}
apply plugin: 'com.google.android.gms.oss-licenses-plugin'
apply plugin: 'com.google.android.gms.oss-licenses-plugin'

android {
compileSdkVersion 36
namespace 'com.amapi.extensibility.demo'
compileSdkVersion = 36
namespace = 'com.amapi.extensibility.demo'

buildFeatures {
compose true
compose = true
}
composeOptions {
kotlinCompilerExtensionVersion = "1.5.15"
Expand All @@ -36,43 +35,46 @@ android {
}

defaultConfig {
applicationId "com.amapi.extensibility.demo"
minSdkVersion 23
targetSdkVersion 35
versionCode 1
versionName "1.0"
applicationId = "com.amapi.extensibility.demo"
minSdkVersion = 24
targetSdkVersion = 35
versionCode = 1
versionName = "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
minifyEnabled = true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt')
}
debug {
minifyEnabled false
proguardFiles 'proguard-rules.pro'
minifyEnabled = false
}
}

compileOptions {
// Flag to enable support for the new language APIs
coreLibraryDesugaringEnabled true
coreLibraryDesugaringEnabled = true

sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
kotlinOptions {
freeCompilerArgs = ['-Xjvm-default=all-compatibility']
jvmTarget = '17'
}

kotlin {
compilerOptions {
freeCompilerArgs.add('-Xjvm-default=all-compatibility')
jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17
}
}


dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.1.5'
implementation 'com.google.android.libraries.enterprise.amapi:amapi:1.7.0-rc01'
implementation 'com.google.android.libraries.enterprise.amapi:amapi:1.8.4'
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.17.0'
implementation 'androidx.appcompat:appcompat:1.7.1'
Expand All @@ -82,26 +84,17 @@ dependencies {
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
implementation 'com.google.guava:guava:33.5.0-android'
implementation 'com.google.android.gms:play-services-oss-licenses:17.3.0'
implementation 'androidx.test.espresso:espresso-idling-resource:3.7.0'

// Compose dependencies
def composeBom = platform('androidx.compose:compose-bom:2025.09.01')
def composeBom = platform('androidx.compose:compose-bom:2026.01.01')
implementation composeBom
androidTestImplementation composeBom
implementation 'androidx.compose.material3:material3'
implementation 'androidx.compose.foundation:foundation'
implementation 'androidx.compose.runtime:runtime'
implementation 'androidx.compose.ui:ui'
implementation 'androidx.lifecycle:lifecycle-viewmodel-compose:2.9.4'
implementation 'androidx.activity:activity-compose'
implementation 'androidx.navigation:navigation-compose:2.9.7'
implementation 'androidx.compose.ui:ui-tooling-preview'
debugImplementation 'androidx.compose.ui:ui-tooling'

testImplementation 'junit:junit:4.13.2'

androidTestImplementation 'androidx.test:rules:1.7.0'
androidTestImplementation 'androidx.test.ext:junit:1.3.0'
androidTestImplementation 'androidx.test:runner:1.7.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.7.0'
androidTestImplementation 'androidx.compose.ui:ui-test-junit4'
}
43 changes: 40 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
package="com.amapi.extensibility.demo" >

<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-permission android:name="android.permission.INTERNET" />


<queries>
<package android:name="com.google.android.apps.work.clouddpc" />
Expand All @@ -31,29 +33,64 @@
android:taskAffinity=""
android:theme="@style/AppTheme" >
<activity
android:name=".commands.CommandActivity"
android:name=".main.MainActivity"
android:exported="true" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".commands.CommandActivity"
android:exported="true" />


<activity android:name=".customapp.CustomAppActivity"
android:exported="true" />

<activity android:name=".requestdeviceinfo.RequestDeviceInfoActivity"
<activity android:name=".requestdeviceinfo.RequestDeviceInfoActivity"
android:exported="true" />

<activity android:name=".accountsetup.AccountSetupActivity"
android:exported="true" />

<activity android:name=".dpcmigration.DpcMigrationActivity"
android:exported="true" />

<activity android:name=".devicetrust.DeviceTrustSignalsActivity"
android:exported="true" />

<activity
android:name=".environment.EnvironmentActivity"
android:exported="true" />

<activity android:name=".oemsystemupdate.OemSystemUpdateActivity"
android:exported="true" />

<receiver android:name=".receiver.DeviceAdminReceiver"
android:permission="android.permission.BIND_DEVICE_ADMIN"
android:exported="true">
<meta-data android:name="android.app.device_admin"
android:resource="@xml/device_admin_receiver" />
<intent-filter>
<action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
</intent-filter>
</receiver>

<service
android:name=".notification.NotificationReceiverService"
android:exported="true" >
<meta-data android:name="com.google.android.managementapi.notification.NotificationReceiverService.SERVICE_COMMAND_STATUS" android:value="" />
<meta-data android:name="com.google.android.managementapi.notification.NotificationReceiverService.SERVICE_COMMAND_STATUS" android:value="" />
<meta-data android:name="com.google.android.managementapi.notification.NotificationReceiverService.SERVICE_APP_ROLES" android:value="" />
</service>

<activity
android:name="com.google.android.gms.oss.licenses.OssLicensesMenuActivity"
android:exported="false"/>
<activity
android:name=".approles.AppRolesActivity"
android:exported="false"
android:label="@string/app_roles_title"/>

<activity
android:name="com.google.android.gms.oss.licenses.OssLicensesActivity"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
/* Copyright 2022 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.amapi.extensibility.demo.accountsetup

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.Button
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.material3.TextField
import androidx.compose.material3.TopAppBar
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import com.amapi.extensibility.demo.R
import kotlinx.coroutines.launch

/** Activity for Account setup related operations. */
class AccountSetupActivity : ComponentActivity() {

private lateinit var viewModel: AccountSetupViewModel

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

val factory =
AccountSetupViewModel.AccountSetupViewModelFactory(application, activityResultRegistry)
viewModel = ViewModelProvider(this, factory)[AccountSetupViewModel::class.java]
lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.STARTED) {
setContent {
Surface(modifier = Modifier.fillMaxSize(), color = MaterialTheme.colorScheme.background) {
val accountSetupResult by viewModel.accountSetupResult.collectAsState()
AccountSetupScreen(accountSetupResult)
}
}
}
}
}

@Composable
@OptIn(ExperimentalMaterial3Api::class)
private fun AccountSetupScreen(accountSetupResult: String?) {
Scaffold(
topBar = {
TopAppBar(
colors =
TopAppBarDefaults.topAppBarColors(
containerColor = MaterialTheme.colorScheme.primaryContainer,
titleContentColor = MaterialTheme.colorScheme.primary,
),
title = { Text(text = stringResource(R.string.account_setup)) },
)
}
) { innerPadding ->
AccountSetupScreenContent(accountSetupResult, Modifier.padding(innerPadding))
}
}

@Composable
private fun AccountSetupScreenContent(
accountSetupResult: String?,
modifier: Modifier = Modifier,
) {
val scrollState = rememberScrollState()

Column(
modifier = modifier.then(Modifier.fillMaxSize().padding(16.dp).verticalScroll(scrollState)),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.spacedBy(8.dp),
) {
val buttonModifier = Modifier.fillMaxWidth()

Text(
text = accountSetupResult ?: stringResource(R.string.account_setup_result),
modifier = Modifier.padding(bottom = 16.dp),
color = MaterialTheme.colorScheme.onSurface,
)

var enrollmentToken by remember { mutableStateOf("TOKEN") }

TextField(
value = enrollmentToken,
onValueChange = { enrollmentToken = it },
label = { Text("Enrollment Token") },
modifier = Modifier.fillMaxWidth(),
)

Button(
onClick = { viewModel.startAccountSetup(enrollmentToken) },
modifier = buttonModifier,
) {
Text(text = stringResource(R.string.start_account_setup_button))
}

Button(onClick = viewModel::launchAuthenticationActivity, modifier = buttonModifier) {
Text(text = stringResource(R.string.launch_auth_activity_button))
}

Button(onClick = viewModel::listAccountSetupAttempts, modifier = buttonModifier) {
Text(text = stringResource(R.string.list_account_setup_attempts_button))
}

Button(onClick = viewModel::cancelAccountSetupAttempt, modifier = buttonModifier) {
Text(text = stringResource(R.string.cancel_account_setup_attempt_button))
}
}
}
}
Loading
Loading