Merge "Add work profile badge for icon of free up space" into tm-dev
diff --git a/res/drawable/ic_files_go_round.xml b/res/drawable/ic_files_go_round.xml
deleted file mode 100644
index 2025b00..0000000
--- a/res/drawable/ic_files_go_round.xml
+++ /dev/null
@@ -1,121 +0,0 @@
-<!--
- Copyright (C) 2021 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.
--->
-<vector
- xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:aapt="http://schemas.android.com/aapt"
- android:width="32dp"
- android:height="32dp"
- android:viewportWidth="192"
- android:viewportHeight="192">
- <path
- android:pathData="M96,96m-88,0a88,88 0,1 1,176 0a88,88 0,1 1,-176 0"
- android:fillColor="#FFFFFF"/>
- <path
- android:pathData="M96,183c-48.43,0 -87.72,-39.13 -87.99,-87.5C8.01,95.67 8,95.83 8,96c0,48.6 39.4,88 88,88s88,-39.4 88,-88c0,-0.17 -0.01,-0.33 -0.01,-0.5C183.72,143.87 144.43,183 96,183z"
- android:fillColor="#263238"
- android:fillAlpha="0.2"/>
- <path
- android:pathData="M96,9c48.43,0 87.72,39.13 87.99,87.5c0,-0.17 0.01,-0.33 0.01,-0.5c0,-48.6 -39.4,-88 -88,-88S8,47.4 8,96c0,0.17 0.01,0.33 0.01,0.5C8.28,48.13 47.57,9 96,9z"
- android:fillColor="#FFFFFF"
- android:fillAlpha="0.2"/>
- <path
- android:pathData="M85.09,59.18H44.18c-4.52,0 -8.18,3.66 -8.18,8.18v40.91v2.05v-0.35c0,-1.08 0.43,-2.13 1.2,-2.89L85.09,59.18z"
- android:fillColor="#0F9D58"/>
- <path
- android:pathData="M85.09,59.18H44.18c-4.52,0 -8.18,3.66 -8.18,8.18v40.91v2.05v-0.35c0,-1.08 0.43,-2.13 1.2,-2.89L85.09,59.18z">
- <aapt:attr name="android:fillColor">
- <gradient
- android:startY="110.3181"
- android:startX="60.5458"
- android:endY="59.182"
- android:endX="60.5458"
- android:type="linear">
- <item android:offset="0" android:color="#33263238"/>
- <item android:offset="1" android:color="#00263238"/>
- </gradient>
- </aapt:attr>
- </path>
- <path
- android:pathData="M37.2,106.39c-0.77,0.77 -1.2,1.81 -1.2,2.89v0.35v0.33c0,-1.08 0.43,-2.13 1.2,-2.89l47.89,-47.89h-0.68L37.2,106.39z"
- android:fillColor="#263238"
- android:fillAlpha="0.2"/>
- <path
- android:pathData="M44.18,59.86h39.55l0.68,-0.68H44.18c-4.52,0 -8.18,3.66 -8.18,8.18v0.68C36,63.53 39.66,59.86 44.18,59.86z"
- android:fillColor="#FFFFFF"
- android:fillAlpha="0.2"/>
- <path
- android:pathData="M147.82,143.73H44.18c-4.52,0 -8.18,-3.66 -8.18,-8.18v-25.58c0,-1.08 0.43,-2.13 1.2,-2.89l57.6,-57.6c0.77,-0.77 1.81,-1.2 2.89,-1.2h50.12c4.52,0 8.18,3.66 8.18,8.18v79.09C156,140.06 152.34,143.73 147.82,143.73z"
- android:fillColor="#4285F4"/>
- <path
- android:pathData="M156,135.55l0,-29.32L98.05,48.27l-0.31,0c-1.11,0 -2.17,0.45 -2.94,1.25L37.2,107.07c-0.77,0.77 -1.2,1.81 -1.2,2.89v0.35l33.41,33.41l78.41,0C152.34,143.73 156,140.06 156,135.55z">
- <aapt:attr name="android:fillColor">
- <gradient
- android:startY="78.2732"
- android:startX="66.0008"
- android:endY="153.6034"
- android:endX="141.331"
- android:type="linear">
- <item android:offset="0" android:color="#281A237E"/>
- <item android:offset="1" android:color="#051A237E"/>
- </gradient>
- </aapt:attr>
- </path>
- <path
- android:pathData="M147.82,143.05H44.18c-4.52,0 -8.18,-3.66 -8.18,-8.18v0.68c0,4.52 3.66,8.18 8.18,8.18h103.64c4.52,0 8.18,-3.66 8.18,-8.18v-0.68C156,139.38 152.34,143.05 147.82,143.05z"
- android:fillColor="#1A237E"
- android:fillAlpha="0.2"/>
- <path
- android:pathData="M147.82,48.27H98.05c-0.6,0 -1.14,0.27 -1.51,0.68h51.29c4.52,0 8.18,3.66 8.18,8.18v-0.68C156,51.94 152.34,48.27 147.82,48.27z"
- android:fillColor="#FFFFFF"
- android:fillAlpha="0.2"/>
- <path
- android:pathData="M94.8,49.47l-57.6,57.6c-0.77,0.77 -1.2,1.81 -1.2,2.89v0.35v0c0,-1.13 0.92,-2.05 2.05,-2.05h49.77c4.52,0 8.18,-3.66 8.18,-8.18l0,-49.77c0,-1.13 0.92,-2.05 2.05,-2.05l0,0l-0.35,0C96.61,48.27 95.57,48.7 94.8,49.47z"
- android:fillColor="#DB4437"/>
- <path
- android:pathData="M97.69,48.27c-0.27,0 -0.54,0.03 -0.8,0.08C97.15,48.3 97.42,48.27 97.69,48.27l0.35,0c-1.34,0 -2.55,0.72 -3.21,1.85c0.43,-0.42 0.95,-0.73 1.5,-0.93c0.37,-0.55 0.99,-0.92 1.7,-0.92L97.69,48.27z"
- android:strokeAlpha="0.2"
- android:fillColor="#3E2723"
- android:fillAlpha="0.2"/>
- <path
- android:pathData="M96,99.41c0,4.52 -3.66,8.18 -8.18,8.18H38.05c-0.85,0 -1.57,0.51 -1.88,1.25c-0.1,0.36 -0.16,0.74 -0.16,1.13v0.35c0,-1.13 0.92,-2.05 2.05,-2.05h49.77c4.52,0 8.18,-3.66 8.18,-8.18"
- android:fillColor="#3E2723"
- android:fillAlpha="0.2"/>
- <path
- android:pathData="M36,110.32L36,110.32c0,-1.62 1.05,-3.06 2.6,-3.55L74.95,95.2c3.79,-1.21 6.77,-4.18 7.97,-7.97l11.57,-36.35c0.49,-1.55 1.93,-2.6 3.55,-2.6l0,0h-0.35c-1.08,0 -2.13,0.43 -2.89,1.2l-57.6,57.6c-0.77,0.77 -1.2,1.81 -1.2,2.89L36,110.32z"
- android:fillColor="#F4B400"/>
- <path
- android:pathData="M94.84,49.44c-0.14,0.24 -0.26,0.48 -0.35,0.75L82.92,86.54c-1.21,3.79 -4.18,6.77 -7.97,7.97L38.6,106.08c-0.27,0.09 -0.52,0.21 -0.76,0.35l-0.64,0.64c-0.77,0.77 -1.2,1.81 -1.2,2.89l0,0.35c0,-1.62 1.05,-3.06 2.6,-3.55L74.95,95.2c3.79,-1.21 6.77,-4.18 7.97,-7.97l11.57,-36.35c0.49,-1.55 1.93,-2.6 3.55,-2.6h-0.35C96.63,48.27 95.6,48.69 94.84,49.44z"
- android:fillColor="#BF360C"
- android:fillAlpha="0.3"/>
- <path
- android:pathData="M39,105.95l55.36,-55.36l0.13,-0.4c0.09,-0.27 0.21,-0.52 0.35,-0.75c-0.01,0.01 -0.03,0.02 -0.04,0.03l-56.96,56.96c0.24,-0.14 0.49,-0.27 0.76,-0.35L39,105.95z"
- android:strokeAlpha="0.2"
- android:fillColor="#FFFFFF"
- android:fillAlpha="0.2"/>
- <path
- android:pathData="M36,109.97v25.58c0,4.52 3.66,8.18 8.18,8.18h103.64c4.52,0 8.18,-3.66 8.18,-8.18V56.45c0,-4.52 -3.66,-8.18 -8.18,-8.18H97.69c-1.08,0 -2.13,0.43 -2.89,1.2l-9.71,9.71H44.18c-4.52,0 -8.18,3.66 -8.18,8.18v40.91L36,109.97">
- <aapt:attr name="android:fillColor">
- <gradient
- android:gradientRadius="115.3882"
- android:centerX="72.364"
- android:centerY="59.4093"
- android:type="radial">
- <item android:offset="0.0029046" android:color="#19FFFFFF"/>
- <item android:offset="1" android:color="#00FFFFFF"/>
- </gradient>
- </aapt:attr>
- </path>
-</vector>
diff --git a/res/layout/card_preference.xml b/res/layout/card_preference.xml
new file mode 100644
index 0000000..be49ca3
--- /dev/null
+++ b/res/layout/card_preference.xml
@@ -0,0 +1,74 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2022 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.
+ -->
+
+<LinearLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:minHeight="?android:attr/listPreferredItemHeightSmall"
+ android:gravity="center_vertical"
+ android:paddingStart="20dp"
+ android:paddingEnd="8dp"
+ android:background="?android:attr/selectableItemBackground"
+ android:clipToPadding="false"
+ android:baselineAligned="false">
+
+ <include layout="@layout/card_preference_icon_frame"/>
+
+ <RelativeLayout
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:layout_weight="1"
+ android:paddingTop="16dp"
+ android:paddingBottom="16dp">
+
+ <TextView
+ android:id="@android:id/title"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:maxLines="2"
+ android:textAppearance="?android:attr/textAppearanceListItem"
+ android:ellipsize="marquee"/>
+
+ <TextView
+ android:id="@android:id/summary"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_below="@android:id/title"
+ android:layout_alignLeft="@android:id/title"
+ android:layout_alignStart="@android:id/title"
+ android:layout_gravity="start"
+ android:textAlignment="viewStart"
+ android:textColor="?android:attr/textColorSecondary"
+ android:maxLines="10"
+ style="@style/PreferenceSummaryTextStyle"/>
+
+ </RelativeLayout>
+
+ <!-- Preference should place its actual preference widget here. -->
+ <LinearLayout
+ android:id="@android:id/widget_frame"
+ android:layout_width="wrap_content"
+ android:layout_height="match_parent"
+ android:gravity="end|center_vertical"
+ android:paddingLeft="16dp"
+ android:paddingStart="16dp"
+ android:paddingRight="0dp"
+ android:paddingEnd="0dp"
+ android:orientation="vertical"/>
+
+</LinearLayout>
\ No newline at end of file
diff --git a/res/layout/card_preference_icon_frame.xml b/res/layout/card_preference_icon_frame.xml
new file mode 100644
index 0000000..c8003ef
--- /dev/null
+++ b/res/layout/card_preference_icon_frame.xml
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2022 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.
+ -->
+<LinearLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:app="http://schemas.android.com/apk/res-auto"
+ android:id="@+id/icon_frame"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:minWidth="32dp"
+ android:gravity="start|center_vertical"
+ android:orientation="horizontal"
+ android:paddingStart="0dp"
+ android:paddingEnd="20dp"
+ android:paddingTop="4dp"
+ android:paddingBottom="4dp">
+
+ <androidx.preference.internal.PreferenceImageView
+ android:id="@android:id/icon"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ app:maxWidth="32dp"
+ app:maxHeight="32dp"/>
+
+</LinearLayout>
\ No newline at end of file
diff --git a/res/layout/card_preference_layout.xml b/res/layout/card_preference_layout.xml
index 5ac4afc..8373637 100644
--- a/res/layout/card_preference_layout.xml
+++ b/res/layout/card_preference_layout.xml
@@ -29,5 +29,5 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="-8dp"
- layout="@layout/settingslib_preference"/>
+ layout="@layout/card_preference"/>
</com.google.android.material.card.MaterialCardView>
diff --git a/res/xml/storage_category_fragment.xml b/res/xml/storage_category_fragment.xml
index 08f3f27..9731836 100644
--- a/res/xml/storage_category_fragment.xml
+++ b/res/xml/storage_category_fragment.xml
@@ -24,7 +24,7 @@
android:order="4"
android:title="@string/storage_free_up_space_title"
android:summary="@string/storage_free_up_space_summary"
- android:icon="@drawable/ic_files_go_round"/>
+ settings:controller="com.android.settings.deviceinfo.storage.ManageStoragePreferenceController"/>
<!-- Preference order 100~200 are 'ONLY' for storage category preferences below. -->
<Preference
android:key="pref_public_storage"
diff --git a/res/xml/storage_dashboard_fragment.xml b/res/xml/storage_dashboard_fragment.xml
index 9c0f1d1..e234cad 100644
--- a/res/xml/storage_dashboard_fragment.xml
+++ b/res/xml/storage_dashboard_fragment.xml
@@ -43,7 +43,7 @@
android:order="4"
android:title="@string/storage_free_up_space_title"
android:summary="@string/storage_free_up_space_summary"
- android:icon="@drawable/ic_files_go_round"/>
+ settings:controller="com.android.settings.deviceinfo.storage.ManageStoragePreferenceController"/>
<!-- Preference order 100~200 are 'ONLY' for storage category preferences below. -->
<Preference
android:key="pref_public_storage"
diff --git a/src/com/android/settings/deviceinfo/StorageCategoryFragment.java b/src/com/android/settings/deviceinfo/StorageCategoryFragment.java
index efdd165..e024972 100644
--- a/src/com/android/settings/deviceinfo/StorageCategoryFragment.java
+++ b/src/com/android/settings/deviceinfo/StorageCategoryFragment.java
@@ -19,10 +19,8 @@
import android.app.settings.SettingsEnums;
import android.app.usage.StorageStatsManager;
import android.content.Context;
-import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
-import android.os.UserHandle;
import android.os.UserManager;
import android.os.storage.StorageManager;
import android.util.SparseArray;
@@ -31,12 +29,12 @@
import androidx.annotation.VisibleForTesting;
import androidx.loader.app.LoaderManager;
import androidx.loader.content.Loader;
-import androidx.preference.Preference;
import com.android.settings.R;
import com.android.settings.Utils;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.dashboard.profileselector.ProfileSelectFragment;
+import com.android.settings.deviceinfo.storage.ManageStoragePreferenceController;
import com.android.settings.deviceinfo.storage.SecondaryUserController;
import com.android.settings.deviceinfo.storage.StorageAsyncLoader;
import com.android.settings.deviceinfo.storage.StorageCacheHelper;
@@ -44,10 +42,8 @@
import com.android.settings.deviceinfo.storage.StorageItemPreferenceController;
import com.android.settings.deviceinfo.storage.UserIconLoader;
import com.android.settings.deviceinfo.storage.VolumeSizesLoader;
-import com.android.settings.overlay.FeatureFactory;
import com.android.settingslib.applications.StorageStatsSource;
import com.android.settingslib.core.AbstractPreferenceController;
-import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
import com.android.settingslib.deviceinfo.PrivateStorageInfo;
import com.android.settingslib.deviceinfo.StorageManagerVolumeProvider;
@@ -70,12 +66,10 @@
*/
public class StorageCategoryFragment extends DashboardFragment
implements
- LoaderManager.LoaderCallbacks<SparseArray<StorageAsyncLoader.StorageResult>>,
- Preference.OnPreferenceClickListener {
+ LoaderManager.LoaderCallbacks<SparseArray<StorageAsyncLoader.StorageResult>> {
private static final String TAG = "StorageCategoryFrag";
private static final String SELECTED_STORAGE_ENTRY_KEY = "selected_storage_entry_key";
private static final String SUMMARY_PREF_KEY = "storage_summary";
- private static final String FREE_UP_SPACE_PREF_KEY = "free_up_space";
private static final int STORAGE_JOB_ID = 0;
private static final int ICON_JOB_ID = 1;
private static final int VOLUME_SIZE_JOB_ID = 2;
@@ -90,7 +84,6 @@
private List<AbstractPreferenceController> mSecondaryUsers;
private boolean mIsWorkProfile;
private int mUserId;
- private Preference mFreeUpSpacePreference;
private boolean mIsLoadedFromCache;
private StorageCacheHelper mStorageCacheHelper;
@@ -152,8 +145,6 @@
mSelectedStorageEntry = icicle.getParcelable(SELECTED_STORAGE_ENTRY_KEY);
}
- initializePreference();
-
if (mStorageCacheHelper.hasCachedSizeInfo()) {
mIsLoadedFromCache = true;
if (mSelectedStorageEntry != null) {
@@ -164,11 +155,6 @@
}
}
- private void initializePreference() {
- mFreeUpSpacePreference = getPreferenceScreen().findPreference(FREE_UP_SPACE_PREF_KEY);
- mFreeUpSpacePreference.setOnPreferenceClickListener(this);
- }
-
@Override
public void onAttach(Context context) {
// These member variables are initialized befoer super.onAttach for
@@ -180,6 +166,10 @@
mStorageCacheHelper = new StorageCacheHelper(getContext(), mUserId);
super.onAttach(context);
+
+ ManageStoragePreferenceController manageStoragePreferenceController =
+ use(ManageStoragePreferenceController.class);
+ manageStoragePreferenceController.setUserId(mUserId);
}
@Override
@@ -305,22 +295,6 @@
public void onLoaderReset(Loader<SparseArray<StorageAsyncLoader.StorageResult>> loader) {
}
- @Override
- public boolean onPreferenceClick(Preference preference) {
- if (preference == mFreeUpSpacePreference) {
- final Context context = getContext();
- final MetricsFeatureProvider metricsFeatureProvider =
- FeatureFactory.getFactory(context).getMetricsFeatureProvider();
- metricsFeatureProvider.logClickedPreference(preference, getMetricsCategory());
- metricsFeatureProvider.action(context, SettingsEnums.STORAGE_FREE_UP_SPACE_NOW);
- final Intent intent = new Intent(StorageManager.ACTION_MANAGE_STORAGE);
- intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- context.startActivityAsUser(intent, new UserHandle(mUserId));
- return true;
- }
- return false;
- }
-
@VisibleForTesting
public PrivateStorageInfo getPrivateStorageInfo() {
return mStorageInfo;
diff --git a/src/com/android/settings/deviceinfo/StorageDashboardFragment.java b/src/com/android/settings/deviceinfo/StorageDashboardFragment.java
index cf31724..07ac4e5 100644
--- a/src/com/android/settings/deviceinfo/StorageDashboardFragment.java
+++ b/src/com/android/settings/deviceinfo/StorageDashboardFragment.java
@@ -20,7 +20,6 @@
import android.app.settings.SettingsEnums;
import android.app.usage.StorageStatsManager;
import android.content.Context;
-import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.UserHandle;
@@ -38,13 +37,13 @@
import androidx.annotation.VisibleForTesting;
import androidx.loader.app.LoaderManager;
import androidx.loader.content.Loader;
-import androidx.preference.Preference;
import com.android.settings.R;
import com.android.settings.Utils;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.deviceinfo.storage.AutomaticStorageManagementSwitchPreferenceController;
import com.android.settings.deviceinfo.storage.DiskInitFragment;
+import com.android.settings.deviceinfo.storage.ManageStoragePreferenceController;
import com.android.settings.deviceinfo.storage.SecondaryUserController;
import com.android.settings.deviceinfo.storage.StorageAsyncLoader;
import com.android.settings.deviceinfo.storage.StorageCacheHelper;
@@ -55,11 +54,9 @@
import com.android.settings.deviceinfo.storage.StorageUtils;
import com.android.settings.deviceinfo.storage.UserIconLoader;
import com.android.settings.deviceinfo.storage.VolumeSizesLoader;
-import com.android.settings.overlay.FeatureFactory;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settingslib.applications.StorageStatsSource;
import com.android.settingslib.core.AbstractPreferenceController;
-import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
import com.android.settingslib.deviceinfo.PrivateStorageInfo;
import com.android.settingslib.deviceinfo.StorageManagerVolumeProvider;
import com.android.settingslib.search.SearchIndexable;
@@ -85,11 +82,9 @@
@SearchIndexable
public class StorageDashboardFragment extends DashboardFragment
implements
- LoaderManager.LoaderCallbacks<SparseArray<StorageAsyncLoader.StorageResult>>,
- Preference.OnPreferenceClickListener {
+ LoaderManager.LoaderCallbacks<SparseArray<StorageAsyncLoader.StorageResult>> {
private static final String TAG = "StorageDashboardFrag";
private static final String SUMMARY_PREF_KEY = "storage_summary";
- private static final String FREE_UP_SPACE_PREF_KEY = "free_up_space";
private static final String SELECTED_STORAGE_ENTRY_KEY = "selected_storage_entry_key";
private static final int STORAGE_JOB_ID = 0;
private static final int ICON_JOB_ID = 1;
@@ -109,7 +104,6 @@
private List<AbstractPreferenceController> mSecondaryUsers;
private boolean mIsWorkProfile;
private int mUserId;
- private Preference mFreeUpSpacePreference;
private boolean mIsLoadedFromCache;
private StorageCacheHelper mStorageCacheHelper;
@@ -290,7 +284,6 @@
mSelectedStorageEntry = icicle.getParcelable(SELECTED_STORAGE_ENTRY_KEY);
}
- initializePreference();
initializeOptionsMenu(activity);
if (mStorageCacheHelper.hasCachedSizeInfo()) {
@@ -304,11 +297,6 @@
}
}
- private void initializePreference() {
- mFreeUpSpacePreference = getPreferenceScreen().findPreference(FREE_UP_SPACE_PREF_KEY);
- mFreeUpSpacePreference.setOnPreferenceClickListener(this);
- }
-
@Override
public void onAttach(Context context) {
// These member variables are initialized befoer super.onAttach for
@@ -334,6 +322,10 @@
}
});
mStorageUsageProgressBarController = use(StorageUsageProgressBarPreferenceController.class);
+
+ ManageStoragePreferenceController manageStoragePreferenceController =
+ use(ManageStoragePreferenceController.class);
+ manageStoragePreferenceController.setUserId(mUserId);
}
@VisibleForTesting
@@ -505,22 +497,6 @@
public void onLoaderReset(Loader<SparseArray<StorageAsyncLoader.StorageResult>> loader) {
}
- @Override
- public boolean onPreferenceClick(Preference preference) {
- if (preference == mFreeUpSpacePreference) {
- final Context context = getContext();
- final MetricsFeatureProvider metricsFeatureProvider =
- FeatureFactory.getFactory(context).getMetricsFeatureProvider();
- metricsFeatureProvider.logClickedPreference(preference, getMetricsCategory());
- metricsFeatureProvider.action(context, SettingsEnums.STORAGE_FREE_UP_SPACE_NOW);
- final Intent intent = new Intent(StorageManager.ACTION_MANAGE_STORAGE);
- intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- context.startActivityAsUser(intent, new UserHandle(mUserId));
- return true;
- }
- return false;
- }
-
@VisibleForTesting
public PrivateStorageInfo getPrivateStorageInfo() {
return mStorageInfo;
diff --git a/src/com/android/settings/deviceinfo/storage/ManageStoragePreferenceController.java b/src/com/android/settings/deviceinfo/storage/ManageStoragePreferenceController.java
new file mode 100644
index 0000000..1a60cb8
--- /dev/null
+++ b/src/com/android/settings/deviceinfo/storage/ManageStoragePreferenceController.java
@@ -0,0 +1,77 @@
+/*
+ * Copyright (C) 2022 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.deviceinfo.storage;
+
+import android.app.settings.SettingsEnums;
+import android.content.Context;
+import android.content.Intent;
+import android.graphics.drawable.Drawable;
+import android.os.UserHandle;
+import android.os.storage.StorageManager;
+
+import androidx.preference.Preference;
+import androidx.preference.PreferenceScreen;
+
+import com.android.settings.core.BasePreferenceController;
+import com.android.settings.overlay.FeatureFactory;
+import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
+
+/**
+ * Preference controller to control the storage management preference.
+ */
+public class ManageStoragePreferenceController extends BasePreferenceController {
+
+ private int mUserId;
+ private Drawable mManageStorageDrawable;
+
+ public ManageStoragePreferenceController(Context context, String preferenceKey) {
+ super(context, preferenceKey);
+ }
+
+ /**
+ * Set user ID.
+ */
+ public void setUserId(int userId) {
+ mUserId = userId;
+ mManageStorageDrawable = StorageUtils.getManageStorageIcon(mContext, userId);
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ return mManageStorageDrawable == null ? CONDITIONALLY_UNAVAILABLE : AVAILABLE;
+ }
+
+ @Override
+ public void displayPreference(PreferenceScreen screen) {
+ super.displayPreference(screen);
+
+ Preference preference = screen.findPreference(getPreferenceKey());
+ preference.setIcon(mManageStorageDrawable);
+ }
+
+ @Override
+ public boolean handlePreferenceTreeClick(Preference preference) {
+ final MetricsFeatureProvider metricsFeatureProvider =
+ FeatureFactory.getFactory(mContext).getMetricsFeatureProvider();
+ metricsFeatureProvider.action(mContext, SettingsEnums.STORAGE_FREE_UP_SPACE_NOW);
+
+ final Intent intent = new Intent(StorageManager.ACTION_MANAGE_STORAGE);
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ mContext.startActivityAsUser(intent, new UserHandle(mUserId));
+ return true;
+ }
+}
diff --git a/src/com/android/settings/deviceinfo/storage/StorageUtils.java b/src/com/android/settings/deviceinfo/storage/StorageUtils.java
index 0820712..4b6a2c4 100644
--- a/src/com/android/settings/deviceinfo/storage/StorageUtils.java
+++ b/src/com/android/settings/deviceinfo/storage/StorageUtils.java
@@ -19,6 +19,9 @@
import android.app.Dialog;
import android.app.settings.SettingsEnums;
import android.content.Context;
+import android.content.Intent;
+import android.content.pm.ResolveInfo;
+import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
@@ -35,6 +38,7 @@
import androidx.fragment.app.Fragment;
import com.android.settings.R;
+import com.android.settings.Utils;
import com.android.settings.core.SubSettingLauncher;
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
import com.android.settings.deviceinfo.PrivateVolumeForget;
@@ -231,4 +235,15 @@
bytes, Formatter.FLAG_SHORTER);
return context.getString(resId, result.value, result.units);
}
+
+ /** Gets icon for Preference of Free up space. */
+ public static Drawable getManageStorageIcon(Context context, int userId) {
+ ResolveInfo resolveInfo = context.getPackageManager().resolveActivityAsUser(
+ new Intent(StorageManager.ACTION_MANAGE_STORAGE), 0 /* flags */, userId);
+ if (resolveInfo == null || resolveInfo.activityInfo == null) {
+ return null;
+ }
+
+ return Utils.getBadgedIcon(context, resolveInfo.activityInfo.applicationInfo);
+ }
}