org.chromium.base.ApplicationState Java Examples

The following examples show how to use org.chromium.base.ApplicationState. 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: 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 #2
Source File: NetworkChangeNotifierAutoDetect.java    From cronet with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * @param networkInfo The NetworkInfo for the active network.
 * @return the info of the network that is available to this app.
 */
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private NetworkInfo processActiveNetworkInfo(NetworkInfo networkInfo) {
    if (networkInfo == null) {
        return null;
    }

    if (networkInfo.isConnected()) {
        return networkInfo;
    }

    // If |networkInfo| is BLOCKED, but the app is in the foreground, then it's likely that
    // Android hasn't finished updating the network access permissions as BLOCKED is only
    // meant for apps in the background.  See https://crbug.com/677365 for more details.
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        // https://crbug.com/677365 primarily affects only Lollipop and higher versions.
        return null;
    }

    if (networkInfo.getDetailedState() != NetworkInfo.DetailedState.BLOCKED) {
        // Network state is not blocked which implies that network access is
        // unavailable (not just blocked to this app).
        return null;
    }

    if (ApplicationStatus.getStateForApplication()
            != ApplicationState.HAS_RUNNING_ACTIVITIES) {
        // The app is not in the foreground.
        return null;
    }
    return networkInfo;
}
 
Example #3
Source File: RegistrationPolicyApplicationStatus.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public void onApplicationStateChange(int newState) {
    if (newState == ApplicationState.HAS_RUNNING_ACTIVITIES) {
        register();
    } else if (newState == ApplicationState.HAS_PAUSED_ACTIVITIES) {
        unregister();
    }
}
 
Example #4
Source File: NetworkChangeNotifierAutoDetect.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * @return the info of the network that is available to this app.
 */
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private NetworkInfo getActiveNetworkInfo() {
    final NetworkInfo networkInfo = mConnectivityManager.getActiveNetworkInfo();
    if (networkInfo == null) {
        return null;
    }

    if (networkInfo.isConnected()) {
        return networkInfo;
    }

    // If |networkInfo| is BLOCKED, but the app is in the foreground, then it's likely that
    // Android hasn't finished updating the network access permissions as BLOCKED is only
    // meant for apps in the background.  See https://crbug.com/677365 for more details.
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        // https://crbug.com/677365 primarily affects only Lollipop and higher versions.
        return null;
    }

    if (networkInfo.getDetailedState() != NetworkInfo.DetailedState.BLOCKED) {
        // Network state is not blocked which implies that network access is
        // unavailable (not just blocked to this app).
        return null;
    }

    if (ApplicationStatus.getStateForApplication()
            != ApplicationState.HAS_RUNNING_ACTIVITIES) {
        // The app is not in the foreground.
        return null;
    }
    return networkInfo;
}
 
Example #5
Source File: InvalidationController.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public void onApplicationStateChange(int newState) {
    // The isSyncEnabled() check is used to check whether the InvalidationController would be
    // started if it did not stop itself when the application is paused.
    if (AndroidSyncSettings.isSyncEnabled(mContext)) {
        if (newState == ApplicationState.HAS_RUNNING_ACTIVITIES) {
            start();
        } else if (newState == ApplicationState.HAS_PAUSED_ACTIVITIES) {
            stop();
        }
    }
}
 
Example #6
Source File: DefaultMediaRouteController.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public void onApplicationStateChange(int newState) {
    switch (newState) {
        // HAS_DESTROYED_ACTIVITIES means all Chrome activities have been destroyed.
        case ApplicationState.HAS_DESTROYED_ACTIVITIES:
            onActivitiesDestroyed();
            break;
        default:
            break;
    }
}
 
Example #7
Source File: ChromeActivitySessionTracker.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private ApplicationStateListener createApplicationStateListener() {
    return new ApplicationStateListener() {
        @Override
        public void onApplicationStateChange(int newState) {
            if (newState == ApplicationState.HAS_STOPPED_ACTIVITIES) {
                onForegroundSessionEnd();
            } else if (newState == ApplicationState.HAS_DESTROYED_ACTIVITIES) {
                onForegroundActivityDestroyed();
            }
        }
    };
}
 
Example #8
Source File: InvalidationController.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@Override
public void onApplicationStateChange(int newState) {
    // The isSyncEnabled() check is used to check whether the InvalidationController would be
    // started if it did not stop itself when the application is paused.
    if (AndroidSyncSettings.isSyncEnabled(mContext)) {
        if (newState == ApplicationState.HAS_RUNNING_ACTIVITIES) {
            start();
        } else if (newState == ApplicationState.HAS_PAUSED_ACTIVITIES) {
            stop();
        }
    }
}
 
Example #9
Source File: DefaultMediaRouteController.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@Override
public void onApplicationStateChange(int newState) {
    switch (newState) {
        // HAS_DESTROYED_ACTIVITIES means all Chrome activities have been destroyed.
        case ApplicationState.HAS_DESTROYED_ACTIVITIES:
            onActivitiesDestroyed();
            break;
        default:
            break;
    }
}
 
Example #10
Source File: ChromeActivitySessionTracker.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
private ApplicationStateListener createApplicationStateListener() {
    return new ApplicationStateListener() {
        @Override
        public void onApplicationStateChange(int newState) {
            if (newState == ApplicationState.HAS_STOPPED_ACTIVITIES) {
                onForegroundSessionEnd();
            } else if (newState == ApplicationState.HAS_DESTROYED_ACTIVITIES) {
                onForegroundActivityDestroyed();
            }
        }
    };
}
 
Example #11
Source File: AndroidCellularSignalStrength.java    From cronet with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void onApplicationStateChange(int newState) {
    if (newState == ApplicationState.HAS_RUNNING_ACTIVITIES) {
        register();
    } else if (newState == ApplicationState.HAS_PAUSED_ACTIVITIES) {
        unregister();
    }
}
 
Example #12
Source File: RegistrationPolicyApplicationStatus.java    From cronet with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void onApplicationStateChange(int newState) {
    if (newState == ApplicationState.HAS_RUNNING_ACTIVITIES) {
        register();
    } else if (newState == ApplicationState.HAS_PAUSED_ACTIVITIES) {
        unregister();
    }
}
 
Example #13
Source File: InvalidationController.java    From delion with Apache License 2.0 5 votes vote down vote up
@Override
public void onApplicationStateChange(int newState) {
    // The isSyncEnabled() check is used to check whether the InvalidationController would be
    // started if it did not stop itself when the application is paused.
    if (AndroidSyncSettings.isSyncEnabled(mContext)) {
        if (newState == ApplicationState.HAS_RUNNING_ACTIVITIES) {
            start();
        } else if (newState == ApplicationState.HAS_PAUSED_ACTIVITIES) {
            stop();
        }
    }
}
 
Example #14
Source File: DefaultMediaRouteController.java    From delion with Apache License 2.0 5 votes vote down vote up
@Override
public void onApplicationStateChange(int newState) {
    switch (newState) {
        // HAS_DESTROYED_ACTIVITIES means all Chrome activities have been destroyed.
        case ApplicationState.HAS_DESTROYED_ACTIVITIES:
            onActivitiesDestroyed();
            break;
        default:
            break;
    }
}
 
Example #15
Source File: ChromeApplication.java    From delion with Apache License 2.0 5 votes vote down vote up
private ApplicationStateListener createApplicationStateListener() {
    return new ApplicationStateListener() {
        @Override
        public void onApplicationStateChange(int newState) {
            if (newState == ApplicationState.HAS_STOPPED_ACTIVITIES) {
                onForegroundSessionEnd();
            } else if (newState == ApplicationState.HAS_DESTROYED_ACTIVITIES) {
                onForegroundActivityDestroyed();
            }
        }
    };
}
 
Example #16
Source File: ExternalDataUseObserver.java    From 365browser with Apache License 2.0 4 votes vote down vote up
@Override
public void onApplicationStateChange(int newState) {
    if (newState == ApplicationState.HAS_RUNNING_ACTIVITIES) {
        checkAndNotifyPackageInstallState();
    }
}
 
Example #17
Source File: ExternalNavigationDelegateImpl.java    From 365browser with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isChromeAppInForeground() {
    return ApplicationStatus.getStateForApplication()
            == ApplicationState.HAS_RUNNING_ACTIVITIES;
}
 
Example #18
Source File: ExternalDataUseObserver.java    From delion with Apache License 2.0 4 votes vote down vote up
@Override
public void onApplicationStateChange(int newState) {
    if (newState == ApplicationState.HAS_RUNNING_ACTIVITIES) {
        checkAndNotifyPackageInstallState();
    }
}
 
Example #19
Source File: TabWebContentsObserver.java    From 365browser with Apache License 2.0 4 votes vote down vote up
@Override
public void renderProcessGone(boolean processWasOomProtected) {
    Log.i(TAG, "renderProcessGone() for tab id: " + mTab.getId()
            + ", oom protected: " + Boolean.toString(processWasOomProtected)
            + ", already needs reload: " + Boolean.toString(mTab.needsReload()));
    // Do nothing for subsequent calls that happen while the tab remains crashed. This
    // can occur when the tab is in the background and it shares the renderer with other
    // tabs. After the renderer crashes, the WebContents of its tabs are still around
    // and they still share the RenderProcessHost. When one of the tabs reloads spawning
    // a new renderer for the shared RenderProcessHost and the new renderer crashes
    // again, all tabs sharing this renderer will be notified about the crash (including
    // potential background tabs that did not reload yet).
    if (mTab.needsReload() || mTab.isShowingSadTab()) return;

    // This will replace TabRendererCrashStatus if numbers line up.
    int appState = ApplicationStatus.getStateForApplication();
    boolean applicationRunning = (appState == ApplicationState.HAS_RUNNING_ACTIVITIES);
    boolean applicationPaused = (appState == ApplicationState.HAS_PAUSED_ACTIVITIES);
    @TabRendererExitStatus int rendererExitStatus = TAB_RENDERER_EXIT_STATUS_MAX;
    if (processWasOomProtected) {
        if (applicationRunning) {
            rendererExitStatus = TAB_RENDERER_EXIT_STATUS_OOM_PROTECTED_IN_RUNNING_APP;
        } else if (applicationPaused) {
            rendererExitStatus = TAB_RENDERER_EXIT_STATUS_OOM_PROTECTED_IN_PAUSED_APP;
        } else {
            rendererExitStatus = TAB_RENDERER_EXIT_STATUS_OOM_PROTECTED_IN_BACKGROUND_APP;
        }
    } else {
        if (applicationRunning) {
            rendererExitStatus = TAB_RENDERER_EXIT_STATUS_NOT_PROTECTED_IN_RUNNING_APP;
        } else if (applicationPaused) {
            rendererExitStatus = TAB_RENDERER_EXIT_STATUS_NOT_PROTECTED_IN_PAUSED_APP;
        } else {
            rendererExitStatus = TAB_RENDERER_EXIT_STATUS_NOT_PROTECTED_IN_BACKGROUND_APP;
        }
    }
    RecordHistogram.recordEnumeratedHistogram(
            "Tab.RendererExitStatus", rendererExitStatus, TAB_RENDERER_EXIT_STATUS_MAX);

    int activityState = ApplicationStatus.getStateForActivity(
            mTab.getWindowAndroid().getActivity().get());
    int rendererCrashStatus = TAB_RENDERER_CRASH_STATUS_MAX;
    if (!processWasOomProtected
            || activityState == ActivityState.PAUSED
            || activityState == ActivityState.STOPPED
            || activityState == ActivityState.DESTROYED) {
        // The tab crashed in background or was killed by the OS out-of-memory killer.
        //setNeedsReload(true);
        mTab.setNeedsReload(true);
        if (applicationRunning) {
            rendererCrashStatus = TAB_RENDERER_CRASH_STATUS_HIDDEN_IN_FOREGROUND_APP;
        } else {
            rendererCrashStatus = TAB_RENDERER_CRASH_STATUS_HIDDEN_IN_BACKGROUND_APP;
        }
    } else {
        rendererCrashStatus = TAB_RENDERER_CRASH_STATUS_SHOWN_IN_FOREGROUND_APP;
        mTab.showSadTab();
        // This is necessary to correlate histogram data with stability counts.
        UmaSessionStats.logRendererCrash();
    }
    RecordHistogram.recordEnumeratedHistogram(
            "Tab.RendererCrashStatus", rendererCrashStatus, TAB_RENDERER_CRASH_STATUS_MAX);

    mTab.handleTabCrash();
}
 
Example #20
Source File: GoogleServicesManager.java    From 365browser with Apache License 2.0 4 votes vote down vote up
@Override
public void onApplicationStateChange(int newState) {
    if (newState == ApplicationState.HAS_RUNNING_ACTIVITIES) {
        onMainActivityStart();
    }
}
 
Example #21
Source File: GoogleServicesManager.java    From delion with Apache License 2.0 4 votes vote down vote up
@Override
public void onApplicationStateChange(int newState) {
    if (newState == ApplicationState.HAS_RUNNING_ACTIVITIES) {
        onMainActivityStart();
    }
}
 
Example #22
Source File: ExternalDataUseObserver.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
@Override
public void onApplicationStateChange(int newState) {
    if (newState == ApplicationState.HAS_RUNNING_ACTIVITIES) {
        checkAndNotifyPackageInstallState();
    }
}
 
Example #23
Source File: ExternalNavigationDelegateImpl.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isChromeAppInForeground() {
    return ApplicationStatus.getStateForApplication()
            == ApplicationState.HAS_RUNNING_ACTIVITIES;
}
 
Example #24
Source File: TabWebContentsObserver.java    From delion with Apache License 2.0 4 votes vote down vote up
@Override
public void renderProcessGone(boolean processWasOomProtected) {
    Log.i(TAG, "renderProcessGone() for tab id: " + mTab.getId()
            + ", oom protected: " + Boolean.toString(processWasOomProtected)
            + ", already needs reload: " + Boolean.toString(mTab.needsReload()));
    // Do nothing for subsequent calls that happen while the tab remains crashed. This
    // can occur when the tab is in the background and it shares the renderer with other
    // tabs. After the renderer crashes, the WebContents of its tabs are still around
    // and they still share the RenderProcessHost. When one of the tabs reloads spawning
    // a new renderer for the shared RenderProcessHost and the new renderer crashes
    // again, all tabs sharing this renderer will be notified about the crash (including
    // potential background tabs that did not reload yet).
    if (mTab.needsReload() || mTab.isShowingSadTab()) return;

    // This will replace TabRendererCrashStatus if numbers line up.
    int appState = ApplicationStatus.getStateForApplication();
    boolean applicationRunning = (appState == ApplicationState.HAS_RUNNING_ACTIVITIES);
    boolean applicationPaused = (appState == ApplicationState.HAS_PAUSED_ACTIVITIES);
    @TabRendererExitStatus int rendererExitStatus = TAB_RENDERER_EXIT_STATUS_MAX;
    if (processWasOomProtected) {
        if (applicationRunning) {
            rendererExitStatus = TAB_RENDERER_EXIT_STATUS_OOM_PROTECTED_IN_RUNNING_APP;
        } else if (applicationPaused) {
            rendererExitStatus = TAB_RENDERER_EXIT_STATUS_OOM_PROTECTED_IN_PAUSED_APP;
        } else {
            rendererExitStatus = TAB_RENDERER_EXIT_STATUS_OOM_PROTECTED_IN_BACKGROUND_APP;
        }
    } else {
        if (applicationRunning) {
            rendererExitStatus = TAB_RENDERER_EXIT_STATUS_NOT_PROTECTED_IN_RUNNING_APP;
        } else if (applicationPaused) {
            rendererExitStatus = TAB_RENDERER_EXIT_STATUS_NOT_PROTECTED_IN_PAUSED_APP;
        } else {
            rendererExitStatus = TAB_RENDERER_EXIT_STATUS_NOT_PROTECTED_IN_BACKGROUND_APP;
        }
    }
    RecordHistogram.recordEnumeratedHistogram(
            "Tab.RendererExitStatus", rendererExitStatus, TAB_RENDERER_EXIT_STATUS_MAX);

    int activityState = ApplicationStatus.getStateForActivity(
            mTab.getWindowAndroid().getActivity().get());
    int rendererCrashStatus = TAB_RENDERER_CRASH_STATUS_MAX;
    if (!processWasOomProtected
            || activityState == ActivityState.PAUSED
            || activityState == ActivityState.STOPPED
            || activityState == ActivityState.DESTROYED) {
        // The tab crashed in background or was killed by the OS out-of-memory killer.
        //setNeedsReload(true);
        mTab.setNeedsReload(true);
        if (applicationRunning) {
            rendererCrashStatus = TAB_RENDERER_CRASH_STATUS_HIDDEN_IN_FOREGROUND_APP;
        } else {
            rendererCrashStatus = TAB_RENDERER_CRASH_STATUS_HIDDEN_IN_BACKGROUND_APP;
        }
    } else {
        rendererCrashStatus = TAB_RENDERER_CRASH_STATUS_SHOWN_IN_FOREGROUND_APP;
        mTab.showSadTab();
        // This is necessary to correlate histogram data with stability counts.
        UmaSessionStats.logRendererCrash();
    }
    RecordHistogram.recordEnumeratedHistogram(
            "Tab.RendererCrashStatus", rendererCrashStatus, TAB_RENDERER_CRASH_STATUS_MAX);

    mTab.handleTabCrash();

    boolean sadTabShown = mTab.isShowingSadTab();
    RewindableIterator<TabObserver> observers = mTab.getTabObservers();
    while (observers.hasNext()) {
        observers.next().onCrash(mTab, sadTabShown);
    }
}
 
Example #25
Source File: TabWebContentsObserver.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
@Override
public void renderProcessGone(boolean processWasOomProtected) {
    Log.i(TAG, "renderProcessGone() for tab id: " + mTab.getId()
            + ", oom protected: " + Boolean.toString(processWasOomProtected)
            + ", already needs reload: " + Boolean.toString(mTab.needsReload()));
    // Do nothing for subsequent calls that happen while the tab remains crashed. This
    // can occur when the tab is in the background and it shares the renderer with other
    // tabs. After the renderer crashes, the WebContents of its tabs are still around
    // and they still share the RenderProcessHost. When one of the tabs reloads spawning
    // a new renderer for the shared RenderProcessHost and the new renderer crashes
    // again, all tabs sharing this renderer will be notified about the crash (including
    // potential background tabs that did not reload yet).
    if (mTab.needsReload() || mTab.isShowingSadTab()) return;

    // This will replace TabRendererCrashStatus if numbers line up.
    int appState = ApplicationStatus.getStateForApplication();
    boolean applicationRunning = (appState == ApplicationState.HAS_RUNNING_ACTIVITIES);
    boolean applicationPaused = (appState == ApplicationState.HAS_PAUSED_ACTIVITIES);
    @TabRendererExitStatus int rendererExitStatus = TAB_RENDERER_EXIT_STATUS_MAX;
    if (processWasOomProtected) {
        if (applicationRunning) {
            rendererExitStatus = TAB_RENDERER_EXIT_STATUS_OOM_PROTECTED_IN_RUNNING_APP;
        } else if (applicationPaused) {
            rendererExitStatus = TAB_RENDERER_EXIT_STATUS_OOM_PROTECTED_IN_PAUSED_APP;
        } else {
            rendererExitStatus = TAB_RENDERER_EXIT_STATUS_OOM_PROTECTED_IN_BACKGROUND_APP;
        }
    } else {
        if (applicationRunning) {
            rendererExitStatus = TAB_RENDERER_EXIT_STATUS_NOT_PROTECTED_IN_RUNNING_APP;
        } else if (applicationPaused) {
            rendererExitStatus = TAB_RENDERER_EXIT_STATUS_NOT_PROTECTED_IN_PAUSED_APP;
        } else {
            rendererExitStatus = TAB_RENDERER_EXIT_STATUS_NOT_PROTECTED_IN_BACKGROUND_APP;
        }
    }
    RecordHistogram.recordEnumeratedHistogram(
            "Tab.RendererExitStatus", rendererExitStatus, TAB_RENDERER_EXIT_STATUS_MAX);

    int activityState = ApplicationStatus.getStateForActivity(
            mTab.getWindowAndroid().getActivity().get());
    int rendererCrashStatus = TAB_RENDERER_CRASH_STATUS_MAX;
    if (!processWasOomProtected
            || activityState == ActivityState.PAUSED
            || activityState == ActivityState.STOPPED
            || activityState == ActivityState.DESTROYED) {
        // The tab crashed in background or was killed by the OS out-of-memory killer.
        //setNeedsReload(true);
        mTab.setNeedsReload(true);
        if (applicationRunning) {
            rendererCrashStatus = TAB_RENDERER_CRASH_STATUS_HIDDEN_IN_FOREGROUND_APP;
        } else {
            rendererCrashStatus = TAB_RENDERER_CRASH_STATUS_HIDDEN_IN_BACKGROUND_APP;
        }
    } else {
        rendererCrashStatus = TAB_RENDERER_CRASH_STATUS_SHOWN_IN_FOREGROUND_APP;
        mTab.showSadTab();
        // This is necessary to correlate histogram data with stability counts.
        UmaSessionStats.logRendererCrash();
    }
    RecordHistogram.recordEnumeratedHistogram(
            "Tab.RendererCrashStatus", rendererCrashStatus, TAB_RENDERER_CRASH_STATUS_MAX);

    mTab.handleTabCrash();

    boolean sadTabShown = mTab.isShowingSadTab();
    RewindableIterator<TabObserver> observers = mTab.getTabObservers();
    while (observers.hasNext()) {
        observers.next().onCrash(mTab, sadTabShown);
    }
}
 
Example #26
Source File: GoogleServicesManager.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
@Override
public void onApplicationStateChange(int newState) {
    if (newState == ApplicationState.HAS_RUNNING_ACTIVITIES) {
        onMainActivityStart();
    }
}
 
Example #27
Source File: ExternalNavigationDelegateImpl.java    From delion with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isChromeAppInForeground() {
    return ApplicationStatus.getStateForApplication()
            == ApplicationState.HAS_RUNNING_ACTIVITIES;
}