public boolean resume() {
   int i = Process.getThreadPriority(Process.myTid());
   Process.setThreadPriority(Process.THREAD_PRIORITY_URGENT_AUDIO);
   if (audioResume(ctx)) paused = false;
   Process.setThreadPriority(i);
   return paused == false;
 }
 @Override
 public void onCancel() {
   int pri = Process.getThreadPriority(Process.myTid());
   try {
     Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
     mSession.onCancel();
   } finally {
     Process.setThreadPriority(pri);
   }
 }
 public boolean inc_vol() {
   int i = Process.getThreadPriority(Process.myTid());
   Process.setThreadPriority(Process.THREAD_PRIORITY_URGENT_AUDIO);
   if (volume <= 0x2000) {
     volume += 0x400;
     audioSetVolume(ctx, volume);
   }
   Process.setThreadPriority(i);
   return true;
 }
 public boolean dec_vol() {
   int i = Process.getThreadPriority(Process.myTid());
   Process.setThreadPriority(Process.THREAD_PRIORITY_URGENT_AUDIO);
   if (volume >= 0x400) {
     volume -= 0x400;
     audioSetVolume(ctx, volume);
   } else if (volume != 0) audioSetVolume(ctx, 0);
   Process.setThreadPriority(i);
   return true;
 }
 @Override
 public void onGetSuggestionsMultiple(
     TextInfo[] textInfos, int suggestionsLimit, boolean sequentialWords) {
   int pri = Process.getThreadPriority(Process.myTid());
   try {
     Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
     mListener.onGetSuggestions(
         mSession.onGetSuggestionsMultiple(textInfos, suggestionsLimit, sequentialWords));
   } catch (RemoteException e) {
   } finally {
     Process.setThreadPriority(pri);
   }
 }
  @Override
  public void run() {
    Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
    while (true) {
      Request<?> request;
      try {
        request = mQueue.take();
      } catch (InterruptedException e) {
        if (mQuit) {
          return;
        }
        continue;
      }

      // If the request was cancelled already, do not perform the download request.
      if (request.isCanceled()) {
        request.finish();
        continue;
      }

      boolean prepare = mPrepare.preparePerform(request, mDelivery);
      if (!prepare) {
        continue;
      }

      mDownload.performRequest(request, mDelivery);

      request.finish();
    }
  }
  public void run() {
    android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_AUDIO);

    byte[] buffer = new byte[BUFFER_SIZE];
    DatagramPacket packet;

    try {
      int minBuf = AudioRecord.getMinBufferSize(sampleRate, channelConfig, audioFormat);
      recorder =
          new AudioRecord(
              MediaRecorder.AudioSource.MIC, sampleRate, channelConfig, audioFormat, minBuf);
      recorder.startRecording();
    } catch (Exception ex) {
      // TODO: handle this exception
    }

    while (recordAudio) {
      try {
        recorder.read(buffer, 0, buffer.length);

        packet = new DatagramPacket(buffer, buffer.length, InetAddress.getByName(_server), _port);
        socket.send(packet);
      } catch (Exception ex) {
        // TODO: handle this exception
      }
    }

    buffer = null;
  }
 public void run() {
   stopped = false;
   Process.setThreadPriority(Process.THREAD_PRIORITY_AUDIO);
   try {
     if (file.endsWith(".ape") || file.endsWith(".APE")) {
       if (initAudioMode(driver_mode)) apePlay(ctx, file, 0);
     } else if (file.endsWith(".flac") || file.endsWith(".FLAC")) {
       if (initAudioMode(driver_mode)) flacPlay(ctx, file, startpos);
     } else if (file.endsWith(".m4a") || file.endsWith(".M4A")) {
       if (initAudioMode(driver_mode)) alacPlay(ctx, file, 0);
     } else if (file.endsWith(".wav") || file.endsWith(".WAV")) {
       if (initAudioMode(driver_mode)) wavPlay(ctx, file, 0);
     } else if (file.endsWith(".wv") || file.endsWith(".WV")) {
       if (initAudioMode(driver_mode)) wvPlay(ctx, file, 0);
     } else if (file.endsWith(".mpc") || file.endsWith(".MPC")) {
       if (initAudioMode(driver_mode)) mpcPlay(ctx, file, 0);
     }
     if (cb != null && !stopped) {
       audioStop(ctx);
       stopped = true;
       paused = false;
       cb.onCompletion();
     }
   } catch (Exception e) {
   }
 }
Exemple #9
0
  @Override
  public void run() {
    Log.v(Constants.TAG, "Started audio output thread.");
    android.os.Process.setThreadPriority(Process.THREAD_PRIORITY_URGENT_AUDIO);
    mRunning = true;
    mAudioTrack.play();

    final short[] mix = new short[Audio.FRAME_SIZE * 12];

    while (mRunning) {
      Arrays.fill(mix, (short) 0);
      boolean play = mix(mix, mix.length);
      if (play) {
        mAudioTrack.write(mix, 0, mix.length);
      } else if (System.nanoTime() - mLastPacket > SLEEP_THRESHOLD) {
        Log.v(Constants.TAG, "Pausing audio output thread.");
        synchronized (mInactiveLock) {
          try {
            mInactiveLock.wait();
          } catch (InterruptedException e) {
            e.printStackTrace();
          }
        }
        Log.v(Constants.TAG, "Resuming audio output thread.");
      }
    }

    mAudioTrack.flush();
    mAudioTrack.stop();
  }
  @Override
  public void run() {
    Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
    while (true) {
      NetworkRequestor<?> request;
      try {
        request = mRequestQueue.take();
      } catch (InterruptedException e) {
        if (mQuit) {
          return;
        }
        continue;
      }

      if (request.request.isCanceled()) {
        continue;
      }
      // start
      final ThreadPoster startThread = new ThreadPoster(request.what, request.responseListener);
      startThread.onStart();
      getPosterHandler().post(startThread);
      // finish
      final ThreadPoster finishThread = new ThreadPoster(request.what, request.responseListener);
      Response<?> response = mConnectionRest.request(request.request);
      if (request.request.isCanceled()) {
        finishThread.onFinished();
      } else {
        finishThread.onResponse(response);
      }
      getPosterHandler().post(finishThread);
    }
  }
Exemple #11
0
 public Void call() {
   try {
     setThreadPriority(THREAD_PRIORITY_DISPLAY);
     final Drawable drawable = drawableFuture.get();
     if (imageUrl.equals(imageView.getTag())) {
       new Handler(mainLooper)
           .post(
               new Runnable() {
                 @Override
                 public void run() {
                   imageView.setImageDrawable(drawable);
                   imageView.setTag(null);
                 }
               });
     }
   } catch (InterruptedException e) {
     throw new RuntimeException(e);
   } catch (ExecutionException e) {
     throw new RuntimeException(e);
   } finally {
     synchronized (outstandingDownloads) {
       outstandingDownloads.remove(imageUrl);
       outstandingDraws.remove(imageView);
     }
   }
   return null;
 }
Exemple #12
0
  @Override
  public void run() {
    Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
    while (info.redirect < MAX_REDIRECTS) {
      HttpURLConnection conn = null;
      try {
        conn = (HttpURLConnection) new URL(info.realUrl).openConnection();
        conn.setInstanceFollowRedirects(false);
        conn.setConnectTimeout(DEFAULT_TIMEOUT);
        conn.setReadTimeout(DEFAULT_TIMEOUT);

        addRequestHeaders(conn);

        final int code = conn.getResponseCode();
        switch (code) {
          case HTTP_OK:
          case HTTP_PARTIAL:
            dlInit(conn, code);
            return;
          case HTTP_MOVED_PERM:
          case HTTP_MOVED_TEMP:
          case HTTP_SEE_OTHER:
          case HTTP_NOT_MODIFIED:
          case HTTP_TEMP_REDIRECT:
            final String location = conn.getHeaderField("location");
            if (TextUtils.isEmpty(location))
              throw new DLException("Can not obtain real url from location in header.");
            info.realUrl = location;
            info.redirect++;
            continue;
          default:
            if (info.hasListener) info.listener.onError(code, conn.getResponseMessage(), info);
            EventBus.getDefault().post(info, "onError");
            DLManager.getInstance(context).removeDLTask(info.baseUrl);
            info.state = DLState.FAIL;
            try {
              mDLInfoDao.update(info);
            } catch (SQLException e1) {
              e1.printStackTrace();
            }
            return;
        }
      } catch (Exception e) {
        if (info.hasListener) info.listener.onError(ERROR_OPEN_CONNECT, e.toString(), info);
        EventBus.getDefault().post(info, "onError");
        DLManager.getInstance(context).removeDLTask(info.baseUrl);
        info.state = DLState.FAIL;
        try {
          mDLInfoDao.update(info);
        } catch (SQLException e1) {
          e1.printStackTrace();
        }
        return;
      } finally {
        if (null != conn) conn.disconnect();
      }
    }
    throw new RuntimeException("Too many redirects");
  }
Exemple #13
0
  @Override
  public void run() {
    // 描画よりも若干高い優先度のスレッドにする
    android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_DISPLAY - 1);

    // 実行
    mCore.run(this);
  }
 public void run() {
   Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
   initialize();
   Looper.prepare();
   mHandler = new ProviderHandler();
   // signal when we are initialized and ready to go
   mInitializedLatch.countDown();
   Looper.loop();
 }
Exemple #15
0
 public void run() {
   android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_URGENT_AUDIO);
   try {
     audioLoop();
   } catch (final InterruptedException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
 }
Exemple #16
0
  @Override
  public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
    if (sUriMatcher.match(uri) == TYPE_RESTRICTION) {
      // Check access
      enforcePermission();

      // Get arguments
      String restrictionName = selection;
      int uid = values.getAsInteger(COL_UID);
      String methodName = values.getAsString(COL_METHOD);
      boolean allowed = !Boolean.parseBoolean(values.getAsString(COL_RESTRICTED));

      // Update
      updateRestriction(uid, restrictionName, methodName, allowed);

      return 1; // rows
    } else if (sUriMatcher.match(uri) == TYPE_USAGE) {
      Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);

      // Get arguments
      int uid = values.getAsInteger(COL_UID);
      String restrictionName = values.getAsString(PrivacyProvider.COL_RESTRICTION);
      String methodName = values.getAsString(COL_METHOD);
      boolean restricted = false;
      if (values.containsKey(PrivacyProvider.COL_RESTRICTED))
        restricted = values.getAsBoolean(PrivacyProvider.COL_RESTRICTED);
      long timeStamp = values.getAsLong(PrivacyProvider.COL_USED);
      Util.log(
          null,
          Log.INFO,
          String.format(
              "Update usage data %d/%s/%s=%b", uid, restrictionName, methodName, restricted));

      // Update usage data
      if (methodName != null) updateUsage(uid, restrictionName, methodName, restricted, timeStamp);

      return 1;
    } else if (sUriMatcher.match(uri) == TYPE_SETTING) {
      // Check access
      enforcePermission();

      // Get arguments
      String settingName = selection;

      // Update setting
      SharedPreferences prefs =
          getContext().getSharedPreferences(PREF_SETTINGS, Context.MODE_WORLD_READABLE);
      SharedPreferences.Editor editor = prefs.edit();
      editor.putString(getSettingPref(settingName), values.getAsString(COL_VALUE));
      editor.apply();
      setPrefFileReadable(PREF_SETTINGS);

      return 1;
    }

    throw new IllegalArgumentException(uri.toString());
  }
    public void run() {
      // Make sure we're running with a background priority
      Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);

      try {
        mDiskCache.flush();
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
 public void run() {
   try {
     Process.setThreadPriority(NamedThreadFactory.a(this.b));
     label10:
     this.a.run();
     return;
   } catch (Throwable localThrowable) {
     break label10;
   }
 }
Exemple #19
0
 public final void run() {
   Process.setThreadPriority(10);
   try {
     kbw localkbw =
         bqo.a(this.a, this.b, this.c, this.d, this.e, this.f, this.g, this.h, this.i, null);
     this.k.b(this.j, new dmx(localkbw), null);
     return;
   } catch (Exception localException) {
     this.k.b(this.j, new dmx(0, null, localException), null);
   }
 }
  /**
   * Sets the priority of the calling thread to a specific value.
   *
   * @param threadPriority the priority to be set on the calling thread
   */
  public static void setThreadPriority(int threadPriority) {
    Throwable exception = null;

    try {
      Process.setThreadPriority(threadPriority);
    } catch (IllegalArgumentException iae) {
      exception = iae;
    } catch (SecurityException se) {
      exception = se;
    }
    if (exception != null) logger.warn("Failed to set thread priority.", exception);
  }
    @Override
    public void run() {
      // TODO Auto-generated method stub
      Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
      refreshTime = System.currentTimeMillis();

      String filePath = FileCatchConfigUtil.getCatchPath() + "bithealth.apk";
      ;

      IServerBusiness.getInstance(DownLoadApkService.this.getApplicationContext())
          .DownLoadFile(downloadApkUrl, filePath, DownLoadApkService.this);
    }
  @Override
  public void run() {
    android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_URGENT_AUDIO);
    Modulation.initDecoder(); // init demodulator
    Modulation.initProcess();
    recdata = new short[recBufSize / 2];

    while (!Thread.interrupted() && !mStopRecording) {
      if (recorder == null) {
        break;
      }
      nread = recorder.read(recdata, 0, recBufSize / 2);

      if (nread > 0) {
        retval = Modulation.process(recdata, nread);
        if (retval == 2) {
          String str = "";
          byte[] result = Modulation.getResult();
          try {
            str = new String(result, "UTF-8");
          } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
          }

          if (mStopRecording) {
            continue;
          }

          Message msg = mHandler.obtainMessage();
          msg.what = mEventId;
          msg.obj = str;

          mHandler.sendMessage(msg);
          try {
            // when receive a message, sleep a little while;
            // so the main thread has a chance to stop recording immediately
            Thread.sleep(200);
          } catch (InterruptedException e) {
            continue;
          }
        }
      }
    }
    try {
      recorder.stop();
      recorder.release();
    } catch (Exception e) {
      e.printStackTrace();
    }
    recorder = null;
    Modulation.releaseDecoder();
  }
 @Override
 public void run() {
   mTid = Process.myTid();
   Looper.prepare();
   synchronized (this) {
     mLooper = Looper.myLooper();
     notifyAll();
   }
   Process.setThreadPriority(mPriority);
   onLooperPrepared();
   Looper.loop();
   mTid = -1;
 }
Exemple #24
0
    public void run() {
      // Make sure we're running with a background priority
      Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);

      if (Constants.DEBUG) {
        Log.d(Constants.LOG_TAG, "Flushing Disk Cache");
      }
      try {
        mDiskCache.flush();
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
Exemple #25
0
 @Override
 public Drawable call() throws Exception {
   InputStream inputStream = null;
   try {
     setThreadPriority(THREAD_PRIORITY_DEFAULT);
     inputStream = urlStreamer.get(imageUrl);
     return Drawable.createFromStream(inputStream, "src");
   } catch (IOException e) {
     throw new RuntimeException(e);
   } finally {
     if (inputStream != null) {
       inputStream.close();
     }
   }
 }
  @Override
  public void run() {
    // reduce priority below other background threads to avoid interfering
    // with other services at boot time.
    android.os.Process.setThreadPriority(
        android.os.Process.THREAD_PRIORITY_BACKGROUND
            + android.os.Process.THREAD_PRIORITY_LESS_FAVORABLE);
    Looper.prepare();

    mLooper = Looper.myLooper();
    mHandler = new ServiceHandler();

    mInitialized = true;

    Looper.loop();
  }
 @Override
 public int onStartCommand(Intent intent, int flags, int startId) {
   super.onStartCommand(intent, flags, startId);
   if (db == null) {
     android.os.Process.setThreadPriority(Process.THREAD_PRIORITY_FOREGROUND);
     dbHelper = new DatabaseHelper(getApplicationContext());
     db = dbHelper.getWritableDatabase();
     dataHelper = DataHelper.getInstance(getApplicationContext());
     appChangeReceiver = new ApplicationChangeReceiver();
     screenStateReceiver = new ScreenStateReceiver();
     remoteLoggingReceiver = new RemoteLoggingReceiver();
     registerReceiver(screenStateReceiver, screenStateReceiver.buildIntentFilter());
     startRemoteLogging();
     startTimeCount();
   }
   return START_STICKY;
 }
Exemple #28
0
    @Override
    public void run() {

      android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_BACKGROUND);

      try {

        CacheRequest request;
        while ((request = requests.take()) != null) {
          processDeletionQueue();
          handleRequest(request);
        }

      } catch (InterruptedException e) {
        throw new RuntimeException(e);
      }
    }
  public void onSurfaceChanged(GL10 gl, int w, int h) {
    if (!setup) {
      Log.i("OF", "initializing app");
      OFAndroid.init();
      OFAndroid.setup(w, h);
      initialized = true;
      setup = true;
      android.os.Process.setThreadPriority(8);
      OFGestureListener.swipe_Min_Distance = (int) (Math.max(w, h) * .1);
      OFGestureListener.swipe_Max_Distance = (int) (Math.max(w, h) * .6);

      /*if(ETC1Util.isETC1Supported()) Log.i("OF","ETC supported");
      else Log.i("OF","ETC not supported");*/
    }
    OFAndroid.resize(w, h);
    this.w = w;
    this.h = h;
  }
    @Override
    protected Result<ReactApplicationContext> doInBackground(ReactContextInitParams... params) {
      // TODO(t11687218): Look over all threading
      // Default priority is Process.THREAD_PRIORITY_BACKGROUND which means we'll be put in a cgroup
      // that only has access to a small fraction of CPU time. The priority will be reset after
      // this task finishes:
      // https://android.googlesource.com/platform/frameworks/base/+/d630f105e8bc0021541aacb4dc6498a49048ecea/core/java/android/os/AsyncTask.java#256
      Process.setThreadPriority(Process.THREAD_PRIORITY_DEFAULT);

      Assertions.assertCondition(params != null && params.length > 0 && params[0] != null);
      try {
        JavaScriptExecutor jsExecutor = params[0].getJsExecutorFactory().create();
        return Result.of(createReactContext(jsExecutor, params[0].getJsBundleLoader()));
      } catch (Exception e) {
        // Pass exception to onPostExecute() so it can be handled on the main thread
        return Result.of(e);
      }
    }