Search in sources :

Example 1 with VisibleForTesting

use of org.chromium.base.VisibleForTesting in project AndroidChromium by JackyAndroid.

the class ChromeBackgroundService method onRunTask.

@Override
@VisibleForTesting
public int onRunTask(final TaskParams params) {
    final String taskTag = params.getTag();
    Log.i(TAG, "[" + taskTag + "] Woken up at " + new java.util.Date().toString());
    final ChromeBackgroundServiceWaiter waiter = getWaiterIfNeeded(params.getExtras());
    final Context context = this;
    ThreadUtils.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            switch(taskTag) {
                case BackgroundSyncLauncher.TASK_TAG:
                    handleBackgroundSyncEvent(context, taskTag);
                    break;
                case OfflinePageUtils.TASK_TAG:
                    handleOfflinePageBackgroundLoad(context, params.getExtras(), waiter, taskTag);
                    break;
                case SnippetsLauncher.TASK_TAG_WIFI:
                case SnippetsLauncher.TASK_TAG_FALLBACK:
                    handleFetchSnippets(context, taskTag);
                    break;
                case PrecacheController.PERIODIC_TASK_TAG:
                case PrecacheController.CONTINUATION_TASK_TAG:
                    handlePrecache(context, taskTag);
                    break;
                case DownloadResumptionScheduler.TASK_TAG:
                    DownloadResumptionScheduler.getDownloadResumptionScheduler(context.getApplicationContext()).handleDownloadResumption();
                    break;
                default:
                    Log.i(TAG, "Unknown task tag " + taskTag);
                    break;
            }
        }
    });
    // If needed, block the GcmNetworkManager thread until the UI thread has finished its work.
    waitForTaskIfNeeded(waiter);
    return GcmNetworkManager.RESULT_SUCCESS;
}
Also used : Context(android.content.Context) VisibleForTesting(org.chromium.base.VisibleForTesting)

Example 2 with VisibleForTesting

use of org.chromium.base.VisibleForTesting in project AndroidChromium by JackyAndroid.

the class ChromeActivity method onShareMenuItemSelected.

/**
     * Triggered when the share menu item is selected.
     * This creates and shows a share intent picker dialog or starts a share intent directly.
     * @param shareDirectly Whether it should share directly with the activity that was most
     *                      recently used to share.
     * @param isIncognito Whether currentTab is incognito.
     */
@VisibleForTesting
public void onShareMenuItemSelected(final boolean shareDirectly, final boolean isIncognito) {
    final Tab currentTab = getActivityTab();
    if (currentTab == null)
        return;
    PrintingController printingController = PrintingControllerImpl.getInstance();
    if (printingController != null && !currentTab.isNativePage() && !printingController.isBusy() && PrefServiceBridge.getInstance().isPrintingEnabled()) {
        PrintShareActivity.enablePrintShareOption(this, new Runnable() {

            @Override
            public void run() {
                triggerShare(currentTab, shareDirectly, isIncognito);
            }
        });
        return;
    }
    triggerShare(currentTab, shareDirectly, isIncognito);
}
Also used : Tab(org.chromium.chrome.browser.tab.Tab) PrintingController(org.chromium.printing.PrintingController) VisibleForTesting(org.chromium.base.VisibleForTesting)

Example 3 with VisibleForTesting

use of org.chromium.base.VisibleForTesting in project AndroidChromium by JackyAndroid.

the class ShareHelper method setLastShareComponentName.

/*
     * Stores the component selected for sharing last time share was called.
     *
     * This method is public since it is used in tests to avoid creating share dialog.
     */
@VisibleForTesting
public static void setLastShareComponentName(ComponentName component) {
    SharedPreferences preferences = ContextUtils.getAppSharedPreferences();
    SharedPreferences.Editor editor = preferences.edit();
    editor.putString(PACKAGE_NAME_KEY, component.getPackageName());
    editor.putString(CLASS_NAME_KEY, component.getClassName());
    editor.apply();
}
Also used : SharedPreferences(android.content.SharedPreferences) VisibleForTesting(org.chromium.base.VisibleForTesting)

Example 4 with VisibleForTesting

use of org.chromium.base.VisibleForTesting in project AndroidChromium by JackyAndroid.

the class SingleWebsitePreferences method resetSite.

/**
     * Resets the current site, clearing all permissions and storage used (inc. cookies).
     */
@VisibleForTesting
protected void resetSite() {
    if (getActivity() == null)
        return;
    // Clear the screen.
    // TODO(mvanouwerkerk): Refactor this class so that it does not depend on the screen state
    // for its logic. This class should maintain its own data model, and only update the screen
    // after a change is made.
    PreferenceScreen screen = getPreferenceScreen();
    for (String key : PERMISSION_PREFERENCE_KEYS) {
        Preference preference = screen.findPreference(key);
        if (preference != null)
            screen.removePreference(preference);
    }
    // Clear the permissions.
    mSite.setAutoplayPermission(ContentSetting.DEFAULT);
    mSite.setBackgroundSyncPermission(ContentSetting.DEFAULT);
    mSite.setCameraPermission(ContentSetting.DEFAULT);
    mSite.setCookiePermission(ContentSetting.DEFAULT);
    WebsitePreferenceBridge.nativeClearCookieData(mSite.getAddress().getTitle());
    mSite.setFullscreenPermission(ContentSetting.DEFAULT);
    mSite.setGeolocationPermission(ContentSetting.DEFAULT);
    mSite.setJavaScriptPermission(ContentSetting.DEFAULT);
    mSite.setKeygenPermission(ContentSetting.DEFAULT);
    mSite.setMicrophonePermission(ContentSetting.DEFAULT);
    mSite.setMidiPermission(ContentSetting.DEFAULT);
    mSite.setNotificationPermission(ContentSetting.DEFAULT);
    mSite.setPopupPermission(ContentSetting.DEFAULT);
    mSite.setProtectedMediaIdentifierPermission(ContentSetting.DEFAULT);
    for (UsbInfo info : mSite.getUsbInfo()) info.revoke();
    // Clear the storage and finish the activity if necessary.
    if (mSite.getTotalUsage() > 0) {
        clearStoredData();
    } else {
        // Clearing stored data implies popping back to parent menu if there
        // is nothing left to show. Therefore, we only need to explicitly
        // close the activity if there's no stored data to begin with.
        getActivity().finish();
    }
}
Also used : PreferenceScreen(android.preference.PreferenceScreen) ListPreference(android.preference.ListPreference) Preference(android.preference.Preference) VisibleForTesting(org.chromium.base.VisibleForTesting)

Example 5 with VisibleForTesting

use of org.chromium.base.VisibleForTesting in project AndroidChromium by JackyAndroid.

the class NotificationBuilderBase method createIconGenerator.

@VisibleForTesting
static RoundedIconGenerator createIconGenerator(Resources resources) {
    int largeIconWidthPx = resources.getDimensionPixelSize(android.R.dimen.notification_large_icon_width);
    int largeIconHeightPx = resources.getDimensionPixelSize(android.R.dimen.notification_large_icon_height);
    float density = resources.getDisplayMetrics().density;
    int cornerRadiusPx = Math.min(largeIconWidthPx, largeIconHeightPx) / 2;
    return new RoundedIconGenerator(largeIconWidthPx, largeIconHeightPx, cornerRadiusPx, NOTIFICATION_ICON_BG_COLOR, NOTIFICATION_ICON_TEXT_SIZE_DP * density);
}
Also used : Paint(android.graphics.Paint) RoundedIconGenerator(org.chromium.chrome.browser.widget.RoundedIconGenerator) VisibleForTesting(org.chromium.base.VisibleForTesting)

Aggregations

VisibleForTesting (org.chromium.base.VisibleForTesting)52 Intent (android.content.Intent)6 IOException (java.io.IOException)6 SharedPreferences (android.content.SharedPreferences)5 JSONObject (org.json.JSONObject)4 PendingIntent (android.app.PendingIntent)3 SpannableString (android.text.SpannableString)3 BufferedReader (java.io.BufferedReader)3 Matcher (java.util.regex.Matcher)3 CalledByNative (org.chromium.base.annotations.CalledByNative)3 AccountManagerHelper (org.chromium.components.signin.AccountManagerHelper)3 SpanInfo (org.chromium.ui.text.SpanApplier.SpanInfo)3 SuppressLint (android.annotation.SuppressLint)2 IntentFilter (android.content.IntentFilter)2 Paint (android.graphics.Paint)2 File (java.io.File)2 FileReader (java.io.FileReader)2 HttpURLConnection (java.net.HttpURLConnection)2 ArrayList (java.util.ArrayList)2 Formatter (java.util.Formatter)2