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