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