Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 369212ae authored by Sunny Goyal's avatar Sunny Goyal
Browse files

Adding a utility class to listen for app launches

Change-Id: I62e82a6e04b7101773d98c6e7aec574facd053fe
parent 4397d8d5
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -70,6 +70,7 @@
    <string name="instant_app_resolver_class" translatable="false"></string>
    <string name="main_process_initializer_class" translatable="false"></string>
    <string name="system_shortcut_factory_class" translatable="false"></string>
    <string name="app_launch_tracker_class" translatable="false"></string>

    <!-- Package name of the default wallpaper picker. -->
    <string name="wallpaper_picker_package" translatable="false"></string>
+16 −3
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.launcher3;

import static com.android.launcher3.model.AppLaunchTracker.CONTAINER_SEARCH;

import android.app.ActivityOptions;
import android.content.ActivityNotFoundException;
import android.content.Intent;
@@ -32,10 +34,13 @@ import android.widget.Toast;

import com.android.launcher3.LauncherSettings.Favorites;
import com.android.launcher3.compat.LauncherAppsCompat;
import com.android.launcher3.model.AppLaunchTracker;
import com.android.launcher3.shortcuts.DeepShortcutManager;
import com.android.launcher3.uioverrides.DisplayRotationListener;
import com.android.launcher3.uioverrides.WallpaperColorInfo;

import androidx.annotation.Nullable;

/**
 * Extension of BaseActivity allowing support for drag-n-drop
 */
@@ -148,7 +153,8 @@ public abstract class BaseDraggingActivity extends BaseActivity

    public abstract ActivityOptions getActivityLaunchOptions(View v);

    public boolean startActivitySafely(View v, Intent intent, ItemInfo item) {
    public boolean startActivitySafely(View v, Intent intent, @Nullable ItemInfo item,
            @Nullable String sourceContainer) {
        if (mIsSafeModeEnabled && !Utilities.isSystemApp(this, intent)) {
            Toast.makeText(this, R.string.safemode_shortcut_error, Toast.LENGTH_SHORT).show();
            return false;
@@ -169,13 +175,17 @@ public abstract class BaseDraggingActivity extends BaseActivity
                    && !((ShortcutInfo) item).isPromise();
            if (isShortcut) {
                // Shortcuts need some special checks due to legacy reasons.
                startShortcutIntentSafely(intent, optsBundle, item);
                startShortcutIntentSafely(intent, optsBundle, item, sourceContainer);
            } else if (user == null || user.equals(Process.myUserHandle())) {
                // Could be launching some bookkeeping activity
                startActivity(intent, optsBundle);
                AppLaunchTracker.INSTANCE.get(this).onStartApp(intent.getComponent(),
                        Process.myUserHandle(), sourceContainer);
            } else {
                LauncherAppsCompat.getInstance(this).startActivityForProfile(
                        intent.getComponent(), user, intent.getSourceBounds(), optsBundle);
                AppLaunchTracker.INSTANCE.get(this).onStartApp(intent.getComponent(), user,
                        sourceContainer);
            }
            getUserEventDispatcher().logAppLaunch(v, intent);
            getStatsLogManager().logAppLaunch(v, intent);
@@ -187,7 +197,8 @@ public abstract class BaseDraggingActivity extends BaseActivity
        return false;
    }

    private void startShortcutIntentSafely(Intent intent, Bundle optsBundle, ItemInfo info) {
    private void startShortcutIntentSafely(Intent intent, Bundle optsBundle, ItemInfo info,
            @Nullable String sourceContainer) {
        try {
            StrictMode.VmPolicy oldPolicy = StrictMode.getVmPolicy();
            try {
@@ -202,6 +213,8 @@ public abstract class BaseDraggingActivity extends BaseActivity
                    String packageName = intent.getPackage();
                    DeepShortcutManager.getInstance(this).startShortcut(
                            packageName, id, intent.getSourceBounds(), optsBundle, info.user);
                    AppLaunchTracker.INSTANCE.get(this).onStartShortcut(packageName, id, info.user,
                            sourceContainer);
                } else {
                    // Could be launching some bookkeeping activity
                    startActivity(intent, optsBundle);
+6 −3
Original line number Diff line number Diff line
@@ -97,6 +97,7 @@ import com.android.launcher3.logging.FileLog;
import com.android.launcher3.logging.StatsLogUtils;
import com.android.launcher3.logging.UserEventDispatcher;
import com.android.launcher3.logging.UserEventDispatcher.UserEventDelegate;
import com.android.launcher3.model.AppLaunchTracker;
import com.android.launcher3.model.ModelWriter;
import com.android.launcher3.notification.NotificationListener;
import com.android.launcher3.popup.PopupContainerWithArrow;
@@ -694,7 +695,7 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns,

            if (grantResults.length > 0
                    && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                startActivitySafely(v, intent, null);
                startActivitySafely(v, intent, null, null);
            } else {
                // TODO: Show a snack bar with link to settings
                Toast.makeText(this, getString(R.string.msg_no_phone_permission,
@@ -798,6 +799,7 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns,
            getUserEventDispatcher().startSession();

            UiFactory.onLauncherStateOrResumeChanged(this);
            AppLaunchTracker.INSTANCE.get(this).onReturnedToHome();
        }
    }

@@ -1652,8 +1654,9 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns,
        }
    }

    public boolean startActivitySafely(View v, Intent intent, ItemInfo item) {
        boolean success = super.startActivitySafely(v, intent, item);
    public boolean startActivitySafely(View v, Intent intent, ItemInfo item,
            @Nullable String sourceContainer) {
        boolean success = super.startActivitySafely(v, intent, item, sourceContainer);
        if (success && v instanceof BubbleTextView) {
            // This is set to the view that launched the activity that navigated the user away
            // from launcher. Since there is no callback for when the activity has finished
+3 −6
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import com.android.launcher3.Launcher;
import com.android.launcher3.R;
import com.android.launcher3.allapps.AlphabeticalAppsList.AdapterItem;
import com.android.launcher3.compat.UserManagerCompat;
import com.android.launcher3.model.AppLaunchTracker;
import com.android.launcher3.touch.ItemClickHandler;
import com.android.launcher3.touch.ItemLongClickListener;
import com.android.launcher3.util.PackageManagerHelper;
@@ -263,12 +264,8 @@ public class AllAppsGridAdapter extends RecyclerView.Adapter<AllAppsGridAdapter.
            case VIEW_TYPE_SEARCH_MARKET:
                View searchMarketView = mLayoutInflater.inflate(R.layout.all_apps_search_market,
                        parent, false);
                searchMarketView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mLauncher.startActivitySafely(v, mMarketSearchIntent, null);
                    }
                });
                searchMarketView.setOnClickListener(v -> mLauncher.startActivitySafely(
                        v, mMarketSearchIntent, null, AppLaunchTracker.CONTAINER_SEARCH));
                return new ViewHolder(searchMarketView);
            case VIEW_TYPE_ALL_APPS_DIVIDER:
                return new ViewHolder(mLayoutInflater.inflate(
+3 −1
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import android.widget.TextView.OnEditorActionListener;
import com.android.launcher3.ExtendedEditText;
import com.android.launcher3.Launcher;
import com.android.launcher3.Utilities;
import com.android.launcher3.model.AppLaunchTracker;
import com.android.launcher3.util.ComponentKey;
import com.android.launcher3.util.PackageManagerHelper;

@@ -111,7 +112,8 @@ public class AllAppsSearchBarController
            return false;
        }
        return mLauncher.startActivitySafely(v,
                PackageManagerHelper.getMarketSearchIntent(mLauncher, query), null);
                PackageManagerHelper.getMarketSearchIntent(mLauncher, query), null,
                AppLaunchTracker.CONTAINER_SEARCH);
    }

    @Override
Loading