增加accountmanager相关service
This commit is contained in:
parent
38957d9407
commit
770c98d3cc
@ -188,7 +188,17 @@
|
|||||||
<category android:name="android.intent.category.default" />
|
<category android:name="android.intent.category.default" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</service>
|
</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
|
<supports-screens
|
||||||
android:anyDensity="true"
|
android:anyDensity="true"
|
||||||
android:largeScreens="true"
|
android:largeScreens="true"
|
||||||
@ -240,6 +250,7 @@
|
|||||||
tools:ignore="ScopedStorage" />
|
tools:ignore="ScopedStorage" />
|
||||||
<uses-permission android:name="android.permission.USE_BIOMETRIC" />
|
<uses-permission android:name="android.permission.USE_BIOMETRIC" />
|
||||||
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
|
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
|
||||||
|
<uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS" />
|
||||||
<queries>
|
<queries>
|
||||||
<package android:name="com.zhiliaoapp.musically" />
|
<package android:name="com.zhiliaoapp.musically" />
|
||||||
<package android:name="com.ss.android.ugc.trill" />
|
<package android:name="com.ss.android.ugc.trill" />
|
||||||
|
@ -167,6 +167,8 @@ public class MainActivity extends UnityPlayerActivity
|
|||||||
|
|
||||||
private AccountManager accountManager;
|
private AccountManager accountManager;
|
||||||
|
|
||||||
|
private String accountType = "com.cege.games.auth";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||||
@ -208,7 +210,7 @@ public class MainActivity extends UnityPlayerActivity
|
|||||||
|
|
||||||
PayClient payClient = PayClient.getInstance();
|
PayClient payClient = PayClient.getInstance();
|
||||||
payClient.init(this);
|
payClient.init(this);
|
||||||
accountManager = AccountManager.get(this);
|
accountManager = AccountManager.get(this.getApplicationContext());
|
||||||
String id = Installation.id(this);
|
String id = Installation.id(this);
|
||||||
Log.i(TAG, "custom id:: " + id);
|
Log.i(TAG, "custom id:: " + id);
|
||||||
Log.i(TAG, "build info::" + Installation.getBuildInfo());
|
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) {
|
public void storagePass(String funid, String account, String password) {
|
||||||
Log.i(TAG, "storagePass with: " + account + " | " + password);
|
Log.i(TAG, "storagePass with: " + account + " | " + password);
|
||||||
|
Bundle userData = new Bundle();
|
||||||
|
userData.putString("pass", password);
|
||||||
// save to account manage
|
// save to account manage
|
||||||
final Account act = new Account(account, "main");
|
runOnUiThread(() -> {
|
||||||
accountManager.addAccountExplicitly(act, password, null);
|
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(() -> {
|
// runOnUiThread(() -> {
|
||||||
// Intent intent = new Intent(this, BiometricActivity.class);
|
// Intent intent = new Intent(this, BiometricActivity.class);
|
||||||
// intent.putExtra("action", "encrypt");
|
// intent.putExtra("action", "encrypt");
|
||||||
@ -934,9 +943,9 @@ public class MainActivity extends UnityPlayerActivity
|
|||||||
|
|
||||||
public void authGetStoragePass(String funid, String account) {
|
public void authGetStoragePass(String funid, String account) {
|
||||||
Log.i(TAG, "authGetStoragePass with: " + account);
|
Log.i(TAG, "authGetStoragePass with: " + account);
|
||||||
Account[] accounts = accountManager.getAccounts();
|
Account[] accounts = accountManager.getAccountsByType(accountType);
|
||||||
for (Account act : accounts) {
|
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(() -> {
|
// runOnUiThread(() -> {
|
||||||
// Intent intent = new Intent(this, BiometricActivity.class);
|
// Intent intent = new Intent(this, BiometricActivity.class);
|
||||||
|
56
app/src/com/jc/jcfw/accountmanager/Authenticator.java
Normal file
56
app/src/com/jc/jcfw/accountmanager/Authenticator.java
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
19
app/src/com/jc/jcfw/accountmanager/AuthenticatorService.java
Normal file
19
app/src/com/jc/jcfw/accountmanager/AuthenticatorService.java
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
@ -13,4 +13,6 @@
|
|||||||
<string name="prompt_info_title" translatable="false">Biometric login for Wallet</string>
|
<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_subtitle" translatable="false">Login using your biometric credential</string>
|
||||||
<string name="prompt_info_description" translatable="false">Confirm biometric to continue</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>
|
</resources>
|
5
res/xml/authenticator.xml
Normal file
5
res/xml/authenticator.xml
Normal 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"/>
|
Loading…
x
Reference in New Issue
Block a user