Merge "Backport Prevent shortcut info package name spoofing" into oc-dev
am: c6dbcc137e
Change-Id: Ib3becad73fadba2be82e44bc6fb4afc3c1921a6a
This commit is contained in:
@@ -131,6 +131,7 @@ import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Predicate;
|
||||
@@ -1531,6 +1532,24 @@ public class ShortcutService extends IShortcutService.Stub {
|
||||
"Ephemeral apps can't use ShortcutManager");
|
||||
}
|
||||
|
||||
private void verifyShortcutInfoPackage(String callerPackage, ShortcutInfo si) {
|
||||
if (si == null) {
|
||||
return;
|
||||
}
|
||||
if (!Objects.equals(callerPackage, si.getPackage())) {
|
||||
android.util.EventLog.writeEvent(0x534e4554, "109824443", -1, "");
|
||||
throw new SecurityException("Shortcut package name mismatch");
|
||||
}
|
||||
}
|
||||
|
||||
private void verifyShortcutInfoPackages(
|
||||
String callerPackage, List<ShortcutInfo> list) {
|
||||
final int size = list.size();
|
||||
for (int i = 0; i < size; i++) {
|
||||
verifyShortcutInfoPackage(callerPackage, list.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
// Overridden in unit tests to execute r synchronously.
|
||||
void injectPostToHandler(Runnable r) {
|
||||
mHandler.post(r);
|
||||
@@ -1678,6 +1697,7 @@ public class ShortcutService extends IShortcutService.Stub {
|
||||
verifyCaller(packageName, userId);
|
||||
|
||||
final List<ShortcutInfo> newShortcuts = (List<ShortcutInfo>) shortcutInfoList.getList();
|
||||
verifyShortcutInfoPackages(packageName, newShortcuts);
|
||||
final int size = newShortcuts.size();
|
||||
|
||||
synchronized (mLock) {
|
||||
@@ -1729,6 +1749,7 @@ public class ShortcutService extends IShortcutService.Stub {
|
||||
verifyCaller(packageName, userId);
|
||||
|
||||
final List<ShortcutInfo> newShortcuts = (List<ShortcutInfo>) shortcutInfoList.getList();
|
||||
verifyShortcutInfoPackages(packageName, newShortcuts);
|
||||
final int size = newShortcuts.size();
|
||||
|
||||
synchronized (mLock) {
|
||||
@@ -1809,6 +1830,7 @@ public class ShortcutService extends IShortcutService.Stub {
|
||||
verifyCaller(packageName, userId);
|
||||
|
||||
final List<ShortcutInfo> newShortcuts = (List<ShortcutInfo>) shortcutInfoList.getList();
|
||||
verifyShortcutInfoPackages(packageName, newShortcuts);
|
||||
final int size = newShortcuts.size();
|
||||
|
||||
synchronized (mLock) {
|
||||
@@ -1868,6 +1890,7 @@ public class ShortcutService extends IShortcutService.Stub {
|
||||
Preconditions.checkNotNull(shortcut);
|
||||
Preconditions.checkArgument(shortcut.isEnabled(), "Shortcut must be enabled");
|
||||
verifyCaller(packageName, userId);
|
||||
verifyShortcutInfoPackage(packageName, shortcut);
|
||||
|
||||
final Intent ret;
|
||||
synchronized (mLock) {
|
||||
@@ -1889,6 +1912,7 @@ public class ShortcutService extends IShortcutService.Stub {
|
||||
private boolean requestPinItem(String packageName, int userId, ShortcutInfo shortcut,
|
||||
AppWidgetProviderInfo appWidget, Bundle extras, IntentSender resultIntent) {
|
||||
verifyCaller(packageName, userId);
|
||||
verifyShortcutInfoPackage(packageName, shortcut);
|
||||
|
||||
final boolean ret;
|
||||
synchronized (mLock) {
|
||||
|
||||
Reference in New Issue
Block a user