launcher3: Improve SimpleBroadcastReceiver.
Unless explicitly annotated, parameters in java are by default nullable. There are a few cases where a null context may be passed to the unregisterReceiverSafely function of SimpleBroadcastReceiver. To mitigate misuses or incorrect contexts being passed for register vs unregister, keep the context as a strong reference in the constructor. Also added NonNull annotations for any public callsites to enforce behavior. Bug: 395019017, 395966395 Flag: NONE - bug fixed Test: manual - presubmit Change-Id: Ie371fa45cadceaf51cf184b446df9123ef27c337
This commit is contained in:
1 parent
4425ab3062
commit
1b26bb4a74
16 files changed
+118
-113
No files matched your search
@@ -119,14 +119,13 @@ public class LauncherAppState implements SafeCloseable {
|
||||
}
|
||||
|
||||
SimpleBroadcastReceiver modelChangeReceiver =
|
||||
new SimpleBroadcastReceiver(UI_HELPER_EXECUTOR, mModel::onBroadcastIntent);
|
||||
new SimpleBroadcastReceiver(context, UI_HELPER_EXECUTOR, mModel::onBroadcastIntent);
|
||||
modelChangeReceiver.register(
|
||||
mContext,
|
||||
ACTION_DEVICE_POLICY_RESOURCE_UPDATED);
|
||||
if (BuildConfig.IS_STUDIO_BUILD) {
|
||||
modelChangeReceiver.register(mContext, RECEIVER_EXPORTED, ACTION_FORCE_ROLOAD);
|
||||
modelChangeReceiver.register(RECEIVER_EXPORTED, ACTION_FORCE_ROLOAD);
|
||||
}
|
||||
mOnTerminateCallback.add(() -> modelChangeReceiver.unregisterReceiverSafely(mContext));
|
||||
mOnTerminateCallback.add(() -> modelChangeReceiver.unregisterReceiverSafely());
|
||||
|
||||
SafeCloseable userChangeListener = UserCache.INSTANCE.get(mContext)
|
||||
.addUserEventListener(mModel::onUserEvent);
|
||||
|
||||
Reference in new issue
Block a user