Ejemplo n.º 1
1
 public void register(Context context, Looper thread, UserHandle user, boolean externalStorage) {
   if (mRegisteredContext != null) {
     throw new IllegalStateException("Already registered");
   }
   mRegisteredContext = context;
   if (thread == null) {
     synchronized (sLock) {
       if (sBackgroundThread == null) {
         sBackgroundThread =
             new HandlerThread("PackageMonitor", android.os.Process.THREAD_PRIORITY_BACKGROUND);
         sBackgroundThread.start();
         sBackgroundHandler = new Handler(sBackgroundThread.getLooper());
       }
       mRegisteredHandler = sBackgroundHandler;
     }
   } else {
     mRegisteredHandler = new Handler(thread);
   }
   if (user != null) {
     context.registerReceiverAsUser(this, user, sPackageFilt, null, mRegisteredHandler);
     context.registerReceiverAsUser(this, user, sNonDataFilt, null, mRegisteredHandler);
     if (externalStorage) {
       context.registerReceiverAsUser(this, user, sExternalFilt, null, mRegisteredHandler);
     }
   } else {
     context.registerReceiver(this, sPackageFilt, null, mRegisteredHandler);
     context.registerReceiver(this, sNonDataFilt, null, mRegisteredHandler);
     if (externalStorage) {
       context.registerReceiver(this, sExternalFilt, null, mRegisteredHandler);
     }
   }
 }
 private synchronized void ensureHandler() {
   if (mHandler == null) {
     HandlerThread thread = new HandlerThread(TAG, THREAD_PRIORITY_BACKGROUND);
     thread.start();
     mHandler = new Handler(thread.getLooper());
   }
 }
Ejemplo n.º 3
0
  @CalledByNative
  public void startCapture() {
    Log.d(TAG, "startCapture");
    synchronized (mCaptureStateLock) {
      if (mCaptureState != CaptureState.ALLOWED) {
        Log.e(TAG, "startCapture() invoked without user permission.");
        return;
      }
    }
    mMediaProjection = mMediaProjectionManager.getMediaProjection(mResultCode, mResultData);
    if (mMediaProjection == null) {
      Log.e(TAG, "mMediaProjection is null");
      return;
    }
    mMediaProjection.registerCallback(new MediaProjectionCallback(), null);

    mThread = new HandlerThread("ScreenCapture");
    mThread.start();
    mBackgroundHandler = new Handler(mThread.getLooper());

    // On Android M and above, YUV420 is prefered. Some Android L devices will silently
    // fail with YUV420, so keep with RGBA_8888 on L.
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
      mFormat = PixelFormat.RGBA_8888;
    } else {
      mFormat = ImageFormat.YUV_420_888;
    }
    maybeDoRotation();
    createImageReaderWithFormat();
    createVirtualDisplay();

    changeCaptureStateAndNotify(CaptureState.STARTED);
  }
Ejemplo n.º 4
0
  protected Looper getLooper(int type) {
    if (mHandlerThread != null) {
      mHandlerThread.quit();
      mHandlerThread = null;
    }

    int priority;
    switch (type) {
      case THREAD_TYPE_MAIN_THREAD:
        return Looper.getMainLooper();
      case THREAD_TYPE_HIGH_PRIORITY:
        priority = android.os.Process.THREAD_PRIORITY_URGENT_DISPLAY;
        break;
      case THREAD_TYPE_LOW_PRIORITY:
        priority = android.os.Process.THREAD_PRIORITY_LOWEST;
        break;
      case THREAD_TYPE_NORMAL_PRIORITY:
      default:
        priority = android.os.Process.THREAD_PRIORITY_DEFAULT;
        break;
    }
    String threadName = "DFM Handler Thread #" + priority;
    mHandlerThread = new HandlerThread(threadName, priority);
    mHandlerThread.start();
    return mHandlerThread.getLooper();
  }
Ejemplo n.º 5
0
  private static Looper createLooper() {
    HandlerThread thread =
        new HandlerThread("[location handler thread]", Process.THREAD_PRIORITY_BACKGROUND);
    thread.start();

    return thread.getLooper();
  }
  /**
   * Test use SurfaceTextureHelper on a separate thread. A uniform texture frame is created and
   * received on a thread separate from the test thread and returned after disconnect.
   */
  @MediumTest
  public static void testLateReturnFrameOnSeparateThread() throws InterruptedException {
    final HandlerThread thread = new HandlerThread("SurfaceTextureHelperTestThread");
    thread.start();
    final Handler handler = new Handler(thread.getLooper());

    // Create SurfaceTextureHelper and listener.
    final SurfaceTextureHelper surfaceTextureHelper = SurfaceTextureHelper.create(null, handler);
    // Create a mock listener and expect frames to be delivered on |thread|.
    final MockTextureListener listener = new MockTextureListener(thread);
    surfaceTextureHelper.setListener(listener);

    // Create resources for stubbing an OES texture producer. |eglOesBase| has the
    // SurfaceTexture in |surfaceTextureHelper| as the target EGLSurface.
    final EglBase eglOesBase = EglBase.create(null, EglBase.ConfigType.PLAIN);
    eglOesBase.createSurface(surfaceTextureHelper.getSurfaceTexture());
    eglOesBase.makeCurrent();
    // Draw a frame onto the SurfaceTexture.
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
    // swapBuffers() will ultimately trigger onTextureFrameAvailable().
    eglOesBase.swapBuffers();
    eglOesBase.release();

    // Wait for an OES texture to arrive.
    listener.waitForNewFrame();

    surfaceTextureHelper.disconnect(handler);

    surfaceTextureHelper.returnTextureFrame();
  }
  @Override
  public void init(Activity context, String nick) {
    synchronized (sVcLock) {
      if (sVcHandler == null) {
        HandlerThread vcthread = new HandlerThread("LicodeConnectorThread");
        vcthread.start();
        sVcHandler = new Handler(vcthread.getLooper());
      }
    }
    if (context == null) {
      throw new NullPointerException("Failed to initialize LicodeConnector. Activity is required.");
    }
    mActivity = context;
    mState = State.kDisconnected;
    mNick = nick;

    Runnable init =
        new Runnable() {
          @Override
          public void run() {
            if (!sInitializedAndroidGlobals) {
              sInitializedAndroidGlobals = true;
              // newer libjingle versions have options for video and audio
              PeerConnectionFactory.initializeAndroidGlobals(mActivity); // ,
              // true,
              // true);
            }

            if (sFactory == null) {
              sFactory = new PeerConnectionFactory();
            }
          };
        };
    sVcHandler.post(init);
  }
  /** Start the transfer */
  public void start() {
    /* check Bluetooth enable status */
    /*
     * normally it's impossible to reach here if BT is disabled. Just check
     * for safety
     */
    if (!mAdapter.isEnabled()) {
      Log.e(TAG, "Can't start transfer when Bluetooth is disabled for " + mBatch.mId);
      markBatchFailed();
      mBatch.mStatus = Constants.BATCH_STATUS_FAILED;
      return;
    }

    if (mHandlerThread == null) {
      if (V) Log.v(TAG, "Create handler thread for batch " + mBatch.mId);
      mHandlerThread =
          new HandlerThread("BtOpp Transfer Handler", Process.THREAD_PRIORITY_BACKGROUND);
      mHandlerThread.start();
      mSessionHandler = new EventHandler(mHandlerThread.getLooper());

      if (mBatch.mDirection == BluetoothShare.DIRECTION_OUTBOUND) {
        /* for outbound transfer, we do connect first */
        startConnectSession();
      } else if (mBatch.mDirection == BluetoothShare.DIRECTION_INBOUND) {
        /*
         * for inbound transfer, it's already connected, so we start
         * OBEX session directly
         */
        startObexSession();
      }
    }
  }
Ejemplo n.º 9
0
 public SideChannelManager(Context paramContext)
 {
   mContext = paramContext;
   mHandlerThread = new HandlerThread("NotificationManagerCompat");
   mHandlerThread.start();
   mHandler = new Handler(mHandlerThread.getLooper(), this);
 }
Ejemplo n.º 10
0
  /** Initializes the service when it is first created */
  @Override
  public void onCreate() {
    super.onCreate();
    if (Constants.LOGVV) {
      Log.v(Constants.TAG, "Service onCreate");
    }

    if (mSystemFacade == null) {
      mSystemFacade = new RealSystemFacade(this);
    }

    mAlarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    mStorageManager = new StorageManager(this);

    mUpdateThread = new HandlerThread(TAG + "-UpdateThread");
    mUpdateThread.start();
    mUpdateHandler = new Handler(mUpdateThread.getLooper(), mUpdateCallback);

    mScanner = new DownloadScanner(this);

    mNotifier = new DownloadNotifier(this);
    mNotifier.cancelAll();

    mObserver = new DownloadManagerContentObserver();
    getContentResolver()
        .registerContentObserver(Downloads.Impl.ALL_DOWNLOADS_CONTENT_URI, true, mObserver);
  }
Ejemplo n.º 11
0
 /** Private constructor for static class */
 private ContactsAsyncHelper() {
   Log.d(THIS_FILE, "Self creation");
   HandlerThread thread = new HandlerThread("ContactsAsyncWorker");
   thread.start();
   sThreadHandler = new WorkerHandler(thread.getLooper());
   contactsWrapper = ContactsWrapper.getInstance();
 }
  @Override
  public void setPreferredNetworkType(int networkType, Message response) {
    /* Samsung modem implementation does bad things when a datacall is running
     * while switching the preferred networktype.
     */
    HandlerThread handlerThread;
    Looper looper;

    if (NeedReconnect()) {
      if (mSamsungExynos4RILHandler == null) {

        handlerThread = new HandlerThread("mSamsungExynos4RILThread");
        mSamsungExynos4RILThread = handlerThread;

        mSamsungExynos4RILThread.start();

        looper = mSamsungExynos4RILThread.getLooper();
        mSamsungExynos4RILHandler = new ConnectivityHandler(mContext, looper);
      }
      mSamsungExynos4RILHandler.setPreferedNetworkType(networkType, response);
    } else {
      if (mSamsungExynos4RILHandler != null) {
        mSamsungExynos4RILThread = null;
        mSamsungExynos4RILHandler = null;
      }
      sendPreferedNetworktype(networkType, response);
    }
  }
Ejemplo n.º 13
0
  @Override
  public void onCreate() {
    super.onCreate();

    Log.i(TAG, "SenderSvc created");

    // created = true;
    processingStatus = 0;
    app = ((EncrypText) getApplication());
    cryptor = app.getCryptor();
    dbUtils = app.getDbUtils();
    currentConv = "";
    mgr = SmsManager.getDefault();

    /* if(app == null)
    {
        Log.v(TAG, "Error retrieving application instance");
        throw new NullPointerException();
    }*/

    partialConfs = new TreeMap<>();
    confirmTimes = new TreeMap<>();

    HandlerThread worker = new HandlerThread("Sender Worker");
    worker.start();
    handler = new SenderHandler(worker.getLooper(), this);

    created = true;
  }
  /**
   * Se non &egrave; gi&agrave; avvenuto in una chiamata precedente, avvia un thread in background e
   * registra il servizio per ricever&agrave; gli update della posizione.
   *
   * @author Michele Piccirillo <*****@*****.**>
   */
  @Override
  public int onStartCommand(Intent intent, int flags, int startId) {
    super.onStartCommand(intent, flags, startId);

    // Un servizio puo' essere avviato piu' volte.
    // Avviamo il worker thread e ci registriamo per le posizioni solo la prima volta.
    if (worker == null) {
      Log.i("PositionTrackingService", "Service started");
      worker = new HandlerThread("PositionTrackingService", Process.THREAD_PRIORITY_BACKGROUND);
      worker.start();

      locationManager.requestLocationUpdates(
          LocationManager.GPS_PROVIDER,
          Setup.TRACKING_MIN_TIME,
          Setup.TRACKING_MIN_DISTANCE,
          locationListener,
          worker.getLooper());

      locationManager.requestLocationUpdates(
          LocationManager.NETWORK_PROVIDER,
          Setup.TRACKING_MIN_TIME,
          Setup.TRACKING_MIN_DISTANCE,
          locationListener,
          worker.getLooper());
    }

    return START_STICKY;
  }
Ejemplo n.º 15
0
  @Override
  public void onCreate() {
    super.onCreate();
    executorService = Executors.newSingleThreadExecutor();

    handlerThread = new HandlerThread("TabQueueHandlerThread");
    handlerThread.start();
    tabQueueHandler = new Handler(handlerThread.getLooper());

    windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);

    LayoutInflater layoutInflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
    toastLayout = layoutInflater.inflate(R.layout.tab_queue_toast, null);

    final Resources resources = getResources();

    TextView messageView = (TextView) toastLayout.findViewById(R.id.toast_message);
    messageView.setText(resources.getText(R.string.tab_queue_toast_message));

    openNowButton = (Button) toastLayout.findViewById(R.id.toast_button);
    openNowButton.setText(resources.getText(R.string.tab_queue_toast_action));

    toastLayoutParams =
        new WindowManager.LayoutParams(
            WindowManager.LayoutParams.MATCH_PARENT,
            WindowManager.LayoutParams.WRAP_CONTENT,
            WindowManager.LayoutParams.TYPE_PHONE,
            WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
                | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH
                | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
            PixelFormat.TRANSLUCENT);

    toastLayoutParams.gravity = Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL;
  }
Ejemplo n.º 16
0
  @Override
  public void onCreate() {
    super.onCreate();
    Log.i(TAG, "Create");

    HandlerThread thread = new HandlerThread(getString(R.string.app_name));
    thread.start();

    mServiceLooper = thread.getLooper();
    mServiceHandler = new ServiceHandler(mServiceLooper);

    last_roaming = Util.isRoaming(SinkholeService.this);

    // Listen for interactive state changes
    IntentFilter ifInteractive = new IntentFilter();
    ifInteractive.addAction(Intent.ACTION_SCREEN_ON);
    ifInteractive.addAction(Intent.ACTION_SCREEN_OFF);
    registerReceiver(interactiveStateReceiver, ifInteractive);

    // Listen for connectivity updates
    IntentFilter ifConnectivity = new IntentFilter();
    ifConnectivity.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
    registerReceiver(connectivityChangedReceiver, ifConnectivity);

    // Listen for added applications
    IntentFilter ifPackage = new IntentFilter();
    ifPackage.addAction(Intent.ACTION_PACKAGE_ADDED);
    ifPackage.addDataScheme("package");
    registerReceiver(packageAddedReceiver, ifPackage);
  }
 @Override
 protected void setUp() throws Exception {
   super.setUp();
   mContext = getActivity();
   assertNotNull("Unable to get activity", mContext);
   mCameraManager = (CameraManager) mContext.getSystemService(Context.CAMERA_SERVICE);
   assertNotNull("Unable to get CameraManager", mCameraManager);
   mCameraIds = mCameraManager.getCameraIdList();
   assertNotNull("Unable to get camera ids", mCameraIds);
   mHandlerThread = new HandlerThread(TAG);
   mHandlerThread.start();
   mHandler = new Handler(mHandlerThread.getLooper());
   mCameraListener = new BlockingStateCallback();
   Camera2MultiViewCtsActivity activity = (Camera2MultiViewCtsActivity) mContext;
   mTextureView[0] = activity.getTextureView(0);
   mTextureView[1] = activity.getTextureView(1);
   assertNotNull("Unable to get texture view", mTextureView);
   mCameraIdMap = new HashMap<String, Integer>();
   int numCameras = mCameraIds.length;
   mCameraHolders = new CameraHolder[numCameras];
   for (int i = 0; i < numCameras; i++) {
     mCameraHolders[i] = new CameraHolder(mCameraIds[i]);
     mCameraIdMap.put(mCameraIds[i], i);
   }
   mWindowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
 }
Ejemplo n.º 18
0
 /** This method initializes the aysnc screenshot saving logic */
 private void initScreenShotSaver() {
   if (screenShotSaverThread == null || screenShotSaver == null) {
     screenShotSaverThread = new HandlerThread("ScreenShotSaver");
     screenShotSaverThread.start();
     screenShotSaver = new ScreenShotSaver(screenShotSaverThread);
   }
 }
Ejemplo n.º 19
0
  @Override
  public void start() {
    mStorageManager = (StorageManager) mContext.getSystemService(Context.STORAGE_SERVICE);
    final boolean connected = mStorageManager.isUsbMassStorageConnected();
    if (DEBUG)
      Log.d(
          TAG,
          String.format(
              "Startup with UMS connection %s (media state %s)",
              mUmsAvailable, Environment.getExternalStorageState()));

    HandlerThread thr = new HandlerThread("SystemUI StorageNotification");
    thr.start();
    mAsyncEventHandler = new Handler(thr.getLooper());

    if (GN_USB_SUPPORT && isFirstBoot()) {
      setToMtpByDefault();
    }

    mStorageEventlistener = new StorageNotificationEventListener();
    mStorageEventlistener.onUsbMassStorageConnectionChanged(connected);
    mStorageManager.registerListener(mStorageEventlistener);

    IntentFilter filter = new IntentFilter();
    filter.addAction(UsbManager.ACTION_USB_STATE);
    mContext.registerReceiver(mUsbStateReceiver, filter);
  }
Ejemplo n.º 20
0
  /**
   * Constructor creates a StateMachine with its own thread.
   *
   * @param name of the state machine
   */
  protected StateMachine(String name) {
    mSmThread = new HandlerThread(name);
    mSmThread.start();
    Looper looper = mSmThread.getLooper();

    initStateMachine(name, looper);
  }
Ejemplo n.º 21
0
 @Override
 public void onCreate() {
   super.onCreate();
   HandlerThread thread = new HandlerThread("HandlerService");
   thread.start();
   handler = new Handler(thread.getLooper());
 }
Ejemplo n.º 22
0
  public void showWhileExecuting(Runnable runnable) {
    showCalledCount++;
    if (showCalledCount > 1) {
      return;
    }
    show();
    HandlerThread backgroundThread = new HandlerThread("showWhileExecuting");
    backgroundThread.start();
    showWhileExecutingLooper = backgroundThread.getLooper();
    Handler handler = new Handler(showWhileExecutingLooper);
    handler.post(runnable);
    handler.post(
        new Runnable() {

          @Override
          public void run() {
            if (null != dialog && dialog.isShowing()) {
              mainHandler.post(
                  new Runnable() {

                    @Override
                    public void run() {
                      stopAnimation();
                      dialog.cancel();
                    }
                  });
            }
          }
        });
  }
Ejemplo n.º 23
0
 public CoffeeState(SwipeController controller) {
   this.controller = controller;
   this.model = controller.getModel();
   workerThread = new HandlerThread("Unlocked Save Thread");
   workerThread.start();
   workerHandler = new Handler(workerThread.getLooper());
 }
Ejemplo n.º 24
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (mStorageManager == null) {
      mStorageManager = (StorageManager) getSystemService(Context.STORAGE_SERVICE);
      if (mStorageManager == null) {
        Log.w(TAG, "Failed to get StorageManager");
      }
    }

    mUIHandler = new Handler();

    HandlerThread thr = new HandlerThread("SystemUI UsbStorageActivity");
    thr.start();
    mAsyncStorageHandler = new Handler(thr.getLooper());

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
    if (Environment.isExternalStorageRemovable()) {
      getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
    }

    setContentView(com.android.internal.R.layout.usb_storage_activity);

    mIcon = (ImageView) findViewById(com.android.internal.R.id.icon);
    mBanner = (TextView) findViewById(com.android.internal.R.id.banner);
    mMessage = (TextView) findViewById(com.android.internal.R.id.message);

    mMountButton = (Button) findViewById(com.android.internal.R.id.mount_button);
    mMountButton.setOnClickListener(this);
    mUnmountButton = (Button) findViewById(com.android.internal.R.id.unmount_button);
    mUnmountButton.setOnClickListener(this);
    mProgressBar = (ProgressBar) findViewById(com.android.internal.R.id.progress);
  }
Ejemplo n.º 25
0
  public TargetsController(ArrayList<Target> model) {
    this.model = model;
    workerThread = new HandlerThread("Targets Worker Thread");
    workerThread.start();
    workerHandler = new Handler(workerThread.getLooper());

    setPrefs();
  }
 public NewCameraInputProviders(RongContext context) {
   super(context);
   this.mContext = context;
   // 来自融云demo
   mWorkThread = new HandlerThread("RongDemo");
   mWorkThread.start();
   mUploadHandler = new Handler(mWorkThread.getLooper());
 }
Ejemplo n.º 27
0
 @Override
 protected void onEnabled(long positionUs, boolean joining) {
   source.enable(trackIndex, positionUs);
   parserThread = new HandlerThread("textParser");
   parserThread.start();
   parserHelper = new SubtitleParserHelper(parserThread.getLooper(), subtitleParsers[parserIndex]);
   seekToInternal(positionUs);
 }
 public void begin() {
   if (mThread == null) {
     mThread = new HandlerThread("DFM Cache-Building Thread");
     mThread.start();
   }
   if (mHandler == null) mHandler = new CacheHandler(mThread.getLooper());
   mHandler.begin();
 }
Ejemplo n.º 29
0
  /** Service initialization */
  @Override
  public void onCreate() {
    super.onCreate();
    Log_OC.d(TAG, "Creating service");

    /// First worker thread for most of operations
    HandlerThread thread =
        new HandlerThread("Operations thread", Process.THREAD_PRIORITY_BACKGROUND);
    thread.start();
    mOperationsHandler = new ServiceHandler(thread.getLooper(), this);
    mOperationsBinder = new OperationsServiceBinder(mOperationsHandler);

    /// Separated worker thread for download of folders (WIP)
    thread = new HandlerThread("Syncfolder thread", Process.THREAD_PRIORITY_BACKGROUND);
    thread.start();
    mSyncFolderHandler = new SyncFolderHandler(thread.getLooper(), this);
  }
 @Override
 public void onCreate() {
   if (Log.DEBUG) Log.v("SMSReceiverService: onCreate()");
   HandlerThread thread = new HandlerThread(Log.LOGTAG, Process.THREAD_PRIORITY_BACKGROUND);
   thread.start();
   context = getApplicationContext();
   mServiceLooper = thread.getLooper();
   mServiceHandler = new ServiceHandler(mServiceLooper);
 }