-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
29ecc00
commit 9902bd7
Showing
15 changed files
with
387 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,6 +48,5 @@ fastlane/readme.md | |
.idea/dictionaries | ||
|
||
build/ | ||
/easyaccount | ||
local.properties | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
apply plugin: 'com.android.library' | ||
apply plugin: 'com.github.dcendents.android-maven' | ||
group='com.github.KouroshMsv' | ||
android { | ||
compileSdkVersion 27 | ||
defaultConfig { | ||
minSdkVersion 19 | ||
targetSdkVersion 27 | ||
versionCode 1 | ||
versionName "1.0" | ||
} | ||
|
||
} | ||
|
||
dependencies { | ||
implementation fileTree(dir: 'libs', include: ['*.jar']) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.mousavi.card.gmail.easyaccount"> | ||
|
||
<uses-permission | ||
android:name="android.permission.AUTHENTICATE_ACCOUNTS" | ||
android:maxSdkVersion="22"/> | ||
|
||
|
||
</manifest> |
52 changes: 52 additions & 0 deletions
52
...nt/src/main/java/com/mousavi/card/gmail/easyaccount/AbstractEasyAccountAuthenticator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.mousavi.card.gmail.easyaccount; | ||
|
||
import android.accounts.AbstractAccountAuthenticator; | ||
import android.accounts.Account; | ||
import android.accounts.AccountAuthenticatorResponse; | ||
import android.accounts.AccountManager; | ||
import android.accounts.NetworkErrorException; | ||
import android.app.Activity; | ||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.os.Bundle; | ||
import android.text.TextUtils; | ||
|
||
abstract class AbstractEasyAccountAuthenticator extends AbstractAccountAuthenticator { | ||
|
||
|
||
|
||
AbstractEasyAccountAuthenticator(Context context) { | ||
super(context); | ||
} | ||
|
||
|
||
@Override | ||
public Bundle editProperties(AccountAuthenticatorResponse response, String accountType) { | ||
return null; | ||
} | ||
|
||
|
||
@Override | ||
public Bundle confirmCredentials(AccountAuthenticatorResponse response, Account account, Bundle options) | ||
throws NetworkErrorException { | ||
return null; | ||
} | ||
|
||
@Override | ||
public String getAuthTokenLabel(String authTokenType) { | ||
return null; | ||
} | ||
|
||
@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; | ||
} | ||
|
||
} |
154 changes: 154 additions & 0 deletions
154
easyaccount/src/main/java/com/mousavi/card/gmail/easyaccount/EasyAccountAuthenticator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
package com.mousavi.card.gmail.easyaccount; | ||
|
||
import android.accounts.Account; | ||
import android.accounts.AccountAuthenticatorResponse; | ||
import android.accounts.AccountManager; | ||
import android.app.Activity; | ||
import android.app.Service; | ||
import android.content.Intent; | ||
import android.os.Bundle; | ||
import android.os.Parcelable; | ||
import android.text.TextUtils; | ||
import java.util.Arrays; | ||
|
||
final class EasyAccountAuthenticator extends AbstractEasyAccountAuthenticator { | ||
|
||
private String authTokenType; | ||
private String accountType; | ||
private Class loginClass; | ||
private L l; | ||
private Intent tokenIntent; | ||
private Service service; | ||
|
||
EasyAccountAuthenticator(Service service, Class loginClass, L l, Intent tokenIntent) { | ||
super(service); | ||
this.loginClass = loginClass; | ||
this.l = l; | ||
this.tokenIntent = tokenIntent; | ||
this.service = service; | ||
} | ||
|
||
@Override | ||
public Bundle addAccount(AccountAuthenticatorResponse response, String accountType, String authTokenType, | ||
String[] requiredFeatures, Bundle options) { | ||
if (loginClass != null) { | ||
final Intent intent = new Intent(service, loginClass); | ||
intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response); | ||
l.d("addAccount", intentToString(intent)); | ||
final Bundle bundle = new Bundle(); | ||
bundle.putParcelable(AccountManager.KEY_INTENT, intent); | ||
return bundle; | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
public Bundle getAuthToken(AccountAuthenticatorResponse response, Account account, String authTokenType, Bundle options) { | ||
Bundle bundle = new Bundle(); | ||
if (this.authTokenType.equals(authTokenType)) { | ||
AccountManager am = AccountManager.get(service); | ||
String authToken = am.peekAuthToken(account, authTokenType); | ||
if (authToken != null) { | ||
l.d("authToken", authToken); | ||
} | ||
if (TextUtils.isEmpty(authToken)) { | ||
l.d("auth token is empty"); | ||
final Intent intent = new Intent(service, loginClass); | ||
am.setAuthToken(account, this.authTokenType, null); | ||
intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response); | ||
intent.putExtra(AccountManager.KEY_ACCOUNT_NAME, account.name); | ||
if (tokenIntent != null) { | ||
intent.putExtras(tokenIntent); | ||
} | ||
l.d("startActivity(" + loginClass.getSimpleName() + ")", "intent : " + intentToString(intent)); | ||
bundle.putParcelable(AccountManager.KEY_INTENT, intent); | ||
return bundle; | ||
} | ||
bundle.putString(AccountManager.KEY_ACCOUNT_NAME, account.name); | ||
bundle.putString(AccountManager.KEY_ACCOUNT_TYPE, account.type); | ||
bundle.putString(AccountManager.KEY_AUTHTOKEN, authToken); | ||
|
||
l.d("sent token", "intent : " + bundleToString(bundle)); | ||
return bundle; | ||
} | ||
l.d("invalid authTokenType\n" | ||
+ "1: " + authTokenType + "\n" | ||
+ "2: " + this.authTokenType); | ||
bundle.putString(AccountManager.KEY_ERROR_MESSAGE, "invalid authTokenType"); | ||
return bundle; | ||
} | ||
|
||
public void setAuthTokenType(String authTokenType) { | ||
this.authTokenType = authTokenType; | ||
} | ||
|
||
public String getAuthTokenType() { | ||
return authTokenType; | ||
} | ||
|
||
public void setAccountType(String accountType) { | ||
this.accountType = accountType; | ||
} | ||
|
||
public String getAccountType() { | ||
return accountType; | ||
} | ||
|
||
private String intentToString(Intent intent) { | ||
if (intent == null) { | ||
return null; | ||
} | ||
|
||
return intent.toString() + " " + bundleToString(intent.getExtras()); | ||
} | ||
|
||
private String bundleToString(Bundle bundle) { | ||
StringBuilder out = new StringBuilder("Bundle["); | ||
|
||
if (bundle == null) { | ||
out.append("null"); | ||
} else { | ||
boolean first = true; | ||
for (String key : bundle.keySet()) { | ||
if (!first) { | ||
out.append(", "); | ||
} | ||
|
||
out.append(key).append('='); | ||
|
||
Object value = bundle.get(key); | ||
|
||
if (value instanceof int[]) { | ||
out.append(Arrays.toString((int[]) value)); | ||
} else if (value instanceof byte[]) { | ||
out.append(Arrays.toString((byte[]) value)); | ||
} else if (value instanceof boolean[]) { | ||
out.append(Arrays.toString((boolean[]) value)); | ||
} else if (value instanceof short[]) { | ||
out.append(Arrays.toString((short[]) value)); | ||
} else if (value instanceof long[]) { | ||
out.append(Arrays.toString((long[]) value)); | ||
} else if (value instanceof float[]) { | ||
out.append(Arrays.toString((float[]) value)); | ||
} else if (value instanceof double[]) { | ||
out.append(Arrays.toString((double[]) value)); | ||
} else if (value instanceof String[]) { | ||
out.append(Arrays.toString((String[]) value)); | ||
} else if (value instanceof CharSequence[]) { | ||
out.append(Arrays.toString((CharSequence[]) value)); | ||
} else if (value instanceof Parcelable[]) { | ||
out.append(Arrays.toString((Parcelable[]) value)); | ||
} else if (value instanceof Bundle) { | ||
out.append(bundleToString((Bundle) value)); | ||
} else { | ||
out.append(value); | ||
} | ||
|
||
first = false; | ||
} | ||
} | ||
|
||
out.append("]"); | ||
return out.toString(); | ||
} | ||
} |
Oops, something went wrong.