Add dark theme custom type into the dark theme settings page

Also fix some test cases.

I'd prefer using Robolectric shadows rather than mocking Android
framework classes. However, I can't do that in this CL due to the
lack of multiple shadow classes support.

Test: make RunSettingsRoboTests -j56
      ROBOTEST_FILTER=com.android.settings.display.darkmode.*
Bug: 215182463
Change-Id: If557d2933927a5dd0fadd3f6db6bb6f0ab7dd5ee
This commit is contained in:
Steven Ng
2022-01-17 17:25:50 +00:00
parent 0128837312
commit 3859251be0
16 changed files with 698 additions and 108 deletions

View File

@@ -0,0 +1,50 @@
/*
* 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.settings.testutils;
import static com.android.settings.display.darkmode.BedtimeSettings.ACTION_BEDTIME_SETTINGS;
import static org.robolectric.Shadows.shadowOf;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.ApplicationInfo;
import android.content.pm.ResolveInfo;
/** A helper class for installing bedtime settings activity. */
public final class BedtimeSettingsUtils {
private Context mContext;
public BedtimeSettingsUtils(Context context) {
mContext = context;
}
public void installBedtimeSettings(String wellbeingPackage, boolean enabled) {
Intent bedtimeSettingsIntent = new Intent(ACTION_BEDTIME_SETTINGS)
.setPackage(wellbeingPackage);
ResolveInfo bedtimeResolveInfo = new ResolveInfo();
bedtimeResolveInfo.activityInfo = new ActivityInfo();
bedtimeResolveInfo.activityInfo.name = "BedtimeSettings";
bedtimeResolveInfo.activityInfo.packageName = "wellbeing";
bedtimeResolveInfo.activityInfo.enabled = enabled;
bedtimeResolveInfo.activityInfo.applicationInfo = new ApplicationInfo();
bedtimeResolveInfo.activityInfo.applicationInfo.enabled = true;
shadowOf(mContext.getPackageManager()).addResolveInfoForIntent(
bedtimeSettingsIntent, bedtimeResolveInfo);
}
}