summaryrefslogtreecommitdiff
path: root/services/appwidget
diff options
context:
space:
mode:
authorHui Yu <huiyu@google.com>2020-04-10 14:18:51 -0700
committerHui Yu <huiyu@google.com>2020-04-15 22:06:12 -0700
commit48032682297d848754ded3b157044bbc4e22db71 (patch)
tree7a708dcee8b4b6b761bace7cd89c2c17598439e5 /services/appwidget
parent4d7fb0b4c24d1e3be98b824497edc207498a0a81 (diff)
Move noteAppWidgetTapped call into AppWidgetHostView.
RemoteViews is public API used out of scope of widget. The correct place to call noteAppWidgetTapped is in AppWidgetHostView. Fix: 153676411 Test: manual test, tap a widget, "adb shell dumpsys usagestats | grep USER_INTERACTION" to oberserve USER_INTERACTION event sent to UsageStas, "adb shell dumpsys appops | grep appWidgetVisible" to observer appWidgetVisible flag. Change-Id: Ic473211b91fd952dbb81b09b1e1568d6f69a0dd8
Diffstat (limited to 'services/appwidget')
-rw-r--r--services/appwidget/java/com/android/server/appwidget/AppWidgetServiceImpl.java47
1 files changed, 19 insertions, 28 deletions
diff --git a/services/appwidget/java/com/android/server/appwidget/AppWidgetServiceImpl.java b/services/appwidget/java/com/android/server/appwidget/AppWidgetServiceImpl.java
index ca1b27bd261e..74e4e4a43126 100644
--- a/services/appwidget/java/com/android/server/appwidget/AppWidgetServiceImpl.java
+++ b/services/appwidget/java/com/android/server/appwidget/AppWidgetServiceImpl.java
@@ -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
* foreground so the app can get while-in-use permission.
*
- * @param uid UID of the underlying app.
- * @param packageName Package name of the app.
+ * @param callingPackage calling app's packageName.
+ * @param appWidgetId App widget id.
*/
@Override
- public void noteAppWidgetTapped(int uid, String packageName) {
+ public void noteAppWidgetTapped(String callingPackage, int appWidgetId) {
+ mSecurityPolicy.enforceCallFromPackage(callingPackage);
final int callingUid = Binder.getCallingUid();
final long ident = Binder.clearCallingIdentity();
try {
@@ -3665,32 +3666,22 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku
if (procState > ActivityManager.PROCESS_STATE_TOP) {
return;
}
-
- // Default launcher from package manager.
- final ComponentName defaultLauncher = mPackageManagerInternal
- .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;
- }
- // The callingUid must be default launcher uid.
- if (defaultLauncherUid != callingUid) {
- return;
+ synchronized (mLock) {
+ final Widget widget = lookupWidgetLocked(appWidgetId, callingUid, callingPackage);
+ if (widget == null) {
+ return;
+ }
+ final ProviderId providerId = widget.provider.id;
+ final String packageName = providerId.componentName.getPackageName();
+ if (packageName == null) {
+ return;
+ }
+ final SparseArray<String> uid2PackageName = new SparseArray<String>();
+ uid2PackageName.put(providerId.uid, packageName);
+ mAppOpsManagerInternal.updateAppWidgetVisibility(uid2PackageName, true);
+ mUsageStatsManagerInternal.reportEvent(packageName,
+ UserHandle.getUserId(providerId.uid), UsageEvents.Event.USER_INTERACTION);
}
- final SparseArray<String> uid2PackageName = new SparseArray<String>();
- uid2PackageName.put(uid, packageName);
- mAppOpsManagerInternal.updateAppWidgetVisibility(uid2PackageName, true);
- mUsageStatsManagerInternal.reportEvent(packageName, UserHandle.getUserId(uid),
- UsageEvents.Event.USER_INTERACTION);
} finally {
Binder.restoreCallingIdentity(ident);
}