Merge "Fix power usage detail page is launched in wrong user"

This commit is contained in:
TreeHugger Robot
2017-08-29 22:42:47 +00:00
committed by Android (Google) Code Review
4 changed files with 66 additions and 3 deletions

View File

@@ -53,6 +53,7 @@ import com.android.settings.TestConfig;
import com.android.settings.applications.LayoutPreference;
import com.android.settings.R;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.shadow.ShadowActivityManager;
import com.android.settings.testutils.shadow.ShadowEntityHeaderController;
import com.android.settings.widget.EntityHeaderController;
import com.android.settingslib.applications.AppUtils;
@@ -78,7 +79,7 @@ import java.util.List;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
shadows = ShadowEntityHeaderController.class)
shadows = {ShadowEntityHeaderController.class, ShadowActivityManager.class})
public class AdvancedPowerUsageDetailTest {
private static final String APP_LABEL = "app label";
private static final String SUMMARY = "summary";
@@ -349,6 +350,22 @@ public class AdvancedPowerUsageDetailTest {
nullable(CharSequence.class), eq(new UserHandle(10)));
}
@Test
public void testStartBatteryDetailPage_typeUser_startByCurrentUser() {
mBatterySipper.drainType = BatterySipper.DrainType.USER;
mBatterySipper.userId = 10;
final int currentUser = 20;
ShadowActivityManager.setCurrentUser(currentUser);
AdvancedPowerUsageDetail.startBatteryDetailPage(mTestActivity, mBatteryUtils, null,
mBatteryStatsHelper, 0, mBatteryEntry, USAGE_PERCENT, null);
verify(mTestActivity).startPreferencePanelAsUser(
nullable(Fragment.class), nullable(String.class), nullable(Bundle.class), anyInt(),
nullable(CharSequence.class), eq(new UserHandle(currentUser)));
}
@Test
public void testStartBatteryDetailPage_noBatteryUsage_hasBasicData() {
final ArgumentCaptor<Bundle> captor = ArgumentCaptor.forClass(Bundle.class);

View File

@@ -0,0 +1,36 @@
/*
* 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.testutils.shadow;
import android.app.ActivityManager;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
@Implements(ActivityManager.class)
public class ShadowActivityManager {
private static int sCurrentUserId = 0;
@Implementation
public static int getCurrentUser() {
return sCurrentUserId;
}
public static void setCurrentUser(int userId) {
sCurrentUserId = userId;
}
}