| 1 | // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | package org.chromium.sync.test.util; |
| 6 | |
| 7 | import android.accounts.Account; |
| 8 | import android.app.Activity; |
| 9 | import android.content.Intent; |
| 10 | import android.os.Bundle; |
| 11 | import android.os.Handler; |
| 12 | import android.os.Looper; |
| 13 | import android.util.Log; |
| 14 | import android.widget.TextView; |
| 15 | |
| 16 | /** |
| 17 | * A dummy implementation of the Android {@link GrantCredentialsPermissionActivity} that is used |
| 18 | * when displaying the Allow/Deny dialog when an application asks for an auth token |
| 19 | * for a given auth token type and that app has never gotten the permission. |
| 20 | * |
| 21 | * Currently this activity just starts up, broadcasts an intent, and finishes. |
| 22 | * |
| 23 | * This class is used by {@link MockAccountManager}. |
| 24 | */ |
| 25 | public class MockGrantCredentialsPermissionActivity extends Activity { |
| 26 | |
| 27 | private static final String TAG = "MockGrantCredentialsPermissionActivity"; |
| 28 | |
| 29 | static final String ACCOUNT = "account"; |
| 30 | |
| 31 | static final String AUTH_TOKEN_TYPE = "authTokenType"; |
| 32 | |
| 33 | @Override |
| 34 | protected void onCreate(Bundle savedInstanceState) { |
| 35 | super.onCreate(savedInstanceState); |
| 36 | TextView textView = new TextView(this); |
| 37 | Account account = (Account) getIntent().getParcelableExtra(ACCOUNT); |
| 38 | String authTokenType = getIntent().getStringExtra(AUTH_TOKEN_TYPE); |
| 39 | String accountName = account == null ? null : account.name; |
| 40 | String message = "account = " + accountName + ", authTokenType = " + authTokenType; |
| 41 | textView.setText(message); |
| 42 | setContentView(textView); |
| 43 | } |
| 44 | |
| 45 | @Override |
| 46 | protected void onResume() { |
| 47 | super.onResume(); |
| 48 | // Send out the broadcast after the Activity has completely started up. |
| 49 | Handler handler = new Handler(Looper.getMainLooper()); |
| 50 | handler.post(new Runnable() { |
| 51 | @Override |
| 52 | public void run() { |
| 53 | Log.d(TAG, "Broadcasting " + MockAccountManager.MUTEX_WAIT_ACTION); |
| 54 | sendBroadcast(new Intent(MockAccountManager.MUTEX_WAIT_ACTION)); |
| 55 | finish(); |
| 56 | } |
| 57 | }); |
| 58 | } |
| 59 | } |