1616package android .accounts ;
1717
1818import android .app .Activity ;
19+ import android .content .pm .RegisteredServicesCache ;
20+ import android .content .res .Resources ;
1921import android .os .Bundle ;
20- import android .os .RemoteException ;
2122import android .widget .TextView ;
2223import android .widget .LinearLayout ;
23- import android .widget .ImageView ;
2424import android .view .View ;
2525import android .view .LayoutInflater ;
26- import android .view .Window ;
2726import android .content .Context ;
2827import android .content .Intent ;
2928import android .content .pm .PackageManager ;
30- import android .content .pm .RegisteredServicesCache ;
3129import android .text .TextUtils ;
32- import android .graphics .drawable .Drawable ;
3330import com .android .internal .R ;
3431
32+ import java .io .IOException ;
33+ import java .net .Authenticator ;
34+
3535/**
3636 * @hide
3737 */
@@ -48,7 +48,6 @@ public class GrantCredentialsPermissionActivity extends Activity implements View
4848 private int mUid ;
4949 private Bundle mResultBundle = null ;
5050 protected LayoutInflater mInflater ;
51- private final AccountManagerService accountManagerService = AccountManagerService .getSingleton ();
5251
5352 protected void onCreate (Bundle savedInstanceState ) {
5453 super .onCreate (savedInstanceState );
@@ -81,7 +80,7 @@ protected void onCreate(Bundle savedInstanceState) {
8180
8281 String accountTypeLabel ;
8382 try {
84- accountTypeLabel = accountManagerService . getAccountLabel (mAccount . type );
83+ accountTypeLabel = getAccountLabel (mAccount );
8584 } catch (IllegalArgumentException e ) {
8685 // label or resource was missing. abort the activity.
8786 setResult (Activity .RESULT_CANCELED );
@@ -92,28 +91,27 @@ protected void onCreate(Bundle savedInstanceState) {
9291 final TextView authTokenTypeView = (TextView ) findViewById (R .id .authtoken_type );
9392 authTokenTypeView .setVisibility (View .GONE );
9493
95- /** Handles the responses from the AccountManager */
96- IAccountManagerResponse response = new IAccountManagerResponse . Stub ( ) {
97- public void onResult ( Bundle bundle ) {
98- final String authTokenLabel =
99- bundle . getString ( AccountManager . KEY_AUTH_TOKEN_LABEL );
100- if (! TextUtils . isEmpty ( authTokenLabel ) ) {
101- runOnUiThread ( new Runnable () {
102- public void run ( ) {
103- if (! isFinishing ()) {
104- authTokenTypeView .setText ( authTokenLabel );
105- authTokenTypeView . setVisibility ( View . VISIBLE );
94+ final AccountManagerCallback < String > callback = new AccountManagerCallback < String >() {
95+ public void run ( AccountManagerFuture < String > future ) {
96+ try {
97+ final String authTokenLabel = future . getResult ();
98+ if (! TextUtils . isEmpty ( authTokenLabel )) {
99+ runOnUiThread ( new Runnable ( ) {
100+ public void run () {
101+ if (! isFinishing () ) {
102+ authTokenTypeView . setText ( authTokenLabel );
103+ authTokenTypeView .setVisibility ( View . VISIBLE );
104+ }
106105 }
107- }
108- });
106+ });
107+ }
108+ } catch (OperationCanceledException e ) {
109+ } catch (IOException e ) {
110+ } catch (AuthenticatorException e ) {
109111 }
110112 }
111-
112- public void onError (int code , String message ) {
113- }
114113 };
115-
116- accountManagerService .getAuthTokenLabel (response , mAccount , mAuthTokenType , mUid );
114+ AccountManager .get (this ).getAuthTokenLabel (mAccount .type , mAuthTokenType , callback , null );
117115
118116 findViewById (R .id .allow_button ).setOnClickListener (this );
119117 findViewById (R .id .deny_button ).setOnClickListener (this );
@@ -134,6 +132,24 @@ public void onError(int code, String message) {
134132 ((TextView ) findViewById (R .id .account_type )).setText (accountTypeLabel );
135133 }
136134
135+ private String getAccountLabel (Account account ) {
136+ final AuthenticatorDescription [] authenticatorTypes =
137+ AccountManager .get (this ).getAuthenticatorTypes ();
138+ for (int i = 0 , N = authenticatorTypes .length ; i < N ; i ++) {
139+ final AuthenticatorDescription desc = authenticatorTypes [i ];
140+ if (desc .type .equals (account .type )) {
141+ try {
142+ return createPackageContext (desc .packageName , 0 ).getString (desc .labelId );
143+ } catch (PackageManager .NameNotFoundException e ) {
144+ return account .type ;
145+ } catch (Resources .NotFoundException e ) {
146+ return account .type ;
147+ }
148+ }
149+ }
150+ return account .type ;
151+ }
152+
137153 private View newPackageView (String packageLabel ) {
138154 View view = mInflater .inflate (R .layout .permissions_package_list_item , null );
139155 ((TextView ) view .findViewById (R .id .package_label )).setText (packageLabel );
@@ -143,15 +159,15 @@ private View newPackageView(String packageLabel) {
143159 public void onClick (View v ) {
144160 switch (v .getId ()) {
145161 case R .id .allow_button :
146- accountManagerService . grantAppPermission ( mAccount , mAuthTokenType , mUid );
162+ AccountManager . get ( this ). updateAppPermission ( mAccount , mAuthTokenType , mUid , true );
147163 Intent result = new Intent ();
148164 result .putExtra ("retry" , true );
149165 setResult (RESULT_OK , result );
150166 setAccountAuthenticatorResult (result .getExtras ());
151167 break ;
152168
153169 case R .id .deny_button :
154- accountManagerService . revokeAppPermission ( mAccount , mAuthTokenType , mUid );
170+ AccountManager . get ( this ). updateAppPermission ( mAccount , mAuthTokenType , mUid , false );
155171 setResult (RESULT_CANCELED );
156172 break ;
157173 }
0 commit comments