Skip to content

Commit

Permalink
Added isDWProfileEnabled method in the DWSynchronousMethod class.
Browse files Browse the repository at this point in the history
  • Loading branch information
ltrudu committed Dec 15, 2022
1 parent 50ebd16 commit a2ac0f4
Showing 1 changed file with 71 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public enum EResults

private String mLastMessage = "";
private EResults mLastResult = EResults.NONE;
private boolean mIsDWPluginEnabledResult = false;
private List<DWEnumerateScanners.Scanner> mEnumerateScannersReturnList = null;
private CountDownLatch mJobDoneLatch = null;
private Context mContext = null;
Expand Down Expand Up @@ -450,6 +451,76 @@ public void timeOut(String profileName) {
}
}

public Pair<EResults, String> isDWPluginEnabled()
{
return isDWPluginEnabled(mContext.getPackageName());
}

public Pair<EResults, String> 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<EResults, String> deleteProfile()
{
return deleteProfile(mContext.getPackageName());
Expand Down

0 comments on commit a2ac0f4

Please sign in to comment.