Search in sources :

Example 1 with InstanceId

use of com.android.launcher3.logging.InstanceId in project android_packages_apps_Launcher3 by crdroidandroid.

the class HotseatPredictionController method logLaunchedAppRankingInfo.

/**
 * Logs rank info based on current list of predicted items
 */
public void logLaunchedAppRankingInfo(@NonNull ItemInfo itemInfo, InstanceId instanceId) {
    ComponentName targetCN = itemInfo.getTargetComponent();
    if (targetCN == null) {
        return;
    }
    int rank = -1;
    for (int i = mPredictedItems.size() - 1; i >= 0; i--) {
        ItemInfo info = mPredictedItems.get(i);
        if (targetCN.equals(info.getTargetComponent()) && itemInfo.user.equals(info.user)) {
            rank = i;
            break;
        }
    }
    if (rank < 0) {
        return;
    }
    int cardinality = 0;
    for (PredictedAppIcon icon : getPredictedIcons()) {
        ItemInfo info = (ItemInfo) icon.getTag();
        cardinality |= 1 << info.screenId;
    }
    PredictedHotseatContainer.Builder containerBuilder = PredictedHotseatContainer.newBuilder();
    containerBuilder.setCardinality(cardinality);
    if (itemInfo.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT_PREDICTION) {
        containerBuilder.setIndex(rank);
    }
    mLauncher.getStatsLogManager().logger().withInstanceId(instanceId).withRank(rank).withContainerInfo(ContainerInfo.newBuilder().setPredictedHotseatContainer(containerBuilder).build()).log(LAUNCHER_HOTSEAT_RANKED);
}
Also used : PredictedHotseatContainer(com.android.launcher3.logger.LauncherAtom.PredictedHotseatContainer) ItemInfo(com.android.launcher3.model.data.ItemInfo) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) PredictedAppIcon(com.android.launcher3.uioverrides.PredictedAppIcon) ComponentName(android.content.ComponentName)

Example 2 with InstanceId

use of com.android.launcher3.logging.InstanceId in project android_packages_apps_Launcher3 by crdroidandroid.

the class FolderIcon method setLabelSuggestion.

/**
 * Set the suggested folder name.
 */
public void setLabelSuggestion(FolderNameInfos nameInfos, InstanceId instanceId) {
    if (!FeatureFlags.FOLDER_NAME_SUGGEST.get()) {
        return;
    }
    if (!mInfo.getLabelState().equals(LabelState.UNLABELED)) {
        return;
    }
    if (nameInfos == null || !nameInfos.hasSuggestions()) {
        StatsLogManager.newInstance(getContext()).logger().withInstanceId(instanceId).withItemInfo(mInfo).log(LAUNCHER_FOLDER_AUTO_LABELING_SKIPPED_EMPTY_SUGGESTIONS);
        return;
    }
    if (!nameInfos.hasPrimary()) {
        StatsLogManager.newInstance(getContext()).logger().withInstanceId(instanceId).withItemInfo(mInfo).log(LAUNCHER_FOLDER_AUTO_LABELING_SKIPPED_EMPTY_PRIMARY);
        return;
    }
    CharSequence newTitle = nameInfos.getLabels()[0];
    FromState fromState = mInfo.getFromLabelState();
    mInfo.setTitle(newTitle, mFolder.mLauncherDelegate.getModelWriter());
    onTitleChanged(mInfo.title);
    mFolder.mFolderName.setText(mInfo.title);
    // Logging for folder creation flow
    StatsLogManager.newInstance(getContext()).logger().withInstanceId(instanceId).withItemInfo(mInfo).withFromState(fromState).withToState(ToState.TO_SUGGESTION0).withEditText(newTitle.toString()).log(LAUNCHER_FOLDER_AUTO_LABELED);
}
Also used : FromState(com.android.launcher3.logger.LauncherAtom.FromState)

Example 3 with InstanceId

use of com.android.launcher3.logging.InstanceId in project android_packages_apps_Launcher3 by crdroidandroid.

the class BaseDraggingActivity method startActivitySafely.

public boolean startActivitySafely(View v, Intent intent, @Nullable ItemInfo item) {
    if (mIsSafeModeEnabled && !PackageManagerHelper.isSystemApp(this, intent)) {
        Toast.makeText(this, R.string.safemode_shortcut_error, Toast.LENGTH_SHORT).show();
        return false;
    }
    Bundle optsBundle = (v != null) ? getActivityLaunchOptions(v, item).toBundle() : null;
    UserHandle user = item == null ? null : item.user;
    // Prepare intent
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    if (v != null) {
        intent.setSourceBounds(getViewBounds(v));
    }
    try {
        boolean isShortcut = (item instanceof WorkspaceItemInfo) && (item.itemType == Favorites.ITEM_TYPE_SHORTCUT || item.itemType == Favorites.ITEM_TYPE_DEEP_SHORTCUT) && !((WorkspaceItemInfo) item).isPromise();
        if (isShortcut) {
            // Shortcuts need some special checks due to legacy reasons.
            startShortcutIntentSafely(intent, optsBundle, item);
        } else if (user == null || user.equals(Process.myUserHandle())) {
            // Could be launching some bookkeeping activity
            startActivity(intent, optsBundle);
        } else {
            getSystemService(LauncherApps.class).startMainActivity(intent.getComponent(), user, intent.getSourceBounds(), optsBundle);
        }
        if (item != null) {
            InstanceId instanceId = new InstanceIdSequence().newInstanceId();
            logAppLaunch(item, instanceId);
        }
        return true;
    } catch (NullPointerException | ActivityNotFoundException | SecurityException e) {
        Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
        Log.e(TAG, "Unable to launch. tag=" + item + " intent=" + intent, e);
    }
    return false;
}
Also used : InstanceId(com.android.launcher3.logging.InstanceId) InstanceIdSequence(com.android.launcher3.logging.InstanceIdSequence) ActivityNotFoundException(android.content.ActivityNotFoundException) Bundle(android.os.Bundle) UserHandle(android.os.UserHandle) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo)

Example 4 with InstanceId

use of com.android.launcher3.logging.InstanceId in project android_packages_apps_Launcher3 by crdroidandroid.

the class QuickstepModelDelegate method modelLoadComplete.

@Override
@WorkerThread
public void modelLoadComplete() {
    super.modelLoadComplete();
    // Log snapshot of the model
    SharedPreferences prefs = getDevicePrefs(mApp.getContext());
    long lastSnapshotTimeMillis = prefs.getLong(LAST_SNAPSHOT_TIME_MILLIS, 0);
    // Log snapshot only if previous snapshot was older than a day
    long now = System.currentTimeMillis();
    if (now - lastSnapshotTimeMillis < DAY_IN_MILLIS) {
        if (IS_DEBUG) {
            String elapsedTime = formatElapsedTime((now - lastSnapshotTimeMillis) / 1000);
            Log.d(TAG, String.format("Skipped snapshot logging since previous snapshot was %s old.", elapsedTime));
        }
    } else {
        IntSparseArrayMap<ItemInfo> itemsIdMap;
        synchronized (mDataModel) {
            itemsIdMap = mDataModel.itemsIdMap.clone();
        }
        InstanceId instanceId = new InstanceIdSequence().newInstanceId();
        for (ItemInfo info : itemsIdMap) {
            FolderInfo parent = info.container > 0 ? (FolderInfo) itemsIdMap.get(info.container) : null;
            StatsLogCompatManager.writeSnapshot(info.buildProto(parent), instanceId);
        }
        additionalSnapshotEvents(instanceId);
        prefs.edit().putLong(LAST_SNAPSHOT_TIME_MILLIS, now).apply();
    }
}
Also used : SharedPreferences(android.content.SharedPreferences) ItemInfo(com.android.launcher3.model.data.ItemInfo) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) InstanceId(com.android.launcher3.logging.InstanceId) InstanceIdSequence(com.android.launcher3.logging.InstanceIdSequence) FolderInfo(com.android.launcher3.model.data.FolderInfo) WorkerThread(androidx.annotation.WorkerThread)

Example 5 with InstanceId

use of com.android.launcher3.logging.InstanceId in project android_packages_apps_Launcher3 by crdroidandroid.

the class LauncherDelegate method replaceFolderWithFinalItem.

void replaceFolderWithFinalItem(Folder folder) {
    // Add the last remaining child to the workspace in place of the folder
    Runnable onCompleteRunnable = new Runnable() {

        @Override
        public void run() {
            int itemCount = folder.getItemCount();
            FolderInfo info = folder.mInfo;
            if (itemCount <= 1) {
                View newIcon = null;
                WorkspaceItemInfo finalItem = null;
                if (itemCount == 1) {
                    // Move the item from the folder to the workspace, in the position of the
                    // folder
                    CellLayout cellLayout = mLauncher.getCellLayout(info.container, info.screenId);
                    finalItem = info.contents.remove(0);
                    newIcon = mLauncher.createShortcut(cellLayout, finalItem);
                    mLauncher.getModelWriter().addOrMoveItemInDatabase(finalItem, info.container, info.screenId, info.cellX, info.cellY);
                }
                // Remove the folder
                mLauncher.removeItem(folder.mFolderIcon, info, true);
                if (folder.mFolderIcon instanceof DropTarget) {
                    folder.mDragController.removeDropTarget((DropTarget) folder.mFolderIcon);
                }
                if (newIcon != null) {
                    // We add the child after removing the folder to prevent both from existing
                    // at the same time in the CellLayout.  We need to add the new item with
                    // addInScreenFromBind() to ensure that hotseat items are placed correctly.
                    mLauncher.getWorkspace().addInScreenFromBind(newIcon, info);
                    // Focus the newly created child
                    newIcon.requestFocus();
                }
                if (finalItem != null) {
                    StatsLogger logger = mLauncher.getStatsLogManager().logger().withItemInfo(finalItem);
                    ((Optional<InstanceId>) folder.mDragController.getLogInstanceId()).map(logger::withInstanceId).orElse(logger).log(LAUNCHER_FOLDER_CONVERTED_TO_ICON);
                }
            }
        }
    };
    View finalChild = folder.mContent.getLastItem();
    if (finalChild != null) {
        folder.mFolderIcon.performDestroyAnimation(onCompleteRunnable);
    } else {
        onCompleteRunnable.run();
    }
}
Also used : StatsLogger(com.android.launcher3.logging.StatsLogManager.StatsLogger) CellLayout(com.android.launcher3.CellLayout) Optional(java.util.Optional) DropTarget(com.android.launcher3.DropTarget) FolderInfo(com.android.launcher3.model.data.FolderInfo) View(android.view.View) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo)

Aggregations

WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)5 ItemInfo (com.android.launcher3.model.data.ItemInfo)3 InstanceId (com.android.launcher3.logging.InstanceId)2 InstanceIdSequence (com.android.launcher3.logging.InstanceIdSequence)2 StatsLogger (com.android.launcher3.logging.StatsLogManager.StatsLogger)2 FolderInfo (com.android.launcher3.model.data.FolderInfo)2 ActivityNotFoundException (android.content.ActivityNotFoundException)1 ComponentName (android.content.ComponentName)1 SharedPreferences (android.content.SharedPreferences)1 Bundle (android.os.Bundle)1 UserHandle (android.os.UserHandle)1 View (android.view.View)1 WorkerThread (androidx.annotation.WorkerThread)1 CellLayout (com.android.launcher3.CellLayout)1 DropTarget (com.android.launcher3.DropTarget)1 FromState (com.android.launcher3.logger.LauncherAtom.FromState)1 PredictedHotseatContainer (com.android.launcher3.logger.LauncherAtom.PredictedHotseatContainer)1 PredictedAppIcon (com.android.launcher3.uioverrides.PredictedAppIcon)1 Optional (java.util.Optional)1