Exemple #1
0
  public BrightnessController(Context context, ImageView icon, ToggleSlider control) {
    mContext = context;
    mIcon = icon;
    mControl = control;
    mHandler = new Handler();
    mUserTracker =
        new CurrentUserTracker(mContext) {
          @Override
          public void onUserSwitched(int newUserId) {
            updateMode();
            updateSlider();
          }
        };
    mBrightnessObserver = new BrightnessObserver(mHandler);

    PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    mMinimumBacklight = pm.getMinimumScreenBrightnessSetting();
    mMaximumBacklight = pm.getMaximumScreenBrightnessSetting();

    mAutomaticAvailable =
        context
            .getResources()
            .getBoolean(com.android.internal.R.bool.config_automatic_brightness_available);
    mPower = IPowerManager.Stub.asInterface(ServiceManager.getService("power"));
  }
 private void setBrightness(int value) {
   if (mPowerManager == null) {
     mPowerManager = IPowerManager.Stub.asInterface(ServiceManager.getService("power"));
   }
   try {
     mPowerManager.setTemporaryScreenBrightnessSettingOverride(value);
   } catch (RemoteException ex) {
     Slog.e(TAG, "Could not set backlight brightness", ex);
   }
   Settings.System.putInt(mContext.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS, value);
 }
Exemple #3
0
  /** Private constructor; @see init() */
  private Ringer(Context context, BluetoothManager bluetoothManager) {
    mContext = context;
    mBluetoothManager = bluetoothManager;
    mPowerManager =
        IPowerManager.Stub.asInterface(ServiceManager.getService(Context.POWER_SERVICE));
    // We don't rely on getSystemService(Context.VIBRATOR_SERVICE) to make sure this
    // vibrator object will be isolated from others.
    mVibrator = new SystemVibrator(context);

    /// M: For MTK Features
    initRingerMtk(context);
  }
 /**
  * Gets state of brightness mode.
  *
  * @param context
  * @return true if auto brightness is on.
  */
 private static boolean getBrightnessMode(Context context) {
   try {
     IPowerManager power = IPowerManager.Stub.asInterface(ServiceManager.getService("power"));
     if (power != null) {
       int brightnessMode =
           Settings.System.getInt(
               context.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS_MODE);
       return brightnessMode == Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC;
     }
   } catch (Exception e) {
     Xlog.d(TAG, "getBrightnessMode: " + e);
   }
   return false;
 }
  /**
   * Increases or decreases the brightness.
   *
   * @param context
   */
  private void toggleBrightness(Context context) {
    try {
      IPowerManager power = IPowerManager.Stub.asInterface(ServiceManager.getService("power"));
      if (power != null) {
        ContentResolver cr = context.getContentResolver();
        int brightness = Settings.System.getInt(cr, Settings.System.SCREEN_BRIGHTNESS);
        int brightnessMode = Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL;
        // Only get brightness setting if available
        if (context
            .getResources()
            .getBoolean(com.android.internal.R.bool.config_automatic_brightness_available)) {
          brightnessMode = Settings.System.getInt(cr, Settings.System.SCREEN_BRIGHTNESS_MODE);
        }

        // Rotate AUTO -> MINIMUM -> DEFAULT -> MAXIMUM
        // Technically, not a toggle...
        if (brightnessMode == Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC) {
          brightness = MINIMUM_BACKLIGHT;
          brightnessMode = Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL;
        } else if (brightness < DEFAULT_BACKLIGHT) {
          brightness = DEFAULT_BACKLIGHT;
        } else if (brightness < MAXIMUM_BACKLIGHT) {
          brightness = MAXIMUM_BACKLIGHT;
        } else {
          brightnessMode = Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC;
          brightness = MINIMUM_BACKLIGHT;
        }

        if (context
            .getResources()
            .getBoolean(com.android.internal.R.bool.config_automatic_brightness_available)) {
          // Set screen brightness mode (automatic or manual)
          Settings.System.putInt(
              context.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS_MODE, brightnessMode);
        } else {
          // Make sure we set the brightness if automatic mode isn't available
          brightnessMode = Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL;
        }
        if (brightnessMode == Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL) {
          power.setBacklightBrightness(brightness);
          Settings.System.putInt(cr, Settings.System.SCREEN_BRIGHTNESS, brightness);
        }
      }
    } catch (RemoteException e) {
      Xlog.d(TAG, "toggleBrightness: " + e);
    } catch (Settings.SettingNotFoundException e) {
      Xlog.d(TAG, "toggleBrightness: " + e);
    }
  }
  public BrightnessSlider(Context context) {
    mContext = context;
    mView = View.inflate(mContext, R.layout.brightness_slider, null);

    mControl = (ToggleSlider) mView.findViewById(R.id.brightness);

    mScreenBrightnessDim =
        mContext
            .getResources()
            .getInteger(com.android.internal.R.integer.config_screenBrightnessDim);

    boolean automaticAvailable =
        context
            .getResources()
            .getBoolean(com.android.internal.R.bool.config_automatic_brightness_available);
    mPower = IPowerManager.Stub.asInterface(ServiceManager.getService("power"));

    if (automaticAvailable) {
      int automatic;
      try {
        automatic =
            Settings.System.getInt(
                mContext.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS_MODE);
      } catch (SettingNotFoundException snfe) {
        automatic = 0;
      }
      mControl.setChecked(automatic != 0);
    } else {
      mControl.setChecked(false);
      // control.hideToggle();
    }

    int value;
    try {
      value =
          Settings.System.getInt(mContext.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS);
    } catch (SettingNotFoundException ex) {
      value = MAXIMUM_BACKLIGHT;
    }

    mControl.setMax(MAXIMUM_BACKLIGHT - mScreenBrightnessDim);
    mControl.setValue(value - mScreenBrightnessDim);

    mControl.setOnChangedListener(this);

    SettingsObserver so = new SettingsObserver(new Handler());
    so.observe();
  }
        public void run() {
          boolean autoLcd =
              Settings.System.getInt(
                      getContentResolver(), Settings.System.SCREEN_BRIGHTNESS_MODE, 1337)
                  == Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC;
          boolean filterEnabled =
              Settings.System.getInt(getContentResolver(), Settings.System.LIGHT_FILTER, 0) != 0;

          try {
            IPowerManager power =
                IPowerManager.Stub.asInterface(ServiceManager.getService("power"));
            if (filterEnabled && autoLcd) {
              mSensor.setText(
                  String.valueOf(power.getLightSensorValue())
                      + " / "
                      + String.valueOf(power.getRawLightSensorValue()));
            } else {
              String value = String.valueOf(power.getLightSensorValue());
              mSensor.setText(value + " / " + value);
            }
            if (autoLcd) {
              mScreen.setText(String.valueOf(power.getLightSensorScreenBrightness()));
            } else {
              mScreen.setText(getString(R.string.ll_disabled));
            }
            mButtons.setText(String.valueOf(power.getLightSensorButtonBrightness()));
            if (mHasKeyboard) {
              mKeyboard.setText(String.valueOf(power.getLightSensorKeyboardBrightness()));
            }
          } catch (Exception e) {
            // Display "-" on any error

            if (autoLcd) {
              mScreen.setText("-");
            } else {
              mScreen.setText(getString(R.string.ll_disabled));
            }

            mSensor.setText("- / -");
            mButtons.setText("-");
            mKeyboard.setText("-");
          }

          mHandler.postDelayed(mUpdateTask, UPDATE_RATE);
        }
 /**
  * Gets state of brightness.
  *
  * @param context
  * @return true if more than moderately bright.
  */
 public static int getBrightness(Context context) {
   if (DBG) {
     Xlog.i(TAG, "getBrightness called.");
   }
   try {
     IPowerManager power = IPowerManager.Stub.asInterface(ServiceManager.getService("power"));
     if (power != null) {
       int brightness =
           Settings.System.getInt(context.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS);
       if (brightness <= MINIMUM_BACKLIGHT) {
         brightness = MINIMUM_BACKLIGHT;
       } else if (brightness <= DEFAULT_BACKLIGHT) {
         brightness = DEFAULT_BACKLIGHT;
       } else {
         brightness = MAXIMUM_BACKLIGHT;
       }
       return brightness;
     }
   } catch (Exception e) {
     Xlog.d(TAG, "getBrightness: " + e);
   }
   return DEFAULT_BACKLIGHT;
 }
Exemple #9
0
  @Override
  public void onCreate() {
    if (Config.LOGV) Log.v(LOG_TAG, "onCreate()...");

    ContentResolver resolver = getContentResolver();

    if (phone == null) {
      // Initialize the telephony framework
      PhoneFactory.makeDefaultPhones(this);

      // Get the default phone
      phone = PhoneFactory.getDefaultPhone();

      NotificationMgr.init(this);

      phoneMgr = new PhoneInterfaceManager(this, phone);
      if (getSystemService(Context.BLUETOOTH_SERVICE) != null) {
        mBtHandsfree = new BluetoothHandsfree(this, phone);
        startService(new Intent(this, BluetoothHeadsetService.class));
      } else {
        // Device is not bluetooth capable
        mBtHandsfree = null;
      }

      ringer = new Ringer(phone);

      // before registering for phone state changes
      PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
      mWakeLock =
          pm.newWakeLock(
              PowerManager.FULL_WAKE_LOCK
                  | PowerManager.ACQUIRE_CAUSES_WAKEUP
                  | PowerManager.ON_AFTER_RELEASE,
              LOG_TAG);
      // lock used to keep the processor awake, when we don't care for the display.
      mPartialWakeLock =
          pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, LOG_TAG);
      mKeyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
      mKeyguardLock = mKeyguardManager.newKeyguardLock(LOG_TAG);

      // get a handle to the service so that we can use it later when we
      // want to set the poke lock.
      mPowerManagerService = IPowerManager.Stub.asInterface(ServiceManager.getService("power"));

      notifier = new CallNotifier(this, phone, ringer, mBtHandsfree);

      // register for ICC status
      IccCard sim = phone.getIccCard();
      if (sim != null) {
        if (Config.LOGV) Log.v(LOG_TAG, "register for ICC status");
        sim.registerForAbsent(mHandler, EVENT_SIM_ABSENT, null);
        sim.registerForLocked(mHandler, EVENT_SIM_LOCKED, null);
        sim.registerForNetworkLocked(mHandler, EVENT_SIM_NETWORK_LOCKED, null);
      }

      // register for MMI/USSD
      phone.registerForMmiComplete(mHandler, MMI_COMPLETE, null);

      // register connection tracking to PhoneUtils
      PhoneUtils.initializeConnectionHandler(phone);

      // Register for misc other intent broadcasts.
      IntentFilter intentFilter = new IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED);
      intentFilter.addAction(BluetoothIntent.HEADSET_STATE_CHANGED_ACTION);
      intentFilter.addAction(BluetoothIntent.HEADSET_AUDIO_STATE_CHANGED_ACTION);
      intentFilter.addAction(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED);
      intentFilter.addAction(Intent.ACTION_HEADSET_PLUG);
      intentFilter.addAction(Intent.ACTION_BATTERY_LOW);
      intentFilter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED);
      intentFilter.addAction(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED);
      intentFilter.addAction(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED);
      intentFilter.addAction(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED);
      intentFilter.addAction(ACTION_VIBRATE_45);
      registerReceiver(mReceiver, intentFilter);

      // Use a separate receiver for ACTION_MEDIA_BUTTON broadcasts,
      // since we need to manually adjust its priority (to make sure
      // we get these intents *before* the media player.)
      IntentFilter mediaButtonIntentFilter = new IntentFilter(Intent.ACTION_MEDIA_BUTTON);
      //
      // Make sure we're higher priority than the media player's
      // MediaButtonIntentReceiver (which currently has the default
      // priority of zero; see apps/Music/AndroidManifest.xml.)
      mediaButtonIntentFilter.setPriority(1);
      //
      registerReceiver(mMediaButtonReceiver, mediaButtonIntentFilter);

      // set the default values for the preferences in the phone.
      PreferenceManager.setDefaultValues(this, R.xml.network_setting, false);
      PreferenceManager.setDefaultValues(this, R.xml.call_feature_setting, false);

      // Make sure the audio mode (along with some
      // audio-mode-related state of our own) is initialized
      // correctly, given the current state of the phone.
      switch (phone.getState()) {
        case IDLE:
          if (DBG) Log.d(LOG_TAG, "Resetting audio state/mode: IDLE");
          PhoneUtils.setAudioControlState(PhoneUtils.AUDIO_IDLE);
          PhoneUtils.setAudioMode(this, AudioManager.MODE_NORMAL);
          break;
        case RINGING:
          if (DBG) Log.d(LOG_TAG, "Resetting audio state/mode: RINGING");
          PhoneUtils.setAudioControlState(PhoneUtils.AUDIO_RINGING);
          PhoneUtils.setAudioMode(this, AudioManager.MODE_RINGTONE);
          break;
        case OFFHOOK:
          if (DBG) Log.d(LOG_TAG, "Resetting audio state/mode: OFFHOOK");
          PhoneUtils.setAudioControlState(PhoneUtils.AUDIO_OFFHOOK);
          PhoneUtils.setAudioMode(this, AudioManager.MODE_IN_CALL);
          break;
      }
    }

    // XXX pre-load the SimProvider so that it's ready
    resolver.getType(Uri.parse("content://icc/adn"));

    // start with the default value to set the mute state.
    mShouldRestoreMuteOnInCallResume = false;

    // add by cytown
    mSettings =
        CallFeaturesSetting.getInstance(PreferenceManager.getDefaultSharedPreferences(this));
    if (mVibrator == null) {
      mVibrator = (Vibrator) this.getSystemService(Context.VIBRATOR_SERVICE);
      mAM = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE);
      mVibrateIntent = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_VIBRATE_45), 0);
    }

    // Register for Cdma Information Records
    // TODO(Moto): Merge
    // phone.registerCdmaInformationRecord(mHandler, EVENT_UNSOL_CDMA_INFO_RECORD, null);

    if (phone.getPhoneName().equals("CDMA")) {
      // Create an instance of CdmaPhoneCallState and initialize it to IDLE
      cdmaPhoneCallState = new CdmaPhoneCallState();
      cdmaPhoneCallState.CdmaPhoneCallStateInit();
    }
  }