adjust phone num save.
authorTrillGates <williamtrillgates@gmail.com>
Fri, 27 Aug 2021 12:44:55 +0000 (20:44 +0800)
committerTrillGates <williamtrillgates@gmail.com>
Fri, 27 Aug 2021 12:44:55 +0000 (20:44 +0800)
app/release/ICSer_V926_2108272032_release.apk [new file with mode: 0644]
app/release/output.json
app/src/main/java/com/enqualcomm/support/provider/ICMembersProvider.java
app/src/main/java/com/enqualcomm/support/service/PhoneCallListener.java
app/src/main/java/com/ic/protocols/protocol_s123.java
app/version_code.properties

diff --git a/app/release/ICSer_V926_2108272032_release.apk b/app/release/ICSer_V926_2108272032_release.apk
new file mode 100644 (file)
index 0000000..d226349
Binary files /dev/null and b/app/release/ICSer_V926_2108272032_release.apk differ
index 6689845..df7bcf4 100644 (file)
@@ -1 +1 @@
-[{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":921,"versionName":"2108232010","enabled":true,"outputFile":"ICSer_V921_2108232010_release.apk","fullName":"release","baseName":"release"},"path":"ICSer_V921_2108232010_release.apk","properties":{}}]
\ No newline at end of file
+[{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":926,"versionName":"2108272032","enabled":true,"outputFile":"ICSer_V926_2108272032_release.apk","fullName":"release","baseName":"release"},"path":"ICSer_V926_2108272032_release.apk","properties":{}}]
\ No newline at end of file
index f3df2a3..bc79f21 100644 (file)
@@ -79,7 +79,8 @@ public class ICMembersProvider extends ContentProvider {
         if (match == MATH_CODE_TABLE) {
             SQLiteDatabase writableDatabase = mDatabase.getWritableDatabase();
             //判断是否有存在吧,确保唯一,删除再添加吧,否则也是添加不进去的
-            writableDatabase.delete(ICDatabaseHelper.tMembers, ICDatabaseHelper.mId + "=?", new String[]{
+            writableDatabase.delete(ICDatabaseHelper.tMembers,
+                    ICDatabaseHelper.mId + "=?", new String[]{
                     values.getAsString(ICDatabaseHelper.mId)
             });
             long insert = writableDatabase.insert(ICDatabaseHelper.tMembers, null, values);
index 917eb00..5d0cf36 100644 (file)
@@ -5,10 +5,11 @@ import android.content.ContentValues;
 import android.content.Context;
 import android.database.Cursor;
 import android.net.Uri;
+import android.os.SystemClock;
 import android.provider.CallLog;
 import android.telephony.PhoneStateListener;
 import android.telephony.ServiceState;
-import android.text.TextUtils;
+import android.util.Log;
 
 import com.enqualcomm.support.provider.ICDatabaseHelper;
 import com.enqualcomm.support.provider.ICNotificationProvider;
@@ -23,6 +24,7 @@ import static com.enqualcomm.support.provider.ICGlobalSettingsProvider.SETTINGS;
  */
 public class PhoneCallListener extends PhoneStateListener {
 
+    private static final String TAG = "PhoneCallListener";
     private final Context mContext;
     private String mLastPhoneNumber;
 
@@ -33,74 +35,91 @@ public class PhoneCallListener extends PhoneStateListener {
     @Override
     public void onServiceStateChanged(ServiceState serviceState) {
         super.onServiceStateChanged(serviceState);
-        ICLogger.d("onServiceStateChanged == > " + serviceState);
+        Log.d(TAG, "onServiceStateChanged == > " + serviceState);
     }
 
+    private final Object mLock = new Object();
+
     @Override
     public void onCallStateChanged(int state, String incomingNumber) {
         super.onCallStateChanged(state, incomingNumber);
         ICLogger.d("state == > " + state + " incomingNumber ==>  " + incomingNumber);
-        if (!TextUtils.isEmpty(incomingNumber)) {
-            this.mLastPhoneNumber = incomingNumber;
-        }
         //挂断的时候,去查询一下是不是未接电话即可
         if (state == CALL_STATE_IDLE) {
-            //去查询是否有未接电话
-            queryCallState(this.mLastPhoneNumber);
+            new Thread(() -> {
+                synchronized (mLock) {
+                    SystemClock.sleep(1000);
+                    //查询整个通话记录
+                    queryCallState();
+                }
+            }).start();
         }
     }
 
-    private void queryCallState(String phoneNum) {
-        if (TextUtils.isEmpty(phoneNum)) {
-            return;
-        }
+    private void queryCallState() {
         String[] projection = {
                 CallLog.Calls.NUMBER,
                 CallLog.Calls.TYPE
         };
-        String where = CallLog.Calls.TYPE + "=" + CallLog.Calls.MISSED_TYPE + " and " +
-                CallLog.Calls.NUMBER + "=" + phoneNum;
+        String where = "type=? and is_read=?";
         Cursor c = mContext.getContentResolver().query(
                 Uri.parse("content://call_log/calls"),
                 projection,
                 where,
-                null,
+                new String[]{"3", "0"},
                 null
         );
-        ICLogger.d("where is == > " + where);
+        Log.d(TAG, "where is == > " + where);
         if (c != null) {
-            if (c.moveToNext()) {
+            int count = c.getCount();
+            Log.d(TAG, "int count ==> " + count);
+            if (count == 0) {
+                updateSettingsState(0);
+            } else {
+                //修改顶部的状态
+                updateSettingsState(1);
+            }
+            while (c.moveToNext()) {
                 //创建通知,如果大于1的知,说明有未接电话
+                String phoneNum = c.getString(0);
                 createNotification(phoneNum);
-                //修改顶部的状态
-                updateSettingsState();
             }
             c.close();
         }
+        //修改电话状态为已读,这样子以后就不会再创建通知了
+        ContentValues updateValues = new ContentValues();
+        //更新为已读
+        updateValues.put("is_read", 1);
+        int update = mContext.getContentResolver().update(Uri.parse("content://call_log/calls"),
+                updateValues,
+                where,
+                new String[]{"3", "0"});
+        Log.d(TAG, "update ==> " + update);
         this.mLastPhoneNumber = null;
     }
 
-    private void updateSettingsState() {
+    private void updateSettingsState(int value) {
         ContentResolver resolver = mContext.getContentResolver();
         ContentValues values = new ContentValues();
         values.put(ICDatabaseHelper.sKey, "has_missed_phone");
-        values.put(ICDatabaseHelper.sValue, 1);
+        values.put(ICDatabaseHelper.sValue, value);
         resolver.insert(Uri.parse(SETTINGS), values);
     }
 
     private void createNotification(String phoneNum) {
+        Log.d(TAG, "createNotification ===> " + phoneNum);
         //先查询是否有,如果已经有的话,就不创建了
         Cursor query = mContext.getContentResolver().query(Uri.parse(ICNotificationProvider.NOTIFICATIONS),
                 null, "category=? and type=? and title=?",
                 new String[]{"com.ic.phone", "missed_phone", phoneNum}, null);
         if (query != null) {
             if (query.moveToNext()) {
-                ICLogger.d("has one in there...");
+                Log.d(TAG, "has one in there...");
                 return;
             }
             query.close();
         }
-        ICLogger.d("createNotification==> " + phoneNum);
+        Log.d(TAG, "createNotification==> " + phoneNum);
         ContentValues contentValues = new ContentValues();
         contentValues.put(ICDatabaseHelper.notification_category, "com.ic.phone");
         contentValues.put(ICDatabaseHelper.notification_title, phoneNum);
index 4a097ab..20bb1a9 100644 (file)
@@ -1267,7 +1267,9 @@ public class protocol_s123 {
 
             if (Config.custom_name.equals("YT")) {
                 ICLogger.i("=====add hotline 96885 ");
-                contactArray.add(new Contact(Contact.CATEGORY_CALL, runtime.getContextProxy().context.getResources().getString(R.string.hotline), "96885"));
+                contactArray.add(new Contact(Contact.CATEGORY_CALL,
+                        runtime.getContextProxy().context.getResources().getString(R.string.hotline),
+                        "96885"));
             }
             ContentResolver resolver = runtime.getContextProxy().getResolver();
             //添加之前先删除白名单的内容
@@ -1285,7 +1287,6 @@ public class protocol_s123 {
                     ContentValues contentValues = new ContentValues();
                     contentValues.put(ICDatabaseHelper.fType, ICDatabaseHelper.MemberType.WHITE_LIST);
                     contentValues.put(ICDatabaseHelper.fPhoneNum, phonem);
-                    contentValues.put(ICDatabaseHelper.fID, phonem);
                     contentValues.put(ICDatabaseHelper.fUserName, name);
                     contentValues.put(ICDatabaseHelper.fCreateTime, System.currentTimeMillis());
                     contentValues.put(ICDatabaseHelper.fUpdateTime, System.currentTimeMillis());
@@ -1383,7 +1384,8 @@ public class protocol_s123 {
                                 alarmName = context.getString(R.string.alarm_sit_too_long_tips_text);
                             }
                             alarmList.add(new Alarm("ST" + alarmtime.substring(0, 2) + "." + alarmtime.substring(2),
-                                    "W" + repeat, "CON", alarmswitch == 1 ? "ON" : "OFF", alarmName));
+                                    "W" + repeat, "CON",
+                                    alarmswitch == 1 ? "ON" : "OFF", alarmName));
                         } catch (Exception e) {
                             ICLogger.e(e.getMessage(), e);
                         }
index bdc7ec8..f956531 100644 (file)
@@ -1,2 +1,2 @@
-#Mon Aug 23 20:10:28 CST 2021\r
-VERSION_CODE=921\r
+#Fri Aug 27 20:32:10 CST 2021\r
+VERSION_CODE=926\r