Remove app info page v1 related codes.
- change to use AppInfoDashboardFragment completely - remove InstalledAppDetails and the corresponding tests Change-Id: I8cbdf71cadc8b5743929abbafe91185e5e39b6b2 Fixes: 69384089 Test: make RunSettingsRoboTests
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -17,30 +17,21 @@
|
||||
package com.android.settings.applications;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.util.FeatureFlagUtils;
|
||||
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.applications.appinfo.AppInfoDashboardFragment;
|
||||
import com.android.settings.core.FeatureFlags;
|
||||
|
||||
public class InstalledAppDetailsTop extends SettingsActivity {
|
||||
|
||||
@Override
|
||||
public Intent getIntent() {
|
||||
Intent modIntent = new Intent(super.getIntent());
|
||||
if (FeatureFlagUtils.isEnabled(this, FeatureFlags.APP_INFO_V2)) {
|
||||
modIntent.putExtra(EXTRA_SHOW_FRAGMENT, AppInfoDashboardFragment.class.getName());
|
||||
} else {
|
||||
modIntent.putExtra(EXTRA_SHOW_FRAGMENT, InstalledAppDetails.class.getName());
|
||||
}
|
||||
modIntent.putExtra(EXTRA_SHOW_FRAGMENT, AppInfoDashboardFragment.class.getName());
|
||||
return modIntent;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isValidFragment(String fragmentName) {
|
||||
if (FeatureFlagUtils.isEnabled(this, FeatureFlags.APP_INFO_V2)) {
|
||||
return AppInfoDashboardFragment.class.getName().equals(fragmentName);
|
||||
}
|
||||
return InstalledAppDetails.class.getName().equals(fragmentName);
|
||||
return AppInfoDashboardFragment.class.getName().equals(fragmentName);
|
||||
}
|
||||
}
|
||||
|
@@ -34,14 +34,12 @@ import android.support.v7.preference.PreferenceScreen;
|
||||
import android.text.TextUtils;
|
||||
import android.util.ArrayMap;
|
||||
import android.util.ArraySet;
|
||||
import android.util.FeatureFlagUtils;
|
||||
import android.util.IconDrawableFactory;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.applications.appinfo.AppInfoDashboardFragment;
|
||||
import com.android.settings.core.FeatureFlags;
|
||||
import com.android.settings.core.PreferenceControllerMixin;
|
||||
import com.android.settings.widget.AppPreference;
|
||||
import com.android.settingslib.applications.AppUtils;
|
||||
@@ -245,17 +243,10 @@ public class RecentAppsPreferenceController extends AbstractPreferenceController
|
||||
System.currentTimeMillis() - stat.getLastTimeUsed(), false));
|
||||
pref.setOrder(i);
|
||||
pref.setOnPreferenceClickListener(preference -> {
|
||||
if (FeatureFlagUtils.isEnabled(mContext, FeatureFlags.APP_INFO_V2)) {
|
||||
AppInfoBase.startAppInfoFragment(AppInfoDashboardFragment.class,
|
||||
R.string.application_info_label, pkgName, appEntry.info.uid, mHost,
|
||||
1001 /*RequestCode*/, SETTINGS_APP_NOTIF_CATEGORY);
|
||||
return true;
|
||||
} else {
|
||||
AppInfoBase.startAppInfoFragment(InstalledAppDetails.class,
|
||||
R.string.application_info_label, pkgName, appEntry.info.uid, mHost,
|
||||
1001 /*RequestCode*/, SETTINGS_APP_NOTIF_CATEGORY);
|
||||
return true;
|
||||
}
|
||||
AppInfoBase.startAppInfoFragment(AppInfoDashboardFragment.class,
|
||||
R.string.application_info_label, pkgName, appEntry.info.uid, mHost,
|
||||
1001 /*RequestCode*/, SETTINGS_APP_NOTIF_CATEGORY);
|
||||
return true;
|
||||
});
|
||||
if (!rebindPref) {
|
||||
mCategory.addPreference(pref);
|
||||
|
@@ -45,19 +45,15 @@ import android.util.Log;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.DeviceAdminAdd;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.applications.LayoutPreference;
|
||||
import com.android.settings.applications.manageapplications.ManageApplications;
|
||||
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settings.widget.EntityHeaderController;
|
||||
import com.android.settings.widget.PreferenceCategoryController;
|
||||
import com.android.settings.wrapper.DevicePolicyManagerWrapper;
|
||||
import com.android.settingslib.RestrictedLockUtils;
|
||||
|
@@ -50,7 +50,6 @@ import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.TextUtils;
|
||||
import android.util.ArraySet;
|
||||
import android.util.FeatureFlagUtils;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
@@ -91,15 +90,14 @@ import com.android.settings.applications.AppStateWriteSettingsBridge;
|
||||
import com.android.settings.applications.AppStorageSettings;
|
||||
import com.android.settings.applications.DefaultAppSettings;
|
||||
import com.android.settings.applications.InstalledAppCounter;
|
||||
import com.android.settings.applications.InstalledAppDetails;
|
||||
import com.android.settings.applications.NotificationApps;
|
||||
import com.android.settings.applications.DirectoryAccessDetails;
|
||||
import com.android.settings.applications.UsageAccessDetails;
|
||||
import com.android.settings.applications.appinfo.AppInfoDashboardFragment;
|
||||
import com.android.settings.applications.appinfo.AppNotificationPreferenceController;
|
||||
import com.android.settings.applications.appinfo.DrawOverlayDetails;
|
||||
import com.android.settings.applications.appinfo.ExternalSourcesDetails;
|
||||
import com.android.settings.applications.appinfo.WriteSettingsDetails;
|
||||
import com.android.settings.core.FeatureFlags;
|
||||
import com.android.settings.core.InstrumentedPreferenceFragment;
|
||||
import com.android.settings.dashboard.SummaryLoader;
|
||||
import com.android.settings.fuelgauge.HighPowerDetail;
|
||||
@@ -151,7 +149,7 @@ public class ManageApplications extends InstrumentedPreferenceFragment
|
||||
private static final String EXTRA_HAS_ENTRIES = "hasEntries";
|
||||
private static final String EXTRA_HAS_BRIDGE = "hasBridge";
|
||||
|
||||
// attributes used as keys when passing values to InstalledAppDetails activity
|
||||
// attributes used as keys when passing values to AppInfoDashboardFragment activity
|
||||
public static final String APP_CHG = "chg";
|
||||
|
||||
// constant value that can be used to check return code from sub activity.
|
||||
@@ -553,13 +551,8 @@ public class ManageApplications extends InstrumentedPreferenceFragment
|
||||
// process ahead of time, to avoid a long load of data when user clicks on a managed
|
||||
// app. Maybe when they load the list of apps that contains managed profile apps.
|
||||
default:
|
||||
if (FeatureFlagUtils.isEnabled(getContext(), FeatureFlags.APP_INFO_V2)) {
|
||||
startAppInfoFragment(
|
||||
AppInfoDashboardFragment.class, R.string.application_info_label);
|
||||
} else {
|
||||
startAppInfoFragment(
|
||||
InstalledAppDetails.class, R.string.application_info_label);
|
||||
}
|
||||
startAppInfoFragment(
|
||||
AppInfoDashboardFragment.class, R.string.application_info_label);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -1227,7 +1220,8 @@ public class ManageApplications extends InstrumentedPreferenceFragment
|
||||
switch (mManageApplications.mListType) {
|
||||
case LIST_TYPE_NOTIFICATION:
|
||||
if (entry.extraInfo != null) {
|
||||
holder.setSummary(InstalledAppDetails.getNotificationSummary(
|
||||
holder.setSummary(
|
||||
AppNotificationPreferenceController.getNotificationSummary(
|
||||
(AppRow) entry.extraInfo, mContext));
|
||||
} else {
|
||||
holder.setSummary(null);
|
||||
|
@@ -20,7 +20,6 @@ package com.android.settings.core;
|
||||
* This class keeps track of all feature flags in Settings.
|
||||
*/
|
||||
public class FeatureFlags {
|
||||
public static final String APP_INFO_V2 = "settings_app_info_v2";
|
||||
public static final String CONNECTED_DEVICE_V2 = "settings_connected_device_v2";
|
||||
public static final String BATTERY_SETTINGS_V2 = "settings_battery_v2";
|
||||
public static final String BATTERY_DISPLAY_APP_LIST = "settings_battery_display_app_list";
|
||||
|
@@ -39,7 +39,6 @@ import com.android.settings.accounts.ManagedProfileSettings;
|
||||
import com.android.settings.accounts.AccountDashboardFragment;
|
||||
import com.android.settings.applications.AppAndNotificationDashboardFragment;
|
||||
import com.android.settings.applications.DefaultAppSettings;
|
||||
import com.android.settings.applications.InstalledAppDetails;
|
||||
import com.android.settings.applications.ManageDomainUrls;
|
||||
import com.android.settings.applications.NotificationApps;
|
||||
import com.android.settings.applications.ProcessStatsSummary;
|
||||
@@ -207,7 +206,6 @@ public class SettingsGateway {
|
||||
ConfigureNotificationSettings.class.getName(),
|
||||
ChooseLockPassword.ChooseLockPasswordFragment.class.getName(),
|
||||
ChooseLockPattern.ChooseLockPatternFragment.class.getName(),
|
||||
InstalledAppDetails.class.getName(),
|
||||
AppInfoDashboardFragment.class.getName(),
|
||||
BatterySaverSettings.class.getName(),
|
||||
AppNotificationSettings.class.getName(),
|
||||
|
@@ -22,7 +22,6 @@ import android.os.Bundle;
|
||||
import android.os.UserHandle;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceViewHolder;
|
||||
import android.util.FeatureFlagUtils;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
@@ -33,9 +32,7 @@ import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
import com.android.settings.applications.AppStateBaseBridge;
|
||||
import com.android.settings.applications.InstalledAppDetails;
|
||||
import com.android.settings.applications.appinfo.AppInfoDashboardFragment;
|
||||
import com.android.settings.core.FeatureFlags;
|
||||
import com.android.settings.datausage.AppStateDataUsageBridge.DataUsageState;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settings.widget.AppSwitchPreference;
|
||||
@@ -286,17 +283,10 @@ public class UnrestrictedDataAccess extends SettingsPreferenceFragment
|
||||
protected void onClick() {
|
||||
if (mState.isDataSaverBlacklisted) {
|
||||
// app is blacklisted, launch App Data Usage screen
|
||||
if (FeatureFlagUtils.isEnabled(getContext(), FeatureFlags.APP_INFO_V2)) {
|
||||
AppInfoDashboardFragment.startAppInfoFragment(AppDataUsage.class,
|
||||
R.string.app_data_usage,
|
||||
UnrestrictedDataAccess.this,
|
||||
mEntry);
|
||||
} else {
|
||||
InstalledAppDetails.startAppInfoFragment(AppDataUsage.class,
|
||||
R.string.app_data_usage,
|
||||
UnrestrictedDataAccess.this,
|
||||
mEntry);
|
||||
}
|
||||
AppInfoDashboardFragment.startAppInfoFragment(AppDataUsage.class,
|
||||
R.string.app_data_usage,
|
||||
UnrestrictedDataAccess.this,
|
||||
mEntry);
|
||||
} else {
|
||||
// app is not blacklisted, let superclass handle toggle switch
|
||||
super.onClick();
|
||||
|
@@ -74,7 +74,7 @@ import java.util.List;
|
||||
* An easy way to handle them is to delegate them to {@link #handleDialogClick(int)} and
|
||||
* {@link #handleActivityResult(int, int, Intent)} in this controller.
|
||||
*/
|
||||
//TODO(b/35810915): Make InstalledAppDetails use this controller
|
||||
//TODO(b/35810915): Make AppInfoDashboardFragment use this controller
|
||||
public class AppButtonsPreferenceController extends AbstractPreferenceController implements
|
||||
PreferenceControllerMixin, LifecycleObserver, OnResume, OnDestroy,
|
||||
ApplicationsState.Callbacks {
|
||||
|
@@ -20,19 +20,15 @@ import android.support.annotation.VisibleForTesting;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceCategory;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
import android.util.FeatureFlagUtils;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.applications.InstalledAppDetails;
|
||||
import com.android.settings.applications.appinfo.AppInfoDashboardFragment;
|
||||
import com.android.settings.core.FeatureFlags;
|
||||
import com.android.settings.widget.AppPreference;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
import com.android.settingslib.location.RecentLocationApps;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
public class RecentLocationRequestPreferenceController extends LocationBasePreferenceController {
|
||||
@@ -60,19 +56,11 @@ public class RecentLocationRequestPreferenceController extends LocationBasePrefe
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
// start new fragment to display extended information
|
||||
final Bundle args = new Bundle();
|
||||
if (FeatureFlagUtils.isEnabled(mFragment.getActivity(), FeatureFlags.APP_INFO_V2)) {
|
||||
args.putString(AppInfoDashboardFragment.ARG_PACKAGE_NAME, mPackage);
|
||||
((SettingsActivity) mFragment.getActivity()).startPreferencePanelAsUser(
|
||||
mFragment,
|
||||
AppInfoDashboardFragment.class.getName(), args,
|
||||
R.string.application_info_label, null, mUserHandle);
|
||||
} else {
|
||||
args.putString(InstalledAppDetails.ARG_PACKAGE_NAME, mPackage);
|
||||
((SettingsActivity) mFragment.getActivity()).startPreferencePanelAsUser(
|
||||
mFragment,
|
||||
InstalledAppDetails.class.getName(), args,
|
||||
R.string.application_info_label, null, mUserHandle);
|
||||
}
|
||||
args.putString(AppInfoDashboardFragment.ARG_PACKAGE_NAME, mPackage);
|
||||
((SettingsActivity) mFragment.getActivity()).startPreferencePanelAsUser(
|
||||
mFragment,
|
||||
AppInfoDashboardFragment.class.getName(), args,
|
||||
R.string.application_info_label, null, mUserHandle);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@@ -37,7 +37,6 @@ import android.support.annotation.IntDef;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.TextUtils;
|
||||
import android.util.FeatureFlagUtils;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
@@ -48,10 +47,8 @@ import android.widget.TextView;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.applications.AppInfoBase;
|
||||
import com.android.settings.applications.InstalledAppDetails;
|
||||
import com.android.settings.applications.LayoutPreference;
|
||||
import com.android.settings.applications.appinfo.AppInfoDashboardFragment;
|
||||
import com.android.settings.core.FeatureFlags;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settingslib.applications.ApplicationsState;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
@@ -285,17 +282,10 @@ public class EntityHeaderController {
|
||||
entityHeaderContent.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (FeatureFlagUtils.isEnabled(mAppContext, FeatureFlags.APP_INFO_V2)) {
|
||||
AppInfoBase.startAppInfoFragment(
|
||||
AppInfoDashboardFragment.class, R.string.application_info_label,
|
||||
mPackageName, mUid, mFragment, 0 /* request */,
|
||||
mMetricsCategory);
|
||||
} else {
|
||||
AppInfoBase.startAppInfoFragment(
|
||||
InstalledAppDetails.class, R.string.application_info_label,
|
||||
mPackageName, mUid, mFragment, 0 /* request */,
|
||||
mMetricsCategory);
|
||||
}
|
||||
AppInfoBase.startAppInfoFragment(
|
||||
AppInfoDashboardFragment.class, R.string.application_info_label,
|
||||
mPackageName, mUid, mFragment, 0 /* request */,
|
||||
mMetricsCategory);
|
||||
}
|
||||
});
|
||||
return;
|
||||
|
@@ -43,7 +43,6 @@ com.android.settings.fuelgauge.BatteryHistoryDetail
|
||||
com.android.settings.applications.RunningServices
|
||||
com.android.settings.applications.ConfirmConvertToFbe
|
||||
com.android.settings.deviceinfo.PublicVolumeSettings
|
||||
com.android.settings.applications.InstalledAppDetails
|
||||
com.android.settings.accessibility.ToggleAccessibilityServicePreferenceFragment
|
||||
com.android.settings.print.PrintServiceSettingsFragment
|
||||
com.android.settings.deviceinfo.PrivateVolumeSettings
|
||||
|
@@ -1,591 +0,0 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.nullable;
|
||||
import static org.mockito.Matchers.anyDouble;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.app.AppOpsManager;
|
||||
import android.app.Fragment;
|
||||
import android.app.LoaderManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.Resources;
|
||||
import android.os.BatteryStats;
|
||||
import android.os.Bundle;
|
||||
import android.os.UserManager;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceManager;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
import android.view.View;
|
||||
|
||||
import com.android.internal.os.BatterySipper;
|
||||
import com.android.internal.os.BatteryStatsHelper;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.applications.instantapps.InstantAppButtonsController;
|
||||
import com.android.settings.applications.instantapps.InstantAppButtonsController.ShowDialogDelegate;
|
||||
import com.android.settings.fuelgauge.BatteryUtils;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.widget.ActionButtonPreferenceTest;
|
||||
import com.android.settings.wrapper.DevicePolicyManagerWrapper;
|
||||
import com.android.settingslib.Utils;
|
||||
import com.android.settingslib.applications.AppUtils;
|
||||
import com.android.settingslib.applications.ApplicationsState.AppEntry;
|
||||
import com.android.settingslib.applications.StorageStatsSource.AppStorageStats;
|
||||
import com.android.settingslib.applications.instantapps.InstantAppDataProvider;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Answers;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.annotation.Implementation;
|
||||
import org.robolectric.annotation.Implements;
|
||||
import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(
|
||||
manifest = TestConfig.MANIFEST_PATH,
|
||||
sdk = TestConfig.SDK_VERSION,
|
||||
shadows = InstalledAppDetailsTest.ShadowUtils.class
|
||||
)
|
||||
public final class InstalledAppDetailsTest {
|
||||
|
||||
private static final String PACKAGE_NAME = "test_package_name";
|
||||
private static final int TARGET_UID = 111;
|
||||
private static final int OTHER_UID = 222;
|
||||
private static final double BATTERY_LEVEL = 60;
|
||||
private static final String BATTERY_LEVEL_STRING = "60%";
|
||||
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private Context mContext;
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private UserManager mUserManager;
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private SettingsActivity mActivity;
|
||||
@Mock
|
||||
private DevicePolicyManagerWrapper mDevicePolicyManager;
|
||||
@Mock
|
||||
private BatterySipper mBatterySipper;
|
||||
@Mock
|
||||
private BatterySipper mOtherBatterySipper;
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private BatteryStatsHelper mBatteryStatsHelper;
|
||||
@Mock
|
||||
private BatteryStats.Uid mUid;
|
||||
@Mock
|
||||
private PackageManager mPackageManager;
|
||||
@Mock
|
||||
private BatteryUtils mBatteryUtils;
|
||||
@Mock
|
||||
private LoaderManager mLoaderManager;
|
||||
@Mock
|
||||
private AppOpsManager mAppOpsManager;
|
||||
|
||||
private FakeFeatureFactory mFeatureFactory;
|
||||
private InstalledAppDetails mAppDetail;
|
||||
private Context mShadowContext;
|
||||
private Preference mBatteryPreference;
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mFeatureFactory = FakeFeatureFactory.setupForTest();
|
||||
mShadowContext = RuntimeEnvironment.application;
|
||||
mAppDetail = spy(new InstalledAppDetails());
|
||||
mAppDetail.mBatteryUtils = mBatteryUtils;
|
||||
|
||||
mBatteryPreference = new Preference(mShadowContext);
|
||||
mAppDetail.mBatteryPreference = mBatteryPreference;
|
||||
mAppDetail.mActionButtons = ActionButtonPreferenceTest.createMock();
|
||||
|
||||
mBatterySipper.drainType = BatterySipper.DrainType.IDLE;
|
||||
mBatterySipper.uidObj = mUid;
|
||||
doReturn(TARGET_UID).when(mBatterySipper).getUid();
|
||||
doReturn(OTHER_UID).when(mOtherBatterySipper).getUid();
|
||||
doReturn(mActivity).when(mAppDetail).getActivity();
|
||||
doReturn(mShadowContext).when(mAppDetail).getContext();
|
||||
doReturn(mPackageManager).when(mActivity).getPackageManager();
|
||||
doReturn(mAppOpsManager).when(mActivity).getSystemService(Context.APP_OPS_SERVICE);
|
||||
|
||||
// Default to not considering any apps to be instant (individual tests can override this).
|
||||
ReflectionHelpers.setStaticField(AppUtils.class, "sInstantAppDataProvider",
|
||||
(InstantAppDataProvider) (i -> false));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldShowUninstallForAll_installForOneOtherUserOnly_shouldReturnTrue() {
|
||||
when(mDevicePolicyManager.packageHasActiveAdmins(nullable(String.class))).thenReturn(false);
|
||||
when(mUserManager.getUsers().size()).thenReturn(2);
|
||||
ReflectionHelpers.setField(mAppDetail, "mDpm", mDevicePolicyManager);
|
||||
ReflectionHelpers.setField(mAppDetail, "mUserManager", mUserManager);
|
||||
final ApplicationInfo info = new ApplicationInfo();
|
||||
info.enabled = true;
|
||||
final AppEntry appEntry = mock(AppEntry.class);
|
||||
appEntry.info = info;
|
||||
final PackageInfo packageInfo = mock(PackageInfo.class);
|
||||
ReflectionHelpers.setField(mAppDetail, "mPackageInfo", packageInfo);
|
||||
|
||||
assertThat(mAppDetail.shouldShowUninstallForAll(appEntry)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldShowUninstallForAll_installForSelfOnly_shouldReturnFalse() {
|
||||
when(mDevicePolicyManager.packageHasActiveAdmins(nullable(String.class))).thenReturn(false);
|
||||
when(mUserManager.getUsers().size()).thenReturn(2);
|
||||
ReflectionHelpers.setField(mAppDetail, "mDpm", mDevicePolicyManager);
|
||||
ReflectionHelpers.setField(mAppDetail, "mUserManager", mUserManager);
|
||||
final ApplicationInfo info = new ApplicationInfo();
|
||||
info.flags = ApplicationInfo.FLAG_INSTALLED;
|
||||
info.enabled = true;
|
||||
final AppEntry appEntry = mock(AppEntry.class);
|
||||
appEntry.info = info;
|
||||
final PackageInfo packageInfo = mock(PackageInfo.class);
|
||||
ReflectionHelpers.setField(mAppDetail, "mPackageInfo", packageInfo);
|
||||
|
||||
assertThat(mAppDetail.shouldShowUninstallForAll(appEntry)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getStorageSummary_shouldWorkForExternal() {
|
||||
Context context = RuntimeEnvironment.application.getApplicationContext();
|
||||
AppStorageStats stats = mock(AppStorageStats.class);
|
||||
when(stats.getTotalBytes()).thenReturn(1L);
|
||||
|
||||
assertThat(InstalledAppDetails.getStorageSummary(context, stats, true))
|
||||
.isEqualTo("1 B used in external storage");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getStorageSummary_shouldWorkForInternal() {
|
||||
Context context = RuntimeEnvironment.application.getApplicationContext();
|
||||
AppStorageStats stats = mock(AppStorageStats.class);
|
||||
when(stats.getTotalBytes()).thenReturn(1L);
|
||||
|
||||
assertThat(InstalledAppDetails.getStorageSummary(context, stats, false))
|
||||
.isEqualTo("1 B used in internal storage");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void launchFragment_hasNoPackageInfo_shouldFinish() {
|
||||
ReflectionHelpers.setField(mAppDetail, "mPackageInfo", null);
|
||||
|
||||
assertThat(mAppDetail.ensurePackageInfoAvailable(mActivity)).isFalse();
|
||||
verify(mActivity).finishAndRemoveTask();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void launchFragment_hasPackageInfo_shouldReturnTrue() {
|
||||
final PackageInfo packageInfo = mock(PackageInfo.class);
|
||||
ReflectionHelpers.setField(mAppDetail, "mPackageInfo", packageInfo);
|
||||
|
||||
assertThat(mAppDetail.ensurePackageInfoAvailable(mActivity)).isTrue();
|
||||
verify(mActivity, never()).finishAndRemoveTask();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void packageSizeChange_isOtherPackage_shouldNotRefreshUi() {
|
||||
ReflectionHelpers.setField(mAppDetail, "mPackageName", PACKAGE_NAME);
|
||||
mAppDetail.onPackageSizeChanged("Not_" + PACKAGE_NAME);
|
||||
|
||||
verify(mAppDetail, never()).refreshUi();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void packageSizeChange_isOwnPackage_shouldRefreshUi() {
|
||||
doReturn(Boolean.TRUE).when(mAppDetail).refreshUi();
|
||||
ReflectionHelpers.setField(mAppDetail, "mPackageName", PACKAGE_NAME);
|
||||
|
||||
mAppDetail.onPackageSizeChanged(PACKAGE_NAME);
|
||||
|
||||
verify(mAppDetail).refreshUi();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void launchPowerUsageDetailFragment_shouldNotCrash() {
|
||||
mAppDetail.mBatteryPreference = mBatteryPreference;
|
||||
mAppDetail.mSipper = mBatterySipper;
|
||||
mAppDetail.mBatteryHelper = mBatteryStatsHelper;
|
||||
|
||||
// Should not crash
|
||||
mAppDetail.onPreferenceClick(mBatteryPreference);
|
||||
}
|
||||
|
||||
// Tests that we don't show the "uninstall for all users" button for instant apps.
|
||||
@Test
|
||||
public void instantApps_noUninstallForAllButton() {
|
||||
// Make this app appear to be instant.
|
||||
ReflectionHelpers.setStaticField(AppUtils.class, "sInstantAppDataProvider",
|
||||
(InstantAppDataProvider) (i -> true));
|
||||
when(mDevicePolicyManager.packageHasActiveAdmins(nullable(String.class))).thenReturn(false);
|
||||
when(mUserManager.getUsers().size()).thenReturn(2);
|
||||
|
||||
final ApplicationInfo info = new ApplicationInfo();
|
||||
info.enabled = true;
|
||||
final AppEntry appEntry = mock(AppEntry.class);
|
||||
appEntry.info = info;
|
||||
final PackageInfo packageInfo = mock(PackageInfo.class);
|
||||
|
||||
ReflectionHelpers.setField(mAppDetail, "mDpm", mDevicePolicyManager);
|
||||
ReflectionHelpers.setField(mAppDetail, "mUserManager", mUserManager);
|
||||
ReflectionHelpers.setField(mAppDetail, "mPackageInfo", packageInfo);
|
||||
|
||||
assertThat(mAppDetail.shouldShowUninstallForAll(appEntry)).isFalse();
|
||||
}
|
||||
|
||||
// Tests that we don't show the uninstall button for instant apps"
|
||||
@Test
|
||||
public void instantApps_noUninstallButton() {
|
||||
// Make this app appear to be instant.
|
||||
ReflectionHelpers.setStaticField(AppUtils.class, "sInstantAppDataProvider",
|
||||
(InstantAppDataProvider) (i -> true));
|
||||
final ApplicationInfo info = new ApplicationInfo();
|
||||
info.flags = ApplicationInfo.FLAG_INSTALLED;
|
||||
info.enabled = true;
|
||||
final AppEntry appEntry = mock(AppEntry.class);
|
||||
appEntry.info = info;
|
||||
final PackageInfo packageInfo = mock(PackageInfo.class);
|
||||
packageInfo.applicationInfo = info;
|
||||
|
||||
ReflectionHelpers.setField(mAppDetail, "mUserManager", mUserManager);
|
||||
ReflectionHelpers.setField(mAppDetail, "mAppEntry", appEntry);
|
||||
ReflectionHelpers.setField(mAppDetail, "mPackageInfo", packageInfo);
|
||||
|
||||
mAppDetail.initUninstallButtonForUserApp();
|
||||
verify(mAppDetail.mActionButtons).setButton1Visible(false);
|
||||
}
|
||||
|
||||
// Tests that we don't show the force stop button for instant apps (they aren't allowed to run
|
||||
// when they aren't in the foreground).
|
||||
@Test
|
||||
public void instantApps_noForceStop() {
|
||||
// Make this app appear to be instant.
|
||||
ReflectionHelpers.setStaticField(AppUtils.class, "sInstantAppDataProvider",
|
||||
(InstantAppDataProvider) (i -> true));
|
||||
final PackageInfo packageInfo = mock(PackageInfo.class);
|
||||
final AppEntry appEntry = mock(AppEntry.class);
|
||||
final ApplicationInfo info = new ApplicationInfo();
|
||||
appEntry.info = info;
|
||||
|
||||
ReflectionHelpers.setField(mAppDetail, "mDpm", mDevicePolicyManager);
|
||||
ReflectionHelpers.setField(mAppDetail, "mPackageInfo", packageInfo);
|
||||
ReflectionHelpers.setField(mAppDetail, "mAppEntry", appEntry);
|
||||
|
||||
mAppDetail.checkForceStop();
|
||||
verify(mAppDetail.mActionButtons).setButton2Visible(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void instantApps_buttonControllerHandlesDialog() {
|
||||
InstantAppButtonsController mockController = mock(InstantAppButtonsController.class);
|
||||
ReflectionHelpers.setField(
|
||||
mAppDetail, "mInstantAppButtonsController", mockController);
|
||||
// Make sure first that button controller is not called for supported dialog id
|
||||
AlertDialog mockDialog = mock(AlertDialog.class);
|
||||
when(mockController.createDialog(InstantAppButtonsController.DLG_CLEAR_APP))
|
||||
.thenReturn(mockDialog);
|
||||
assertThat(mAppDetail.createDialog(InstantAppButtonsController.DLG_CLEAR_APP, 0))
|
||||
.isEqualTo(mockDialog);
|
||||
verify(mockController).createDialog(InstantAppButtonsController.DLG_CLEAR_APP);
|
||||
}
|
||||
|
||||
// A helper class for testing the InstantAppButtonsController - it lets us look up the
|
||||
// preference associated with a key for instant app buttons and get back a mock
|
||||
// LayoutPreference (to avoid a null pointer exception).
|
||||
public static class InstalledAppDetailsWithMockInstantButtons extends InstalledAppDetails {
|
||||
@Mock
|
||||
private LayoutPreference mInstantButtons;
|
||||
|
||||
public InstalledAppDetailsWithMockInstantButtons() {
|
||||
super();
|
||||
MockitoAnnotations.initMocks(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Preference findPreference(CharSequence key) {
|
||||
if (key == "instant_app_buttons") {
|
||||
return mInstantButtons;
|
||||
}
|
||||
return super.findPreference(key);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void instantApps_instantSpecificButtons() {
|
||||
// Make this app appear to be instant.
|
||||
ReflectionHelpers.setStaticField(AppUtils.class, "sInstantAppDataProvider",
|
||||
(InstantAppDataProvider) (i -> true));
|
||||
final PackageInfo packageInfo = mock(PackageInfo.class);
|
||||
|
||||
final InstalledAppDetailsWithMockInstantButtons
|
||||
fragment = new InstalledAppDetailsWithMockInstantButtons();
|
||||
ReflectionHelpers.setField(fragment, "mPackageInfo", packageInfo);
|
||||
ReflectionHelpers.setField(fragment, "mApplicationFeatureProvider",
|
||||
mFeatureFactory.applicationFeatureProvider);
|
||||
|
||||
final InstantAppButtonsController buttonsController =
|
||||
mock(InstantAppButtonsController.class);
|
||||
when(buttonsController.setPackageName(nullable(String.class)))
|
||||
.thenReturn(buttonsController);
|
||||
when(mFeatureFactory.applicationFeatureProvider.newInstantAppButtonsController(
|
||||
nullable(Fragment.class), nullable(View.class), nullable(ShowDialogDelegate.class)))
|
||||
.thenReturn(buttonsController);
|
||||
|
||||
fragment.maybeAddInstantAppButtons();
|
||||
verify(buttonsController).setPackageName(nullable(String.class));
|
||||
verify(buttonsController).show();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void instantApps_removeCorrectPref() {
|
||||
PreferenceScreen mockPreferenceScreen = mock(PreferenceScreen.class);
|
||||
PreferenceManager mockPreferenceManager = mock(PreferenceManager.class);
|
||||
AppDomainsPreference mockAppDomainsPref = mock(AppDomainsPreference.class);
|
||||
Preference mockLaunchPreference = mock(Preference.class);
|
||||
PackageInfo mockPackageInfo = mock(PackageInfo.class);
|
||||
PackageManager mockPackageManager = mock(PackageManager.class);
|
||||
ReflectionHelpers.setField(
|
||||
mAppDetail, "mLaunchPreference", mockLaunchPreference);
|
||||
ReflectionHelpers.setField(
|
||||
mAppDetail, "mInstantAppDomainsPreference", mockAppDomainsPref);
|
||||
ReflectionHelpers.setField(
|
||||
mAppDetail, "mPreferenceManager", mockPreferenceManager);
|
||||
ReflectionHelpers.setField(
|
||||
mAppDetail, "mPackageInfo", mockPackageInfo);
|
||||
ReflectionHelpers.setField(
|
||||
mAppDetail, "mPm", mockPackageManager);
|
||||
when(mockPreferenceManager.getPreferenceScreen()).thenReturn(mockPreferenceScreen);
|
||||
|
||||
ReflectionHelpers.setStaticField(AppUtils.class, "sInstantAppDataProvider",
|
||||
(InstantAppDataProvider) (i -> false));
|
||||
mAppDetail.prepareInstantAppPrefs();
|
||||
|
||||
// For the non instant case we remove the app domain pref, and leave the launch pref
|
||||
verify(mockPreferenceScreen).removePreference(mockAppDomainsPref);
|
||||
verify(mockPreferenceScreen, never()).removePreference(mockLaunchPreference);
|
||||
|
||||
// For the instant app case we remove the launch preff, and leave the app domain pref
|
||||
ReflectionHelpers.setStaticField(AppUtils.class, "sInstantAppDataProvider",
|
||||
(InstantAppDataProvider) (i -> true));
|
||||
|
||||
mAppDetail.prepareInstantAppPrefs();
|
||||
verify(mockPreferenceScreen).removePreference(mockLaunchPreference);
|
||||
// Will be 1 still due to above call
|
||||
verify(mockPreferenceScreen, times(1))
|
||||
.removePreference(mockAppDomainsPref);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onActivityResult_uninstalledUpdates_shouldInvalidateOptionsMenu() {
|
||||
doReturn(true).when(mAppDetail).refreshUi();
|
||||
|
||||
mAppDetail.onActivityResult(InstalledAppDetails.REQUEST_UNINSTALL, 0, mock(Intent.class));
|
||||
|
||||
verify(mActivity).invalidateOptionsMenu();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findTargetSipper_findCorrectSipper() {
|
||||
List<BatterySipper> usageList = new ArrayList<>();
|
||||
usageList.add(mBatterySipper);
|
||||
usageList.add(mOtherBatterySipper);
|
||||
doReturn(usageList).when(mBatteryStatsHelper).getUsageList();
|
||||
|
||||
assertThat(mAppDetail.findTargetSipper(mBatteryStatsHelper, TARGET_UID)).isEqualTo(
|
||||
mBatterySipper);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateBattery_noBatteryStats_summaryNo() {
|
||||
doReturn(mShadowContext.getString(R.string.no_battery_summary)).when(mAppDetail).getString(
|
||||
R.string.no_battery_summary);
|
||||
mAppDetail.updateBattery();
|
||||
|
||||
assertThat(mBatteryPreference.getSummary()).isEqualTo(
|
||||
"No battery use since last full charge");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateBattery_hasBatteryStats_summaryPercent() {
|
||||
mAppDetail.mBatteryHelper = mBatteryStatsHelper;
|
||||
mAppDetail.mSipper = mBatterySipper;
|
||||
doReturn(BATTERY_LEVEL).when(mBatteryUtils).calculateBatteryPercent(anyDouble(),
|
||||
anyDouble(), anyDouble(), anyInt());
|
||||
doReturn(mShadowContext.getString(R.string.battery_summary, BATTERY_LEVEL_STRING)).when(
|
||||
mAppDetail).getString(R.string.battery_summary, BATTERY_LEVEL_STRING);
|
||||
doReturn(new ArrayList<>()).when(mBatteryStatsHelper).getUsageList();
|
||||
|
||||
mAppDetail.updateBattery();
|
||||
|
||||
assertThat(mBatteryPreference.getSummary()).isEqualTo("60% use since last full charge");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isBatteryStatsAvailable_hasBatteryStatsHelperAndSipper_returnTrue() {
|
||||
mAppDetail.mBatteryHelper = mBatteryStatsHelper;
|
||||
mAppDetail.mSipper = mBatterySipper;
|
||||
|
||||
assertThat(mAppDetail.isBatteryStatsAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isBatteryStatsAvailable_parametersNull_returnFalse() {
|
||||
assertThat(mAppDetail.isBatteryStatsAvailable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handleDisableable_appIsHomeApp_buttonShouldNotWork() {
|
||||
final ApplicationInfo info = new ApplicationInfo();
|
||||
info.packageName = "pkg";
|
||||
info.enabled = true;
|
||||
final AppEntry appEntry = mock(AppEntry.class);
|
||||
appEntry.info = info;
|
||||
final HashSet<String> homePackages = new HashSet<>();
|
||||
homePackages.add(info.packageName);
|
||||
|
||||
ReflectionHelpers.setField(mAppDetail, "mHomePackages", homePackages);
|
||||
ReflectionHelpers.setField(mAppDetail, "mAppEntry", appEntry);
|
||||
|
||||
assertThat(mAppDetail.handleDisableable()).isFalse();
|
||||
verify(mAppDetail.mActionButtons).setButton1Text(R.string.disable_text);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handleDisableable_appIsEnabled_buttonShouldWork() {
|
||||
final ApplicationInfo info = new ApplicationInfo();
|
||||
info.packageName = "pkg";
|
||||
info.enabled = true;
|
||||
info.enabledSetting = PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
|
||||
|
||||
final AppEntry appEntry = mock(AppEntry.class);
|
||||
appEntry.info = info;
|
||||
when(mFeatureFactory.applicationFeatureProvider.getKeepEnabledPackages()).thenReturn(
|
||||
new HashSet<>());
|
||||
|
||||
ReflectionHelpers.setField(mAppDetail, "mApplicationFeatureProvider",
|
||||
mFeatureFactory.applicationFeatureProvider);
|
||||
ReflectionHelpers.setField(mAppDetail, "mAppEntry", appEntry);
|
||||
|
||||
assertThat(mAppDetail.handleDisableable()).isTrue();
|
||||
verify(mAppDetail.mActionButtons).setButton1Text(R.string.disable_text);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = ShadowUtils.class)
|
||||
public void handleDisableable_appIsDisabled_buttonShouldShowEnable() {
|
||||
final ApplicationInfo info = new ApplicationInfo();
|
||||
info.packageName = "pkg";
|
||||
info.enabled = false;
|
||||
info.enabledSetting = PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
|
||||
|
||||
final AppEntry appEntry = mock(AppEntry.class);
|
||||
appEntry.info = info;
|
||||
when(mFeatureFactory.applicationFeatureProvider.getKeepEnabledPackages()).thenReturn(
|
||||
new HashSet<>());
|
||||
|
||||
ReflectionHelpers.setField(mAppDetail, "mApplicationFeatureProvider",
|
||||
mFeatureFactory.applicationFeatureProvider);
|
||||
ReflectionHelpers.setField(mAppDetail, "mAppEntry", appEntry);
|
||||
|
||||
assertThat(mAppDetail.handleDisableable()).isTrue();
|
||||
verify(mAppDetail.mActionButtons).setButton1Text(R.string.enable_text);
|
||||
verify(mAppDetail.mActionButtons).setButton1Positive(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handleDisableable_appIsEnabledAndInKeepEnabledWhitelist_buttonShouldNotWork() {
|
||||
final ApplicationInfo info = new ApplicationInfo();
|
||||
info.packageName = "pkg";
|
||||
info.enabled = true;
|
||||
info.enabledSetting = PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
|
||||
|
||||
final AppEntry appEntry = mock(AppEntry.class);
|
||||
appEntry.info = info;
|
||||
|
||||
final HashSet<String> packages = new HashSet<>();
|
||||
packages.add(info.packageName);
|
||||
when(mFeatureFactory.applicationFeatureProvider.getKeepEnabledPackages()).thenReturn(
|
||||
packages);
|
||||
|
||||
ReflectionHelpers.setField(mAppDetail, "mApplicationFeatureProvider",
|
||||
mFeatureFactory.applicationFeatureProvider);
|
||||
ReflectionHelpers.setField(mAppDetail, "mAppEntry", appEntry);
|
||||
|
||||
assertThat(mAppDetail.handleDisableable()).isFalse();
|
||||
verify(mAppDetail.mActionButtons).setButton1Text(R.string.disable_text);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRestartBatteryStatsLoader() {
|
||||
doReturn(mLoaderManager).when(mAppDetail).getLoaderManager();
|
||||
|
||||
mAppDetail.restartBatteryStatsLoader();
|
||||
|
||||
verify(mLoaderManager).restartLoader(InstalledAppDetails.LOADER_BATTERY, Bundle.EMPTY,
|
||||
mAppDetail.mBatteryCallbacks);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initUninstallButtonForUserApp_shouldSetNegativeButton() {
|
||||
final ApplicationInfo info = new ApplicationInfo();
|
||||
info.flags = ApplicationInfo.FLAG_INSTALLED;
|
||||
info.enabled = true;
|
||||
final PackageInfo packageInfo = mock(PackageInfo.class);
|
||||
packageInfo.applicationInfo = info;
|
||||
ReflectionHelpers.setField(mAppDetail, "mUserManager", mUserManager);
|
||||
ReflectionHelpers.setField(mAppDetail, "mPackageInfo", packageInfo);
|
||||
|
||||
mAppDetail.initUninstallButtonForUserApp();
|
||||
|
||||
verify(mAppDetail.mActionButtons).setButton1Positive(false);
|
||||
}
|
||||
|
||||
@Implements(Utils.class)
|
||||
public static class ShadowUtils {
|
||||
@Implementation
|
||||
public static boolean isSystemPackage(Resources resources, PackageManager pm,
|
||||
PackageInfo pkg) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@@ -33,14 +33,11 @@ import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceCategory;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
import android.text.TextUtils;
|
||||
import android.util.FeatureFlagUtils;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.applications.InstalledAppDetails;
|
||||
import com.android.settings.applications.appinfo.AppInfoDashboardFragment;
|
||||
import com.android.settings.core.FeatureFlags;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.widget.AppPreference;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
@@ -179,15 +176,9 @@ public class RecentLocationRequestPreferenceControllerTest {
|
||||
|
||||
preference.performClick();
|
||||
|
||||
if (FeatureFlagUtils.isEnabled(mContext, FeatureFlags.APP_INFO_V2)) {
|
||||
verify(activity).startPreferencePanelAsUser(any(),
|
||||
eq(AppInfoDashboardFragment.class.getName()),
|
||||
any(Bundle.class), anyInt(), any(), any());
|
||||
} else {
|
||||
verify(activity).startPreferencePanelAsUser(any(),
|
||||
eq(InstalledAppDetails.class.getName()),
|
||||
any(Bundle.class), anyInt(), any(), any());
|
||||
}
|
||||
verify(activity).startPreferencePanelAsUser(any(),
|
||||
eq(AppInfoDashboardFragment.class.getName()),
|
||||
any(Bundle.class), anyInt(), any(), any());
|
||||
}
|
||||
|
||||
private static ArgumentMatcher<Preference> titleMatches(String expected) {
|
||||
|
@@ -1,94 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2016 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;
|
||||
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.UserInfo;
|
||||
import android.os.UserManager;
|
||||
import android.support.test.filters.SmallTest;
|
||||
import android.support.test.runner.AndroidJUnit4;
|
||||
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;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
@SmallTest
|
||||
@Deprecated
|
||||
public class PackageUtilTest {
|
||||
private static final String ALL_USERS_APP_NAME = "com.google.allusers.app";
|
||||
private static final String ONE_USER_APP_NAME = "com.google.oneuser.app";
|
||||
private static final int USER1_ID = 1;
|
||||
private static final int USER2_ID = 11;
|
||||
|
||||
@Mock
|
||||
private PackageManager mMockPackageManager;
|
||||
@Mock
|
||||
private UserManager mMockUserManager;
|
||||
|
||||
private InstalledAppDetails.PackageUtil mPackageUtil;
|
||||
private List<UserInfo> mUserInfos;
|
||||
|
||||
@Before
|
||||
public void setUp() throws PackageManager.NameNotFoundException {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
mUserInfos = new ArrayList<>();
|
||||
mUserInfos.add(new UserInfo(USER1_ID, "lei", 0));
|
||||
mUserInfos.add(new UserInfo(USER2_ID, "yue", 0));
|
||||
when(mMockUserManager.getUsers(true)).thenReturn(mUserInfos);
|
||||
|
||||
ApplicationInfo usersApp = new ApplicationInfo();
|
||||
usersApp.flags = ApplicationInfo.FLAG_INSTALLED;
|
||||
|
||||
when(mMockPackageManager.getApplicationInfoAsUser(
|
||||
ALL_USERS_APP_NAME, PackageManager.GET_META_DATA, USER1_ID))
|
||||
.thenReturn(usersApp);
|
||||
when(mMockPackageManager.getApplicationInfoAsUser(
|
||||
ALL_USERS_APP_NAME, PackageManager.GET_META_DATA, USER2_ID))
|
||||
.thenReturn(usersApp);
|
||||
|
||||
when(mMockPackageManager.getApplicationInfoAsUser(
|
||||
ONE_USER_APP_NAME, PackageManager.GET_META_DATA, USER1_ID))
|
||||
.thenReturn(usersApp);
|
||||
|
||||
when(mMockPackageManager.getApplicationInfoAsUser(
|
||||
ONE_USER_APP_NAME, PackageManager.GET_META_DATA, USER2_ID))
|
||||
.thenThrow(new PackageManager.NameNotFoundException());
|
||||
|
||||
mPackageUtil = new InstalledAppDetails.PackageUtil();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCountPackageInUsers_twoUsersInstalled_returnTwo() {
|
||||
assertEquals(2, mPackageUtil.countPackageInUsers(
|
||||
mMockPackageManager, mMockUserManager, ALL_USERS_APP_NAME));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCountPackageInUsers_oneUsersInstalled_returnOne() {
|
||||
assertEquals(1, mPackageUtil.countPackageInUsers(
|
||||
mMockPackageManager, mMockUserManager, ONE_USER_APP_NAME));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user