Messaging: Remove low storage handling
* SMS are the least of your storage issues, if you reach the limit * Both Intent.ACTION_DEVICE_STORAGE_LOW and Intent.ACTION_DEVICE_STORAGE_LOW are not delivered to apps after O * Remove all now unused strings from all languages - we don't sync those with crowdin (yet) Change-Id: If01f937acdafbb34d5a9e792db54de4761ec4cc5
This commit is contained in:
@@ -1,166 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2015 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.messaging.sms;
|
||||
|
||||
import android.content.res.Resources;
|
||||
|
||||
import com.android.messaging.Factory;
|
||||
import com.android.messaging.R;
|
||||
import com.android.messaging.datamodel.SyncManager;
|
||||
import com.android.messaging.util.BugleGservices;
|
||||
import com.android.messaging.util.BugleGservicesKeys;
|
||||
import com.android.messaging.util.LogUtil;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Class handling message cleanup when storage is low
|
||||
*/
|
||||
public class SmsReleaseStorage {
|
||||
/**
|
||||
* Class representing a time duration specified by Gservices
|
||||
*/
|
||||
public static class Duration {
|
||||
// Time duration unit types
|
||||
public static final int UNIT_WEEK = 'w';
|
||||
public static final int UNIT_MONTH = 'm';
|
||||
public static final int UNIT_YEAR = 'y';
|
||||
|
||||
// Number of units
|
||||
public final int mCount;
|
||||
// Unit type: week, month or year
|
||||
public final int mUnit;
|
||||
|
||||
public Duration(final int count, final int unit) {
|
||||
mCount = count;
|
||||
mUnit = unit;
|
||||
}
|
||||
}
|
||||
|
||||
private static final String TAG = LogUtil.BUGLE_TAG;
|
||||
|
||||
private static final Duration DEFAULT_DURATION = new Duration(1, Duration.UNIT_MONTH);
|
||||
|
||||
private static final Pattern DURATION_PATTERN = Pattern.compile("([1-9]+\\d*)(w|m|y)");
|
||||
/**
|
||||
* Parse message retaining time duration specified by Gservices
|
||||
*
|
||||
* @return The parsed time duration from Gservices
|
||||
*/
|
||||
public static Duration parseMessageRetainingDuration() {
|
||||
final String smsAutoDeleteMessageRetainingDuration =
|
||||
BugleGservices.get().getString(
|
||||
BugleGservicesKeys.SMS_STORAGE_PURGING_MESSAGE_RETAINING_DURATION,
|
||||
BugleGservicesKeys.SMS_STORAGE_PURGING_MESSAGE_RETAINING_DURATION_DEFAULT);
|
||||
final Matcher matcher = DURATION_PATTERN.matcher(smsAutoDeleteMessageRetainingDuration);
|
||||
try {
|
||||
if (matcher.matches()) {
|
||||
return new Duration(
|
||||
Integer.parseInt(matcher.group(1)),
|
||||
matcher.group(2).charAt(0));
|
||||
}
|
||||
} catch (final NumberFormatException e) {
|
||||
// Nothing to do
|
||||
}
|
||||
LogUtil.e(TAG, "SmsAutoDelete: invalid duration " +
|
||||
smsAutoDeleteMessageRetainingDuration);
|
||||
return DEFAULT_DURATION;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get string representation of the time duration
|
||||
*
|
||||
* @param duration
|
||||
* @return
|
||||
*/
|
||||
public static String getMessageRetainingDurationString(final Duration duration) {
|
||||
final Resources resources = Factory.get().getApplicationContext().getResources();
|
||||
switch (duration.mUnit) {
|
||||
case Duration.UNIT_WEEK:
|
||||
return resources.getQuantityString(
|
||||
R.plurals.week_count, duration.mCount, duration.mCount);
|
||||
case Duration.UNIT_MONTH:
|
||||
return resources.getQuantityString(
|
||||
R.plurals.month_count, duration.mCount, duration.mCount);
|
||||
case Duration.UNIT_YEAR:
|
||||
return resources.getQuantityString(
|
||||
R.plurals.year_count, duration.mCount, duration.mCount);
|
||||
}
|
||||
throw new IllegalArgumentException(
|
||||
"SmsAutoDelete: invalid duration unit " + duration.mUnit);
|
||||
}
|
||||
|
||||
// Time conversations
|
||||
private static final long WEEK_IN_MILLIS = 7 * 24 * 3600 * 1000L;
|
||||
private static final long MONTH_IN_MILLIS = 30 * 24 * 3600 * 1000L;
|
||||
private static final long YEAR_IN_MILLIS = 365 * 24 * 3600 * 1000L;
|
||||
|
||||
/**
|
||||
* Convert time duration to time in milliseconds
|
||||
*
|
||||
* @param duration
|
||||
* @return
|
||||
*/
|
||||
public static long durationToTimeInMillis(final Duration duration) {
|
||||
switch (duration.mUnit) {
|
||||
case Duration.UNIT_WEEK:
|
||||
return duration.mCount * WEEK_IN_MILLIS;
|
||||
case Duration.UNIT_MONTH:
|
||||
return duration.mCount * MONTH_IN_MILLIS;
|
||||
case Duration.UNIT_YEAR:
|
||||
return duration.mCount * YEAR_IN_MILLIS;
|
||||
}
|
||||
return -1L;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete message actions:
|
||||
* 0: delete media messages
|
||||
* 1: delete old messages
|
||||
*
|
||||
* @param actionIndex The index of the delete action to perform
|
||||
* @param durationInMillis The time duration for retaining messages
|
||||
*/
|
||||
public static void deleteMessages(final int actionIndex, final long durationInMillis) {
|
||||
int deleted = 0;
|
||||
switch (actionIndex) {
|
||||
case 0: {
|
||||
// Delete media
|
||||
deleted = MmsUtils.deleteMediaMessages();
|
||||
break;
|
||||
}
|
||||
case 1: {
|
||||
// Delete old messages
|
||||
final long now = System.currentTimeMillis();
|
||||
final long cutOffTimestampInMillis = now - durationInMillis;
|
||||
// Delete messages from telephony provider
|
||||
deleted = MmsUtils.deleteMessagesOlderThan(cutOffTimestampInMillis);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
LogUtil.e(TAG, "SmsStorageStatusManager: invalid action " + actionIndex);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (deleted > 0) {
|
||||
// Kick off a sync to update local db.
|
||||
SyncManager.sync();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,104 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2015 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.messaging.sms;
|
||||
|
||||
import android.app.Notification;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import androidx.core.app.NotificationCompat;
|
||||
import androidx.core.app.NotificationManagerCompat;
|
||||
|
||||
import com.android.messaging.Factory;
|
||||
import com.android.messaging.R;
|
||||
import com.android.messaging.ui.UIIntents;
|
||||
import com.android.messaging.util.NotificationsUtil;
|
||||
import com.android.messaging.util.PendingIntentConstants;
|
||||
import com.android.messaging.util.PhoneUtils;
|
||||
|
||||
/**
|
||||
* Class that handles SMS auto delete and notification when storage is low
|
||||
*/
|
||||
public class SmsStorageStatusManager {
|
||||
/**
|
||||
* Handles storage low signal for SMS
|
||||
*/
|
||||
public static void handleStorageLow() {
|
||||
if (!PhoneUtils.getDefault().isSmsEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: Auto-delete messages, when that setting exists and is enabled
|
||||
|
||||
// Notify low storage for SMS
|
||||
postStorageLowNotification();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles storage OK signal for SMS
|
||||
*/
|
||||
public static void handleStorageOk() {
|
||||
if (!PhoneUtils.getDefault().isSmsEnabled()) {
|
||||
return;
|
||||
}
|
||||
cancelStorageLowNotification();
|
||||
}
|
||||
|
||||
/**
|
||||
* Post sms storage low notification
|
||||
*/
|
||||
private static void postStorageLowNotification() {
|
||||
final Context context = Factory.get().getApplicationContext();
|
||||
final Resources resources = context.getResources();
|
||||
final PendingIntent pendingIntent = UIIntents.get()
|
||||
.getPendingIntentForLowStorageNotifications(context);
|
||||
|
||||
final NotificationCompat.Builder builder = new NotificationCompat.Builder(context,
|
||||
NotificationsUtil.DEFAULT_CHANNEL_ID);
|
||||
builder.setContentTitle(resources.getString(R.string.sms_storage_low_title))
|
||||
.setTicker(resources.getString(R.string.sms_storage_low_notification_ticker))
|
||||
.setSmallIcon(R.drawable.ic_failed_light)
|
||||
.setPriority(Notification.PRIORITY_DEFAULT)
|
||||
.setOngoing(true) // Can't be swiped off
|
||||
.setAutoCancel(false) // Don't auto cancel
|
||||
.setContentIntent(pendingIntent);
|
||||
|
||||
final NotificationCompat.BigTextStyle bigTextStyle =
|
||||
new NotificationCompat.BigTextStyle(builder);
|
||||
bigTextStyle.bigText(resources.getString(R.string.sms_storage_low_text));
|
||||
final Notification notification = bigTextStyle.build();
|
||||
|
||||
final NotificationManagerCompat notificationManager =
|
||||
NotificationManagerCompat.from(Factory.get().getApplicationContext());
|
||||
|
||||
notificationManager.notify(getNotificationTag(),
|
||||
PendingIntentConstants.SMS_STORAGE_LOW_NOTIFICATION_ID, notification);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancel the notification
|
||||
*/
|
||||
public static void cancelStorageLowNotification() {
|
||||
final NotificationManagerCompat notificationManager =
|
||||
NotificationManagerCompat.from(Factory.get().getApplicationContext());
|
||||
notificationManager.cancel(getNotificationTag(),
|
||||
PendingIntentConstants.SMS_STORAGE_LOW_NOTIFICATION_ID);
|
||||
}
|
||||
|
||||
private static String getNotificationTag() {
|
||||
return Factory.get().getApplicationContext().getPackageName() + ":smsstoragelow";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user