AccountSwitcher
可設(shè)置多個(gè)測(cè)試賬號(hào)并且能快速切換的工具。無(wú)需自行構(gòu)建界面,輕松配置測(cè)試賬號(hào),同時(shí)避免測(cè)試賬號(hào)的泄漏。
項(xiàng)目地址:https://github.com/KKaKa/AccountSwitcher
:smile: 如果這對(duì)你有幫助,隨手給個(gè)star,這將是我前進(jìn)的動(dòng)力。
由來(lái)
由于在項(xiàng)目中,經(jīng)常需要切換測(cè)試賬號(hào)來(lái)測(cè)試不同的場(chǎng)景,每次都要手動(dòng)輸入那些爛熟如心的賬號(hào)和密碼,就想著有個(gè)一鍵切換賬號(hào)來(lái)避免手輸,而且如果能連界面都不寫的話就更好了,并且能在以后的任何項(xiàng)目中直接配置使用,不用每次都去重新寫界面,于是乎就產(chǎn)生了AccountSwitcher。
效果展示

接入
implementation 'com.sdj.kkaka:account-switcher:1.0.3'
debugAnnotationProcessor 'com.sdj.kkaka:account-switcher-compiler:1.0.3'
releaseAnnotationProcessor 'com.sdj.kkaka:account-switcher-compiler-release:1.0.3'
使用
推薦private修飾且勿引用任何一個(gè)變量。避免后續(xù)混淆無(wú)法正?;煜撐募?。
使用@Account修飾的屬性表示一個(gè)賬號(hào)。accountName,password,alias三個(gè)值必須指定。isDefault默認(rèn)為false,所有賬號(hào)中,需要指定一個(gè)為isDefault,有且只能有一個(gè)賬號(hào)isDefault = true?。?!
/**
* @Description:請(qǐng)勿引用此類中任何變量
*/
public class AccountConfig {
@Account(accountName = "13737373737",password = "12341234",alias = "奧巴馬",isDefault = true)
private String accountAo;
@Account(accountName = "14711111111",password = "45674567",alias = "馬冬梅")
private String accountMei;
@Account(accountName = "15521155958",password = "78907890",alias = "自己的")
private String accountMY;
}
在任何需要監(jiān)聽賬號(hào)變換的地方添加監(jiān)聽,
AccountSwitcher.addAccountChangeListener(new OnAccountChangeListener() {
@Override
public void onAccountChange(AccountBean account) {
//......
}
});
安全
由于賬號(hào)密碼這種極度機(jī)密的信息不能隨意泄漏,AccountSwitcher這在方面做了處理,在debug版本中顯示如下:
public final class AccountSwitcher {
...
public static final AccountBean ACCOUNT_ACCOUNTAO = new AccountBean("13737373737","12341234","奧巴馬");
public static final AccountBean ACCOUNT_ACCOUNTMEI = new AccountBean("14711111111","45674567","馬冬梅");
public static final AccountBean ACCOUNT_ACCOUNTMY = new AccountBean("15521155958","78907890","自己的");
private static final AccountBean DEFAULT_ACCOUNT = ACCOUNT_ACCOUNTAO;
....
}
在release版中,顯示如下:
public final class AccountSwitcher {
...
public static final AccountBean ACCOUNT_ACCOUNTAO = new AccountBean("","","");
public static final AccountBean ACCOUNT_ACCOUNTMEI = new AccountBean("","","");
public static final AccountBean ACCOUNT_ACCOUNTMY = new AccountBean("","","");
private static final AccountBean DEFAULT_ACCOUNT = ACCOUNT_ACCOUNTAO;
....
}
AccountSwitcher在release中會(huì)自行將敏感信息替換為"",避免泄漏,同時(shí)開啟混淆會(huì)將AccountConfig混淆,同樣不會(huì)造成信息泄漏。這也是為什么AccountConfig的變量要為private且不要引用的原因。
自帶賬號(hào)切換界面
如果需要賬號(hào)切換界面AccountSwitcherBoxActivity,需導(dǎo)入'com.sdj.kkaka:account-switcher:1.0.3',建議添加debug檢查,
if (!BuildConfig.DEBUG) {
//....
AccountSwitcherBoxActivity.toAccountSwitcherBoxActivity(this);
}