Merge "Prevent disabling default phone/sms apps in battery setting" into pi-dev

This commit is contained in:
TreeHugger Robot
2018-05-30 00:18:45 +00:00
committed by Android (Google) Code Review
5 changed files with 140 additions and 15 deletions

View File

@@ -20,6 +20,7 @@ import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.when;
import android.app.admin.DevicePolicyManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
@@ -34,6 +35,8 @@ import android.os.UserManager;
import com.android.settings.testutils.ApplicationTestUtils;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.testutils.shadow.ShadowDefaultDialerManager;
import com.android.settings.testutils.shadow.ShadowSmsApplication;
import com.android.settingslib.wrapper.PackageManagerWrapper;
import org.junit.Before;
@@ -41,11 +44,15 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowApplication;
import org.robolectric.util.ReflectionHelpers;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
/**
* Tests for {@link ApplicationFeatureProviderImpl}.
@@ -247,8 +254,18 @@ public final class ApplicationFeatureProviderImplTest {
}
@Test
public void getKeepEnabledPackages_shouldContainNothing() {
assertThat(mProvider.getKeepEnabledPackages()).isEmpty();
@Config(shadows = {ShadowSmsApplication.class, ShadowDefaultDialerManager.class})
public void getKeepEnabledPackages_shouldContainDefaultPhoneAndSms() {
final String testDialer = "com.android.test.defaultdialer";
final String testSms = "com.android.test.defaultsms";
ShadowSmsApplication.setDefaultSmsApplication(new ComponentName(testSms, "receiver"));
ShadowDefaultDialerManager.setDefaultDialerApplication(testDialer);
ReflectionHelpers.setField(mProvider, "mContext", RuntimeEnvironment.application);
final Set<String> keepEnabledPackages = mProvider.getKeepEnabledPackages();
final List<String> expectedPackages = Arrays.asList(testDialer, testSms);
assertThat(keepEnabledPackages).containsExactlyElementsIn(expectedPackages);
}
private void setUpUsersAndInstalledApps() {

View File

@@ -0,0 +1,44 @@
/*
* 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.testutils.shadow;
import android.content.Context;
import android.telecom.DefaultDialerManager;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
import org.robolectric.annotation.Resetter;
@Implements(DefaultDialerManager.class)
public class ShadowDefaultDialerManager {
private static String sDefaultDailer;
@Resetter
public void reset() {
sDefaultDailer = null;
}
@Implementation
public static String getDefaultDialerApplication(Context context) {
return sDefaultDailer;
}
public static void setDefaultDialerApplication(String dialer) {
sDefaultDailer = dialer;
}
}

View File

@@ -0,0 +1,46 @@
/*
* 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.testutils.shadow;
import android.content.ComponentName;
import android.content.Context;
import com.android.internal.telephony.SmsApplication;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
import org.robolectric.annotation.Resetter;
@Implements(SmsApplication.class)
public class ShadowSmsApplication {
private static ComponentName sDefaultSmsApplication;
@Resetter
public void reset() {
sDefaultSmsApplication = null;
}
@Implementation
public static ComponentName getDefaultSmsApplication(Context context, boolean updateIfNeeded) {
return sDefaultSmsApplication;
}
public static void setDefaultSmsApplication(ComponentName cn) {
sDefaultSmsApplication = cn;
}
}