Fields Summary |
---|
private static final String | TAG |
private static final boolean | DEBUG |
private static final boolean | LOCAL_LOGV |
private static final int | RATE_LIMIT |
private static final long | ONE_HOUR |
private static final int | NO_ANSWER |
private static final int | ANSWER_YES |
private static final int | ANSWER_NO |
public static final int | ANSWER_TIMEOUT |
public static final String | RATE_LIMIT_SURPASSED_ACTION |
public static final String | RATE_LIMIT_CONFIRMED_ACTION |
private static RateController | sInstance |
private static boolean | sMutexLock |
private final android.content.Context | mContext |
private int | mAnswer |
private final android.content.BroadcastReceiver | mBroadcastReceiver |
Methods Summary |
---|
public static com.android.mms.util.RateController | getInstance()
if (sInstance == null) {
throw new IllegalStateException("Uninitialized.");
}
return sInstance;
|
public static void | init(android.content.Context context)
if (LOCAL_LOGV) {
Log.v(TAG, "RateController.init()");
}
if (sInstance != null) {
Log.w(TAG, "Already initialized.");
}
sInstance = new RateController(context);
|
public synchronized boolean | isAllowedByUser()
while (sMutexLock) {
try {
wait();
} catch (InterruptedException _) {
// Ignore it.
}
}
sMutexLock = true;
mContext.registerReceiver(mBroadcastReceiver,
new IntentFilter(RATE_LIMIT_CONFIRMED_ACTION));
mAnswer = NO_ANSWER;
try {
Intent intent = new Intent(RATE_LIMIT_SURPASSED_ACTION);
// Using NEW_TASK here is necessary because we're calling
// startActivity from outside an activity.
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mContext.startActivity(intent);
return waitForAnswer() == ANSWER_YES;
} finally {
mContext.unregisterReceiver(mBroadcastReceiver);
sMutexLock = false;
notifyAll();
}
|
public final boolean | isLimitSurpassed()
long oneHourAgo = System.currentTimeMillis() - ONE_HOUR;
Cursor c = SqliteWrapper.query(mContext, mContext.getContentResolver(),
Rate.CONTENT_URI, new String[] { "COUNT(*) AS rate" },
Rate.SENT_TIME + ">" + oneHourAgo, null, null);
if (c != null) {
try {
if (c.moveToFirst()) {
return c.getInt(0) >= RATE_LIMIT;
}
} finally {
c.close();
}
}
return false;
|
public final void | update()
ContentValues values = new ContentValues(1);
values.put(Rate.SENT_TIME, System.currentTimeMillis());
SqliteWrapper.insert(mContext, mContext.getContentResolver(),
Rate.CONTENT_URI, values);
|
private synchronized int | waitForAnswer()
for (int t = 0; (mAnswer == NO_ANSWER) && (t < ANSWER_TIMEOUT); t += 1000) {
try {
if (LOCAL_LOGV) {
Log.v(TAG, "Waiting for answer..." + t / 1000);
}
wait(1000L);
} catch (InterruptedException _) {
// Ignore it.
}
}
return mAnswer;
|