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