@Override
  protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.downloader);

    _downloadingText = (TextView) findViewById(R.id.downloadDownloadingText);
    _infoText = (TextView) findViewById(R.id.downloadInfoText);
    _progressBar = (ProgressBar) findViewById(R.id.downloadProgressBar);
    _progressText = (TextView) findViewById(R.id.downloadProgressText);

    _progressBar.setMax(100);

    _handler = new DownloadMessageHandler(this);

    final WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
    _wifiLock =
        wifiManager.createWifiLock(WifiManager.WIFI_MODE_FULL, DownloadActivity.class.getName());

    scheduleDownloadingTextAnimation();

    final Intent intent = getIntent();
    final EpisodeModel episode =
        (EpisodeModel) intent.getSerializableExtra(getString(R.string.key_episode));

    final ProgrammeModel programme = episode.getProgramme();
    final String programmeName = programme.getName();
    final String name = episode.getName();
    final Date date = episode.getDate();
    final String dateStr = DATE_FORMAT.format(date);
    setTitle(getString(R.string.download_title) + " - " + programmeName);
    _infoText.setText(programmeName + " " + dateStr + "\n" + name);

    new Downloader(this, episode, 10, _wifiLock, _handler).start();
  }
예제 #2
0
  @Override
  protected void setUp() throws Exception {
    super.setUp();
    if (!WifiFeature.isWifiSupported(getContext())) {
      // skip the test if WiFi is not supported
      return;
    }
    mMySync = new MySync();
    mIntentFilter = new IntentFilter();
    mIntentFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
    mIntentFilter.addAction(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION);
    mIntentFilter.addAction(WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION);
    mIntentFilter.addAction(WifiManager.SUPPLICANT_STATE_CHANGED_ACTION);
    mIntentFilter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);
    mIntentFilter.addAction(WifiManager.RSSI_CHANGED_ACTION);
    mIntentFilter.addAction(WifiManager.NETWORK_IDS_CHANGED_ACTION);
    mIntentFilter.addAction(WifiManager.ACTION_PICK_WIFI_NETWORK);

    mContext.registerReceiver(mReceiver, mIntentFilter);
    mWifiManager = (WifiManager) getContext().getSystemService(Context.WIFI_SERVICE);
    assertNotNull(mWifiManager);
    mWifiLock = mWifiManager.createWifiLock(TAG);
    mWifiLock.acquire();
    if (!mWifiManager.isWifiEnabled()) setWifiEnabled(true);
    Thread.sleep(ENABLE_WAIT_MSEC);
    assertTrue(mWifiManager.isWifiEnabled());
    mMySync.expectedState = STATE_NULL;
  }
예제 #3
0
 public static WifiManager.WifiLock createWifiLock(Context context, String tag) {
   WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
   int lockType = WifiManager.WIFI_MODE_FULL;
   if (Build.VERSION.SDK_INT >= 12) {
     lockType = 3;
   }
   return wm.createWifiLock(lockType, tag);
 }
예제 #4
0
 private void takeWifiLock() {
   if (mWifiLock == null) {
     WifiManager manager = (WifiManager) sContext.getSystemService(Context.WIFI_SERVICE);
     mWifiLock = manager.createWifiLock(WAKE_LOCK_TAG);
     mWifiLock.setReferenceCounted(false);
   }
   mWifiLock.acquire();
 }
예제 #5
0
 protected static synchronized WifiManager.WifiLock getWifiLock(Context context) {
   // keep wifi alive
   if (wifilock == null) {
     WifiManager manager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
     wifilock = manager.createWifiLock(CLASS_TAG);
     wifilock.setReferenceCounted(true);
   }
   return wifilock;
 }
 public void aquireWifiLock() {
   if (mWifiLock == null) {
     Log.d(TAG, "creating new WifiLock");
     mWifiLock = mManager.createWifiLock(WifiManager.WIFI_MODE_FULL, WIFI_LOCK_TAG);
   }
   if (!mWifiLock.isHeld()) {
     Log.d(TAG, "aquiring WifiLock");
     mWifiLock.acquire();
   }
 }
    @Override
    protected void onPreExecute() {
      PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
      wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "DexcomShareDashclock");
      wl.acquire();

      WifiManager wfm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
      wifiLock = wfm.createWifiLock("DexcomShareDashclock");
      wifiLock.acquire();
    }
예제 #8
0
  private void stayAwake() {
    // Keep the device awake. PARTIAL_WAKE_LOCK isn't sufficient because the WIFI slows down.
    // Keeping the screen
    // slightly on keeps WIFI going at full speed.
    PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
    wakeLock = powerManager.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "Garage");
    wakeLock.acquire();

    // Keep WIFI on.
    WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
    wifiManager.createWifiLock(WifiManager.WIFI_MODE_FULL, "Garage").acquire();
  }
예제 #9
0
 private void updateWifiLock(boolean isStarted) {
     WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
     if (null == wifiLock) {
         wifiLock = wifiManager.createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF, "fqrouter wifi hotspot");
     }
     if (isStarted) {
         wifiLock.acquire();
     } else {
         if (wifiLock.isHeld()) {
             wifiLock.release();
         }
     }
 }
예제 #10
0
  @Override
  public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (isNetworkRequired()) {
      final WifiManager wifiManager =
          (WifiManager) getActivity().getSystemService(Context.WIFI_SERVICE);
      wifiLock = wifiManager.createWifiLock(TAG);
    }

    finishOnComplete = getArguments().getBoolean(EXTRA_FINISH_ON_COMPLETE, true);
    autoResumeManagement = getArguments().getBoolean(EXTRA_AUTO_RESUME_MANAGEMENT, true);
  }
 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();
   }
 }
예제 #12
0
  private void prePoll() {
    mWifiLock = null;

    if (!checkConnectivity()) {
      WifiManager wm = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
      mWifiLock = wm.createWifiLock(getClass().getSimpleName());

      mWifiLock.acquire();

      long start = System.currentTimeMillis();
      while (!checkConnectivity() && System.currentTimeMillis() - start < Millis.SEC * 10) {
        Sleep.sleep(Millis.SEC);
      }
    }
  }
예제 #13
0
  public ClientStatus(Context ctx) {
    this.ctx = ctx;

    // set up CPU Wake Lock
    // see documentation at http://developer.android.com/reference/android/os/PowerManager.html
    PowerManager pm = (PowerManager) ctx.getSystemService(Context.POWER_SERVICE);
    wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, Logging.TAG);
    wakeLock.setReferenceCounted(
        false); // "one call to release() is sufficient to undo the effect of all previous calls to
    // acquire()"

    // set up Wifi wake lock
    WifiManager wm = (WifiManager) ctx.getSystemService(Context.WIFI_SERVICE);
    wifiLock = wm.createWifiLock(WifiManager.WIFI_MODE_FULL, "MyWifiLock");
    wifiLock.setReferenceCounted(false);
  }
 public APIClientProvider(
     AppSession appSession,
     UserAgentProvider userAgentProvider,
     Context context,
     CacheProvider cacheProvider,
     WifiManager wifiManager) {
   this.appSession = appSession;
   this.headers = appSession.getHttpHeader().entrySet();
   this.client = new OkHttpClient();
   this.userAgent = userAgentProvider.get();
   this.context = context;
   this.cacheProvider = cacheProvider;
   this.wifiManager = wifiManager;
   this.baseUrl = appSession.getConfigValue("ApiBaseUrl", null);
   this.wifiLock = wifiManager.createWifiLock(this.getClass().getName());
   this.configHttpClient();
   instance = this;
 }
예제 #15
0
  private void initView(View view) {
    listView = (ListView) view.findViewById(R.id.myCenter_listView);
    mTvStatusInfo = (TextView) view.findViewById(R.id.wifi_tv_createap_ssid);
    mCheckBox = (CheckBox) view.findViewById(R.id.ck_clouds_dog_switch);

    mWiFiMainView = (WiFiMainView) view.findViewById(R.id.wifi_main_ly);
    mWiFiConnectView = (WiFiConnectView) view.findViewById(R.id.wifi_connect_wlan_ly);
    // mWiFiMainView.setOnItemClickListener(onItemClickListener);
    mWiFiMainView.setOnClickListener(clickListener);

    int itemWidth = ScreenUtils.getRealWidthValue(getActivity(), ALBUM_ITEM_WIDTH);
    int itemHeight = ScreenUtils.getRealHeightValue(getActivity(), ALBUM_ITEM_HEIGHT);
    AbsListView.LayoutParams param = new AbsListView.LayoutParams(itemWidth, itemHeight);
    ReturnBarView.LayoutParams lp = new ReturnBarView.LayoutParams(itemWidth, itemHeight);

    wifiLock = wifiManager.createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF, "lock");
    // 添加wifi锁
    wifiLock.acquire();
    initShowReturnBarView(view);
  }
예제 #16
0
  @Override
  public void onCreate() {
    Log.d(DEBUG_TAG, "created");
    super.onCreate();

    handler = new Handler();

    // initialise the locks
    loopMode = ConfigHelper.isLoopMode(this);

    // initialise the locks
    wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
    wifiLock = wifiManager.createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF, "RMBTWifiLock");
    wakeLock =
        ((PowerManager) getApplicationContext().getSystemService(Context.POWER_SERVICE))
            .newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "RMBTWakeLock");

    // mNetworkStateIntentReceiver = new BroadcastReceiver() {
    // @Override
    // public void onReceive(Context context, Intent intent) {
    // if
    // (intent.getAction().equals(ConnectivityManager.CONNECTIVITY_ACTION))
    // {
    //
    // final boolean connected = !
    // intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY,
    // false);
    // if (! connected)
    // stopTest();
    // }
    // }
    // };
    // final IntentFilter networkStateChangedFilter = new IntentFilter();
    // networkStateChangedFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
    //
    // registerReceiver(mNetworkStateIntentReceiver,
    // networkStateChangedFilter);
  }
  @Override
  public void onCreate() {
    super.onCreate();
    // TODO Auto-generated method stub
    // Instantiate the current List of geofences
    mCurrentGeofences = new ArrayList<Geofence>();

    // Instantiate a new geofence storage area
    mPrefs = new SimpleGeofenceStore(this);

    mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);

    //
    geofenceList = "";

    PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
    wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "SetLocService");
    wakeLock.acquire();

    WifiManager wm = (WifiManager) getSystemService(Context.WIFI_SERVICE);
    wifiLock = wm.createWifiLock(WifiManager.WIFI_MODE_FULL, "SetLocService");
    wifiLock.acquire();
  }
예제 #18
0
파일: WifiAdmin.java 프로젝트: theric/myAPP
 // ����һ��WifiLock
 public void creatWifiLock() {
   mWifiLock = mWifiManager.createWifiLock("Test");
 }
예제 #19
0
  @Override
  public void onCreate() {
    super.onCreate();

    android.util.Log.d("LinphoneService", "onCreate()");

    // In case restart after a crash. Main in LinphoneActivity
    LinphonePreferenceManager.getInstance(this);

    // Set default preferences
    PreferenceManager.setDefaultValues(this, R.get("xml", "preferences"), true);

    //		mNotificationTitle = getString(R.get("string", "app_name"));

    // Dump some debugging information to the logs
    Log.i(START_LINPHONE_LOGS);
    dumpDeviceInformation();
    dumpInstalledLinphoneInformation();

    //		mNM = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    //		mNM.cancel(INCALL_NOTIF_ID); // in case of crash the icon is not removed
    //		mNotif = new Notification(R.get("drawable", "status_level"), "",
    // System.currentTimeMillis());
    //		mNotif.iconLevel=IC_LEVEL_ORANGE;
    //		mNotif.flags |= Notification.FLAG_ONGOING_EVENT;

    //		Intent notifIntent = new Intent();
    //		notifIntent.addCategory(Intent.CATEGORY_LAUNCHER);
    //		notifIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
    // Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
    //		notifIntent.setClassName(ALModuleProxy.PKG_NAME, ALModuleProxy.PKG_NAME + "." +
    // ALModuleProxy.ACT_NAME);
    //		notifIntent.setAction(Intent.ACTION_MAIN);
    //		mNotifContentIntent = PendingIntent.getActivity(this, 0, notifIntent, 0);
    //		mNotif.setLatestEventInfo(this, mNotificationTitle,"", mNotifContentIntent);

    LinphoneManager.createAndStart(this, this);
    LinphoneManager.getLc().setPresenceInfo(0, null, OnlineStatus.Online);
    mWifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
    mWifiLock =
        mWifiManager.createWifiLock(
            WifiManager.WIFI_MODE_FULL_HIGH_PERF, this.getPackageName() + "-wifi-call-lock");
    mWifiLock.setReferenceCounted(false);
    instance = this; // instance is ready once linphone manager has been created

    // Retrieve methods to publish notification and keep Android
    // from killing us and keep the audio quality high.
    if (Version.sdkStrictlyBelow(Version.API05_ECLAIR_20)) {
      try {
        mSetForeground = getClass().getMethod("setForeground", mSetFgSign);
      } catch (NoSuchMethodException e) {
        Log.e(e, "Couldn't find foreground method");
      }
    } else {
      try {
        mStartForeground = getClass().getMethod("startForeground", mStartFgSign);
        mStopForeground = getClass().getMethod("stopForeground", mStopFgSign);
      } catch (NoSuchMethodException e) {
        Log.e(e, "Couldn't find startGoreground or stopForeground");
      }
    }

    //		startForegroundCompat(NOTIF_ID, mNotif);

    LinphoneManager.setOnTextReceivedListener(this);

    if (!mTestDelayElapsed) {
      // Only used when testing. Simulates a 5 seconds delay for launching service
      mHandler.postDelayed(
          new Runnable() {
            @Override
            public void run() {
              mTestDelayElapsed = true;
            }
          },
          5000);
    }
  }
예제 #20
0
  /** Set the audio mode as in call */
  @SuppressWarnings("deprecation")
  private synchronized void actualSetAudioInCall() {
    // Ensure not already set
    if (isSetAudioMode) {
      return;
    }
    stopRing();
    saveAudioState();

    // Set the rest of the phone in a better state to not interferate with
    // current call
    // Do that only if we were not already in silent mode
    /*
     * Not needed anymore with on flight gsm call capture
     * if(audioManager.getRingerMode() != AudioManager.RINGER_MODE_SILENT) {
     * audioManager.setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER,
     * AudioManager.VIBRATE_SETTING_ON);
     * audioManager.setVibrateSetting(AudioManager
     * .VIBRATE_TYPE_NOTIFICATION, AudioManager.VIBRATE_SETTING_OFF);
     * audioManager.setRingerMode(AudioManager.RINGER_MODE_VIBRATE); }
     */

    // LOCKS

    // Wifi management if necessary
    ContentResolver ctntResolver = service.getContentResolver();
    Settings.System.putInt(
        ctntResolver, Settings.System.WIFI_SLEEP_POLICY, Settings.System.WIFI_SLEEP_POLICY_NEVER);

    // Acquire wifi lock
    WifiManager wman = (WifiManager) service.getSystemService(Context.WIFI_SERVICE);
    if (wifiLock == null) {
      wifiLock =
          wman.createWifiLock(
              (Compatibility.isCompatible(9))
                  ? WifiManager.WIFI_MODE_FULL_HIGH_PERF
                  : WifiManager.WIFI_MODE_FULL,
              "com.csipsimple.InCallLock");
      wifiLock.setReferenceCounted(false);
    }
    WifiInfo winfo = wman.getConnectionInfo();
    if (winfo != null) {
      DetailedState dstate = WifiInfo.getDetailedStateOf(winfo.getSupplicantState());
      // We assume that if obtaining ip addr, we are almost connected so
      // can keep wifi lock
      if (dstate == DetailedState.OBTAINING_IPADDR || dstate == DetailedState.CONNECTED) {
        if (!wifiLock.isHeld()) {
          wifiLock.acquire();
        }
      }

      // This wake lock purpose is to prevent PSP wifi mode
      if (service.getPrefs().getPreferenceBooleanValue(SipConfigManager.KEEP_AWAKE_IN_CALL)) {
        if (screenLock == null) {
          PowerManager pm = (PowerManager) service.getSystemService(Context.POWER_SERVICE);
          screenLock =
              pm.newWakeLock(
                  PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE,
                  "com.csipsimple.onIncomingCall.SCREEN");
          screenLock.setReferenceCounted(false);
        }
        // Ensure single lock
        if (!screenLock.isHeld()) {
          screenLock.acquire();
        }
      }
    }

    if (!useWebRTCImpl) {
      // Audio routing
      int targetMode = getAudioTargetMode();
      Log.d(THIS_FILE, "Set mode audio in call to " + targetMode);

      if (service.getPrefs().generateForSetCall()) {
        boolean needOutOfSilent = (audioManager.getRingerMode() == AudioManager.RINGER_MODE_SILENT);
        if (needOutOfSilent) {
          audioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
        }
        ToneGenerator toneGenerator = new ToneGenerator(AudioManager.STREAM_VOICE_CALL, 1);
        toneGenerator.startTone(41 /* ToneGenerator.TONE_CDMA_CONFIRM */);
        toneGenerator.stopTone();
        toneGenerator.release();
        // Restore silent mode
        if (needOutOfSilent) {
          audioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
        }
      }

      // Set mode
      if (targetMode != AudioManager.MODE_IN_CALL && useSgsWrkAround) {
        // For galaxy S we need to set in call mode before to reset
        // stack
        audioManager.setMode(AudioManager.MODE_IN_CALL);
      }

      audioManager.setMode(targetMode);

      // Routing
      if (service.getPrefs().useRoutingApi()) {
        audioManager.setRouting(
            targetMode,
            userWantSpeaker ? AudioManager.ROUTE_SPEAKER : AudioManager.ROUTE_EARPIECE,
            AudioManager.ROUTE_ALL);
      } else {
        audioManager.setSpeakerphoneOn(userWantSpeaker ? true : false);
      }

      audioManager.setMicrophoneMute(false);
      if (bluetoothWrapper != null && userWantBluetooth && bluetoothWrapper.canBluetooth()) {
        Log.d(THIS_FILE, "Try to enable bluetooth");
        bluetoothWrapper.setBluetoothOn(true);
      }

    } else {
      // WebRTC implementation for routing
      int apiLevel = Compatibility.getApiLevel();

      // SetAudioMode
      // ***IMPORTANT*** When the API level for honeycomb (H) has been
      // decided,
      // the condition should be changed to include API level 8 to H-1.
      if (android.os.Build.BRAND.equalsIgnoreCase("Samsung") && (8 == apiLevel)) {
        // Set Samsung specific VoIP mode for 2.2 devices
        int mode = 4;
        audioManager.setMode(mode);
        if (audioManager.getMode() != mode) {
          Log.e(THIS_FILE, "Could not set audio mode for Samsung device");
        }
      }

      // SetPlayoutSpeaker
      if ((3 == apiLevel) || (4 == apiLevel)) {
        // 1.5 and 1.6 devices
        if (userWantSpeaker) {
          // route audio to back speaker
          audioManager.setMode(AudioManager.MODE_NORMAL);
        } else {
          // route audio to earpiece
          audioManager.setMode(AudioManager.MODE_IN_CALL);
        }
      } else {
        // 2.x devices
        if ((android.os.Build.BRAND.equalsIgnoreCase("samsung"))
            && ((5 == apiLevel) || (6 == apiLevel) || (7 == apiLevel))) {
          // Samsung 2.0, 2.0.1 and 2.1 devices
          if (userWantSpeaker) {
            // route audio to back speaker
            audioManager.setMode(AudioManager.MODE_IN_CALL);
            audioManager.setSpeakerphoneOn(userWantSpeaker);
          } else {
            // route audio to earpiece
            audioManager.setSpeakerphoneOn(userWantSpeaker);
            audioManager.setMode(AudioManager.MODE_NORMAL);
          }
        } else {
          // Non-Samsung and Samsung 2.2 and up devices
          audioManager.setSpeakerphoneOn(userWantSpeaker);
        }
      }
    }

    // Set stream solo/volume/focus

    int inCallStream = Compatibility.getInCallStream(userWantBluetooth);
    if (doFocusAudio) {
      if (!accessibilityManager.isEnabled()) {
        audioManager.setStreamSolo(inCallStream, true);
      }
      audioFocusWrapper.focus(userWantBluetooth);
    }
    Log.d(THIS_FILE, "Initial volume level : " + service.getPrefs().getInitialVolumeLevel());
    setStreamVolume(
        inCallStream,
        (int)
            (audioManager.getStreamMaxVolume(inCallStream)
                * service.getPrefs().getInitialVolumeLevel()),
        0);

    isSetAudioMode = true;
    // System.gc();
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (!OpenCVLoader.initDebug()) {
      Log.e(this.getClass().getSimpleName(), "  OpenCVLoader.initDebug(), not working.");
    } else {
      Log.d(this.getClass().getSimpleName(), "  OpenCVLoader.initDebug(), working.");
    }

    receivedUsbAttachmentNotifications = new ConcurrentLinkedQueue<UsbDevice>();
    eventLoop = null;

    setContentView(R.layout.activity_ftc_controller);

    utility = new Utility(this);
    context = this;
    entireScreenLayout = (LinearLayout) findViewById(R.id.entire_screen);
    buttonMenu = (ImageButton) findViewById(R.id.menu_buttons);
    buttonMenu.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            openOptionsMenu();
          }
        });

    textDeviceName = (TextView) findViewById(R.id.textDeviceName);
    textWifiDirectStatus = (TextView) findViewById(R.id.textWifiDirectStatus);
    textRobotStatus = (TextView) findViewById(R.id.textRobotStatus);
    textOpMode = (TextView) findViewById(R.id.textOpMode);
    textErrorMessage = (TextView) findViewById(R.id.textErrorMessage);
    textGamepad[0] = (TextView) findViewById(R.id.textGamepad1);
    textGamepad[1] = (TextView) findViewById(R.id.textGamepad2);
    mOpenCvCameraView = (CameraBridgeViewBase) findViewById(R.id.camerapreview);
    immersion = new ImmersiveMode(getWindow().getDecorView());
    dimmer = new Dimmer(this);
    dimmer.longBright();
    Restarter restarter = new RobotRestarter();

    updateUI = new UpdateUI(this, dimmer);
    updateUI.setRestarter(restarter);
    updateUI.setTextViews(
        textWifiDirectStatus,
        textRobotStatus,
        textGamepad,
        textOpMode,
        textErrorMessage,
        textDeviceName);
    callback = updateUI.new Callback();

    PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
    preferences = PreferenceManager.getDefaultSharedPreferences(this);

    WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
    wifiLock = wifiManager.createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF, "");

    hittingMenuButtonBrightensScreen();

    if (USE_DEVICE_EMULATION) {
      HardwareFactory.enableDeviceEmulation();
    }
  }
예제 #22
0
  @Override
  public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    Log.e(TermDebug.LOG_TAG, "onCreate");
    mPrefs = PreferenceManager.getDefaultSharedPreferences(this);
    mSettings = new TermSettings(getResources(), mPrefs);

    Intent broadcast = new Intent(ACTION_PATH_BROADCAST);
    if (AndroidCompat.SDK >= 12) {
      broadcast.addFlags(FLAG_INCLUDE_STOPPED_PACKAGES);
    }
    mPendingPathBroadcasts++;
    sendOrderedBroadcast(
        broadcast, PERMISSION_PATH_BROADCAST, mPathReceiver, null, RESULT_OK, null, null);

    broadcast = new Intent(broadcast);
    broadcast.setAction(ACTION_PATH_PREPEND_BROADCAST);
    mPendingPathBroadcasts++;
    sendOrderedBroadcast(
        broadcast, PERMISSION_PATH_PREPEND_BROADCAST, mPathReceiver, null, RESULT_OK, null, null);

    TSIntent = new Intent(this, TermService.class);
    startService(TSIntent);

    if (!bindService(TSIntent, mTSConnection, BIND_AUTO_CREATE)) {
      Log.w(TermDebug.LOG_TAG, "bind to service failed!");
    }

    if (AndroidCompat.SDK >= 11) {
      int actionBarMode = mSettings.actionBarMode();
      mActionBarMode = actionBarMode;
      switch (actionBarMode) {
        case TermSettings.ACTION_BAR_MODE_ALWAYS_VISIBLE:
          setTheme(R.style.Theme_Holo);
          break;
        case TermSettings.ACTION_BAR_MODE_HIDES:
          setTheme(R.style.Theme_Holo_ActionBarOverlay);
          break;
      }
    }

    setContentView(R.layout.term_activity);
    mViewFlipper = (TermViewFlipper) findViewById(VIEW_FLIPPER);

    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TermDebug.LOG_TAG);
    WifiManager wm = (WifiManager) getSystemService(Context.WIFI_SERVICE);
    int wifiLockMode = WifiManager.WIFI_MODE_FULL;
    if (AndroidCompat.SDK >= 12) {
      wifiLockMode = WIFI_MODE_FULL_HIGH_PERF;
    }
    mWifiLock = wm.createWifiLock(wifiLockMode, TermDebug.LOG_TAG);

    ActionBarCompat actionBar = ActivityCompat.getActionBar(this);
    if (actionBar != null) {
      mActionBar = actionBar;
      actionBar.setNavigationMode(ActionBarCompat.NAVIGATION_MODE_LIST);
      actionBar.setDisplayOptions(0, ActionBarCompat.DISPLAY_SHOW_TITLE);
      if (mActionBarMode == TermSettings.ACTION_BAR_MODE_HIDES) {
        actionBar.hide();
      }
    }

    mHaveFullHwKeyboard = checkHaveFullHwKeyboard(getResources().getConfiguration());

    updatePrefs();
    mAlreadyStarted = true;
  }
 public WifiLock getNewWifiLock(String lock_postfix) {
   return mManager.createWifiLock(WifiManager.WIFI_MODE_FULL, WIFI_LOCK_TAG + lock_postfix);
 }
예제 #24
0
  public static void init(Context context) throws Exception {
    mContext = context;
    try {
      Logger.debug("initializing System...");
      mStoragePath =
          getSettings()
              .getString("PREF_SAVE_PATH", Environment.getExternalStorageDirectory().toString());
      mSessionName = "csploit-session-" + java.lang.System.currentTimeMillis();
      mKnownIssues = new KnownIssues();
      mPlugins = new ArrayList<Plugin>();
      mOpenPorts = new SparseIntArray(3);

      // if we are here, network initialization didn't throw any error, lock wifi
      WifiManager wifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);

      if (mWifiLock == null)
        mWifiLock = wifiManager.createWifiLock(WifiManager.WIFI_MODE_FULL, "wifiLock");

      if (!mWifiLock.isHeld()) mWifiLock.acquire();

      // wake lock if enabled
      if (getSettings().getBoolean("PREF_WAKE_LOCK", true)) {
        PowerManager powerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);

        if (mWakeLock == null)
          mWakeLock = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, "wakeLock");

        if (!mWakeLock.isHeld()) mWakeLock.acquire();
      }

      // set ports
      try {
        HTTP_PROXY_PORT = Integer.parseInt(getSettings().getString("PREF_HTTP_PROXY_PORT", "8080"));
        HTTP_SERVER_PORT =
            Integer.parseInt(getSettings().getString("PREF_HTTP_SERVER_PORT", "8081"));
        HTTPS_REDIR_PORT =
            Integer.parseInt(getSettings().getString("PREF_HTTPS_REDIRECTOR_PORT", "8082"));
        MSF_RPC_PORT = Integer.parseInt(getSettings().getString("MSF_RPC_PORT", "55553"));
      } catch (NumberFormatException e) {
        HTTP_PROXY_PORT = 8080;
        HTTP_SERVER_PORT = 8081;
        HTTPS_REDIR_PORT = 8082;
        MSF_RPC_PORT = 55553;
      }

      // initialize network data at the end
      mNetwork = new Network(mContext);

      Target network = new Target(mNetwork),
          gateway = new Target(mNetwork.getGatewayAddress(), mNetwork.getGatewayHardware()),
          device = new Target(mNetwork.getLocalAddress(), mNetwork.getLocalHardware());

      gateway.setAlias(mNetwork.getSSID());
      device.setAlias(android.os.Build.MODEL);

      mTargets.add(network);
      mTargets.add(gateway);
      mTargets.add(device);

      mInitialized = true;
    } catch (Exception e) {
      if (!(e instanceof NoRouteToHostException)) errorLogging(e);

      throw e;
    }
  }