mwarning / trigger

Android app to lock/unlock/ring doors. Supports generic HTTPS/SSH/Bluetooth/MQTT and Nuki Smartlock.
GNU General Public License v3.0
134 stars 22 forks source link

callback compatibility issue when initialing method #73

Closed PSDroid2022 closed 2 years ago

PSDroid2022 commented 2 years ago

We confirm a callback compatibility issue which might threaten the robustness of your app and give a detailed suggestion for you.

In ''app.trigger.QRScanActivity", you super the framework API "<android.app.Activity: void onRequestPermissionsResult(int,java.lang.String[],int[])>" in "onRequestPermissionsResult" method as shown in following. But actually, this method is added in API level 23 (https://developer.android.google.cn/reference/android/app/Activity?hl=en#onRequestPermissionsResult(int,%20java.lang.String[],%20int[])).

@Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        if (grantResults[0] == PackageManager.PERMISSION_GRANTED){
            startScan();
        } else {
            Toast.makeText(this, "Camera permissions required for QR code scan.", Toast.LENGTH_LONG).show();
            finish();
        }
    }

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

mwarning commented 2 years ago

Thank you for your hint. I will see what can be done.

mwarning commented 2 years ago

Fixed here: https://github.com/mwarning/trigger/commit/b03385a69b488cadf9f077f06233118506253f3d