From bbb1237e909295d4b74a5bbe60d6ae50b6203f61 Mon Sep 17 00:00:00 2001 From: Nikos Gorogiannis Date: Mon, 18 Nov 2019 01:57:31 -0800 Subject: [PATCH] [concurrency] add models for Android UI thread callbacks (ServiceConnection) Summary: As per summary. Reviewed By: ezgicicek Differential Revision: D18530731 fbshipit-source-id: a0419aeab --- infer/src/concurrency/ConcurrencyModels.ml | 6 ++- .../MyServiceConnection.java | 43 +++++++++++++++++++ .../java/starvation-whole-program/issues.exp | 4 ++ 3 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 infer/tests/codetoanalyze/java/starvation-whole-program/MyServiceConnection.java diff --git a/infer/src/concurrency/ConcurrencyModels.ml b/infer/src/concurrency/ConcurrencyModels.ml index d84d34fc0..90a353389 100644 --- a/infer/src/concurrency/ConcurrencyModels.ml +++ b/infer/src/concurrency/ConcurrencyModels.ml @@ -345,7 +345,11 @@ let ui_matcher_records = https://developer.android.com/reference/android/view/View.html *) method_prefix= true ; classname= "android.view.View" - ; methods= ["on"] } ] + ; methods= ["on"] } + ; { default with + classname= "android.content.ServiceConnection" + ; methods= ["onBindingDied"; "onNullBinding"; "onServiceConnected"; "onServiceDisconnected"] } + ] let is_modeled_ui_method = diff --git a/infer/tests/codetoanalyze/java/starvation-whole-program/MyServiceConnection.java b/infer/tests/codetoanalyze/java/starvation-whole-program/MyServiceConnection.java new file mode 100644 index 000000000..59c0b2dd8 --- /dev/null +++ b/infer/tests/codetoanalyze/java/starvation-whole-program/MyServiceConnection.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +import android.content.ComponentName; +import android.content.ServiceConnection; +import android.os.Binder; +import android.os.IBinder; +import android.os.RemoteException; + +class MyServiceConnection implements ServiceConnection { + Binder b; + + private void bad() { + try { + b.transact(0, null, null, 0); + } catch (RemoteException r) { + } + } + + // implemented/overrides so no Bad suffixes + + void onBindingDied(ComponentName name) { + bad(); + } + + void onNullBinding(ComponentName name) { + bad(); + } + + @Override + public void onServiceConnected(ComponentName name, IBinder service) { + bad(); + } + + @Override + public void onServiceDisconnected(ComponentName name) { + bad(); + } +} diff --git a/infer/tests/codetoanalyze/java/starvation-whole-program/issues.exp b/infer/tests/codetoanalyze/java/starvation-whole-program/issues.exp index d385fef9e..a6b87e8fa 100644 --- a/infer/tests/codetoanalyze/java/starvation-whole-program/issues.exp +++ b/infer/tests/codetoanalyze/java/starvation-whole-program/issues.exp @@ -13,3 +13,7 @@ codetoanalyze/java/starvation-whole-program/MyActivity.java, MyActivity.onResume codetoanalyze/java/starvation-whole-program/MyActivity.java, MyActivity.onResume():void, 100, DEADLOCK, no_bucket, ERROR, [[Trace 1] `void MyActivity.onResume()`,Method call: `void MyActivity$3.run()`, locks `this.FP_monitorE` in `class MyActivity`, locks `this.FP_monitorD` in `class MyActivity`,[Trace 2] `void MyActivity.onResume()`, locks `this.FP_monitorD` in `class MyActivity`, locks `this.FP_monitorE` in `class MyActivity`] codetoanalyze/java/starvation-whole-program/MyActivity.java, MyActivity.onStart():void, 33, STARVATION, no_bucket, ERROR, [`void MyActivity.onStart()`,Method call: `void MyActivity.bad()`,calls `boolean Binder.transact(int,Parcel,Parcel,int)`] codetoanalyze/java/starvation-whole-program/MyActivity.java, MyActivity.onStop():void, 48, STARVATION, no_bucket, ERROR, [[Trace 1] `void MyActivity.onStop()`, locks `this.monitorA` in `class MyActivity`,[Trace 2] `void MyActivity.onStop()`,Method call: `void MyActivity$1.run()`, locks `this.monitorA` in `class MyActivity`,Method call: `void MyActivity.bad()`,calls `boolean Binder.transact(int,Parcel,Parcel,int)`] +codetoanalyze/java/starvation-whole-program/MyServiceConnection.java, MyServiceConnection.onBindingDied(android.content.ComponentName):void, 27, STARVATION, no_bucket, ERROR, [`void MyServiceConnection.onBindingDied(ComponentName)`,Method call: `void MyServiceConnection.bad()`,calls `boolean Binder.transact(int,Parcel,Parcel,int)`] +codetoanalyze/java/starvation-whole-program/MyServiceConnection.java, MyServiceConnection.onNullBinding(android.content.ComponentName):void, 31, STARVATION, no_bucket, ERROR, [`void MyServiceConnection.onNullBinding(ComponentName)`,Method call: `void MyServiceConnection.bad()`,calls `boolean Binder.transact(int,Parcel,Parcel,int)`] +codetoanalyze/java/starvation-whole-program/MyServiceConnection.java, MyServiceConnection.onServiceConnected(android.content.ComponentName,android.os.IBinder):void, 36, STARVATION, no_bucket, ERROR, [`void MyServiceConnection.onServiceConnected(ComponentName,IBinder)`,Method call: `void MyServiceConnection.bad()`,calls `boolean Binder.transact(int,Parcel,Parcel,int)`] +codetoanalyze/java/starvation-whole-program/MyServiceConnection.java, MyServiceConnection.onServiceDisconnected(android.content.ComponentName):void, 41, STARVATION, no_bucket, ERROR, [`void MyServiceConnection.onServiceDisconnected(ComponentName)`,Method call: `void MyServiceConnection.bad()`,calls `boolean Binder.transact(int,Parcel,Parcel,int)`]