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,97 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2015 The Android Open Source Project
|
||||
* Copyright (C) 2024 The LineageOS 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.datamodel.action;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.android.messaging.sms.SmsReleaseStorage;
|
||||
import com.android.messaging.util.Assert;
|
||||
|
||||
/**
|
||||
* Action used to handle low storage related issues on the device.
|
||||
*/
|
||||
public class HandleLowStorageAction extends Action implements Parcelable {
|
||||
private static final int SUB_OP_CODE_CLEAR_MEDIA_MESSAGES = 100;
|
||||
private static final int SUB_OP_CODE_CLEAR_OLD_MESSAGES = 101;
|
||||
|
||||
public static void handleDeleteMediaMessages(final long durationInMillis) {
|
||||
final HandleLowStorageAction action = new HandleLowStorageAction(
|
||||
SUB_OP_CODE_CLEAR_MEDIA_MESSAGES, durationInMillis);
|
||||
action.start();
|
||||
}
|
||||
|
||||
public static void handleDeleteOldMessages(final long durationInMillis) {
|
||||
final HandleLowStorageAction action = new HandleLowStorageAction(
|
||||
SUB_OP_CODE_CLEAR_OLD_MESSAGES, durationInMillis);
|
||||
action.start();
|
||||
}
|
||||
|
||||
private static final String KEY_SUB_OP_CODE = "sub_op_code";
|
||||
private static final String KEY_CUTOFF_DURATION_MILLIS = "cutoff_duration_millis";
|
||||
|
||||
private HandleLowStorageAction(final int subOpcode, final long durationInMillis) {
|
||||
super();
|
||||
actionParameters.putInt(KEY_SUB_OP_CODE, subOpcode);
|
||||
actionParameters.putLong(KEY_CUTOFF_DURATION_MILLIS, durationInMillis);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object executeAction() {
|
||||
final int subOpCode = actionParameters.getInt(KEY_SUB_OP_CODE);
|
||||
final long durationInMillis = actionParameters.getLong(KEY_CUTOFF_DURATION_MILLIS);
|
||||
switch (subOpCode) {
|
||||
case SUB_OP_CODE_CLEAR_MEDIA_MESSAGES:
|
||||
SmsReleaseStorage.deleteMessages(0, durationInMillis);
|
||||
break;
|
||||
|
||||
case SUB_OP_CODE_CLEAR_OLD_MESSAGES:
|
||||
SmsReleaseStorage.deleteMessages(1, durationInMillis);
|
||||
break;
|
||||
|
||||
default:
|
||||
Assert.fail("Unsupported action type!");
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private HandleLowStorageAction(final Parcel in) {
|
||||
super(in);
|
||||
}
|
||||
|
||||
public static final Parcelable.Creator<HandleLowStorageAction> CREATOR
|
||||
= new Parcelable.Creator<HandleLowStorageAction>() {
|
||||
@Override
|
||||
public HandleLowStorageAction createFromParcel(final Parcel in) {
|
||||
return new HandleLowStorageAction(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandleLowStorageAction[] newArray(final int size) {
|
||||
return new HandleLowStorageAction[size];
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public void writeToParcel(@NonNull final Parcel parcel, final int flags) {
|
||||
writeActionToParcel(parcel, flags);
|
||||
}
|
||||
}
|
||||
@@ -1,38 +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.receiver;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
import com.android.messaging.sms.SmsStorageStatusManager;
|
||||
|
||||
/**
|
||||
* Receiver that listens on storage status changes
|
||||
*/
|
||||
public class StorageStatusReceiver extends BroadcastReceiver {
|
||||
|
||||
@Override
|
||||
public void onReceive(final Context context, final Intent intent) {
|
||||
if (Intent.ACTION_DEVICE_STORAGE_LOW.equals(intent.getAction())) {
|
||||
SmsStorageStatusManager.handleStorageLow();
|
||||
} else if (Intent.ACTION_DEVICE_STORAGE_OK.equals(intent.getAction())) {
|
||||
SmsStorageStatusManager.handleStorageOk();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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";
|
||||
}
|
||||
}
|
||||
@@ -1,36 +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.ui;
|
||||
|
||||
import android.app.FragmentTransaction;
|
||||
import android.os.Bundle;
|
||||
|
||||
/**
|
||||
* Activity to contain the dialog of warning sms storage low.
|
||||
*/
|
||||
public class SmsStorageLowWarningActivity extends BaseBugleFragmentActivity {
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
FragmentTransaction ft = getFragmentManager().beginTransaction();
|
||||
SmsStorageLowWarningFragment fragment =
|
||||
SmsStorageLowWarningFragment.newInstance();
|
||||
ft.add(fragment, null/*tag*/);
|
||||
ft.commit();
|
||||
}
|
||||
}
|
||||
@@ -1,253 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2015 The Android Open Source Project
|
||||
* Copyright (C) 2024 The LineageOS 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.ui;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.app.DialogFragment;
|
||||
import android.app.Fragment;
|
||||
import android.app.FragmentTransaction;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.res.Resources;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.android.messaging.R;
|
||||
import com.android.messaging.datamodel.action.HandleLowStorageAction;
|
||||
import com.android.messaging.sms.SmsReleaseStorage;
|
||||
import com.android.messaging.sms.SmsReleaseStorage.Duration;
|
||||
import com.android.messaging.sms.SmsStorageStatusManager;
|
||||
import com.android.messaging.util.Assert;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Dialog to show the sms storage low warning
|
||||
*/
|
||||
public class SmsStorageLowWarningFragment extends Fragment {
|
||||
private SmsStorageLowWarningFragment() {
|
||||
}
|
||||
|
||||
public static SmsStorageLowWarningFragment newInstance() {
|
||||
return new SmsStorageLowWarningFragment();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(final Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
final FragmentTransaction ft = getFragmentManager().beginTransaction();
|
||||
final ChooseActionDialogFragment dialog = ChooseActionDialogFragment.newInstance();
|
||||
dialog.setTargetFragment(this, 0/*requestCode*/);
|
||||
dialog.show(ft, null/*tag*/);
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform confirm action for a specific action
|
||||
*
|
||||
* @param actionIndex
|
||||
*/
|
||||
private void confirm(final int actionIndex) {
|
||||
final FragmentTransaction ft = getFragmentManager().beginTransaction();
|
||||
final ConfirmationDialog dialog = ConfirmationDialog.newInstance(actionIndex);
|
||||
dialog.setTargetFragment(this, 0/*requestCode*/);
|
||||
dialog.show(ft, null/*tag*/);
|
||||
}
|
||||
|
||||
/**
|
||||
* The dialog is cancelled at any step
|
||||
*/
|
||||
private void cancel() {
|
||||
getActivity().finish();
|
||||
}
|
||||
|
||||
/**
|
||||
* The dialog to show for user to choose what delete actions to take when storage is low
|
||||
*/
|
||||
public static class ChooseActionDialogFragment extends DialogFragment {
|
||||
public static ChooseActionDialogFragment newInstance() {
|
||||
return new ChooseActionDialogFragment();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dialog onCreateDialog(final Bundle savedInstanceState) {
|
||||
final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||
|
||||
final LayoutInflater inflater = getActivity().getLayoutInflater();
|
||||
final View dialogLayout = inflater.inflate(
|
||||
R.layout.sms_storage_low_warning_dialog, null);
|
||||
final ListView actionListView = (ListView) dialogLayout.findViewById(
|
||||
R.id.free_storage_action_list);
|
||||
final List<String> actions = loadFreeStorageActions(getActivity().getResources());
|
||||
final ActionListAdapter listAdapter = new ActionListAdapter(getActivity(), actions);
|
||||
actionListView.setAdapter(listAdapter);
|
||||
|
||||
builder.setTitle(R.string.sms_storage_low_title)
|
||||
.setView(dialogLayout)
|
||||
.setNegativeButton(R.string.ignore, (dialog, id) -> dialog.cancel());
|
||||
|
||||
final Dialog dialog = builder.create();
|
||||
dialog.setCanceledOnTouchOutside(false);
|
||||
return dialog;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCancel(final DialogInterface dialog) {
|
||||
((SmsStorageLowWarningFragment) getTargetFragment()).cancel();
|
||||
}
|
||||
|
||||
private class ActionListAdapter extends ArrayAdapter<String> {
|
||||
public ActionListAdapter(final Context context, final List<String> actions) {
|
||||
super(context, R.layout.sms_free_storage_action_item_view, actions);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public View getView(final int position, final View view,
|
||||
@NonNull final ViewGroup parent) {
|
||||
TextView actionItemView;
|
||||
if (view == null || !(view instanceof TextView)) {
|
||||
final LayoutInflater inflater = LayoutInflater.from(getContext());
|
||||
actionItemView = (TextView) inflater.inflate(
|
||||
R.layout.sms_free_storage_action_item_view, parent, false);
|
||||
} else {
|
||||
actionItemView = (TextView) view;
|
||||
}
|
||||
|
||||
final String action = getItem(position);
|
||||
actionItemView.setText(action);
|
||||
actionItemView.setOnClickListener(view1 -> {
|
||||
dismiss();
|
||||
((SmsStorageLowWarningFragment) getTargetFragment()).confirm(position);
|
||||
});
|
||||
return actionItemView;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static final String KEY_ACTION_INDEX = "action_index";
|
||||
|
||||
/**
|
||||
* The dialog to confirm user's delete action
|
||||
*/
|
||||
public static class ConfirmationDialog extends DialogFragment {
|
||||
private Duration mDuration;
|
||||
private String mDurationString;
|
||||
|
||||
public static ConfirmationDialog newInstance(final int actionIndex) {
|
||||
final ConfirmationDialog dialog = new ConfirmationDialog();
|
||||
final Bundle args = new Bundle();
|
||||
args.putInt(KEY_ACTION_INDEX, actionIndex);
|
||||
dialog.setArguments(args);
|
||||
return dialog;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCancel(final DialogInterface dialog) {
|
||||
((SmsStorageLowWarningFragment) getTargetFragment()).cancel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dialog onCreateDialog(final Bundle savedInstanceState) {
|
||||
mDuration = SmsReleaseStorage.parseMessageRetainingDuration();
|
||||
mDurationString = SmsReleaseStorage.getMessageRetainingDurationString(mDuration);
|
||||
|
||||
final int actionIndex = getArguments().getInt(KEY_ACTION_INDEX);
|
||||
if (actionIndex < 0 || actionIndex > 1) {
|
||||
return null;
|
||||
}
|
||||
final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||
builder.setTitle(R.string.sms_storage_low_title)
|
||||
.setMessage(getConfirmDialogMessage(actionIndex))
|
||||
.setNegativeButton(android.R.string.cancel, (dialog, button) -> {
|
||||
dismiss();
|
||||
((SmsStorageLowWarningFragment) getTargetFragment()).cancel();
|
||||
})
|
||||
.setPositiveButton(android.R.string.ok, (dialog, button) -> {
|
||||
dismiss();
|
||||
handleAction(actionIndex);
|
||||
getActivity().finish();
|
||||
SmsStorageStatusManager.cancelStorageLowNotification();
|
||||
});
|
||||
return builder.create();
|
||||
}
|
||||
|
||||
private void handleAction(final int actionIndex) {
|
||||
final long durationInMillis =
|
||||
SmsReleaseStorage.durationToTimeInMillis(mDuration);
|
||||
switch (actionIndex) {
|
||||
case 0:
|
||||
HandleLowStorageAction.handleDeleteMediaMessages(durationInMillis);
|
||||
break;
|
||||
|
||||
case 1:
|
||||
HandleLowStorageAction.handleDeleteOldMessages(durationInMillis);
|
||||
break;
|
||||
|
||||
default:
|
||||
Assert.fail("Unsupported action");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the confirm dialog text for a specific delete action
|
||||
* @param index The action index
|
||||
* @return
|
||||
*/
|
||||
private String getConfirmDialogMessage(final int index) {
|
||||
switch (index) {
|
||||
case 0:
|
||||
return getString(R.string.delete_all_media_confirmation, mDurationString);
|
||||
case 1:
|
||||
return getString(R.string.delete_oldest_messages_confirmation, mDurationString);
|
||||
case 2:
|
||||
return getString(R.string.auto_delete_oldest_messages_confirmation,
|
||||
mDurationString);
|
||||
}
|
||||
throw new IllegalArgumentException(
|
||||
"SmsStorageLowWarningFragment: invalid action index " + index);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the text of delete message actions
|
||||
*
|
||||
* @param resources
|
||||
* @return
|
||||
*/
|
||||
private static List<String> loadFreeStorageActions(final Resources resources) {
|
||||
final Duration duration = SmsReleaseStorage.parseMessageRetainingDuration();
|
||||
final String durationString = SmsReleaseStorage.getMessageRetainingDurationString(duration);
|
||||
final List<String> actions = Lists.newArrayList();
|
||||
actions.add(resources.getString(R.string.delete_all_media));
|
||||
actions.add(resources.getString(R.string.delete_oldest_messages, durationString));
|
||||
|
||||
// TODO: Auto-purging is disabled for Bugle V1.
|
||||
// actions.add(resources.getString(R.string.auto_delete_oldest_messages, durationString));
|
||||
return actions;
|
||||
}
|
||||
}
|
||||
@@ -319,11 +319,6 @@ public abstract class UIIntents {
|
||||
final int updateTargets, final ConversationIdSet conversationIdSet,
|
||||
final int requestCode);
|
||||
|
||||
/**
|
||||
* Get a PendingIntent for showing low storage notifications.
|
||||
*/
|
||||
public abstract PendingIntent getPendingIntentForLowStorageNotifications(final Context context);
|
||||
|
||||
/**
|
||||
* Get a PendingIntent for showing a new message to a secondary user.
|
||||
*/
|
||||
|
||||
@@ -152,13 +152,6 @@ public class UIIntentsImpl extends UIIntents {
|
||||
context.startActivity(intent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an intent which shows the low storage warning activity.
|
||||
*/
|
||||
private Intent getSmsStorageLowWarningActivityIntent(final Context context) {
|
||||
return new Intent(context, SmsStorageLowWarningActivity.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void launchConversationActivity(final Context context,
|
||||
final String conversationId, final MessageData draft, final Bundle activityOptions,
|
||||
@@ -450,18 +443,6 @@ public class UIIntentsImpl extends UIIntents {
|
||||
return resultPendingIntent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PendingIntent getPendingIntentForLowStorageNotifications(final Context context) {
|
||||
final TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(context);
|
||||
final Intent conversationListIntent = getConversationListActivityIntent(context);
|
||||
taskStackBuilder.addNextIntent(conversationListIntent);
|
||||
taskStackBuilder.addNextIntentWithParentStack(
|
||||
getSmsStorageLowWarningActivityIntent(context));
|
||||
|
||||
return taskStackBuilder.getPendingIntent(
|
||||
0, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PendingIntent getPendingIntentForSecondaryUserNewMessageNotification(
|
||||
final Context context) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (C) 2015 The Android Open Source Project
|
||||
* Copyright (C) 2024 The LineageOS Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -119,20 +120,6 @@ public final class BugleGservicesKeys {
|
||||
"bugle_sms_full_sync_backoff_time";
|
||||
public static final long SMS_FULL_SYNC_BACKOFF_TIME_MILLIS_DEFAULT = 60 * 60 * 1000;
|
||||
|
||||
/**
|
||||
* Time duration to retain the most recent SMS messages for SMS storage purging
|
||||
*
|
||||
* Format:
|
||||
* <number>(w|m|y)
|
||||
* Examples:
|
||||
* "1y" -- a year
|
||||
* "2w" -- two weeks
|
||||
* "6m" -- six months
|
||||
*/
|
||||
public static final String SMS_STORAGE_PURGING_MESSAGE_RETAINING_DURATION =
|
||||
"bugle_sms_storage_purging_message_retaining_duration";
|
||||
public static final String SMS_STORAGE_PURGING_MESSAGE_RETAINING_DURATION_DEFAULT = "1m";
|
||||
|
||||
/**
|
||||
* MMS UA profile url.
|
||||
*
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (C) 2015 The Android Open Source Project
|
||||
* Copyright (C) 2024 The LineageOS Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -22,7 +23,6 @@ public class PendingIntentConstants {
|
||||
public static final int SMS_NOTIFICATION_ID = 0;
|
||||
public static final int SMS_SECONDARY_USER_NOTIFICATION_ID = 1;
|
||||
public static final int MSG_SEND_ERROR = 2;
|
||||
public static final int SMS_STORAGE_LOW_NOTIFICATION_ID = 3;
|
||||
|
||||
// Request codes
|
||||
public static final int UPDATE_NOTIFICATIONS_ALARM_ACTION_ID = 100;
|
||||
|
||||
Reference in New Issue
Block a user