<commit_before>package org.wikipedia.activity;

import android.Manifest;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.ShortcutManager;
import android.content.res.Configuration;
import android.net.ConnectivityManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.provider.Settings;
import android.text.TextUtils;
import android.view.MenuItem;
import android.view.View;

import androidx.annotation.ColorInt;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.ContextCompat;

import com.google.android.material.snackbar.Snackbar;

import org.wikipedia.Constants;
import org.wikipedia.R;
import org.wikipedia.WikipediaApp;
import org.wikipedia.analytics.LoginFunnel;
import org.wikipedia.appshortcuts.AppShortcuts;
import org.wikipedia.auth.AccountUtil;
import org.wikipedia.crash.CrashReportActivity;
import org.wikipedia.events.LoggedOutInBackgroundEvent;
import org.wikipedia.events.NetworkConnectEvent;
import org.wikipedia.events.ReadingListsEnableDialogEvent;
import org.wikipedia.events.ReadingListsNoLongerSyncedEvent;
import org.wikipedia.events.SplitLargeListsEvent;
import org.wikipedia.events.ThemeChangeEvent;
import org.wikipedia.login.LoginActivity;
import org.wikipedia.readinglist.ReadingListSyncBehaviorDialogs;
import org.wikipedia.readinglist.sync.ReadingListSyncAdapter;
import org.wikipedia.recurring.RecurringTasksExecutor;
import org.wikipedia.savedpages.SavedPageSyncService;
import org.wikipedia.settings.Prefs;
import org.wikipedia.settings.SiteInfoClient;
import org.wikipedia.util.DeviceUtil;
import org.wikipedia.util.FeedbackUtil;
import org.wikipedia.util.PermissionUtil;
import org.wikipedia.util.ResourceUtil;
import org.wikipedia.util.log.L;

import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;

import static org.wikipedia.Constants.INTENT_EXTRA_INVOKE_SOURCE;
import static org.wikipedia.appshortcuts.AppShortcuts.APP_SHORTCUT_ID;

public abstract class BaseActivity extends AppCompatActivity {
    private static ExclusiveBusConsumer EXCLUSIVE_BUS_METHODS;
    private static Disposable EXCLUSIVE_DISPOSABLE;

    private ExclusiveBusConsumer exclusiveBusMethods;
    private NetworkStateReceiver networkStateReceiver = new NetworkStateReceiver();
    private boolean previousNetworkState = WikipediaApp.getInstance().isOnline();
    private CompositeDisposable disposables = new CompositeDisposable();

    @Override protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        exclusiveBusMethods = new ExclusiveBusConsumer();
        disposables.add(WikipediaApp.getInstance().getBus().subscribe(new NonExclusiveBusConsumer()));
        setTheme();
        removeSplashBackground();

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1
                && AppShortcuts.ACTION_APP_SHORTCUT.equals(getIntent().getAction())) {
            getIntent().putExtra(INTENT_EXTRA_INVOKE_SOURCE, Constants.InvokeSource.APP_SHORTCUTS);
            String shortcutId = getIntent().getStringExtra(APP_SHORTCUT_ID);
            if (!TextUtils.isEmpty(shortcutId)) {
                getApplicationContext().getSystemService(ShortcutManager.class)
                        .reportShortcutUsed(shortcutId);
            }
        }

        if (getSupportActionBar() != null) {
            getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        }

        // Conditionally execute all recurring tasks
        new RecurringTasksExecutor(WikipediaApp.getInstance()).run();

        if (Prefs.isReadingListsFirstTimeSync() && AccountUtil.isLoggedIn()) {
            Prefs.setReadingListsFirstTimeSync(false);
            Prefs.setReadingListSyncEnabled(true);
            ReadingListSyncAdapter.manualSyncWithForce();
        }

        IntentFilter filter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);
        registerReceiver(networkStateReceiver, filter);

        DeviceUtil.setLightSystemUiVisibility(this);
        setNavigationBarColor(ResourceUtil.getThemedColor(this, R.attr.paper_color));

        maybeShowLoggedOutInBackgroundDialog();
    }

    @Override protected void onDestroy() {
        unregisterReceiver(networkStateReceiver);
        disposables.dispose();
        if (EXCLUSIVE_BUS_METHODS == exclusiveBusMethods) {
            unregisterExclusiveBusMethods();
        }
        super.onDestroy();
    }

    @Override
    protected void onStop() {
        WikipediaApp.getInstance().getSessionFunnel().persistSession();
        super.onStop();
    }

    @Override protected void onResume() {
        super.onResume();
        WikipediaApp.getInstance().getSessionFunnel().touchSession();<commit_msg>Add probe to research mysterious crash.<commit_after>package org.wikipedia.activity;

import android.Manifest;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.ShortcutManager;
import android.content.res.Configuration;
import android.net.ConnectivityManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.provider.Settings;
import android.text.TextUtils;
import android.view.MenuItem;
import android.view.View;

import androidx.annotation.ColorInt;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.ContextCompat;

import com.google.android.material.snackbar.Snackbar;

import org.wikipedia.Constants;
import org.wikipedia.R;
import org.wikipedia.WikipediaApp;
import org.wikipedia.analytics.LoginFunnel;
import org.wikipedia.appshortcuts.AppShortcuts;
import org.wikipedia.auth.AccountUtil;
import org.wikipedia.crash.CrashReportActivity;
import org.wikipedia.events.LoggedOutInBackgroundEvent;
import org.wikipedia.events.NetworkConnectEvent;
import org.wikipedia.events.ReadingListsEnableDialogEvent;
import org.wikipedia.events.ReadingListsNoLongerSyncedEvent;
import org.wikipedia.events.SplitLargeListsEvent;
import org.wikipedia.events.ThemeChangeEvent;
import org.wikipedia.login.LoginActivity;
import org.wikipedia.readinglist.ReadingListSyncBehaviorDialogs;
import org.wikipedia.readinglist.sync.ReadingListSyncAdapter;
import org.wikipedia.recurring.RecurringTasksExecutor;
import org.wikipedia.savedpages.SavedPageSyncService;
import org.wikipedia.settings.Prefs;
import org.wikipedia.settings.SiteInfoClient;
import org.wikipedia.util.DeviceUtil;
import org.wikipedia.util.FeedbackUtil;
import org.wikipedia.util.PermissionUtil;
import org.wikipedia.util.ResourceUtil;
import org.wikipedia.util.log.L;

import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;

import static org.wikipedia.Constants.INTENT_EXTRA_INVOKE_SOURCE;
import static org.wikipedia.appshortcuts.AppShortcuts.APP_SHORTCUT_ID;

public abstract class BaseActivity extends AppCompatActivity {
    private static ExclusiveBusConsumer EXCLUSIVE_BUS_METHODS;
    private static Disposable EXCLUSIVE_DISPOSABLE;

    private ExclusiveBusConsumer exclusiveBusMethods;
    private NetworkStateReceiver networkStateReceiver = new NetworkStateReceiver();
    private boolean previousNetworkState = WikipediaApp.getInstance().isOnline();
    private CompositeDisposable disposables = new CompositeDisposable();

    @Override protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        exclusiveBusMethods = new ExclusiveBusConsumer();
        disposables.add(WikipediaApp.getInstance().getBus().subscribe(new NonExclusiveBusConsumer()));
        setTheme();
        removeSplashBackground();

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1
                && AppShortcuts.ACTION_APP_SHORTCUT.equals(getIntent().getAction())) {
            getIntent().putExtra(INTENT_EXTRA_INVOKE_SOURCE, Constants.InvokeSource.APP_SHORTCUTS);
            String shortcutId = getIntent().getStringExtra(APP_SHORTCUT_ID);
            if (!TextUtils.isEmpty(shortcutId)) {
                getApplicationContext().getSystemService(ShortcutManager.class)
                        .reportShortcutUsed(shortcutId);
            }
        }

        if (getSupportActionBar() != null) {
            getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        }

        // Conditionally execute all recurring tasks
        new RecurringTasksExecutor(WikipediaApp.getInstance()).run();

        if (Prefs.isReadingListsFirstTimeSync() && AccountUtil.isLoggedIn()) {
            Prefs.setReadingListsFirstTimeSync(false);
            Prefs.setReadingListSyncEnabled(true);
            ReadingListSyncAdapter.manualSyncWithForce();
        }

        IntentFilter filter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);
        registerReceiver(networkStateReceiver, filter);

        DeviceUtil.setLightSystemUiVisibility(this);
        setNavigationBarColor(ResourceUtil.getThemedColor(this, R.attr.paper_color));

        maybeShowLoggedOutInBackgroundDialog();
    }

    @Override protected void onDestroy() {
        unregisterReceiver(networkStateReceiver);
        disposables.dispose();
        if (EXCLUSIVE_BUS_METHODS == exclusiveBusMethods) {
            unregisterExclusiveBusMethods();
        }
        super.onDestroy();
    }

    @Override
    protected void onStart() {
        try {
            // TODO: remove when bug is fixed.
            // https://appcenter.ms/orgs/ci-apps-hockeyapp-f5mf/apps/Wikipedia-Beta/crashes/errors/2836099990u/overview
            super.onStart();
        } catch (Exception e) {
            String className = this.getLocalClassName();
            RuntimeException ex = new RuntimeException("Exception in " + className + ": " + e.getMessage());
            ex.setStackTrace(e.getStackTrace());
            throw ex;
        }
    }

    @Override
    protected void onStop() {
        WikipediaApp.getInstance().getSessionFunnel().persistSession();
        super.onStop();
    }

    @Override protected void onResume() {
        super.onResume();
        WikipediaApp.getInstance().getSessionFunnel().touchSession();
{'fraction_non_alphanumeric': 0.09011216891318692, 'fraction_numerical': 0.0012253746818738807, 'mean_word_length': 4.364004044489383, 'pattern_counts': {'":': 1, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4552606', 'n_tokens_mistral': 2898, 'n_tokens_neox': 2788, 'n_words': 465}