org.chromium.base.BuildInfo Java Examples

The following examples show how to use org.chromium.base.BuildInfo. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PassphraseTypeDialogFragment.java    From delion with Apache License 2.0 6 votes vote down vote up
private SpannableString getResetText() {
    final Context context = getActivity();
    return SpanApplier.applySpans(
            context.getString(R.string.sync_passphrase_encryption_reset_instructions),
            new SpanInfo("<resetlink>", "</resetlink>", new ClickableSpan() {
                @Override
                public void onClick(View view) {
                    Uri syncDashboardUrl = Uri.parse(
                            context.getText(R.string.sync_dashboard_url).toString());
                    Intent intent = new Intent(Intent.ACTION_VIEW, syncDashboardUrl);
                    intent.setPackage(BuildInfo.getPackageName(context));
                    IntentUtils.safePutBinderExtra(
                            intent, CustomTabsIntent.EXTRA_SESSION, null);
                    context.startActivity(intent);
                }
            }));
}
 
Example #2
Source File: PassphraseDialogFragment.java    From delion with Apache License 2.0 6 votes vote down vote up
private SpannableString getResetText() {
    final Context context = getActivity();
    return SpanApplier.applySpans(
            context.getString(R.string.sync_passphrase_reset_instructions),
            new SpanInfo("<resetlink>", "</resetlink>", new ClickableSpan() {
                @Override
                public void onClick(View view) {
                    recordPassphraseDialogDismissal(PASSPHRASE_DIALOG_RESET_LINK);
                    Uri syncDashboardUrl = Uri.parse(
                            context.getText(R.string.sync_dashboard_url).toString());
                    Intent intent = new Intent(Intent.ACTION_VIEW, syncDashboardUrl);
                    intent.setPackage(BuildInfo.getPackageName(context));
                    IntentUtils.safePutBinderExtra(
                            intent, CustomTabsIntent.EXTRA_SESSION, null);
                    context.startActivity(intent);
                }
            }));
}
 
Example #3
Source File: PassphraseTypeDialogFragment.java    From 365browser with Apache License 2.0 6 votes vote down vote up
private SpannableString getResetText() {
    final Context context = getActivity();
    return SpanApplier.applySpans(
            context.getString(R.string.sync_passphrase_encryption_reset_instructions),
            new SpanInfo("<resetlink>", "</resetlink>", new ClickableSpan() {
                @Override
                public void onClick(View view) {
                    Uri syncDashboardUrl = Uri.parse(
                            context.getText(R.string.sync_dashboard_url).toString());
                    Intent intent = new Intent(Intent.ACTION_VIEW, syncDashboardUrl);
                    intent.setPackage(BuildInfo.getPackageName());
                    IntentUtils.safePutBinderExtra(
                            intent, CustomTabsIntent.EXTRA_SESSION, null);
                    context.startActivity(intent);
                }
            }));
}
 
Example #4
Source File: SyncCustomizationFragment.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Gets hint message to resolve sync error.
 * @param error The sync error.
 */
private String getSyncErrorHint(@SyncError int error) {
    Resources res = getActivity().getResources();
    switch (error) {
        case SYNC_ANDROID_SYNC_DISABLED:
            return res.getString(R.string.hint_android_sync_disabled);
        case SYNC_AUTH_ERROR:
            return res.getString(R.string.hint_sync_auth_error);
        case SYNC_CLIENT_OUT_OF_DATE:
            return res.getString(R.string.hint_client_out_of_date, BuildInfo.getPackageLabel());
        case SYNC_OTHER_ERRORS:
            return res.getString(R.string.hint_other_sync_errors);
        case SYNC_PASSPHRASE_REQUIRED:
            return res.getString(R.string.hint_passphrase_required);
        case SYNC_NO_ERROR:
        default:
            return null;
    }
}
 
Example #5
Source File: SelectionPopupController.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@VisibleForTesting
public boolean canPasteAsPlainText() {
    // String resource "paste_as_plain_text" only exist in O.
    // Also this is an O feature, we need to make it consistant with TextView.
    if (!BuildInfo.isAtLeastO()) return false;
    if (!mCanEditRichlyForPastePopup) return false;
    ClipboardManager clipMgr =
            (ClipboardManager) mContext.getSystemService(Context.CLIPBOARD_SERVICE);
    if (!clipMgr.hasPrimaryClip()) return false;

    ClipData clipData = clipMgr.getPrimaryClip();
    ClipDescription description = clipData.getDescription();
    CharSequence text = clipData.getItemAt(0).getText();
    boolean isPlainType = description.hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN);
    // On Android, Spanned could be copied to Clipboard as plain_text MIME type, but in some
    // cases, Spanned could have text format, we need to show "paste as plain text" when
    // that happens.
    if (isPlainType && (text instanceof Spanned)) {
        Spanned spanned = (Spanned) text;
        if (hasStyleSpan(spanned)) return true;
    }
    return description.hasMimeType(ClipDescription.MIMETYPE_TEXT_HTML);
}
 
Example #6
Source File: PassphraseDialogFragment.java    From 365browser with Apache License 2.0 6 votes vote down vote up
private SpannableString getResetText() {
    final Context context = getActivity();
    return SpanApplier.applySpans(
            context.getString(R.string.sync_passphrase_reset_instructions),
            new SpanInfo("<resetlink>", "</resetlink>", new ClickableSpan() {
                @Override
                public void onClick(View view) {
                    recordPassphraseDialogDismissal(PASSPHRASE_DIALOG_RESET_LINK);
                    Uri syncDashboardUrl = Uri.parse(
                            context.getText(R.string.sync_dashboard_url).toString());
                    Intent intent = new Intent(Intent.ACTION_VIEW, syncDashboardUrl);
                    intent.setPackage(BuildInfo.getPackageName());
                    IntentUtils.safePutBinderExtra(
                            intent, CustomTabsIntent.EXTRA_SESSION, null);
                    context.startActivity(intent);
                }
            }));
}
 
Example #7
Source File: PassphraseTypeDialogFragment.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
private SpannableString getResetText() {
    final Context context = getActivity();
    return SpanApplier.applySpans(
            context.getString(R.string.sync_passphrase_encryption_reset_instructions),
            new SpanInfo("<resetlink>", "</resetlink>", new ClickableSpan() {
                @Override
                public void onClick(View view) {
                    Uri syncDashboardUrl = Uri.parse(
                            context.getText(R.string.sync_dashboard_url).toString());
                    Intent intent = new Intent(Intent.ACTION_VIEW, syncDashboardUrl);
                    intent.setPackage(BuildInfo.getPackageName(context));
                    IntentUtils.safePutBinderExtra(
                            intent, CustomTabsIntent.EXTRA_SESSION, null);
                    context.startActivity(intent);
                }
            }));
}
 
Example #8
Source File: SyncCustomizationFragment.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * Gets hint message to resolve sync error.
 * @param error The sync error.
 */
private String getSyncErrorHint(@SyncError int error) {
    Resources res = getActivity().getResources();
    switch (error) {
        case SYNC_ANDROID_SYNC_DISABLED:
            return res.getString(R.string.hint_android_sync_disabled);
        case SYNC_AUTH_ERROR:
            return res.getString(R.string.hint_sync_auth_error);
        case SYNC_CLIENT_OUT_OF_DATE:
            return res.getString(
                    R.string.hint_client_out_of_date, BuildInfo.getPackageLabel(getActivity()));
        case SYNC_OTHER_ERRORS:
            return res.getString(R.string.hint_other_sync_errors);
        case SYNC_PASSPHRASE_REQUIRED:
            return res.getString(R.string.hint_passphrase_required);
        case SYNC_NO_ERROR:
        default:
            return null;
    }
}
 
Example #9
Source File: PassphraseDialogFragment.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
private SpannableString getResetText() {
    final Context context = getActivity();
    return SpanApplier.applySpans(
            context.getString(R.string.sync_passphrase_reset_instructions),
            new SpanInfo("<resetlink>", "</resetlink>", new ClickableSpan() {
                @Override
                public void onClick(View view) {
                    recordPassphraseDialogDismissal(PASSPHRASE_DIALOG_RESET_LINK);
                    Uri syncDashboardUrl = Uri.parse(
                            context.getText(R.string.sync_dashboard_url).toString());
                    Intent intent = new Intent(Intent.ACTION_VIEW, syncDashboardUrl);
                    intent.setPackage(BuildInfo.getPackageName(context));
                    IntentUtils.safePutBinderExtra(
                            intent, CustomTabsIntent.EXTRA_SESSION, null);
                    context.startActivity(intent);
                }
            }));
}
 
Example #10
Source File: DefaultBrowserInfo.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Initialize an AsyncTask for getting menu title of opening a link in default browser.
 */
public static void initBrowserFetcher() {
    synchronized (sDirCreationLock) {
        if (sDefaultBrowserFetcher == null) {
            sDefaultBrowserFetcher = new AsyncTask<Void, Void, ArrayList<String>>() {
                @Override
                protected ArrayList<String> doInBackground(Void... params) {
                    Context context = ContextUtils.getApplicationContext();
                    ArrayList<String> menuTitles = new ArrayList<String>(2);
                    // Store the package label of current application.
                    menuTitles.add(
                            getTitleFromPackageLabel(context, BuildInfo.getPackageLabel()));

                    PackageManager pm = context.getPackageManager();
                    ResolveInfo info = getResolveInfoForViewIntent(pm);

                    // Caches whether Chrome is set as a default browser on the device.
                    boolean isDefault = (info != null && info.match != 0
                            && context.getPackageName().equals(info.activityInfo.packageName));
                    ChromePreferenceManager.getInstance().setCachedChromeDefaultBrowser(
                            isDefault);

                    // Check if there is a default handler for the Intent.  If so, store its
                    // label.
                    String packageLabel = null;
                    if (info != null && info.match != 0 && info.loadLabel(pm) != null) {
                        packageLabel = info.loadLabel(pm).toString();
                    }
                    menuTitles.add(getTitleFromPackageLabel(context, packageLabel));
                    return menuTitles;
                }
            };
            sDefaultBrowserFetcher.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
    }
}
 
Example #11
Source File: MediaNotificationManager.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private static void finishStartingForegroundService(ListenerService s) {
    if (!BuildInfo.isAtLeastO()) return;

    ChromeNotificationBuilder builder =
            NotificationBuilderFactory.createChromeNotificationBuilder(
                    true /* preferCompat */, ChannelDefinitions.CHANNEL_ID_MEDIA);
    s.startForeground(s.getNotificationId(), builder.build());
}
 
Example #12
Source File: RequestGenerator.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Sends additional info that might be useful for statistics generation,
 * including information about channel and device type.
 * This string is partially sanitized for dashboard viewing and because people randomly set
 * these strings when building their own custom Android ROMs.
 */
public String getAdditionalParameters() {
    String applicationLabel = StringSanitizer.sanitize(BuildInfo.getPackageLabel());
    String brand = StringSanitizer.sanitize(Build.BRAND);
    String model = StringSanitizer.sanitize(Build.MODEL);
    return applicationLabel + ";" + brand + ";" + model;
}
 
Example #13
Source File: InvalidationController.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private void startServiceIfPossible(Intent intent) {
    // The use of background services is restricted when the application is not in foreground
    // for O. See crbug.com/680812.
    if (BuildInfo.isAtLeastO()) {
        try {
            mContext.startService(intent);
        } catch (IllegalStateException exception) {
            Log.e(TAG, "Failed to start service from exception: ", exception);
        }
    } else {
        mContext.startService(intent);
    }
}
 
Example #14
Source File: ViewResourceFrameLayout.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
protected void dispatchDraw(Canvas canvas) {
    super.dispatchDraw(canvas);
    // TODO(tedchoc): Switch to a better API when available. crbug.com/681877
    if (BuildInfo.isAtLeastO() && isReadyForCapture()) {
        mResourceAdapter.invalidate(null);
    }
}
 
Example #15
Source File: KillChildUncaughtExceptionHandler.java    From 365browser with Apache License 2.0 5 votes vote down vote up
static void maybeInstallHandler() {
    // Only suppress default dialog on release builds. This matches behavior for native crashes
    // in breakpad::FinalizeCrashDoneAndroid, where the dialog is suppressed on release builds
    // due to bad user experience. Note this is also the reason the exception stack is not
    // printed here, to avoid the stack being printed twice in release builds where breakpad
    // is also enabled.
    if (BuildInfo.isDebugAndroid()) return;
    Thread.setDefaultUncaughtExceptionHandler(new KillChildUncaughtExceptionHandler());
}
 
Example #16
Source File: BrowserAccessibilityManager.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Only relevant prior to Android O, see shouldRespectDisplayedPasswordText.
 */
@CalledByNative
boolean shouldExposePasswordText() {
    ContentResolver contentResolver = mContentViewCore.getContext().getContentResolver();

    if (BuildInfo.isAtLeastO()) {
        return (Settings.System.getInt(contentResolver, Settings.System.TEXT_SHOW_PASSWORD, 1)
                == 1);
    }

    return (Settings.Secure.getInt(
                    contentResolver, Settings.Secure.ACCESSIBILITY_SPEAK_PASSWORD, 0)
            == 1);
}
 
Example #17
Source File: SelectionPopupController.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Create {@link SelectionPopupController} instance.
 * @param context Context for action mode.
 * @param window WindowAndroid instance.
 * @param webContents WebContents instance.
 * @param view Container view.
 * @param renderCoordinates Coordinates info used to position elements.
 */
public SelectionPopupController(Context context, WindowAndroid window, WebContents webContents,
        View view, RenderCoordinates renderCoordinates) {
    mContext = context;
    mWindowAndroid = window;
    mWebContents = webContents;
    mView = view;
    mRenderCoordinates = renderCoordinates;

    // The menu items are allowed by default.
    mAllowedMenuItems = MENU_ITEM_SHARE | MENU_ITEM_WEB_SEARCH | MENU_ITEM_PROCESS_TEXT;
    mRepeatingHideRunnable = new Runnable() {
        @Override
        public void run() {
            assert mHidden;
            final long hideDuration = getDefaultHideDuration();
            // Ensure the next hide call occurs before the ActionMode reappears.
            mView.postDelayed(mRepeatingHideRunnable, hideDuration - 1);
            hideActionModeTemporarily(hideDuration);
        }
    };

    mSelectionClient =
            SmartSelectionClient.create(new SmartSelectionCallback(), window, webContents);

    // TODO(timav): Use android.R.id.textAssist for the Assist item id once we switch to
    // Android O SDK and remove |mAssistMenuItemId|.
    if (BuildInfo.isAtLeastO()) {
        mAssistMenuItemId =
                mContext.getResources().getIdentifier("textAssist", "id", "android");
    }

    nativeInit(webContents);
}
 
Example #18
Source File: SelectionPopupController.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private void updateAssistMenuItem(MenuDescriptor descriptor) {
    // There is no Assist functionality before Android O.
    if (!BuildInfo.isAtLeastO() || mAssistMenuItemId == 0) return;

    // The assist menu item ID has to be equal to android.R.id.textAssist. Until we compile
    // with Android O SDK where this ID is defined we replace the corresponding inflated
    // item with an item with the proper ID.
    // TODO(timav): Use android.R.id.textAssist for the Assist item id once we switch to
    // Android O SDK and remove |mAssistMenuItemId|.

    if (mClassificationResult != null && mClassificationResult.hasNamedAction()) {
        descriptor.addItem(R.id.select_action_menu_assist_items, mAssistMenuItemId, 1,
                mClassificationResult.label, mClassificationResult.icon);
    }
}
 
Example #19
Source File: ActivityWindowAndroid.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private String getHasRequestedPermissionKey(String permission) {
    String permissionQueriedKey = permission;
    // Prior to O, permissions were granted at the group level.  Post O, each permission is
    // granted individually.
    if (!BuildInfo.isAtLeastO()) {
        try {
            // Runtime permissions are controlled at the group level.  So when determining
            // whether we have requested a particular permission before, we should check whether
            // we have requested any permission in that group as that mimics the logic in the
            // Android framework.
            //
            // e.g. Requesting first the permission ACCESS_FINE_LOCATION will result in Chrome
            //      treating ACCESS_COARSE_LOCATION as if it had already been requested as well.
            PermissionInfo permissionInfo =
                    getApplicationContext().getPackageManager().getPermissionInfo(
                            permission, PackageManager.GET_META_DATA);

            if (!TextUtils.isEmpty(permissionInfo.group)) {
                permissionQueriedKey = permissionInfo.group;
            }
        } catch (NameNotFoundException e) {
            // Unknown permission.  Default back to the permission name instead of the group.
        }
    }

    return PERMISSION_QUERIED_KEY_PREFIX + permissionQueriedKey;
}
 
Example #20
Source File: InvalidationClientService.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private void startServiceIfPossible(Intent intent) {
    // The use of background services is restricted when the application is not in foreground
    // for O. See crbug.com/680812.
    if (BuildInfo.isAtLeastO()) {
        try {
            startService(intent);
        } catch (IllegalStateException exception) {
            Log.e(TAG, "Failed to start service from exception: ", exception);
        }
    } else {
        startService(intent);
    }
}
 
Example #21
Source File: InvalidationService.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private void startServiceIfPossible(Intent intent) {
    // The use of background services is restricted when the application is not in foreground
    // for O. See crbug.com/680812.
    if (BuildInfo.isAtLeastO()) {
        try {
            ContextUtils.getApplicationContext().startService(intent);
        } catch (IllegalStateException exception) {
            Log.e(TAG, "Failed to start service from exception: ", exception);
        }
    } else {
        ContextUtils.getApplicationContext().startService(intent);
    }
}
 
Example #22
Source File: NotificationUmaTracker.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Logs {@link android.app.Notification} usage, categorized into {@link SystemNotificationType}
 * types.  Splits the logs by the global enabled state of notifications and also logs the last
 * notification shown prior to the global notifications state being disabled by the user.
 * @param type The type of notification that was shown.
 * @param channelId The id of the notification channel set on the notification.
 * @see SystemNotificationType
 */
public void onNotificationShown(
        @SystemNotificationType int type, @ChannelDefinitions.ChannelId String channelId) {
    if (!mNotificationManager.areNotificationsEnabled()) {
        logPotentialBlockedCause();
        recordHistogram("Mobile.SystemNotification.Blocked", type);
        return;
    }
    if (BuildInfo.isAtLeastO() && channelId != null && isChannelBlocked(channelId)) {
        recordHistogram("Mobile.SystemNotification.ChannelBlocked", type);
        return;
    }
    saveLastShownNotification(type);
    recordHistogram("Mobile.SystemNotification.Shown", type);
}
 
Example #23
Source File: RequestGenerator.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Sends additional info that might be useful for statistics generation,
 * including information about channel and device type.
 * This string is partially sanitized for dashboard viewing and because people randomly set
 * these strings when building their own custom Android ROMs.
 */
public String getAdditionalParameters() {
    String applicationLabel =
            StringSanitizer.sanitize(BuildInfo.getPackageLabel(mApplicationContext));
    String brand = StringSanitizer.sanitize(Build.BRAND);
    String model = StringSanitizer.sanitize(Build.MODEL);
    return applicationLabel + ";" + brand + ";" + model;
}
 
Example #24
Source File: ChromeTabbedActivity.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Reports that a new tab launcher shortcut was selected or an action equivalent to a shortcut
 * was performed.
 * @param isIncognito Whether the shortcut or action created a new incognito tab.
 */
@TargetApi(25)
private void reportNewTabShortcutUsed(boolean isIncognito) {
    if (!BuildInfo.isGreaterThanN()) return;

    try {
        Class<?> clazz = Class.forName("android.content.pm.ShortcutManager");
        Method method = clazz.getDeclaredMethod("reportShortcutUsed", String.class);
        method.invoke(getSystemService(clazz),
                isIncognito ? "new-incognito-tab-shortcut" : "new-tab-shortcut");
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example #25
Source File: CustomTabAppMenuPropertiesDelegate.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Creates an {@link CustomTabAppMenuPropertiesDelegate} instance.
 */
public CustomTabAppMenuPropertiesDelegate(final ChromeActivity activity,
        List<String> menuEntries, boolean showShare, final boolean isOpenedByChrome,
        final boolean isMediaViewer) {
    super(activity);
    mMenuEntries = menuEntries;
    mShowShare = showShare;
    mIsMediaViewer = isMediaViewer;

    mDefaultBrowserFetcher = new AsyncTask<Void, Void, String>() {
        @Override
        protected String doInBackground(Void... params) {
            String packageLabel = null;
            if (isOpenedByChrome) {
                // If the Custom Tab was created by Chrome, Chrome should open it.
                packageLabel = BuildInfo.getPackageLabel(activity);
            } else {
                // Check if there is a default handler for the Intent.  If so, grab its label.
                Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(SAMPLE_URL));
                PackageManager pm = activity.getPackageManager();
                ResolveInfo info = pm.resolveActivity(intent, 0);
                if (info != null && info.match != 0) {
                    packageLabel = info.loadLabel(pm).toString();
                }
            }

            return packageLabel == null
                    ? activity.getString(R.string.menu_open_in_product_default)
                    : activity.getString(R.string.menu_open_in_product, packageLabel);
        }
    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
 
Example #26
Source File: RequestGenerator.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Sends additional info that might be useful for statistics generation,
 * including information about channel and device type.
 * This string is partially sanitized for dashboard viewing and because people randomly set
 * these strings when building their own custom Android ROMs.
 */
public String getAdditionalParameters() {
    String applicationLabel =
            StringSanitizer.sanitize(BuildInfo.getPackageLabel(mApplicationContext));
    String brand = StringSanitizer.sanitize(Build.BRAND);
    String model = StringSanitizer.sanitize(Build.MODEL);
    return applicationLabel + ";" + brand + ";" + model;
}
 
Example #27
Source File: MediaNotificationManager.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
void updateNotification(boolean serviceStarting) {
    if (mService == null) return;

    if (mMediaNotificationInfo == null) {
        if (serviceStarting) {
            finishStartingForegroundService(mService);
            mService.stopForeground(true /* removeNotification */);
        }
        return;
    }
    updateMediaSession();
    updateNotificationBuilder();

    Notification notification = mNotificationBuilder.build();

    // On O, finish starting the foreground service nevertheless, or Android will
    // crash Chrome.
    boolean foregroundedService = false;
    if (BuildInfo.isAtLeastO() && serviceStarting) {
        mService.startForeground(mMediaNotificationInfo.id, notification);
        foregroundedService = true;
    }

    // We keep the service as a foreground service while the media is playing. When it is not,
    // the service isn't stopped but is no longer in foreground, thus at a lower priority.
    // While the service is in foreground, the associated notification can't be swipped away.
    // Moving it back to background allows the user to remove the notification.
    if (mMediaNotificationInfo.supportsSwipeAway() && mMediaNotificationInfo.isPaused) {
        mService.stopForeground(false /* removeNotification */);

        NotificationManagerCompat manager = NotificationManagerCompat.from(getContext());
        manager.notify(mMediaNotificationInfo.id, notification);
    } else if (!foregroundedService) {
        mService.startForeground(mMediaNotificationInfo.id, notification);
    }
}
 
Example #28
Source File: PackageReplacedBroadcastReceiver.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public void onReceive(final Context context, Intent intent) {
    if (!Intent.ACTION_MY_PACKAGE_REPLACED.equals(intent.getAction())) return;
    updateChannelsIfNecessary();
    if (BuildInfo.isAtLeastO()) return;
    UpgradeIntentService.startMigrationIfNecessary(context);
}
 
Example #29
Source File: ShortcutHelper.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private static boolean isRequestPinShortcutSupported() {
    if (!sCheckedIfRequestPinShortcutSupported) {
        if (BuildInfo.isAtLeastO()) {
            checkIfRequestPinShortcutSupported();
        }
        sCheckedIfRequestPinShortcutSupported = true;
    }
    return sIsRequestPinShortcutSupported;
}
 
Example #30
Source File: DownloadSnackbarController.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Called to display the download succeeded snackbar.
 *
 * @param downloadInfo Info of the download.
 * @param notificationId Notification Id of the successful download.
 * @param downloadId Id of the download from Android DownloadManager.
 * @param canBeResolved Whether the download can be resolved to any activity.
 * @param usesAndroidDownloadManager Whether the download uses Android DownloadManager.
 */
public void onDownloadSucceeded(
        DownloadInfo downloadInfo, int notificationId, long downloadId, boolean canBeResolved,
        boolean usesAndroidDownloadManager) {
    if (getSnackbarManager() == null) return;
    Snackbar snackbar;
    if (getActivity() instanceof CustomTabActivity) {
        String packageLabel = BuildInfo.getPackageLabel();
        snackbar = Snackbar.make(mContext.getString(R.string.download_succeeded_message,
                downloadInfo.getFileName(), packageLabel),
                this, Snackbar.TYPE_NOTIFICATION, Snackbar.UMA_DOWNLOAD_SUCCEEDED);
    } else {
        snackbar = Snackbar.make(mContext.getString(R.string.download_succeeded_message_default,
                downloadInfo.getFileName()),
                this, Snackbar.TYPE_NOTIFICATION, Snackbar.UMA_DOWNLOAD_SUCCEEDED);
    }
    // TODO(qinmin): Coalesce snackbars if multiple downloads finish at the same time.
    snackbar.setDuration(SNACKBAR_DURATION_IN_MILLISECONDS).setSingleLine(false);
    ActionDataInfo info = null;
    if (canBeResolved || !LegacyHelpers.isLegacyDownload(downloadInfo.getContentId())
            || usesAndroidDownloadManager) {
        info = new ActionDataInfo(downloadInfo, notificationId, downloadId,
                usesAndroidDownloadManager);
    }
    // Show downloads app if the download cannot be resolved to any activity.
    snackbar.setAction(
            mContext.getString(R.string.open_downloaded_label), info);
    getSnackbarManager().showSnackbar(snackbar);
}