Preventing a shortcut which requires permissions from being added to
homescreen
A shortcut can be added by any app as INSTALL_SHORTCUT is a normal
level permission. But the intent is actually launched by the launcher
app which can have other permission as well.
> When adding a shortcut from the broadcast, verify that the intent does
not require any permission
> When adding a shortcut using the two-step drop process, verify that
the source app also has the permission to create such a shortcut
Bug: 30778130
Change-Id: I33a391bc0af81248aaff4459aaa79d1adc77926b
(cherry picked from commit fb5096d07b)
This commit is contained in:
@@ -106,6 +106,7 @@ import com.android.launcher3.compat.UserManagerCompat;
|
||||
import com.android.launcher3.model.WidgetsModel;
|
||||
import com.android.launcher3.util.ComponentKey;
|
||||
import com.android.launcher3.util.LongArrayMap;
|
||||
import com.android.launcher3.util.PackageManagerHelper;
|
||||
import com.android.launcher3.util.TestingUtils;
|
||||
import com.android.launcher3.util.Thunk;
|
||||
import com.android.launcher3.widget.PendingAddWidgetInfo;
|
||||
@@ -191,6 +192,8 @@ public class Launcher extends Activity
|
||||
private static final String RUNTIME_STATE_PENDING_ADD_SPAN_X = "launcher.add_span_x";
|
||||
// Type: int
|
||||
private static final String RUNTIME_STATE_PENDING_ADD_SPAN_Y = "launcher.add_span_y";
|
||||
// Type: int
|
||||
private static final String RUNTIME_STATE_PENDING_ADD_COMPONENT = "launcher.add_component";
|
||||
// Type: parcelable
|
||||
private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_INFO = "launcher.add_widget_info";
|
||||
// Type: parcelable
|
||||
@@ -242,7 +245,7 @@ public class Launcher extends Activity
|
||||
private AppWidgetManagerCompat mAppWidgetManager;
|
||||
private LauncherAppWidgetHost mAppWidgetHost;
|
||||
|
||||
@Thunk ItemInfo mPendingAddInfo = new ItemInfo();
|
||||
@Thunk PendingAddItemInfo mPendingAddInfo = new PendingAddItemInfo();
|
||||
private LauncherAppWidgetProviderInfo mPendingAddWidgetInfo;
|
||||
private int mPendingAddWidgetId = -1;
|
||||
|
||||
@@ -1312,6 +1315,8 @@ public class Launcher extends Activity
|
||||
mPendingAddInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
|
||||
mPendingAddInfo.spanX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_X);
|
||||
mPendingAddInfo.spanY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y);
|
||||
mPendingAddInfo.componentName =
|
||||
savedState.getParcelable(RUNTIME_STATE_PENDING_ADD_COMPONENT);
|
||||
AppWidgetProviderInfo info = savedState.getParcelable(
|
||||
RUNTIME_STATE_PENDING_ADD_WIDGET_INFO);
|
||||
mPendingAddWidgetInfo = info == null ?
|
||||
@@ -1499,7 +1504,13 @@ public class Launcher extends Activity
|
||||
CellLayout layout = getCellLayout(container, screenId);
|
||||
|
||||
ShortcutInfo info = InstallShortcutReceiver.fromShortcutIntent(this, data);
|
||||
if (info == null) {
|
||||
if (info == null || mPendingAddInfo.componentName == null) {
|
||||
return;
|
||||
}
|
||||
if (!PackageManagerHelper.hasPermissionForActivity(
|
||||
this, info.intent, mPendingAddInfo.componentName.getPackageName())) {
|
||||
// The app is trying to add a shortcut without sufficient permissions
|
||||
Log.e(TAG, "Ignoring malicious intent " + info.intent.toUri(0));
|
||||
return;
|
||||
}
|
||||
final View view = createShortcut(info);
|
||||
@@ -1966,6 +1977,8 @@ public class Launcher extends Activity
|
||||
outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mPendingAddInfo.cellY);
|
||||
outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_X, mPendingAddInfo.spanX);
|
||||
outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y, mPendingAddInfo.spanY);
|
||||
outState.putParcelable(RUNTIME_STATE_PENDING_ADD_COMPONENT,
|
||||
mPendingAddInfo.componentName);
|
||||
outState.putParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO, mPendingAddWidgetInfo);
|
||||
outState.putInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID, mPendingAddWidgetId);
|
||||
}
|
||||
@@ -2198,6 +2211,7 @@ public class Launcher extends Activity
|
||||
mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1;
|
||||
mPendingAddInfo.minSpanX = mPendingAddInfo.minSpanY = 1;
|
||||
mPendingAddInfo.dropPos = null;
|
||||
mPendingAddInfo.componentName = null;
|
||||
}
|
||||
|
||||
void addAppWidgetFromDropImpl(final int appWidgetId, final ItemInfo info, final
|
||||
@@ -2273,6 +2287,7 @@ public class Launcher extends Activity
|
||||
mPendingAddInfo.container = container;
|
||||
mPendingAddInfo.screenId = screenId;
|
||||
mPendingAddInfo.dropPos = null;
|
||||
mPendingAddInfo.componentName = componentName;
|
||||
|
||||
if (cell != null) {
|
||||
mPendingAddInfo.cellX = cell[0];
|
||||
|
||||
Reference in New Issue
Block a user