Add a few pages to search index.

- Data saver
- A few special permission access pages
   - Picture-in-picture
   - Premium sms
   - do not disturb access
- And a unrelated cleanup: move EmptyTextFragment from
  notification/ to widget/

Bug: 70720645
Test: robotests
Change-Id: I6a87f712bf81f9fd32fa9a3826fba851ca748409
This commit is contained in:
Fan Zhang
2018-07-10 15:46:31 -07:00
parent dc313813e6
commit 4560ab7a35
34 changed files with 326 additions and 65 deletions

View File

@@ -0,0 +1,95 @@
/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.applications.specialaccess.pictureinpicture;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.content.Context;
import com.android.settings.R;
import com.android.settings.applications.appinfo.AppInfoDashboardFragment;
import com.android.settings.core.BasePreferenceController;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import androidx.preference.Preference;
@RunWith(SettingsRobolectricTestRunner.class)
public class PictureInPictureDetailPreferenceControllerTest {
@Mock
private AppInfoDashboardFragment mFragment;
@Mock
private Preference mPreference;
private Context mContext;
private PictureInPictureDetailPreferenceController mController;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
mController = spy(new PictureInPictureDetailPreferenceController(mContext, "test_key"));
mController.setPackageName("Package1");
mController.setParentFragment(mFragment);
final String key = mController.getPreferenceKey();
when(mPreference.getKey()).thenReturn(key);
}
@Test
public void getAvailabilityStatus_noPictureInPictureActivities_shouldReturnDisabled() {
doReturn(false).when(mController).hasPictureInPictureActivites();
assertThat(mController.getAvailabilityStatus())
.isEqualTo(BasePreferenceController.DISABLED_FOR_USER);
}
@Test
public void getAvailabilityStatus_hasPictureInPictureActivities_shouldReturnAvailable() {
doReturn(true).when(mController).hasPictureInPictureActivites();
assertThat(mController.getAvailabilityStatus())
.isEqualTo(BasePreferenceController.AVAILABLE);
}
@Test
public void getDetailFragmentClass_shouldReturnPictureInPictureDetails() {
assertThat(mController.getDetailFragmentClass()).isEqualTo(PictureInPictureDetails.class);
}
@Test
public void updateState_shouldSetSummary() {
final int summary = R.string.app_permission_summary_allowed;
doReturn(summary).when(mController).getPreferenceSummary();
mController.updateState(mPreference);
verify(mPreference).setSummary(summary);
}
}

View File

@@ -0,0 +1,111 @@
/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.applications.specialaccess.pictureinpicture;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.nullable;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.verify;
import android.content.Context;
import android.content.pm.ActivityInfo;
import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.MockitoAnnotations;
@RunWith(SettingsRobolectricTestRunner.class)
public class PictureInPictureDetailsTest {
private FakeFeatureFactory mFeatureFactory;
private PictureInPictureDetails mFragment;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mFeatureFactory = FakeFeatureFactory.setupForTest();
mFragment = new PictureInPictureDetails();
}
@Test
public void testIgnoredApp() {
for (String ignoredPackage : PictureInPictureSettings.IGNORE_PACKAGE_LIST) {
assertThat(checkPackageHasPictureInPictureActivities(ignoredPackage, true))
.isFalse();
}
}
@Test
public void testNonPippableApp() {
assertThat(checkPackageHasPictureInPictureActivities("com.android.dummypackage")).isFalse();
assertThat(checkPackageHasPictureInPictureActivities("com.android.dummypackage",
false, false, false)).isFalse();
}
@Test
public void testPippableApp() {
assertThat(checkPackageHasPictureInPictureActivities("com.android.dummypackage",
true)).isTrue();
assertThat(checkPackageHasPictureInPictureActivities("com.android.dummypackage",
false, true)).isTrue();
assertThat(checkPackageHasPictureInPictureActivities("com.android.dummypackage",
true, false)).isTrue();
}
@Test
public void logSpecialPermissionChange() {
mFragment.logSpecialPermissionChange(true, "app");
verify(mFeatureFactory.metricsFeatureProvider).action(nullable(Context.class),
eq(MetricsProto.MetricsEvent.APP_PICTURE_IN_PICTURE_ALLOW), eq("app"));
mFragment.logSpecialPermissionChange(false, "app");
verify(mFeatureFactory.metricsFeatureProvider).action(nullable(Context.class),
eq(MetricsProto.MetricsEvent.APP_PICTURE_IN_PICTURE_DENY), eq("app"));
}
private boolean checkPackageHasPictureInPictureActivities(String packageName,
boolean... resizeableActivityState) {
ActivityInfo[] activities = null;
if (resizeableActivityState.length > 0) {
activities = new ActivityInfo[resizeableActivityState.length];
for (int i = 0; i < activities.length; i++) {
activities[i] = new MockActivityInfo(resizeableActivityState[i]);
}
}
return PictureInPictureSettings.checkPackageHasPictureInPictureActivities(packageName,
activities);
}
private class MockActivityInfo extends ActivityInfo {
private boolean mSupportsPictureInPicture;
private MockActivityInfo(boolean supportsPictureInPicture) {
mSupportsPictureInPicture = supportsPictureInPicture;
}
@Override
public boolean supportsPictureInPicture() {
return mSupportsPictureInPicture;
}
}
}

View File

@@ -0,0 +1,161 @@
/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.applications.specialaccess.pictureinpicture;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.when;
import android.content.pm.ActivityInfo;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.UserInfo;
import android.os.UserManager;
import android.util.Pair;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.google.common.collect.ImmutableList;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import java.util.ArrayList;
import java.util.List;
@RunWith(SettingsRobolectricTestRunner.class)
public class PictureInPictureSettingsTest {
private static final int PRIMARY_USER_ID = 0;
private static final int PROFILE_USER_ID = 10;
private PictureInPictureSettings mFragment;
@Mock
private PackageManager mPackageManager;
@Mock
private UserManager mUserManager;
private ArrayList<PackageInfo> mPrimaryUserPackages;
private ArrayList<PackageInfo> mProfileUserPackages;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
FakeFeatureFactory.setupForTest();
mFragment = new PictureInPictureSettings(mPackageManager, mUserManager);
mPrimaryUserPackages = new ArrayList<>();
mProfileUserPackages = new ArrayList<>();
when(mPackageManager.getInstalledPackagesAsUser(anyInt(), eq(PRIMARY_USER_ID)))
.thenReturn(mPrimaryUserPackages);
when(mPackageManager.getInstalledPackagesAsUser(anyInt(), eq(PROFILE_USER_ID)))
.thenReturn(mProfileUserPackages);
UserInfo primaryUserInfo = new UserInfo();
primaryUserInfo.id = PRIMARY_USER_ID;
UserInfo profileUserInfo = new UserInfo();
profileUserInfo.id = PROFILE_USER_ID;
when(mUserManager.getProfiles(PRIMARY_USER_ID))
.thenReturn(ImmutableList.of(primaryUserInfo, profileUserInfo));
}
@Test
public void testCollectPipApps() {
PackageInfo primaryP1 = createPackage("Calculator", true);
PackageInfo primaryP2 = createPackage("Clock", false);
PackageInfo profileP1 = createPackage("Calculator", false);
PackageInfo profileP2 = createPackage("Clock", true);
mPrimaryUserPackages.add(primaryP1);
mPrimaryUserPackages.add(primaryP2);
mProfileUserPackages.add(profileP1);
mProfileUserPackages.add(profileP2);
List<Pair<ApplicationInfo, Integer>> apps = mFragment.collectPipApps(PRIMARY_USER_ID);
assertThat(containsPackages(apps, primaryP1, profileP2)).isTrue();
assertThat(containsPackages(apps, primaryP2, profileP1)).isFalse();
}
@Test
public void testAppSort() {
PackageInfo primaryP1 = createPackage("Android", true);
PackageInfo primaryP2 = createPackage("Boop", true);
PackageInfo primaryP3 = createPackage("Deck", true);
PackageInfo profileP1 = createPackage("Android", true);
PackageInfo profileP2 = createPackage("Cool", true);
PackageInfo profileP3 = createPackage("Fast", false);
mPrimaryUserPackages.add(primaryP1);
mPrimaryUserPackages.add(primaryP2);
mPrimaryUserPackages.add(primaryP3);
mProfileUserPackages.add(profileP1);
mProfileUserPackages.add(profileP2);
mProfileUserPackages.add(profileP3);
List<Pair<ApplicationInfo, Integer>> apps = mFragment.collectPipApps(PRIMARY_USER_ID);
apps.sort(new PictureInPictureSettings.AppComparator(null));
assertThat(isOrdered(apps, primaryP1, profileP1, primaryP2, profileP2, primaryP3)).isTrue();
}
private boolean containsPackages(List<Pair<ApplicationInfo, Integer>> apps,
PackageInfo... packages) {
for (PackageInfo aPackage : packages) {
boolean found = false;
for (Pair<ApplicationInfo, Integer> app : apps) {
if (app.first == aPackage.applicationInfo) {
found = true;
break;
}
}
if (!found) {
return false;
}
}
return true;
}
private boolean isOrdered(List<Pair<ApplicationInfo, Integer>> apps, PackageInfo... packages) {
if (apps.size() != packages.length) {
return false;
}
for (int i = 0; i < packages.length; i++) {
if (packages[i].applicationInfo != apps.get(i).first) {
return false;
}
}
return true;
}
private PackageInfo createPackage(String appTitle, boolean supportsPip) {
PackageInfo pi = new PackageInfo();
ActivityInfo ai = new ActivityInfo();
if (supportsPip) {
ai.flags |= ActivityInfo.FLAG_SUPPORTS_PICTURE_IN_PICTURE;
}
pi.activities = new ActivityInfo[1];
pi.activities[0] = ai;
pi.applicationInfo = new ApplicationInfo();
pi.applicationInfo.name = appTitle;
return pi;
}
}

View File

@@ -0,0 +1,69 @@
/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.applications.specialaccess.premiumsms;
import static org.mockito.ArgumentMatchers.nullable;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.verify;
import android.content.Context;
import com.android.internal.logging.nano.MetricsProto;
import com.android.internal.telephony.SmsUsageMonitor;
import com.android.settings.applications.specialaccess.premiumsms.PremiumSmsAccess;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
@RunWith(SettingsRobolectricTestRunner.class)
public class PremiumSmsAccessTest {
private FakeFeatureFactory mFeatureFactory;
private PremiumSmsAccess mFragment;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mFeatureFactory = FakeFeatureFactory.setupForTest();
mFragment = new PremiumSmsAccess();
mFragment.onAttach(RuntimeEnvironment.application);
}
@Test
public void logSpecialPermissionChange() {
mFragment.logSpecialPermissionChange(SmsUsageMonitor.PREMIUM_SMS_PERMISSION_ASK_USER,
"app");
verify(mFeatureFactory.metricsFeatureProvider).action(nullable(Context.class),
eq(MetricsProto.MetricsEvent.APP_SPECIAL_PERMISSION_PREMIUM_SMS_ASK), eq("app"));
mFragment.logSpecialPermissionChange(SmsUsageMonitor.PREMIUM_SMS_PERMISSION_NEVER_ALLOW,
"app");
verify(mFeatureFactory.metricsFeatureProvider).action(nullable(Context.class),
eq(MetricsProto.MetricsEvent.APP_SPECIAL_PERMISSION_PREMIUM_SMS_DENY), eq("app"));
mFragment.logSpecialPermissionChange(SmsUsageMonitor.PREMIUM_SMS_PERMISSION_ALWAYS_ALLOW,
"app");
verify(mFeatureFactory.metricsFeatureProvider).action(nullable(Context.class),
eq(MetricsProto.MetricsEvent.APP_SPECIAL_PERMISSION_PREMIUM_SMS_ALWAYS_ALLOW),
eq("app"));
}
}

View File

@@ -14,8 +14,9 @@
* limitations under the License.
*/
package com.android.settings.applications.specialaccess;
package com.android.settings.applications.specialaccess.premiumsms;
import static com.android.settings.core.BasePreferenceController.AVAILABLE_UNSEARCHABLE;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.spy;
@@ -44,13 +45,13 @@ public class PremiumSmsControllerTest {
}
@Test
public void testPremiumSms_byDefault_shouldBeShown() {
assertThat(mController.isAvailable()).isTrue();
public void getAvailability_byDefault_shouldBeShown() {
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE_UNSEARCHABLE);
}
@Test
@Config(qualifiers = "mcc999")
public void testPremiumSms_ifDisabled_shouldNotBeShown() {
public void getAvailability_disabled_returnUnavailable() {
assertThat(mController.isAvailable()).isFalse();
}
}

View File

@@ -0,0 +1,57 @@
/*
* Copyright (C) 2018 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.applications.specialaccess.premiumsms;
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.spy;
import android.content.Context;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
public class PremiumSmsScreenPreferenceControllerTest {
private Context mContext;
private PremiumSmsScreenPreferenceController mController;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application.getApplicationContext());
mController = new PremiumSmsScreenPreferenceController(mContext, "key");
}
@Test
public void getAvailability_byDefault_shouldBeShown() {
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
}
@Test
@Config(qualifiers = "mcc999")
public void getAvailability_disabled_returnUnavailable() {
assertThat(mController.isAvailable()).isFalse();
}
}