Search in sources :

Example 1 with StrictMode

use of android.os.StrictMode in project qksms by moezbhatti.

the class QKSMSAppBase method onCreate.

@Override
public void onCreate() {
    super.onCreate();
    if (Log.isLoggable(LogTag.STRICT_MODE_TAG, Log.DEBUG)) {
        // Log tag for enabling/disabling StrictMode violation log. This will dump a stack
        // in the log that shows the StrictMode violator.
        // To enable: adb shell setprop log.tag.Mms:strictmode DEBUG
        StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectAll().penaltyLog().build());
    }
    sQKSMSApp = this;
    loadDefaultPreferenceValues();
    // Initialize analytics, leakcanary, and crittercism
    AnalyticsManager.getInstance().init(this);
    refWatcher = LeakCanary.install(this);
    // Figure out the country *before* loading contacts and formatting numbers
    Country country = new Country(Locale.getDefault().getCountry(), Country.COUNTRY_SOURCE_LOCALE);
    mCountryIso = country.getCountryIso();
    Context context = getApplicationContext();
    mPduLoaderManager = new PduLoaderManager(context);
    mThumbnailManager = new ThumbnailManager(context);
    registerActivityLifecycleCallbacks(new LifecycleHandler());
    ThemeManager.init(this);
    MmsConfig.init(this);
    Contact.init(this);
    DraftCache.init(this);
    Conversation.init(this);
    DownloadManager.init(this);
    RateController.init(this);
    LayoutManager.init(this);
    NotificationManager.init(this);
    LiveViewManager.init(this);
    QKPreferences.init(this);
    activePendingMessages();
}
Also used : Context(android.content.Context) StrictMode(android.os.StrictMode) ThumbnailManager(com.moez.QKSMS.common.google.ThumbnailManager) LifecycleHandler(com.moez.QKSMS.common.LifecycleHandler) Country(android.location.Country) PduLoaderManager(com.moez.QKSMS.common.google.PduLoaderManager)

Example 2 with StrictMode

use of android.os.StrictMode in project AndroidChromium by JackyAndroid.

the class ChromeStrictMode method configureStrictMode.

/**
     * Turn on StrictMode detection based on build and command-line switches.
     */
@UiThread
// FindBugs doesn't like conditionals with compile time results
@SuppressFBWarnings("UCF_USELESS_CONTROL_FLOW")
public static void configureStrictMode() {
    assert ThreadUtils.runningOnUiThread();
    if (sIsStrictModeAlreadyConfigured) {
        return;
    }
    sIsStrictModeAlreadyConfigured = true;
    StrictMode.ThreadPolicy.Builder threadPolicy = new StrictMode.ThreadPolicy.Builder(StrictMode.getThreadPolicy());
    StrictMode.VmPolicy.Builder vmPolicy = new StrictMode.VmPolicy.Builder(StrictMode.getVmPolicy());
    CommandLine commandLine = CommandLine.getInstance();
    if ("eng".equals(Build.TYPE) || BuildConfig.DCHECK_IS_ON || ChromeVersionInfo.isLocalBuild() || commandLine.hasSwitch(ChromeSwitches.STRICT_MODE)) {
        turnOnDetection(threadPolicy, vmPolicy);
        addDefaultPenalties(threadPolicy, vmPolicy);
        if ("death".equals(commandLine.getSwitchValue(ChromeSwitches.STRICT_MODE))) {
            addThreadDeathPenalty(threadPolicy);
            addVmDeathPenalty(vmPolicy);
        } else if ("testing".equals(commandLine.getSwitchValue(ChromeSwitches.STRICT_MODE))) {
            addThreadDeathPenalty(threadPolicy);
        // Currently VmDeathPolicy kills the process, and is not visible on bot test output.
        }
    }
    // Enroll 1% of dev sessions into StrictMode watch. This is done client-side rather than
    // through finch because this decision is as early as possible in the browser initialization
    // process. We need to detect early start-up StrictMode violations before loading native and
    // before warming the SharedPreferences (that is a violation in an of itself). We will
    // closely monitor this on dev channel.
    boolean enableStrictModeWatch = (ChromeVersionInfo.isDevBuild() && Math.random() < UPLOAD_PROBABILITY);
    if ((ChromeVersionInfo.isLocalBuild() && !BuildConfig.DCHECK_IS_ON) || enableStrictModeWatch) {
        turnOnDetection(threadPolicy, vmPolicy);
        initializeStrictModeWatch();
    }
    StrictMode.setThreadPolicy(threadPolicy.build());
    StrictMode.setVmPolicy(vmPolicy.build());
}
Also used : StrictMode(android.os.StrictMode) CommandLine(org.chromium.base.CommandLine) UiThread(android.support.annotation.UiThread) SuppressFBWarnings(org.chromium.base.annotations.SuppressFBWarnings)

Example 3 with StrictMode

use of android.os.StrictMode in project AndroidChromium by JackyAndroid.

the class ChromeActivity method setContentView.

/**
     * This function builds the {@link CompositorViewHolder}.  Subclasses *must* call
     * super.setContentView() before using {@link #getTabModelSelector()} or
     * {@link #getCompositorViewHolder()}.
     */
@Override
protected final void setContentView() {
    final long begin = SystemClock.elapsedRealtime();
    TraceEvent.begin("onCreate->setContentView()");
    enableHardwareAcceleration();
    setLowEndTheme();
    int controlContainerLayoutId = getControlContainerLayoutId();
    WarmupManager warmupManager = WarmupManager.getInstance();
    if (warmupManager.hasBuiltOrClearViewHierarchyWithToolbar(controlContainerLayoutId)) {
        View placeHolderView = new View(this);
        setContentView(placeHolderView);
        ViewGroup contentParent = (ViewGroup) placeHolderView.getParent();
        WarmupManager.getInstance().transferViewHierarchyTo(contentParent);
        contentParent.removeView(placeHolderView);
    } else {
        // Allow disk access for the content view and toolbar container setup.
        // On certain android devices this setup sequence results in disk writes outside
        // of our control, so we have to disable StrictMode to work. See crbug.com/639352.
        StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites();
        try {
            setContentView(R.layout.main);
            if (controlContainerLayoutId != NO_CONTROL_CONTAINER) {
                ViewStub toolbarContainerStub = ((ViewStub) findViewById(R.id.control_container_stub));
                toolbarContainerStub.setLayoutResource(controlContainerLayoutId);
                toolbarContainerStub.inflate();
            }
        } finally {
            StrictMode.setThreadPolicy(oldPolicy);
        }
    }
    TraceEvent.end("onCreate->setContentView()");
    mInflateInitialLayoutDurationMs = SystemClock.elapsedRealtime() - begin;
    // Set the status bar color to black by default. This is an optimization for
    // Chrome not to draw under status and navigation bars when we use the default
    // black status bar
    ApiCompatibilityUtils.setStatusBarColor(getWindow(), Color.BLACK);
    ViewGroup rootView = (ViewGroup) getWindow().getDecorView().getRootView();
    mCompositorViewHolder = (CompositorViewHolder) findViewById(R.id.compositor_view_holder);
    mCompositorViewHolder.setRootView(rootView);
    // Setting fitsSystemWindows to false ensures that the root view doesn't consume the insets.
    rootView.setFitsSystemWindows(false);
    // Add a custom view right after the root view that stores the insets to access later.
    // ContentViewCore needs the insets to determine the portion of the screen obscured by
    // non-content displaying things such as the OSK.
    mInsetObserverView = InsetObserverView.create(this);
    rootView.addView(mInsetObserverView, 0);
}
Also used : StrictMode(android.os.StrictMode) ViewStub(android.view.ViewStub) ViewGroup(android.view.ViewGroup) DistilledPagePrefsView(org.chromium.chrome.browser.dom_distiller.DistilledPagePrefsView) View(android.view.View) ContentVideoView(org.chromium.content.browser.ContentVideoView) SuppressLint(android.annotation.SuppressLint)

Example 4 with StrictMode

use of android.os.StrictMode in project AndroidChromium by JackyAndroid.

the class WarmupManager method initializeViewHierarchy.

/**
     * Inflates and constructs the view hierarchy that the app will use.
     * @param baseContext The base context to use for creating the ContextWrapper.
     * @param toolbarContainerId Id of the toolbar container.
     */
public void initializeViewHierarchy(Context baseContext, int toolbarContainerId) {
    TraceEvent.begin("WarmupManager.initializeViewHierarchy");
    // Inflating the view hierarchy causes StrictMode violations on some
    // devices. Since layout inflation should happen on the UI thread, allow
    // the disk reads. crbug.com/644243.
    StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
    try {
        ThreadUtils.assertOnUiThread();
        if (mMainView != null && mToolbarContainerId == toolbarContainerId)
            return;
        ContextThemeWrapper context = new ContextThemeWrapper(baseContext, ChromeActivity.getThemeId());
        FrameLayout contentHolder = new FrameLayout(context);
        mMainView = (ViewGroup) LayoutInflater.from(context).inflate(R.layout.main, contentHolder);
        mToolbarContainerId = toolbarContainerId;
        if (toolbarContainerId != ChromeActivity.NO_CONTROL_CONTAINER) {
            ViewStub stub = (ViewStub) mMainView.findViewById(R.id.control_container_stub);
            stub.setLayoutResource(toolbarContainerId);
            stub.inflate();
        }
    } catch (InflateException e) {
        // See crbug.com/606715.
        Log.e(TAG, "Inflation exception.", e);
        mMainView = null;
    } finally {
        StrictMode.setThreadPolicy(oldPolicy);
        TraceEvent.end("WarmupManager.initializeViewHierarchy");
    }
}
Also used : StrictMode(android.os.StrictMode) ViewStub(android.view.ViewStub) ContextThemeWrapper(android.view.ContextThemeWrapper) FrameLayout(android.widget.FrameLayout) InflateException(android.view.InflateException)

Aggregations

StrictMode (android.os.StrictMode)4 ViewStub (android.view.ViewStub)2 SuppressLint (android.annotation.SuppressLint)1 Context (android.content.Context)1 Country (android.location.Country)1 UiThread (android.support.annotation.UiThread)1 ContextThemeWrapper (android.view.ContextThemeWrapper)1 InflateException (android.view.InflateException)1 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 FrameLayout (android.widget.FrameLayout)1 LifecycleHandler (com.moez.QKSMS.common.LifecycleHandler)1 PduLoaderManager (com.moez.QKSMS.common.google.PduLoaderManager)1 ThumbnailManager (com.moez.QKSMS.common.google.ThumbnailManager)1 CommandLine (org.chromium.base.CommandLine)1 SuppressFBWarnings (org.chromium.base.annotations.SuppressFBWarnings)1 DistilledPagePrefsView (org.chromium.chrome.browser.dom_distiller.DistilledPagePrefsView)1 ContentVideoView (org.chromium.content.browser.ContentVideoView)1