Merge "Fix crash in IntentForwarderActivity" into rvc-dev am: f9a02be500 am: 25d9d08a8a am: c691919a5e
Change-Id: I3a4c84349eaa45fe2758a75278006d552dd0e04a
This commit is contained in:
@@ -50,6 +50,9 @@ import java.util.Arrays;
|
|||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is used in conjunction with
|
* This is used in conjunction with
|
||||||
@@ -74,11 +77,13 @@ public class IntentForwarderActivity extends Activity {
|
|||||||
private Injector mInjector;
|
private Injector mInjector;
|
||||||
|
|
||||||
private MetricsLogger mMetricsLogger;
|
private MetricsLogger mMetricsLogger;
|
||||||
|
protected ExecutorService mExecutorService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
mInjector = createInjector();
|
mInjector = createInjector();
|
||||||
|
mExecutorService = Executors.newSingleThreadExecutor();
|
||||||
|
|
||||||
Intent intentReceived = getIntent();
|
Intent intentReceived = getIntent();
|
||||||
String className = intentReceived.getComponent().getClassName();
|
String className = intentReceived.getComponent().getClassName();
|
||||||
@@ -118,30 +123,9 @@ public class IntentForwarderActivity extends Activity {
|
|||||||
mInjector.getIPackageManager(), getContentResolver());
|
mInjector.getIPackageManager(), getContentResolver());
|
||||||
if (newIntent != null) {
|
if (newIntent != null) {
|
||||||
newIntent.prepareToLeaveUser(callingUserId);
|
newIntent.prepareToLeaveUser(callingUserId);
|
||||||
|
maybeShowDisclosureAsync(intentReceived, newIntent, targetUserId, userMessageId);
|
||||||
final ResolveInfo ri = mInjector.resolveActivityAsUser(newIntent, MATCH_DEFAULT_ONLY,
|
CompletableFuture.runAsync(() -> startActivityAsCaller(
|
||||||
targetUserId);
|
newIntent, targetUserId), mExecutorService);
|
||||||
try {
|
|
||||||
startActivityAsCaller(newIntent, null, null, false, targetUserId);
|
|
||||||
} catch (RuntimeException e) {
|
|
||||||
int launchedFromUid = -1;
|
|
||||||
String launchedFromPackage = "?";
|
|
||||||
try {
|
|
||||||
launchedFromUid = ActivityTaskManager.getService().getLaunchedFromUid(
|
|
||||||
getActivityToken());
|
|
||||||
launchedFromPackage = ActivityTaskManager.getService().getLaunchedFromPackage(
|
|
||||||
getActivityToken());
|
|
||||||
} catch (RemoteException ignored) {
|
|
||||||
}
|
|
||||||
|
|
||||||
Slog.wtf(TAG, "Unable to launch as UID " + launchedFromUid + " package "
|
|
||||||
+ launchedFromPackage + ", while running in "
|
|
||||||
+ ActivityThread.currentProcessName(), e);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (shouldShowDisclosure(ri, intentReceived)) {
|
|
||||||
mInjector.showToast(userMessageId, Toast.LENGTH_LONG);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
Slog.wtf(TAG, "the intent: " + intentReceived + " cannot be forwarded from user "
|
Slog.wtf(TAG, "the intent: " + intentReceived + " cannot be forwarded from user "
|
||||||
+ callingUserId + " to user " + targetUserId);
|
+ callingUserId + " to user " + targetUserId);
|
||||||
@@ -149,6 +133,44 @@ public class IntentForwarderActivity extends Activity {
|
|||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void maybeShowDisclosureAsync(
|
||||||
|
Intent intentReceived, Intent newIntent, int userId, int messageId) {
|
||||||
|
final CompletableFuture<ResolveInfo> resolveInfoFuture =
|
||||||
|
mInjector.resolveActivityAsUser(newIntent, MATCH_DEFAULT_ONLY, userId);
|
||||||
|
resolveInfoFuture.thenAcceptAsync(ri -> {
|
||||||
|
if (shouldShowDisclosure(ri, intentReceived)) {
|
||||||
|
mInjector.showToast(messageId, Toast.LENGTH_LONG);
|
||||||
|
}
|
||||||
|
}, getApplicationContext().getMainExecutor());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void startActivityAsCaller(Intent newIntent, int userId) {
|
||||||
|
try {
|
||||||
|
startActivityAsCaller(
|
||||||
|
newIntent,
|
||||||
|
/* options= */ null,
|
||||||
|
/* permissionToken= */ null,
|
||||||
|
/* ignoreTargetSecurity= */ false,
|
||||||
|
userId);
|
||||||
|
} catch (RuntimeException e) {
|
||||||
|
int launchedFromUid = -1;
|
||||||
|
String launchedFromPackage = "?";
|
||||||
|
try {
|
||||||
|
launchedFromUid = ActivityTaskManager.getService().getLaunchedFromUid(
|
||||||
|
getActivityToken());
|
||||||
|
launchedFromPackage = ActivityTaskManager.getService()
|
||||||
|
.getLaunchedFromPackage(getActivityToken());
|
||||||
|
} catch (RemoteException ignored) {
|
||||||
|
}
|
||||||
|
|
||||||
|
Slog.wtf(TAG, "Unable to launch as UID " + launchedFromUid + " package "
|
||||||
|
+ launchedFromPackage + ", while running in "
|
||||||
|
+ ActivityThread.currentProcessName(), e);
|
||||||
|
} finally {
|
||||||
|
mExecutorService.shutdown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void launchChooserActivityWithCorrectTab(Intent intentReceived, String className) {
|
private void launchChooserActivityWithCorrectTab(Intent intentReceived, String className) {
|
||||||
// When showing the sharesheet, instead of forwarding to the other profile,
|
// When showing the sharesheet, instead of forwarding to the other profile,
|
||||||
// we launch the sharesheet in the current user and select the other tab.
|
// we launch the sharesheet in the current user and select the other tab.
|
||||||
@@ -322,8 +344,11 @@ public class IntentForwarderActivity extends Activity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResolveInfo resolveActivityAsUser(Intent intent, int flags, int userId) {
|
@Nullable
|
||||||
return getPackageManager().resolveActivityAsUser(intent, flags, userId);
|
public CompletableFuture<ResolveInfo> resolveActivityAsUser(
|
||||||
|
Intent intent, int flags, int userId) {
|
||||||
|
return CompletableFuture.supplyAsync(
|
||||||
|
() -> getPackageManager().resolveActivityAsUser(intent, flags, userId));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -339,7 +364,7 @@ public class IntentForwarderActivity extends Activity {
|
|||||||
|
|
||||||
PackageManager getPackageManager();
|
PackageManager getPackageManager();
|
||||||
|
|
||||||
ResolveInfo resolveActivityAsUser(Intent intent, int flags, int userId);
|
CompletableFuture<ResolveInfo> resolveActivityAsUser(Intent intent, int flags, int userId);
|
||||||
|
|
||||||
void showToast(@StringRes int messageId, int duration);
|
void showToast(@StringRes int messageId, int duration);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,6 +68,8 @@ import org.mockito.MockitoAnnotations;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
@RunWith(AndroidJUnit4.class)
|
@RunWith(AndroidJUnit4.class)
|
||||||
public class IntentForwarderActivityTest {
|
public class IntentForwarderActivityTest {
|
||||||
@@ -633,6 +635,11 @@ public class IntentForwarderActivityTest {
|
|||||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
getIntent().setComponent(sComponentName);
|
getIntent().setComponent(sComponentName);
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
try {
|
||||||
|
mExecutorService.awaitTermination(/* timeout= */ 30, TimeUnit.SECONDS);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -671,7 +678,8 @@ public class IntentForwarderActivityTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResolveInfo resolveActivityAsUser(Intent intent, int flags, int userId) {
|
public CompletableFuture<ResolveInfo> resolveActivityAsUser(
|
||||||
|
Intent intent, int flags, int userId) {
|
||||||
ActivityInfo activityInfo = new ActivityInfo();
|
ActivityInfo activityInfo = new ActivityInfo();
|
||||||
activityInfo.packageName = sPackageName;
|
activityInfo.packageName = sPackageName;
|
||||||
activityInfo.name = sActivityName;
|
activityInfo.name = sActivityName;
|
||||||
@@ -680,7 +688,7 @@ public class IntentForwarderActivityTest {
|
|||||||
ResolveInfo resolveInfo = new ResolveInfo();
|
ResolveInfo resolveInfo = new ResolveInfo();
|
||||||
resolveInfo.activityInfo = activityInfo;
|
resolveInfo.activityInfo = activityInfo;
|
||||||
|
|
||||||
return resolveInfo;
|
return CompletableFuture.completedFuture(resolveInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user