[Dagger] Make SettingsCache provided by DaggerSingletonObject
Test: presubmit Bug: 361850561 Flag: NONE - dagger Change-Id: Id709a6e1d14446b8361cf292d5f5422f2ea3524c
This commit is contained in:
1 parent
49df29669d
commit
4d819d9dea
10 files changed
+42
-30
No files matched your search
@@ -237,7 +237,7 @@ public class QuickstepModelDelegate extends ModelDelegate {
|
||||
InstanceId instanceId = new InstanceIdSequence().newInstanceId();
|
||||
for (ItemInfo info : itemsIdMap) {
|
||||
CollectionInfo parent = getContainer(info, itemsIdMap);
|
||||
StatsLogCompatManager.writeSnapshot(info.buildProto(parent), instanceId);
|
||||
StatsLogCompatManager.writeSnapshot(info.buildProto(parent, mContext), instanceId);
|
||||
}
|
||||
additionalSnapshotEvents(instanceId);
|
||||
prefs.put(LAST_SNAPSHOT_TIME_MILLIS, now);
|
||||
@@ -274,7 +274,7 @@ public class QuickstepModelDelegate extends ModelDelegate {
|
||||
|
||||
for (ItemInfo info : itemsIdMap) {
|
||||
CollectionInfo parent = getContainer(info, itemsIdMap);
|
||||
LauncherAtom.ItemInfo itemInfo = info.buildProto(parent);
|
||||
LauncherAtom.ItemInfo itemInfo = info.buildProto(parent, mContext);
|
||||
Log.d(TAG, itemInfo.toString());
|
||||
StatsEvent statsEvent = StatsLogCompatManager.buildStatsEvent(itemInfo,
|
||||
instanceId);
|
||||
|
||||
@@ -386,12 +386,12 @@ public class StatsLogCompatManager extends StatsLogManager {
|
||||
// and then write to StatsLog.
|
||||
app.getModel().enqueueModelUpdateTask((taskController, dataModel, apps) ->
|
||||
write(event, applyOverwrites(mItemInfo.buildProto(
|
||||
dataModel.collections.get(mItemInfo.container)))));
|
||||
dataModel.collections.get(mItemInfo.container), mContext))));
|
||||
})) {
|
||||
// Write log on the model thread so that logs do not go out of order
|
||||
// (for eg: drop comes after drag)
|
||||
Executors.MODEL_EXECUTOR.execute(
|
||||
() -> write(event, applyOverwrites(mItemInfo.buildProto())));
|
||||
() -> write(event, applyOverwrites(mItemInfo.buildProto(mContext))));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ import android.content.Context;
|
||||
import com.android.launcher3.pm.InstallSessionHelper;
|
||||
import com.android.launcher3.util.DaggerSingletonTracker;
|
||||
import com.android.launcher3.util.ScreenOnTracker;
|
||||
import com.android.launcher3.util.SettingsCache;
|
||||
|
||||
import dagger.BindsInstance;
|
||||
|
||||
@@ -36,6 +37,7 @@ public interface LauncherBaseAppComponent {
|
||||
DaggerSingletonTracker getDaggerSingletonTracker();
|
||||
InstallSessionHelper getInstallSessionHelper();
|
||||
ScreenOnTracker getScreenOnTracker();
|
||||
SettingsCache getSettingsCache();
|
||||
|
||||
/** Builder for LauncherBaseAppComponent. */
|
||||
interface Builder {
|
||||
|
||||
@@ -74,7 +74,7 @@ class AppPairInfo() : CollectionInfo() {
|
||||
(ActivityContext.lookupContext(context) as ActivityContext).getDeviceProfile().isTablet
|
||||
return Pair(
|
||||
isTablet || !getFirstApp().isNonResizeable(),
|
||||
isTablet || !getSecondApp().isNonResizeable()
|
||||
isTablet || !getSecondApp().isNonResizeable(),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -105,10 +105,10 @@ class AppPairInfo() : CollectionInfo() {
|
||||
}
|
||||
|
||||
/** Generates an ItemInfo for logging. */
|
||||
override fun buildProto(cInfo: CollectionInfo?): LauncherAtom.ItemInfo {
|
||||
override fun buildProto(cInfo: CollectionInfo?, context: Context): LauncherAtom.ItemInfo {
|
||||
val appPairIcon = LauncherAtom.FolderIcon.newBuilder().setCardinality(contents.size)
|
||||
appPairIcon.setLabelInfo(title.toString())
|
||||
return getDefaultItemInfoBuilder()
|
||||
return getDefaultItemInfoBuilder(context)
|
||||
.setFolderIcon(appPairIcon)
|
||||
.setRank(rank)
|
||||
.setContainerInfo(getContainerInfo())
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package com.android.launcher3.model.data
|
||||
|
||||
import com.android.launcher3.LauncherSettings
|
||||
import com.android.launcher3.logger.LauncherAtom
|
||||
import com.android.launcher3.util.ContentWriter
|
||||
import java.util.function.Predicate
|
||||
|
||||
@@ -42,9 +41,4 @@ abstract class CollectionInfo : ItemInfo() {
|
||||
super.onAddToDatabase(writer)
|
||||
writer.put(LauncherSettings.Favorites.TITLE, title)
|
||||
}
|
||||
|
||||
/** Returns the collection wrapped as {@link LauncherAtom.ItemInfo} for logging. */
|
||||
override fun buildProto(): LauncherAtom.ItemInfo {
|
||||
return buildProto(null)
|
||||
}
|
||||
}
|
||||
@@ -24,6 +24,8 @@ import static com.android.launcher3.logger.LauncherAtom.Attribute.EMPTY_LABEL;
|
||||
import static com.android.launcher3.logger.LauncherAtom.Attribute.MANUAL_LABEL;
|
||||
import static com.android.launcher3.logger.LauncherAtom.Attribute.SUGGESTED_LABEL;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
@@ -245,13 +247,13 @@ public class FolderInfo extends CollectionInfo {
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public LauncherAtom.ItemInfo buildProto(@Nullable CollectionInfo cInfo) {
|
||||
public LauncherAtom.ItemInfo buildProto(@Nullable CollectionInfo cInfo, Context context) {
|
||||
FolderIcon.Builder folderIcon = FolderIcon.newBuilder()
|
||||
.setCardinality(getContents().size());
|
||||
if (LabelState.SUGGESTED.equals(getLabelState())) {
|
||||
folderIcon.setLabelInfo(title.toString());
|
||||
}
|
||||
return getDefaultItemInfoBuilder()
|
||||
return getDefaultItemInfoBuilder(context)
|
||||
.setFolderIcon(folderIcon)
|
||||
.setRank(rank)
|
||||
.addItemAttributes(getLabelState().mLogAttribute)
|
||||
|
||||
@@ -36,6 +36,7 @@ import static com.android.launcher3.shortcuts.ShortcutKey.EXTRA_SHORTCUT_ID;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Process;
|
||||
@@ -352,16 +353,16 @@ public class ItemInfo {
|
||||
* Creates {@link LauncherAtom.ItemInfo} with important fields and parent container info.
|
||||
*/
|
||||
@NonNull
|
||||
public LauncherAtom.ItemInfo buildProto() {
|
||||
return buildProto(null);
|
||||
public LauncherAtom.ItemInfo buildProto(Context context) {
|
||||
return buildProto(null, context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates {@link LauncherAtom.ItemInfo} with important fields and parent container info.
|
||||
*/
|
||||
@NonNull
|
||||
public LauncherAtom.ItemInfo buildProto(@Nullable final CollectionInfo cInfo) {
|
||||
LauncherAtom.ItemInfo.Builder itemBuilder = getDefaultItemInfoBuilder();
|
||||
public LauncherAtom.ItemInfo buildProto(@Nullable final CollectionInfo cInfo, Context context) {
|
||||
LauncherAtom.ItemInfo.Builder itemBuilder = getDefaultItemInfoBuilder(context);
|
||||
Optional<ComponentName> nullableComponent = Optional.ofNullable(getTargetComponent());
|
||||
switch (itemType) {
|
||||
case ITEM_TYPE_APPLICATION:
|
||||
@@ -434,10 +435,10 @@ public class ItemInfo {
|
||||
}
|
||||
|
||||
@NonNull
|
||||
protected LauncherAtom.ItemInfo.Builder getDefaultItemInfoBuilder() {
|
||||
protected LauncherAtom.ItemInfo.Builder getDefaultItemInfoBuilder(Context context) {
|
||||
LauncherAtom.ItemInfo.Builder itemBuilder = LauncherAtom.ItemInfo.newBuilder();
|
||||
SettingsCache.INSTANCE.executeIfCreated(cache ->
|
||||
itemBuilder.setIsKidsMode(cache.getValue(NAV_BAR_KIDS_MODE, 0)));
|
||||
itemBuilder.setIsKidsMode(
|
||||
SettingsCache.INSTANCE.get(context).getValue(NAV_BAR_KIDS_MODE, 0));
|
||||
UserCache.INSTANCE.executeIfCreated(cache ->
|
||||
itemBuilder.setUserType(getUserType(cache.getUserInfo(user))));
|
||||
itemBuilder.setRank(rank);
|
||||
|
||||
@@ -24,6 +24,7 @@ import static com.android.launcher3.LauncherSettings.Favorites.CONTAINER_WIDGETS
|
||||
|
||||
import android.appwidget.AppWidgetHostView;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Resources;
|
||||
import android.os.Process;
|
||||
@@ -270,8 +271,9 @@ public class LauncherAppWidgetInfo extends ItemInfo {
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public LauncherAtom.ItemInfo buildProto(@Nullable CollectionInfo collectionInfo) {
|
||||
LauncherAtom.ItemInfo info = super.buildProto(collectionInfo);
|
||||
public LauncherAtom.ItemInfo buildProto(
|
||||
@Nullable CollectionInfo collectionInfo, Context context) {
|
||||
LauncherAtom.ItemInfo info = super.buildProto(collectionInfo, context);
|
||||
return info.toBuilder()
|
||||
.setWidget(info.getWidget().toBuilder().setWidgetFeatures(widgetFeatures))
|
||||
.addItemAttributes(getAttribute(sourceContainer))
|
||||
|
||||
@@ -25,14 +25,21 @@ import android.content.Context;
|
||||
import android.database.ContentObserver;
|
||||
import android.net.Uri;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.provider.Settings;
|
||||
|
||||
import com.android.launcher3.dagger.ApplicationContext;
|
||||
import com.android.launcher3.dagger.LauncherAppSingleton;
|
||||
import com.android.launcher3.dagger.LauncherBaseAppComponent;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
* ContentObserver over Settings keys that also has a caching layer.
|
||||
* Consumers can register for callbacks via {@link #register(Uri, OnChangeListener)} and
|
||||
@@ -47,6 +54,7 @@ import java.util.concurrent.CopyOnWriteArrayList;
|
||||
*
|
||||
* Cache will also be updated if a key queried is missing (even if it has no listeners registered).
|
||||
*/
|
||||
@LauncherAppSingleton
|
||||
public class SettingsCache extends ContentObserver implements SafeCloseable {
|
||||
|
||||
/** Hidden field Settings.Secure.NOTIFICATION_BADGING */
|
||||
@@ -79,12 +87,14 @@ public class SettingsCache extends ContentObserver implements SafeCloseable {
|
||||
/**
|
||||
* Singleton instance
|
||||
*/
|
||||
public static MainThreadInitializedObject<SettingsCache> INSTANCE =
|
||||
new MainThreadInitializedObject<>(SettingsCache::new);
|
||||
public static final DaggerSingletonObject<SettingsCache> INSTANCE =
|
||||
new DaggerSingletonObject<>(LauncherBaseAppComponent::getSettingsCache);
|
||||
|
||||
private SettingsCache(Context context) {
|
||||
super(new Handler());
|
||||
@Inject
|
||||
SettingsCache(@ApplicationContext final Context context, DaggerSingletonTracker tracker) {
|
||||
super(new Handler(Looper.getMainLooper()));
|
||||
mResolver = context.getContentResolver();
|
||||
ExecutorUtil.executeSyncOnMainOrFail(() -> tracker.addCloseable(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -82,8 +82,9 @@ public class PendingAddWidgetInfo extends PendingAddItemInfo {
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public LauncherAtom.ItemInfo buildProto(@Nullable CollectionInfo collectionInfo) {
|
||||
LauncherAtom.ItemInfo info = super.buildProto(collectionInfo);
|
||||
public LauncherAtom.ItemInfo buildProto(
|
||||
@Nullable CollectionInfo collectionInfo, Context context) {
|
||||
LauncherAtom.ItemInfo info = super.buildProto(collectionInfo, context);
|
||||
return info.toBuilder()
|
||||
.addItemAttributes(LauncherAppWidgetInfo.getAttribute(sourceContainer))
|
||||
.build();
|
||||
|
||||
Reference in new issue
Block a user