Merge "Import translations. DO NOT MERGE" into oc-dev
diff --git a/res/layout/wifi_network_details_two_buttons_panel.xml b/res/layout/wifi_network_details_two_buttons_panel.xml
new file mode 100644
index 0000000..6abfac3
--- /dev/null
+++ b/res/layout/wifi_network_details_two_buttons_panel.xml
@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<!--
+ Defines a panel with two buttons and a spacer in between.
+ The right button uses the Material.Button.Colored style.
+-->
+
+<LinearLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:gravity="bottom"
+ android:paddingTop="4dip"
+ android:orientation="horizontal">
+ <Button
+ android:id="@+id/forget_button"
+ android:layout_width="120dip"
+ android:layout_weight="0.4"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_vertical"/>
+ <!-- Spacer -->
+ <View
+ android:id="@+id/buttons_spacer_left"
+ android:layout_width="0dip"
+ android:layout_height="wrap_content"
+ android:visibility="invisible"
+ android:layout_weight="0.2" />
+ <Button
+ style="@android:style/Widget.Material.Button.Colored"
+ android:id="@+id/signin_button"
+ android:layout_width="120dip"
+ android:text="@string/cancel"
+ android:layout_weight="0.4"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_vertical"/>
+</LinearLayout>
diff --git a/res/xml/wifi_network_details_fragment.xml b/res/xml/wifi_network_details_fragment.xml
index 5d5958d..fafbbb0 100644
--- a/res/xml/wifi_network_details_fragment.xml
+++ b/res/xml/wifi_network_details_fragment.xml
@@ -29,7 +29,7 @@
<!-- Buttons -->
<com.android.settings.applications.LayoutPreference
android:key="buttons"
- android:layout="@layout/two_buttons_panel"
+ android:layout="@layout/wifi_network_details_two_buttons_panel"
android:selectable="false" />
<com.android.settings.wifi.WifiDetailPreference
diff --git a/src/com/android/settings/DeviceAdminAdd.java b/src/com/android/settings/DeviceAdminAdd.java
index fb2f29f..5978f5e 100644
--- a/src/com/android/settings/DeviceAdminAdd.java
+++ b/src/com/android/settings/DeviceAdminAdd.java
@@ -40,6 +40,7 @@
import android.os.Binder;
import android.os.Bundle;
import android.os.Handler;
+import android.os.IBinder;
import android.os.RemoteCallback;
import android.os.RemoteException;
import android.os.UserHandle;
@@ -90,6 +91,7 @@
public static final String EXTRA_CALLED_FROM_SUPPORT_DIALOG =
"android.app.extra.CALLED_FROM_SUPPORT_DIALOG";
+ private final IBinder mToken = new Binder();
Handler mHandler;
DevicePolicyManager mDPM;
@@ -118,8 +120,6 @@
boolean mWaitingForRemoveMsg;
boolean mAddingProfileOwner;
boolean mAdminPoliciesInitialized;
- int mCurSysAppOpMode;
- int mCurToastAppOpMode;
boolean mIsCalledFromSupportDialog = false;
@@ -352,6 +352,9 @@
restrictedAction.setFilterTouchesWhenObscured(true);
restrictedAction.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
+ if (!mActionButton.isEnabled()) {
+ return;
+ }
if (mAdding) {
addAndFinish();
} else if (isManagedProfile(mDeviceAdmin)
@@ -473,24 +476,21 @@
@Override
protected void onResume() {
super.onResume();
+ mActionButton.setEnabled(true);
updateInterface();
- // As long as we are running, don't let this admin overlay stuff on top of the screen.
- final int uid = mDeviceAdmin.getActivityInfo().applicationInfo.uid;
- final String pkg = mDeviceAdmin.getActivityInfo().applicationInfo.packageName;
- mCurSysAppOpMode = mAppOps.checkOp(AppOpsManager.OP_SYSTEM_ALERT_WINDOW, uid, pkg);
- mCurToastAppOpMode = mAppOps.checkOp(AppOpsManager.OP_TOAST_WINDOW, uid, pkg);
- mAppOps.setMode(AppOpsManager.OP_SYSTEM_ALERT_WINDOW, uid, pkg, AppOpsManager.MODE_IGNORED);
- mAppOps.setMode(AppOpsManager.OP_TOAST_WINDOW, uid, pkg, AppOpsManager.MODE_IGNORED);
+ // As long as we are running, don't let anyone overlay stuff on top of the screen.
+ mAppOps.setUserRestriction(AppOpsManager.OP_SYSTEM_ALERT_WINDOW, true, mToken);
+ mAppOps.setUserRestriction(AppOpsManager.OP_TOAST_WINDOW, true, mToken);
+
}
@Override
protected void onPause() {
super.onPause();
- // As long as we are running, don't let this admin overlay stuff on top of the screen.
- final int uid = mDeviceAdmin.getActivityInfo().applicationInfo.uid;
- final String pkg = mDeviceAdmin.getActivityInfo().applicationInfo.packageName;
- mAppOps.setMode(AppOpsManager.OP_SYSTEM_ALERT_WINDOW, uid, pkg, mCurSysAppOpMode);
- mAppOps.setMode(AppOpsManager.OP_TOAST_WINDOW, uid, pkg, mCurToastAppOpMode);
+ // This just greys out the button. The actual listener is attached to R.id.restricted_action
+ mActionButton.setEnabled(false);
+ mAppOps.setUserRestriction(AppOpsManager.OP_SYSTEM_ALERT_WINDOW, false, mToken);
+ mAppOps.setUserRestriction(AppOpsManager.OP_TOAST_WINDOW, false, mToken);
try {
ActivityManager.getService().resumeAppSwitches();
} catch (RemoteException e) {
diff --git a/src/com/android/settings/applications/defaultapps/DefaultHomePicker.java b/src/com/android/settings/applications/defaultapps/DefaultHomePicker.java
index 038267b..dca7ad1 100644
--- a/src/com/android/settings/applications/defaultapps/DefaultHomePicker.java
+++ b/src/com/android/settings/applications/defaultapps/DefaultHomePicker.java
@@ -63,13 +63,15 @@
}
final String summary;
+ boolean enabled = true;
if (mustSupportManagedProfile && !launcherHasManagedProfilesFeature(resolveInfo)) {
summary = getContext().getString(R.string.home_work_profile_not_supported);
+ enabled = false;
} else {
summary = null;
}
final DefaultAppInfo candidate =
- new DefaultAppInfo(mPm, mUserId, activityName, summary);
+ new DefaultAppInfo(mPm, mUserId, activityName, summary, enabled);
candidates.add(candidate);
}
return candidates;
diff --git a/src/com/android/settings/deviceinfo/StorageDashboardFragment.java b/src/com/android/settings/deviceinfo/StorageDashboardFragment.java
index 4974f78..13b3d0b 100644
--- a/src/com/android/settings/deviceinfo/StorageDashboardFragment.java
+++ b/src/com/android/settings/deviceinfo/StorageDashboardFragment.java
@@ -131,7 +131,7 @@
}
}
- mPreferenceController.onLoadFinished(mAppsResult.get(UserHandle.myUserId()));
+ mPreferenceController.onLoadFinished(mAppsResult, UserHandle.myUserId());
updateSecondaryUserControllers(mSecondaryUsers, mAppsResult);
// setLoading always causes a flicker, so let's avoid doing it.
diff --git a/src/com/android/settings/deviceinfo/StorageProfileFragment.java b/src/com/android/settings/deviceinfo/StorageProfileFragment.java
index 7e2d941..dee6793 100644
--- a/src/com/android/settings/deviceinfo/StorageProfileFragment.java
+++ b/src/com/android/settings/deviceinfo/StorageProfileFragment.java
@@ -120,7 +120,8 @@
@Override
public void onLoadFinished(Loader<SparseArray<AppsStorageResult>> loader,
SparseArray<AppsStorageResult> result) {
- mPreferenceController.onLoadFinished(scrubAppsFromResult(result.get(mUserId)));
+ scrubAppsFromResult(result.get(mUserId));
+ mPreferenceController.onLoadFinished(result, mUserId);
}
@Override
diff --git a/src/com/android/settings/deviceinfo/storage/StorageAsyncLoader.java b/src/com/android/settings/deviceinfo/storage/StorageAsyncLoader.java
index 8652804..74474b3 100644
--- a/src/com/android/settings/deviceinfo/storage/StorageAsyncLoader.java
+++ b/src/com/android/settings/deviceinfo/storage/StorageAsyncLoader.java
@@ -22,8 +22,8 @@
import android.content.Context;
import android.content.pm.ApplicationInfo;
-import android.content.pm.UserInfo;
import android.content.pm.PackageManager.NameNotFoundException;
+import android.content.pm.UserInfo;
import android.os.UserHandle;
import android.util.Log;
import android.util.SparseArray;
@@ -87,45 +87,43 @@
stats = mStatsManager.getStatsForPackage(mUuid, app.packageName, myUser);
} catch (NameNotFoundException | IOException e) {
// This may happen if the package was removed during our calculation.
- Log.w("App unexpectedly not found", e);
+ Log.w(TAG, "App unexpectedly not found", e);
continue;
}
- long attributedAppSizeInBytes = stats.getDataBytes();
- // This matches how the package manager calculates sizes -- by zeroing out code sizes of
- // system apps which are not updated. My initial tests suggest that this results in the
- // original code size being counted for updated system apps when they shouldn't, but
- // I am not sure how to avoid this problem without specifically going in to find that
- // code size.
- if (!app.isSystemApp() || app.isUpdatedSystemApp()) {
- attributedAppSizeInBytes += stats.getCodeBytes();
- } else {
- result.systemSize += stats.getCodeBytes();
+ long blamedSize = stats.getDataBytes() - stats.getCacheBytes();
+
+ // Only count app code against the current user; we don't want
+ // double-counting on multi-user devices.
+ if (userId == UserHandle.myUserId()) {
+ blamedSize += stats.getCodeBytes();
}
+
switch (app.category) {
case CATEGORY_GAME:
- result.gamesSize += attributedAppSizeInBytes;
+ result.gamesSize += blamedSize;
break;
case CATEGORY_AUDIO:
- result.musicAppsSize += attributedAppSizeInBytes;
+ result.musicAppsSize += blamedSize;
break;
case CATEGORY_VIDEO:
- result.videoAppsSize += attributedAppSizeInBytes;
+ result.videoAppsSize += blamedSize;
break;
default:
// The deprecated game flag does not set the category.
if ((app.flags & ApplicationInfo.FLAG_IS_GAME) != 0) {
- result.gamesSize += attributedAppSizeInBytes;
+ result.gamesSize += blamedSize;
break;
}
- result.otherAppsSize += attributedAppSizeInBytes;
+ result.otherAppsSize += blamedSize;
break;
}
}
Log.d(TAG, "Loading external stats");
try {
- result.externalStats = mStatsManager.getExternalStorageStats(mUuid, UserHandle.of(userId));
+ result.externalStats = mStatsManager.getExternalStorageStats(mUuid,
+ UserHandle.of(userId));
} catch (IOException e) {
Log.w(TAG, e);
}
@@ -142,7 +140,6 @@
public long musicAppsSize;
public long videoAppsSize;
public long otherAppsSize;
- public long systemSize;
public StorageStatsSource.ExternalStorageStats externalStats;
}
diff --git a/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceController.java b/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceController.java
index f8df375..cebd114 100644
--- a/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceController.java
+++ b/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceController.java
@@ -23,6 +23,7 @@
import android.content.pm.PackageManager;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
+import android.net.TrafficStats;
import android.os.Bundle;
import android.os.UserHandle;
import android.os.storage.VolumeInfo;
@@ -30,6 +31,7 @@
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;
import android.util.Log;
+import android.util.SparseArray;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R;
@@ -237,7 +239,10 @@
setFilesPreferenceVisibility();
}
- public void onLoadFinished(StorageAsyncLoader.AppsStorageResult data) {
+ public void onLoadFinished(SparseArray<StorageAsyncLoader.AppsStorageResult> result,
+ int userId) {
+ final StorageAsyncLoader.AppsStorageResult data = result.get(userId);
+
// TODO(b/35927909): Figure out how to split out apps which are only installed for work
// profiles in order to attribute those app's code bytes only to that profile.
mPhotoPreference.setStorageSize(
@@ -248,23 +253,30 @@
mMoviesPreference.setStorageSize(data.videoAppsSize, mTotalSize);
mAppPreference.setStorageSize(data.otherAppsSize, mTotalSize);
- long unattributedExternalBytes =
+ long otherExternalBytes =
data.externalStats.totalBytes
- data.externalStats.audioBytes
- data.externalStats.videoBytes
- - data.externalStats.imageBytes;
- mFilePreference.setStorageSize(unattributedExternalBytes, mTotalSize);
+ - data.externalStats.imageBytes
+ - data.externalStats.appBytes;
+ mFilePreference.setStorageSize(otherExternalBytes, mTotalSize);
- // We define the system size as everything we can't classify.
if (mSystemPreference != null) {
- mSystemPreference.setStorageSize(
- mUsedBytes
- - data.externalStats.totalBytes
- - data.musicAppsSize
- - data.gamesSize
- - data.videoAppsSize
- - data.otherAppsSize,
- mTotalSize);
+ // Everything else that hasn't already been attributed is tracked as
+ // belonging to system.
+ long attributedSize = 0;
+ for (int i = 0; i < result.size(); i++) {
+ final StorageAsyncLoader.AppsStorageResult otherData = result.valueAt(i);
+ attributedSize += otherData.gamesSize
+ + otherData.musicAppsSize
+ + otherData.videoAppsSize
+ + otherData.otherAppsSize;
+ attributedSize += otherData.externalStats.totalBytes
+ - otherData.externalStats.appBytes;
+ }
+
+ final long systemSize = Math.max(TrafficStats.GB_IN_BYTES, mUsedBytes - attributedSize);
+ mSystemPreference.setStorageSize(systemSize, mTotalSize);
}
}
diff --git a/src/com/android/settings/wifi/details/WifiDetailPreferenceController.java b/src/com/android/settings/wifi/details/WifiDetailPreferenceController.java
index a5d922d..b3f83b3 100644
--- a/src/com/android/settings/wifi/details/WifiDetailPreferenceController.java
+++ b/src/com/android/settings/wifi/details/WifiDetailPreferenceController.java
@@ -224,7 +224,7 @@
mConnectionDetailPref = screen.findPreference(KEY_CONNECTION_DETAIL_PREF);
mButtonsPref = (LayoutPreference) screen.findPreference(KEY_BUTTONS_PREF);
- mSignInButton = (Button) mButtonsPref.findViewById(R.id.right_button);
+ mSignInButton = (Button) mButtonsPref.findViewById(R.id.signin_button);
mSignInButton.setText(R.string.support_sign_in_button_text);
mSignInButton.setOnClickListener(
view -> mConnectivityManagerWrapper.startCaptivePortalApp(mNetwork));
@@ -245,7 +245,7 @@
(PreferenceCategory) screen.findPreference(KEY_IPV6_ADDRESS_CATEGORY);
mSecurityPref.setDetailText(mAccessPoint.getSecurityString(false /* concise */));
- mForgetButton = (Button) mButtonsPref.findViewById(R.id.left_button);
+ mForgetButton = (Button) mButtonsPref.findViewById(R.id.forget_button);
mForgetButton.setText(R.string.forget);
mForgetButton.setOnClickListener(view -> forgetNetwork());
updateInfo();
diff --git a/tests/robotests/src/com/android/settings/applications/MusicViewHolderControllerTest.java b/tests/robotests/src/com/android/settings/applications/MusicViewHolderControllerTest.java
index 6440141..779e0b6 100644
--- a/tests/robotests/src/com/android/settings/applications/MusicViewHolderControllerTest.java
+++ b/tests/robotests/src/com/android/settings/applications/MusicViewHolderControllerTest.java
@@ -83,7 +83,7 @@
@Test
public void storageShouldRepresentStorageStatsQuery() throws Exception {
when(mSource.getExternalStorageStats(any(String.class), any(UserHandle.class))).thenReturn(
- new StorageStatsSource.ExternalStorageStats(1, 1, 0, 0));
+ new StorageStatsSource.ExternalStorageStats(1, 1, 0, 0, 0));
mController.queryStats();
mController.setupView(mHolder);
diff --git a/tests/robotests/src/com/android/settings/applications/defaultapps/DefaultHomePickerTest.java b/tests/robotests/src/com/android/settings/applications/defaultapps/DefaultHomePickerTest.java
index 38104a9..f425d2f 100644
--- a/tests/robotests/src/com/android/settings/applications/defaultapps/DefaultHomePickerTest.java
+++ b/tests/robotests/src/com/android/settings/applications/defaultapps/DefaultHomePickerTest.java
@@ -16,11 +16,17 @@
package com.android.settings.applications.defaultapps;
-
import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.IntentFilter;
+import android.content.pm.ActivityInfo;
+import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageManager;
+import android.content.pm.PackageManager.NameNotFoundException;
+import android.content.pm.ResolveInfo;
+import android.content.pm.UserInfo;
+import android.os.Build;
import android.os.UserManager;
import com.android.settings.SettingsRobolectricTestRunner;
@@ -33,14 +39,22 @@
import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.util.ReflectionHelpers;
+import java.util.ArrayList;
+import java.util.List;
+
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.anyList;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -55,7 +69,9 @@
@Mock
private UserManager mUserManager;
@Mock
- private PackageManagerWrapper mPackageManager;
+ private PackageManagerWrapper mPackageManagerWrapper;
+ @Mock
+ private PackageManager mPackageManager;
private DefaultHomePicker mPicker;
@@ -63,28 +79,89 @@
public void setUp() {
MockitoAnnotations.initMocks(this);
when(mActivity.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
+ when(mPackageManagerWrapper.getPackageManager()).thenReturn(mPackageManager);
- mPicker = new DefaultHomePicker();
+ mPicker = spy(new DefaultHomePicker());
mPicker.onAttach((Context) mActivity);
- ReflectionHelpers.setField(mPicker, "mPm", mPackageManager);
+ ReflectionHelpers.setField(mPicker, "mPm", mPackageManagerWrapper);
+ doReturn(RuntimeEnvironment.application).when(mPicker).getContext();
}
@Test
public void setDefaultAppKey_shouldUpdateDefault() {
assertThat(mPicker.setDefaultKey(TEST_APP_KEY)).isTrue();
- verify(mPackageManager).replacePreferredActivity(any(IntentFilter.class),
+ verify(mPackageManagerWrapper).replacePreferredActivity(any(IntentFilter.class),
anyInt(), any(ComponentName[].class), any(ComponentName.class));
}
@Test
public void getDefaultAppKey_shouldReturnDefault() {
final ComponentName cn = mock(ComponentName.class);
- when(mPackageManager.getHomeActivities(anyList()))
+ when(mPackageManagerWrapper.getHomeActivities(anyList()))
.thenReturn(cn);
mPicker.getDefaultKey();
verify(cn).flattenToString();
}
+ @Test
+ public void getCandidates_allLaunchersAvailableIfNoManagedProfile()
+ throws NameNotFoundException {
+ addLaunchers();
+ List<DefaultAppInfo> candidates = mPicker.getCandidates();
+ assertThat(candidates.size()).isEqualTo(2);
+ assertThat(candidates.get(0).summary).isNull();
+ assertThat(candidates.get(0).enabled).isTrue();
+ assertThat(candidates.get(1).summary).isNull();
+ assertThat(candidates.get(1).enabled).isTrue();
+ }
+
+ @Test
+ public void getCandidates_onlyLollipopPlusLaunchersAvailableIfManagedProfile()
+ throws NameNotFoundException {
+ createManagedProfile();
+ addLaunchers();
+ List<DefaultAppInfo> candidates = mPicker.getCandidates();
+ assertThat(candidates.size()).isEqualTo(2);
+ DefaultAppInfo lollipopPlusLauncher = candidates.get(0);
+ assertThat(lollipopPlusLauncher.summary).isNull();
+ assertThat(lollipopPlusLauncher.enabled).isTrue();
+
+ DefaultAppInfo preLollipopLauncher = candidates.get(1);
+ assertThat(preLollipopLauncher.summary).isNotNull();
+ assertThat(preLollipopLauncher.enabled).isFalse();
+ }
+
+ private void createManagedProfile() {
+ ArrayList<UserInfo> profiles = new ArrayList<UserInfo>();
+ profiles.add(new UserInfo(/*id=*/ 10, "TestUserName", UserInfo.FLAG_MANAGED_PROFILE));
+ when(mUserManager.getProfiles(anyInt())).thenReturn(profiles);
+ }
+
+ private ResolveInfo createLauncher(
+ String packageName, String className, int targetSdk) throws NameNotFoundException {
+ ResolveInfo launcher = new ResolveInfo();
+ launcher.activityInfo = new ActivityInfo();
+ launcher.activityInfo.packageName = packageName;
+ launcher.activityInfo.name = className;
+ ApplicationInfo launcherAppInfo = new ApplicationInfo();
+ launcherAppInfo.targetSdkVersion = targetSdk;
+ when(mPackageManager.getApplicationInfo(eq(launcher.activityInfo.packageName), anyInt()))
+ .thenReturn(launcherAppInfo);
+ return launcher;
+ }
+
+ private void addLaunchers() throws NameNotFoundException {
+ doAnswer(invocation -> {
+ // The result of this method is stored in the first parameter...
+ List<ResolveInfo> parameter = (List<ResolveInfo>) invocation.getArguments()[0];
+ parameter.add(createLauncher(
+ "package.1", "LollipopPlusLauncher", Build.VERSION_CODES.LOLLIPOP));
+ parameter.add(createLauncher(
+ "package.2", "PreLollipopLauncher", Build.VERSION_CODES.KITKAT));
+ return null;
+ })
+ .when(mPackageManagerWrapper).getHomeActivities(anyList());
+ }
}
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/StorageProfileFragmentTest.java b/tests/robotests/src/com/android/settings/deviceinfo/StorageProfileFragmentTest.java
index 8d48e63..03f15bb 100644
--- a/tests/robotests/src/com/android/settings/deviceinfo/StorageProfileFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/deviceinfo/StorageProfileFragmentTest.java
@@ -17,6 +17,7 @@
import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Matchers.anyInt;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
@@ -31,11 +32,16 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
+import org.mockito.Captor;
+import org.mockito.MockitoAnnotations;
import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class StorageProfileFragmentTest {
+ @Captor
+ private ArgumentCaptor<SparseArray<StorageAsyncLoader.AppsStorageResult>> mCaptor;
+
@Test
public void verifyAppSizesAreZeroedOut() {
StorageItemPreferenceController controller = mock(StorageItemPreferenceController.class);
@@ -45,18 +51,17 @@
result.otherAppsSize = 200;
result.gamesSize = 300;
result.videoAppsSize = 400;
- result.externalStats = new StorageStatsSource.ExternalStorageStats(6, 1, 2, 3);
+ result.externalStats = new StorageStatsSource.ExternalStorageStats(6, 1, 2, 3, 0);
SparseArray<StorageAsyncLoader.AppsStorageResult> resultsArray = new SparseArray<>();
resultsArray.put(0, result);
fragment.setPreferenceController(controller);
fragment.onLoadFinished(null, resultsArray);
- ArgumentCaptor<StorageAsyncLoader.AppsStorageResult> resultCaptor = ArgumentCaptor.forClass(
- StorageAsyncLoader.AppsStorageResult.class);
- verify(controller).onLoadFinished(resultCaptor.capture());
+ MockitoAnnotations.initMocks(this);
+ verify(controller).onLoadFinished(mCaptor.capture(), anyInt());
- StorageAsyncLoader.AppsStorageResult extractedResult = resultCaptor.getValue();
+ StorageAsyncLoader.AppsStorageResult extractedResult = mCaptor.getValue().get(0);
assertThat(extractedResult.musicAppsSize).isEqualTo(0);
assertThat(extractedResult.videoAppsSize).isEqualTo(0);
assertThat(extractedResult.otherAppsSize).isEqualTo(0);
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/storage/SecondaryUserControllerTest.java b/tests/robotests/src/com/android/settings/deviceinfo/storage/SecondaryUserControllerTest.java
index 32def69..dc1c286 100644
--- a/tests/robotests/src/com/android/settings/deviceinfo/storage/SecondaryUserControllerTest.java
+++ b/tests/robotests/src/com/android/settings/deviceinfo/storage/SecondaryUserControllerTest.java
@@ -168,7 +168,7 @@
MEGABYTE_IN_BYTES * 30,
MEGABYTE_IN_BYTES * 10,
MEGABYTE_IN_BYTES * 10,
- MEGABYTE_IN_BYTES * 10);
+ MEGABYTE_IN_BYTES * 10, 0);
result.put(10, userResult);
mController.handleResult(result);
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceControllerTest.java
index e8057a6..3ad3783 100644
--- a/tests/robotests/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceControllerTest.java
@@ -28,7 +28,6 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-
import android.app.Fragment;
import android.content.Context;
import android.content.Intent;
@@ -36,6 +35,7 @@
import android.os.UserHandle;
import android.os.storage.VolumeInfo;
import android.support.v7.preference.PreferenceScreen;
+import android.util.SparseArray;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
@@ -275,22 +275,22 @@
result.videoAppsSize = MEGABYTE_IN_BYTES * 160;
result.musicAppsSize = MEGABYTE_IN_BYTES * 40;
result.otherAppsSize = MEGABYTE_IN_BYTES * 90;
- result.systemSize = MEGABYTE_IN_BYTES * 100; // This value is ignored and overridden now.
result.externalStats =
new StorageStatsSource.ExternalStorageStats(
MEGABYTE_IN_BYTES * 500, // total
MEGABYTE_IN_BYTES * 100, // audio
MEGABYTE_IN_BYTES * 150, // video
- MEGABYTE_IN_BYTES * 200); // image
+ MEGABYTE_IN_BYTES * 200, 0); // image
- mController.onLoadFinished(result);
+ SparseArray<StorageAsyncLoader.AppsStorageResult> results = new SparseArray<>();
+ results.put(0, result);
+ mController.onLoadFinished(results, 0);
assertThat(audio.getSummary().toString()).isEqualTo("0.14GB");
assertThat(image.getSummary().toString()).isEqualTo("0.35GB");
assertThat(games.getSummary().toString()).isEqualTo("0.08GB");
assertThat(movies.getSummary().toString()).isEqualTo("0.16GB");
assertThat(apps.getSummary().toString()).isEqualTo("0.09GB");
- assertThat(system.getSummary().toString()).isEqualTo("0.10GB");
assertThat(files.getSummary().toString()).isEqualTo("0.05GB");
}
@@ -488,4 +488,4 @@
verify(screen).addPreference(files);
}
-}
\ No newline at end of file
+}
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/storage/UserProfileControllerTest.java b/tests/robotests/src/com/android/settings/deviceinfo/storage/UserProfileControllerTest.java
index 8b7110d..2199824 100644
--- a/tests/robotests/src/com/android/settings/deviceinfo/storage/UserProfileControllerTest.java
+++ b/tests/robotests/src/com/android/settings/deviceinfo/storage/UserProfileControllerTest.java
@@ -114,7 +114,7 @@
99 * MEGABYTE_IN_BYTES,
33 * MEGABYTE_IN_BYTES,
33 * MEGABYTE_IN_BYTES,
- 33 * MEGABYTE_IN_BYTES);
+ 33 * MEGABYTE_IN_BYTES, 0);
result.put(10, userResult);
mController.handleResult(result);
@@ -141,4 +141,4 @@
Preference preference = argumentCaptor.getValue();
assertThat(preference.getIcon()).isEqualTo(drawable);
}
-}
\ No newline at end of file
+}
diff --git a/tests/robotests/src/com/android/settings/wifi/details/WifiDetailPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/wifi/details/WifiDetailPreferenceControllerTest.java
index 208c157..0298195 100644
--- a/tests/robotests/src/com/android/settings/wifi/details/WifiDetailPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/details/WifiDetailPreferenceControllerTest.java
@@ -195,9 +195,9 @@
.thenReturn(mockConnectionDetailPref);
when(mockScreen.findPreference(WifiDetailPreferenceController.KEY_BUTTONS_PREF))
.thenReturn(mockButtonsPref);
- when(mockButtonsPref.findViewById(R.id.left_button))
+ when(mockButtonsPref.findViewById(R.id.forget_button))
.thenReturn(mockForgetButton);
- when(mockButtonsPref.findViewById(R.id.right_button))
+ when(mockButtonsPref.findViewById(R.id.signin_button))
.thenReturn(mockSignInButton);
when(mockScreen.findPreference(WifiDetailPreferenceController.KEY_SIGNAL_STRENGTH_PREF))
.thenReturn(mockSignalStrengthPref);
diff --git a/tests/unit/src/com/android/settings/deviceinfo/storage/StorageAsyncLoaderTest.java b/tests/unit/src/com/android/settings/deviceinfo/storage/StorageAsyncLoaderTest.java
index 546ea4b..79a4595 100644
--- a/tests/unit/src/com/android/settings/deviceinfo/storage/StorageAsyncLoaderTest.java
+++ b/tests/unit/src/com/android/settings/deviceinfo/storage/StorageAsyncLoaderTest.java
@@ -133,9 +133,9 @@
info.id = SECONDARY_USER_ID;
mUsers.add(info);
when(mSource.getExternalStorageStats(anyString(), eq(UserHandle.SYSTEM)))
- .thenReturn(new StorageStatsSource.ExternalStorageStats(9, 2, 3, 4));
+ .thenReturn(new StorageStatsSource.ExternalStorageStats(9, 2, 3, 4, 0));
when(mSource.getExternalStorageStats(anyString(), eq(new UserHandle(SECONDARY_USER_ID))))
- .thenReturn(new StorageStatsSource.ExternalStorageStats(10, 3, 3, 4));
+ .thenReturn(new StorageStatsSource.ExternalStorageStats(10, 3, 3, 4, 0));
SparseArray<StorageAsyncLoader.AppsStorageResult> result = mLoader.loadInBackground();
@@ -145,19 +145,6 @@
}
@Test
- public void testSystemAppsBaseSizeIsAddedToSystem() throws Exception {
- ApplicationInfo systemApp =
- addPackage(PACKAGE_NAME_1, 100, 1, 10, ApplicationInfo.CATEGORY_UNDEFINED);
- systemApp.flags = ApplicationInfo.FLAG_SYSTEM;
-
- SparseArray<StorageAsyncLoader.AppsStorageResult> result = mLoader.loadInBackground();
-
- assertThat(result.size()).isEqualTo(1);
- assertThat(result.get(PRIMARY_USER_ID).otherAppsSize).isEqualTo(10L);
- assertThat(result.get(PRIMARY_USER_ID).systemSize).isEqualTo(1L);
- }
-
- @Test
public void testUpdatedSystemAppCodeSizeIsCounted() throws Exception {
ApplicationInfo systemApp =
addPackage(PACKAGE_NAME_1, 100, 1, 10, ApplicationInfo.CATEGORY_UNDEFINED);