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

Commit c00639f2 authored by Hui Yu's avatar Hui Yu Committed by Automerger Merge Worker
Browse files

Merge "Move noteAppWidgetTapped call into AppWidgetHostView." into rvc-dev am: 4db77a97

Change-Id: I7983d7b08a35459f94115d2f9ac4f92a7e90fd0e
parents 4c5da601 4db77a97
Loading
Loading
Loading
Loading
+14 −3
Original line number Original line Diff line number Diff line
@@ -104,7 +104,7 @@ public class AppWidgetHostView extends FrameLayout {
     */
     */
    public AppWidgetHostView(Context context, OnClickHandler handler) {
    public AppWidgetHostView(Context context, OnClickHandler handler) {
        this(context, android.R.anim.fade_in, android.R.anim.fade_out);
        this(context, android.R.anim.fade_in, android.R.anim.fade_out);
        mOnClickHandler = handler;
        mOnClickHandler = getHandler(handler);
    }
    }


    /**
    /**
@@ -131,7 +131,7 @@ public class AppWidgetHostView extends FrameLayout {
     * @hide
     * @hide
     */
     */
    public void setOnClickHandler(OnClickHandler handler) {
    public void setOnClickHandler(OnClickHandler handler) {
        mOnClickHandler = handler;
        mOnClickHandler = getHandler(handler);
    }
    }


    /**
    /**
@@ -423,7 +423,6 @@ public class AppWidgetHostView extends FrameLayout {
            // inflate any requested LayoutParams.
            // inflate any requested LayoutParams.
            mRemoteContext = getRemoteContext();
            mRemoteContext = getRemoteContext();
            int layoutId = remoteViews.getLayoutId();
            int layoutId = remoteViews.getLayoutId();

            // If our stale view has been prepared to match active, and the new
            // If our stale view has been prepared to match active, and the new
            // layout matches, try recycling it
            // layout matches, try recycling it
            if (content == null && layoutId == mLayoutId) {
            if (content == null && layoutId == mLayoutId) {
@@ -711,4 +710,16 @@ public class AppWidgetHostView extends FrameLayout {
        }
        }
        return null;
        return null;
    }
    }

    private OnClickHandler getHandler(OnClickHandler handler) {
        return (view, pendingIntent, response) -> {
            AppWidgetManager.getInstance(mContext).noteAppWidgetTapped(mAppWidgetId);
            if (handler != null) {
                return handler.onClickHandler(view, pendingIntent, response);
            } else {
                return RemoteViews.startPendingIntent(view, pendingIntent,
                        response.getLaunchOptions(view));
            }
        };
    }
}
}
+4 −4
Original line number Original line Diff line number Diff line
@@ -1243,13 +1243,13 @@ public class AppWidgetManager {


    /**
    /**
     * Note an app widget is tapped on.
     * Note an app widget is tapped on.
     * @param uid App UID.
     *
     * @param packageName App package name.
     * @param appWidgetId App widget id.
     * @hide
     * @hide
     */
     */
    public void noteAppWidgetTapped(int uid, @NonNull String packageName) {
    public void noteAppWidgetTapped(int appWidgetId) {
        try {
        try {
            mService.noteAppWidgetTapped(uid, packageName);
            mService.noteAppWidgetTapped(mPackageName, appWidgetId);
        } catch (RemoteException e) {
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
            throw e.rethrowFromSystemServer();
        }
        }
+1 −12
Original line number Original line Diff line number Diff line
@@ -29,7 +29,6 @@ import android.app.Application;
import android.app.PendingIntent;
import android.app.PendingIntent;
import android.app.RemoteInput;
import android.app.RemoteInput;
import android.appwidget.AppWidgetHostView;
import android.appwidget.AppWidgetHostView;
import android.appwidget.AppWidgetManager;
import android.compat.annotation.UnsupportedAppUsage;
import android.compat.annotation.UnsupportedAppUsage;
import android.content.Context;
import android.content.Context;
import android.content.ContextWrapper;
import android.content.ContextWrapper;
@@ -4131,18 +4130,8 @@ public class RemoteViews implements Parcelable, Filter {
            // The NEW_TASK flags are applied through the activity options and not as a part of
            // The NEW_TASK flags are applied through the activity options and not as a part of
            // the call to startIntentSender() to ensure that they are consistently applied to
            // the call to startIntentSender() to ensure that they are consistently applied to
            // both mutable and immutable PendingIntents.
            // both mutable and immutable PendingIntents.
            final IntentSender intentSender = pendingIntent.getIntentSender();
            final int uid = intentSender.getCreatorUid();
            final String packageName = intentSender.getCreatorPackage();
            if (uid != -1 && packageName != null) {
                final AppWidgetManager appWidgetManager =
                        context.getSystemService(AppWidgetManager.class);
                if (appWidgetManager != null) {
                    appWidgetManager.noteAppWidgetTapped(uid, packageName);
                }
            }
            context.startIntentSender(
            context.startIntentSender(
                    intentSender, options.first,
                    pendingIntent.getIntentSender(), options.first,
                    0, 0, 0, options.second.toBundle());
                    0, 0, 0, options.second.toBundle());
        } catch (IntentSender.SendIntentException e) {
        } catch (IntentSender.SendIntentException e) {
            Log.e(LOG_TAG, "Cannot send pending intent: ", e);
            Log.e(LOG_TAG, "Cannot send pending intent: ", e);
+1 −1
Original line number Original line Diff line number Diff line
@@ -77,6 +77,6 @@ interface IAppWidgetService {
    boolean requestPinAppWidget(String packageName, in ComponentName providerComponent,
    boolean requestPinAppWidget(String packageName, in ComponentName providerComponent,
            in Bundle extras, in IntentSender resultIntent);
            in Bundle extras, in IntentSender resultIntent);
    boolean isRequestPinAppWidgetSupported();
    boolean isRequestPinAppWidgetSupported();
    void noteAppWidgetTapped(int uid, String packageName);
    oneway void noteAppWidgetTapped(in String callingPackage, in int appWidgetId);
}
}
+19 −28
Original line number Original line Diff line number Diff line
@@ -3652,11 +3652,12 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku
     * Note an app widget is tapped on. If a app widget is tapped, the underlying app is treated as
     * Note an app widget is tapped on. If a app widget is tapped, the underlying app is treated as
     * foreground so the app can get while-in-use permission.
     * foreground so the app can get while-in-use permission.
     *
     *
     * @param uid UID of the underlying app.
     * @param callingPackage calling app's packageName.
     * @param packageName Package name of the app.
     * @param appWidgetId App widget id.
     */
     */
    @Override
    @Override
    public void noteAppWidgetTapped(int uid, String packageName) {
    public void noteAppWidgetTapped(String callingPackage, int appWidgetId) {
        mSecurityPolicy.enforceCallFromPackage(callingPackage);
        final int callingUid = Binder.getCallingUid();
        final int callingUid = Binder.getCallingUid();
        final long ident = Binder.clearCallingIdentity();
        final long ident = Binder.clearCallingIdentity();
        try {
        try {
@@ -3665,32 +3666,22 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku
            if (procState > ActivityManager.PROCESS_STATE_TOP) {
            if (procState > ActivityManager.PROCESS_STATE_TOP) {
                return;
                return;
            }
            }

            synchronized (mLock) {
            // Default launcher from package manager.
                final Widget widget = lookupWidgetLocked(appWidgetId, callingUid, callingPackage);
            final ComponentName defaultLauncher = mPackageManagerInternal
                if (widget == null) {
                    .getDefaultHomeActivity(UserHandle.getUserId(callingUid));
            if (defaultLauncher == null) {
                return;
            }
            int defaultLauncherUid  = 0;
            try {
                defaultLauncherUid = mPackageManager.getApplicationInfo(
                        defaultLauncher.getPackageName(), 0 ,
                        UserHandle.getUserId(callingUid)).uid;
            } catch (RemoteException e) {
                Slog.e(TAG, "Failed to getApplicationInfo for package:"
                        + defaultLauncher.getPackageName(), e);
                    return;
                    return;
                }
                }
            // The callingUid must be default launcher uid.
                final ProviderId providerId = widget.provider.id;
            if (defaultLauncherUid != callingUid) {
                final String packageName = providerId.componentName.getPackageName();
                if (packageName == null) {
                    return;
                    return;
                }
                }
                final SparseArray<String> uid2PackageName = new SparseArray<String>();
                final SparseArray<String> uid2PackageName = new SparseArray<String>();
            uid2PackageName.put(uid, packageName);
                uid2PackageName.put(providerId.uid, packageName);
                mAppOpsManagerInternal.updateAppWidgetVisibility(uid2PackageName, true);
                mAppOpsManagerInternal.updateAppWidgetVisibility(uid2PackageName, true);
            mUsageStatsManagerInternal.reportEvent(packageName, UserHandle.getUserId(uid),
                mUsageStatsManagerInternal.reportEvent(packageName,
                    UsageEvents.Event.USER_INTERACTION);
                        UserHandle.getUserId(providerId.uid), UsageEvents.Event.USER_INTERACTION);
            }
        } finally {
        } finally {
            Binder.restoreCallingIdentity(ident);
            Binder.restoreCallingIdentity(ident);
        }
        }
Loading