kvdroid / Kvdroid

Some Pyjnius tools for Kivy-Android developments.
MIT License
101 stars 24 forks source link

get_call_log on other devices than Samsung #55

Closed kony19 closed 1 year ago

kony19 commented 1 year ago

Hi. I've got Samsung A70 and kvdroid get_call_log() is printing entire call register very fine. But on other phones (not Samsung) e.g. Motorola e22 get_call_log() is printing nothing. Samsung A70 is running on Android 11 (API 30); Motorola e22 = Android 12 (API 31). For both Androids READ_CALL_LOG permission is granted.

You wrote in short manual: Since the release of Android 11 (API 30), the way file are stored became different. What does that mean? Any tips?

I've checked whole case on my friend's Samsung A53 (Android 13, API 33) and everything is fine - same as on Samsung A70 mentioned above.

Thanks in advance and take a look at this issue. Best regards.

kengoon commented 1 year ago

@kony19 1) do you have any call logs in your Motorola? 2) the tip has nothing to do with call log. It's just for storage, kind of heads up warning when dealing with file systems directly. It is not directly related to kvdroid

Also check to see if you added the necessary permissions

kony19 commented 1 year ago

log.txt

Logcat dump from Motorola attached.

Permissions from buildozer.spec as below: android.permissions = VIBRATE,WAKE_LOCK,CALL_PRIVILEGED,CALL_PHONE,INTERNET,ACCESS_WIFI_STATE,READ_PHONE_STATE,POST_NOTIFICATIONS,READ_CONTACTS,WRITE_CONTACTS,READ_CALL_LOG

Also: requirements = python3,kivy==2.1.0,kivymd==1.0.2,plyer,pillow,pyjnius,kvdroid,pycryptodome

kengoon commented 1 year ago

@kony19 You didn't answer the question

kengoon commented 1 year ago

@kony19 I won't be reading that log you dumped there. You didn't narrow it to the main issue. In the future, don't assume that every code maintainer has nothing else doing with their time and then bomb them with this kind of error log. You have to do some work yourself by narrowing the error log to the logs that are related to the issues

kony19 commented 1 year ago
  1. do you have any call logs in your Motorola?

Yes, there are planty of incoming, outgoing and rejected calls. The phone is in use. The calling app is from Google. On Samsung phones, the dialer app is from Galaxy Store. It's native app (v12.7.20.4).

In my opinion lines: 1867, 1868, 1883, 1891, 1892 are suspicious. There is one more interesting thing. I've added print(get_call_log()[1]) (as mark) in my code and couldn't find any empty list or dict in dumped log. On Samsung phones everything is listed just fine. I used logcat dump, too.

kony19 commented 1 year ago

I've found some tips in article: https://thegeekpage.com/fix-call-history-not-showing-up-on-android/

I've done more researches:

from jnius import autoclass, cast
pyActivity = autoclass("org.kivy.android.PythonActivity")
aContext = autoclass("android.content.Context")
defaultDialer = cast("android.telecom.TelecomManager", pyActivity.mActivity.getSystemService(aContext.TELECOM_SERVICE)).getDefaultDialerPackage()

If the default dialer is com.samsung.android.dialer everything works fine in context of URI: content://call_log/calls and android.provider.CallLog$Calls autoclass. If the default dialer is com.google.android.dialer kvdroid.tools.call.get_call_log() won't work. And it doesn't matter that READ_CALL_LOG permission is granted all the time.

I`ve noticed that in newly sold phones (other than Samsung) the only one and native app is Google Dialer. So the problem will grow.

kengoon commented 1 year ago

I've found some tips in article: https://thegeekpage.com/fix-call-history-not-showing-up-on-android/

I've done more researches: from jnius import autoclass, cast pyActivity = autoclass("org.kivy.android.PythonActivity") aContext = autoclass("android.content.Context") defaultDialer = cast("android.telecom.TelecomManager", pyActivity.mActivity.getSystemService(aContext.TELECOM_SERVICE)).getDefaultDialerPackage()

If the default dialer is com.samsung.android.dialer everything works fine in context of URI: content://call_log/calls and android.provider.CallLog$Calls autoclass. If the default dialer is com.google.android.dialer kvdroid.tools.call.get_call_log() won't work. And it doesn't matter that READ_CALL_LOG permission is granted all the time.

I`ve noticed that in newly sold phones (other than Samsung) the only one and native app is Google Dialer. So the problem will grow.

@kony19 I don't understand what you are trying to say and how the Samsung dialer has anything to do with kvdroid

kony19 commented 1 year ago

In the file: kvdroid/jclass/android/provider/__init__.py


def CallLogCalls(*args, instantiate: bool = False):
    # In simplification
    defaultDialer = cast("android.telecom.TelecomManager", pyActivity.mActivity.getSystemService(aContext.TELECOM_SERVICE)).getDefaultDialerPackage()

    if defaultDialer == 'com.google.android.dialer':
        # Google Dialer has got its own autonomous call logs. I'm not sure yet how to get to it correctly, more digging required.
        return _class_call(autoclass('??com.google.android.dialer/databases/annotated_call_log'), args, instantiate)

    return _class_call(autoclass('android.provider.CallLog$Calls'), args, instantiate)
kengoon commented 1 year ago

In the file: kvdroid/jclass/android/provider/__init__.py


def CallLogCalls(*args, instantiate: bool = False):
  # In simplification
  defaultDialer = cast("android.telecom.TelecomManager", pyActivity.mActivity.getSystemService(aContext.TELECOM_SERVICE)).getDefaultDialerPackage()

  if defaultDialer == 'com.google.android.dialer':
      # Google Dialer has got its own autonomous call logs. I'm not sure yet how to get to it correctly, more digging required.
      return _class_call(autoclass('??com.google.android.dialer/databases/annotated_call_log'), args, instantiate)

  return _class_call(autoclass('android.provider.CallLog$Calls'), args, instantiate)

@kony19 this code still has nothing to do with kvdroid. It doesn't directly affect CallLog.Calls java class. And this

'??com.google.android.dialer/databases/annotated_call_log'

Is not in any way a Java class. You can point me to where you got this so that I would understand what you're trying to say.

kony19 commented 1 year ago

@kengoon As I wrote: I'm not sure yet how to get to it correctly, more digging required. Please, read slowly and with understanding.

kengoon commented 1 year ago

@kony19 I read what you wrote there, and I'm requesting you to point me to the source of where you got that string I mentioned

kengoon commented 1 year ago

@kony19 Also always tag my username while commenting on this issue so that I get a notification and not to keep checking in to know when you have sent a message 😕

kony19 commented 1 year ago

@kengoon

... and I'm requesting you to point me to the source of where you got that string I mentioned

Here it is: https://android.stackexchange.com/questions/248173/how-long-and-where-android-10-keeps-phone-logs

The guy that wrote - that the dialer app handles it, so it depends on the app, not the device or Android version - is right. But there is some market dependence between phone manufacturer and Google Dialer. Non Samsung phones are sold with Google Dialer and THIS dialer provides its own autonomous call logs. If you got Samsung phone, the native dialer's call logs can be requested by Java class 'android.provider.CallLog$Calls'.

The point is that method CallLogCalls() in the file: kvdroid/jclass/android/provider/__init__.py is using Java class which does not cover all cases to read every call logs from every dialers.

I'm not sure if there exist such a class for Google Dialer that could be reimplemented in kvdroid. Maybe it will be impossible to read call logs from Google Dialer because of its hermetic approach. This is the space for community discussion. I would be very happy if I was wrong in my investigation.

kengoon commented 1 year ago

@kony19 Like I said this is not an issue with kvdroid. The link you provided does not provide any valuable information. I will go ahead and close this issue. You are welcome to open a pull request to add extra support for Samsung dialers.

kengoon commented 1 year ago

@kony19 here's a suggestion from bing chat:

However, if you are using a Samsung phone and this code is not working for you, you may need to add the following permissions to your manifest file:

<uses-permission android:name="com.sec.android.provider.logsprovider.permission.READ_LOGS" />
<uses-permission android:name="com.sec.android.provider.logsprovider.permission.WRITE_LOGS" />

PS: This is platform specific problem and not directly connected with kvdroid. Kvdroid follows the google standard android API. if a certain manufacturer decides to drift away from google standard API, then that's not kvdroid problem and we may or may not try to support the manufacturers device depending on how clear their documentation are