String addAccountAuthTokenType,
String[] addAccountRequiredFeatures,
Bundle addAccountOptions)
/**
-
将某个帐号对特定包名可见性(允许/拒绝)
-
只有和account的authenticator app签名一致才能调用此接口
*/
public boolean setAccountVisibility(Account account, String packageName, @AccountVisibility int visibility)
/**
-
此外,android8.0还追加下面接口,与setAccountVisibility接口相同
-
在登录成功,向AccountManager数据库中添加帐号时添加对特定包名的可见性
-
名义上,只有authenticator app才可以调用此接口
*/
public boolean addAccountExplicitly(Account account, String password, Bundle extras, Map<String, Integer> visibility)
上述接口要么是用户来选择授权同意,要么是authenticator app给予授权,具体来说android 8.0更加加强了用户的隐私数据安全性
newChooseAccountIntent显示给用户的弹窗样式如下:
从源码的角度分析这几种解决方案
上面说了几种解决方案,为什么这几种方案会有效果呢?
下面让我们一起从源码的角度来解读。
@NonNull
public Account[] getAccountsByType(String type) {
return getAccountsByTypeAsUser(type, Process.myUserH
《Android学习笔记总结+最新移动架构视频+大厂安卓面试真题+项目实战源码讲义》
【docs.qq.com/doc/DSkNLaERkbnFoS0ZF】 完整内容开源分享
andle());
}
/** @hide Same as {@link #getAccountsByType(String)} but for a specific user. */
@NonNull
public Account[] getAccountsByTypeAsUser(String type, UserHandle userHandle) {
try {
return mService.getAccountsAsUser(type, userHandle.getIdentifier(),
mContext.getOpPackageName());
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
getAccountsByType 方法里面调用 getAccountsByTypeAsUser 方法,而在 getAccountsByTypeAsUser 方法里面,有调用 mService 的 getAccountsAsUser 方法。
那这个 mService 是什么东东呢?
private final IAccountManager mService;
可以看到其实是一个 AIDl,里面有若干方法
interface IAccountManager {
Account[] getAccounts(String accountType,