use of com.stardust.autojs.runtime.exception.ScriptException in project Auto.js by hyb1996.
the class ScreenCapturer method capture.
@Nullable
public Image capture() {
if (!mImageAvailable) {
waitForImageAvailable();
}
if (mException != null) {
Exception e = mException;
mException = null;
throw new ScriptException(e);
}
synchronized (mCachedImageLock) {
if (mCachedImage != null) {
if (mUnderUsingImage != null)
mUnderUsingImage.close();
mUnderUsingImage = mCachedImage;
mCachedImage = null;
}
}
return mUnderUsingImage;
}
use of com.stardust.autojs.runtime.exception.ScriptException in project Auto.js by hyb1996.
the class Device method isCharging.
public boolean isCharging() {
Intent intent = mContext.registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
if (intent == null) {
throw new ScriptException("Cannot retrieve the battery state");
}
int plugged = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1);
return plugged == BatteryManager.BATTERY_PLUGGED_AC || plugged == BatteryManager.BATTERY_PLUGGED_USB;
}
use of com.stardust.autojs.runtime.exception.ScriptException in project Auto.js by hyb1996.
the class Events method observeNotification.
@RequiresApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
public void observeNotification() {
mScriptRuntime.requiresApi(18);
if (mListeningNotification)
return;
mListeningNotification = true;
ensureHandler();
mLoopers.waitWhenIdle(true);
if (NotificationListenerService.getInstance() == null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
mContext.startActivity(new Intent(Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS));
}
throw new ScriptException(mContext.getString(R.string.exception_notification_service_disabled));
}
NotificationListenerService.getInstance().addListener(this);
}
use of com.stardust.autojs.runtime.exception.ScriptException in project Auto.js by hyb1996.
the class Events method observeKey.
public void observeKey() {
if (mListeningKey)
return;
mScriptRuntime.ensureAccessibilityServiceEnabled();
AccessibilityService service = mAccessibilityBridge.getService();
if (service == null)
throw new ScriptException("AccessibilityService = null");
if ((service.getServiceInfo().flags & AccessibilityServiceInfo.FLAG_REQUEST_FILTER_KEY_EVENTS) == 0) {
throw new ScriptException(mContext.getString(R.string.text_should_enable_key_observing));
}
ensureHandler();
mLoopers.waitWhenIdle(true);
mListeningKey = true;
mAccessibilityBridge.ensureServiceEnabled();
service.getOnKeyObserver().addListener(this);
}
use of com.stardust.autojs.runtime.exception.ScriptException in project Auto.js by hyb1996.
the class RootAutomatorEngine method execute.
public void execute(String autoFile) {
mExecutablePath = getExecutablePath(mContext);
Log.d(LOG_TAG, "exec: " + autoFile);
final String[] commands = { "chmod 755 " + mExecutablePath, // to run root_automator
String.format("\"%s\" \"%s\" -d \"%s\" &", mExecutablePath, autoFile, mDeviceNameOrPath), // to print the root_automator pid
"echo $!", // to exit su
"exit", // to exit shell
"exit" };
try {
mProcess = Runtime.getRuntime().exec("su");
executeCommands(mProcess, commands);
mPid = readPid(mProcess);
mProcess.waitFor();
} catch (IOException e) {
throw new ScriptException(e);
} catch (InterruptedException e) {
throw new ScriptInterruptedException();
} finally {
mProcess.destroy();
mProcess = null;
}
}
Aggregations