Example usage for android.os StrictMode setThreadPolicy

List of usage examples for android.os StrictMode setThreadPolicy

Introduction

In this page you can find the example usage for android.os StrictMode setThreadPolicy.

Prototype

public static void setThreadPolicy(final ThreadPolicy policy) 

Source Link

Document

Sets the policy for what actions on the current thread should be detected, as well as the penalty if such actions occur.

Usage

From source file:org.mozilla.gecko.BrowserApp.java

@Override
protected void onNewIntent(Intent intent) {
    String action = intent.getAction();

    final boolean isViewAction = Intent.ACTION_VIEW.equals(action);
    final boolean isBookmarkAction = GeckoApp.ACTION_HOMESCREEN_SHORTCUT.equals(action);
    final boolean isTabQueueAction = TabQueueHelper.LOAD_URLS_ACTION.equals(action);

    if (mInitialized && (isViewAction || isBookmarkAction)) {
        // Dismiss editing mode if the user is loading a URL from an external app.
        mBrowserToolbar.cancelEdit();/* w  w w  .java 2 s. com*/

        // Hide firstrun-pane if the user is loading a URL from an external app.
        hideFirstrunPager();

        if (isBookmarkAction) {
            // GeckoApp.ACTION_HOMESCREEN_SHORTCUT means we're opening a bookmark that
            // was added to Android's homescreen.
            Telemetry.sendUIEvent(TelemetryContract.Event.LOAD_URL, TelemetryContract.Method.HOMESCREEN);
        }
    }

    showTabQueuePromptIfApplicable(intent);

    super.onNewIntent(intent);

    if (AppConstants.MOZ_ANDROID_BEAM && NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action)) {
        String uri = intent.getDataString();
        GeckoAppShell.sendEventToGecko(GeckoEvent.createURILoadEvent(uri));
    }

    // Only solicit feedback when the app has been launched from the icon shortcut.
    if (GuestSession.NOTIFICATION_INTENT.equals(action)) {
        GuestSession.handleIntent(this, intent);
    }

    // If the user has clicked the tab queue notification then load the tabs.
    if (AppConstants.NIGHTLY_BUILD && AppConstants.MOZ_ANDROID_TAB_QUEUE && mInitialized && isTabQueueAction) {
        Telemetry.sendUIEvent(TelemetryContract.Event.ACTION, TelemetryContract.Method.NOTIFICATION,
                "tabqueue");
        ThreadUtils.postToBackgroundThread(new Runnable() {
            @Override
            public void run() {
                openQueuedTabs();
            }
        });
    }

    if (!mInitialized || !Intent.ACTION_MAIN.equals(action)) {
        return;
    }

    // Check to see how many times the app has been launched.
    final String keyName = getPackageName() + ".feedback_launch_count";
    final StrictMode.ThreadPolicy savedPolicy = StrictMode.allowThreadDiskReads();

    // Faster on main thread with an async apply().
    try {
        SharedPreferences settings = getPreferences(Activity.MODE_PRIVATE);
        int launchCount = settings.getInt(keyName, 0);
        if (launchCount < FEEDBACK_LAUNCH_COUNT) {
            // Increment the launch count and store the new value.
            launchCount++;
            settings.edit().putInt(keyName, launchCount).apply();

            // If we've reached our magic number, show the feedback page.
            if (launchCount == FEEDBACK_LAUNCH_COUNT) {
                GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Feedback:Show", null));
            }
        }
    } finally {
        StrictMode.setThreadPolicy(savedPolicy);
    }
}