Search in sources :

Example 1 with ScriptException

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;
}
Also used : ScriptException(com.stardust.autojs.runtime.exception.ScriptException) ScriptException(com.stardust.autojs.runtime.exception.ScriptException) ScriptInterruptedException(com.stardust.autojs.runtime.exception.ScriptInterruptedException) Nullable(android.support.annotation.Nullable)

Example 2 with ScriptException

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;
}
Also used : IntentFilter(android.content.IntentFilter) ScriptException(com.stardust.autojs.runtime.exception.ScriptException) Intent(android.content.Intent) SuppressLint(android.annotation.SuppressLint)

Example 3 with ScriptException

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);
}
Also used : ScriptException(com.stardust.autojs.runtime.exception.ScriptException) Intent(android.content.Intent) RequiresApi(android.support.annotation.RequiresApi)

Example 4 with ScriptException

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);
}
Also used : AccessibilityService(com.stardust.view.accessibility.AccessibilityService) ScriptException(com.stardust.autojs.runtime.exception.ScriptException)

Example 5 with ScriptException

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;
    }
}
Also used : ScriptException(com.stardust.autojs.runtime.exception.ScriptException) ScriptInterruptedException(com.stardust.autojs.runtime.exception.ScriptInterruptedException) IOException(java.io.IOException) ScriptInterruptedException(com.stardust.autojs.runtime.exception.ScriptInterruptedException)

Aggregations

ScriptException (com.stardust.autojs.runtime.exception.ScriptException)5 Intent (android.content.Intent)2 ScriptInterruptedException (com.stardust.autojs.runtime.exception.ScriptInterruptedException)2 SuppressLint (android.annotation.SuppressLint)1 IntentFilter (android.content.IntentFilter)1 Nullable (android.support.annotation.Nullable)1 RequiresApi (android.support.annotation.RequiresApi)1 AccessibilityService (com.stardust.view.accessibility.AccessibilityService)1 IOException (java.io.IOException)1