diff options
author | Veeti Paananen <veeti.paananen@rojekti.fi> | 2013-02-04 02:32:05 +0200 |
---|---|---|
committer | Veeti Paananen <veeti.paananen@rojekti.fi> | 2013-02-04 23:02:15 +0200 |
commit | 61ce07c6fabfd53b1a2ee453837ea188fda9d0fe (patch) | |
tree | 8ff03287a7480ee74904ebbd16a8829f8397c4bc | |
parent | bc3688674fbfc1a079adbef7cd3d0e1f501cae0c (diff) | |
download | frameworks_opt_telephony-61ce07c6fabfd53b1a2ee453837ea188fda9d0fe.zip frameworks_opt_telephony-61ce07c6fabfd53b1a2ee453837ea188fda9d0fe.tar.gz frameworks_opt_telephony-61ce07c6fabfd53b1a2ee453837ea188fda9d0fe.tar.bz2 |
Update the SMS sending limit instantly (1/2)
Patch Set 2: observe the setting value instead of checking its value
every time
Patch Set 3: readd accidentally removed final modifier
Patch Set 4: remove redundant inner context variable
Change-Id: If8a0867945cf308391009eae168bf05a6dd429eb
-rw-r--r-- | src/java/com/android/internal/telephony/SmsUsageMonitor.java | 36 |
1 files changed, 21 insertions, 15 deletions
diff --git a/src/java/com/android/internal/telephony/SmsUsageMonitor.java b/src/java/com/android/internal/telephony/SmsUsageMonitor.java index 0032881..5490c13 100644 --- a/src/java/com/android/internal/telephony/SmsUsageMonitor.java +++ b/src/java/com/android/internal/telephony/SmsUsageMonitor.java @@ -22,6 +22,7 @@ import android.content.Context; import android.content.pm.ApplicationInfo; import android.content.res.XmlResourceParser; import android.database.ContentObserver; +import android.net.Uri; import android.os.Binder; import android.os.Handler; import android.os.Message; @@ -111,7 +112,7 @@ public class SmsUsageMonitor { public static final int PREMIUM_SMS_PERMISSION_ALWAYS_ALLOW = 3; private final int mCheckPeriod; - private final int mMaxAllowed; + private int mMaxAllowed; private final HashMap<String, ArrayList<Long>> mSmsStamp = new HashMap<String, ArrayList<Long>>(); @@ -228,30 +229,32 @@ public class SmsUsageMonitor { /** * Observe the secure setting for enable flag */ - private static class SettingsObserver extends ContentObserver { - private final Context mContext; - private final AtomicBoolean mEnabled; + private class SettingsObserver extends ContentObserver { - SettingsObserver(Handler handler, Context context, AtomicBoolean enabled) { + SettingsObserver(Handler handler) { super(handler); - mContext = context; - mEnabled = enabled; - onChange(false); } @Override - public void onChange(boolean selfChange) { - mEnabled.set(Settings.Global.getInt(mContext.getContentResolver(), - Settings.Global.SMS_SHORT_CODE_CONFIRMATION, 1) != 0); + public void onChange(boolean selfChange, Uri uri) { + if (uri.equals(Settings.Global.getUriFor(Settings.Global.SMS_SHORT_CODE_CONFIRMATION))) { + mCheckEnabled.set(Settings.Global.getInt(mContext.getContentResolver(), + Settings.Global.SMS_SHORT_CODE_CONFIRMATION, 1) != 0); + } else if (uri.equals(Settings.Global.getUriFor(Settings.Global.SMS_OUTGOING_CHECK_MAX_COUNT))) { + mMaxAllowed = Settings.Global.getInt(mContext.getContentResolver(), + Settings.Global.SMS_OUTGOING_CHECK_MAX_COUNT, DEFAULT_SMS_MAX_COUNT); + } } } - private static class SettingsObserverHandler extends Handler { - SettingsObserverHandler(Context context, AtomicBoolean enabled) { + private class SettingsObserverHandler extends Handler { + SettingsObserverHandler(Context context) { ContentResolver resolver = context.getContentResolver(); - ContentObserver globalObserver = new SettingsObserver(this, context, enabled); + ContentObserver globalObserver = new SettingsObserver(this); resolver.registerContentObserver(Settings.Global.getUriFor( Settings.Global.SMS_SHORT_CODE_CONFIRMATION), false, globalObserver); + resolver.registerContentObserver(Settings.Global.getUriFor( + Settings.Global.SMS_OUTGOING_CHECK_MAX_COUNT), false, globalObserver); } } @@ -271,7 +274,10 @@ public class SmsUsageMonitor { Settings.Global.SMS_OUTGOING_CHECK_INTERVAL_MS, DEFAULT_SMS_CHECK_PERIOD); - mSettingsObserverHandler = new SettingsObserverHandler(mContext, mCheckEnabled); + mCheckEnabled.set(Settings.Global.getInt(resolver, + Settings.Global.SMS_SHORT_CODE_CONFIRMATION, 1) != 0); + + mSettingsObserverHandler = new SettingsObserverHandler(mContext); loadPremiumSmsPolicyDb(); } |