Merge "No disclaimer when switching profile for system SMS and dialer apps." into pi-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
a7a496f3a1
@@ -16,14 +16,21 @@
|
||||
|
||||
package com.android.internal.app;
|
||||
|
||||
import static android.content.pm.PackageManager.MATCH_DEFAULT_ONLY;
|
||||
|
||||
import android.annotation.Nullable;
|
||||
import android.annotation.StringRes;
|
||||
import android.app.Activity;
|
||||
import android.app.ActivityManager;
|
||||
import android.app.ActivityThread;
|
||||
import android.app.AppGlobals;
|
||||
import android.app.admin.DevicePolicyManager;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.IPackageManager;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.content.pm.UserInfo;
|
||||
import android.os.Bundle;
|
||||
import android.os.RemoteException;
|
||||
@@ -31,12 +38,11 @@ import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.util.Slog;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
import static android.content.pm.PackageManager.MATCH_DEFAULT_ONLY;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* This is used in conjunction with
|
||||
@@ -44,7 +50,6 @@ import static android.content.pm.PackageManager.MATCH_DEFAULT_ONLY;
|
||||
* be passed in and out of a managed profile.
|
||||
*/
|
||||
public class IntentForwarderActivity extends Activity {
|
||||
|
||||
public static String TAG = "IntentForwarderActivity";
|
||||
|
||||
public static String FORWARD_INTENT_TO_PARENT
|
||||
@@ -53,6 +58,9 @@ public class IntentForwarderActivity extends Activity {
|
||||
public static String FORWARD_INTENT_TO_MANAGED_PROFILE
|
||||
= "com.android.internal.app.ForwardIntentToManagedProfile";
|
||||
|
||||
private static final Set<String> ALLOWED_TEXT_MESSAGE_SCHEME
|
||||
= new HashSet<>(Arrays.asList("sms", "smsto", "mms", "mmsto"));
|
||||
|
||||
private Injector mInjector;
|
||||
|
||||
@Override
|
||||
@@ -93,19 +101,8 @@ public class IntentForwarderActivity extends Activity {
|
||||
newIntent.prepareToLeaveUser(callingUserId);
|
||||
}
|
||||
|
||||
final android.content.pm.ResolveInfo ri =
|
||||
mInjector.getPackageManager().resolveActivityAsUser(
|
||||
newIntent,
|
||||
MATCH_DEFAULT_ONLY,
|
||||
targetUserId);
|
||||
|
||||
// Don't show the disclosure if next activity is ResolverActivity or ChooserActivity
|
||||
// as those will already have shown work / personal as neccesary etc.
|
||||
final boolean shouldShowDisclosure = ri == null || ri.activityInfo == null ||
|
||||
!"android".equals(ri.activityInfo.packageName) ||
|
||||
!(ResolverActivity.class.getName().equals(ri.activityInfo.name)
|
||||
|| ChooserActivity.class.getName().equals(ri.activityInfo.name));
|
||||
|
||||
final ResolveInfo ri = mInjector.resolveActivityAsUser(newIntent, MATCH_DEFAULT_ONLY,
|
||||
targetUserId);
|
||||
try {
|
||||
startActivityAsCaller(newIntent, null, false, targetUserId);
|
||||
} catch (RuntimeException e) {
|
||||
@@ -124,8 +121,8 @@ public class IntentForwarderActivity extends Activity {
|
||||
+ ActivityThread.currentProcessName(), e);
|
||||
}
|
||||
|
||||
if (shouldShowDisclosure) {
|
||||
Toast.makeText(this, getString(userMessageId), Toast.LENGTH_LONG).show();
|
||||
if (shouldShowDisclosure(ri, intentReceived)) {
|
||||
mInjector.showToast(userMessageId, Toast.LENGTH_LONG);
|
||||
}
|
||||
} else {
|
||||
Slog.wtf(TAG, "the intent: " + intentReceived + " cannot be forwarded from user "
|
||||
@@ -134,6 +131,35 @@ public class IntentForwarderActivity extends Activity {
|
||||
finish();
|
||||
}
|
||||
|
||||
private boolean shouldShowDisclosure(@Nullable ResolveInfo ri, Intent intent) {
|
||||
if (ri == null || ri.activityInfo == null) {
|
||||
return true;
|
||||
}
|
||||
if (ri.activityInfo.applicationInfo.isSystemApp()
|
||||
&& (isDialerIntent(intent) || isTextMessageIntent(intent))) {
|
||||
return false;
|
||||
}
|
||||
return !isTargetResolverOrChooserActivity(ri.activityInfo);
|
||||
}
|
||||
|
||||
private boolean isTextMessageIntent(Intent intent) {
|
||||
return Intent.ACTION_SENDTO.equals(intent.getAction()) && intent.getData() != null
|
||||
&& ALLOWED_TEXT_MESSAGE_SCHEME.contains(intent.getData().getScheme());
|
||||
}
|
||||
|
||||
private boolean isDialerIntent(Intent intent) {
|
||||
return Intent.ACTION_DIAL.equals(intent.getAction())
|
||||
|| Intent.ACTION_CALL.equals(intent.getAction());
|
||||
}
|
||||
|
||||
private boolean isTargetResolverOrChooserActivity(ActivityInfo activityInfo) {
|
||||
if (!"android".equals(activityInfo.packageName)) {
|
||||
return false;
|
||||
}
|
||||
return ResolverActivity.class.getName().equals(activityInfo.name)
|
||||
|| ChooserActivity.class.getName().equals(activityInfo.name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the intent can be forwarded to target user. Return the intent used for
|
||||
* forwarding if it can be forwarded, {@code null} otherwise.
|
||||
@@ -241,6 +267,16 @@ public class IntentForwarderActivity extends Activity {
|
||||
public PackageManager getPackageManager() {
|
||||
return IntentForwarderActivity.this.getPackageManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResolveInfo resolveActivityAsUser(Intent intent, int flags, int userId) {
|
||||
return getPackageManager().resolveActivityAsUser(intent, flags, userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showToast(int messageId, int duration) {
|
||||
Toast.makeText(IntentForwarderActivity.this, getString(messageId), duration).show();
|
||||
}
|
||||
}
|
||||
|
||||
public interface Injector {
|
||||
@@ -249,5 +285,9 @@ public class IntentForwarderActivity extends Activity {
|
||||
UserManager getUserManager();
|
||||
|
||||
PackageManager getPackageManager();
|
||||
|
||||
ResolveInfo resolveActivityAsUser(Intent intent, int flags, int userId);
|
||||
|
||||
void showToast(@StringRes int messageId, int duration);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user