use of org.chromium.chrome.browser.ChromeTabbedActivity in project AndroidChromium by JackyAndroid.
the class ChromeLauncherActivity method launchFirstRunExperience.
/**
* Tries to launch the First Run Experience. If ChromeLauncherActivity is running with the
* wrong Intent flags, we instead relaunch ChromeLauncherActivity to make sure it runs in its
* own task, which then triggers First Run.
* @return Whether or not the First Run Experience needed to be shown.
* @param forTabbedMode Whether the First Run Experience is launched for tabbed mode.
*/
private boolean launchFirstRunExperience(boolean forTabbedMode) {
// Tries to launch the Generic First Run Experience for intent from GSA.
boolean showLightweightFre = IntentHandler.determineExternalIntentSource(this.getPackageName(), getIntent()) != ExternalAppId.GSA;
Intent freIntent = FirstRunFlowSequencer.checkIfFirstRunIsNecessary(this, getIntent(), showLightweightFre);
if (freIntent == null)
return false;
if ((getIntent().getFlags() & Intent.FLAG_ACTIVITY_NEW_TASK) != 0) {
if (CommandLine.getInstance().hasSwitch(ChromeSwitches.ENABLE_LIGHTWEIGHT_FIRST_RUN_EXPERIENCE)) {
boolean isTabbedModeActive = false;
boolean isLightweightFreActive = false;
boolean isGenericFreActive = false;
List<WeakReference<Activity>> activities = ApplicationStatus.getRunningActivities();
for (WeakReference<Activity> weakActivity : activities) {
Activity activity = weakActivity.get();
if (activity == null) {
continue;
}
if (activity instanceof ChromeTabbedActivity) {
isTabbedModeActive = true;
continue;
}
if (activity instanceof LightweightFirstRunActivity) {
isLightweightFreActive = true;
// A Generic or a new Lightweight First Run Experience will be launched
// below, so finish the old Lightweight First Run Experience.
activity.setResult(Activity.RESULT_CANCELED);
activity.finish();
continue;
}
if (activity instanceof FirstRunActivity) {
isGenericFreActive = true;
continue;
}
}
if (forTabbedMode) {
if (isTabbedModeActive || isLightweightFreActive || !showLightweightFre) {
// Lets ChromeTabbedActivity checks and launches the Generic First Run
// Experience.
launchTabbedMode(false);
finish();
return true;
}
} else if (isGenericFreActive) {
// Launch the Generic First Run Experience if it is active previously.
freIntent = FirstRunFlowSequencer.createGenericFirstRunIntent(this, TextUtils.equals(getIntent().getAction(), Intent.ACTION_MAIN));
}
}
// Add a PendingIntent so that the intent used to launch Chrome will be resent when
// first run is completed or canceled.
FirstRunFlowSequencer.addPendingIntent(this, freIntent, getIntent());
startActivity(freIntent);
} else {
Intent newIntent = new Intent(getIntent());
newIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(newIntent);
}
finish();
return true;
}
use of org.chromium.chrome.browser.ChromeTabbedActivity in project AndroidChromium by JackyAndroid.
the class IncognitoNotificationService method focusChromeIfNecessary.
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;
}
}
// 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);
}
use of org.chromium.chrome.browser.ChromeTabbedActivity in project AndroidChromium by JackyAndroid.
the class DownloadUtils method showDownloadManager.
/**
* Displays the download manager UI. Note the UI is different on tablets and on phones.
* @return Whether the UI was shown.
*/
public static boolean showDownloadManager(@Nullable Activity activity, @Nullable Tab tab) {
if (!isDownloadHomeEnabled())
return false;
// Figure out what tab was last being viewed by the user.
if (activity == null)
activity = ApplicationStatus.getLastTrackedFocusedActivity();
if (tab == null && activity instanceof ChromeTabbedActivity) {
tab = ((ChromeTabbedActivity) activity).getActivityTab();
}
Context appContext = ContextUtils.getApplicationContext();
if (DeviceFormFactor.isTablet(appContext)) {
// Download Home shows up as a tab on tablets.
LoadUrlParams params = new LoadUrlParams(UrlConstants.DOWNLOADS_URL);
if (tab == null || !tab.isInitialized()) {
// Open a new tab, which pops Chrome into the foreground.
TabDelegate delegate = new TabDelegate(false);
delegate.createNewTab(params, TabLaunchType.FROM_CHROME_UI, null);
} else {
// Download Home shows up inside an existing tab, but only if the last Activity was
// the ChromeTabbedActivity.
tab.loadUrl(params);
// Bring Chrome to the foreground, if possible.
Intent intent = Tab.createBringTabToFrontIntent(tab.getId());
if (intent != null) {
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
IntentUtils.safeStartActivity(appContext, intent);
}
}
} else {
// Download Home shows up as a new Activity on phones.
Intent intent = new Intent();
intent.setClass(appContext, DownloadActivity.class);
if (tab != null)
intent.putExtra(EXTRA_IS_OFF_THE_RECORD, tab.isIncognito());
if (activity == null) {
// Stands alone in its own task.
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
appContext.startActivity(intent);
} else {
// Sits on top of another Activity.
intent.putExtra(IntentHandler.EXTRA_PARENT_COMPONENT, activity.getComponentName());
activity.startActivity(intent);
}
}
return true;
}
use of org.chromium.chrome.browser.ChromeTabbedActivity in project AndroidChromium by JackyAndroid.
the class MultiWindowUtils method getTabbedActivityForIntent.
/**
* Determines the correct ChromeTabbedActivity class to use for an incoming intent.
* @param intent The incoming intent that is starting ChromeTabbedActivity.
* @param context The current Context, used to retrieve the ActivityManager system service.
* @return The ChromeTabbedActivity to use for the incoming intent.
*/
public Class<? extends ChromeTabbedActivity> getTabbedActivityForIntent(Intent intent, Context context) {
// ChromeTabbedActivity2 isn't running.
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.M || (mTabbedActivity2TaskRunning != null && !mTabbedActivity2TaskRunning)) {
return ChromeTabbedActivity.class;
}
// 2. If the intent has a window id set, use that.
if (intent.hasExtra(IntentHandler.EXTRA_WINDOW_ID)) {
int windowId = IntentUtils.safeGetIntExtra(intent, IntentHandler.EXTRA_WINDOW_ID, 0);
if (windowId == 1)
return ChromeTabbedActivity.class;
if (windowId == 2)
return ChromeTabbedActivity2.class;
}
// 3. If only one ChromeTabbedActivity is currently in Android recents, use it.
boolean tabbed2TaskRunning = isActivityTaskInRecents(ChromeTabbedActivity2.class.getName(), context);
// Exit early if ChromeTabbedActivity2 isn't running.
if (!tabbed2TaskRunning) {
mTabbedActivity2TaskRunning = false;
return ChromeTabbedActivity.class;
}
boolean tabbedTaskRunning = isActivityTaskInRecents(ChromeTabbedActivity.class.getName(), context);
if (!tabbedTaskRunning) {
return ChromeTabbedActivity2.class;
}
// 4. If only one of the ChromeTabbedActivity's is currently visible use it.
// e.g. ChromeTabbedActivity is docked to the top of the screen and another app is docked
// to the bottom.
// Find the activities.
Activity tabbedActivity = null;
Activity tabbedActivity2 = null;
for (WeakReference<Activity> reference : ApplicationStatus.getRunningActivities()) {
Activity activity = reference.get();
if (activity == null)
continue;
if (activity.getClass().equals(ChromeTabbedActivity.class)) {
tabbedActivity = activity;
} else if (activity.getClass().equals(ChromeTabbedActivity2.class)) {
tabbedActivity2 = activity;
}
}
// Determine if only one is visible.
boolean tabbedActivityVisible = isActivityVisible(tabbedActivity);
boolean tabbedActivity2Visible = isActivityVisible(tabbedActivity2);
if (tabbedActivityVisible ^ tabbedActivity2Visible) {
if (tabbedActivityVisible)
return ChromeTabbedActivity.class;
return ChromeTabbedActivity2.class;
}
// 5. Use the ChromeTabbedActivity that was resumed most recently if it's still running.
if (mLastResumedTabbedActivity != null) {
ChromeTabbedActivity lastResumedActivity = mLastResumedTabbedActivity.get();
if (lastResumedActivity != null) {
Class<?> lastResumedClassName = lastResumedActivity.getClass();
if (tabbedTaskRunning && lastResumedClassName.equals(ChromeTabbedActivity.class)) {
return ChromeTabbedActivity.class;
}
if (tabbed2TaskRunning && lastResumedClassName.equals(ChromeTabbedActivity2.class)) {
return ChromeTabbedActivity2.class;
}
}
}
// 6. Default to regular ChromeTabbedActivity.
return ChromeTabbedActivity.class;
}
Aggregations