mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-02-19 10:48:19 +00:00
Fix launcher crash when trying to open work profile promise icon.
Bug: 138609751 Change-Id: Ifb1c4628ce6307a19a2bb696e4771d5cd5810a90
This commit is contained in:
@@ -25,9 +25,15 @@ import static com.android.launcher3.Launcher.REQUEST_RECONFIGURE_APPWIDGET;
|
||||
import static com.android.launcher3.model.AppLaunchTracker.CONTAINER_ALL_APPS;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.LauncherApps;
|
||||
import android.content.pm.PackageInstaller.SessionInfo;
|
||||
import android.os.Process;
|
||||
import android.os.UserHandle;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.Toast;
|
||||
@@ -43,11 +49,12 @@ import com.android.launcher3.LauncherAppWidgetInfo;
|
||||
import com.android.launcher3.LauncherAppWidgetProviderInfo;
|
||||
import com.android.launcher3.PromiseAppInfo;
|
||||
import com.android.launcher3.R;
|
||||
import com.android.launcher3.Utilities;
|
||||
import com.android.launcher3.WorkspaceItemInfo;
|
||||
import com.android.launcher3.compat.AppWidgetManagerCompat;
|
||||
import com.android.launcher3.compat.PackageInstallerCompat;
|
||||
import com.android.launcher3.folder.Folder;
|
||||
import com.android.launcher3.folder.FolderIcon;
|
||||
import com.android.launcher3.testing.TestProtocol;
|
||||
import com.android.launcher3.util.PackageManagerHelper;
|
||||
import com.android.launcher3.views.FloatingIconView;
|
||||
import com.android.launcher3.widget.PendingAppWidgetHostView;
|
||||
@@ -58,6 +65,8 @@ import com.android.launcher3.widget.WidgetAddFlowHandler;
|
||||
*/
|
||||
public class ItemClickHandler {
|
||||
|
||||
private static final String TAG = ItemClickHandler.class.getSimpleName();
|
||||
|
||||
/**
|
||||
* Instance used for click handling on items
|
||||
*/
|
||||
@@ -146,6 +155,8 @@ public class ItemClickHandler {
|
||||
startMarketIntentForPackage(v, launcher, packageName);
|
||||
return;
|
||||
}
|
||||
UserHandle user = v.getTag() instanceof ItemInfo
|
||||
? ((ItemInfo) v.getTag()).user : Process.myUserHandle();
|
||||
new AlertDialog.Builder(launcher)
|
||||
.setTitle(R.string.abandoned_promises_title)
|
||||
.setMessage(R.string.abandoned_promise_explanation)
|
||||
@@ -153,12 +164,28 @@ public class ItemClickHandler {
|
||||
(d, i) -> startMarketIntentForPackage(v, launcher, packageName))
|
||||
.setNeutralButton(R.string.abandoned_clean_this,
|
||||
(d, i) -> launcher.getWorkspace()
|
||||
.removeAbandonedPromise(packageName, Process.myUserHandle()))
|
||||
.removeAbandonedPromise(packageName, user))
|
||||
.create().show();
|
||||
}
|
||||
|
||||
private static void startMarketIntentForPackage(View v, Launcher launcher, String packageName) {
|
||||
ItemInfo item = (ItemInfo) v.getTag();
|
||||
if (Utilities.ATLEAST_Q) {
|
||||
PackageInstallerCompat pkgInstaller = PackageInstallerCompat.getInstance(launcher);
|
||||
SessionInfo sessionInfo = pkgInstaller.getActiveSessionInfo(item.user, packageName);
|
||||
if (sessionInfo != null) {
|
||||
LauncherApps launcherApps = launcher.getSystemService(LauncherApps.class);
|
||||
try {
|
||||
launcherApps.startPackageInstallerSessionDetailsActivity(sessionInfo, null,
|
||||
launcher.getActivityLaunchOptionsAsBundle(v));
|
||||
return;
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "Unable to launch market intent for package=" + packageName, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback to using custom market intent.
|
||||
Intent intent = new PackageManagerHelper(launcher).getMarketIntent(packageName);
|
||||
launcher.startActivitySafely(v, intent, item, null);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user