Merge "Clean up unused clock code" into udc-dev
diff --git a/res/layout/clock_option.xml b/res/layout/clock_option.xml
deleted file mode 100644
index e65cb65..0000000
--- a/res/layout/clock_option.xml
+++ /dev/null
@@ -1,46 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
- Copyright (C) 2019 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.
--->
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:paddingRight="2dp"
- android:paddingBottom="@dimen/option_bottom_margin"
- android:clipChildren="false"
- android:clipToPadding="false"
- android:orientation="vertical">
-
- <TextView
- android:id="@+id/option_label"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="center_horizontal"
- android:layout_marginBottom="@dimen/theme_option_label_margin"
- android:textAppearance="@style/OptionTitleTextAppearance"/>
- <FrameLayout
- android:id="@+id/option_tile"
- android:layout_width="@dimen/option_tile_width"
- android:layout_height="@dimen/option_tile_width"
- android:layout_gravity="center_horizontal"
- android:paddingHorizontal="@dimen/option_tile_padding_horizontal"
- android:paddingVertical="@dimen/option_tile_padding_vertical"
- android:background="@drawable/option_border">
- <ImageView
- android:id="@+id/clock_option_thumbnail"
- android:layout_width="match_parent"
- android:layout_height="match_parent"/>
- </FrameLayout>
-</LinearLayout>
diff --git a/src/com/android/customization/model/clock/BaseClockManager.java b/src/com/android/customization/model/clock/BaseClockManager.java
deleted file mode 100644
index 3434780..0000000
--- a/src/com/android/customization/model/clock/BaseClockManager.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Copyright (C) 2019 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.customization.model.clock;
-
-import com.android.customization.model.CustomizationManager;
-
-/**
- * {@link CustomizationManager} for clock faces.
- */
-public abstract class BaseClockManager implements CustomizationManager<Clockface> {
-
- private final ClockProvider mClockProvider;
-
- public BaseClockManager(ClockProvider provider) {
- mClockProvider = provider;
- }
-
- @Override
- public boolean isAvailable() {
- return mClockProvider.isAvailable();
- }
-
- @Override
- public void apply(Clockface option, Callback callback) {
- handleApply(option, callback);
- }
-
- @Override
- public void fetchOptions(OptionsFetchedListener<Clockface> callback, boolean reload) {
- mClockProvider.fetch(callback, false);
- }
-
- /** Returns the ID of the current clock face, which may be null for the default clock face. */
- String getCurrentClock() {
- return lookUpCurrentClock();
- }
-
- /**
- * Implement to apply the clock picked by the user for {@link BaseClockManager#apply}.
- *
- * @param option Clock option, containing ID of the clock, that the user picked.
- * @param callback Report success and failure.
- */
- protected abstract void handleApply(Clockface option, Callback callback);
-
- /**
- * Implement to look up the current clock face for {@link BaseClockManager#getCurrentClock()}.
- *
- * @return ID of current clock. Can be null for the default clock face.
- */
- protected abstract String lookUpCurrentClock();
-}
diff --git a/src/com/android/customization/model/clock/ClockManager.java b/src/com/android/customization/model/clock/ClockManager.java
deleted file mode 100644
index 4e77a49..0000000
--- a/src/com/android/customization/model/clock/ClockManager.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * Copyright (C) 2019 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.customization.model.clock;
-
-import android.content.ContentResolver;
-import android.provider.Settings.Secure;
-import android.text.TextUtils;
-
-import com.android.customization.module.ThemesUserEventLogger;
-
-import org.json.JSONException;
-import org.json.JSONObject;
-
-/**
- * {@link CustomizationManager} for clock faces that implements apply by writing to secure settings.
- */
-public class ClockManager extends BaseClockManager {
-
- // TODO: use constant from Settings.Secure
- static final String CLOCK_FACE_SETTING = "lock_screen_custom_clock_face";
- private static final String CLOCK_FIELD = "clock";
- private static final String TIMESTAMP_FIELD = "_applied_timestamp";
- private final ContentResolver mContentResolver;
- private final ThemesUserEventLogger mEventLogger;
-
- public ClockManager(ContentResolver resolver, ClockProvider provider,
- ThemesUserEventLogger logger) {
- super(provider);
- mContentResolver = resolver;
- mEventLogger = logger;
- }
-
- @Override
- protected void handleApply(Clockface option, Callback callback) {
- boolean stored;
- try {
- final JSONObject json = new JSONObject();
- json.put(CLOCK_FIELD, option.getId());
- json.put(TIMESTAMP_FIELD, System.currentTimeMillis());
- stored = Secure.putString(mContentResolver, CLOCK_FACE_SETTING, json.toString());
- } catch (JSONException ex) {
- stored = false;
- }
- if (stored) {
- mEventLogger.logClockApplied(option);
- callback.onSuccess();
- } else {
- callback.onError(null);
- }
- }
-
- @Override
- protected String lookUpCurrentClock() {
- final String value = Secure.getString(mContentResolver, CLOCK_FACE_SETTING);
- if (TextUtils.isEmpty(value)) {
- return value;
- }
- try {
- final JSONObject json = new JSONObject(value);
- return json.getString(CLOCK_FIELD);
- } catch (JSONException ex) {
- return value;
- }
- }
-}
diff --git a/src/com/android/customization/model/clock/ClockProvider.java b/src/com/android/customization/model/clock/ClockProvider.java
deleted file mode 100644
index d9a6779..0000000
--- a/src/com/android/customization/model/clock/ClockProvider.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Copyright (C) 2019 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.customization.model.clock;
-
-import com.android.customization.model.CustomizationManager.OptionsFetchedListener;
-
-/**
- * Interface for a class that can retrieve Themes from the system.
- */
-public interface ClockProvider {
- /**
- * Returns whether clockfaces are available in the current setup.
- */
- boolean isAvailable();
-
- /**
- * Retrieve the available clockfaces.
- * @param callback called when the clockfaces have been retrieved (or immediately if cached)
- * @param reload whether to reload clockfaces if they're cached.
- */
- void fetch(OptionsFetchedListener<Clockface> callback, boolean reload);
-}
diff --git a/src/com/android/customization/model/clock/Clockface.java b/src/com/android/customization/model/clock/Clockface.java
deleted file mode 100644
index 9bdcaef..0000000
--- a/src/com/android/customization/model/clock/Clockface.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * Copyright (C) 2019 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.customization.model.clock;
-
-import android.text.TextUtils;
-import android.view.View;
-import android.widget.ImageView;
-
-import com.android.customization.model.CustomizationManager;
-import com.android.customization.model.CustomizationOption;
-import com.android.wallpaper.R;
-import com.android.wallpaper.asset.Asset;
-
-public class Clockface implements CustomizationOption<Clockface> {
-
- private final String mTitle;
- private final String mId;
- private final Asset mPreview;
- private final Asset mThumbnail;
-
- private Clockface(String title, String id, Asset preview, Asset thumbnail) {
- mTitle = title;
- mId = id;
- mPreview = preview;
- mThumbnail = thumbnail;
- }
-
- @Override
- public String getTitle() {
- return mTitle;
- }
-
- @Override
- public void bindThumbnailTile(View view) {
- ImageView thumbView = view.findViewById(R.id.clock_option_thumbnail);
- mThumbnail.loadDrawableWithTransition(thumbView.getContext(), thumbView, 50, null,
- thumbView.getResources().getColor(android.R.color.transparent, null));
- }
-
- @Override
- public boolean isActive(CustomizationManager<Clockface> manager) {
- String currentClock = ((BaseClockManager) manager).getCurrentClock();
- // Empty clock Id is the default system clock
- return (TextUtils.isEmpty(currentClock) && TextUtils.isEmpty(mId))
- || (mId != null && mId.equals(currentClock));
- }
-
- @Override
- public int getLayoutResId() {
- return R.layout.clock_option;
- }
-
- public Asset getPreviewAsset() {
- return mPreview;
- }
-
- public String getId() {
- return mId;
- }
-
- public static class Builder {
- private String mTitle;
- private String mId;
- private Asset mPreview;
- private Asset mThumbnail;
-
- public Clockface build() {
- return new Clockface(mTitle, mId, mPreview, mThumbnail);
- }
-
- public Builder setTitle(String title) {
- mTitle = title;
- return this;
- }
-
- public Builder setId(String id) {
- mId = id;
- return this;
- }
-
- public Builder setPreview(Asset preview) {
- mPreview = preview;
- return this;
- }
-
- public Builder setThumbnail(Asset thumbnail) {
- mThumbnail = thumbnail;
- return this;
- }
- }
-}
diff --git a/src/com/android/customization/model/clock/ContentProviderClockProvider.java b/src/com/android/customization/model/clock/ContentProviderClockProvider.java
deleted file mode 100644
index f0df031..0000000
--- a/src/com/android/customization/model/clock/ContentProviderClockProvider.java
+++ /dev/null
@@ -1,135 +0,0 @@
-package com.android.customization.model.clock;
-
-import android.content.ContentResolver;
-import android.content.Context;
-import android.content.pm.ApplicationInfo;
-import android.content.pm.PackageManager;
-import android.content.pm.PackageManager.NameNotFoundException;
-import android.content.pm.ProviderInfo;
-import android.database.Cursor;
-import android.net.Uri;
-import android.os.Handler;
-import android.os.Looper;
-import android.text.TextUtils;
-import android.util.Log;
-
-import com.android.customization.model.CustomizationManager.OptionsFetchedListener;
-import com.android.customization.model.clock.Clockface.Builder;
-import com.android.wallpaper.R;
-import com.android.wallpaper.asset.ContentUriAsset;
-
-import com.bumptech.glide.Glide;
-import com.bumptech.glide.request.RequestOptions;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-
-public class ContentProviderClockProvider implements ClockProvider {
-
- private static final String TAG = "ContentProviderClockProvider";
- private static final ExecutorService sExecutorService = Executors.newSingleThreadExecutor();
- private static final String LIST_OPTIONS = "list_options";
- private static final String COL_TITLE = "title";
- private static final String COL_ID = "id";
- private static final String COL_THUMBNAIL = "thumbnail";
- private static final String COL_PREVIEW = "preview";
-
- private final Context mContext;
- private final ProviderInfo mProviderInfo;
- private List<Clockface> mClocks;
- private boolean mClockContentAvailable;
-
- public ContentProviderClockProvider(Context context) {
- mContext = context;
- String providerAuthority = mContext.getString(R.string.clocks_provider_authority);
- // TODO: check permissions if needed
- mProviderInfo = TextUtils.isEmpty(providerAuthority) ? null
- : mContext.getPackageManager().resolveContentProvider(providerAuthority,
- PackageManager.MATCH_SYSTEM_ONLY);
-
- if (TextUtils.isEmpty(mContext.getString(R.string.clocks_stub_package))) {
- mClockContentAvailable = false;
- } else {
- try {
- ApplicationInfo applicationInfo = mContext.getPackageManager().getApplicationInfo(
- mContext.getString(R.string.clocks_stub_package),
- PackageManager.MATCH_SYSTEM_ONLY);
- mClockContentAvailable = applicationInfo != null;
- } catch (NameNotFoundException e) {
- mClockContentAvailable = false;
- }
- }
- }
-
- @Override
- public boolean isAvailable() {
- return mProviderInfo != null && mClockContentAvailable
- && (mClocks == null || !mClocks.isEmpty());
- }
-
- @Override
- public void fetch(OptionsFetchedListener<Clockface> callback, boolean reload) {
- if (!isAvailable()) {
- if (callback != null) {
- callback.onError(null);
- }
- return;
- }
- if (mClocks != null && !reload) {
- if (callback != null) {
- if (!mClocks.isEmpty()) {
- callback.onOptionsLoaded(mClocks);
- } else {
- callback.onError(null);
- }
- }
- return;
- }
- sExecutorService.submit(() -> {
- Uri optionsUri = new Uri.Builder()
- .scheme(ContentResolver.SCHEME_CONTENT)
- .authority(mProviderInfo.authority)
- .appendPath(LIST_OPTIONS)
- .build();
-
- ContentResolver resolver = mContext.getContentResolver();
-
- List<Clockface> clockfaces = new ArrayList<>();
- try (Cursor c = resolver.query(optionsUri, null, null, null, null)) {
- while (c != null && c.moveToNext()) {
- String id = c.getString(c.getColumnIndex(COL_ID));
- String title = c.getString(c.getColumnIndex(COL_TITLE));
- String thumbnailUri = c.getString(c.getColumnIndex(COL_THUMBNAIL));
- String previewUri = c.getString(c.getColumnIndex(COL_PREVIEW));
- Uri thumbnail = Uri.parse(thumbnailUri);
- Uri preview = Uri.parse(previewUri);
-
- Clockface.Builder builder = new Builder();
- builder.setId(id).setTitle(title)
- .setThumbnail(new ContentUriAsset(mContext, thumbnail,
- RequestOptions.fitCenterTransform()))
- .setPreview(new ContentUriAsset(mContext, preview,
- RequestOptions.fitCenterTransform()));
- clockfaces.add(builder.build());
- }
- Glide.get(mContext).clearDiskCache();
- } catch (Exception e) {
- clockfaces = null;
- Log.e(TAG, "Failed to query clock face options.", e);
- }
- final List<Clockface> clockfaceList = clockfaces;
- new Handler(Looper.getMainLooper()).post(() -> {
- mClocks = clockfaceList;
- if (callback != null) {
- if (!mClocks.isEmpty()) {
- callback.onOptionsLoaded(mClocks);
- } else {
- callback.onError(null);
- }
- }
- });
- });
- }
-}
diff --git a/src/com/android/customization/model/clock/custom/ClockCustomManager.java b/src/com/android/customization/model/clock/custom/ClockCustomManager.java
deleted file mode 100644
index 0815a3e..0000000
--- a/src/com/android/customization/model/clock/custom/ClockCustomManager.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright (C) 2022 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.customization.model.clock.custom;
-
-import com.android.customization.model.CustomizationManager;
-
-import com.google.common.collect.Lists;
-
-/**
- * {@link CustomizationManager} for clock faces.
- */
-public class ClockCustomManager implements CustomizationManager<ClockOption> {
- @Override
- public boolean isAvailable() {
- return true;
- }
-
- @Override
- public void apply(ClockOption option, Callback callback) {
- // TODO(/b241966062) execute applying the clock when user selects a clock
- }
-
- @Override
- public void fetchOptions(OptionsFetchedListener<ClockOption> callback, boolean reload) {
- // TODO(/b241966062) fetch the real clock metadata from the ClockRegistry
- callback.onOptionsLoaded(
- Lists.newArrayList(new ClockOption(), new ClockOption(), new ClockOption(),
- new ClockOption(), new ClockOption()));
- }
-}
diff --git a/src/com/android/customization/model/clock/custom/ClockOption.java b/src/com/android/customization/model/clock/custom/ClockOption.java
deleted file mode 100644
index 5a9f051..0000000
--- a/src/com/android/customization/model/clock/custom/ClockOption.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright (C) 2022 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.customization.model.clock.custom;
-
-import android.view.View;
-
-import com.android.customization.model.CustomizationManager;
-import com.android.customization.model.CustomizationOption;
-import com.android.wallpaper.R;
-
-/**
- * {@link CustomizationOption} for a clock face.
- */
-public class ClockOption implements CustomizationOption<ClockOption> {
-
- @Override
- public String getTitle() {
- // TODO(/b241966062) use the title from the clock metadata
- return "title";
- }
-
- @Override
- public void bindThumbnailTile(View view) {
- // TODO(/b241966062) bind the thumbnail
- }
-
- @Override
- public boolean isActive(CustomizationManager<ClockOption> manager) {
- return false;
- }
-
-
- @Override
- public int getLayoutResId() {
- return R.layout.clock_option;
- }
-}
diff --git a/src/com/android/customization/module/StatsLogUserEventLogger.java b/src/com/android/customization/module/StatsLogUserEventLogger.java
index 9645454..32e0599 100644
--- a/src/com/android/customization/module/StatsLogUserEventLogger.java
+++ b/src/com/android/customization/module/StatsLogUserEventLogger.java
@@ -44,7 +44,6 @@
import androidx.annotation.Nullable;
-import com.android.customization.model.clock.Clockface;
import com.android.customization.model.color.ColorOption;
import com.android.customization.model.grid.GridOption;
import com.android.customization.model.theme.ThemeBundle;
@@ -237,22 +236,6 @@
}
@Override
- public void logClockSelected(Clockface clock) {
- new SysUiStatsLogger()
- .setAction(StyleEnums.PICKER_SELECT)
- .setClockPackageHash(Objects.hashCode(clock.getId()))
- .log();
- }
-
- @Override
- public void logClockApplied(Clockface clock) {
- new SysUiStatsLogger()
- .setAction(StyleEnums.PICKER_APPLIED)
- .setClockPackageHash(Objects.hashCode(clock.getId()))
- .log();
- }
-
- @Override
public void logGridSelected(GridOption grid) {
new SysUiStatsLogger()
.setAction(StyleEnums.PICKER_SELECT)
diff --git a/src/com/android/customization/module/ThemesUserEventLogger.java b/src/com/android/customization/module/ThemesUserEventLogger.java
index 3e5bb54..b1a87b9 100644
--- a/src/com/android/customization/module/ThemesUserEventLogger.java
+++ b/src/com/android/customization/module/ThemesUserEventLogger.java
@@ -15,7 +15,6 @@
*/
package com.android.customization.module;
-import com.android.customization.model.clock.Clockface;
import com.android.customization.model.color.ColorOption;
import com.android.customization.model.grid.GridOption;
import com.android.customization.model.theme.ThemeBundle;
@@ -38,10 +37,6 @@
*/
void logColorApplied(int action, ColorOption colorOption);
- void logClockSelected(Clockface clock);
-
- void logClockApplied(Clockface clock);
-
void logGridSelected(GridOption grid);
void logGridApplied(GridOption grid);
diff --git a/tests/robotests/src/com/android/customization/model/clock/BaseClockManagerTest.java b/tests/robotests/src/com/android/customization/model/clock/BaseClockManagerTest.java
deleted file mode 100644
index 2b80bde..0000000
--- a/tests/robotests/src/com/android/customization/model/clock/BaseClockManagerTest.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * Copyright (C) 2019 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.customization.model.clock;
-
-import static junit.framework.TestCase.assertTrue;
-import static junit.framework.TestCase.fail;
-
-import static org.junit.Assert.assertEquals;
-import static org.mockito.Mockito.anyBoolean;
-import static org.mockito.Mockito.eq;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import androidx.annotation.Nullable;
-
-import com.android.customization.model.CustomizationManager.Callback;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-import org.robolectric.RobolectricTestRunner;
-
-@RunWith(RobolectricTestRunner.class)
-public class BaseClockManagerTest {
-
- private static final String CURRENT_CLOCK = "current_clock";
-
- @Mock ClockProvider mProvider;
- private TestClockManager mManager;
-
- @Before
- public void setUp() {
- MockitoAnnotations.initMocks(this);
- mManager = new TestClockManager(mProvider);
- }
-
- @Test
- public void testIsAvailable() {
- // GIVEN that the ClockProvider is available
- when(mProvider.isAvailable()).thenReturn(true);
- // THEN the BaseClockManager is true
- assertTrue(mManager.isAvailable());
- }
-
- @Test
- public void testApply() {
- final String id = "id";
- Clockface clock = new Clockface.Builder().setId(id).build();
-
- mManager.apply(clock, new Callback() {
- @Override
- public void onSuccess() {
- //Nothing to do here, the test passed
- }
- @Override
- public void onError(@Nullable Throwable throwable) {
- fail("onError was called when grid had been applied successfully");
- }
- });
-
- assertEquals(id, mManager.getClockId());
- }
-
- @Test
- public void testFetch() {
- mManager.fetchOptions(null, false);
- verify(mProvider).fetch(eq(null), anyBoolean());
- }
-
- /**
- * Testable BaseClockManager that provides basic implementations of abstract methods.
- */
- private static final class TestClockManager extends BaseClockManager {
-
- private String mClockId;
-
- TestClockManager(ClockProvider provider) {
- super(provider);
- }
-
- String getClockId() {
- return mClockId;
- }
-
- @Override
- protected void handleApply(Clockface option, Callback callback) {
- mClockId = option.getId();
- callback.onSuccess();
- }
-
- @Override
- protected String lookUpCurrentClock() {
- return CURRENT_CLOCK;
- }
- }
-}
diff --git a/tests/robotests/src/com/android/customization/model/clock/ClockManagerTest.java b/tests/robotests/src/com/android/customization/model/clock/ClockManagerTest.java
deleted file mode 100644
index 574548a..0000000
--- a/tests/robotests/src/com/android/customization/model/clock/ClockManagerTest.java
+++ /dev/null
@@ -1,134 +0,0 @@
-/*
- * Copyright (C) 2019 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.customization.model.clock;
-
-import static junit.framework.TestCase.fail;
-
-import static org.junit.Assert.assertEquals;
-import static org.mockito.Mockito.doAnswer;
-import static org.mockito.Mockito.verify;
-
-import android.content.ContentResolver;
-import android.provider.Settings.Secure;
-
-import androidx.annotation.Nullable;
-
-import com.android.customization.model.CustomizationManager.Callback;
-import com.android.customization.module.ThemesUserEventLogger;
-
-import org.json.JSONException;
-import org.json.JSONObject;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-import org.robolectric.RobolectricTestRunner;
-import org.robolectric.RuntimeEnvironment;
-
-@RunWith(RobolectricTestRunner.class)
-public class ClockManagerTest {
-
- private static final String CLOCK_ID = "id";
- private static final String CLOCK_FIELD = "clock";
- private static final String CLOCK_FACE_SETTING = "fake_clock_face_setting";
-
- @Mock ClockProvider mProvider;
- @Mock ThemesUserEventLogger mLogger;
- private ContentResolver mContentResolver;
- private ClockManager mManager;
- @Mock private Clockface mMockClockface;
- @Mock private Callback mMockCallback;
-
- @Before
- public void setUp() {
- MockitoAnnotations.initMocks(this);
- mContentResolver = RuntimeEnvironment.application.getContentResolver();
- mManager = new ClockManager(mContentResolver, mProvider, mLogger);
- }
-
- @Test
- public void testApply() throws JSONException {
- Clockface clock = new Clockface.Builder().setId(CLOCK_ID).build();
-
- mManager.apply(clock, new Callback() {
- @Override
- public void onSuccess() {
- //Nothing to do here, the test passed
- }
-
- @Override
- public void onError(@Nullable Throwable throwable) {
- fail("onError was called when grid had been applied successfully");
- }
- });
-
- // THEN the clock id is written to secure settings.
- JSONObject json =
- new JSONObject(Secure.getString(mContentResolver, ClockManager.CLOCK_FACE_SETTING));
- assertEquals(CLOCK_ID, json.getString(CLOCK_FIELD));
- // AND the event is logged
- verify(mLogger).logClockApplied(clock);
- }
-
- @Test
- public void testApply_whenJSONExceptionOccurs_callsOnError() {
- doAnswer((invocation) -> {
- throw new JSONException("Fake Test Excepton");
- }).when(mMockClockface).getId();
-
- mManager.apply(mMockClockface, mMockCallback);
-
- verify(mMockCallback).onError(null);
- }
-
- @Test
- public void testGetCurrentClock_returnsClockId() throws JSONException {
- // Secure settings contains a clock id
- JSONObject json = new JSONObject().put(CLOCK_FIELD, CLOCK_ID);
- Secure.putString(mContentResolver, ClockManager.CLOCK_FACE_SETTING, json.toString());
-
- // The current clock is that id
- assertEquals(CLOCK_ID, mManager.getCurrentClock());
- }
-
- @Test
- public void testGetCurrentClock_whenJSONExceptionOccurs_returnsClockFaceSetting() {
- // Secure settings contains a clock face setting with invalid format to cause JSONException.
- Secure.putString(mContentResolver, ClockManager.CLOCK_FACE_SETTING, CLOCK_FACE_SETTING);
-
- // The current clock is the clock face setting which is saved in secure settings.
- assertEquals(CLOCK_FACE_SETTING, mManager.getCurrentClock());
- }
-
- @Test
- public void testGetCurrentClock_withNullIdInSecureSettings_returnsNullId() {
- // Secure settings contains a null clock id
- Secure.putString(mContentResolver, ClockManager.CLOCK_FACE_SETTING, /* value= */ null);
-
- // The current clock is null
- assertEquals(null, mManager.getCurrentClock());
- }
-
- @Test
- public void testGetCurrentClock_withEmptyIdInSecureSettings_returnsEmptyId() {
- // Secure settings contains an empty clock id
- Secure.putString(mContentResolver, ClockManager.CLOCK_FACE_SETTING, /* value= */ "");
-
- // The current clock is empty
- assertEquals("", mManager.getCurrentClock());
- }
-}
diff --git a/tests/src/com/android/customization/testing/TestThemesUserEventLogger.java b/tests/src/com/android/customization/testing/TestThemesUserEventLogger.java
index 9250a86..2bb2082 100644
--- a/tests/src/com/android/customization/testing/TestThemesUserEventLogger.java
+++ b/tests/src/com/android/customization/testing/TestThemesUserEventLogger.java
@@ -1,6 +1,5 @@
package com.android.customization.testing;
-import com.android.customization.model.clock.Clockface;
import com.android.customization.model.color.ColorOption;
import com.android.customization.model.grid.GridOption;
import com.android.customization.model.theme.ThemeBundle;
@@ -28,16 +27,6 @@
}
@Override
- public void logClockSelected(Clockface clock) {
- // Do nothing.
- }
-
- @Override
- public void logClockApplied(Clockface clock) {
- // Do nothing.
- }
-
- @Override
public void logGridSelected(GridOption grid) {
// Do nothing.
}