2 * Copyright (C) 2010 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.android.settings;
19 import com.android.settings.tests.Manufacturer;
20 import com.android.settings.tests.Operator;
22 import android.content.ComponentName;
23 import android.content.Context;
24 import android.content.Intent;
25 import android.content.pm.ActivityInfo;
26 import android.content.pm.ApplicationInfo;
27 import android.content.pm.PackageManager;
28 import android.content.pm.ResolveInfo;
29 import android.content.res.Resources;
30 import android.os.Bundle;
31 import android.preference.Preference;
32 import android.preference.PreferenceGroup;
33 import android.test.ActivityInstrumentationTestCase2;
35 import java.util.List;
38 * Tests for the Settings operator/manufacturer hook.
43 * adb push SettingsTests.apk /system/app/SettingsTests.apk
44 * adb shell am instrument \
45 * -w com.android.settings.tests/android.test.InstrumentationTestRunner
47 public class SettingsHookTests extends ActivityInstrumentationTestCase2<Settings> {
49 private static final String PACKAGE_NAME = "com.android.settings.tests";
51 private static final String KEY_SETTINGS_ROOT = "parent";
52 private static final String KEY_SETTINGS_OPERATOR = "operator_settings";
53 private static final String KEY_SETTINGS_MANUFACTURER = "manufacturer_settings";
55 private static final String INTENT_OPERATOR_HOOK = "com.android.settings.OPERATOR_APPLICATION_SETTING";
56 private static final String INTENT_MANUFACTURER_HOOK = "com.android.settings.MANUFACTURER_APPLICATION_SETTING";
58 private Settings mSettings;
60 public SettingsHookTests() {
61 super("com.android.settings", Settings.class);
65 protected void setUp() throws Exception {
67 mSettings = getActivity();
71 * Test that the operator/manufacturer settings hook test application is
72 * available and that it's installed in the device's system image.
74 public void testSettingsHookTestAppAvailable() throws Exception {
75 Context context = mSettings.getApplicationContext();
76 PackageManager pm = context.getPackageManager();
77 ApplicationInfo applicationInfo = pm.getApplicationInfo(PACKAGE_NAME, 0);
78 assertTrue((applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0);
82 * Test that the operator test activity has registered an intent-filter for
83 * an action named 'android.settings.OPERATOR_APPLICATION_SETTING'.
85 public void testOperatorIntentFilter() {
86 boolean result = false;
87 Context context = mSettings.getApplicationContext();
88 PackageManager pm = context.getPackageManager();
89 Intent intent = new Intent(INTENT_OPERATOR_HOOK);
90 List<ResolveInfo> list = pm.queryIntentActivities(intent, 0);
91 for (ResolveInfo resolveInfo : list) {
92 if (resolveInfo.activityInfo.packageName.equals(PACKAGE_NAME)) {
96 assertTrue("Intent-filer not found", result);
100 * Test that the manufacturer test activity has registered an intent-filter
101 * for an action named 'android.settings.MANUFACTURER_APPLICATION_SETTING'.
103 public void testManufacturerIntentFilter() {
104 boolean result = false;
105 Context context = mSettings.getApplicationContext();
106 PackageManager pm = context.getPackageManager();
107 Intent intent = new Intent(INTENT_MANUFACTURER_HOOK);
108 List<ResolveInfo> list = pm.queryIntentActivities(intent, 0);
109 for (ResolveInfo resolveInfo : list) {
110 if (resolveInfo.activityInfo.packageName.equals(PACKAGE_NAME)) {
114 assertTrue("Intent-filer not found", result);
118 * Test that the operator preference is available in the Settings
121 public void testOperatorPreferenceAvailable() {
122 PreferenceGroup root = (PreferenceGroup)mSettings.findPreference(KEY_SETTINGS_ROOT);
123 Preference operatorPreference = root.findPreference(KEY_SETTINGS_OPERATOR);
124 assertNotNull(operatorPreference);
128 * Test that the manufacturer preference is available in the Settings
131 public void testManufacturerPreferenceAvailable() {
132 PreferenceGroup root = (PreferenceGroup)mSettings.findPreference(KEY_SETTINGS_ROOT);
133 Preference manufacturerHook = root.findPreference(KEY_SETTINGS_MANUFACTURER);
134 assertNotNull(manufacturerHook);