Java Code Examples for org.chromium.base.ContextUtils#getApplicationContext()

The following examples show how to use org.chromium.base.ContextUtils#getApplicationContext() . 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: IncognitoNotificationService.java    From delion with Apache License 2.0 6 votes vote down vote up
private void focusChromeIfNecessary() {
    Set<Integer> visibleTaskIds = getTaskIdsForVisibleActivities();
    int tabbedTaskId = -1;

    List<WeakReference<Activity>> runningActivities =
            ApplicationStatus.getRunningActivities();
    for (int i = 0; i < runningActivities.size(); i++) {
        Activity activity = runningActivities.get(i).get();
        if (activity == null) continue;

        if (activity instanceof ChromeTabbedActivity) {
            tabbedTaskId = activity.getTaskId();
            break;
        }
    }

    // If the task containing the tabbed activity is visible, then do nothing as there is no
    // snapshot that would need to be regenerated.
    if (visibleTaskIds.contains(tabbedTaskId)) return;

    Context context = ContextUtils.getApplicationContext();
    Intent startIntent = new Intent(Intent.ACTION_MAIN);
    startIntent.setPackage(context.getPackageName());
    startIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(startIntent);
}
 
Example 2
Source File: FeatureUtilities.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * Cache whether or not Chrome Home is enabled.
 */
public static void cacheChromeHomeEnabled() {
    Context context = ContextUtils.getApplicationContext();

    // Chrome Home doesn't work with tablets.
    if (DeviceFormFactor.isTablet(context)) return;

    boolean isChromeHomeEnabled = ChromeFeatureList.isEnabled(ChromeFeatureList.CHROME_HOME);
    ChromePreferenceManager manager = ChromePreferenceManager.getInstance(context);
    boolean valueChanged = isChromeHomeEnabled != manager.isChromeHomeEnabled();
    manager.setChromeHomeEnabled(isChromeHomeEnabled);
    sChromeHomeEnabled = isChromeHomeEnabled;

    // If the cached value changed, restart chrome.
    if (valueChanged) ApplicationLifetime.terminate(true);
}
 
Example 3
Source File: DownloadHistoryItemWrapper.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
@Override
public void open() {
    Context context = ContextUtils.getApplicationContext();

    if (mItem.hasBeenExternallyRemoved()) {
        Toast.makeText(context, context.getString(R.string.download_cant_open_file),
                Toast.LENGTH_SHORT).show();
        return;
    }

    if (DownloadUtils.openFile(getFile(), getMimeType(), isOffTheRecord())) {
        recordOpenSuccess();
    } else {
        recordOpenFailure();
    }
}
 
Example 4
Source File: ActivityDelegateImpl.java    From delion with Apache License 2.0 6 votes vote down vote up
@Override
public List<Entry> getTasksFromRecents(boolean isIncognito) {
    Context context = ContextUtils.getApplicationContext();
    ActivityManager activityManager =
            (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);

    List<Entry> entries = new ArrayList<Entry>();
    for (ActivityManager.AppTask task : activityManager.getAppTasks()) {
        Intent intent = DocumentUtils.getBaseIntentFromTask(task);
        if (!isValidActivity(isIncognito, intent)) continue;

        int tabId = getTabIdFromIntent(intent);
        if (tabId == Tab.INVALID_TAB_ID) continue;

        String initialUrl = getInitialUrlForDocument(intent);
        entries.add(new Entry(tabId, initialUrl));
    }
    return entries;
}
 
Example 5
Source File: ToolbarModelImpl.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the primary color and changes the state for isUsingBrandColor.
 * @param color The primary color for the current tab.
 */
public void setPrimaryColor(int color) {
    mPrimaryColor = color;
    Context context = ContextUtils.getApplicationContext();
    mIsUsingBrandColor = !isIncognito()
            && mPrimaryColor != ApiCompatibilityUtils.getColor(context.getResources(),
                    R.color.default_primary_color)
            && getTab() != null && !getTab().isNativePage();
}
 
Example 6
Source File: ChromeLauncherActivity.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * @return Whether or not an Herb prototype may hijack an Intent.
 */
public static boolean canBeHijackedByHerb(Intent intent) {
    String url = IntentHandler.getUrlFromIntent(intent);

    // Only VIEW Intents with URLs are rerouted to Custom Tabs.
    if (intent == null || !TextUtils.equals(Intent.ACTION_VIEW, intent.getAction())
            || TextUtils.isEmpty(url)) {
        return false;
    }

    // Don't reroute Chrome Intents.
    Context context = ContextUtils.getApplicationContext();
    if (TextUtils.equals(context.getPackageName(),
            IntentUtils.safeGetStringExtra(intent, Browser.EXTRA_APPLICATION_ID))) {
        return false;
    }

    // Don't reroute internal chrome URLs.
    try {
        URI uri = URI.create(url);
        if (UrlUtilities.isInternalScheme(uri)) return false;
    } catch (IllegalArgumentException e) {
        return false;
    }

    return true;
}
 
Example 7
Source File: LocaleManager.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@Override
public void onAction(Object actionData) {
    Context context = ContextUtils.getApplicationContext();
    Intent intent = PreferencesLauncher.createIntentForSettingsPage(context,
            SearchEnginePreference.class.getName());
    context.startActivity(intent);
}
 
Example 8
Source File: DocumentTabModelSelector.java    From delion with Apache License 2.0 5 votes vote down vote up
private int getLargestTaskIdFromRecents() {
    int biggestId = Tab.INVALID_TAB_ID;
    Context context = ContextUtils.getApplicationContext();
    ActivityManager activityManager =
            (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    for (ActivityManager.AppTask task : activityManager.getAppTasks()) {
        RecentTaskInfo info = DocumentUtils.getTaskInfoFromTask(task);
        if (info == null) continue;
        biggestId = Math.max(biggestId, info.persistentId);
    }
    return biggestId;
}
 
Example 9
Source File: AppBannerInfoBarDelegateAndroid.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@CalledByNative
private void openWebApk() {
    Context context = ContextUtils.getApplicationContext();
    PackageManager packageManager = getPackageManager(context);

    if (InstallerDelegate.isInstalled(packageManager, mWebApkPackage)) {
        openApp(context, mWebApkPackage);
    }
}
 
Example 10
Source File: PlatformUtil.java    From delion with Apache License 2.0 5 votes vote down vote up
@CalledByNative
private static void launchExternalProtocol(String url) {
    Context context = ContextUtils.getApplicationContext();
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.addCategory(Intent.CATEGORY_BROWSABLE);
    try {
        context.startActivity(intent);
    } catch (ActivityNotFoundException e) {
        Log.e(TAG, "cannot find activity to launch %s", url, e);
    }
}
 
Example 11
Source File: MultiWindowUtils.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the singleton instance of MultiWindowUtils, creating it if needed.
 */
public static MultiWindowUtils getInstance() {
    if (sInstance.get() == null) {
        ChromeApplication application =
                (ChromeApplication) ContextUtils.getApplicationContext();
        sInstance.compareAndSet(null, application.createMultiWindowUtils());
    }
    return sInstance.get();
}
 
Example 12
Source File: AbstractMediaRouteController.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
protected AbstractMediaRouteController() {
    mContext = ContextUtils.getApplicationContext();
    assert (getContext() != null);

    mHandler = new Handler();

    mMediaRouteSelector = buildMediaRouteSelector();

    MediaRouter mediaRouter;

    try {
        // Pre-MR1 versions of JB do not have the complete MediaRouter APIs,
        // so getting the MediaRouter instance will throw an exception.
        mediaRouter = MediaRouter.getInstance(getContext());
    } catch (NoSuchMethodError e) {
        Log.e(TAG, "Can't get an instance of MediaRouter, casting is not supported."
                + " Are you still on JB (JVP15S)?");
        mediaRouter = null;
    }
    mMediaRouter = mediaRouter;

    mAvailableRouteListeners = new HashSet<MediaStateListener>();
    // TODO(aberent): I am unclear why this is accessed from multiple threads, but
    // if I make it a HashSet then it gets ConcurrentModificationExceptions on some
    // types of disconnect. Investigate and fix.
    mUiListeners = new CopyOnWriteArraySet<UiListener>();

    mDeviceDiscoveryCallback = new DeviceDiscoveryCallback();
    mDeviceSelectionCallback = new DeviceSelectionCallback();
}
 
Example 13
Source File: LocationSettings.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the singleton instance of LocationSettings, creating it if needed.
 */
@SuppressFBWarnings("LI_LAZY_INIT_STATIC")
public static LocationSettings getInstance() {
    ThreadUtils.assertOnUiThread();
    if (sInstance == null) {
        ChromeApplication application =
                (ChromeApplication) ContextUtils.getApplicationContext();
        sInstance = application.createLocationSettings();
    }
    return sInstance;
}
 
Example 14
Source File: Profile.java    From delion with Apache License 2.0 5 votes vote down vote up
@CalledByNative
private void onNativeDestroyed() {
    mNativeProfileAndroid = 0;

    if (mIsOffTheRecord) {
        Context context = ContextUtils.getApplicationContext();
        CookiesFetcher.deleteCookiesIfNecessary(context);
    }
}
 
Example 15
Source File: ProcessInitializationHandler.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Performs the post native initialization.
 */
protected void handlePostNativeInitialization() {
    final ChromeApplication application =
            (ChromeApplication) ContextUtils.getApplicationContext();

    DataReductionProxySettings.reconcileDataReductionProxyEnabledState(application);
    ChromeActivitySessionTracker.getInstance().initializeWithNative();
    ChromeApplication.removeSessionCookies();
    AppBannerManager.setAppDetailsDelegate(application.createAppDetailsDelegate());
    ChromeLifetimeController.initialize();

    PrefServiceBridge.getInstance().migratePreferences(application);
}
 
Example 16
Source File: NetworkChangeNotifierAutoDetect.java    From cronet with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Constructs a NetworkChangeNotifierAutoDetect.  Lives on calling thread, receives broadcast
 * notifications on the UI thread and forwards the notifications to be processed on the calling
 * thread.
 * @param policy The RegistrationPolicy which determines when this class should watch
 *     for network changes (e.g. see (@link RegistrationPolicyAlwaysRegister} and
 *     {@link RegistrationPolicyApplicationStatus}).
 */
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public NetworkChangeNotifierAutoDetect(Observer observer, RegistrationPolicy policy) {
    mLooper = Looper.myLooper();
    mHandler = new Handler(mLooper);
    mObserver = observer;
    mConnectivityManagerDelegate =
            new ConnectivityManagerDelegate(ContextUtils.getApplicationContext());
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
        mWifiManagerDelegate = new WifiManagerDelegate(ContextUtils.getApplicationContext());
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        mNetworkCallback = new MyNetworkCallback();
        mNetworkRequest = new NetworkRequest.Builder()
                                  .addCapability(NET_CAPABILITY_INTERNET)
                                  // Need to hear about VPNs too.
                                  .removeCapability(NET_CAPABILITY_NOT_VPN)
                                  .build();
    } else {
        mNetworkCallback = null;
        mNetworkRequest = null;
    }
    mDefaultNetworkCallback = Build.VERSION.SDK_INT >= Build.VERSION_CODES.P
            ? new DefaultNetworkCallback()
            : null;
    mNetworkState = getCurrentNetworkState();
    mIntentFilter = new NetworkConnectivityIntentFilter();
    mIgnoreNextBroadcast = false;
    mShouldSignalObserver = false;
    mRegistrationPolicy = policy;
    mRegistrationPolicy.init(this);
    mShouldSignalObserver = true;
}
 
Example 17
Source File: PowerBroadcastReceiver.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
/**
 * Executed when all of the system conditions are met.
 */
public void runActions() {
    Context context = ContextUtils.getApplicationContext();
    OmahaClient.onForegroundSessionStart(context);
    DelayedInvalidationsController.getInstance().notifyPendingInvalidations(context);
}
 
Example 18
Source File: PowerBroadcastReceiver.java    From delion with Apache License 2.0 4 votes vote down vote up
/**
 * Executed when all of the system conditions are met.
 */
public void runActions() {
    Context context = ContextUtils.getApplicationContext();
    OmahaClient.onForegroundSessionStart(context);
    DelayedInvalidationsController.getInstance().notifyPendingInvalidations(context);
}
 
Example 19
Source File: NearbyBackgroundSubscription.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
NearbyBackgroundSubscription(int action, Runnable callback) {
    super(ContextUtils.getApplicationContext());
    mAction = action;
    mCallback = callback;
}
 
Example 20
Source File: PrivacyPreferencesManager.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
public static PrivacyPreferencesManager getInstance() {
    if (sInstance == null) {
        sInstance = new PrivacyPreferencesManager(ContextUtils.getApplicationContext());
    }
    return sInstance;
}