diff options
author | Martijn Coenen <maco@google.com> | 2011-07-04 11:16:08 +0200 |
---|---|---|
committer | Martijn Coenen <maco@google.com> | 2011-07-04 11:16:08 +0200 |
commit | eee2126458da109b65bbed42904c6c407872c3af (patch) | |
tree | 5d3af27fcc654cdb4f206fe6194c1152843dd100 /src | |
parent | b14ff2febe4b6a07a73c875858437c89cf43fc72 (diff) | |
download | packages_apps_Browser-eee2126458da109b65bbed42904c6c407872c3af.zip packages_apps_Browser-eee2126458da109b65bbed42904c6c407872c3af.tar.gz packages_apps_Browser-eee2126458da109b65bbed42904c6c407872c3af.tar.bz2 |
0-click NFC: check for private tab on UI thread.
A recent change to Webview broke our code - we're no longer
allowed to call isPrivateBrowsingEnabled() from a non-UI-thread.
Moved the code in an AsyncTask to address this.
Change-Id: I69a5ea539dc1578bfbacbc67c996e28870743870
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/browser/NfcHandler.java | 48 |
1 files changed, 37 insertions, 11 deletions
diff --git a/src/com/android/browser/NfcHandler.java b/src/com/android/browser/NfcHandler.java index bbac640..bc19950 100644 --- a/src/com/android/browser/NfcHandler.java +++ b/src/com/android/browser/NfcHandler.java @@ -20,6 +20,7 @@ import android.app.Activity; import android.nfc.NdefMessage; import android.nfc.NdefRecord; import android.nfc.NfcAdapter; +import android.os.AsyncTask; /** This class implements sharing the URL of the currently * shown browser page over NFC. Sharing is only active @@ -31,6 +32,37 @@ public class NfcHandler implements NfcAdapter.NdefPushCallback { private Activity mActivity; private Controller mController; + /** We need an async task to check whether the tab is private + * on the UI thread. + */ + private class CreateMessageTask extends AsyncTask<Void, Void, NdefMessage> { + private boolean mIsPrivate = false; + private Tab mCurrentTab; + + @Override + protected void onPreExecute() { + mCurrentTab = mController.getCurrentTab(); + if ((mCurrentTab != null) && (mCurrentTab.getWebView() != null)) { + mIsPrivate = mCurrentTab.getWebView().isPrivateBrowsingEnabled(); + } + } + + @Override + protected NdefMessage doInBackground(Void... params) { + if ((mCurrentTab == null) || mIsPrivate) { + return null; + } + String currentUrl = mCurrentTab.getUrl(); + if (currentUrl != null) { + NdefRecord record = NdefRecord.createUri(currentUrl); + NdefMessage msg = new NdefMessage(new NdefRecord[] { record }); + return msg; + } else { + return null; + } + } + } + public NfcHandler(Activity browser, Controller controller) { mActivity = browser; mController = controller; @@ -51,17 +83,11 @@ public class NfcHandler implements NfcAdapter.NdefPushCallback { @Override public NdefMessage createMessage() { - Tab currentTab = mController.getCurrentTab(); - if (currentTab == null) { - return null; - } - String currentUrl = currentTab.getUrl(); - if (currentUrl != null && currentTab.getWebView() != null && - !currentTab.getWebView().isPrivateBrowsingEnabled()) { - NdefRecord record = NdefRecord.createUri(currentUrl); - NdefMessage msg = new NdefMessage(new NdefRecord[] { record }); - return msg; - } else { + CreateMessageTask task = new CreateMessageTask(); + task.execute(); + try { + return task.get(); + } catch (Exception e) { return null; } } |