增加accountmanager相关service

This commit is contained in:
CounterFire2023 2023-08-21 18:22:33 +08:00
parent 38957d9407
commit 770c98d3cc
6 changed files with 109 additions and 7 deletions

View File

@ -188,7 +188,17 @@
<category android:name="android.intent.category.default" />
</intent-filter>
</service>
</application>
<service
android:name="com.jc.jcfw.accountmanager.AuthenticatorService"
>
<intent-filter>
<action android:name="android.accounts.AccountAuthenticator" />
</intent-filter>
<meta-data android:name="android.accounts.AccountAuthenticator"
android:resource="@xml/authenticator" />
</service>
</application>
<supports-screens
android:anyDensity="true"
android:largeScreens="true"
@ -240,6 +250,7 @@
tools:ignore="ScopedStorage" />
<uses-permission android:name="android.permission.USE_BIOMETRIC" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS" />
<queries>
<package android:name="com.zhiliaoapp.musically" />
<package android:name="com.ss.android.ugc.trill" />

View File

@ -167,6 +167,8 @@ public class MainActivity extends UnityPlayerActivity
private AccountManager accountManager;
private String accountType = "com.cege.games.auth";
@Override
protected void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
@ -208,7 +210,7 @@ public class MainActivity extends UnityPlayerActivity
PayClient payClient = PayClient.getInstance();
payClient.init(this);
accountManager = AccountManager.get(this);
accountManager = AccountManager.get(this.getApplicationContext());
String id = Installation.id(this);
Log.i(TAG, "custom id:: " + id);
Log.i(TAG, "build info::" + Installation.getBuildInfo());
@ -918,10 +920,17 @@ public class MainActivity extends UnityPlayerActivity
public void storagePass(String funid, String account, String password) {
Log.i(TAG, "storagePass with: " + account + " | " + password);
Bundle userData = new Bundle();
userData.putString("pass", password);
// save to account manage
final Account act = new Account(account, "main");
accountManager.addAccountExplicitly(act, password, null);
runOnUiThread(() -> {
final Account act = new Account(account, accountType);
if (accountManager.addAccountExplicitly(act, password, userData)) {
Log.i(TAG, "storage pass success");
} else {
Log.i(TAG, "storage pass error");
}
});
// runOnUiThread(() -> {
// Intent intent = new Intent(this, BiometricActivity.class);
// intent.putExtra("action", "encrypt");
@ -934,9 +943,9 @@ public class MainActivity extends UnityPlayerActivity
public void authGetStoragePass(String funid, String account) {
Log.i(TAG, "authGetStoragePass with: " + account);
Account[] accounts = accountManager.getAccounts();
Account[] accounts = accountManager.getAccountsByType(accountType);
for (Account act : accounts) {
Log.i(TAG, "authGetStoragePass account: " + act.name + " | " + act.type + " | " + accountManager.getPassword(act));
Log.i(TAG, "authGetStoragePass account: " + act.name + " | " + act.type );
}
// runOnUiThread(() -> {
// Intent intent = new Intent(this, BiometricActivity.class);

View File

@ -0,0 +1,56 @@
package com.jc.jcfw.accountmanager;
import android.accounts.AbstractAccountAuthenticator;
import android.accounts.Account;
import android.accounts.AccountAuthenticatorResponse;
import android.accounts.NetworkErrorException;
import android.content.Context;
import android.os.Bundle;
/**
* Created by sebastian on 07-03-16.
*/
public class Authenticator extends AbstractAccountAuthenticator {
private Context context;
public Authenticator(Context context) {
super(context);
this.context = context;
}
@Override
public Bundle editProperties(AccountAuthenticatorResponse response, String accountType) {
return null;
}
@Override
public Bundle addAccount(AccountAuthenticatorResponse response, String accountType, String authTokenType, String[] requiredFeatures, Bundle options) throws NetworkErrorException {
return null;
}
@Override
public Bundle confirmCredentials(AccountAuthenticatorResponse response, Account account, Bundle options) throws NetworkErrorException {
return null;
}
@Override
public Bundle getAuthToken(AccountAuthenticatorResponse response, Account account, String authTokenType, Bundle options) throws NetworkErrorException {
return null;
}
@Override
public String getAuthTokenLabel(String authTokenType) {
return authTokenType;
}
@Override
public Bundle updateCredentials(AccountAuthenticatorResponse response, Account account, String authTokenType, Bundle options) throws NetworkErrorException {
return null;
}
@Override
public Bundle hasFeatures(AccountAuthenticatorResponse response, Account account, String[] features) throws NetworkErrorException {
return null;
}
}

View File

@ -0,0 +1,19 @@
package com.jc.jcfw.accountmanager;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
public class AuthenticatorService extends Service {
private Authenticator authenticator;
@Override
public void onCreate() {
authenticator = new Authenticator(this);
}
@Override
public IBinder onBind(Intent intent) {
return authenticator.getIBinder();
}
}

View File

@ -13,4 +13,6 @@
<string name="prompt_info_title" translatable="false">Biometric login for Wallet</string>
<string name="prompt_info_subtitle" translatable="false">Login using your biometric credential</string>
<string name="prompt_info_description" translatable="false">Confirm biometric to continue</string>
<string name="account_manager_description" translatable="false">store you account</string>
</resources>

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<account-authenticator
xmlns:android="http://schemas.android.com/apk/res/android"
android:accountType="com.cege.games.auth"
android:label="@string/account_manager_description"/>