OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.chrome.browser.multiwindow; | 5 package org.chromium.chrome.browser.multiwindow; |
6 | 6 |
7 import android.annotation.TargetApi; | 7 import android.annotation.TargetApi; |
8 import android.app.Activity; | 8 import android.app.Activity; |
9 import android.app.ActivityManager; | 9 import android.app.ActivityManager; |
10 import android.app.ActivityManager.AppTask; | 10 import android.app.ActivityManager.AppTask; |
(...skipping 13 matching lines...) Expand all Loading... |
24 import org.chromium.chrome.browser.IntentHandler; | 24 import org.chromium.chrome.browser.IntentHandler; |
25 import org.chromium.chrome.browser.document.ChromeLauncherActivity; | 25 import org.chromium.chrome.browser.document.ChromeLauncherActivity; |
26 import org.chromium.chrome.browser.util.IntentUtils; | 26 import org.chromium.chrome.browser.util.IntentUtils; |
27 | 27 |
28 import java.lang.ref.WeakReference; | 28 import java.lang.ref.WeakReference; |
29 import java.lang.reflect.InvocationTargetException; | 29 import java.lang.reflect.InvocationTargetException; |
30 import java.lang.reflect.Method; | 30 import java.lang.reflect.Method; |
31 import java.util.List; | 31 import java.util.List; |
32 import java.util.concurrent.atomic.AtomicReference; | 32 import java.util.concurrent.atomic.AtomicReference; |
33 | 33 |
| 34 import javax.annotation.Nullable; |
| 35 |
34 /** | 36 /** |
35 * Utilities for detecting multi-window/multi-instance support. | 37 * Utilities for detecting multi-window/multi-instance support. |
36 * | 38 * |
37 * Thread-safe: This class may be accessed from any thread. | 39 * Thread-safe: This class may be accessed from any thread. |
38 */ | 40 */ |
39 public class MultiWindowUtils implements ActivityStateListener { | 41 public class MultiWindowUtils implements ActivityStateListener { |
40 | 42 |
41 // TODO(twellington): replace this with Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT
once we're building | 43 // TODO(twellington): replace this with Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT
once we're building |
42 // against N. | 44 // against N. |
43 public static final int FLAG_ACTIVITY_LAUNCH_ADJACENT = 0x00001000; | 45 public static final int FLAG_ACTIVITY_LAUNCH_ADJACENT = 0x00001000; |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 new WeakReference<ChromeTabbedActivity>((ChromeTabbedActivit
y) activity); | 151 new WeakReference<ChromeTabbedActivity>((ChromeTabbedActivit
y) activity); |
150 } | 152 } |
151 } | 153 } |
152 | 154 |
153 /** | 155 /** |
154 * Determines the correct ChromeTabbedActivity class to use for an incoming
intent. | 156 * Determines the correct ChromeTabbedActivity class to use for an incoming
intent. |
155 * @param intent The incoming intent that is starting ChromeTabbedActivity. | 157 * @param intent The incoming intent that is starting ChromeTabbedActivity. |
156 * @param context The current Context, used to retrieve the ActivityManager
system service. | 158 * @param context The current Context, used to retrieve the ActivityManager
system service. |
157 * @return The ChromeTabbedActivity to use for the incoming intent. | 159 * @return The ChromeTabbedActivity to use for the incoming intent. |
158 */ | 160 */ |
159 public Class<? extends ChromeTabbedActivity> getTabbedActivityForIntent(Inte
nt intent, | 161 public Class<? extends ChromeTabbedActivity> getTabbedActivityForIntent( |
160 Context context) { | 162 @Nullable Intent intent, Context context) { |
161 // 1. Exit early if the build version doesn't support Android N+ multi-w
indow mode or | 163 // 1. Exit early if the build version doesn't support Android N+ multi-w
indow mode or |
162 // ChromeTabbedActivity2 isn't running. | 164 // ChromeTabbedActivity2 isn't running. |
163 if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.M | 165 if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.M |
164 || (mTabbedActivity2TaskRunning != null && !mTabbedActivity2Task
Running)) { | 166 || (mTabbedActivity2TaskRunning != null && !mTabbedActivity2Task
Running)) { |
165 return ChromeTabbedActivity.class; | 167 return ChromeTabbedActivity.class; |
166 } | 168 } |
167 | 169 |
168 // 2. If the intent has a window id set, use that. | 170 // 2. If the intent has a window id set, use that. |
169 if (intent.hasExtra(IntentHandler.EXTRA_WINDOW_ID)) { | 171 if (intent != null && IntentUtils.safeHasExtra(intent, IntentHandler.EXT
RA_WINDOW_ID)) { |
170 int windowId = IntentUtils.safeGetIntExtra(intent, IntentHandler.EXT
RA_WINDOW_ID, 0); | 172 int windowId = IntentUtils.safeGetIntExtra(intent, IntentHandler.EXT
RA_WINDOW_ID, 0); |
171 if (windowId == 1) return ChromeTabbedActivity.class; | 173 if (windowId == 1) return ChromeTabbedActivity.class; |
172 if (windowId == 2) return ChromeTabbedActivity2.class; | 174 if (windowId == 2) return ChromeTabbedActivity2.class; |
173 } | 175 } |
174 | 176 |
175 // 3. If only one ChromeTabbedActivity is currently in Android recents,
use it. | 177 // 3. If only one ChromeTabbedActivity is currently in Android recents,
use it. |
176 boolean tabbed2TaskRunning = isActivityTaskInRecents( | 178 boolean tabbed2TaskRunning = isActivityTaskInRecents( |
177 ChromeTabbedActivity2.class.getName(), context); | 179 ChromeTabbedActivity2.class.getName(), context); |
178 | 180 |
179 // Exit early if ChromeTabbedActivity2 isn't running. | 181 // Exit early if ChromeTabbedActivity2 isn't running. |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 if (isLegacyMultiWindow(activity)) { | 308 if (isLegacyMultiWindow(activity)) { |
307 if (TextUtils.equals(ChromeTabbedActivity.class.getName(), | 309 if (TextUtils.equals(ChromeTabbedActivity.class.getName(), |
308 intent.getComponent().getClassName())) { | 310 intent.getComponent().getClassName())) { |
309 intent.setClassName(activity, MultiInstanceChromeTabbedActivity.
class.getName()); | 311 intent.setClassName(activity, MultiInstanceChromeTabbedActivity.
class.getName()); |
310 } | 312 } |
311 intent.setFlags(intent.getFlags() | 313 intent.setFlags(intent.getFlags() |
312 & ~(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NEW
_DOCUMENT)); | 314 & ~(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NEW
_DOCUMENT)); |
313 } | 315 } |
314 } | 316 } |
315 } | 317 } |
OLD | NEW |