Merge "Send widget registration broadcasts before BOOT_COMPLETE" into pi-dev

This commit is contained in:
TreeHugger Robot
2018-08-20 23:44:32 +00:00
committed by Android (Google) Code Review
4 changed files with 34 additions and 13 deletions

View File

@@ -16,12 +16,9 @@
package android.appwidget;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.util.ArraySet;
import java.util.Set;
/**
* App widget manager local system service interface.
*
@@ -36,4 +33,13 @@ public abstract class AppWidgetManagerInternal {
* @return Whether the UID hosts widgets from the package.
*/
public abstract @Nullable ArraySet<String> getHostedWidgetPackages(int uid);
/**
* Execute the widget-related work of unlocking a user. This is intentionally
* invoked just <em>before</em> the boot-completed broadcast is issued, after
* the data-related work of unlock has completed.
*
* @param userId The user that is being unlocked.
*/
public abstract void unlockUser(int userId);
}

View File

@@ -47,11 +47,6 @@ public class AppWidgetService extends SystemService {
}
}
@Override
public void onUnlockUser(int userHandle) {
FgThread.getHandler().post(() -> mImpl.onUserUnlocked(userHandle));
}
@Override
public void onStopUser(int userHandle) {
mImpl.onUserStopped(userHandle);

View File

@@ -19,7 +19,6 @@ package com.android.server.appwidget;
import static android.content.Context.KEYGUARD_SERVICE;
import static android.content.Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS;
import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
import static com.android.server.pm.PackageManagerService.PLATFORM_PACKAGE_NAME;
import android.annotation.UserIdInt;
@@ -2697,7 +2696,12 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku
}
}
void onUserUnlocked(int userId) {
/**
* This does not use the usual onUserUnlocked() listener mechanism because it is
* invoked at a choreographed point in the middle of the user unlock sequence,
* before the boot-completed broadcast is issued and the listeners notified.
*/
void handleUserUnlocked(int userId) {
if (isProfileWithLockedParent(userId)) {
return;
}
@@ -2734,7 +2738,7 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku
}
}
}
Slog.i(TAG, "Async processing of onUserUnlocked u" + userId + " took "
Slog.i(TAG, "Processing of handleUserUnlocked u" + userId + " took "
+ (SystemClock.elapsedRealtime() - time) + " ms");
}
@@ -4801,5 +4805,11 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku
return widgetPackages;
}
}
@Override
public void unlockUser(int userId) {
handleUserUnlocked(userId);
}
}
}

View File

@@ -24,7 +24,6 @@ import static android.app.ActivityManager.USER_OP_IS_CURRENT;
import static android.app.ActivityManager.USER_OP_SUCCESS;
import static android.os.Process.SHELL_UID;
import static android.os.Process.SYSTEM_UID;
import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_MU;
import static com.android.server.am.ActivityManagerDebugConfig.TAG_AM;
import static com.android.server.am.ActivityManagerDebugConfig.TAG_WITH_CLASS_NAME;
@@ -48,6 +47,7 @@ import android.app.IStopUserCallback;
import android.app.IUserSwitchObserver;
import android.app.KeyguardManager;
import android.app.usage.UsageEvents;
import android.appwidget.AppWidgetManagerInternal;
import android.content.Context;
import android.content.IIntentReceiver;
import android.content.Intent;
@@ -87,8 +87,8 @@ import android.util.SparseArray;
import android.util.SparseIntArray;
import android.util.TimingsTraceLog;
import android.util.proto.ProtoOutputStream;
import android.view.Window;
import com.android.internal.R;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
@@ -533,6 +533,9 @@ class UserController implements Handler.Callback {
}
}
// Spin up app widgets prior to boot-complete, so they can be ready promptly
mInjector.startUserWidgets(userId);
Slog.i(TAG, "Sending BOOT_COMPLETE user #" + userId);
// Do not report secondary users, runtime restarts or first boot/upgrade
if (userId == UserHandle.USER_SYSTEM
@@ -2173,6 +2176,13 @@ class UserController implements Handler.Callback {
}
}
void startUserWidgets(int userId) {
AppWidgetManagerInternal awm = LocalServices.getService(AppWidgetManagerInternal.class);
if (awm != null) {
awm.unlockUser(userId);
}
}
void updateUserConfiguration() {
synchronized (mService) {
mService.updateUserConfigurationLocked();