Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a0c10071 authored by Fynn Godau's avatar Fynn Godau
Browse files

Work account POC

parent 529304b8
Loading
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -6,6 +6,9 @@

<manifest xmlns:android="http://schemas.android.com/apk/res/android">

    <uses-permission
        android:name="android.permission.AUTHENTICATE_ACCOUNTS"
        android:maxSdkVersion="22" />
    <uses-permission
        android:name="android.permission.GET_ACCOUNTS"
        android:maxSdkVersion="22" />
@@ -23,7 +26,7 @@
            </intent-filter>
        </service>
        <service
            android:name="org.microg.gms.auth.account.authenticator.WorkAccountAuthenticatorService"
            android:name="com.google.android.gms.auth.account.authenticator.WorkAccountAuthenticatorService"
            android:process=":persistent"
            android:enabled="false"
            android:exported="false">
+84 −0
Original line number Diff line number Diff line
package com.google.android.gms.auth.account.authenticator

import android.accounts.AbstractAccountAuthenticator
import android.accounts.Account
import android.accounts.AccountAuthenticatorResponse
import android.accounts.AccountManager
import android.content.Context
import android.os.Bundle
import android.util.Log

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

    override fun editProperties(
        response: AccountAuthenticatorResponse,
        accountType: String?
    ): Bundle {
        TODO("Not yet implemented: editProperties")
    }

    override fun addAccount(
        response: AccountAuthenticatorResponse,
        accountType: String,
        authTokenType: String?,
        requiredFeatures: Array<out String>?,
        options: Bundle
    ): Bundle {
        val name = "account${options.getInt(AccountManager.KEY_CALLER_UID)}"
        val type = "com.google.work"
        AccountManager.get(context).addAccountExplicitly(
            Account(name, type), "***", Bundle()
        )
        return Bundle().apply {
            putString(AccountManager.KEY_ACCOUNT_NAME, name)
            putString(AccountManager.KEY_ACCOUNT_TYPE, type)
        }
    }

    override fun confirmCredentials(
        response: AccountAuthenticatorResponse?,
        account: Account?,
        options: Bundle?
    ): Bundle {
        return Bundle().apply {
            putBoolean(AccountManager.KEY_BOOLEAN_RESULT, true)
        }
    }

    override fun getAuthToken(
        response: AccountAuthenticatorResponse?,
        account: Account?,
        authTokenType: String?,
        options: Bundle?
    ): Bundle {
        TODO("Not yet implemented: getAuthToken")
    }

    override fun getAuthTokenLabel(authTokenType: String?): String {
        TODO("Not yet implemented: getAuthTokenLabel")
    }

    override fun updateCredentials(
        response: AccountAuthenticatorResponse?,
        account: Account?,
        authTokenType: String?,
        options: Bundle?
    ): Bundle {
        TODO("Not yet implemented: updateCredentials")
    }

    override fun hasFeatures(
        response: AccountAuthenticatorResponse?,
        account: Account?,
        features: Array<out String>
    ): Bundle {
        Log.i(TAG, "Queried features: " + features.joinToString(", "))
        return Bundle().apply {
            putBoolean(AccountManager.KEY_BOOLEAN_RESULT, false)
        }
    }

    companion object {
        const val TAG = "WorkAccAuthenticator"
    }
}
 No newline at end of file
+17 −0
Original line number Diff line number Diff line
package org.microg.gms.auth.account.authenticator
package com.google.android.gms.auth.account.authenticator

import android.accounts.AccountManager
import android.app.Service
import android.content.Intent
import android.os.IBinder

class WorkAccountAuthenticatorService : Service() {
    private val authenticator by lazy { WorkAccountAuthenticator(this) }

    override fun onBind(intent: Intent?): IBinder? {
    override fun onBind(intent: Intent): IBinder? {
        if (intent.action == AccountManager.ACTION_AUTHENTICATOR_INTENT) {
            return authenticator.iBinder
        }
        return null
    }
}
 No newline at end of file
+5 −3
Original line number Diff line number Diff line
@@ -39,11 +39,13 @@ class WorkAccountServiceImpl(val context: Context) : IWorkAccountService.Stub()
        return super.onTransact(code, data, reply, flags)
    }

    override fun addWorkAccount(googleApiClient: IObjectWrapper?, s: String?): IWorkAccountService.AddAccountResult {
    override fun addWorkAccount(googleApiClient: IObjectWrapper?, s: String?): AddAccountResult {
        // TODO: caller expects that an account is actually created
        Log.d(TAG, "addWorkAccount with $googleApiClient, $s")
        Log.d(TAG, "stub implementation, not creating account; please create manually!")
        // TODO: use correct AIDL
        return object : AddAccountResult.Stub() {
            override fun getAccount(): Account? {
                // TODO

                return AccountManager.get(context).accounts.firstOrNull()?.also { Log.d(TAG, "returning account $it") }
            }
@@ -68,7 +70,7 @@ class WorkAccountServiceImpl(val context: Context) : IWorkAccountService.Stub()
         sharedPreferences.edit().putBoolean("enabled_by_admin", true).apply()

         val componentName = ComponentName("com.google.android.gms", "com.google.android.gms.auth.account.authenticator.WorkAccountAuthenticatorService")
         //context.packageManager.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP)
         context.packageManager.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP)
    }

     override fun setWorkAuthenticatorEnabledWithResult(googleApiClient: IObjectWrapper?, b: Boolean): IObjectWrapper {
+5 −0
Original line number Diff line number Diff line
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:tint="#4285F4" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp">
      
    <path android:fillColor="@android:color/white" android:pathData="M20,6h-4L16,4c0,-1.11 -0.89,-2 -2,-2h-4c-1.11,0 -2,0.89 -2,2v2L4,6c-1.11,0 -1.99,0.89 -1.99,2L2,19c0,1.11 0.89,2 2,2h16c1.11,0 2,-0.89 2,-2L22,8c0,-1.11 -0.89,-2 -2,-2zM14,6h-4L10,4h4v2z"/>
    
</vector>
Loading