Merge "Explicitly allow access to share targets by package" into tm-dev
This commit is contained in:
@@ -105,6 +105,7 @@ import android.util.TypedXmlSerializer;
|
|||||||
import android.util.Xml;
|
import android.util.Xml;
|
||||||
import android.view.IWindowManager;
|
import android.view.IWindowManager;
|
||||||
|
|
||||||
|
import com.android.internal.R;
|
||||||
import com.android.internal.annotations.GuardedBy;
|
import com.android.internal.annotations.GuardedBy;
|
||||||
import com.android.internal.annotations.VisibleForTesting;
|
import com.android.internal.annotations.VisibleForTesting;
|
||||||
import com.android.internal.config.sysui.SystemUiDeviceConfigFlags;
|
import com.android.internal.config.sysui.SystemUiDeviceConfigFlags;
|
||||||
@@ -455,6 +456,8 @@ public class ShortcutService extends IShortcutService.Stub {
|
|||||||
|
|
||||||
private final boolean mIsAppSearchEnabled;
|
private final boolean mIsAppSearchEnabled;
|
||||||
|
|
||||||
|
private ComponentName mChooserActivity;
|
||||||
|
|
||||||
static class InvalidFileFormatException extends Exception {
|
static class InvalidFileFormatException extends Exception {
|
||||||
public InvalidFileFormatException(String message, Throwable cause) {
|
public InvalidFileFormatException(String message, Throwable cause) {
|
||||||
super(message, cause);
|
super(message, cause);
|
||||||
@@ -1646,6 +1649,26 @@ public class ShortcutService extends IShortcutService.Stub {
|
|||||||
return callingUid == Process.SHELL_UID || callingUid == Process.ROOT_UID;
|
return callingUid == Process.SHELL_UID || callingUid == Process.ROOT_UID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
ComponentName injectChooserActivity() {
|
||||||
|
if (mChooserActivity == null) {
|
||||||
|
mChooserActivity = ComponentName.unflattenFromString(
|
||||||
|
mContext.getResources().getString(R.string.config_chooserActivity));
|
||||||
|
}
|
||||||
|
return mChooserActivity;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isCallerChooserActivity() {
|
||||||
|
// TODO(b/228975502): Migrate this check to a proper permission or role check
|
||||||
|
final int callingUid = injectBinderCallingUid();
|
||||||
|
ComponentName systemChooser = injectChooserActivity();
|
||||||
|
if (systemChooser == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
int uid = injectGetPackageUid(systemChooser.getPackageName(), UserHandle.USER_SYSTEM);
|
||||||
|
return uid == callingUid;
|
||||||
|
}
|
||||||
|
|
||||||
private void enforceSystemOrShell() {
|
private void enforceSystemOrShell() {
|
||||||
if (!(isCallerSystem() || isCallerShell())) {
|
if (!(isCallerSystem() || isCallerShell())) {
|
||||||
throw new SecurityException("Caller must be system or shell");
|
throw new SecurityException("Caller must be system or shell");
|
||||||
@@ -2525,7 +2548,9 @@ public class ShortcutService extends IShortcutService.Stub {
|
|||||||
IntentFilter filter, @UserIdInt int userId) {
|
IntentFilter filter, @UserIdInt int userId) {
|
||||||
Preconditions.checkStringNotEmpty(packageName, "packageName");
|
Preconditions.checkStringNotEmpty(packageName, "packageName");
|
||||||
Objects.requireNonNull(filter, "intentFilter");
|
Objects.requireNonNull(filter, "intentFilter");
|
||||||
verifyCaller(packageName, userId);
|
if (!isCallerChooserActivity()) {
|
||||||
|
verifyCaller(packageName, userId);
|
||||||
|
}
|
||||||
enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_APP_PREDICTIONS,
|
enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_APP_PREDICTIONS,
|
||||||
"getShareTargets");
|
"getShareTargets");
|
||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
|
|||||||
@@ -537,6 +537,11 @@ public abstract class BaseShortcutManagerTest extends InstrumentationTestCase {
|
|||||||
return mInjectCheckAccessShortcutsPermission;
|
return mInjectCheckAccessShortcutsPermission;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
ComponentName injectChooserActivity() {
|
||||||
|
return mInjectedChooserActivity;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void wtf(String message, Throwable th) {
|
void wtf(String message, Throwable th) {
|
||||||
// During tests, WTF is fatal.
|
// During tests, WTF is fatal.
|
||||||
@@ -678,6 +683,7 @@ public abstract class BaseShortcutManagerTest extends InstrumentationTestCase {
|
|||||||
|
|
||||||
protected int mInjectedCallingUid;
|
protected int mInjectedCallingUid;
|
||||||
protected String mInjectedClientPackage;
|
protected String mInjectedClientPackage;
|
||||||
|
protected ComponentName mInjectedChooserActivity;
|
||||||
|
|
||||||
protected Map<String, PackageInfo> mInjectedPackages;
|
protected Map<String, PackageInfo> mInjectedPackages;
|
||||||
|
|
||||||
@@ -723,6 +729,9 @@ public abstract class BaseShortcutManagerTest extends InstrumentationTestCase {
|
|||||||
protected static final String LAUNCHER_4 = "com.android.launcher.4";
|
protected static final String LAUNCHER_4 = "com.android.launcher.4";
|
||||||
protected static final int LAUNCHER_UID_4 = 10014;
|
protected static final int LAUNCHER_UID_4 = 10014;
|
||||||
|
|
||||||
|
protected static final String CHOOSER_ACTIVITY_PACKAGE = "com.android.intentresolver";
|
||||||
|
protected static final int CHOOSER_ACTIVITY_UID = 10015;
|
||||||
|
|
||||||
protected static final int USER_0 = UserHandle.USER_SYSTEM;
|
protected static final int USER_0 = UserHandle.USER_SYSTEM;
|
||||||
protected static final int USER_10 = 10;
|
protected static final int USER_10 = 10;
|
||||||
protected static final int USER_11 = 11;
|
protected static final int USER_11 = 11;
|
||||||
|
|||||||
@@ -6901,6 +6901,9 @@ public class ShortcutManagerTest1 extends BaseShortcutManagerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testGetShareTargets_permission() {
|
public void testGetShareTargets_permission() {
|
||||||
|
addPackage(CHOOSER_ACTIVITY_PACKAGE, CHOOSER_ACTIVITY_UID, 10, "sig1");
|
||||||
|
mInjectedChooserActivity =
|
||||||
|
ComponentName.createRelative(CHOOSER_ACTIVITY_PACKAGE, ".ChooserActivity");
|
||||||
IntentFilter filter = new IntentFilter();
|
IntentFilter filter = new IntentFilter();
|
||||||
|
|
||||||
assertExpectException(SecurityException.class, "Missing permission", () ->
|
assertExpectException(SecurityException.class, "Missing permission", () ->
|
||||||
@@ -6909,6 +6912,11 @@ public class ShortcutManagerTest1 extends BaseShortcutManagerTest {
|
|||||||
// Has permission, now it should pass.
|
// Has permission, now it should pass.
|
||||||
mCallerPermissions.add(permission.MANAGE_APP_PREDICTIONS);
|
mCallerPermissions.add(permission.MANAGE_APP_PREDICTIONS);
|
||||||
mManager.getShareTargets(filter);
|
mManager.getShareTargets(filter);
|
||||||
|
|
||||||
|
runWithCaller(CHOOSER_ACTIVITY_PACKAGE, USER_0, () -> {
|
||||||
|
// Access is allowed when called from the configured system ChooserActivity
|
||||||
|
mManager.getShareTargets(filter);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testHasShareTargets_permission() {
|
public void testHasShareTargets_permission() {
|
||||||
|
|||||||
Reference in New Issue
Block a user