1 /*
2  * Copyright (C) 2021 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.homepage;
18 
19 import static com.google.common.truth.Truth.assertThat;
20 import static com.google.common.truth.Truth.assert_;
21 
22 import android.app.Instrumentation;
23 import android.content.ComponentName;
24 import android.content.Intent;
25 import android.provider.Settings;
26 import android.util.Log;
27 
28 import androidx.test.ext.junit.runners.AndroidJUnit4;
29 import androidx.test.filters.SmallTest;
30 import androidx.test.platform.app.InstrumentationRegistry;
31 
32 import com.google.common.collect.ImmutableList;
33 
34 import org.junit.Test;
35 import org.junit.runner.RunWith;
36 
37 import java.util.List;
38 
39 @RunWith(AndroidJUnit4.class)
40 @SmallTest
41 public class HomepageComponentTest {
42     public final String TAG = this.getClass().getSimpleName();
43 
44     private final Instrumentation mInstrumentation = InstrumentationRegistry.getInstrumentation();
45 
46     @Test
test_launch_all_settings_in_home()47     public void test_launch_all_settings_in_home()
48             throws ClassNotFoundException {
49 
50         List<Intent> launchIntents = ImmutableList.of(
51 
52                 // Wifi
53                 // Implemented in WifiSettings2ActivityTest
54 
55                 // Connected devices
56                 new Intent(Settings.ACTION_BLUETOOTH_SETTINGS),
57 
58                 // Applications
59                 new Intent(Settings.ACTION_AUTO_ROTATE_SETTINGS),
60 
61                 // Notifications
62                 new Intent(Settings.ACTION_NOTIFICATION_SETTINGS),
63 
64                 // Display
65                 new Intent(Settings.ACTION_DISPLAY_SETTINGS),
66 
67                 // Battery
68                 // Implemented in fuelgauge.batterysaver
69 
70                 // Storage
71                 new Intent(Settings.ACTION_INTERNAL_STORAGE_SETTINGS),
72 
73                 // Sound
74                 new Intent(Settings.ACTION_SOUND_SETTINGS),
75 
76                 // Display
77                 new Intent(Settings.ACTION_DISPLAY_SETTINGS),
78 
79                 // Wallpaper
80                 new Intent(mInstrumentation.getTargetContext(), Class.forName(
81                         "com.android.settings.wallpaper.WallpaperSuggestionActivity")),
82 
83                 // A11y
84                 new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS),
85 
86                 // Security
87                 new Intent(Settings.ACTION_SECURITY_SETTINGS),
88 
89                 // Privacy
90                 new Intent(Settings.ACTION_PRIVACY_SETTINGS),
91 
92                 // Location
93                 new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS),
94 
95                 // Emergency ? EmergencyDashboardFragment
96                 // TODO: find out launch method
97 
98                 // Password & Account
99                 new Intent(Settings.ACTION_SYNC_SETTINGS),
100 
101                 // Digital wellbeing
102                 // Use IA link
103                 new Intent().setComponent(
104                         new ComponentName(
105                                 "com.google.android.apps.wellbeing",
106                                 "com.google.android.apps.wellbeing.settings"
107                                         + ".TopLevelSettingsActivity")),
108 
109                 // Google
110                 // Use IA link
111                 new Intent().setComponent(
112                         new ComponentName(
113                                 "com.google.android.gms",
114                                 "com.google.android.gms.app.settings.GoogleSettingsIALink")),
115 
116                 // System ?
117                 // TODO: find out launch method.
118 
119                 // About
120                 new Intent(Settings.ACTION_DEVICE_INFO_SETTINGS)
121 
122         );
123 
124         for (Intent intent : launchIntents) {
125             Log.d(TAG, "Start to launch intent " + intent.getAction());
126             try {
127                 mInstrumentation.getTargetContext()
128                         .startActivity(intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
129             } catch (Exception e) {
130                 Log.e(TAG, "Launch with exception. " + e.toString());
131                 assert_().fail();
132             }
133             // Launch success without exception.
134             assertThat(Boolean.TRUE).isTrue();
135         }
136     }
137 }
138