org.chromium.base.ApplicationStatus Java Examples

The following examples show how to use org.chromium.base.ApplicationStatus. 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: Tab.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * @return Intent that tells Chrome to bring an Activity for a particular Tab back to the
 *         foreground, or null if this isn't possible.
 */
@Nullable
public static Intent createBringTabToFrontIntent(int tabId) {
    // Iterate through all {@link CustomTab}s and check whether the given tabId belongs to a
    // {@link CustomTab}. If so, return null as the client app's task cannot be foregrounded.
    List<WeakReference<Activity>> list = ApplicationStatus.getRunningActivities();
    for (WeakReference<Activity> ref : list) {
        Activity activity = ref.get();
        if (activity instanceof CustomTabActivity
                && ((CustomTabActivity) activity).getActivityTab() != null
                && tabId == ((CustomTabActivity) activity).getActivityTab().getId()) {
            return null;
        }
    }

    String packageName = ContextUtils.getApplicationContext().getPackageName();
    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.putExtra(Browser.EXTRA_APPLICATION_ID, packageName);
    intent.putExtra(TabOpenType.BRING_TAB_TO_FRONT.name(), tabId);
    intent.setPackage(packageName);
    return intent;
}
 
Example #2
Source File: BaseMediaRouteDialogManager.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
@Override
public void openDialog() {
    if (mAndroidMediaRouter == null) {
        mDelegate.onDialogCancelled();
        return;
    }

    FragmentActivity currentActivity =
            (FragmentActivity) ApplicationStatus.getLastTrackedFocusedActivity();
    if (currentActivity == null)  {
        mDelegate.onDialogCancelled();
        return;
    }

    FragmentManager fm = currentActivity.getSupportFragmentManager();
    if (fm == null)  {
        mDelegate.onDialogCancelled();
        return;
    }

    mDialogFragment = openDialogInternal(fm);
    if (mDialogFragment == null)  {
        mDelegate.onDialogCancelled();
        return;
    }
}
 
Example #3
Source File: ChromeFullscreenManager.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@Override
public void onActivityStateChange(Activity activity, int newState) {
    if (newState == ActivityState.STOPPED && mExitFullscreenOnStop) {
        // Exit fullscreen in onStop to ensure the system UI flags are set correctly when
        // showing again (on JB MR2+ builds, the omnibox would be covered by the
        // notification bar when this was done in onStart()).
        setPersistentFullscreenMode(false);
    } else if (newState == ActivityState.STARTED) {
        ThreadUtils.postOnUiThreadDelayed(new Runnable() {
            @Override
            public void run() {
                mBrowserVisibilityDelegate.showControlsTransient();
            }
        }, ACTIVITY_RETURN_SHOW_REQUEST_DELAY_MS);
    } else if (newState == ActivityState.DESTROYED) {
        ApplicationStatus.unregisterActivityStateListener(this);
        ((BaseChromiumApplication) mWindow.getContext().getApplicationContext())
                .unregisterWindowFocusChangedListener(this);

        mTabModelObserver.destroy();
    }
}
 
Example #4
Source File: RecentTabsPage.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Updates whether the page is in the foreground based on whether the application is in the
 * foreground and whether {@link #mView} is attached to the application window. If the page is
 * no longer in the foreground, records the time that the page spent in the foreground to UMA.
 */
private void updateForegroundState() {
    boolean inForeground = mIsAttachedToWindow
            && ApplicationStatus.getStateForActivity(mActivity) == ActivityState.RESUMED;
    if (mInForeground == inForeground) {
        return;
    }

    mInForeground = inForeground;
    if (mInForeground) {
        mForegroundTimeMs = SystemClock.elapsedRealtime();
        StartupMetrics.getInstance().recordOpenedRecents();
    } else {
        RecordHistogram.recordLongTimesHistogram("NewTabPage.RecentTabsPage.TimeVisibleAndroid",
                SystemClock.elapsedRealtime() - mForegroundTimeMs, TimeUnit.MILLISECONDS);
    }
}
 
Example #5
Source File: LifecycleHook.java    From delion with Apache License 2.0 6 votes vote down vote up
@Override
public void onApplicationStateChange(int newState) {
    Log.d(TAG, "onApplicationStateChange");
    ThreadUtils.assertOnUiThread();

    boolean newVisibility = ApplicationStatus.hasVisibleActivities();
    if (mIsApplicationVisible == newVisibility) return;

    Log.d(TAG, "Application visibilty changed to %s. Updating state of %d client(s).",
            newVisibility, mClientHelpers.size());

    mIsApplicationVisible = newVisibility;

    synchronized (mClientHelpers) {
        for (GoogleApiClientHelper clientHelper : mClientHelpers) {
            if (mIsApplicationVisible) clientHelper.restoreConnectedState();
            else clientHelper.scheduleDisconnection();
        }
    }
}
 
Example #6
Source File: WebApkInstaller.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
private ApplicationStatus.ApplicationStateListener createApplicationStateListener() {
    return new ApplicationStatus.ApplicationStateListener() {
        @Override
        public void onApplicationStateChange(int newState) {
            if (!ApplicationStatus.hasVisibleActivities()) return;
            /**
             * Currently WebAPKs aren't installed by Play. A user can cancel the installation
             * when the Android native installation dialog shows. The only way to detect the
             * user cancelling the installation is to check whether the WebAPK is installed
             * when Chrome is resumed. The monitoring of application state changes will be
             * removed once WebAPKs are installed by Play.
             */
            if (newState == ApplicationState.HAS_RUNNING_ACTIVITIES
                    && !isWebApkInstalled(mWebApkPackageName)) {
                onInstallFinishedInternal(false);
                return;
            }
        }
    };
}
 
Example #7
Source File: ChromeLifetimeController.java    From delion with Apache License 2.0 6 votes vote down vote up
@Override
public void onTerminate(boolean restart) {
    mRestartChromeOnDestroy = restart;

    for (WeakReference<Activity> weakActivity : ApplicationStatus.getRunningActivities()) {
        Activity activity = weakActivity.get();
        if (activity != null) {
            ApplicationStatus.registerStateListenerForActivity(this, activity);
            mRemainingActivitiesCount++;
            activity.finish();
        }
    }

    // Start the Activity that will ultimately kill this process.
    fireBrowserRestartActivityIntent(BrowserRestartActivity.ACTION_START_WATCHDOG);
}
 
Example #8
Source File: PrintShareActivity.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
private static void unregisterActivity(final Activity activity) {
    ThreadUtils.assertOnUiThread();

    sPendingShareActivities.remove(activity);
    if (!sPendingShareActivities.isEmpty()) return;
    ApplicationStatus.unregisterActivityStateListener(sStateListener);

    waitForPendingStateChangeTask();
    sStateChangeTask = new AsyncTask<Void, Void, Void>() {
        @Override
        protected Void doInBackground(Void... params) {
            if (!sPendingShareActivities.isEmpty()) return null;

            activity.getPackageManager().setComponentEnabledSetting(
                    new ComponentName(activity, PrintShareActivity.class),
                    PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
                    PackageManager.DONT_KILL_APP);
            return null;
        }

        @Override
        protected void onPostExecute(Void result) {
            if (sStateChangeTask == this) sStateChangeTask = null;
        }
    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
 
Example #9
Source File: WebappLauncherActivity.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * Brings a live WebappActivity back to the foreground if one exists for the given tab ID.
 * @param tabId ID of the Tab to bring back to the foreground.
 * @return True if a live WebappActivity was found, false otherwise.
 */
public static boolean bringWebappToFront(int tabId) {
    if (tabId == Tab.INVALID_TAB_ID) return false;

    for (WeakReference<Activity> activityRef : ApplicationStatus.getRunningActivities()) {
        Activity activity = activityRef.get();
        if (activity == null || !(activity instanceof WebappActivity)) continue;

        WebappActivity webappActivity = (WebappActivity) activity;
        if (webappActivity.getActivityTab() != null
                && webappActivity.getActivityTab().getId() == tabId) {
            Tab tab = webappActivity.getActivityTab();
            tab.getTabWebContentsDelegateAndroid().activateContents();
            return true;
        }
    }

    return false;
}
 
Example #10
Source File: ChromeActivity.java    From delion with Apache License 2.0 6 votes vote down vote up
/**
 * Called by the system when the activity changes from fullscreen mode to multi-window mode
 * and visa-versa.
 * @param isInMultiWindowMode True if the activity is in multi-window mode.
 */
public void onMultiWindowModeChanged(boolean isInMultiWindowMode) {
    recordMultiWindowModeChangedUserAction(isInMultiWindowMode);

    if (!isInMultiWindowMode
            && ApplicationStatus.getStateForActivity(this) == ActivityState.RESUMED) {
        // Start a new UMA session when exiting multi-window mode if the activity is currently
        // resumed. When entering multi-window Android recents gains focus, so ChromeActivity
        // will get a call to onPauseWithNative(), ending the current UMA session. When exiting
        // multi-window, however, if ChromeActivity is resumed it stays in that state.
        markSessionEnd();
        markSessionResume();
        FeatureUtilities.setIsInMultiWindowMode(
                MultiWindowUtils.getInstance().isInMultiWindowMode(this));
    }
}
 
Example #11
Source File: WebApkInstaller.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * Installs a WebAPK and monitors the installation process.
 * @param filePath File to install.
 * @param packageName Package name to install WebAPK at.
 * @return True if the install was started. A "true" return value does not guarantee that the
 *         install succeeds.
 */
@CalledByNative
private boolean installAsyncAndMonitorInstallationFromNative(
        String filePath, String packageName) {
    mIsInstall = true;
    mWebApkPackageName = packageName;

    // Start monitoring the installation.
    PackageManager packageManager = ContextUtils.getApplicationContext().getPackageManager();
    mInstallTask = new InstallerDelegate(Looper.getMainLooper(), packageManager,
            createInstallerDelegateObserver(), mWebApkPackageName);
    mInstallTask.start();
    // Start monitoring the application state changes.
    mListener = createApplicationStateListener();
    ApplicationStatus.registerApplicationStateListener(mListener);

    return installDownloadedWebApk(filePath);
}
 
Example #12
Source File: BaseMediaRouteDialogManager.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@Override
public void openDialog() {
    if (mAndroidMediaRouter == null) {
        mDelegate.onDialogCancelled();
        return;
    }

    FragmentActivity currentActivity =
            (FragmentActivity) ApplicationStatus.getLastTrackedFocusedActivity();
    if (currentActivity == null)  {
        mDelegate.onDialogCancelled();
        return;
    }

    FragmentManager fm = currentActivity.getSupportFragmentManager();
    if (fm == null)  {
        mDelegate.onDialogCancelled();
        return;
    }

    mDialogFragment = openDialogInternal(fm);
    if (mDialogFragment == null)  {
        mDelegate.onDialogCancelled();
        return;
    }
}
 
Example #13
Source File: WebappLauncherActivity.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Brings a live WebappActivity back to the foreground if one exists for the given tab ID.
 * @param tabId ID of the Tab to bring back to the foreground.
 * @return True if a live WebappActivity was found, false otherwise.
 */
public static boolean bringWebappToFront(int tabId) {
    if (tabId == Tab.INVALID_TAB_ID) return false;

    for (WeakReference<Activity> activityRef : ApplicationStatus.getRunningActivities()) {
        Activity activity = activityRef.get();
        if (activity == null || !(activity instanceof WebappActivity)) continue;

        WebappActivity webappActivity = (WebappActivity) activity;
        if (webappActivity.getActivityTab() != null
                && webappActivity.getActivityTab().getId() == tabId) {
            Tab tab = webappActivity.getActivityTab();
            tab.getTabWebContentsDelegateAndroid().activateContents();
            return true;
        }
    }

    return false;
}
 
Example #14
Source File: ChromeBrowserInitializer.java    From delion with Apache License 2.0 6 votes vote down vote up
private void preInflationStartup() {
    ThreadUtils.assertOnUiThread();
    if (mPreInflationStartupComplete) return;
    PathUtils.setPrivateDataDirectorySuffix(PRIVATE_DATA_DIRECTORY_SUFFIX, mApplication);

    // Ensure critical files are available, so they aren't blocked on the file-system
    // behind long-running accesses in next phase.
    // Don't do any large file access here!
    ContentApplication.initCommandLine(mApplication);
    waitForDebuggerIfNeeded();
    ChromeStrictMode.configureStrictMode();
    if (CommandLine.getInstance().hasSwitch(ChromeSwitches.ENABLE_WEBAPK)) {
        ChromeWebApkHost.init();
    }

    warmUpSharedPrefs();

    DeviceUtils.addDeviceSpecificUserAgentSwitch(mApplication);
    ApplicationStatus.registerStateListenerForAllActivities(
            createActivityStateListener());

    mPreInflationStartupComplete = true;
}
 
Example #15
Source File: ChromeBrowserInitializer.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
private void preInflationStartup() {
    ThreadUtils.assertOnUiThread();
    if (mPreInflationStartupComplete) return;
    PathUtils.setPrivateDataDirectorySuffix(PRIVATE_DATA_DIRECTORY_SUFFIX);

    // Ensure critical files are available, so they aren't blocked on the file-system
    // behind long-running accesses in next phase.
    // Don't do any large file access here!
    ContentApplication.initCommandLine(mApplication);
    waitForDebuggerIfNeeded();
    ChromeStrictMode.configureStrictMode();
    ChromeWebApkHost.init();

    warmUpSharedPrefs();

    DeviceUtils.addDeviceSpecificUserAgentSwitch(mApplication);
    ApplicationStatus.registerStateListenerForAllActivities(
            createActivityStateListener());

    mPreInflationStartupComplete = true;
}
 
Example #16
Source File: ChromeLifetimeController.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
@Override
public void onTerminate(boolean restart) {
    mRestartChromeOnDestroy = restart;

    for (WeakReference<Activity> weakActivity : ApplicationStatus.getRunningActivities()) {
        Activity activity = weakActivity.get();
        if (activity != null) {
            ApplicationStatus.registerStateListenerForActivity(this, activity);
            mRemainingActivitiesCount++;
            activity.finish();
        }
    }

    // Start the Activity that will ultimately kill this process.
    fireBrowserRestartActivityIntent(BrowserRestartActivity.ACTION_START_WATCHDOG);
}
 
Example #17
Source File: ChromeActivitySessionTracker.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * Called when last of Chrome activities is stopped, ending the foreground session. This will
 * not be called when a Chrome activity is stopped because another Chrome activity takes over.
 * This is ensured by ActivityStatus, which switches to track new activity when its started and
 * will not report the old one being stopped (see createStateListener() below).
 */
private void onForegroundSessionEnd() {
    if (!mIsStarted) return;
    ChromeApplication.flushPersistentData();
    mIsStarted = false;
    mPowerBroadcastReceiver.onForegroundSessionEnd();

    ChildProcessLauncher.onSentToBackground();
    IntentHandler.clearPendingReferrer();
    IntentHandler.clearPendingIncognitoUrl();

    int totalTabCount = 0;
    for (WeakReference<Activity> reference : ApplicationStatus.getRunningActivities()) {
        Activity activity = reference.get();
        if (activity instanceof ChromeActivity) {
            TabModelSelector tabModelSelector =
                    ((ChromeActivity) activity).getTabModelSelector();
            if (tabModelSelector != null) {
                totalTabCount += tabModelSelector.getTotalTabCount();
            }
        }
    }
    RecordHistogram.recordCountHistogram(
            "Tab.TotalTabCount.BeforeLeavingApp", totalTabCount);
}
 
Example #18
Source File: ActivityDelegate.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Check if the Tab is associated with an Activity that hasn't been destroyed.
 * This catches situations where a DocumentActivity is no longer listed in Android's Recents
 * list, but is not dead yet.
 * @param tabId ID of the Tab to find.
 * @return Whether the tab is still alive.
 */
public boolean isTabAssociatedWithNonDestroyedActivity(boolean isIncognito, int tabId) {
    List<WeakReference<Activity>> activities = ApplicationStatus.getRunningActivities();
    for (WeakReference<Activity> ref : activities) {
        Activity activity = ref.get();
        if (activity != null
                && isValidActivity(isIncognito, activity.getIntent())
                && getTabIdFromIntent(activity.getIntent()) == tabId
                && !isActivityDestroyed(activity)) {
            return true;
        }
    }
    return false;
}
 
Example #19
Source File: RecentTabsPage.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Constructor returns an instance of RecentTabsPage.
 *
 * @param activity The activity this view belongs to.
 * @param recentTabsManager The RecentTabsManager which provides the model data.
 */
public RecentTabsPage(ChromeActivity activity, RecentTabsManager recentTabsManager) {
    mActivity = activity;
    mRecentTabsManager = recentTabsManager;

    mTitle = activity.getResources().getString(R.string.recent_tabs);
    mThemeColor = ApiCompatibilityUtils.getColor(
            activity.getResources(), R.color.default_primary_color);
    mRecentTabsManager.setUpdatedCallback(this);
    LayoutInflater inflater = LayoutInflater.from(activity);
    mView = (ViewGroup) inflater.inflate(R.layout.recent_tabs_page, null);
    mListView = (ExpandableListView) mView.findViewById(R.id.odp_listview);
    mAdapter = new RecentTabsRowAdapter(activity, recentTabsManager);
    mListView.setAdapter(mAdapter);
    mListView.setOnChildClickListener(this);
    mListView.setGroupIndicator(null);
    mListView.setOnGroupCollapseListener(this);
    mListView.setOnGroupExpandListener(this);
    mListView.setOnCreateContextMenuListener(this);

    mView.addOnAttachStateChangeListener(this);
    ApplicationStatus.registerStateListenerForActivity(this, activity);
    // {@link #mInForeground} will be updated once the view is attached to the window.

    if (activity.getBottomSheet() != null) {
        View recentTabsRoot = mView.findViewById(R.id.recent_tabs_root);
        ApiCompatibilityUtils.setPaddingRelative(recentTabsRoot,
                ApiCompatibilityUtils.getPaddingStart(recentTabsRoot), 0,
                ApiCompatibilityUtils.getPaddingEnd(recentTabsRoot),
                activity.getResources().getDimensionPixelSize(
                        R.dimen.bottom_control_container_height));
    }

    onUpdated();
}
 
Example #20
Source File: AccountsChangedReceiver.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
private void continueHandleAccountChangeIfNeeded(final Context context, final Intent intent) {
    if (!AccountManager.LOGIN_ACCOUNTS_CHANGED_ACTION.equals(intent.getAction())) return;

    AccountTrackerService.get(context).invalidateAccountSeedStatus(
            false /* don't refresh right now */);
    boolean isChromeVisible = ApplicationStatus.hasVisibleActivities();
    if (isChromeVisible) {
        startBrowserIfNeededAndValidateAccounts(context);
    } else {
        // Notify SigninHelper of changed accounts (via shared prefs).
        SigninHelper.markAccountsChangedPref(context);
    }
    notifyAccountsChangedOnBrowserStartup(context, intent);
}
 
Example #21
Source File: OptionalShareTargetsManager.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Handles when the triggering activity has finished the sharing operation. If all
 * pending shares have been complete then it will disable all enabled components.
 * @param triggeringActivity The activity that is triggering the share action.
 */
public static void handleShareFinish(final Activity triggeringActivity) {
    ThreadUtils.assertOnUiThread();

    sPendingShareActivities.remove(triggeringActivity);
    if (!sPendingShareActivities.isEmpty()) return;
    ApplicationStatus.unregisterActivityStateListener(sStateListener);

    waitForPendingStateChangeTask();
    sStateChangeTask = new AsyncTask<Void, Void, Void>() {
        @Override
        protected Void doInBackground(Void... params) {
            if (!sPendingShareActivities.isEmpty()) return null;
            for (int i = 0; i < sEnabledComponents.size(); i++) {
                triggeringActivity.getPackageManager().setComponentEnabledSetting(
                        sEnabledComponents.get(i),
                        PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
                        PackageManager.DONT_KILL_APP);
            }
            return null;
        }

        @Override
        protected void onPostExecute(Void result) {
            if (sStateChangeTask == this) sStateChangeTask = null;
        }
    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
 
Example #22
Source File: OMADownloadHandler.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Shows a dialog to ask whether user wants to open the nextURL.
 *
 * @param omaInfo Information about the OMA content.
 */
private void showNextUrlDialog(OMAInfo omaInfo) {
    if (omaInfo.isValueEmpty(OMA_NEXT_URL)) {
        return;
    }
    final String nextUrl = omaInfo.getValue(OMA_NEXT_URL);
    final Activity activity = ApplicationStatus.getLastTrackedFocusedActivity();
    DialogInterface.OnClickListener clickListener = new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            if (which == AlertDialog.BUTTON_POSITIVE) {
                Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(nextUrl));
                intent.putExtra(Browser.EXTRA_APPLICATION_ID, activity.getPackageName());
                intent.putExtra(Browser.EXTRA_CREATE_NEW_TAB, true);
                intent.setPackage(mContext.getPackageName());
                activity.startActivity(intent);
            }
        }
    };
    new AlertDialog.Builder(activity)
            .setTitle(R.string.open_url_post_oma_download)
            .setPositiveButton(R.string.ok, clickListener)
            .setNegativeButton(R.string.cancel, clickListener)
            .setMessage(nextUrl)
            .setCancelable(false)
            .show();
}
 
Example #23
Source File: ChromeActivity.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public void onWindowFocusChanged(boolean hasFocus) {
    super.onWindowFocusChanged(hasFocus);

    maybeRemoveWindowBackground();

    Tab tab = getActivityTab();
    if (tab == null) return;
    if (hasFocus) {
        tab.onActivityShown();
    } else {
        boolean stopped = ApplicationStatus.getStateForActivity(this) == ActivityState.STOPPED;
        if (stopped) tab.onActivityHidden();
    }
}
 
Example #24
Source File: LifecycleHook.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Reset static singletons.
 * This is needed for JUnit tests as statics are not reset between runs and previous states can
 * make other tests fail. It is not needed in instrumentation tests (and will be removed by
 * Proguard in release builds) since the application lifecycle will naturally do the work.
 */
public static void destroyInstanceForJUnitTests() {
    LifecycleHook hook;
    synchronized (sInstanceLock) {
        if (sInstance == null) return;
        hook = sInstance;
        sInstance = null;
    }
    ApplicationStatus.unregisterApplicationStateListener(hook);
}
 
Example #25
Source File: LifecycleHook.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Reset static singletons.
 * This is needed for JUnit tests as statics are not reset between runs and previous states can
 * make other tests fail. It is not needed in instrumentation tests (and will be removed by
 * Proguard in release builds) since the application lifecycle will naturally do the work.
 */
public static void destroyInstanceForJUnitTests() {
    LifecycleHook hook;
    synchronized (sInstanceLock) {
        if (sInstance == null) return;
        hook = sInstance;
        sInstance = null;
    }
    ApplicationStatus.unregisterApplicationStateListener(hook);
}
 
Example #26
Source File: RemoteMediaPlayerController.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Links this object to the Activity that owns the video, if it exists.
 *
 */
private void linkToBrowserActivity() {

    Activity currentActivity = ApplicationStatus.getLastTrackedFocusedActivity();
    if (currentActivity != null) {
        mChromeVideoActivity = new WeakReference<Activity>(currentActivity);

        mCastContextApplicationContext = currentActivity.getApplicationContext();
        createMediaRouteControllers(currentActivity);
    }
}
 
Example #27
Source File: RemoteMediaPlayerController.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Called when a lower layer requests control of a video that is being cast.
 * @param player The player for which remote playback control is being requested.
 */
public void requestRemotePlaybackControl(MediaRouteController.MediaStateListener player) {
    // Player should match currently remotely played item, but there
    // can be a race between various
    // ways that the a video can stop playing remotely. Check that the
    // player is current, and ignore if not.

    if (mCurrentRouteController == null) return;
    if (mCurrentRouteController.getMediaStateListener() != player) return;

    showMediaRouteControlDialog(player, ApplicationStatus.getLastTrackedFocusedActivity());
}
 
Example #28
Source File: SigninManager.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Returns whether the sign-in flow activity was set but is no longer visible to the user.
 */
private boolean isActivityInvisible() {
    return activity != null
            && (ApplicationStatus.getStateForActivity(activity) == ActivityState.STOPPED
                       || ApplicationStatus.getStateForActivity(activity)
                               == ActivityState.DESTROYED);
}
 
Example #29
Source File: OmahaClient.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Determine whether or not Chrome is currently being used actively.
 */
@VisibleForTesting
protected boolean isChromeBeingUsed() {
    boolean isChromeVisible = ApplicationStatus.hasVisibleActivities();
    boolean isScreenOn = ApiCompatibilityUtils.isInteractive(this);
    return isChromeVisible && isScreenOn;
}
 
Example #30
Source File: VrWindowAndroid.java    From 365browser with Apache License 2.0 5 votes vote down vote up
public VrWindowAndroid(Context context, DisplayAndroid display) {
    super(context, display);
    Activity activity = activityFromContext(context);
    if (activity == null) {
        throw new IllegalArgumentException("Context is not and does not wrap an Activity");
    }
    ApplicationStatus.registerStateListenerForActivity(this, activity);
    setAndroidPermissionDelegate(new ActivityAndroidPermissionDelegate());
}