Add function to AppWidgetService for updating widget visibility

Currently, when the widget host stops listening to the widget updates,
the callback will be set to null and the updates to the widget will be
stashed on the service side. Additionally, the visibility of the widget
will be changed. For an upcoming change to the launcher side, a function
that only changes the visibility should be added.

Test: N/A
Bug: 235358918
Change-Id: I9a0f244ca76b378d9c337e0a364bca5955f5ae96
This commit is contained in:
Sihua Ma
2022-09-20 21:50:43 +00:00
parent 71833c1d3d
commit 45b60acb7b
3 changed files with 44 additions and 0 deletions

View File

@@ -328,6 +328,22 @@ public class AppWidgetHost {
}
}
/**
* Set the visibiity of all widgets associated with this host to hidden
*
* @hide
*/
public void setAppWidgetHidden() {
if (sService == null) {
return;
}
try {
sService.setAppWidgetHidden(mContextOpPackageName, mHostId);
} catch (RemoteException e) {
throw new RuntimeException("System server dead?", e);
}
}
/**
* Set the host's interaction handler.
*

View File

@@ -45,6 +45,7 @@ interface IAppWidgetService {
@UnsupportedAppUsage(maxTargetSdk = 30, trackingBug = 170729553)
RemoteViews getAppWidgetViews(String callingPackage, int appWidgetId);
int[] getAppWidgetIdsForHost(String callingPackage, int hostId);
void setAppWidgetHidden(in String callingPackage, int hostId);
IntentSender createAppWidgetConfigIntentSender(String callingPackage, int appWidgetId,
int intentFlags);

View File

@@ -865,6 +865,33 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku
}
}
@Override
public void setAppWidgetHidden(String callingPackage, int hostId) {
final int userId = UserHandle.getCallingUserId();
if (DEBUG) {
Slog.i(TAG, "setAppWidgetHidden() " + userId);
}
mSecurityPolicy.enforceCallFromPackage(callingPackage);
synchronized (mLock) {
ensureGroupStateLoadedLocked(userId, /* enforceUserUnlockingOrUnlocked */false);
HostId id = new HostId(Binder.getCallingUid(), hostId, callingPackage);
Host host = lookupHostLocked(id);
if (host != null) {
try {
mAppOpsManagerInternal.updateAppWidgetVisibility(host.getWidgetUids(), false);
} catch (NullPointerException e) {
Slog.e(TAG, "setAppWidgetHidden(): Getting host uids: " + host.toString(), e);
throw e;
}
}
}
}
@Override
public void deleteAppWidgetId(String callingPackage, int appWidgetId) {
final int userId = UserHandle.getCallingUserId();