Java Code Examples for android.os.Process

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project AmDroid, under directory /AmDroid/src/main/java/com/jaeckel/amenoid/cwac/task/.

Source file: AsyncTaskEx.java

  19 
vote

/** 
 * Creates a new asynchronous task. This constructor must be invoked on the UI thread.
 */
public AsyncTaskEx(){
  mWorker=new WorkerRunnable<Params,Result>(){
    public Result call() throws Exception {
      Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
      return doInBackground(mParams);
    }
  }
;
  mFuture=new FutureTask<Result>(mWorker){
    @Override protected void done(){
      Message message;
      Result result=null;
      try {
        result=get();
      }
 catch (      InterruptedException e) {
        com.jaeckel.amenoid.util.Log.w(LOG_TAG,e);
      }
catch (      ExecutionException e) {
        throw new RuntimeException("An error occured while executing doInBackground()",e.getCause());
      }
catch (      CancellationException e) {
        message=sHandler.obtainMessage(MESSAGE_POST_CANCEL,new AsyncTaskExResult<Result>(AsyncTaskEx.this,(Result[])null));
        message.sendToTarget();
        return;
      }
catch (      Throwable t) {
        throw new RuntimeException("An error occured while executing " + "doInBackground()",t);
      }
      message=sHandler.obtainMessage(MESSAGE_POST_RESULT,new AsyncTaskExResult<Result>(AsyncTaskEx.this,result));
      message.sendToTarget();
    }
  }
;
}
 

Example 2

From project android-database-sqlcipher, under directory /src/net/sqlcipher/database/.

Source file: SQLiteCursor.java

  19 
vote

public void run(){
  CursorWindow cw=mWindow;
  Process.setThreadPriority(Process.myTid(),Process.THREAD_PRIORITY_BACKGROUND);
  while (true) {
    mLock.lock();
    if (mCursorState != mThreadState) {
      mLock.unlock();
      break;
    }
    try {
      int count=mQuery.fillWindow(cw,mMaxRead,mCount);
      if (count != 0) {
        if (count == NO_COUNT) {
          mCount+=mMaxRead;
          sendMessage();
        }
 else {
          mCount=count;
          sendMessage();
          break;
        }
      }
 else {
        break;
      }
    }
 catch (    Exception e) {
      break;
    }
 finally {
      mLock.unlock();
    }
  }
}
 

Example 3

From project android-service-arch, under directory /ServiceFramework/src/ru/evilduck/framework/service/.

Source file: SFCommandExecutorService.java

  19 
vote

@Override protected void onHandleIntent(Intent intent){
  Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
  String action=intent.getAction();
  if (!TextUtils.isEmpty(action)) {
    ResultReceiver receiver=getReceiver(intent);
    if (TestActionHandler.ACTION_EXAMPLE_ACTION.equals(action)) {
      new TestActionHandler().execute(intent,getApplicationContext(),receiver);
    }
  }
}
 

Example 4

From project android-thaiime, under directory /latinime/src/com/sugree/inputmethod/latin/.

Source file: Utils.java

  19 
vote

private UsabilityStudyLogUtils(){
  mDate=new Date();
  mDateFormat=new SimpleDateFormat("dd MMM HH:mm:ss.SSS");
  HandlerThread handlerThread=new HandlerThread("UsabilityStudyLogUtils logging task",Process.THREAD_PRIORITY_BACKGROUND);
  handlerThread.start();
  mLoggingHandler=new Handler(handlerThread.getLooper());
}
 

Example 5

From project AndroidDevWeekendDub-BookLibrary, under directory /src/org/curiouscreature/android/shelves/provider/.

Source file: BooksUpdater.java

  19 
vote

public void run(){
  Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
  final ImageUtilities.ExpiringBitmap expiring=new ImageUtilities.ExpiringBitmap();
  while (!mStopped) {
    try {
      final String bookId=mQueue.take();
      final Long lastCheck=sLastChecks.get(bookId);
      if (lastCheck != null && (lastCheck + ONE_DAY) >= System.currentTimeMillis()) {
        continue;
      }
      sLastChecks.put(bookId,System.currentTimeMillis());
      final BooksStore.Book book=BooksManager.findBook(mResolver,bookId);
      if (book.getLastModified() == null || book.getImageUrl(BooksStore.ImageSize.TINY) == null) {
        continue;
      }
      if (bookCoverUpdated(book,expiring) && expiring.lastModified != null) {
        ImageUtilities.deleteCachedCover(bookId);
        final Bitmap bitmap=book.loadCover(BooksStore.ImageSize.TINY);
        ImportUtilities.addBookCoverToCache(book,bitmap);
        mValues.put(BooksStore.Book.LAST_MODIFIED,expiring.lastModified.getTimeInMillis());
        mArguments[0]=bookId;
        mResolver.update(BooksStore.Book.CONTENT_URI,mValues,mSelection,mArguments);
      }
      Thread.sleep(1000);
    }
 catch (    InterruptedException e) {
    }
  }
}
 

Example 6

From project android_aosp_packages_apps_Settings, under directory /src/com/android/settings/applications/.

Source file: ApplicationsState.java

  19 
vote

private ApplicationsState(Application app){
  mContext=app;
  mPm=mContext.getPackageManager();
  mThread=new HandlerThread("ApplicationsState.Loader",Process.THREAD_PRIORITY_BACKGROUND);
  mThread.start();
  mBackgroundHandler=new BackgroundHandler(mThread.getLooper());
synchronized (mEntriesMap) {
    try {
      mEntriesMap.wait(1);
    }
 catch (    InterruptedException e) {
    }
  }
}
 

Example 7

From project android_packages_apps_Exchange, under directory /src/com/android/exchange/.

Source file: ExchangeService.java

  19 
vote

static public synchronized EmailClientConnectionManager getClientConnectionManager(){
  if (sClientConnectionManager == null) {
    if (sClientConnectionManagerShutdownCount > MAX_CLIENT_CONNECTION_MANAGER_SHUTDOWNS) {
      alwaysLog("Shutting down process to unblock threads");
      Process.killProcess(Process.myPid());
    }
    HttpParams params=new BasicHttpParams();
    params.setIntParameter(ConnManagerPNames.MAX_TOTAL_CONNECTIONS,25);
    params.setParameter(ConnManagerPNames.MAX_CONNECTIONS_PER_ROUTE,sConnPerRoute);
    sClientConnectionManager=EmailClientConnectionManager.newInstance(params);
  }
  return sClientConnectionManager;
}
 

Example 8

From project android_packages_apps_Gallery, under directory /src/com/android/camera/.

Source file: ImageGetter.java

  19 
vote

public void run(){
  Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
  while (true) {
synchronized (ImageGetter.this) {
      while (mCancel || mDone || mCurrentPosition == -1) {
        if (mDone)         return;
        mIdle=true;
        ImageGetter.this.notify();
        try {
          ImageGetter.this.wait();
        }
 catch (        InterruptedException ex) {
        }
        mIdle=false;
      }
    }
    executeRequest();
synchronized (ImageGetter.this) {
      mCurrentPosition=-1;
    }
  }
}
 

Example 9

From project android_packages_apps_Gallery2, under directory /src/com/android/gallery3d/app/.

Source file: AlbumDataLoader.java

  19 
vote

@Override public void run(){
  Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
  boolean updateComplete=false;
  while (mActive) {
synchronized (this) {
      if (mActive && !mDirty && updateComplete) {
        updateLoading(false);
        Utils.waitWithoutInterrupt(this);
        continue;
      }
    }
    mDirty=false;
    updateLoading(true);
    long version;
synchronized (DataManager.LOCK) {
      version=mSource.reload();
    }
    UpdateInfo info=executeAndWait(new GetUpdateInfo(version));
    updateComplete=info == null;
    if (updateComplete)     continue;
synchronized (DataManager.LOCK) {
      if (info.version != version) {
        info.size=mSource.getMediaItemCount();
        info.version=version;
      }
      if (info.reloadCount > 0) {
        info.items=mSource.getMediaItem(info.reloadStart,info.reloadCount);
      }
    }
    executeAndWait(new UpdateContent(info));
  }
  updateLoading(false);
}
 

Example 10

From project android_packages_apps_Gallery3D, under directory /src/com/cooliris/cache/.

Source file: CacheService.java

  19 
vote

public static final void startNewThumbnailThread(final Context context){
  restartThread(THUMBNAIL_THREAD,"ThumbnailRefresh",new Runnable(){
    public void run(){
      Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
      try {
        Thread.sleep(THUMBNAILER_WAIT_IN_MS);
      }
 catch (      InterruptedException e) {
        return;
      }
      CacheService.buildThumbnails(context);
    }
  }
);
}
 

Example 11

From project android_packages_apps_Nfc, under directory /src/com/android/nfc/.

Source file: NfcService.java

  19 
vote

@Override protected Void doInBackground(Integer... params){
switch (mState) {
case NfcAdapter.STATE_TURNING_OFF:
case NfcAdapter.STATE_TURNING_ON:
    Log.e(TAG,"Processing EnableDisable task " + params[0] + " from bad state "+ mState);
  return null;
}
Process.setThreadPriority(Process.THREAD_PRIORITY_DEFAULT);
switch (params[0].intValue()) {
case TASK_ENABLE:
enableInternal();
break;
case TASK_DISABLE:
disableInternal();
break;
case TASK_BOOT:
Log.d(TAG,"checking on firmware download");
boolean airplaneOverride=mPrefs.getBoolean(PREF_AIRPLANE_OVERRIDE,false);
if (mPrefs.getBoolean(PREF_NFC_ON,NFC_ON_DEFAULT) && (!mIsAirplaneSensitive || !isAirplaneModeOn() || airplaneOverride)) {
Log.d(TAG,"NFC is on. Doing normal stuff");
enableInternal();
}
 else {
Log.d(TAG,"NFC is off.  Checking firmware version");
mDeviceHost.checkFirmware();
}
if (mPrefs.getBoolean(PREF_FIRST_BOOT,true)) {
Log.i(TAG,"First Boot");
mPrefsEditor.putBoolean(PREF_FIRST_BOOT,false);
mPrefsEditor.apply();
executeEeWipe();
}
break;
case TASK_EE_WIPE:
executeEeWipe();
break;
}
Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
return null;
}
 

Example 12

From project android_packages_apps_QuickSearchBox, under directory /src/com/android/quicksearchbox/util/.

Source file: PriorityThreadFactory.java

  19 
vote

public Thread newThread(Runnable r){
  return new Thread(r){
    @Override public void run(){
      Process.setThreadPriority(mPriority);
      super.run();
    }
  }
;
}
 

Example 13

From project android_packages_inputmethods_LatinIME, under directory /java/src/com/android/inputmethod/latin/.

Source file: Utils.java

  19 
vote

private UsabilityStudyLogUtils(){
  mDate=new Date();
  mDateFormat=new SimpleDateFormat("dd MMM HH:mm:ss.SSS");
  HandlerThread handlerThread=new HandlerThread("UsabilityStudyLogUtils logging task",Process.THREAD_PRIORITY_BACKGROUND);
  handlerThread.start();
  mLoggingHandler=new Handler(handlerThread.getLooper());
}
 

Example 14

From project apps-for-android, under directory /AnyCut/src/com/google/android/photostream/.

Source file: UserTask.java

  19 
vote

/** 
 * Creates a new user task. This constructor must be invoked on the UI thread.
 */
public UserTask(){
  mWorker=new WorkerRunnable<Params,Result>(){
    public Result call() throws Exception {
      Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
      return doInBackground(mParams);
    }
  }
;
  mFuture=new FutureTask<Result>(mWorker){
    @Override protected void done(){
      Message message;
      Result result=null;
      try {
        result=get();
      }
 catch (      InterruptedException e) {
        android.util.Log.w(LOG_TAG,e);
      }
catch (      ExecutionException e) {
        throw new RuntimeException("An error occured while executing doInBackground()",e.getCause());
      }
catch (      CancellationException e) {
        message=sHandler.obtainMessage(MESSAGE_POST_CANCEL,new UserTaskResult<Result>(UserTask.this,(Result[])null));
        message.sendToTarget();
        return;
      }
catch (      Throwable t) {
        throw new RuntimeException("An error occured while executing " + "doInBackground()",t);
      }
      message=sHandler.obtainMessage(MESSAGE_POST_RESULT,new UserTaskResult<Result>(UserTask.this,result));
      message.sendToTarget();
    }
  }
;
}
 

Example 15

From project btmidi, under directory /BluetoothMidiPlayer/src/com/noisepages/nettoyeur/midi/player/.

Source file: BluetoothMidiPlayerService.java

  19 
vote

/** 
 * Starts playback.
 */
public void startSong(){
  if (sequencer == null)   return;
  pauseSong();
  if (events == null || !events.hasNext()) {
    resetAllControllers();
    events=sequencer.iterator();
    if (!events.hasNext()) {
      if (receiver != null) {
        receiver.onPlaybackFinished();
        return;
      }
    }
  }
  handlerThread=new HandlerThread(TAG,Process.THREAD_PRIORITY_AUDIO);
  handlerThread.start();
  MidiRunnable midiRunnable=new MidiRunnable(events,handlerThread);
  midiRunnable.scheduleNext();
}
 

Example 16

From project CineShowTime-Android, under directory /Libraries/GreenDroid/src/greendroid/image/.

Source file: ImageLoader.java

  19 
vote

public void run(){
  Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
  final Handler h=mHandler;
  Bitmap bitmap=null;
  Throwable throwable=null;
  h.sendMessage(Message.obtain(h,ON_START));
  try {
    if (TextUtils.isEmpty(mUrl)) {
      throw new Exception("The given URL cannot be null or empty");
    }
    bitmap=BitmapFactory.decodeStream(new URL(mUrl).openStream(),null,(mOptions == null) ? sDefaultOptions : mOptions);
    if (mBitmapProcessor != null && bitmap != null) {
      final Bitmap processedBitmap=mBitmapProcessor.processImage(bitmap);
      if (processedBitmap != null) {
        bitmap=processedBitmap;
      }
    }
  }
 catch (  Exception e) {
    if (Config.GD_ERROR_LOGS_ENABLED) {
      Log.e(LOG_TAG,"Error while fetching image",e);
    }
    throwable=e;
  }
  if (bitmap == null) {
    if (throwable == null) {
      throwable=new Exception("Skia image decoding failed");
    }
    h.sendMessage(Message.obtain(h,ON_FAIL,throwable));
  }
 else {
    h.sendMessage(Message.obtain(h,ON_END,bitmap));
  }
}
 

Example 17

From project cornerstone, under directory /frameworks/base/core/java/android/view/.

Source file: ViewRootImpl.java

  19 
vote

public void findAccessibilityNodeInfoByAccessibilityIdClientThread(int accessibilityId,int interactionId,IAccessibilityInteractionConnectionCallback callback,int interrogatingPid,long interrogatingTid){
  Message message=Message.obtain();
  message.what=DO_FIND_ACCESSIBLITY_NODE_INFO_BY_ACCESSIBILITY_ID;
  message.arg1=accessibilityId;
  message.arg2=interactionId;
  message.obj=callback;
  if (interrogatingPid == Process.myPid() && interrogatingTid == Looper.getMainLooper().getThread().getId()) {
    message.setTarget(ViewRootImpl.this);
    AccessibilityInteractionClient.getInstance().setSameThreadMessage(message);
  }
 else {
    sendMessage(message);
  }
}
 

Example 18

From project creamed_glacier_app_settings, under directory /src/com/android/settings/applications/.

Source file: ApplicationsState.java

  19 
vote

private ApplicationsState(Application app){
  mContext=app;
  mPm=mContext.getPackageManager();
  mThread=new HandlerThread("ApplicationsState.Loader",Process.THREAD_PRIORITY_BACKGROUND);
  mThread.start();
  mBackgroundHandler=new BackgroundHandler(mThread.getLooper());
synchronized (mEntriesMap) {
    try {
      mEntriesMap.wait(1);
    }
 catch (    InterruptedException e) {
    }
  }
}
 

Example 19

From project dungbeetle, under directory /src/edu/stanford/mobisocial/dungbeetle/.

Source file: SettingsActivity.java

  19 
vote

@Override protected Exception doInBackground(Void... params){
  try {
    helper_.getReadableDatabase().close();
    File data=Environment.getDataDirectory();
    String extStorageDirectory=Environment.getExternalStorageDirectory().toString() + "/MusubiBackup/";
    String dbPath=extStorageDirectory + DBHelper.DB_NAME;
    helper_.close();
    data=Environment.getDataDirectory();
    File newDb=new File(dbPath);
    File oldDb=new File(data,helper_.getDatabasePath());
    if (!newDb.exists()) {
      throw new RuntimeException("Backup database not found");
    }
    InputStream in=new FileInputStream(newDb);
    OutputStream out=new FileOutputStream(oldDb);
    long file_size=newDb.length();
    byte[] buf=new byte[65536];
    int len;
    long so_far=0;
    while ((len=in.read(buf)) > 0) {
      out.write(buf,0,len);
      so_far+=len;
      publishProgress((int)(100 * so_far / (file_size + 1)));
    }
    in.close();
    out.close();
    helper_.getWritableDatabase().close();
    helper_.close();
    Process.killProcess(Process.myPid());
    return null;
  }
 catch (  Exception e) {
    Log.e(TAG,"Failure restoring from SD card",e);
    return e;
  }
}
 

Example 20

From project examples_2, under directory /LeakingActivity/src/com/inazaruk/leak/.

Source file: LeakingActivity.java

  19 
vote

@Override public void run(){
synchronized (LeakingActivity.class) {
    sThreads++;
  }
  int timeout=30;
  try {
    for (int i=timeout; i > 0; i--) {
synchronized (LeakingActivity.class) {
        sThreadTimeouts.put(Process.myTid(),i);
      }
      Thread.sleep(1000);
    }
  }
 catch (  InterruptedException e) {
  }
synchronized (LeakingActivity.class) {
    sThreadTimeouts.remove(Process.myTid());
    sThreads--;
  }
}
 

Example 21

From project FBReaderJ, under directory /src/org/geometerplus/android/fbreader/library/.

Source file: KillerCallback.java

  19 
vote

@Override public void onReceive(Context context,Intent intent){
  if (LibraryActivity.ourToBeKilled) {
    System.err.println("kill");
    Process.killProcess(Process.myPid());
  }
}
 

Example 22

From project framework_base_policy, under directory /src/com/android/internal/policy/impl/.

Source file: PhoneWindowManager.java

  19 
vote

public void run(){
  try {
    performHapticFeedbackLw(null,HapticFeedbackConstants.LONG_PRESS,false);
    IActivityManager mgr=ActivityManagerNative.getDefault();
    List<RunningAppProcessInfo> apps=mgr.getRunningAppProcesses();
    for (    RunningAppProcessInfo appInfo : apps) {
      int uid=appInfo.uid;
      if (uid >= Process.FIRST_APPLICATION_UID && uid <= Process.LAST_APPLICATION_UID && appInfo.importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
        Toast.makeText(mContext,R.string.app_killed_message,Toast.LENGTH_SHORT).show();
        if (appInfo.pkgList != null && (apps.size() > 0)) {
          mgr.forceStopPackage(appInfo.pkgList[0]);
        }
 else {
          Process.killProcess(appInfo.pid);
        }
        break;
      }
    }
  }
 catch (  RemoteException remoteException) {
  }
}
 

Example 23

From project GreenDroidQABar, under directory /src/greendroid/image/.

Source file: ImageLoader.java

  19 
vote

public void run(){
  Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
  final Handler h=mHandler;
  Bitmap bitmap=null;
  Throwable throwable=null;
  h.sendMessage(Message.obtain(h,ON_START));
  try {
    if (TextUtils.isEmpty(mUrl)) {
      throw new Exception("The given URL cannot be null or empty");
    }
    bitmap=BitmapFactory.decodeStream(new URL(mUrl).openStream(),null,(mOptions == null) ? sDefaultOptions : mOptions);
    if (mBitmapProcessor != null && bitmap != null) {
      final Bitmap processedBitmap=mBitmapProcessor.processImage(bitmap);
      if (processedBitmap != null) {
        bitmap=processedBitmap;
      }
    }
  }
 catch (  Exception e) {
    if (Config.GD_ERROR_LOGS_ENABLED) {
      Log.e(LOG_TAG,"Error while fetching image",e);
    }
    throwable=e;
  }
  if (bitmap == null) {
    if (throwable == null) {
      throwable=new Exception("Skia image decoding failed");
    }
    h.sendMessage(Message.obtain(h,ON_FAIL,throwable));
  }
 else {
    h.sendMessage(Message.obtain(h,ON_END,bitmap));
  }
}
 

Example 24

From project Hax-Launcher, under directory /src/com/t3hh4xx0r/haxlauncher/.

Source file: AppsCustomizePagedView.java

  19 
vote

protected void snapToPage(int whichPage,int delta,int duration){
  super.snapToPage(whichPage,delta,duration);
  updateCurrentTab(whichPage);
  Iterator<AppsCustomizeAsyncTask> iter=mRunningTasks.iterator();
  while (iter.hasNext()) {
    AppsCustomizeAsyncTask task=(AppsCustomizeAsyncTask)iter.next();
    int pageIndex=task.page + mNumAppsPages;
    if ((mNextPage > mCurrentPage && pageIndex >= mCurrentPage) || (mNextPage < mCurrentPage && pageIndex <= mCurrentPage)) {
      task.setThreadPriority(getThreadPriorityForPage(pageIndex));
    }
 else {
      task.setThreadPriority(Process.THREAD_PRIORITY_LOWEST);
    }
  }
}
 

Example 25

From project HeLauncher, under directory /src/com/handlerexploit/launcher_reloaded/.

Source file: LauncherModel.java

  19 
vote

public void run(){
  if (DEBUG_LOADERS)   d(LOG_TAG,"  ----> running applications loader (" + mId + ")");
  android.os.Process.setThreadPriority(mIsLaunching ? Process.THREAD_PRIORITY_DEFAULT : Process.THREAD_PRIORITY_BACKGROUND);
  final Intent mainIntent=new Intent(Intent.ACTION_MAIN,null);
  mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
  final Launcher launcher=mLauncher.get();
  final PackageManager manager=launcher.getPackageManager();
  final List<ResolveInfo> apps=manager.queryIntentActivities(mainIntent,0);
  if (apps != null && !mStopped) {
    final int count=apps.size();
    final ApplicationsAdapter applicationList=mApplicationsAdapter;
    ChangeNotifier action=new ChangeNotifier(applicationList,true);
    final HashMap<ComponentName,ApplicationInfo> appInfoCache=mAppInfoCache;
    for (int i=0; i < count && !mStopped; i++) {
      ResolveInfo info=apps.get(i);
      ApplicationInfo application=makeAndCacheApplicationInfo(manager,appInfoCache,info,launcher);
      if (action.add(application) && !mStopped) {
        launcher.runOnUiThread(action);
        action=new ChangeNotifier(applicationList,false);
      }
    }
    launcher.runOnUiThread(action);
  }
synchronized (LauncherModel.this) {
    if (!mStopped) {
      mApplicationsLoaded=true;
    }
 else {
      if (DEBUG_LOADERS)       d(LOG_TAG,"  ----> applications loader stopped (" + mId + ")");
    }
  }
  mRunning=false;
}
 

Example 26

From project ICS_LatinIME_QHD, under directory /java/src/com/android/inputmethod/latin/.

Source file: Utils.java

  19 
vote

private UsabilityStudyLogUtils(){
  mDate=new Date();
  mDateFormat=new SimpleDateFormat("dd MMM HH:mm:ss.SSS");
  HandlerThread handlerThread=new HandlerThread("UsabilityStudyLogUtils logging task",Process.THREAD_PRIORITY_BACKGROUND);
  handlerThread.start();
  mLoggingHandler=new Handler(handlerThread.getLooper());
}
 

Example 27

From project k-9, under directory /src/com/fsck/k9/controller/.

Source file: MessagingController.java

  19 
vote

@Override public void run(){
  Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
  while (true) {
    String commandDescription=null;
    try {
      final Command command=mCommands.take();
      if (command != null) {
        commandDescription=command.description;
        if (K9.DEBUG)         Log.i(K9.LOG_TAG,"Running " + (command.isForeground ? "Foreground" : "Background") + " command '"+ command.description+ "', seq = "+ command.sequence);
        mBusy=true;
        try {
          command.runnable.run();
        }
 catch (        UnavailableAccountException e) {
          new Thread(){
            @Override public void run(){
              try {
                sleep(30 * 1000);
                mCommands.put(command);
              }
 catch (              InterruptedException e) {
                Log.e(K9.LOG_TAG,"interrupted while putting a pending command for" + " an unavailable account back into the queue." + " THIS SHOULD NEVER HAPPEN.");
              }
            }
          }
.start();
        }
        if (K9.DEBUG)         Log.i(K9.LOG_TAG,(command.isForeground ? "Foreground" : "Background") + " Command '" + command.description+ "' completed");
        for (        MessagingListener l : getListeners(command.listener)) {
          l.controllerCommandCompleted(!mCommands.isEmpty());
        }
      }
    }
 catch (    Exception e) {
      Log.e(K9.LOG_TAG,"Error running command '" + commandDescription + "'",e);
    }
    mBusy=false;
  }
}
 

Example 28

From project K6nele, under directory /app/src/ee/ioc/phon/android/speak/.

Source file: RecognizerIntentService.java

  19 
vote

/** 
 * <p>Starting chunk sending in a separate thread so that slow internet would not block the UI.</p> TODO
 */
private void startChunkSending(final int interval,int delay,final boolean consumeAll){
  mChunkCount=0;
  HandlerThread thread=new HandlerThread("SendHandlerThread",Process.THREAD_PRIORITY_BACKGROUND);
  thread.start();
  mSendLooper=thread.getLooper();
  mSendHandler=new Handler(mSendLooper);
  mSendTask=new Runnable(){
    public void run(){
      if (mRecorder != null && mRecorder.getState() == RawAudioRecorder.State.RECORDING) {
        try {
          sendChunk(mRecorder.consumeRecording(),consumeAll);
        }
 catch (        IOException e) {
          processError(RecognizerIntent.RESULT_NETWORK_ERROR,e);
          return;
        }
        if (consumeAll == false) {
          mSendHandler.postDelayed(this,interval);
        }
      }
    }
  }
;
  mSendHandler.postDelayed(mSendTask,delay);
}
 

Example 29

From project lastfm-android, under directory /app/src/fm/last/android/utils/.

Source file: UserTask.java

  19 
vote

/** 
 * Creates a new user task. This constructor must be invoked on the UI thread.
 */
public UserTask(){
  mWorker=new WorkerRunnable<Params,Result>(){
    public Result call() throws Exception {
      Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
      return doInBackground(mParams);
    }
  }
;
  mFuture=new FutureTask<Result>(mWorker){
    @SuppressWarnings("unchecked") @Override protected void done(){
      Message message;
      Result result=null;
      try {
        result=get();
      }
 catch (      InterruptedException e) {
        android.util.Log.w(LOG_TAG,e);
      }
catch (      ExecutionException e) {
        throw new RuntimeException("An error occured while executing doInBackground()",e.getCause());
      }
catch (      CancellationException e) {
        message=sHandler.obtainMessage(MESSAGE_POST_CANCEL,new UserTaskResult<Result>(UserTask.this,(Result[])null));
        message.sendToTarget();
        return;
      }
catch (      Throwable t) {
        throw new RuntimeException("An error occured while executing " + "doInBackground()",t);
      }
      message=sHandler.obtainMessage(MESSAGE_POST_RESULT,new UserTaskResult<Result>(UserTask.this,result));
      message.sendToTarget();
    }
  }
;
}
 

Example 30

From project liquidroid, under directory /src/liqui/droid/util/.

Source file: AsyncTask.java

  19 
vote

/** 
 * Creates a new asynchronous task. This constructor must be invoked on the UI thread.
 */
public AsyncTask(){
  mWorker=new WorkerRunnable<Params,Result>(){
    public Result call() throws Exception {
      mTaskInvoked.set(true);
      Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
      return postResult(doInBackground(mParams));
    }
  }
;
  mFuture=new FutureTask<Result>(mWorker){
    @Override protected void done(){
      try {
        final Result result=get();
        postResultIfNotInvoked(result);
      }
 catch (      InterruptedException e) {
        android.util.Log.w(LOG_TAG,e);
      }
catch (      ExecutionException e) {
        throw new RuntimeException("An error occured while executing doInBackground()",e.getCause());
      }
catch (      CancellationException e) {
        postResultIfNotInvoked(null);
      }
catch (      Throwable t) {
        throw new RuntimeException("An error occured while executing " + "doInBackground()",t);
      }
    }
  }
;
}
 

Example 31

From project maven-android-plugin-samples, under directory /apidemos-android-10/application/src/main/java/com/example/android/apis/app/.

Source file: RemoteService.java

  19 
vote

public void onClick(View v){
  if (mSecondaryService != null) {
    try {
      int pid=mSecondaryService.getPid();
      Process.killProcess(pid);
      mCallbackText.setText("Killed service process.");
    }
 catch (    RemoteException ex) {
      Toast.makeText(Binding.this,R.string.remote_call_failed,Toast.LENGTH_SHORT).show();
    }
  }
}
 

Example 32

From project OAK, under directory /oak-library/src/main/java/oak/.

Source file: OAKImageLoader.java

  19 
vote

@Override public void run(){
  Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
  if (handler == null) {
    if (!imageCache.containsKey(this.printedUrl)) {
      downloadImage(true);
    }
    return;
  }
  Bitmap bitmap=imageCache.getBitmap(this.printedUrl);
  if (bitmap == null) {
    bitmap=downloadImage(false);
  }
  notifyImageLoaded(this.printedUrl,bitmap);
}
 

Example 33

From project packages_apps_Calendar, under directory /src/com/android/calendar/alerts/.

Source file: AlertService.java

  19 
vote

@Override public void onCreate(){
  HandlerThread thread=new HandlerThread("AlertService",Process.THREAD_PRIORITY_BACKGROUND);
  thread.start();
  mServiceLooper=thread.getLooper();
  mServiceHandler=new ServiceHandler(mServiceLooper);
}
 

Example 34

From project packages_apps_Camera_1, under directory /tests/src/com/android/camera/functional/.

Source file: CameraTest.java

  19 
vote

@LargeTest public void testVideoCaptureIntentFdLeak() throws Exception {
  Intent intent=new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
  intent.setClass(getInstrumentation().getTargetContext(),VideoCamera.class);
  intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  intent.putExtra(MediaStore.EXTRA_OUTPUT,Uri.parse("file://" + Environment.getExternalStorageDirectory().toString() + "test_fd_leak.3gp"));
  getInstrumentation().startActivitySync(intent).finish();
  for (  File f : new File("/proc/" + Process.myPid() + "/fd").listFiles()) {
    assertEquals(-1,f.getCanonicalPath().indexOf("test_fd_leak.3gp"));
  }
}
 

Example 35

From project packages_apps_Camera_2, under directory /tests/src/com/android/camera/functional/.

Source file: CameraTest.java

  19 
vote

@LargeTest public void testVideoCaptureIntentFdLeak() throws Exception {
  Intent intent=new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
  intent.setClass(getInstrumentation().getTargetContext(),VideoCamera.class);
  intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  intent.putExtra(MediaStore.EXTRA_OUTPUT,Uri.parse("file://" + Environment.getExternalStorageDirectory().toString() + "test_fd_leak.3gp"));
  getInstrumentation().startActivitySync(intent).finish();
  for (  File f : new File("/proc/" + Process.myPid() + "/fd").listFiles()) {
    assertEquals(-1,f.getCanonicalPath().indexOf("test_fd_leak.3gp"));
  }
}
 

Example 36

From project platform_frameworks_support, under directory /v4/java/android/support/v4/content/.

Source file: ModernAsyncTask.java

  19 
vote

/** 
 * Creates a new asynchronous task. This constructor must be invoked on the UI thread.
 */
public ModernAsyncTask(){
  mWorker=new WorkerRunnable<Params,Result>(){
    public Result call() throws Exception {
      mTaskInvoked.set(true);
      Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
      return postResult(doInBackground(mParams));
    }
  }
;
  mFuture=new FutureTask<Result>(mWorker){
    @Override protected void done(){
      try {
        final Result result=get();
        postResultIfNotInvoked(result);
      }
 catch (      InterruptedException e) {
        android.util.Log.w(LOG_TAG,e);
      }
catch (      ExecutionException e) {
        throw new RuntimeException("An error occured while executing doInBackground()",e.getCause());
      }
catch (      CancellationException e) {
        postResultIfNotInvoked(null);
      }
catch (      Throwable t) {
        throw new RuntimeException("An error occured while executing " + "doInBackground()",t);
      }
    }
  }
;
}
 

Example 37

From project platform_packages_apps_browser, under directory /src/com/android/browser/.

Source file: Performance.java

  19 
vote

static void onPageStarted(){
  mStart=SystemClock.uptimeMillis();
  mProcessStart=Process.getElapsedCpuTime();
  long[] sysCpu=new long[7];
  if (Process.readProcFile("/proc/stat",SYSTEM_CPU_FORMAT,null,sysCpu,null)) {
    mUserStart=sysCpu[0] + sysCpu[1];
    mSystemStart=sysCpu[2];
    mIdleStart=sysCpu[3];
    mIrqStart=sysCpu[4] + sysCpu[5] + sysCpu[6];
  }
  mUiStart=SystemClock.currentThreadTimeMillis();
}
 

Example 38

From project platform_packages_apps_calendar, under directory /src/com/android/calendar/alerts/.

Source file: AlertService.java

  19 
vote

@Override public void onCreate(){
  HandlerThread thread=new HandlerThread("AlertService",Process.THREAD_PRIORITY_BACKGROUND);
  thread.start();
  mServiceLooper=thread.getLooper();
  mServiceHandler=new ServiceHandler(mServiceLooper);
}
 

Example 39

From project platform_packages_apps_camera, under directory /tests/src/com/android/camera/functional/.

Source file: CameraTest.java

  19 
vote

@LargeTest public void testVideoCaptureIntentFdLeak() throws Exception {
  Intent intent=new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
  intent.setClass(getInstrumentation().getTargetContext(),VideoCamera.class);
  intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  intent.putExtra(MediaStore.EXTRA_OUTPUT,Uri.parse("file://" + Environment.getExternalStorageDirectory().toString() + "test_fd_leak.3gp"));
  getInstrumentation().startActivitySync(intent).finish();
  for (  File f : new File("/proc/" + Process.myPid() + "/fd").listFiles()) {
    assertEquals(-1,f.getCanonicalPath().indexOf("test_fd_leak.3gp"));
  }
}
 

Example 40

From project platform_packages_apps_contacts, under directory /src/com/android/contacts/editor/.

Source file: AggregationSuggestionEngine.java

  19 
vote

public AggregationSuggestionEngine(Context context){
  super("AggregationSuggestions",Process.THREAD_PRIORITY_BACKGROUND);
  mContext=context.getApplicationContext();
  mMainHandler=new Handler(){
    @Override public void handleMessage(    Message msg){
      AggregationSuggestionEngine.this.deliverNotification((Cursor)msg.obj);
    }
  }
;
}
 

Example 41

From project platform_packages_apps_Gallery, under directory /src/com/android/camera/.

Source file: ImageGetter.java

  19 
vote

public void run(){
  Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
  while (true) {
synchronized (ImageGetter.this) {
      while (mCancel || mDone || mCurrentPosition == -1) {
        if (mDone)         return;
        mIdle=true;
        ImageGetter.this.notify();
        try {
          ImageGetter.this.wait();
        }
 catch (        InterruptedException ex) {
        }
        mIdle=false;
      }
    }
    executeRequest();
synchronized (ImageGetter.this) {
      mCurrentPosition=-1;
    }
  }
}
 

Example 42

From project platform_packages_apps_Gallery2_1, under directory /src/com/android/gallery3d/ui/.

Source file: GLRootView.java

  19 
vote

/** 
 * Called when the OpenGL surface is recreated without destroying the context.
 */
@Override public void onSurfaceChanged(GL10 gl1,int width,int height){
  Log.i(TAG,"onSurfaceChanged: " + width + "x"+ height+ ", gl10: "+ gl1.toString());
  Process.setThreadPriority(Process.THREAD_PRIORITY_DISPLAY);
  GalleryUtils.setRenderThread();
  GL11 gl=(GL11)gl1;
  Utils.assertTrue(mGL == gl);
  mCanvas.setSize(width,height);
  mClipRect.set(0,0,width,height);
  mClipRetryCount=2;
}
 

Example 43

From project platform_packages_apps_launcher, under directory /src/com/android/launcher/.

Source file: LauncherModel.java

  19 
vote

public void run(){
  if (DEBUG_LOADERS)   d(LOG_TAG,"  ----> running applications loader (" + mId + ")");
  android.os.Process.setThreadPriority(mIsLaunching ? Process.THREAD_PRIORITY_DEFAULT : Process.THREAD_PRIORITY_BACKGROUND);
  final Intent mainIntent=new Intent(Intent.ACTION_MAIN,null);
  mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
  final Launcher launcher=mLauncher.get();
  final PackageManager manager=launcher.getPackageManager();
  final List<ResolveInfo> apps=manager.queryIntentActivities(mainIntent,0);
  if (apps != null && !mStopped) {
    final int count=apps.size();
    final ApplicationsAdapter applicationList=mApplicationsAdapter;
    ChangeNotifier action=new ChangeNotifier(applicationList,true);
    final HashMap<ComponentName,ApplicationInfo> appInfoCache=mAppInfoCache;
    for (int i=0; i < count && !mStopped; i++) {
      ResolveInfo info=apps.get(i);
      ApplicationInfo application=makeAndCacheApplicationInfo(manager,appInfoCache,info,launcher);
      if (action.add(application) && !mStopped) {
        launcher.runOnUiThread(action);
        action=new ChangeNotifier(applicationList,false);
      }
    }
    launcher.runOnUiThread(action);
  }
  if (!mStopped) {
    mApplicationsLoaded=true;
  }
 else {
    if (DEBUG_LOADERS)     d(LOG_TAG,"  ----> applications loader stopped (" + mId + ")");
  }
  mRunning=false;
}
 

Example 44

From project platform_packages_apps_mms, under directory /src/com/android/mms/transaction/.

Source file: SmsReceiverService.java

  19 
vote

@Override public void onCreate(){
  HandlerThread thread=new HandlerThread(TAG,Process.THREAD_PRIORITY_BACKGROUND);
  thread.start();
  mServiceLooper=thread.getLooper();
  mServiceHandler=new ServiceHandler(mServiceLooper);
}
 

Example 45

From project platform_packages_apps_settings, under directory /src/com/android/settings/applications/.

Source file: ApplicationsState.java

  19 
vote

private ApplicationsState(Application app){
  mContext=app;
  mPm=mContext.getPackageManager();
  mThread=new HandlerThread("ApplicationsState.Loader",Process.THREAD_PRIORITY_BACKGROUND);
  mThread.start();
  mBackgroundHandler=new BackgroundHandler(mThread.getLooper());
synchronized (mEntriesMap) {
    try {
      mEntriesMap.wait(1);
    }
 catch (    InterruptedException e) {
    }
  }
}
 

Example 46

From project platform_packages_providers_calendarprovider, under directory /src/com/android/providers/calendar/.

Source file: CalendarProvider2.java

  19 
vote

@Override public void run(){
  Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
  verifyAccounts();
  try {
    doUpdateTimezoneDependentFields();
  }
 catch (  IllegalStateException e) {
  }
}
 

Example 47

From project platform_packages_providers_contactsprovider, under directory /src/com/android/providers/contacts/.

Source file: ContactsProvider2.java

  19 
vote

private boolean initialize(){
  StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectAll().penaltyLog().build());
  mFastScrollingIndexCache=new FastScrollingIndexCache(getContext());
  mContactsHelper=getDatabaseHelper(getContext());
  mDbHelper.set(mContactsHelper);
  setDbHelperToSerializeOn(mContactsHelper,CONTACTS_DB_TAG);
  mContactDirectoryManager=new ContactDirectoryManager(this);
  mGlobalSearchSupport=new GlobalSearchSupport(this);
  mReadAccessLatch=new CountDownLatch(1);
  mWriteAccessLatch=new CountDownLatch(1);
  mBackgroundThread=new HandlerThread("ContactsProviderWorker",Process.THREAD_PRIORITY_BACKGROUND);
  mBackgroundThread.start();
  mBackgroundHandler=new Handler(mBackgroundThread.getLooper()){
    @Override public void handleMessage(    Message msg){
      performBackgroundTask(msg.what,msg.obj);
    }
  }
;
  mProfileProvider=getProfileProvider();
  mProfileProvider.setDbHelperToSerializeOn(mContactsHelper,CONTACTS_DB_TAG);
  ProviderInfo profileInfo=new ProviderInfo();
  profileInfo.readPermission="android.permission.READ_PROFILE";
  profileInfo.writePermission="android.permission.WRITE_PROFILE";
  mProfileProvider.attachInfo(getContext(),profileInfo);
  mProfileHelper=mProfileProvider.getDatabaseHelper(getContext());
  mPreAuthorizedUriDuration=android.provider.Settings.Secure.getLong(getContext().getContentResolver(),android.provider.Settings.Secure.CONTACTS_PREAUTH_URI_EXPIRATION,DEFAULT_PREAUTHORIZED_URI_EXPIRATION);
  scheduleBackgroundTask(BACKGROUND_TASK_INITIALIZE);
  scheduleBackgroundTask(BACKGROUND_TASK_UPDATE_ACCOUNTS);
  scheduleBackgroundTask(BACKGROUND_TASK_UPDATE_LOCALE);
  scheduleBackgroundTask(BACKGROUND_TASK_UPGRADE_AGGREGATION_ALGORITHM);
  scheduleBackgroundTask(BACKGROUND_TASK_UPDATE_SEARCH_INDEX);
  scheduleBackgroundTask(BACKGROUND_TASK_UPDATE_PROVIDER_STATUS);
  scheduleBackgroundTask(BACKGROUND_TASK_OPEN_WRITE_ACCESS);
  scheduleBackgroundTask(BACKGROUND_TASK_CLEANUP_PHOTOS);
  return true;
}
 

Example 48

From project platform_packages_providers_downloadprovider, under directory /src/com/android/providers/downloads/.

Source file: DownloadProvider.java

  19 
vote

/** 
 * Initializes the content provider when it is created.
 */
@Override public boolean onCreate(){
  if (mSystemFacade == null) {
    mSystemFacade=new RealSystemFacade(getContext());
  }
  mOpenHelper=new DatabaseHelper(getContext());
  mSystemUid=Process.SYSTEM_UID;
  ApplicationInfo appInfo=null;
  try {
    appInfo=getContext().getPackageManager().getApplicationInfo("com.android.defcontainer",0);
  }
 catch (  NameNotFoundException e) {
    e.printStackTrace();
  }
  if (appInfo != null) {
    mDefContainerUid=appInfo.uid;
  }
  Context context=getContext();
  context.startService(new Intent(context,DownloadService.class));
  mDownloadsDataDir=StorageManager.getInstance(getContext()).getDownloadDataDirectory();
  return true;
}
 

Example 49

From project PowerTutor, under directory /src/edu/umich/PowerTutor/util/.

Source file: SystemInfo.java

  19 
vote

@SuppressWarnings("unchecked") private SystemInfo(){
  try {
    fieldUid=ActivityManager.RunningAppProcessInfo.class.getField("uid");
  }
 catch (  NoSuchFieldException e) {
  }
  try {
    methodGetUidForPid=Process.class.getMethod("getUidForPid",int.class);
  }
 catch (  NoSuchMethodException e) {
    Log.w(TAG,"Could not access getUidForPid method");
  }
  try {
    methodGetPids=Process.class.getMethod("getPids",String.class,int[].class);
  }
 catch (  NoSuchMethodException e) {
    Log.w(TAG,"Could not access getPids method");
  }
  try {
    methodReadProcFile=Process.class.getMethod("readProcFile",String.class,int[].class,String[].class,long[].class,float[].class);
  }
 catch (  NoSuchMethodException e) {
    Log.w(TAG,"Could not access readProcFile method");
  }
  try {
    Class classSystemProperties=Class.forName("android.os.SystemProperties");
    methodGetProperty=classSystemProperties.getMethod("get",String.class);
  }
 catch (  NoSuchMethodException e) {
    Log.w(TAG,"Could not access SystemProperties.get");
  }
catch (  ClassNotFoundException e) {
    Log.w(TAG,"Could not find class android.os.SystemProperties");
  }
  readBuf=new long[1];
}
 

Example 50

From project propoid, under directory /propoid-util/src/main/java/propoid/util/service/.

Source file: TaskService.java

  19 
vote

/** 
 * Called by the  {@link ExecutorService}.
 */
@Override public Void call() throws Exception {
  Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
  try {
    task.onExecute();
  }
 catch (  Throwable ex) {
    if (!onTaskFailed(task,ex)) {
      delayed=null;
    }
  }
  deschedule(this);
  if (delayed != null) {
    for (    Task task : delayed) {
      schedule(task);
    }
  }
  return null;
}
 

Example 51

From project RebeLauncher, under directory /src/com/dirtypepper/rebelauncher/.

Source file: LauncherModel.java

  19 
vote

public void run(){
  if (DEBUG_LOADERS)   d(LOG_TAG,"  ----> running applications loader (" + mId + ")");
  android.os.Process.setThreadPriority(mIsLaunching ? Process.THREAD_PRIORITY_DEFAULT : Process.THREAD_PRIORITY_BACKGROUND);
  final Intent mainIntent=new Intent(Intent.ACTION_MAIN,null);
  mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
  final Launcher launcher=mLauncher.get();
  final PackageManager manager=launcher.getPackageManager();
  final List<ResolveInfo> apps=manager.queryIntentActivities(mainIntent,0);
  if (apps != null && !mStopped) {
    final int count=apps.size();
    final ApplicationsAdapter applicationList=mApplicationsAdapter;
    ChangeNotifier action=new ChangeNotifier(applicationList,true);
    final HashMap<ComponentName,ApplicationInfo> appInfoCache=mAppInfoCache;
    for (int i=0; i < count && !mStopped; i++) {
      ResolveInfo info=apps.get(i);
      ApplicationInfo application=makeAndCacheApplicationInfo(manager,appInfoCache,info,launcher);
      if (action.add(application) && !mStopped) {
        launcher.runOnUiThread(action);
        action=new ChangeNotifier(applicationList,false);
      }
    }
    launcher.runOnUiThread(action);
  }
  mApplicationsLoaded=!mStopped;
  if (mStopped) {
    if (DEBUG_LOADERS)     d(LOG_TAG,"  ----> applications loader stopped (" + mId + ")");
  }
  mRunning=false;
}
 

Example 52

From project SanDisk-HQME-SDK, under directory /projects/HqmeCache/project/src/com/hqme/cm/cache/.

Source file: UntenCacheService.java

  19 
vote

public void onServiceConnected(ComponentName className,IBinder service){
  debugLog(sTag,"onServiceConnected: className = " + className);
  sPluginManagerProxy=IStorageManager.Stub.asInterface(service);
  if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
    try {
      debugLog(sTag,"onServiceConnected: registering plugin, myPid = " + Process.myPid());
      int storageId=sPluginManagerProxy.registerPlugin(sUntenCache);
      if (sStorageId != storageId) {
        sStorageId=storageId;
        sProperties.put("VS_STORAGE_ID",Integer.toString(sStorageId));
        doSaveProperties(sMetaFile,sProperties);
      }
    }
 catch (    RemoteException fault) {
      fault.printStackTrace();
      Log.e(sTag,"onServiceConnected: RemoteExpection fault: " + fault);
    }
  }
 else {
    Log.w(sTag,"onServiceConnected: external storage is not mounted");
  }
}
 

Example 53

From project SMSSync, under directory /smssync/src/org/addhen/smssync/services/.

Source file: SmsReceiverService.java

  19 
vote

@Override public void onCreate(){
  HandlerThread thread=new HandlerThread(CLASS_TAG,Process.THREAD_PRIORITY_BACKGROUND);
  thread.start();
  mContext=getApplicationContext();
  processSms=new ProcessSms(mContext);
  Prefs.loadPreferences(mContext);
  mServiceLooper=thread.getLooper();
  mServiceHandler=new ServiceHandler(mServiceLooper);
}
 

Example 54

From project SyncMyPix, under directory /src/com/nloko/android/.

Source file: PhotoCache.java

  19 
vote

public PhotoCache(Context context){
  if (context == null) {
    throw new IllegalArgumentException("context");
  }
  mContext=new WeakReference<Context>(context);
  mPath=context.getExternalCacheDir();
  startWatchingExternalStorage();
  HandlerThread thread=new HandlerThread("PhotoCacheThread",Process.THREAD_PRIORITY_BACKGROUND);
  thread.start();
  mHandler=new AsyncHandler(thread);
}
 

Example 55

From project Ushahidi_Android, under directory /Libraries/abs/src/android/support/v4/content/.

Source file: ModernAsyncTask.java

  19 
vote

/** 
 * Creates a new asynchronous task. This constructor must be invoked on the UI thread.
 */
public ModernAsyncTask(){
  mWorker=new WorkerRunnable<Params,Result>(){
    public Result call() throws Exception {
      mTaskInvoked.set(true);
      Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
      return postResult(doInBackground(mParams));
    }
  }
;
  mFuture=new FutureTask<Result>(mWorker){
    @Override protected void done(){
      try {
        final Result result=get();
        postResultIfNotInvoked(result);
      }
 catch (      InterruptedException e) {
        android.util.Log.w(LOG_TAG,e);
      }
catch (      ExecutionException e) {
        throw new RuntimeException("An error occured while executing doInBackground()",e.getCause());
      }
catch (      CancellationException e) {
        postResultIfNotInvoked(null);
      }
catch (      Throwable t) {
        throw new RuntimeException("An error occured while executing " + "doInBackground()",t);
      }
    }
  }
;
}
 

Example 56

From project vanilla, under directory /src/org/kreed/vanilla/.

Source file: PlaybackActivity.java

  19 
vote

@Override public void onCreate(Bundle state){
  super.onCreate(state);
  PlaybackService.addActivity(this);
  setVolumeControlStream(AudioManager.STREAM_MUSIC);
  HandlerThread thread=new HandlerThread(getClass().getName(),Process.THREAD_PRIORITY_LOWEST);
  thread.start();
  mLooper=thread.getLooper();
  mHandler=new Handler(mLooper,this);
}