From 6484b6be5ca5233614d0a8991a5d909543824fc7 Mon Sep 17 00:00:00 2001 From: Yang Ni Date: Thu, 24 Mar 2016 09:40:32 -0700 Subject: Added CloseGuard for BaseObj Bug: 27719830 To turn on warnings, apps have to add to their Activity.onCreate() method the following code. StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder() .detectLeakedClosableObjects() .penaltyLog() .build()); For Slang generated ScriptC derived classes, we assume their constructors won't throw exceptions after calling the ScriptC constructor. In addition, ScriptIntrinsic derived classes do not seem to throw exceptions in their constructors either. Therefore, we can leave the guard.open() call in the Script constructor. This may be only an approximation, but allows us to add CloseGuard for script objects without making changes to slang. Change-Id: I77ed45239a60b85af5c811dee6c124fb53da9060 (cherry picked from commit eb4dd08ec132f83745b8b28fa7da58eb4478b5b9) --- rs/java/android/renderscript/Script.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'rs/java/android/renderscript/Script.java') diff --git a/rs/java/android/renderscript/Script.java b/rs/java/android/renderscript/Script.java index 2b0678046e32..414c5a1aced1 100644 --- a/rs/java/android/renderscript/Script.java +++ b/rs/java/android/renderscript/Script.java @@ -41,6 +41,7 @@ public class Script extends BaseObj { mScript = s; mSlot = slot; mSig = sig; + guard.open("destroy"); } } @@ -118,6 +119,7 @@ public class Script extends BaseObj { super(id, rs); mScript = s; mSlot = slot; + guard.open("destroy"); } } @@ -357,6 +359,19 @@ public class Script extends BaseObj { super(id, rs); mInIdsBuffer = new long[1]; + + /* The constructors for the derived classes (including ScriptIntrinsic + * derived classes and ScriptC derived classes generated by Slang + * reflection) seem to be simple enough, so we just put the guard.open() + * call here, rather than in the end of the constructor for the derived + * class. This, of course, assumes the derived constructor would not + * throw any exception after calling this constructor. + * + * If new derived classes are added with more complicated constructors + * that throw exceptions, this call has to be (duplicated and) moved + * to the end of each derived class constructor. + */ + guard.open("destroy"); } /** -- cgit v1.2.3