1 /* 2 * Copyright (C) 2009 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 android.content.cts; 18 19 import static com.android.compatibility.common.util.RequiredServiceRule.hasService; 20 21 import android.app.DownloadManager; 22 import android.app.SearchManager; 23 import android.content.ComponentName; 24 import android.content.ContentUris; 25 import android.content.Context; 26 import android.content.Intent; 27 import android.content.IntentFilter; 28 import android.content.pm.ActivityInfo; 29 import android.content.pm.ApplicationInfo; 30 import android.content.pm.PackageManager; 31 import android.content.pm.ResolveInfo; 32 import android.media.RingtoneManager; 33 import android.net.Uri; 34 import android.net.wifi.WifiManager; 35 import android.os.BatteryManager; 36 import android.os.storage.StorageManager; 37 import android.platform.test.annotations.AppModeFull; 38 import android.provider.AlarmClock; 39 import android.provider.MediaStore; 40 import android.provider.Settings; 41 import android.provider.Telephony; 42 import android.telecom.TelecomManager; 43 import android.test.AndroidTestCase; 44 45 import com.android.compatibility.common.util.CddTest; 46 import com.android.compatibility.common.util.FeatureUtil; 47 48 import java.util.List; 49 50 @AppModeFull // TODO(Instant) Figure out which intents should be visible 51 public class AvailableIntentsTest extends AndroidTestCase { 52 private static final String NORMAL_URL = "http://www.google.com/"; 53 private static final String SECURE_URL = "https://www.google.com/"; 54 private static final String QRCODE= "DPP:I:SN=4774LH2b4044;M:010203040506;K:MDkwEwYHKoZIzj" + 55 "0CAQYIKoZIzj0DAQcDIgADURzxmttZoIRIPWGoQMV00XHWCAQIhXruVWOz0NjlkIA=;;"; 56 57 /** 58 * Assert target intent can be handled by at least one Activity. 59 * @param intent - the Intent will be handled. 60 */ assertCanBeHandled(final Intent intent)61 private void assertCanBeHandled(final Intent intent) { 62 PackageManager packageManager = mContext.getPackageManager(); 63 List<ResolveInfo> resolveInfoList = packageManager.queryIntentActivities(intent, 0); 64 assertNotNull(resolveInfoList); 65 // one or more activity can handle this intent. 66 assertTrue(resolveInfoList.size() > 0); 67 } 68 69 /** 70 * Assert target intent is not resolved by a filter with priority greater than 0. 71 * @param intent - the Intent will be handled. 72 */ assertDefaultHandlerValidPriority(final Intent intent)73 private void assertDefaultHandlerValidPriority(final Intent intent) { 74 PackageManager packageManager = mContext.getPackageManager(); 75 List<ResolveInfo> resolveInfoList = packageManager.queryIntentActivities(intent, 0); 76 assertNotNull(resolveInfoList); 77 // one or more activity can handle this intent. 78 assertTrue(resolveInfoList.size() > 0); 79 // no activities override defaults with a high priority. Only system activities can override 80 // the priority. 81 for (ResolveInfo resolveInfo : resolveInfoList) { 82 assertTrue(resolveInfo.priority <= 0); 83 } 84 } 85 assertHandledBySystemOnly(final Intent intent)86 private void assertHandledBySystemOnly(final Intent intent) { 87 PackageManager packageManager = mContext.getPackageManager(); 88 List<ResolveInfo> resolveInfoList = packageManager.queryIntentActivities(intent, 0); 89 assertNotNull(resolveInfoList); 90 91 // At least one system activity can handle this intent. 92 assertTrue(resolveInfoList.size() > 0); 93 for (ResolveInfo resolveInfo : resolveInfoList) { 94 final int flags = resolveInfo.activityInfo.applicationInfo.flags; 95 assertTrue("Package: " + resolveInfo.getComponentInfo().packageName, 96 (flags & ApplicationInfo.FLAG_SYSTEM) != 0); 97 } 98 } 99 assertHandledBySelfOnly(final Intent intent)100 private void assertHandledBySelfOnly(final Intent intent) { 101 PackageManager packageManager = mContext.getPackageManager(); 102 List<ResolveInfo> resolveInfoList = packageManager.queryIntentActivities(intent, 0); 103 assertNotNull(resolveInfoList); 104 105 assertTrue(resolveInfoList.size() > 0); 106 for (ResolveInfo resolveInfo : resolveInfoList) { 107 final ActivityInfo ai = resolveInfo.activityInfo; 108 assertEquals("android.content.cts", ai.packageName); 109 } 110 } 111 112 /** 113 * Test ACTION_VIEW when url is http://web_address, 114 * it will open a browser window to the URL specified. 115 */ testViewNormalUrl()116 public void testViewNormalUrl() { 117 Uri uri = Uri.parse(NORMAL_URL); 118 Intent intent = new Intent(Intent.ACTION_VIEW, uri); 119 assertCanBeHandled(intent); 120 } 121 122 /** 123 * Test ACTION_VIEW when url is https://web_address, 124 * it will open a browser window to the URL specified. 125 */ testViewSecureUrl()126 public void testViewSecureUrl() { 127 Uri uri = Uri.parse(SECURE_URL); 128 Intent intent = new Intent(Intent.ACTION_VIEW, uri); 129 assertCanBeHandled(intent); 130 } 131 132 /** 133 * Test ACTION_WEB_SEARCH when url is http://web_address, 134 * it will open a browser window to the URL specified. 135 */ testWebSearchNormalUrl()136 public void testWebSearchNormalUrl() { 137 Uri uri = Uri.parse(NORMAL_URL); 138 Intent intent = new Intent(Intent.ACTION_WEB_SEARCH); 139 intent.putExtra(SearchManager.QUERY, uri); 140 assertCanBeHandled(intent); 141 } 142 143 /** 144 * Test ACTION_WEB_SEARCH when url is https://web_address, 145 * it will open a browser window to the URL specified. 146 */ testWebSearchSecureUrl()147 public void testWebSearchSecureUrl() { 148 Uri uri = Uri.parse(SECURE_URL); 149 Intent intent = new Intent(Intent.ACTION_WEB_SEARCH); 150 intent.putExtra(SearchManager.QUERY, uri); 151 assertCanBeHandled(intent); 152 } 153 154 /** 155 * Test ACTION_WEB_SEARCH when url is empty string, 156 * google search will be applied for the plain text. 157 */ testWebSearchPlainText()158 public void testWebSearchPlainText() { 159 String searchString = "where am I?"; 160 Intent intent = new Intent(Intent.ACTION_WEB_SEARCH); 161 intent.putExtra(SearchManager.QUERY, searchString); 162 assertCanBeHandled(intent); 163 } 164 165 /** 166 * Test ACTION_CALL when uri is a phone number, it will call the entered phone number. 167 */ testCallPhoneNumber()168 public void testCallPhoneNumber() { 169 PackageManager packageManager = mContext.getPackageManager(); 170 if (packageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY)) { 171 Uri uri = Uri.parse("tel:2125551212"); 172 Intent intent = new Intent(Intent.ACTION_CALL, uri); 173 assertCanBeHandled(intent); 174 } 175 } 176 177 /** 178 * Test ACTION_DIAL when uri is a phone number, it will dial the entered phone number. 179 */ testDialPhoneNumber()180 public void testDialPhoneNumber() { 181 PackageManager packageManager = mContext.getPackageManager(); 182 if (packageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY)) { 183 Uri uri = Uri.parse("tel:(212)5551212"); 184 Intent intent = new Intent(Intent.ACTION_DIAL, uri); 185 assertCanBeHandled(intent); 186 } 187 } 188 189 /** 190 * Test ACTION_DIAL when uri is a phone number, it will dial the entered phone number. 191 */ testDialVoicemail()192 public void testDialVoicemail() { 193 PackageManager packageManager = mContext.getPackageManager(); 194 if (packageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY)) { 195 Uri uri = Uri.parse("voicemail:"); 196 Intent intent = new Intent(Intent.ACTION_DIAL, uri); 197 assertCanBeHandled(intent); 198 } 199 } 200 201 /** 202 * Test ACTION_CHANGE_PHONE_ACCOUNTS, it will display the phone account preferences. 203 */ testChangePhoneAccounts()204 public void testChangePhoneAccounts() { 205 PackageManager packageManager = mContext.getPackageManager(); 206 if (packageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY)) { 207 Intent intent = new Intent(TelecomManager.ACTION_CHANGE_PHONE_ACCOUNTS); 208 assertCanBeHandled(intent); 209 } 210 } 211 212 /** 213 * Test ACTION_SHOW_CALL_ACCESSIBILITY_SETTINGS, it will display the call accessibility preferences. 214 */ testShowCallAccessibilitySettings()215 public void testShowCallAccessibilitySettings() { 216 PackageManager packageManager = mContext.getPackageManager(); 217 if (packageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY)) { 218 Intent intent = new Intent(TelecomManager.ACTION_SHOW_CALL_ACCESSIBILITY_SETTINGS); 219 assertCanBeHandled(intent); 220 } 221 } 222 223 /** 224 * Test ACTION_SHOW_CALL_SETTINGS, it will display the call preferences. 225 */ testShowCallSettings()226 public void testShowCallSettings() { 227 PackageManager packageManager = mContext.getPackageManager(); 228 if (packageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY)) { 229 Intent intent = new Intent(TelecomManager.ACTION_SHOW_CALL_SETTINGS); 230 assertCanBeHandled(intent); 231 } 232 } 233 234 /** 235 * Test ACTION_SHOW_RESPOND_VIA_SMS_SETTINGS, it will display the respond by SMS preferences. 236 */ testShowRespondViaSmsSettings()237 public void testShowRespondViaSmsSettings() { 238 PackageManager packageManager = mContext.getPackageManager(); 239 if (packageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY)) { 240 Intent intent = new Intent(TelecomManager.ACTION_SHOW_RESPOND_VIA_SMS_SETTINGS); 241 assertCanBeHandled(intent); 242 } 243 } 244 245 /** 246 * Test start camera by intent 247 */ testCamera()248 public void testCamera() { 249 PackageManager packageManager = mContext.getPackageManager(); 250 if (packageManager.hasSystemFeature(PackageManager.FEATURE_CAMERA) 251 || packageManager.hasSystemFeature(PackageManager.FEATURE_CAMERA_FRONT)) { 252 Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 253 assertCanBeHandled(intent); 254 255 intent.setAction(MediaStore.ACTION_VIDEO_CAPTURE); 256 assertCanBeHandled(intent); 257 258 intent.setAction(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA); 259 assertCanBeHandled(intent); 260 261 intent.setAction(MediaStore.INTENT_ACTION_VIDEO_CAMERA); 262 assertCanBeHandled(intent); 263 } 264 } 265 266 /** 267 * TODO: This is a separate test so it can more easily be suppressed while we 268 * fix targets that are out of compliance. 269 */ testImageCaptureIntentsHandledBySystem()270 public void testImageCaptureIntentsHandledBySystem() { 271 PackageManager packageManager = mContext.getPackageManager(); 272 if (packageManager.hasSystemFeature(PackageManager.FEATURE_CAMERA) 273 || packageManager.hasSystemFeature(PackageManager.FEATURE_CAMERA_FRONT)) { 274 275 Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 276 assertHandledBySystemOnly(intent); 277 278 intent.setAction(MediaStore.ACTION_VIDEO_CAPTURE); 279 assertHandledBySystemOnly(intent); 280 281 intent.setAction(MediaStore.INTENT_ACTION_VIDEO_CAMERA); 282 assertHandledBySystemOnly(intent); 283 } 284 } 285 testImageCaptureIntentWithExplicitTargeting()286 public void testImageCaptureIntentWithExplicitTargeting() { 287 PackageManager packageManager = mContext.getPackageManager(); 288 if (packageManager.hasSystemFeature(PackageManager.FEATURE_CAMERA) 289 || packageManager.hasSystemFeature(PackageManager.FEATURE_CAMERA_FRONT)) { 290 Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 291 intent.setPackage("android.content.cts"); 292 assertHandledBySelfOnly(intent); 293 294 intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 295 intent.setComponent(ComponentName.createRelative( 296 "android.content.cts", 297 "com.android.cts.content.StubCameraIntentHandlerActivity")); 298 assertHandledBySelfOnly(intent); 299 } 300 } 301 testSettings()302 public void testSettings() { 303 assertCanBeHandled(new Intent(Settings.ACTION_SETTINGS)); 304 } 305 306 /** 307 * Test add event in calendar 308 */ testCalendarAddAppointment()309 public void testCalendarAddAppointment() { 310 Intent addAppointmentIntent = new Intent(Intent.ACTION_EDIT); 311 addAppointmentIntent.setType("vnd.android.cursor.item/event"); 312 assertCanBeHandled(addAppointmentIntent); 313 } 314 315 /** 316 * Test view call logs 317 */ testContactsCallLogs()318 public void testContactsCallLogs() { 319 PackageManager packageManager = mContext.getPackageManager(); 320 if (packageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY)) { 321 Intent intent = new Intent(Intent.ACTION_VIEW); 322 intent.setType("vnd.android.cursor.dir/calls"); 323 assertCanBeHandled(intent); 324 } 325 } 326 327 /** 328 * Test view music playback 329 */ testMusicPlayback()330 public void testMusicPlayback() { 331 Intent intent = new Intent(Intent.ACTION_VIEW); 332 intent.setDataAndType(ContentUris.withAppendedId( 333 MediaStore.Audio.Media.INTERNAL_CONTENT_URI, 1), "audio/*"); 334 assertCanBeHandled(intent); 335 } 336 testAlarmClockSetAlarm()337 public void testAlarmClockSetAlarm() { 338 Intent intent = new Intent(AlarmClock.ACTION_SET_ALARM); 339 intent.putExtra(AlarmClock.EXTRA_MESSAGE, "Custom message"); 340 intent.putExtra(AlarmClock.EXTRA_HOUR, 12); 341 intent.putExtra(AlarmClock.EXTRA_MINUTES, 0); 342 assertCanBeHandled(intent); 343 } 344 testAlarmClockShowAlarms()345 public void testAlarmClockShowAlarms() { 346 Intent intent = new Intent(AlarmClock.ACTION_SHOW_ALARMS); 347 assertCanBeHandled(intent); 348 } 349 testAlarmClockDismissAlarm()350 public void testAlarmClockDismissAlarm() { 351 if (mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_LEANBACK_ONLY)) { 352 return; 353 } 354 Intent intent = new Intent(AlarmClock.ACTION_DISMISS_ALARM); 355 assertCanBeHandled(intent); 356 } 357 testAlarmClockSnoozeAlarm()358 public void testAlarmClockSnoozeAlarm() { 359 if (mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_LEANBACK_ONLY)) { 360 return; 361 } 362 Intent intent = new Intent(AlarmClock.ACTION_SNOOZE_ALARM); 363 intent.putExtra(AlarmClock.EXTRA_ALARM_SNOOZE_DURATION, 10); 364 assertCanBeHandled(intent); 365 } 366 testAlarmClockSetTimer()367 public void testAlarmClockSetTimer() { 368 Intent intent = new Intent(AlarmClock.ACTION_SET_TIMER); 369 intent.putExtra(AlarmClock.EXTRA_LENGTH, 60000); 370 assertCanBeHandled(intent); 371 } 372 testAlarmClockShowTimers()373 public void testAlarmClockShowTimers() { 374 if (mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_LEANBACK_ONLY)) { 375 return; 376 } 377 Intent intent = new Intent(AlarmClock.ACTION_SHOW_TIMERS); 378 assertCanBeHandled(intent); 379 } 380 testOpenDocumentAny()381 public void testOpenDocumentAny() { 382 Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); 383 intent.addCategory(Intent.CATEGORY_OPENABLE); 384 intent.setType("*/*"); 385 assertCanBeHandled(intent); 386 } 387 testOpenDocumentImage()388 public void testOpenDocumentImage() { 389 Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); 390 intent.addCategory(Intent.CATEGORY_OPENABLE); 391 intent.setType("image/*"); 392 assertCanBeHandled(intent); 393 } 394 testCreateDocument()395 public void testCreateDocument() { 396 Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT); 397 intent.addCategory(Intent.CATEGORY_OPENABLE); 398 intent.setType("text/plain"); 399 assertCanBeHandled(intent); 400 } 401 testGetContentAny()402 public void testGetContentAny() { 403 Intent intent = new Intent(Intent.ACTION_GET_CONTENT); 404 intent.addCategory(Intent.CATEGORY_OPENABLE); 405 intent.setType("*/*"); 406 assertCanBeHandled(intent); 407 } 408 testGetContentImage()409 public void testGetContentImage() { 410 Intent intent = new Intent(Intent.ACTION_GET_CONTENT); 411 intent.addCategory(Intent.CATEGORY_OPENABLE); 412 intent.setType("image/*"); 413 assertCanBeHandled(intent); 414 } 415 testRingtonePicker()416 public void testRingtonePicker() { 417 assertCanBeHandled(new Intent(RingtoneManager.ACTION_RINGTONE_PICKER)); 418 } 419 testViewDownloads()420 public void testViewDownloads() { 421 assertCanBeHandled(new Intent(DownloadManager.ACTION_VIEW_DOWNLOADS)); 422 } 423 testManageStorage()424 public void testManageStorage() { 425 assertCanBeHandled(new Intent(StorageManager.ACTION_MANAGE_STORAGE)); 426 } 427 testFingerprintEnrollStart()428 public void testFingerprintEnrollStart() { 429 PackageManager packageManager = mContext.getPackageManager(); 430 if (packageManager.hasSystemFeature(PackageManager.FEATURE_FINGERPRINT)) { 431 assertCanBeHandled(new Intent(Settings.ACTION_FINGERPRINT_ENROLL)); 432 } 433 } 434 testUsageAccessSettings()435 public void testUsageAccessSettings() { 436 PackageManager packageManager = mContext.getPackageManager(); 437 if (!packageManager.hasSystemFeature(PackageManager.FEATURE_WATCH)) { 438 assertCanBeHandled(new Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS)); 439 } 440 } 441 testPictureInPictureSettings()442 public void testPictureInPictureSettings() { 443 PackageManager packageManager = mContext.getPackageManager(); 444 if (packageManager.hasSystemFeature(PackageManager.FEATURE_PICTURE_IN_PICTURE)) { 445 assertCanBeHandled(new Intent(Settings.ACTION_PICTURE_IN_PICTURE_SETTINGS)); 446 } 447 } 448 testRequestManageMedia()449 public void testRequestManageMedia() { 450 if (FeatureUtil.isAutomotive()) { 451 // Skip the test for automotive device. 452 return; 453 } 454 assertCanBeHandled(new Intent(Settings.ACTION_REQUEST_MANAGE_MEDIA)); 455 } 456 testInteractAcrossProfilesSettings()457 public void testInteractAcrossProfilesSettings() { 458 PackageManager packageManager = mContext.getPackageManager(); 459 if (packageManager.hasSystemFeature(PackageManager.FEATURE_MANAGED_PROFILES)) { 460 assertCanBeHandled(new Intent(Settings.ACTION_MANAGE_CROSS_PROFILE_ACCESS)); 461 } 462 } 463 testChangeDefaultSmsApplication()464 public void testChangeDefaultSmsApplication() { 465 PackageManager packageManager = mContext.getPackageManager(); 466 if (packageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY)) { 467 assertCanBeHandled(new Intent(Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT)); 468 } 469 } 470 testLocationScanningSettings()471 public void testLocationScanningSettings() { 472 PackageManager packageManager = mContext.getPackageManager(); 473 if (packageManager.hasSystemFeature(PackageManager.FEATURE_WATCH)) { 474 // Skip the test for wearable device. 475 return; 476 } 477 if (packageManager.hasSystemFeature(PackageManager.FEATURE_WIFI) 478 || packageManager.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) { 479 assertCanBeHandled(new Intent("android.settings.LOCATION_SCANNING_SETTINGS")); 480 } 481 } 482 testSettingsSearchIntent()483 public void testSettingsSearchIntent() { 484 if (FeatureUtil.isTV() || FeatureUtil.isAutomotive() || FeatureUtil.isWatch()) { 485 return; 486 } 487 assertCanBeHandled(new Intent(Settings.ACTION_APP_SEARCH_SETTINGS)); 488 } 489 testChangeDefaultDialer()490 public void testChangeDefaultDialer() { 491 PackageManager packageManager = mContext.getPackageManager(); 492 if (packageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY)) { 493 assertCanBeHandled(new Intent(TelecomManager.ACTION_CHANGE_DEFAULT_DIALER)); 494 } 495 } 496 testTapAnPaySettings()497 public void testTapAnPaySettings() { 498 PackageManager packageManager = mContext.getPackageManager(); 499 if (packageManager.hasSystemFeature(PackageManager.FEATURE_NFC_HOST_CARD_EMULATION)) { 500 assertCanBeHandled(new Intent(Settings.ACTION_NFC_PAYMENT_SETTINGS)); 501 } 502 } 503 testPowerUsageSummarySettings()504 public void testPowerUsageSummarySettings() { 505 if(FeatureUtil.isWatch()){ 506 return; 507 } 508 if (isBatteryPresent()) { 509 assertCanBeHandled(new Intent(Intent.ACTION_POWER_USAGE_SUMMARY)); 510 } 511 } 512 513 @CddTest(requirement = "7.4.2.6/C-1-1") testEasyConnectIntent()514 public void testEasyConnectIntent() { 515 // Android only supports Initiator-... modes right now, which require the device to 516 // have a QR-code capture mechanism. Therefore this feature does not make sense on 517 // non-handheld devices. 518 if (!isHandheld()) { 519 return; 520 } 521 WifiManager manager = mContext.getSystemService(WifiManager.class); 522 523 if (manager.isEasyConnectSupported()) { 524 Intent intent = new Intent(Settings.ACTION_PROCESS_WIFI_EASY_CONNECT_URI); 525 intent.setData(Uri.parse(QRCODE)); 526 assertCanBeHandled(intent); 527 } 528 } 529 testRequestSetAutofillServiceIntent()530 public void testRequestSetAutofillServiceIntent() { 531 if (FeatureUtil.isWatch()) { 532 return; 533 } 534 Intent intent = new Intent(Settings.ACTION_REQUEST_SET_AUTOFILL_SERVICE) 535 .setData(Uri.parse("package:android.content.cts")); 536 assertCanBeHandled(intent); 537 } 538 testNotificationPolicyDetailIntent()539 public void testNotificationPolicyDetailIntent() { 540 if (!isHandheld()) { 541 return; 542 } 543 544 Intent intent = new Intent(Settings.ACTION_NOTIFICATION_POLICY_ACCESS_DETAIL_SETTINGS) 545 .setData(Uri.parse("package:android.content.cts")); 546 assertCanBeHandled(intent); 547 } 548 testRequestEnableContentCaptureIntent()549 public void testRequestEnableContentCaptureIntent() { 550 if (!hasService(Context.CONTENT_CAPTURE_MANAGER_SERVICE)) return; 551 552 Intent intent = new Intent(Settings.ACTION_REQUEST_ENABLE_CONTENT_CAPTURE); 553 assertCanBeHandled(intent); 554 } 555 testVoiceInputSettingsIntent()556 public void testVoiceInputSettingsIntent() { 557 // Non-handheld devices do not allow more than one VoiceInteractionService, and therefore do 558 // not have to support this Intent. 559 if (!isHandheld()) { 560 return; 561 } 562 Intent intent = new Intent(Settings.ACTION_VOICE_INPUT_SETTINGS); 563 assertCanBeHandled(intent); 564 } 565 testAddNetworksIntent()566 public void testAddNetworksIntent() { 567 assertCanBeHandled(new Intent(Settings.ACTION_WIFI_ADD_NETWORKS)); 568 } 569 testManageUnusedAppsIntent()570 public void testManageUnusedAppsIntent() { 571 assertCanBeHandled(new Intent(Intent.ACTION_MANAGE_UNUSED_APPS)); 572 } 573 isHandheld()574 private boolean isHandheld() { 575 // handheld nature is not exposed to package manager, for now 576 // we check for touchscreen and NOT watch, NOT tv and NOT car 577 PackageManager pm = getContext().getPackageManager(); 578 return pm.hasSystemFeature(pm.FEATURE_TOUCHSCREEN) 579 && !pm.hasSystemFeature(pm.FEATURE_WATCH) 580 && !pm.hasSystemFeature(pm.FEATURE_TELEVISION) 581 && !pm.hasSystemFeature(pm.FEATURE_AUTOMOTIVE); 582 } 583 isBatteryPresent()584 private boolean isBatteryPresent() { 585 final Intent batteryInfo = mContext.registerReceiver(null, 586 new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); 587 return batteryInfo.getBooleanExtra(BatteryManager.EXTRA_PRESENT, true); 588 } 589 } 590