@@ -802,6 +802,44 @@ private void onResult(IAccountManagerResponse response, Bundle result) {
802802 }
803803 }
804804
805+ void getAuthTokenLabel (final IAccountManagerResponse response ,
806+ final Account account , final String authTokenType ) {
807+ if (account == null ) throw new IllegalArgumentException ("account is null" );
808+ if (authTokenType == null ) throw new IllegalArgumentException ("authTokenType is null" );
809+
810+ checkBinderPermission (Manifest .permission .USE_CREDENTIALS );
811+
812+ long identityToken = clearCallingIdentity ();
813+ try {
814+ new Session (response , account .type , false ,
815+ false /* stripAuthTokenFromResult */ ) {
816+ protected String toDebugString (long now ) {
817+ return super .toDebugString (now ) + ", getAuthTokenLabel"
818+ + ", " + account
819+ + ", authTokenType " + authTokenType ;
820+ }
821+
822+ public void run () throws RemoteException {
823+ mAuthenticator .getAuthTokenLabel (this , authTokenType );
824+ }
825+
826+ public void onResult (Bundle result ) {
827+ if (result != null ) {
828+ String label = result .getString (AccountManager .KEY_AUTH_TOKEN_LABEL );
829+ Bundle bundle = new Bundle ();
830+ bundle .putString (AccountManager .KEY_AUTH_TOKEN_LABEL , label );
831+ super .onResult (bundle );
832+ return ;
833+ } else {
834+ super .onResult (result );
835+ }
836+ }
837+ }.bind ();
838+ } finally {
839+ restoreCallingIdentity (identityToken );
840+ }
841+ }
842+
805843 public void getAuthToken (IAccountManagerResponse response , final Account account ,
806844 final String authTokenType , final boolean notifyOnAuthFailure ,
807845 final boolean expectActivityLaunch , final Bundle loginOptions ) {
@@ -912,36 +950,36 @@ private void createNoCredentialsPermissionNotification(Account account, Intent i
912950 .notify (getCredentialPermissionNotificationId (account , authTokenType , uid ), n );
913951 }
914952
915- private Intent newGrantCredentialsPermissionIntent (Account account , int uid ,
916- AccountAuthenticatorResponse response , String authTokenType , String authTokenLabel ) {
953+ String getAccountLabel (String accountType ) {
917954 RegisteredServicesCache .ServiceInfo <AuthenticatorDescription > serviceInfo =
918- mAuthenticatorCache .getServiceInfo (
919- AuthenticatorDescription .newKey (account . type ));
955+ mAuthenticatorCache .getServiceInfo (
956+ AuthenticatorDescription .newKey (accountType ));
920957 if (serviceInfo == null ) {
921- throw new IllegalArgumentException ("unknown account type: " + account . type );
958+ throw new IllegalArgumentException ("unknown account type: " + accountType );
922959 }
923960
924961 final Context authContext ;
925962 try {
926963 authContext = mContext .createPackageContext (
927- serviceInfo .type .packageName , 0 );
964+ serviceInfo .type .packageName , 0 );
928965 } catch (PackageManager .NameNotFoundException e ) {
929- throw new IllegalArgumentException ("unknown account type: " + account . type );
966+ throw new IllegalArgumentException ("unknown account type: " + accountType );
930967 }
968+ return authContext .getString (serviceInfo .type .labelId );
969+ }
970+
971+ private Intent newGrantCredentialsPermissionIntent (Account account , int uid ,
972+ AccountAuthenticatorResponse response , String authTokenType , String authTokenLabel ) {
931973
932974 Intent intent = new Intent (mContext , GrantCredentialsPermissionActivity .class );
933- intent .setFlags (Intent .FLAG_ACTIVITY_NEW_TASK );
934975 intent .addCategory (
935976 String .valueOf (getCredentialPermissionNotificationId (account , authTokenType , uid )));
977+
936978 intent .putExtra (GrantCredentialsPermissionActivity .EXTRAS_ACCOUNT , account );
937- intent .putExtra (GrantCredentialsPermissionActivity .EXTRAS_AUTH_TOKEN_LABEL , authTokenLabel );
938979 intent .putExtra (GrantCredentialsPermissionActivity .EXTRAS_AUTH_TOKEN_TYPE , authTokenType );
939980 intent .putExtra (GrantCredentialsPermissionActivity .EXTRAS_RESPONSE , response );
940- intent .putExtra (GrantCredentialsPermissionActivity .EXTRAS_ACCOUNT_TYPE_LABEL ,
941- authContext .getString (serviceInfo .type .labelId ));
942- intent .putExtra (GrantCredentialsPermissionActivity .EXTRAS_PACKAGES ,
943- mContext .getPackageManager ().getPackagesForUid (uid ));
944981 intent .putExtra (GrantCredentialsPermissionActivity .EXTRAS_REQUESTING_UID , uid );
982+
945983 return intent ;
946984 }
947985
0 commit comments