一勞永逸快速配置測試賬號切換AccountSwitcher
AccountSwitcher
可設定多個測試賬號並且能快速切換的工具。無需自行構建介面,輕鬆配置測試賬號,同時避免測試賬號的洩漏。
專案地址: https://github.com/KKaKa/AccountSwitcher
:smile: 如果這對你有幫助,隨手給個 star ,這將是我前進的動力。
由來
由於在專案中,經常需要切換測試賬號來測試不同的場景,每次都要手動輸入那些爛熟如心的賬號和密碼,就想著有個一鍵切換賬號來避免手輸,而且如果能連介面都不寫的話就更好了,並且能在以後的任何專案中直接配置使用,不用每次都去重新寫介面,於是乎就產生了AccountSwitcher。
效果展示

效果.gif
接入
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修飾且勿引用任何一個變數。避免後續混淆無法正常混淆該檔案。
使用@Account修飾的屬性表示一個賬號。accountName,password,alias三個值必須指定。isDefault預設為false,所有賬號中,需要指定一個為isDefault, 有且只能有一個賬號isDefault = true!!!
/** * @Description:請勿引用此類中任何變數 */ 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; }
在任何需要監聽賬號變換的地方新增監聽,
AccountSwitcher.addAccountChangeListener(new OnAccountChangeListener() { @Override public void onAccountChange(AccountBean account) { //...... } });
安全
由於賬號密碼這種極度機密的資訊不能隨意洩漏,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中會自行將敏感資訊替換為"",避免洩漏,同時開啟混淆會將AccountConfig混淆,同樣不會造成資訊洩漏。這也是為什麼AccountConfig的變數要為private且不要引用的原因。
自帶賬號切換介面
如果需要賬號切換介面AccountSwitcherBoxActivity,需匯入'com.sdj.kkaka:account-switcher:1.0.3',建議新增debug檢查,
if (!BuildConfig.DEBUG) { //.... AccountSwitcherBoxActivity.toAccountSwitcherBoxActivity(this); }