1a1af734418c5578483f3387e5e0bf6128c963dfaTom Taylor/* 2a1af734418c5578483f3387e5e0bf6128c963dfaTom Taylor * Copyright (C) 2009 The Android Open Source Project 3a1af734418c5578483f3387e5e0bf6128c963dfaTom Taylor * 4a1af734418c5578483f3387e5e0bf6128c963dfaTom Taylor * Licensed under the Apache License, Version 2.0 (the "License"); 5a1af734418c5578483f3387e5e0bf6128c963dfaTom Taylor * you may not use this file except in compliance with the License. 6a1af734418c5578483f3387e5e0bf6128c963dfaTom Taylor * You may obtain a copy of the License at 7a1af734418c5578483f3387e5e0bf6128c963dfaTom Taylor * 8a1af734418c5578483f3387e5e0bf6128c963dfaTom Taylor * http://www.apache.org/licenses/LICENSE-2.0 9a1af734418c5578483f3387e5e0bf6128c963dfaTom Taylor * 10a1af734418c5578483f3387e5e0bf6128c963dfaTom Taylor * Unless required by applicable law or agreed to in writing, software 11a1af734418c5578483f3387e5e0bf6128c963dfaTom Taylor * distributed under the License is distributed on an "AS IS" BASIS, 12a1af734418c5578483f3387e5e0bf6128c963dfaTom Taylor * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13a1af734418c5578483f3387e5e0bf6128c963dfaTom Taylor * See the License for the specific language governing permissions and 14a1af734418c5578483f3387e5e0bf6128c963dfaTom Taylor * limitations under the License. 15a1af734418c5578483f3387e5e0bf6128c963dfaTom Taylor */ 16a1af734418c5578483f3387e5e0bf6128c963dfaTom Taylor 17a1af734418c5578483f3387e5e0bf6128c963dfaTom Taylorpackage com.android.mms.transaction; 18a1af734418c5578483f3387e5e0bf6128c963dfaTom Taylor 19a1af734418c5578483f3387e5e0bf6128c963dfaTom Taylorimport android.app.Notification; 20a1af734418c5578483f3387e5e0bf6128c963dfaTom Taylorimport android.app.NotificationManager; 21a1af734418c5578483f3387e5e0bf6128c963dfaTom Taylorimport android.app.PendingIntent; 22a1af734418c5578483f3387e5e0bf6128c963dfaTom Taylorimport android.content.BroadcastReceiver; 23a1af734418c5578483f3387e5e0bf6128c963dfaTom Taylorimport android.content.Context; 24a1af734418c5578483f3387e5e0bf6128c963dfaTom Taylorimport android.content.Intent; 25a1af734418c5578483f3387e5e0bf6128c963dfaTom Taylorimport android.provider.Settings; 26f7e8281a223af6228e6399055a6197a1edd9bc3aTom Taylorimport android.provider.Telephony; 27d64419030e1fec1e751695dab3bd7236e2fb0214Roger Chen 28d64419030e1fec1e751695dab3bd7236e2fb0214Roger Chenimport com.android.mms.R; 29a1af734418c5578483f3387e5e0bf6128c963dfaTom Taylorimport com.android.mms.ui.ConversationList; 30a1af734418c5578483f3387e5e0bf6128c963dfaTom Taylor 31a1af734418c5578483f3387e5e0bf6128c963dfaTom Taylor 32a1af734418c5578483f3387e5e0bf6128c963dfaTom Taylor/** 33a1af734418c5578483f3387e5e0bf6128c963dfaTom Taylor * Receive Intent.SMS_REJECTED. Handle notification that received SMS messages are being 34a1af734418c5578483f3387e5e0bf6128c963dfaTom Taylor * rejected. This can happen when the device is out of storage. 35a1af734418c5578483f3387e5e0bf6128c963dfaTom Taylor */ 36a1af734418c5578483f3387e5e0bf6128c963dfaTom Taylorpublic class SmsRejectedReceiver extends BroadcastReceiver { 37a1af734418c5578483f3387e5e0bf6128c963dfaTom Taylor 38a1af734418c5578483f3387e5e0bf6128c963dfaTom Taylor public static final int SMS_REJECTED_NOTIFICATION_ID = 239; 39a1af734418c5578483f3387e5e0bf6128c963dfaTom Taylor 40a1af734418c5578483f3387e5e0bf6128c963dfaTom Taylor @Override 41a1af734418c5578483f3387e5e0bf6128c963dfaTom Taylor public void onReceive(Context context, Intent intent) { 428b4521b61b8ff87f2a3a13850eaa13d8e8901174Jeff Brown if (Settings.Global.getInt(context.getContentResolver(), 438b4521b61b8ff87f2a3a13850eaa13d8e8901174Jeff Brown Settings.Global.DEVICE_PROVISIONED, 0) == 1 && 44f7e8281a223af6228e6399055a6197a1edd9bc3aTom Taylor Telephony.Sms.Intents.SMS_REJECTED_ACTION.equals(intent.getAction())) { 45a1af734418c5578483f3387e5e0bf6128c963dfaTom Taylor 46a1af734418c5578483f3387e5e0bf6128c963dfaTom Taylor int reason = intent.getIntExtra("result", -1); 47f7e8281a223af6228e6399055a6197a1edd9bc3aTom Taylor boolean outOfMemory = reason == Telephony.Sms.Intents.RESULT_SMS_OUT_OF_MEMORY; 48738c7cb4f2b16f722d7e2938eef9fd6720309c1bTom Taylor if (!outOfMemory) { 49738c7cb4f2b16f722d7e2938eef9fd6720309c1bTom Taylor // Right now, the only user-level rejection we show to the user is out-of-memory. 50738c7cb4f2b16f722d7e2938eef9fd6720309c1bTom Taylor return; 51738c7cb4f2b16f722d7e2938eef9fd6720309c1bTom Taylor } 52a1af734418c5578483f3387e5e0bf6128c963dfaTom Taylor 53a1af734418c5578483f3387e5e0bf6128c963dfaTom Taylor NotificationManager nm = (NotificationManager) 54a1af734418c5578483f3387e5e0bf6128c963dfaTom Taylor context.getSystemService(Context.NOTIFICATION_SERVICE); 55a1af734418c5578483f3387e5e0bf6128c963dfaTom Taylor 56a1af734418c5578483f3387e5e0bf6128c963dfaTom Taylor Intent viewConvIntent = new Intent(context, ConversationList.class); 57a1af734418c5578483f3387e5e0bf6128c963dfaTom Taylor viewConvIntent.setAction(Intent.ACTION_VIEW); 58a1af734418c5578483f3387e5e0bf6128c963dfaTom Taylor viewConvIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK 59a1af734418c5578483f3387e5e0bf6128c963dfaTom Taylor | Intent.FLAG_ACTIVITY_SINGLE_TOP 60a1af734418c5578483f3387e5e0bf6128c963dfaTom Taylor | Intent.FLAG_ACTIVITY_CLEAR_TOP); 61a1af734418c5578483f3387e5e0bf6128c963dfaTom Taylor PendingIntent pendingIntent = PendingIntent.getActivity( 62a1af734418c5578483f3387e5e0bf6128c963dfaTom Taylor context, 0, viewConvIntent, 0); 63a1af734418c5578483f3387e5e0bf6128c963dfaTom Taylor 64a1af734418c5578483f3387e5e0bf6128c963dfaTom Taylor Notification notification = new Notification(); 65a1af734418c5578483f3387e5e0bf6128c963dfaTom Taylor 66a1af734418c5578483f3387e5e0bf6128c963dfaTom Taylor // TODO: need appropriate icons 67a1af734418c5578483f3387e5e0bf6128c963dfaTom Taylor notification.icon = R.drawable.stat_sys_no_sim; 68a1af734418c5578483f3387e5e0bf6128c963dfaTom Taylor int titleId; 69a1af734418c5578483f3387e5e0bf6128c963dfaTom Taylor int bodyId; 70a1af734418c5578483f3387e5e0bf6128c963dfaTom Taylor if (outOfMemory) { 71a1af734418c5578483f3387e5e0bf6128c963dfaTom Taylor titleId = R.string.sms_full_title; 72a1af734418c5578483f3387e5e0bf6128c963dfaTom Taylor bodyId = R.string.sms_full_body; 73a1af734418c5578483f3387e5e0bf6128c963dfaTom Taylor } else { 74a1af734418c5578483f3387e5e0bf6128c963dfaTom Taylor titleId = R.string.sms_rejected_title; 75a1af734418c5578483f3387e5e0bf6128c963dfaTom Taylor bodyId = R.string.sms_rejected_body; 76a1af734418c5578483f3387e5e0bf6128c963dfaTom Taylor } 77a1af734418c5578483f3387e5e0bf6128c963dfaTom Taylor notification.tickerText = context.getString(titleId); 78a1af734418c5578483f3387e5e0bf6128c963dfaTom Taylor notification.defaults = Notification.DEFAULT_ALL; 79a1af734418c5578483f3387e5e0bf6128c963dfaTom Taylor 80a1af734418c5578483f3387e5e0bf6128c963dfaTom Taylor notification.setLatestEventInfo( 81a1af734418c5578483f3387e5e0bf6128c963dfaTom Taylor context, context.getString(titleId), 82a1af734418c5578483f3387e5e0bf6128c963dfaTom Taylor context.getString(bodyId), 83a1af734418c5578483f3387e5e0bf6128c963dfaTom Taylor pendingIntent); 84a1af734418c5578483f3387e5e0bf6128c963dfaTom Taylor nm.notify(SMS_REJECTED_NOTIFICATION_ID, notification); 85a1af734418c5578483f3387e5e0bf6128c963dfaTom Taylor } 86a1af734418c5578483f3387e5e0bf6128c963dfaTom Taylor } 87a1af734418c5578483f3387e5e0bf6128c963dfaTom Taylor 88a1af734418c5578483f3387e5e0bf6128c963dfaTom Taylor} 89