コード例 #1
0
  public KeyguardViewMediator(
      Context context, PhoneWindowManager callback, LocalPowerManager powerManager) {
    mContext = context;

    mRealPowerManager = powerManager;
    mPM = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    mWakeLock =
        mPM.newWakeLock(
            PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "keyguard");
    mWakeLock.setReferenceCounted(false);
    mShowKeyguardWakeLock = mPM.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "show keyguard");
    mShowKeyguardWakeLock.setReferenceCounted(false);

    mWakeAndHandOff = mPM.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "keyguardWakeAndHandOff");
    mWakeAndHandOff.setReferenceCounted(false);

    IntentFilter filter = new IntentFilter();
    filter.addAction(DELAYED_KEYGUARD_ACTION);
    filter.addAction(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
    context.registerReceiver(mBroadCastReceiver, filter);
    mAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    mCallback = callback;

    mUpdateMonitor = new KeyguardUpdateMonitor(context);

    mUpdateMonitor.registerInfoCallback(this);
    mUpdateMonitor.registerSimStateCallback(this);

    mLockPatternUtils = new LockPatternUtils(mContext);
    mKeyguardViewProperties =
        new LockPatternKeyguardViewProperties(mLockPatternUtils, mUpdateMonitor);

    mKeyguardViewManager =
        new KeyguardViewManager(
            context, WindowManagerImpl.getDefault(), this, mKeyguardViewProperties, mUpdateMonitor);

    mUserPresentIntent = new Intent(Intent.ACTION_USER_PRESENT);
    mUserPresentIntent.addFlags(
        Intent.FLAG_RECEIVER_REPLACE_PENDING | Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);

    final ContentResolver cr = mContext.getContentResolver();
    mShowLockIcon = (Settings.System.getInt(cr, "show_status_bar_lock", 0) == 1);

    mLockSounds = new SoundPool(1, AudioManager.STREAM_SYSTEM, 0);
    String soundPath = Settings.System.getString(cr, Settings.System.LOCK_SOUND);
    if (soundPath != null) {
      mLockSoundId = mLockSounds.load(soundPath, 1);
    }
    if (soundPath == null || mLockSoundId == 0) {
      if (DEBUG) Log.d(TAG, "failed to load sound from " + soundPath);
    }
    soundPath = Settings.System.getString(cr, Settings.System.UNLOCK_SOUND);
    if (soundPath != null) {
      mUnlockSoundId = mLockSounds.load(soundPath, 1);
    }
    if (soundPath == null || mUnlockSoundId == 0) {
      if (DEBUG) Log.d(TAG, "failed to load sound from " + soundPath);
    }
  }
 void lock(boolean lock) {
   try {
     if (lock) {
       boolean lockNew =
           (keepon && Receiver.on_wlan)
               || (InCallScreen.mSlidingCardManager != null
                   && InCallScreen.mSlidingCardManager.isSlideInProgress())
               || Receiver.call_state == UserAgent.UA_STATE_INCOMING_CALL
               || Receiver.call_state == UserAgent.UA_STATE_HOLD
               || RtpStreamSender.delay != 0
               || !InCallScreen.started;
       if (lockFirst || lockLast != lockNew) {
         lockLast = lockNew;
         lock(false);
         lockFirst = false;
         if (pwl == null) {
           PowerManager pm =
               (PowerManager) Receiver.mContext.getSystemService(Context.POWER_SERVICE);
           pwl =
               pm.newWakeLock(
                   lockNew
                       ? (PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP)
                       : PROXIMITY_SCREEN_OFF_WAKE_LOCK,
                   "Sipdroid.Receiver");
           pwl.acquire();
         }
       }
     } else {
       lockFirst = true;
       if (pwl != null) {
         pwl.release();
         pwl = null;
       }
     }
   } catch (Exception e) {
   }
   if (lock) {
     if (pwl2 == null) {
       PowerManager pm = (PowerManager) Receiver.mContext.getSystemService(Context.POWER_SERVICE);
       WifiManager wm = (WifiManager) Receiver.mContext.getSystemService(Context.WIFI_SERVICE);
       pwl2 = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Sipdroid.Receiver");
       pwl2.acquire();
       wwl = wm.createWifiLock(3, "Sipdroid.Receiver");
       wwl.acquire();
     }
   } else if (pwl2 != null) {
     pwl2.release();
     pwl2 = null;
     wwl.release();
   }
 }
  private A2dpSinkStateMachine(A2dpSinkService svc, Context context) {
    super("A2dpSinkStateMachine");
    mService = svc;
    mContext = context;
    mAdapter = BluetoothAdapter.getDefaultAdapter();

    // for sink soft handsoff and multicast are disabled
    initNative(maxA2dpSinkConnections, multiCastState);

    mDisconnected = new Disconnected();
    mPending = new Pending();
    mConnected = new Connected();

    addState(mDisconnected);
    addState(mPending);
    addState(mConnected);

    setInitialState(mDisconnected);

    PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "BluetoothA2dpSinkService");

    mIntentBroadcastHandler = new IntentBroadcastHandler();

    mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    if (!USE_AUDIOTRACK) mAudioManager.registerAudioPortUpdateListener(mAudioPortListener);
  }
コード例 #4
0
ファイル: WalletService.java プロジェクト: ksedgwic/Wallet32
  @Override
  public void onCreate() {
    mNM = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    mLBM = LocalBroadcastManager.getInstance(this);

    mLogger.info("WalletService created");

    mApp = (WalletApplication) getApplicationContext();

    mContext = getApplicationContext();
    mRes = mContext.getResources();

    mTimeoutWorker = Executors.newSingleThreadScheduledExecutor();

    final String lockName = getPackageName() + " blockchain sync";
    final PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, lockName);

    mPrefs = PreferenceManager.getDefaultSharedPreferences(this);

    String fiatRateSource = mPrefs.getString(SettingsActivity.KEY_FIAT_RATE_SOURCE, "");
    setFiatRateSource(fiatRateSource);

    // Register for future preference changes.
    mPrefs.registerOnSharedPreferenceChangeListener(this);

    // Register with the WalletApplication.
    mApp.setWalletService(this);
  }
コード例 #5
0
ファイル: JaneService.java プロジェクト: willwhitney/jane
  @Override
  public int onStartCommand(Intent intent, int flags, int startId) {
    instance = this;
    Log.i("Jane", "Received start id " + startId + ": " + intent);
    Log.d("Jane", "Service received start command.");

    tts =
        new TextToSpeech(
            this,
            new TextToSpeech.OnInitListener() {

              @Override
              public void onInit(int status) {}
            });
    tts.setOnUtteranceCompletedListener(this);

    // set up Bluetooth here
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
      bt = new Gingerbread();
    } else {
      bt = new Honeycomb();
    }

    bt.setContext(getApplicationContext());

    try {
      bt.getProxy();
    } catch (Exception e) {
      e.printStackTrace();
    }

    AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    ComponentName mediaButtonResponder =
        new ComponentName(getPackageName(), MediaButtonIntentReceiver.class.getName());
    am.registerMediaButtonEventReceiver(mediaButtonResponder);

    PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
    WakeLock lock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "JaneLock");
    lock.acquire(10 * 60 * 1000);

    localBroadcastManager = LocalBroadcastManager.getInstance(this);
    localChatReceiver = new ChatReceiver(this);

    String username = intent.getExtras().getString("username");
    String password = intent.getExtras().getString("password");
    uiMessenger = intent.getExtras().getParcelable("messenger");

    nameCache = new HashMap<String, String>();
    chatCache = new HashMap<String, Chat>();

    smack = org.jivesoftware.smack.SmackAndroid.init(this);

    this.registerReceiver(stateIntents, new IntentFilter(JaneIntent));
    this.registerReceiver(stateIntents, new IntentFilter(Bluetooth.BLUETOOTH_STATE));

    LoginThread login = new LoginThread(username, password, this);
    login.start();

    return START_STICKY;
  }
コード例 #6
0
 public static void lockScreenSleep() {
   if (wl == null) {
     PowerManager pm = (PowerManager) ofActivity.getSystemService(Context.POWER_SERVICE);
     wl = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "DoNotDimScreen");
   }
   wl.acquire();
 }
コード例 #7
0
  // send notification to Notification bar, open notification bar, will stay there,
  // but if any press, will clear all facebook notifications
  private void sendNotification(String title, String content) {
    WakeLock wl =
        pownermMgr.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "SCREEN_BRIGHT_WAKE_LOCK");
    wl.acquire(10 * 1000);

    if (orm.getNotificationVibrate()) {
      final Vibrator vib =
          (android.os.Vibrator) mContext.getSystemService(Context.VIBRATOR_SERVICE);
      vib.vibrate(2 * 1000);
    }

    Notification notification = new Notification();
    notification.flags |= Notification.FLAG_SHOW_LIGHTS;
    notification.flags |= Notification.DEFAULT_SOUND;
    notification.ledARGB = 0xff00ff00;
    notification.ledOnMS = 500;
    notification.ledOffMS = 2000;

    if (orm.getNotificationVibrate()) {
      notification.defaults |= Notification.DEFAULT_VIBRATE;
    }

    notification.defaults |= Notification.DEFAULT_SOUND;
    notify.notifyNotifications(
        title,
        content,
        R.drawable.facebook_logo,
        Notification.FLAG_AUTO_CANCEL | Notification.FLAG_ONLY_ALERT_ONCE,
        notification);
  }
コード例 #8
0
ファイル: StatesReceiver.java プロジェクト: pvoid/apteryx
 public ReceiveThread(Context context) {
   _mContext = context;
   PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
   _mWakeLock =
       pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Apteryx states receiver wake lock");
   _mWakeLock.acquire();
 }
コード例 #9
0
ファイル: MainActivity.java プロジェクト: bubblecloud/pepper
  // LIFE CYCLE BEGIN
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    hideFragment(R.id.online_screen);
    hideFragment(R.id.sleep_screen);
    hideFragment(R.id.master_password_screen);
    hideFragment(R.id.configure_screen);

    PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE);
    wakeLock =
        pm.newWakeLock(
            PowerManager.FULL_WAKE_LOCK
                | PowerManager.ACQUIRE_CAUSES_WAKEUP
                | PowerManager.ON_AFTER_RELEASE,
            "INFO");
    wakeLock.acquire();

    audioManager = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);

    remoteControlResponder =
        new ComponentName(getPackageName(), RemoteControlReceiver.class.getName());

    securityController = new SecurityController(this);
    MyFirebaseInstanceIDService.setMainActivity(this);
    MyFirebaseMessagingService.setMainActivity(this);
  }
コード例 #10
0
  @Override
  public int onStartCommand(Intent intent, int flags, int startId) {
    currentState = STATE_CONNECTING;

    if (useWakeLock) {
      powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
      wakeLock =
          powerManager.newWakeLock(
              PowerManager.PARTIAL_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, TAG);
      wakeLock.acquire();
      Log.d(TAG, "WakeLock acquired");
    }

    if (sensorsManager != null) {
      // sensorsManager.requestAllDataTypes();			//And all data types
      sensorsManager.connectToAvailableSensors(); // Connect to the sensors
      sensorsManager.addRecordDataListener(this);
    } else {
      Log.e(TAG, "CRITICAL ERROR, SENSORS MANAGER NOT SET");
      currentState = STATE_NOT_CONNECTED;
      stopSelf(); // We cannot continue without a SensorsManager
    }

    // We don't want the OS to restart this service on its own
    return START_NOT_STICKY;
  }
コード例 #11
0
  public RingerSwitchObserver(Context context) {

    mContext = context;

    ThemeUtils.registerThemeChangeReceiver(
        context,
        new BroadcastReceiver() {
          @Override
          public void onReceive(Context context, Intent intent) {
            mUiContext = null;
          }
        });

    mHandler = new Handler();
    mVolumeChangeUiRunnable =
        new Runnable() {
          @Override
          public void run() {
            getVolumePanel()
                .postVolumeChanged(
                    AudioManager.STREAM_RING,
                    AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_VIBRATE);
          }
        };

    PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "RingerSwitchObserver");
    mWakeLock.setReferenceCounted(false);

    startObserving(RINGER_SWITCH_UEVENT_MATCH);

    init(); // set initial status
  }
コード例 #12
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (D) Log.e(TAG, "+++ ON CREATE +++");
    // Set up the window layout
    //        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);  //常亮
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.main);
    initView();
    initBle();
    initThread();
    // 初始化socket
    if (!ConnectSocket()) {
      Toast.makeText(this, "端口不可用", Toast.LENGTH_SHORT).show();
      finish();
    }
    // 开启线程
    startSendThread();
    startBroadcastThread();
    startRecvThread();

    // _TEST
    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "bright");
    // 点亮屏幕
    wl.acquire();
  }
コード例 #13
0
  public void run() {
    // Start the thread
    mNotificationManager =
        (NotificationManager) App.mApp.getSystemService(Context.NOTIFICATION_SERVICE);

    Looper.prepare();
    mHandler = new ClementineConnectionHandler(this);

    mPebble = new Pebble();

    // Get a Wakelock Object
    PowerManager pm = (PowerManager) App.mApp.getSystemService(Context.POWER_SERVICE);
    mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Clementine");

    Resources res = App.mApp.getResources();
    mNotificationHeight = (int) res.getDimension(android.R.dimen.notification_large_icon_height);
    mNotificationWidth = (int) res.getDimension(android.R.dimen.notification_large_icon_width);

    mAudioManager = (AudioManager) App.mApp.getSystemService(Context.AUDIO_SERVICE);
    mClementineMediaButtonEventReceiver =
        new ComponentName(
            App.mApp.getPackageName(), ClementineMediaButtonEventReceiver.class.getName());

    mMediaButtonBroadcastReceiver = new ClementineMediaButtonEventReceiver();

    fireOnConnectionReady();

    Looper.loop();
  }
コード例 #14
0
  public void initSDL() {
    if (!Loader.loaded) return;

    nativeView = new NativeView(this, quitHandler);
    setContentView(nativeView);
    // Receive keyboard events
    nativeView.setFocusableInTouchMode(true);
    nativeView.setFocusable(true);
    nativeView.requestFocus();

    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    wakeLock =
        pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "XCSoar");
    wakeLock.acquire();

    /* add an icon to the notification area while XCSoar runs, to
     * remind the user that we're sucking his battery empty */
    Notification notification = new Notification(R.drawable.icon, null, System.currentTimeMillis());
    Intent intent = new Intent(this, getClass());
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, 0);
    notification.setLatestEventInfo(this, "XCSoar", "XCSoar is running", contentIntent);
    notification.flags |= Notification.FLAG_ONGOING_EVENT;

    NotificationManager notificationManager =
        (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(1, notification);
  }
コード例 #15
0
ファイル: MainActivity.java プロジェクト: jayded/haa
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

    publisherView = (SurfaceView) findViewById(R.id.publisherview);
    takePictureNow = false;

    // Although this call is deprecated, Camera preview still seems to require it :-\
    publisherView.getHolder().setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    // SurfaceHolders are not initially available, so we'll wait to create the publisher
    publisherView.getHolder().addCallback(this);

    // A simple executor will allow us to perform tasks asynchronously.
    executor = Executors.newCachedThreadPool();
    myNoise = new NoiseAlert();
    myNoise.myStartStop();
    reddot = (ImageView) findViewById(R.id.activity_led);
    mHandler.postDelayed(mTakePictureTask, PICTURE_INTERVAL);

    // Disable screen dimming
    PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
    wakeLock = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, "Full Wake Lock");
  }
コード例 #16
0
  private void handleDatabaseMigration(final MasterSecret masterSecret) {
    this.notification = initializeBackgroundNotification();

    final PowerManager power = (PowerManager) getSystemService(Context.POWER_SERVICE);
    final WakeLock wakeLock = power.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Migration");

    new Thread() {
      @Override
      public void run() {
        try {
          wakeLock.acquire();

          setMigrating(true);
          SmsMigrator.migrateDatabase(
              ApplicationMigrationService.this, masterSecret, ApplicationMigrationService.this);
          setMigrating(false);

          if (handler != null) {
            handler.obtainMessage(PROGRESS_COMPLETE).sendToTarget();
          }

          stopForeground(true);
        } finally {
          wakeLock.release();
          stopService(
              new Intent(ApplicationMigrationService.this, ApplicationMigrationService.class));
        }
      }
    }.start();
  }
コード例 #17
0
ファイル: Bee.java プロジェクト: YuFuLin/AirplaneExample
  // Init
  private void Initialize() {
    GV.res = getResources();

    // Get the service of vibrator
    GV.vibrator = (Vibrator) getApplication().getSystemService(Service.VIBRATOR_SERVICE);

    // Setting no title
    requestWindowFeature(Window.FEATURE_NO_TITLE);

    // Full Screen
    getWindow()
        .setFlags(
            WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

    // Fixed the screen
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

    // Get the size of the screen
    DisplayMetrics dm = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(dm);
    GV.scaleWidth = dm.widthPixels;
    GV.scaleHeight = dm.heightPixels;
    GV.halfWidth = GV.scaleWidth >> 1;
    GV.halfHeight = GV.scaleHeight >> 1;

    // Always wake the backlight
    powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
    wakeLock = powerManager.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "BackLight");

    // Get the sensor of gravity
    sensorMgr = (SensorManager) getSystemService(SENSOR_SERVICE);
    sensor = sensorMgr.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
  }
コード例 #18
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow()
        .setFlags(
            WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

    boolean isLandscape =
        (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE);
    int frameBufferWidth = isLandscape ? 480 : 320;
    int frameBufferHeight = isLandscape ? 320 : 480;
    // Apparently drawing completes faster with RGB565
    Bitmap frameBuffer = Bitmap.createBitmap(frameBufferWidth, frameBufferHeight, Config.RGB_565);

    float scaleX = (float) frameBufferWidth / getWindowManager().getDefaultDisplay().getWidth();
    float scaleY = (float) frameBufferHeight / getWindowManager().getDefaultDisplay().getHeight();

    renderView = new AndroidFastRenderView(this, frameBuffer);
    graphics = new AndroidGraphics(getAssets(), frameBuffer);
    fileIO = new AndroidFileIO(this);
    audio = new AndroidAudio(this);
    input = new AndroidInput(this, renderView, scaleX, scaleY);
    screen = getStartScreen();
    setContentView(renderView);

    PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
    wakeLock = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, "GLGame");
  }
コード例 #19
0
    @Override
    public void onStart() {
        final Context context = getContext();
        mTwilightManager = getLocalService(TwilightManager.class);
        final PowerManager powerManager =
                (PowerManager) context.getSystemService(Context.POWER_SERVICE);
        mWakeLock = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, TAG);

        context.registerReceiver(mDockModeReceiver,
                new IntentFilter(Intent.ACTION_DOCK_EVENT));
        context.registerReceiver(mBatteryReceiver,
                new IntentFilter(Intent.ACTION_BATTERY_CHANGED));

        mConfiguration.setToDefaults();

        mDefaultUiModeType = context.getResources().getInteger(
                com.android.internal.R.integer.config_defaultUiModeType);
        mCarModeKeepsScreenOn = (context.getResources().getInteger(
                com.android.internal.R.integer.config_carDockKeepsScreenOn) == 1);
        mDeskModeKeepsScreenOn = (context.getResources().getInteger(
                com.android.internal.R.integer.config_deskDockKeepsScreenOn) == 1);
        mTelevision = context.getPackageManager().hasSystemFeature(
                PackageManager.FEATURE_TELEVISION) ||
            context.getPackageManager().hasSystemFeature(
                    PackageManager.FEATURE_LEANBACK);
        mWatch = context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_WATCH);

        mNightMode = Settings.Secure.getInt(context.getContentResolver(),
                Settings.Secure.UI_NIGHT_MODE, UiModeManager.MODE_NIGHT_AUTO);

        mTwilightManager.registerListener(mTwilightListener, mHandler);

        publishBinderService(Context.UI_MODE_SERVICE, mService);
    }
コード例 #20
0
  public void start() {
    synchronized (this) {
      if (!preferences.isCommandEnabled()) {
        Log.w(NotifierConstants.LOG_TAG, "Commands disabled, not starting");
        return;
      }

      // Ensure the CPU keeps running while we listen for connections
      if (wakeLock == null) {
        PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
        wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, COMMANDS_LOCK_TAG);
        wakeLock.acquire();
      }

      if (preferences.isBluetoothCommandEnabled()) {
        startBluetoothListener();
      }

      if (preferences.isIpCommandEnabled()) {
        startIpListener();
      }

      if (preferences.isUsbCommandEnabled()) {
        startUsbListener();
      }

      startDiscoveryListener();

      preferences.registerOnSharedPreferenceChangeListener(this);
    }
  }
コード例 #21
0
  @SuppressWarnings("deprecation")
  protected void aquireWakelock() {
    if (wakeLock == null) {
      PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
      if (PreferenceManager.getDefaultSharedPreferences(getApplicationContext())
          .getBoolean("pref_keep_screen_bright", false)) {
        wakeLock =
            pm.newWakeLock(
                PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, "CPU");
      } else {
        wakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "CPU");
      }

      wakeLock.acquire();
    }
  }
コード例 #22
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.d(TAG, "onCreate1");
    setContentView(R.layout.main);

    mContext = this;
    sensorMgr = (SensorManager) getSystemService(SENSOR_SERVICE);
    hasSensor = false;

    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    wl =
        pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK + PowerManager.ON_AFTER_RELEASE, "My Tag");
    wl.acquire();

    vib = (Vibrator) getSystemService(VIBRATOR_SERVICE);

    // 画面メッセージ
    tv = (TextView) findViewById(R.id.CountdownTimer);
    tv.setText("00:00:00");
    tv.setTextColor(Color.RED);
    tv_message1 = (TextView) findViewById(R.id.message1);
    tv_message1.setText(R.string.message_timeup);
    tv_message1.setTextColor(Color.RED);
    tv_sensor_message = (TextView) findViewById(R.id.sensor_message);
    tv_sensor_message.setText(R.string.message_Alarm_Stop);
  }
コード例 #23
0
  @Override
  public void onCreate() {
    super.onCreate();
    singleton = this;

    wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
    connManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);

    try {
      mStartForeground =
          getClass().getMethod("startForeground", new Class[] {int.class, Notification.class});
    } catch (NoSuchMethodException e) {
      mStartForeground = null;
    }

    state = STATE_STOPPED;
    filteringEnabled = false;

    app = (BarnacleApp) getApplication();
    app.serviceStarted(this);

    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "BarnacleService");
    wakeLock.acquire();

    IntentFilter filter = new IntentFilter();
    filter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);
    filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
    registerReceiver(connectivityReceiver, filter);
  }
コード例 #24
0
  private void handleMessage(final Context context, Intent intent) {
    // push를 사용 안할 경우 메시지가 오더라도 무시 함.
    SharedPreferences preferences = context.getSharedPreferences("pushPref", Activity.MODE_PRIVATE);
    boolean isPushEnable = preferences.getBoolean("isPushEnable", true);
    if (!isPushEnable) {
      Logger.d("handleMessage", "isPushEnable : " + isPushEnable);
      return;
    }

    // 화면을 켬
    pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    wl =
        pm.newWakeLock(
            PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "bbbb");
    wl.acquire();

    Log.i("handleMessage", "------------ COME MESSAGE: " + pushKey);
    // TODO Auto-generated method stub
    String count = intent.getExtras().getString("badge");
    String message = intent.getExtras().getString("message");
    // String collaspe_key = intent.getExtras().getString("collaspe_key");

    Log.i("handleMessage", "------------ COME MESSAGE: " + message + ", " + count);

    Notification notification =
        new Notification(
            RUtil.getDrawableR(context, "app_icon"), message, System.currentTimeMillis());

    // notiId
    int notiID = (int) System.currentTimeMillis();
    // TODO 현재는 시작 화면으로 가게 했지만 추후 수정해야함.
    String title = PushManager.getInstance().getNotiMessage(PushManager.MESSAGE_TITLE);
    Intent in = new Intent(Intent.ACTION_MAIN);
    in.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    in.addCategory(Intent.CATEGORY_LAUNCHER);
    in.setComponent(new ComponentName(context, DummyActivity.class));
    in.putExtra("push", message);
    in.putExtra("push_noti_id", notiID);
    PendingIntent pi =
        PendingIntent.getActivity(
            context, notiID, in, Intent.FLAG_ACTIVITY_NEW_TASK | PendingIntent.FLAG_ONE_SHOT);
    notification.setLatestEventInfo(context, title, message, pi);
    notification.flags |= Notification.FLAG_AUTO_CANCEL; // 선택시 자동삭제

    NotificationManager nm =
        (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

    AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    // 전체 제거 고려
    if (audioManager.getRingerMode() == AudioManager.RINGER_MODE_NORMAL) {
      notification.defaults |= android.app.Notification.DEFAULT_SOUND;
    } else {
      // 진동 효과 구성
      long[] vibrate = {1000, 1000, 1000, 1000, 1000};
      notification.vibrate = vibrate;
    }
    // nm.notify(PushManager.PUSH_MESSAGE, notification);
    nm.notify(notiID, notification);
    run.run();
  }
コード例 #25
0
  @Override
  protected void onStart() {
    PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
    wakelock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "no sleep");
    wakelock.acquire();

    if (CheckOutNet.isNetworkConnected(getApplicationContext())) {
      if (firstexecution == 0) {
        dialog =
            ProgressDialog.show(
                TechnicienActivity.this,
                getResources().getString(R.string.map_data),
                getResources().getString(R.string.msg_wait),
                true);
        new ConnexionTask().execute();
      }
    } else {
      if (firstexecution == 0) {
        dialog =
            ProgressDialog.show(
                TechnicienActivity.this,
                getResources().getString(R.string.map_data),
                getResources().getString(R.string.msg_wait),
                true);
        new OfflineTask().execute();
      }
    }

    super.onStart();
  }
コード例 #26
0
  @Override
  protected void onResume() {
    super.onResume();
    // GPS OR NETWORK????
    // mgr.requestLocationUpdates(LocationManager.GPS_PROVIDER, 15000, 1, locationListener);
    // provider, update in milliseconds, update in location change, listener
    // mgr.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 200, 10, locationListener);

    // TO SEE NETWORK INFO AND STATUS
    // SimpleLocationListener sll = new SimpleLocationListener();
    //        mLocationListeners.add(sll);
    //        mgr.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 5000, 5, sll);
    //
    // TO SEE GPS INFO AND STATUS
    // SimpleLocationListener sll = new SimpleLocationListener();
    // mLocationListeners.add(sll);
    // mgr.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 10, sll);
    ////        mgr.addGpsStatusListener(gpsStatusListener);

    if (toggleButton.isChecked()) {
      setListener(LocationManager.GPS_PROVIDER);
    } else {
      setListener(LocationManager.NETWORK_PROVIDER);
    }

    // keep screen on!
    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    wakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, "LOCATION TEST");
    wakeLock.acquire();
  }
  @Override
  public void onReceive(Context context, Intent intent) {

    PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, AppTags.UFRGS_MOBILE);
    // Acquire the lock
    wl.acquire();

    prefs = context.getSharedPreferences(AppTags.LIBRARY_LOGIN_PREF, Context.MODE_PRIVATE);
    editor = prefs.edit();
    int value = prefs.getInt(AppTags.ALARM_COUNTER, 0);
    value = value + 1;
    editor.putInt(AppTags.ALARM_COUNTER, value);
    editor.commit();

    LibraryLoader loader = new LibraryLoader(context);
    loader.renewBooks(null, true);

    if (value == DAILY_RETRIES) {
      launchNotification(
          context,
          context.getString(R.string.we_tried_to_renew_your_items_notification_title),
          context.getString(R.string.verify_return_date_notification_message));
      editor.putInt(AppTags.ALARM_COUNTER, 0);
      editor.commit();
    }

    wl.release();
  }
コード例 #28
0
  @Override
  public void onReceive(Context context, Intent intent) {
    if (wakeLock == null) {
      PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
      wakeLock =
          pm.newWakeLock(
              PowerManager.FULL_WAKE_LOCK
                  | PowerManager.ACQUIRE_CAUSES_WAKEUP
                  | PowerManager.ON_AFTER_RELEASE,
              TAG);
    }
    if (!wakeLock.isHeld()) {
      wakeLock.acquire();
    }

    readyToTakePicture = true;

    try {
      if (ApplicationScreen.instance == null
          || ApplicationScreen.getCameraController() == null
          || (CameraController.getCamera() == null && CameraController.getCamera2() == null)) {
        Intent dialogIntent = new Intent(context, MainScreen.class);
        dialogIntent.addFlags(
            Intent.FLAG_ACTIVITY_REORDER_TO_FRONT
                | Intent.FLAG_ACTIVITY_NEW_TASK
                | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        context.startActivity(dialogIntent);
        if (wakeLock != null) if (wakeLock.isHeld()) wakeLock.release();

      } else {
        takePicture();
      }
    } catch (NullPointerException e) {
    }
  }
コード例 #29
0
 private static synchronized PowerManager.WakeLock getLock(Context context) {
   if (lockStatic == null) {
     PowerManager mgr = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
     lockStatic = mgr.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, LOCK_NAME_STATIC);
   }
   return (lockStatic);
 }
コード例 #30
0
  private A2dpStateMachine(A2dpService svc, Context context) {
    super(TAG);
    mService = svc;
    mContext = context;
    mAdapter = BluetoothAdapter.getDefaultAdapter();

    initNative();

    if (DBG) {
      setDbg(true);
    }

    mDisconnected = new Disconnected();
    mPending = new Pending();
    mConnected = new Connected();

    addState(mDisconnected);
    addState(mPending);
    addState(mConnected);

    setInitialState(mDisconnected);

    PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "BluetoothA2dpService");

    mIntentBroadcastHandler = new IntentBroadcastHandler();

    mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
  }