mkulesh / microMathematics

microMathematics Plus - Extended visual calculator
GNU General Public License v3.0
561 stars 68 forks source link

compatibility issue when calling method #116

Closed PSDroid2022 closed 2 years ago

PSDroid2022 commented 2 years ago

Hi, nice day! This time we confirm a callback compatibility issue which might threaten the robustness of your app and give a detailed suggestion for you.

In ''com.mkulesh.micromath.fman.AdapterDocuments", you call the framework API "<android.provider.DocumentsContract: java.lang.String getTreeDocumentId(android.net.Uri)>" in "setUri" method as shown in following. But actually, this method is added in API level 21 (https://developer.android.google.cn/reference/kotlin/android/provider/DocumentsContract?hl=en#getTreeDocumentId(android.net.Uri)).

@Override
    public void setUri(Uri uri_)
    {
        if (this.uri == null && isTreeUri(uri_))
        {
            try
            {
                ctx.getContentResolver().takePersistableUriPermission(uri_,
                        Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
            }
            catch (Exception e)
            {
                e.printStackTrace();
            }
            this.uri = DocumentsContract.buildDocumentUriUsingTree(uri_, DocumentsContract.getTreeDocumentId(uri_));
        }
        else
        {
            this.uri = uri_;
        }
    }

So when the app try to call this API on devices level 14~20, your app will run with an unpredictable results. So we suggest you add an "if(SDK_INT>=21)", " @TargetApi(Build.VERSION_CODES.Lollipop)" or change your app miniSDK from 14 to 21 to fix this potential issue. By the way, "@TargetApi(Build.VERSION_CODES.Lollipop)" will be deleted by Android compiler when extracting APKs, so it seems like a not good way to solve those issues.