• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.settings.testutils;
18 
19 import static android.provider.Settings.ACTION_BEDTIME_SETTINGS;
20 import static android.util.FeatureFlagUtils.SETTINGS_APP_ALLOW_DARK_THEME_ACTIVATION_AT_BEDTIME;
21 
22 import static org.robolectric.Shadows.shadowOf;
23 
24 import android.content.Context;
25 import android.content.Intent;
26 import android.content.pm.ActivityInfo;
27 import android.content.pm.ApplicationInfo;
28 import android.content.pm.ResolveInfo;
29 import android.util.FeatureFlagUtils;
30 
31 /** A helper class for installing bedtime settings activity. */
32 public final class BedtimeSettingsUtils {
33     private Context mContext;
34 
BedtimeSettingsUtils(Context context)35     public BedtimeSettingsUtils(Context context) {
36         mContext = context;
37     }
38 
installBedtimeSettings(String wellbeingPackage, boolean enabled)39     public void installBedtimeSettings(String wellbeingPackage, boolean enabled) {
40         FeatureFlagUtils.setEnabled(mContext, SETTINGS_APP_ALLOW_DARK_THEME_ACTIVATION_AT_BEDTIME,
41                 true /* enabled */);
42         Intent bedtimeSettingsIntent = new Intent(ACTION_BEDTIME_SETTINGS)
43                 .setPackage(wellbeingPackage);
44         ResolveInfo bedtimeResolveInfo = new ResolveInfo();
45         bedtimeResolveInfo.activityInfo = new ActivityInfo();
46         bedtimeResolveInfo.activityInfo.name = "BedtimeSettings";
47         bedtimeResolveInfo.activityInfo.packageName = "wellbeing";
48         bedtimeResolveInfo.activityInfo.enabled = enabled;
49         bedtimeResolveInfo.activityInfo.applicationInfo = new ApplicationInfo();
50         bedtimeResolveInfo.activityInfo.applicationInfo.enabled = true;
51         shadowOf(mContext.getPackageManager()).addResolveInfoForIntent(
52                 bedtimeSettingsIntent, bedtimeResolveInfo);
53     }
54 }
55