summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniel Nishi <dhnishi@google.com>2017-06-26 16:58:12 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2017-06-26 16:58:13 +0000
commit234e3ae5b3c8726a4d22c0265cbd7cb3fc2eda21 (patch)
treef8f8a632b7a83645ff830d3e6a012eb3b2cd6a06 /src
parentb28be1da5ae45370f9b6e3282f7e12bdc3ba3133 (diff)
parent3bb1e61cb9db7d8773d2c75d7059b75337d62ca3 (diff)
downloadStorageManager-234e3ae5b3c8726a4d22c0265cbd7cb3fc2eda21.tar.gz
Merge "Add an informational bar when apps ask for an amount of space." into oc-dr1-dev
Diffstat (limited to 'src')
-rw-r--r--src/com/android/storagemanager/deletionhelper/DeletionHelperSettings.java44
-rw-r--r--src/com/android/storagemanager/deletionhelper/GaugePreference.java34
2 files changed, 78 insertions, 0 deletions
diff --git a/src/com/android/storagemanager/deletionhelper/DeletionHelperSettings.java b/src/com/android/storagemanager/deletionhelper/DeletionHelperSettings.java
index 5347edf..2984df4 100644
--- a/src/com/android/storagemanager/deletionhelper/DeletionHelperSettings.java
+++ b/src/com/android/storagemanager/deletionhelper/DeletionHelperSettings.java
@@ -18,9 +18,13 @@ package com.android.storagemanager.deletionhelper;
import android.Manifest;
import android.app.Activity;
+import android.content.Context;
+import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;
+import android.os.storage.StorageManager;
import android.support.v14.preference.PreferenceFragment;
+import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;
import android.text.format.Formatter;
import android.view.Menu;
@@ -29,7 +33,9 @@ import android.view.View;
import android.widget.Button;
import com.android.internal.logging.MetricsLogger;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
+import com.android.internal.util.Preconditions;
import com.android.settingslib.HelpUtils;
+import com.android.settingslib.applications.AppUtils;
import com.android.storagemanager.ButtonBarProvider;
import com.android.storagemanager.R;
import com.android.storagemanager.overlay.DeletionHelperFeatureProvider;
@@ -49,10 +55,12 @@ public class DeletionHelperSettings extends PreferenceFragment
protected static final String APPS_KEY = "apps_group";
protected static final String KEY_DOWNLOADS_PREFERENCE = "delete_downloads";
protected static final String KEY_PHOTOS_VIDEOS_PREFERENCE = "delete_photos";
+ protected static final String KEY_GAUGE_PREFERENCE = "deletion_gauge";
private static final String THRESHOLD_KEY = "threshold_key";
private static final int DOWNLOADS_LOADER_ID = 1;
private static final int NUM_DELETION_TYPES = 3;
+ private static final long UNSET = -1;
private List<DeletionType> mDeletableContentList;
private AppDeletionPreferenceGroup mApps;
@@ -60,6 +68,7 @@ public class DeletionHelperSettings extends PreferenceFragment
private DownloadsDeletionPreferenceGroup mDownloadsPreference;
private DownloadsDeletionType mDownloadsDeletion;
private PhotosDeletionPreference mPhotoPreference;
+ private Preference mGaugePreference;
private DeletionType mPhotoVideoDeletion;
private Button mCancel, mFree;
private DeletionHelperFeatureProvider mProvider;
@@ -97,6 +106,41 @@ public class DeletionHelperSettings extends PreferenceFragment
mApps.setDeletionType(mAppBackend);
mDeletableContentList = new ArrayList<>(NUM_DELETION_TYPES);
+
+ mGaugePreference = findPreference(KEY_GAUGE_PREFERENCE);
+ Activity activity = getActivity();
+ if (activity != null && mGaugePreference != null) {
+ Intent intent = activity.getIntent();
+ if (intent != null) {
+ CharSequence gaugeTitle =
+ getGaugeString(getContext(), intent, activity.getCallingPackage());
+ if (gaugeTitle != null) {
+ mGaugePreference.setTitle(gaugeTitle);
+ } else {
+ getPreferenceScreen().removePreference(mGaugePreference);
+ }
+ }
+ }
+ }
+
+ protected static CharSequence getGaugeString(
+ Context context, Intent intent, String packageName) {
+ Preconditions.checkNotNull(intent);
+ long requestedBytes = intent.getLongExtra(StorageManager.EXTRA_REQUESTED_BYTES, UNSET);
+ if (requestedBytes > 0) {
+ CharSequence callerLabel =
+ AppUtils.getApplicationLabel(context.getPackageManager(), packageName);
+ // I really hope this isn't the case, but I can't ignore the possibility that we cannot
+ // determine what app the referrer is.
+ if (callerLabel == null) {
+ return null;
+ }
+ return context.getString(
+ R.string.app_requesting_space,
+ callerLabel,
+ Formatter.formatFileSize(context, requestedBytes));
+ }
+ return null;
}
@Override
diff --git a/src/com/android/storagemanager/deletionhelper/GaugePreference.java b/src/com/android/storagemanager/deletionhelper/GaugePreference.java
new file mode 100644
index 0000000..3ffdbac
--- /dev/null
+++ b/src/com/android/storagemanager/deletionhelper/GaugePreference.java
@@ -0,0 +1,34 @@
+/*
+ * 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.storagemanager.deletionhelper;
+
+import android.content.Context;
+import android.support.v7.preference.Preference;
+import android.util.AttributeSet;
+
+import com.android.storagemanager.R;
+
+/**
+ * Preference which describes an app which is requesting space and how much space it is requesting.
+ */
+public class GaugePreference extends Preference {
+
+ public GaugePreference(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ setLayoutResource(R.layout.informational_preference);
+ }
+}