1 /*
2  * Copyright (C) 2020 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.car.settings.common;
18 
19 import android.annotation.Nullable;
20 import android.content.Intent;
21 import android.net.Uri;
22 import android.os.UserHandle;
23 import android.os.UserManager;
24 import android.provider.Settings;
25 import android.text.TextUtils;
26 
27 import androidx.fragment.app.Fragment;
28 
29 import com.android.car.settings.accounts.AccountSettingsFragment;
30 import com.android.car.settings.accounts.ChooseAccountFragment;
31 import com.android.car.settings.applications.ApplicationDetailsFragment;
32 import com.android.car.settings.applications.ApplicationsSettingsFragment;
33 import com.android.car.settings.applications.AppsAndNotificationsFragment;
34 import com.android.car.settings.applications.defaultapps.DefaultAutofillPickerFragment;
35 import com.android.car.settings.applications.specialaccess.ModifySystemSettingsFragment;
36 import com.android.car.settings.applications.specialaccess.NotificationAccessFragment;
37 import com.android.car.settings.applications.specialaccess.PremiumSmsAccessFragment;
38 import com.android.car.settings.applications.specialaccess.SpecialAccessSettingsFragment;
39 import com.android.car.settings.applications.specialaccess.UsageAccessFragment;
40 import com.android.car.settings.applications.specialaccess.WifiControlFragment;
41 import com.android.car.settings.bluetooth.BluetoothSettingsFragment;
42 import com.android.car.settings.datausage.DataUsageFragment;
43 import com.android.car.settings.datetime.DatetimeSettingsFragment;
44 import com.android.car.settings.display.DisplaySettingsFragment;
45 import com.android.car.settings.home.HomepageFragment;
46 import com.android.car.settings.inputmethod.KeyboardFragment;
47 import com.android.car.settings.language.LanguagePickerFragment;
48 import com.android.car.settings.language.LanguagesAndInputFragment;
49 import com.android.car.settings.location.LocationSettingsFragment;
50 import com.android.car.settings.network.MobileNetworkFragment;
51 import com.android.car.settings.network.MobileNetworkListFragment;
52 import com.android.car.settings.network.NetworkAndInternetFragment;
53 import com.android.car.settings.privacy.PrivacySettingsFragment;
54 import com.android.car.settings.quicksettings.QuickSettingFragment;
55 import com.android.car.settings.security.SecuritySettingsFragment;
56 import com.android.car.settings.sound.SoundSettingsFragment;
57 import com.android.car.settings.storage.StorageSettingsFragment;
58 import com.android.car.settings.system.AboutSettingsFragment;
59 import com.android.car.settings.system.LegalInformationFragment;
60 import com.android.car.settings.system.ResetOptionsFragment;
61 import com.android.car.settings.system.SystemSettingsFragment;
62 import com.android.car.settings.tts.TextToSpeechOutputFragment;
63 import com.android.car.settings.units.UnitsSettingsFragment;
64 import com.android.car.settings.users.UserDetailsFragment;
65 import com.android.car.settings.users.UsersListFragment;
66 import com.android.car.settings.wifi.AddWifiFragment;
67 import com.android.car.settings.wifi.WifiSettingsFragment;
68 import com.android.car.settings.wifi.WifiTetherFragment;
69 import com.android.car.settings.wifi.preferences.WifiPreferencesFragment;
70 
71 /**
72  * Top level settings class, containing static instances of CarSettings activities.
73  */
74 public class CarSettingActivities {
75 
76     private static final Logger LOG = new Logger(CarSettingActivities.class);
77 
78     /**
79      * QuickSettings Activity.
80      */
81     public static class QuickSettingActivity extends BaseCarSettingsActivity {
82         @Nullable
83         @Override
getInitialFragment()84         protected Fragment getInitialFragment() {
85             return new QuickSettingFragment();
86         }
87     }
88 
89     /**
90      * Homepage Activity.
91      */
92     public static class HomepageActivity extends BaseCarSettingsActivity {
93         @Nullable
94         @Override
getInitialFragment()95         protected Fragment getInitialFragment() {
96             return new HomepageFragment();
97         }
98     }
99 
100     // Homepage sub-sections
101 
102     /**
103      * Display Settings Activity.
104      */
105     public static class DisplaySettingsActivity extends BaseCarSettingsActivity {
106         @Nullable
107         @Override
getInitialFragment()108         protected Fragment getInitialFragment() {
109             return new DisplaySettingsFragment();
110         }
111     }
112 
113     /**
114      * Sound Settings Activity.
115      */
116     public static class SoundSettingsActivity extends BaseCarSettingsActivity {
117         @Nullable
118         @Override
getInitialFragment()119         protected Fragment getInitialFragment() {
120             return new SoundSettingsFragment();
121         }
122     }
123 
124     /**
125      * Network and Internet Activity.
126      */
127     public static class NetworkAndInternetActivity extends BaseCarSettingsActivity {
128         @Nullable
129         @Override
getInitialFragment()130         protected Fragment getInitialFragment() {
131             return new NetworkAndInternetFragment();
132         }
133     }
134 
135     /**
136      * Bluetooth Settings Activity.
137      */
138     public static class BluetoothSettingsActivity extends BaseCarSettingsActivity {
139         @Nullable
140         @Override
getInitialFragment()141         protected Fragment getInitialFragment() {
142             return new BluetoothSettingsFragment();
143         }
144     }
145 
146     /**
147      * Units Settings Activity.
148      */
149     public static class UnitsSettingsActivity extends BaseCarSettingsActivity {
150         @Nullable
151         @Override
getInitialFragment()152         protected Fragment getInitialFragment() {
153             return new UnitsSettingsFragment();
154         }
155     }
156 
157     /**
158      * Location Settings Activity.
159      */
160     public static class LocationSettingsActivity extends BaseCarSettingsActivity {
161         @Nullable
162         @Override
getInitialFragment()163         protected Fragment getInitialFragment() {
164             return new LocationSettingsFragment();
165         }
166     }
167 
168     /**
169      * Apps and Notifications Activity.
170      */
171     public static class AppsAndNotificationsActivity extends BaseCarSettingsActivity {
172         @Nullable
173         @Override
getInitialFragment()174         protected Fragment getInitialFragment() {
175             return new AppsAndNotificationsFragment();
176         }
177     }
178 
179     /**
180      * Datetime Settings Activity.
181      */
182     public static class DatetimeSettingsActivity extends BaseCarSettingsActivity {
183         @Nullable
184         @Override
getInitialFragment()185         protected Fragment getInitialFragment() {
186             return new DatetimeSettingsFragment();
187         }
188     }
189 
190     /**
191      * User Details Activity.
192      * The initial fragment shown is based on whether the current user is an admin.
193      */
194     public static class UserDetailsActivity extends BaseCarSettingsActivity {
195         @Nullable
196         @Override
getInitialFragment()197         protected Fragment getInitialFragment() {
198             UserManager userManager = UserManager.get(this);
199             if (userManager.isAdminUser()) {
200                 // Admins can see a full list of users in Settings.
201                 LOG.v("Creating UsersListFragment for admin user.");
202                 return new UsersListFragment();
203             } else {
204                 // Non-admins can only manage themselves in Settings.
205                 LOG.v("Creating UserDetailsFragment for non-admin.");
206                 return UserDetailsFragment.newInstance(UserHandle.myUserId());
207             }
208         }
209     }
210 
211     /**
212      * Account Settings Activity.
213      */
214     public static class AccountSettingsActivity extends BaseCarSettingsActivity {
215         @Nullable
216         @Override
getInitialFragment()217         protected Fragment getInitialFragment() {
218             return new AccountSettingsFragment();
219         }
220     }
221 
222     /**
223      * Privacy Settings Activity.
224      */
225     public static class PrivacySettingsActivity extends BaseCarSettingsActivity {
226         @Nullable
227         @Override
getInitialFragment()228         protected Fragment getInitialFragment() {
229             return new PrivacySettingsFragment();
230         }
231     }
232 
233     /**
234      * Storage Settings Activity.
235      */
236     public static class StorageSettingsActivity extends BaseCarSettingsActivity {
237         @Nullable
238         @Override
getInitialFragment()239         protected Fragment getInitialFragment() {
240             return new StorageSettingsFragment();
241         }
242     }
243 
244     /**
245      * Security Settings Activity.
246      */
247     public static class SecuritySettingsActivity extends BaseCarSettingsActivity {
248         @Nullable
249         @Override
getInitialFragment()250         protected Fragment getInitialFragment() {
251             return new SecuritySettingsFragment();
252         }
253     }
254 
255     /**
256      * System Settings Activity.
257      */
258     public static class SystemSettingsActivity extends BaseCarSettingsActivity {
259         @Nullable
260         @Override
getInitialFragment()261         protected Fragment getInitialFragment() {
262             return new SystemSettingsFragment();
263         }
264     }
265 
266     // Network & internet sub-sections
267 
268     /**
269      * Wifi Settings Activity.
270      */
271     public static class WifiSettingsActivity extends BaseCarSettingsActivity {
272         @Nullable
273         @Override
getInitialFragment()274         protected Fragment getInitialFragment() {
275             return new WifiSettingsFragment();
276         }
277     }
278 
279     /**
280      * Wifi Hotspot and Tethering Activity.
281      */
282     public static class WifiTetherActivity extends BaseCarSettingsActivity {
283         @Nullable
284         @Override
getInitialFragment()285         protected Fragment getInitialFragment() {
286             return new WifiTetherFragment();
287         }
288     }
289 
290     /**
291      * Mobile Network Activity.
292      */
293     public static class MobileNetworkActivity extends BaseCarSettingsActivity {
294         @Nullable
295         @Override
getInitialFragment()296         protected Fragment getInitialFragment() {
297             return MobileNetworkFragment.newInstance(
298                     getIntent().getIntExtra("network_sub_id", Integer.MIN_VALUE));
299         }
300     }
301 
302     /**
303      * Mobile Network List Activity.
304      */
305     public static class MobileNetworkListActivity extends BaseCarSettingsActivity {
306         @Nullable
307         @Override
getInitialFragment()308         protected Fragment getInitialFragment() {
309             return new MobileNetworkListFragment();
310         }
311     }
312 
313     /**
314      * Mobile Data Usage Activity.
315      */
316     public static class DataUsageActivity extends BaseCarSettingsActivity {
317         @Nullable
318         @Override
getInitialFragment()319         protected Fragment getInitialFragment() {
320             return new DataUsageFragment();
321         }
322     }
323 
324     // Apps & Notifications sub-sections
325 
326     /**
327      * Application Settings Activity.
328      */
329     public static class ApplicationsSettingsActivity extends BaseCarSettingsActivity {
330         @Nullable
331         @Override
getInitialFragment()332         protected Fragment getInitialFragment() {
333             return new ApplicationsSettingsFragment();
334         }
335     }
336 
337     /**
338      * Application Special Access Settings Activity.
339      */
340     public static class SpecialAccessSettingsActivity extends BaseCarSettingsActivity {
341         @Nullable
342         @Override
getInitialFragment()343         protected Fragment getInitialFragment() {
344             return new SpecialAccessSettingsFragment();
345         }
346     }
347 
348     // System sub-sections
349 
350     /**
351      * Languages and Input Activity.
352      */
353     public static class LanguagesAndInputActivity extends BaseCarSettingsActivity {
354         @Nullable
355         @Override
getInitialFragment()356         protected Fragment getInitialFragment() {
357             return new LanguagesAndInputFragment();
358         }
359     }
360 
361     /**
362      * About Settings Activity.
363      */
364     public static class AboutSettingsActivity extends BaseCarSettingsActivity {
365         @Nullable
366         @Override
getInitialFragment()367         protected Fragment getInitialFragment() {
368             return new AboutSettingsFragment();
369         }
370     }
371 
372     /**
373      * Legal Information Activity.
374      */
375     public static class LegalInformationActivity extends BaseCarSettingsActivity {
376         @Nullable
377         @Override
getInitialFragment()378         protected Fragment getInitialFragment() {
379             return new LegalInformationFragment();
380         }
381     }
382 
383     /**
384      * Reset Options Activity.
385      */
386     public static class ResetOptionsActivity extends BaseCarSettingsActivity {
387         @Nullable
388         @Override
getInitialFragment()389         protected Fragment getInitialFragment() {
390             return new ResetOptionsFragment();
391         }
392     }
393 
394     // Wi-fi sub-sections
395 
396     /**
397      * Add Wifi Network Activity.
398      */
399     public static class AddWifiActivity extends BaseCarSettingsActivity {
400         @Nullable
401         @Override
getInitialFragment()402         protected Fragment getInitialFragment() {
403             return new AddWifiFragment();
404         }
405     }
406 
407     /**
408      * Wifi Preferences Activity.
409      */
410     public static class WifiPreferencesActivity extends BaseCarSettingsActivity {
411         @Nullable
412         @Override
getInitialFragment()413         protected Fragment getInitialFragment() {
414             return new WifiPreferencesFragment();
415         }
416     }
417 
418     // App Info sub-sections
419 
420     /**
421      * Application Details Activity.
422      * Intent required to include package string as Settings.EXTRA_APP_PACKAGE extra.
423      */
424     public static class ApplicationsDetailsActivity extends BaseCarSettingsActivity {
425         @Nullable
426         @Override
getInitialFragment()427         protected Fragment getInitialFragment() {
428             Intent intent = getIntent();
429             String pkg = intent.getStringExtra(Settings.EXTRA_APP_PACKAGE);
430             if (TextUtils.isEmpty(pkg)) {
431                 LOG.w("No package provided for application detailed intent");
432                 Uri uri = intent.getData();
433                 if (uri == null) {
434                     LOG.w("No uri provided for application detailed intent");
435                     return null;
436                 }
437                 pkg = uri.getSchemeSpecificPart();
438             }
439             return ApplicationDetailsFragment.getInstance(pkg);
440         }
441     }
442 
443     // Special app access sub-section
444 
445     /**
446      * App Modify System Settings Access Activity.
447      */
448     public static class ModifySystemSettingsActivity extends BaseCarSettingsActivity {
449         @Nullable
450         @Override
getInitialFragment()451         protected Fragment getInitialFragment() {
452             return new ModifySystemSettingsFragment();
453         }
454     }
455 
456     /**
457      * App Notification Access Activity.
458      */
459     public static class NotificationAccessActivity extends BaseCarSettingsActivity {
460         @Nullable
461         @Override
getInitialFragment()462         protected Fragment getInitialFragment() {
463             return new NotificationAccessFragment();
464         }
465     }
466 
467     /**
468      * App Premium SMS Access Activity.
469      */
470     public static class PremiumSmsAccessActivity extends BaseCarSettingsActivity {
471         @Nullable
472         @Override
getInitialFragment()473         protected Fragment getInitialFragment() {
474             return new PremiumSmsAccessFragment();
475         }
476     }
477 
478     /**
479      * App Usage Access Activity.
480      */
481     public static class UsageAccessActivity extends BaseCarSettingsActivity {
482         @Nullable
483         @Override
getInitialFragment()484         protected Fragment getInitialFragment() {
485             return new UsageAccessFragment();
486         }
487     }
488 
489     /**
490      * App Wifi Control Access Activity.
491      */
492     public static class WifiControlActivity extends BaseCarSettingsActivity {
493         @Nullable
494         @Override
getInitialFragment()495         protected Fragment getInitialFragment() {
496             return new WifiControlFragment();
497         }
498     }
499 
500     // Account sub-section
501 
502     /**
503      * Choose Account Activity.
504      */
505     public static class ChooseAccountActivity extends BaseCarSettingsActivity {
506         @Nullable
507         @Override
getInitialFragment()508         protected Fragment getInitialFragment() {
509             return new ChooseAccountFragment();
510         }
511     }
512 
513     // Languages & input sub-section
514 
515     /**
516      * Language Picker Activity.
517      */
518     public static class LanguagePickerActivity extends BaseCarSettingsActivity {
519         @Nullable
520         @Override
getInitialFragment()521         protected Fragment getInitialFragment() {
522             return new LanguagePickerFragment();
523         }
524     }
525 
526     /**
527      * Default Autofill Picker Activity.
528      */
529     public static class DefaultAutofillPickerActivity extends BaseCarSettingsActivity {
530         @Nullable
531         @Override
getInitialFragment()532         protected Fragment getInitialFragment() {
533             return new DefaultAutofillPickerFragment();
534         }
535     }
536 
537     /**
538      * Keyboard Activity.
539      */
540     public static class KeyboardActivity extends BaseCarSettingsActivity {
541         @Nullable
542         @Override
getInitialFragment()543         protected Fragment getInitialFragment() {
544             return new KeyboardFragment();
545         }
546     }
547 
548     /**
549      * Text to Speech Output Activity.
550      */
551     public static class TextToSpeechOutputActivity extends BaseCarSettingsActivity {
552         @Nullable
553         @Override
getInitialFragment()554         protected Fragment getInitialFragment() {
555             return new TextToSpeechOutputFragment();
556         }
557     }
558 
559 }
560