Skip to content
Draft
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
2 changes: 1 addition & 1 deletion companion/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ am start-foreground-service \
# 2) first-run consent (VISIBLE Activity, the one unavoidable UI step)
am start \
-n ru.vd171.vdbackup/.ConsentActivity \
-e result /data/adb/vdbackup/drive/consent.json
-e result /data/data/ru.vd171.vdbackup/files/consent.json
# user signs in; result JSON: ok=true code=ERR_NONE, or ok=false code=ERR_CONSENT_DENIED
```

Expand Down
13 changes: 11 additions & 2 deletions companion/app/src/main/kotlin/ru/vd171/vdbackup/ConsentActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import com.google.android.gms.auth.api.signin.GoogleSignInClient
import com.google.android.gms.auth.api.signin.GoogleSignInOptions
import com.google.android.gms.common.api.ApiException
import com.google.android.gms.common.api.Scope
import java.io.File

class ConsentActivity : Activity() {

Expand Down Expand Up @@ -71,13 +72,21 @@ class ConsentActivity : Activity() {
}

private fun finishWith(ok: Boolean, code: String, msg: String? = null) {
intent.getStringExtra(EXTRA_RESULT)?.let { path ->
CommandResult.write(path, ok, "consent", code, null, msg ?: if (ok) "consent granted" else "consent denied")
resultFile()?.let { f ->
CommandResult.write(f.path, ok, "consent", code, null, msg ?: if (ok) "consent granted" else "consent denied")
}
setResult(if (ok) RESULT_OK else RESULT_CANCELED)
finish()
}

// The Activity is exported (root starts it with `am start`), so the result path
// comes from any caller: accept only a consent.* file directly in our files dir.
private fun resultFile(): File? {
val path = intent.getStringExtra(EXTRA_RESULT) ?: return null
val f = runCatching { File(path).canonicalFile }.getOrNull() ?: return null
return f.takeIf { it.parentFile == filesDir.canonicalFile && it.name.startsWith("consent.") }
}

companion object {
private const val RC_SIGN_IN = 0x7D1
const val EXTRA_RESULT = "result"
Expand Down
Loading