Skip to content

Commit

Permalink
Improve visuals of vending activity
Browse files Browse the repository at this point in the history
  • Loading branch information
fynngodau committed Sep 15, 2024
1 parent 5a39c65 commit 0db6eed
Show file tree
Hide file tree
Showing 11 changed files with 366 additions and 116 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import com.google.android.gms.auth.workaccount.R
import org.microg.gms.auth.workaccount.AuthRequest
import org.microg.gms.auth.workaccount.AuthResponse
import org.microg.gms.common.PackageUtils
import java.io.IOException

class WorkAccountAuthenticator(val context: Context) : AbstractAccountAuthenticator(context) {

Expand Down Expand Up @@ -120,33 +121,42 @@ class WorkAccountAuthenticator(val context: Context) : AbstractAccountAuthentica
authTokenType: String?,
options: Bundle?
): Bundle {
val authResponse: AuthResponse =
AuthRequest().fromContext(context)
.source("android")
.app(context.packageName, PackageUtils.firstSignatureDigest(context, context.packageName))
.email(account.name)
.token(AccountManager.get(context).getPassword(account))
.service(authTokenType)
.delegation(0, null)
try {
val authResponse: AuthResponse =
AuthRequest().fromContext(context)
.source("android")
.app(
context.packageName,
PackageUtils.firstSignatureDigest(context, context.packageName)
)
.email(account.name)
.token(AccountManager.get(context).getPassword(account))
.service(authTokenType)
.delegation(0, null)
// .oauth2Foreground(oauth2Foreground)
// .oauth2Prompt(oauth2Prompt)
// .oauth2IncludeProfile(includeProfile)
// .oauth2IncludeEmail(includeEmail)
// .itCaveatTypes(itCaveatTypes)
// .tokenRequestOptions(tokenRequestOptions)
.systemPartition(true)
.hasPermission(true)
.systemPartition(true)
.hasPermission(true)
// .putDynamicFiledMap(dynamicFields)
.appIsGms()
.callerIsApp()
.response
.appIsGms()
.callerIsApp()
.response

return Bundle().apply {
putString(AccountManager.KEY_ACCOUNT_NAME, account.name)
putString(AccountManager.KEY_ACCOUNT_TYPE, account.type)
putString(AccountManager.KEY_AUTHTOKEN, authResponse.auth)
return Bundle().apply {
putString(AccountManager.KEY_ACCOUNT_NAME, account.name)
putString(AccountManager.KEY_ACCOUNT_TYPE, account.type)
putString(AccountManager.KEY_AUTHTOKEN, authResponse.auth)
}
} catch (e: IOException) {
return Bundle().apply {
putInt(AccountManager.KEY_ERROR_CODE, AccountManager.ERROR_CODE_NETWORK_ERROR)
putString(AccountManager.KEY_ERROR_MESSAGE, e.message)
}
}

}

override fun getAuthTokenLabel(authTokenType: String?): String {
Expand Down
3 changes: 3 additions & 0 deletions vending-app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ dependencies {
implementation "com.google.android.material:material:$materialVersion"
implementation "com.google.accompanist:accompanist-systemuicontroller:0.28.0"

implementation 'androidx.compose.ui:ui-tooling-preview'
debugImplementation 'androidx.compose.ui:ui-tooling'

//droidguard
implementation project(':play-services-droidguard')

Expand Down
5 changes: 3 additions & 2 deletions vending-app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@
androidx.compose.ui.unit,androidx.compose.ui.text,androidx.compose.ui.graphics,androidx.compose.ui.geometry,
androidx.activity.compose,androidx.compose.runtime.saveable,
androidx.compose.material.ripple,androidx.compose.foundation.layout,androidx.compose.animation.core,
coil.singleton, coil.base, androidx.compose.material3, com.google.accompanist.systemuicontroller, androidx.compose.animation.graphics" />
coil.singleton, coil.base, androidx.compose.material3, com.google.accompanist.systemuicontroller, androidx.compose.animation.graphics,
androidx.compose.ui.tooling.data, androidx.compose.ui.tooling.preview" />

<application
android:forceQueryable="true"
Expand Down Expand Up @@ -185,7 +186,7 @@
<receiver
android:name="com.google.android.finsky.splitinstallservice.SplitInstallManager$InstallResultReceiver"
android:exported="true"/>
<activity android:name="org.microg.vending.PlayDebugActivity"
<activity android:name="org.microg.vending.ui.VendingActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
96 changes: 0 additions & 96 deletions vending-app/src/main/java/org/microg/vending/PlayDebugActivity.kt

This file was deleted.

24 changes: 24 additions & 0 deletions vending-app/src/main/java/org/microg/vending/enterprise/App.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.microg.vending.enterprise

open class App(
val packageName: String,
val displayName: String,
val state: State,
val iconUrl: String
) {
enum class State {
/**
* App is available, but not installed on the user's device.
*/
NOT_INSTALLED,
/**
* App is already installed on the device, but an update is available.
*/
UPDATE_AVAILABLE,

/**
* App is installed on device and up to date.
*/
INSTALLED
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.microg.vending.enterprise

import com.google.android.finsky.AppInstallPolicy

class EnterpriseApp(
packageName: String,
displayName: String,
state: State,
iconUrl: String,
val policy: AppInstallPolicy,
) : App(packageName, displayName, state, iconUrl)
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
package org.microg.vending.ui

import androidx.annotation.StringRes
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Warning
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.android.vending.R
import com.google.android.finsky.AppInstallPolicy
import org.microg.vending.enterprise.App
import org.microg.vending.enterprise.EnterpriseApp



@Composable
fun EnterpriseListComponent(apps: List<EnterpriseApp>) {
if (apps.isNotEmpty()) LazyColumn(Modifier.padding(16.dp)) {

val requiredApps = apps.filter { it.policy == AppInstallPolicy.MANDATORY }
if (requiredApps.isNotEmpty()) {
item { InListHeading(R.string.vending_overview_enterprise_row_mandatory) }
item { InListWarning(R.string.vending_overview_enterprise_row_mandatory_hint) }
items(requiredApps) { AppRow(it) }
}

val optionalApps = apps.filter { it.policy == AppInstallPolicy.OPTIONAL }
if (optionalApps.isNotEmpty()) {
item { InListHeading(R.string.vending_overview_enterprise_row_offered) }
items(optionalApps) { AppRow(it) }
}
} else Box(
Modifier
.fillMaxSize()
.padding(24.dp)) {
Column(Modifier.align(Alignment.Center)) {
Text(
stringResource(R.string.vending_overview_enterprise_no_apps_available),
textAlign = TextAlign.Center
)
}
}

}

@Composable
fun InListHeading(@StringRes text: Int) {
Text(
stringResource(text),
modifier = Modifier.padding(vertical = 8.dp),
style = MaterialTheme.typography.headlineSmall
)
}

@Composable
fun InListWarning(@StringRes text: Int) {
Row(
Modifier
.clip(shape = RoundedCornerShape(16.dp))
.background(MaterialTheme.colorScheme.errorContainer)
) {
Icon(
Icons.Default.Warning,
contentDescription = null,
Modifier
.align(Alignment.CenterVertically)
.padding(start = 16.dp, top = 8.dp, bottom = 8.dp, end = 8.dp),
MaterialTheme.colorScheme.onErrorContainer
)
Text(
stringResource(text),
Modifier.align(Alignment.CenterVertically)
.padding(top = 8.dp, bottom = 8.dp, end = 16.dp),
MaterialTheme.colorScheme.onErrorContainer
)
}

}

@Composable
fun AppRow(app: App) {
Row(Modifier.padding(16.dp)) {
Text(app.displayName)
}
}

@Preview
@Composable
fun EnterpriseListComponentPreview() {
EnterpriseListComponent(
listOf(
EnterpriseApp("com.android.vending", "Market", App.State.INSTALLED, "", AppInstallPolicy.MANDATORY),
EnterpriseApp("org.mozilla.firefox", "Firefox", App.State.NOT_INSTALLED, "", AppInstallPolicy.OPTIONAL)
)
)
}

@Preview
@Composable
fun EnterpriseListComponentEmptyPreview() {
EnterpriseListComponent(emptyList())
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.microg.vending.ui

enum class NetworkState {
ACTIVE,
PASSIVE,
ERROR
}
Loading

0 comments on commit 0db6eed

Please sign in to comment.