From a2ac0f49a7ce8fe22da58b5a5e6ab74d07c5e7c8 Mon Sep 17 00:00:00 2001 From: Trudu Laurent Date: Thu, 15 Dec 2022 14:42:57 +0100 Subject: [PATCH] Added isDWProfileEnabled method in the DWSynchronousMethod class. --- .../DWSynchronousMethods.java | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/datawedgeprofileintentswrapper/src/main/java/com/zebra/datawedgeprofileintents/DWSynchronousMethods.java b/datawedgeprofileintentswrapper/src/main/java/com/zebra/datawedgeprofileintents/DWSynchronousMethods.java index 50a6f03..cad8b17 100644 --- a/datawedgeprofileintentswrapper/src/main/java/com/zebra/datawedgeprofileintents/DWSynchronousMethods.java +++ b/datawedgeprofileintentswrapper/src/main/java/com/zebra/datawedgeprofileintents/DWSynchronousMethods.java @@ -20,6 +20,7 @@ public enum EResults private String mLastMessage = ""; private EResults mLastResult = EResults.NONE; + private boolean mIsDWPluginEnabledResult = false; private List mEnumerateScannersReturnList = null; private CountDownLatch mJobDoneLatch = null; private Context mContext = null; @@ -450,6 +451,76 @@ public void timeOut(String profileName) { } } + public Pair isDWPluginEnabled() + { + return isDWPluginEnabled(mContext.getPackageName()); + } + + public Pair isDWPluginEnabled(final String profileName) + { + if(mJobDoneLatch != null) + { + return new Pair<>(EResults.FAILED, "isDWPluginEnabled: Error, a job is already running in background. Please wait for it to finish or timeout."); + } + + mJobDoneLatch = new CountDownLatch(1); + + DWProfileBaseSettings settings = new DWProfileBaseSettings() + {{ + mProfileName = profileName; + }}; + + try + { + Looper.prepare(); + } + catch(Exception e) + { + } + + DWScannerPluginStatus dwScannerPluginStatus = new DWScannerPluginStatus(mContext); + dwScannerPluginStatus.execute(settings, new DWScannerPluginStatus.onScannerPluginStatus() { + @Override + public void result(String profileName, boolean isEnabled) { + if(isEnabled) + { + mLastMessage = "true"; + mLastResult = EResults.SUCCEEDED; + + } + else + { + mLastMessage = "false"; + mLastResult = EResults.FAILED; + } + mJobDoneLatch.countDown(); + } + + @Override + public void timeOut(String profileName) { + mLastMessage = "isDWPluginEnabled: timeout while trying to enable check if profile exists: " + profileName; + mLastResult = EResults.TIMEOUT; + mJobDoneLatch.countDown(); + } + }); + + + try { + mJobDoneLatch.await(); + mJobDoneLatch = null; + return new Pair<>(mLastResult, mLastMessage); + } catch (InterruptedException e) { + if(mJobDoneLatch != null) + { + while(mJobDoneLatch.getCount() > 0) + mJobDoneLatch.countDown(); + mJobDoneLatch = null; + } + return new Pair<>(EResults.FAILED, "isDWPluginEnabled: Exception while waiting for CountDownLatch : " + e.getMessage()); + } + } + + public Pair deleteProfile() { return deleteProfile(mContext.getPackageName());