Add injection to ClockProvider.
Removes Dependency.get from ClockProvider. Bug: 179775696 Test: atest SystemUITests Change-Id: I730593fcf5cf8d8d969990eccfc0297efd1eb56b
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright (C) 2021 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.keyguard.clock;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
|
||||
/** Dagger Module for clock package. */
|
||||
@Module
|
||||
public abstract class ClockModule {
|
||||
|
||||
/** */
|
||||
@Provides
|
||||
public static List<ClockInfo> provideClockInfoList(ClockManager clockManager) {
|
||||
return clockManager.getClockInfos();
|
||||
}
|
||||
}
|
||||
@@ -28,11 +28,12 @@ import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.systemui.Dependency;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Provider;
|
||||
|
||||
/**
|
||||
* Exposes custom clock face options and provides realistic preview images.
|
||||
@@ -65,15 +66,12 @@ public final class ClockOptionsProvider extends ContentProvider {
|
||||
private static final String CONTENT_SCHEME = "content";
|
||||
private static final String AUTHORITY = "com.android.keyguard.clock";
|
||||
|
||||
private final Supplier<List<ClockInfo>> mClocksSupplier;
|
||||
|
||||
public ClockOptionsProvider() {
|
||||
this(() -> Dependency.get(ClockManager.class).getClockInfos());
|
||||
}
|
||||
@Inject
|
||||
public Provider<List<ClockInfo>> mClockInfosProvider;
|
||||
|
||||
@VisibleForTesting
|
||||
ClockOptionsProvider(Supplier<List<ClockInfo>> clocksSupplier) {
|
||||
mClocksSupplier = clocksSupplier;
|
||||
ClockOptionsProvider(Provider<List<ClockInfo>> clockInfosProvider) {
|
||||
mClockInfosProvider = clockInfosProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -99,7 +97,7 @@ public final class ClockOptionsProvider extends ContentProvider {
|
||||
}
|
||||
MatrixCursor cursor = new MatrixCursor(new String[] {
|
||||
COLUMN_NAME, COLUMN_TITLE, COLUMN_ID, COLUMN_THUMBNAIL, COLUMN_PREVIEW});
|
||||
List<ClockInfo> clocks = mClocksSupplier.get();
|
||||
List<ClockInfo> clocks = mClockInfosProvider.get();
|
||||
for (int i = 0; i < clocks.size(); i++) {
|
||||
ClockInfo clock = clocks.get(i);
|
||||
cursor.newRow()
|
||||
@@ -139,7 +137,7 @@ public final class ClockOptionsProvider extends ContentProvider {
|
||||
throw new FileNotFoundException("Invalid preview url, missing id");
|
||||
}
|
||||
ClockInfo clock = null;
|
||||
List<ClockInfo> clocks = mClocksSupplier.get();
|
||||
List<ClockInfo> clocks = mClockInfosProvider.get();
|
||||
for (int i = 0; i < clocks.size(); i++) {
|
||||
if (id.equals(clocks.get(i).getId())) {
|
||||
clock = clocks.get(i);
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.android.systemui.dagger;
|
||||
|
||||
import com.android.keyguard.clock.ClockOptionsProvider;
|
||||
import com.android.systemui.BootCompleteCacheImpl;
|
||||
import com.android.systemui.Dependency;
|
||||
import com.android.systemui.InitController;
|
||||
@@ -146,4 +147,9 @@ public interface SysUIComponent {
|
||||
* Member injection into the supplied argument.
|
||||
*/
|
||||
void inject(KeyguardSliceProvider keyguardSliceProvider);
|
||||
|
||||
/**
|
||||
* Member injection into the supplied argument.
|
||||
*/
|
||||
void inject(ClockOptionsProvider clockOptionsProvider);
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import android.content.Context;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.android.internal.statusbar.IStatusBarService;
|
||||
import com.android.keyguard.clock.ClockModule;
|
||||
import com.android.keyguard.dagger.KeyguardBouncerComponent;
|
||||
import com.android.systemui.BootCompleteCache;
|
||||
import com.android.systemui.BootCompleteCacheImpl;
|
||||
@@ -90,6 +91,7 @@ import dagger.Provides;
|
||||
@Module(includes = {
|
||||
AppOpsModule.class,
|
||||
AssistModule.class,
|
||||
ClockModule.class,
|
||||
ControlsModule.class,
|
||||
DemoModeModule.class,
|
||||
FalsingModule.class,
|
||||
|
||||
Reference in New Issue
Block a user