Search in sources :

Example 6 with ProcessInitException

use of org.chromium.base.library_loader.ProcessInitException in project AndroidChromium by JackyAndroid.

the class NotificationPlatformBridge method launchNotificationPreferences.

/**
     * Launches the notifications preferences screen. If the received intent indicates it came
     * from the gear button on a flipped notification, this launches the site specific preferences
     * screen.
     *
     * @param context The context that received the intent.
     * @param incomingIntent The received intent.
     */
public static void launchNotificationPreferences(Context context, Intent incomingIntent) {
    // UrlFormatter.formatUrlForSecurityDisplay.
    try {
        ChromeBrowserInitializer.getInstance(context).handleSynchronousStartup();
    } catch (ProcessInitException e) {
        Log.e(TAG, "Failed to start browser process.", e);
        // The library failed to initialize and nothing in the application can work, so kill
        // the whole application.
        System.exit(-1);
        return;
    }
    // Use the application context because it lives longer. When using the given context, it
    // may be stopped before the preferences intent is handled.
    Context applicationContext = context.getApplicationContext();
    // If we can read an origin from the intent, use it to open the settings screen for that
    // origin.
    String origin = getOriginFromTag(incomingIntent.getStringExtra(NotificationConstants.EXTRA_NOTIFICATION_TAG));
    boolean launchSingleWebsitePreferences = origin != null;
    String fragmentName = launchSingleWebsitePreferences ? SingleWebsitePreferences.class.getName() : SingleCategoryPreferences.class.getName();
    Intent preferencesIntent = PreferencesLauncher.createIntentForSettingsPage(applicationContext, fragmentName);
    Bundle fragmentArguments;
    if (launchSingleWebsitePreferences) {
        // Record that the user has clicked on the [Site Settings] button.
        RecordUserAction.record("Notifications.ShowSiteSettings");
        // All preferences for a specific origin.
        fragmentArguments = SingleWebsitePreferences.createFragmentArgsForSite(origin);
    } else {
        // Notification preferences for all origins.
        fragmentArguments = new Bundle();
        fragmentArguments.putString(SingleCategoryPreferences.EXTRA_CATEGORY, SiteSettingsCategory.CATEGORY_NOTIFICATIONS);
        fragmentArguments.putString(SingleCategoryPreferences.EXTRA_TITLE, applicationContext.getResources().getString(R.string.push_notifications_permission_title));
    }
    preferencesIntent.putExtra(Preferences.EXTRA_SHOW_FRAGMENT_ARGUMENTS, fragmentArguments);
    // We need to ensure that no existing preference tasks are being re-used in order for the
    // new activity to appear on top.
    preferencesIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
    applicationContext.startActivity(preferencesIntent);
}
Also used : Context(android.content.Context) Bundle(android.os.Bundle) SingleCategoryPreferences(org.chromium.chrome.browser.preferences.website.SingleCategoryPreferences) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) ProcessInitException(org.chromium.base.library_loader.ProcessInitException) SingleWebsitePreferences(org.chromium.chrome.browser.preferences.website.SingleWebsitePreferences)

Aggregations

ProcessInitException (org.chromium.base.library_loader.ProcessInitException)6 SuppressFBWarnings (org.chromium.base.annotations.SuppressFBWarnings)3 Context (android.content.Context)2 Bundle (android.os.Bundle)2 BrowserParts (org.chromium.chrome.browser.init.BrowserParts)2 EmptyBrowserParts (org.chromium.chrome.browser.init.EmptyBrowserParts)2 SuppressLint (android.annotation.SuppressLint)1 Fragment (android.app.Fragment)1 PendingIntent (android.app.PendingIntent)1 Intent (android.content.Intent)1 Resources (android.content.res.Resources)1 Paint (android.graphics.Paint)1 NfcAdapter (android.nfc.NfcAdapter)1 PreferenceFragment (android.preference.PreferenceFragment)1 ChromeApplication (org.chromium.chrome.browser.ChromeApplication)1 SingleCategoryPreferences (org.chromium.chrome.browser.preferences.website.SingleCategoryPreferences)1 SingleWebsitePreferences (org.chromium.chrome.browser.preferences.website.SingleWebsitePreferences)1