Esempio n. 1
0
  @Override
  public void onResume() {
    super.onResume();

    updateState(true);
    lookupRingtoneNames();

    IntentFilter filter = new IntentFilter(AudioManager.RINGER_MODE_CHANGED_ACTION);
    getActivity().registerReceiver(mReceiver, filter);

    /*Begin: mzikun add for settings menu*/
    if (mReverseCallMute != null) {
      boolean checked = Settings.System.getInt(getContentResolver(), "reversal_mute", 0) != 0;
      mReverseCallMute.setChecked(checked);
      mReverseCallMute.setSummary(
          checked ? R.string.reversal_call_off_summary : R.string.reversal_call_on_summary);
    }

    if (mReverseMP3Mute != null) {
      boolean checked = Settings.System.getInt(getContentResolver(), "reversal_mp3_mute", 0) != 0;
      mReverseMP3Mute.setChecked(checked);
    }

    if (mReverseMP4Mute != null) {
      boolean checked = Settings.System.getInt(getContentResolver(), "reversal_mp4_mute", 0) != 0;
      mReverseMP4Mute.setChecked(checked);
    }
    /*End: mzikun add for settings menu*/
  }
Esempio n. 2
0
  @Override
  public boolean getScreenEnableState(long subId, Activity activity) {
    boolean simReady =
        TelephonyManager.SIM_STATE_READY
            == TelephonyManager.getDefault().getSimState(SubscriptionManager.getSlotId(subId));
    boolean airplaneModeEnabled =
        android.provider.Settings.System.getInt(
                activity.getContentResolver(),
                android.provider.Settings.System.AIRPLANE_MODE_ON,
                -1)
            == 1;

    boolean isMMsNoTransac = isMMSNotTransaction(activity);
    boolean isMultiSimMode = true;
    if (FeatureOption.MTK_GEMINI_SUPPORT) {
      int multiMode =
          Settings.System.getInt(
              activity.getContentResolver(), Settings.System.MSIM_MODE_SETTING, -1);
      isMultiSimMode = multiMode != 0;
    }
    Log.d(
        TAG,
        "subId = "
            + subId
            + ",isMMsNoTransac = "
            + isMMsNoTransac
            + " ,airplaneModeEnabled = "
            + airplaneModeEnabled
            + " ,simReady = "
            + simReady
            + " , isMultiSimMode = "
            + isMultiSimMode);
    return isMMsNoTransac && !airplaneModeEnabled && simReady && isMultiSimMode;
  }
  private void updateState() {
    readFontSizePreference(mFontSizePref);
    updateScreenSaverSummary();

    // Update auto brightness if it is available.
    if (mAutoBrightnessPreference != null) {
      int brightnessMode =
          Settings.System.getInt(
              getContentResolver(), SCREEN_BRIGHTNESS_MODE, SCREEN_BRIGHTNESS_MODE_MANUAL);
      mAutoBrightnessPreference.setChecked(brightnessMode != SCREEN_BRIGHTNESS_MODE_MANUAL);
    }

    // Update lift-to-wake if it is available.
    if (mLiftToWakePreference != null) {
      int value = Settings.Secure.getInt(getContentResolver(), WAKE_GESTURE_ENABLED, 0);
      mLiftToWakePreference.setChecked(value != 0);
    }

    // Update proximity wake if it is available.
    if (mProximityWakePreference != null) {
      boolean defaultValue =
          getResources()
              .getBoolean(com.android.internal.R.bool.config_proximityCheckOnWakeEnabledByDefault);
      boolean enabled =
          Settings.System.getInt(
                  getContentResolver(), Settings.System.PROXIMITY_ON_WAKE, defaultValue ? 1 : 0)
              == 1;
      mProximityWakePreference.setChecked(enabled);
    }
  }
    @Override
    public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);

      // Load the preferences from an XML resource
      addPreferencesFromResource(R.xml.prefs_statusbar_toggles);

      mEnabledToggles = findPreference(PREF_ENABLE_TOGGLES);

      mBrightnessLocation = (ListPreference) findPreference(PREF_BRIGHTNESS_LOC);
      mBrightnessLocation.setOnPreferenceChangeListener(this);
      mBrightnessLocation.setValue(
          Integer.toString(
              Settings.System.getInt(
                  getActivity().getContentResolver(),
                  Settings.System.STATUSBAR_TOGGLES_BRIGHTNESS_LOC,
                  1)));

      mToggleStyle = (ListPreference) findPreference(PREF_TOGGLES_STYLE);
      mToggleStyle.setOnPreferenceChangeListener(this);
      mToggleStyle.setValue(
          Integer.toString(
              Settings.System.getInt(
                  getActivity().getContentResolver(), Settings.System.STATUSBAR_TOGGLES_STYLE, 3)));

      mAlternateButtonLayout = (CheckBoxPreference) findPreference(PREF_ALT_BUTTON_LAYOUT);
      mAlternateButtonLayout.setChecked(
          Settings.System.getInt(
                  getContentResolver(), Settings.System.STATUSBAR_TOGGLES_USE_BUTTONS, 0)
              == 1);
    }
  private void refreshDefault() {
    ContentResolver resolver = getContentResolver();
    Resources res = getResources();

    if (mLowColorPref != null) {
      int lowColor =
          Settings.System.getInt(
              resolver,
              Settings.System.BATTERY_LIGHT_LOW_COLOR,
              res.getInteger(com.android.internal.R.integer.config_notificationsBatteryLowARGB));
      mLowColorPref.setAllValues(lowColor, 0, 0, false);
    }

    if (mMediumColorPref != null) {
      int mediumColor =
          Settings.System.getInt(
              resolver,
              Settings.System.BATTERY_LIGHT_MEDIUM_COLOR,
              res.getInteger(com.android.internal.R.integer.config_notificationsBatteryMediumARGB));
      mMediumColorPref.setAllValues(mediumColor, 0, 0, false);
    }

    if (mFullColorPref != null) {
      int fullColor =
          Settings.System.getInt(
              resolver,
              Settings.System.BATTERY_LIGHT_FULL_COLOR,
              res.getInteger(com.android.internal.R.integer.config_notificationsBatteryFullARGB));
      mFullColorPref.setAllValues(fullColor, 0, 0, false);
    }
  }
 /**
  * On GSM devices, we never use short tones. On CDMA devices, it depends upon the settings. TODO:
  * I don't think this has anything to do with GSM versus CDMA, should we be looking only at the
  * setting?
  */
 /* package */ static boolean useShortDtmfTones(Phone phone, Context context) {
   int toneType;
   int phoneType = phone.getPhoneType();
   if (phoneType == Phone.PHONE_TYPE_GSM) {
     return false;
   } else if (phoneType == Phone.PHONE_TYPE_CDMA) {
     if (TelephonyManager.getDefault().isMultiSimEnabled()) {
       toneType =
           android.provider.Settings.System.getInt(
               context.getContentResolver(),
               Settings.System.DTMF_TONE_TYPE_WHEN_DIALING,
               MSimCallFeaturesSetting.DTMF_TONE_TYPE_NORMAL);
     } else {
       toneType =
           android.provider.Settings.System.getInt(
               context.getContentResolver(),
               Settings.System.DTMF_TONE_TYPE_WHEN_DIALING,
               CallFeaturesSetting.DTMF_TONE_TYPE_NORMAL);
     }
     if (toneType == CallFeaturesSetting.DTMF_TONE_TYPE_NORMAL) {
       return true;
     } else {
       return false;
     }
   } else if (phoneType == Phone.PHONE_TYPE_SIP) {
     return false;
   } else {
     throw new IllegalStateException("Unexpected phone type: " + phoneType);
   }
 }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    addPreferencesFromResource(R.xml.input_methods_settings);

    mDisableFullscreenKeyboard =
        (CheckBoxPreference) findPreference(PREF_DISABLE_FULLSCREEN_KEYBOARD);
    mDisableFullscreenKeyboard.setChecked(
        Settings.System.getInt(getContentResolver(), Settings.System.DISABLE_FULLSCREEN_KEYBOARD, 0)
            == 1);
    mDisableFullscreenKeyboard.setOnPreferenceChangeListener(this);

    // Enable or disable mStatusBarImeSwitcher based on boolean value: config_show_cmIMESwitcher
    final Preference keyImeSwitcherPref = findPreference(KEY_IME_SWITCHER);
    if (keyImeSwitcherPref != null) {
      if (!getResources().getBoolean(com.android.internal.R.bool.config_show_IMESwitcher)) {
        getPreferenceScreen().removePreference(keyImeSwitcherPref);
      } else {
        mStatusBarImeSwitcher = (CheckBoxPreference) keyImeSwitcherPref;
        mStatusBarImeSwitcher.setOnPreferenceChangeListener(this);
      }
    }

    mVolumeKeyCursorControl = (ListPreference) findPreference(VOLUME_KEY_CURSOR_CONTROL);
    if (mVolumeKeyCursorControl != null) {
      mVolumeKeyCursorControl.setValue(
          Integer.toString(
              Settings.System.getInt(
                  getContentResolver(), Settings.System.VOLUME_KEY_CURSOR_CONTROL, 0)));
      mVolumeKeyCursorControl.setSummary(mVolumeKeyCursorControl.getEntry());
      mVolumeKeyCursorControl.setOnPreferenceChangeListener(this);
    }

    mKeyboardRotationToggle = (CheckBoxPreference) findPreference(KEYBOARD_ROTATION_TOGGLE);
    mKeyboardRotationToggle.setChecked(
        Settings.System.getInt(getContentResolver(), Settings.System.KEYBOARD_ROTATION_TIMEOUT, 0)
            > 0);
    mKeyboardRotationToggle.setOnPreferenceChangeListener(this);

    mKeyboardRotationTimeout = (ListPreference) findPreference(KEYBOARD_ROTATION_TIMEOUT);
    mKeyboardRotationTimeout.setOnPreferenceChangeListener(this);
    updateRotationTimeout(
        Settings.System.getInt(
            getContentResolver(),
            Settings.System.KEYBOARD_ROTATION_TIMEOUT,
            KEYBOARD_ROTATION_TIMEOUT_DEFAULT));

    mShowEnterKey = (CheckBoxPreference) findPreference(SHOW_ENTER_KEY);
    mShowEnterKey.setChecked(
        Settings.System.getInt(getContentResolver(), Settings.System.FORMAL_TEXT_INPUT, 0) == 1);
    mShowEnterKey.setOnPreferenceChangeListener(this);
  }
Esempio n. 8
0
 final void updateClock() {
   AM_PM_STYLE = Settings.System.getInt(getContext().getContentResolver(), "status_bar_am_pm", 0);
   Text_Size = Settings.System.getInt(getContext().getContentResolver(), "tweaks_clock_size", 1);
   if (Settings.System.getInt(getContext().getContentResolver(), "tweaks_clock_text_font", 0) == 1)
     ;
   {
     mCalendar.setTimeInMillis(System.currentTimeMillis());
     setTextColor(mClockColor);
     updateTypeface();
     setText(getSmallTime());
   }
 }
  private void updateDisplayRotationPreferenceDescription() {
    if (mDisplayRotationPreference == null) {
      // The preference was removed, do nothing
      return;
    }

    // We have a preference, lets update the summary
    boolean rotationEnabled =
        Settings.System.getInt(getContentResolver(), Settings.System.ACCELEROMETER_ROTATION, 0)
            != 0;

    if (!rotationEnabled) {
      mDisplayRotationPreference.setSummary(R.string.display_rotation_disabled);
      return;
    }

    StringBuilder summary = new StringBuilder();
    int mode =
        Settings.System.getInt(
            getContentResolver(),
            Settings.System.ACCELEROMETER_ROTATION_ANGLES,
            DisplayRotation.ROTATION_0_MODE
                | DisplayRotation.ROTATION_90_MODE
                | DisplayRotation.ROTATION_270_MODE);
    ArrayList<String> rotationList = new ArrayList<String>();
    String delim = "";

    if ((mode & DisplayRotation.ROTATION_0_MODE) != 0) {
      rotationList.add("0");
    }
    if ((mode & DisplayRotation.ROTATION_90_MODE) != 0) {
      rotationList.add("90");
    }
    if ((mode & DisplayRotation.ROTATION_180_MODE) != 0) {
      rotationList.add("180");
    }
    if ((mode & DisplayRotation.ROTATION_270_MODE) != 0) {
      rotationList.add("270");
    }
    for (int i = 0; i < rotationList.size(); i++) {
      summary.append(delim).append(rotationList.get(i));
      if ((rotationList.size() - i) > 2) {
        delim = ", ";
      } else {
        delim = " & ";
      }
    }
    summary.append(" " + getString(R.string.display_rotation_unit));
    mDisplayRotationPreference.setSummary(summary);
  }
 @Override
 public void onResume() {
   super.onResume();
   mAirplaneModeEnabled =
       android.provider.Settings.System.getInt(
               getContentResolver(), android.provider.Settings.System.AIRPLANE_MODE_ON, -1)
           == 1;
   if (GeminiUtils.isGeminiSupport()) {
     mDualSimMode =
         android.provider.Settings.System.getInt(
             getContentResolver(), android.provider.Settings.System.DUAL_SIM_MODE_SETTING, -1);
   }
   updateScreen();
 }
  /**
   * 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);
    }
  }
  @Override
  public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
    if (preference == mEnableNavigationBar) {

      Settings.System.putInt(
          mContentRes,
          Settings.System.NAVIGATION_BAR_SHOW,
          ((CheckBoxPreference) preference).isChecked() ? 1 : 0);
      Helpers.restartSystemUI();
      return true;
    } else if (preference == mColorizeAllIcons) {
      Settings.System.putBoolean(
          mContentRes,
          Settings.System.NAVIGATION_BAR_ALLCOLOR,
          ((CheckBoxPreference) preference).isChecked() ? true : false);
      return true;
    } else if (preference == mNavBarHideEnable) {
      Settings.System.putBoolean(
          mContentRes,
          Settings.System.NAV_HIDE_ENABLE,
          ((CheckBoxPreference) preference).isChecked());
      mDragHandleOpacity.setInitValue(
          Settings.System.getInt(
              getActivity().getContentResolver(), Settings.System.DRAG_HANDLE_OPACITY, 50));
      mDragHandleWidth.setInitValue(
          Settings.System.getInt(
              getActivity().getContentResolver(), Settings.System.DRAG_HANDLE_WEIGHT, 5));
      mNavBarHideTimeout.setValue(
          Settings.System.getInt(
                  getActivity().getContentResolver(), Settings.System.NAV_HIDE_TIMEOUT, 3000)
              + "");
      refreshSettings();
      return true;
    } else if (preference == mConfigureWidgets) {
      FragmentTransaction ft = getFragmentManager().beginTransaction();
      WidgetConfigurationFragment fragment = new WidgetConfigurationFragment();
      ft.addToBackStack("config_widgets");
      ft.replace(this.getId(), fragment);
      ft.commit();
      return true;
    } else if (preference == mMenuArrowKeysCheckBox) {
      Settings.System.putBoolean(
          mContentRes,
          Settings.System.NAVIGATION_BAR_MENU_ARROW_KEYS,
          ((CheckBoxPreference) preference).isChecked());
      return true;
    }
    return super.onPreferenceTreeClick(preferenceScreen, preference);
  }
  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();
  }
 void saveSettings() {
   if (!PreferenceManager.getDefaultSharedPreferences(Receiver.mContext)
       .getBoolean(
           org.sipdroid.sipua.ui.Settings.PREF_OLDVALID,
           org.sipdroid.sipua.ui.Settings.DEFAULT_OLDVALID)) {
     int oldvibrate = am.getVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER);
     int oldvibrate2 = am.getVibrateSetting(AudioManager.VIBRATE_TYPE_NOTIFICATION);
     if (!PreferenceManager.getDefaultSharedPreferences(Receiver.mContext)
         .contains(org.sipdroid.sipua.ui.Settings.PREF_OLDVIBRATE2))
       oldvibrate2 = AudioManager.VIBRATE_SETTING_ON;
     int oldpolicy =
         android.provider.Settings.System.getInt(
             cr,
             android.provider.Settings.System.WIFI_SLEEP_POLICY,
             Settings.System.WIFI_SLEEP_POLICY_DEFAULT);
     Editor edit = PreferenceManager.getDefaultSharedPreferences(Receiver.mContext).edit();
     edit.putInt(org.sipdroid.sipua.ui.Settings.PREF_OLDVIBRATE, oldvibrate);
     edit.putInt(org.sipdroid.sipua.ui.Settings.PREF_OLDVIBRATE2, oldvibrate2);
     edit.putInt(org.sipdroid.sipua.ui.Settings.PREF_OLDPOLICY, oldpolicy);
     edit.putInt(
         org.sipdroid.sipua.ui.Settings.PREF_OLDRING,
         am.getStreamVolume(AudioManager.STREAM_RING));
     edit.putBoolean(org.sipdroid.sipua.ui.Settings.PREF_OLDVALID, true);
     edit.commit();
   }
 }
 private void updateSettings() {
   ContentResolver resolver = mContext.getContentResolver();
   mSignalClusterStyle =
       (Settings.System.getInt(
           resolver, Settings.System.STATUS_BAR_SIGNAL_TEXT, SIGNAL_CLUSTER_STYLE_NORMAL));
   updateSignalClusterStyle();
 }
 private void setSwitchState() {
   boolean enabled =
       Settings.System.getInt(mContext.getContentResolver(), Settings.System.VOICE_WAKEUP, 0) == 1;
   mStateMachineEvent = true;
   mSwitch.setChecked(enabled);
   mStateMachineEvent = false;
 }
  public BatteryMeterView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    mHandler = new Handler();

    final Resources res = context.getResources();
    TypedArray levels = res.obtainTypedArray(R.array.batterymeter_color_levels);
    TypedArray colors = res.obtainTypedArray(R.array.batterymeter_color_values);

    final int N = levels.length();
    mColors = new int[2 * N];
    for (int i = 0; i < N; i++) {
      mColors[2 * i] = levels.getInt(i, 0);
      mColors[2 * i + 1] = colors.getColor(i, 0);
    }
    levels.recycle();
    colors.recycle();
    mShowPercent =
        ENABLE_PERCENT
            && 0
                != Settings.System.getInt(
                    context.getContentResolver(), "status_bar_show_battery_percent", 0);

    mChargeColor = getResources().getColor(R.color.batterymeter_charge_color);

    mWarningString = context.getString(R.string.battery_meter_very_low_overlay_symbol);

    mMeterMode = BatteryMeterMode.BATTERY_METER_ICON_PORTRAIT;
    mBatteryMeterDrawable = createBatteryMeterDrawable(mMeterMode);

    setLayerType(View.LAYER_TYPE_SOFTWARE, null);
  }
  private void parseClockDateFormats() {
    // Parse and repopulate mClockDateFormats's entries based on current date.
    String[] dateEntries = getResources().getStringArray(R.array.clock_date_format_entries_values);
    CharSequence parsedDateEntries[];
    parsedDateEntries = new String[dateEntries.length];
    Date now = new Date();

    int lastEntry = dateEntries.length - 1;
    int dateFormat =
        Settings.System.getInt(
            getActivity().getContentResolver(), Settings.System.STATUSBAR_CLOCK_DATE_STYLE, 2);
    for (int i = 0; i < dateEntries.length; i++) {
      if (i == lastEntry) {
        parsedDateEntries[i] = dateEntries[i];
      } else {
        String newDate;
        CharSequence dateString = DateFormat.format(dateEntries[i], now);
        if (dateFormat == CLOCK_DATE_STYLE_LOWERCASE) {
          newDate = dateString.toString().toLowerCase();
        } else if (dateFormat == CLOCK_DATE_STYLE_UPPERCASE) {
          newDate = dateString.toString().toUpperCase();
        } else {
          newDate = dateString.toString();
        }

        parsedDateEntries[i] = newDate;
      }
    }
    mClockDateFormat.setEntries(parsedDateEntries);
  }
  @Override
  public void onReceive(final Context context, Intent intent) {
    try {
      // Start the load average overlay, if activated
      ContentResolver res = context.getContentResolver();
      if (Settings.System.getInt(res, Settings.System.SHOW_PROCESSES, 0) != 0) {
        Intent loadavg = new Intent(context, com.android.server.LoadAverageService.class);
        context.startService(loadavg);
      }
    } catch (Exception e) {
      Slog.e(TAG, "Can't start load average service", e);
    }

    // Log boot events in the background to avoid blocking the main thread with I/O
    new Thread() {
      @Override
      public void run() {
        try {
          logBootEvents(context);
        } catch (Exception e) {
          Slog.e(TAG, "Can't log boot events", e);
        }
        try {
          removeOldUpdatePackages(context);
        } catch (Exception e) {
          Slog.e(TAG, "Can't remove old update packages", e);
        }
      }
    }.start();
  }
Esempio n. 20
0
  /** Save current audio mode in order to be able to restore it once done */
  @SuppressWarnings("deprecation")
  private synchronized void saveAudioState() {
    if (prefs.getBoolean("isSavedAudioState", false)) {
      // If we have already set, do not set it again !!!
      return;
    }
    ContentResolver ctntResolver = service.getContentResolver();

    Editor ed = prefs.edit();
    // ed.putInt("savedVibrateRing",
    // audioManager.getVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER));
    // ed.putInt("savedVibradeNotif",
    // audioManager.getVibrateSetting(AudioManager.VIBRATE_TYPE_NOTIFICATION));
    // ed.putInt("savedRingerMode", audioManager.getRingerMode());
    ed.putInt(
        "savedWifiPolicy",
        android.provider.Settings.System.getInt(
            ctntResolver,
            android.provider.Settings.System.WIFI_SLEEP_POLICY,
            Settings.System.WIFI_SLEEP_POLICY_DEFAULT));

    int inCallStream = Compatibility.getInCallStream(userWantBluetooth);
    ed.putInt("savedVolume", audioManager.getStreamVolume(inCallStream));

    int targetMode = getAudioTargetMode();
    if (service.getPrefs().useRoutingApi()) {
      ed.putInt("savedRoute", audioManager.getRouting(targetMode));
    } else {
      ed.putBoolean("savedSpeakerPhone", audioManager.isSpeakerphoneOn());
    }
    ed.putInt("savedMode", audioManager.getMode());

    ed.putBoolean("isSavedAudioState", true);
    ed.commit();
  }
Esempio n. 21
0
 /**
  * Initialize unread number by querying system settings provider.
  *
  * @param context
  */
 private void initUnreadNumberFromSystem() {
   final ContentResolver cr = mContext.getContentResolver();
   final int shortcutsNum = sUnreadSupportShortcutsNum;
   UnreadSupportShortcut shortcut = null;
   for (int i = 0; i < shortcutsNum; i++) {
     shortcut = UNREAD_SUPPORT_SHORTCUTS.get(i);
     try {
       shortcut.mUnreadNum = android.provider.Settings.System.getInt(cr, shortcut.mKey);
       if (LauncherLog.DEBUG_UNREAD) {
         LauncherLog.d(
             TAG,
             "initUnreadNumberFromSystem: key = "
                 + shortcut.mKey
                 + ", unreadNum = "
                 + shortcut.mUnreadNum);
       }
     } catch (android.provider.Settings.SettingNotFoundException e) {
       LauncherLog.e(
           TAG,
           "initUnreadNumberFromSystem SettingNotFoundException key = "
               + shortcut.mKey
               + ", e = "
               + e.getMessage());
     }
   }
   if (LauncherLog.DEBUG_UNREAD) {
     LauncherLog.d(TAG, "initUnreadNumberFromSystem end:" + getUnreadSupportShortcutInfo());
   }
 }
  // updateState in fact updates the UI to reflect the system state
  private void updateState(boolean force) {
    final int ringerMode = mAudioManager.getRingerMode();

    // NB: in the UI we now simply call this "silent mode". A separate
    // setting controls whether we're in RINGER_MODE_SILENT or
    // RINGER_MODE_VIBRATE.
    final boolean silentOrVibrateMode = ringerMode != AudioManager.RINGER_MODE_NORMAL;

    if (silentOrVibrateMode != mSilent.isChecked() || force) {
      mSilent.setChecked(silentOrVibrateMode);
    }

    String phoneVibrateSetting = getPhoneVibrateSettingValue();

    if (!phoneVibrateSetting.equals(mVibrate.getValue()) || force) {
      mVibrate.setValue(phoneVibrateSetting);
    }
    mVibrate.setSummary(mVibrate.getEntry());

    int silentModeStreams =
        Settings.System.getInt(
            getContentResolver(), Settings.System.MODE_RINGER_STREAMS_AFFECTED, 0);
    boolean isAlarmInclSilentMode = (silentModeStreams & (1 << AudioManager.STREAM_ALARM)) != 0;
    mSilent.setSummary(
        isAlarmInclSilentMode
            ? R.string.silent_mode_incl_alarm_summary
            : R.string.silent_mode_summary);
  }
  private String getPhoneVibrateSettingValue() {
    boolean vibeInSilent =
        (Settings.System.getInt(getContentResolver(), Settings.System.VIBRATE_IN_SILENT, 1) == 1);

    // Control phone vibe independent of silent mode
    int callsVibrateSetting = mAudioManager.getVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER);

    if (vibeInSilent) {
      if (callsVibrateSetting == AudioManager.VIBRATE_SETTING_OFF) {
        // this state does not make sense; fix it up for the user
        mAudioManager.setVibrateSetting(
            AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_ONLY_SILENT);
      }
      if (callsVibrateSetting == AudioManager.VIBRATE_SETTING_ON) {
        return VALUE_VIBRATE_ALWAYS;
      } else {
        return VALUE_VIBRATE_ONLY_SILENT;
      }
    } else {
      if (callsVibrateSetting == AudioManager.VIBRATE_SETTING_ONLY_SILENT) {
        // this state does not make sense; fix it up
        mAudioManager.setVibrateSetting(
            AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_OFF);
      }
      if (callsVibrateSetting == AudioManager.VIBRATE_SETTING_ON) {
        return VALUE_VIBRATE_UNLESS_SILENT;
      } else {
        return VALUE_VIBRATE_NEVER;
      }
    }
  }
  public void refreshSettings() {

    int lockscreenTargets =
        Settings.System.getInt(getContentResolver(), Settings.System.LOCKSCREEN_LAYOUT, 2);

    PreferenceGroup targetGroup = (PreferenceGroup) findPreference("lockscreen_targets");
    targetGroup.removeAll();

    // quad only uses first 4, but we make the system think there's 6 for the alternate layout
    // so only show 4
    if (lockscreenTargets == 6) {
      Settings.System.putString(
          getContentResolver(), Settings.System.LOCKSCREEN_CUSTOM_APP_ACTIVITIES[4], "**null**");
      Settings.System.putString(
          getContentResolver(), Settings.System.LOCKSCREEN_CUSTOM_APP_ACTIVITIES[5], "**null**");
      lockscreenTargets = 4;
    }

    for (int i = 0; i < lockscreenTargets; i++) {
      ListPreference p = new ListPreference(getActivity());
      String dialogTitle =
          String.format(getResources().getString(R.string.custom_app_n_dialog_title), i + 1);
      ;
      p.setDialogTitle(dialogTitle);
      p.setEntries(R.array.lockscreen_choice_entries);
      p.setEntryValues(R.array.lockscreen_choice_values);
      String title = String.format(getResources().getString(R.string.custom_app_n), i + 1);
      p.setTitle(title);
      p.setKey("lockscreen_target_" + i);
      p.setSummary(getProperSummary(i));
      p.setOnPreferenceChangeListener(this);
      targetGroup.addPreference(p);
    }
  }
 private int readColor() {
   try {
     return Settings.System.getInt(getContentResolver(), mSetting);
   } catch (SettingNotFoundException e) {
     return mDefaultColor;
   }
 }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (getPreferenceManager() != null) {
      addPreferencesFromResource(R.xml.operator_preferences);
      PreferenceScreen prefSet = getPreferenceScreen();

      mOperatorDisplayStyle = (ListPreference) prefSet.findPreference(OPERATOR_STYLE);
      mOperatorDisplayStyle.setOnPreferenceChangeListener(this);

      mOperatorDisplayText = (EditTextPreference) prefSet.findPreference(OPERATOR_TEXT);
      mOperatorDisplayText.setOnPreferenceChangeListener(this);

      if (mOperatorDisplayText != null) {
        String operLabel = mOperatorDisplayText.getText();
        if (TextUtils.isEmpty(operLabel)) {
          mOperatorDisplayText.setSummary(getString(R.string.operator_display_summary));
        } else {
          mOperatorDisplayText.setSummary(mOperatorDisplayText.getText());
        }
      }

      int index = Settings.System.getInt(getContentResolver(), CARRIER_LABEL_TYPE, 0);
      index = index > (mOperatorDisplayStyle.getEntries().length - 1) ? 0 : index;
      mOperatorDisplayStyle.setSummary(mOperatorDisplayStyle.getEntries()[index]);

      mOperatorDisplayText.setEnabled(index == 3);
    }
  }
Esempio n. 27
0
 @Override
 public int getScreenBrightness() throws ScreenSenseException {
   // Return 0 if the screen if off
   if (screenOn < 1) return 0;
   else {
     int currentBrightnessMode = getScreenBrightnessMode();
     if (currentBrightnessMode == Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL) {
       // Manual screen brightness: no problem
       try {
         return android.provider.Settings.System.getInt(
             contentResolver, android.provider.Settings.System.SCREEN_BRIGHTNESS);
       } catch (Exception e) {
         throw new ScreenSenseException(
             "Error while getting screen brightness ( " + e.getMessage() + ")");
       }
     } else {
       // auto brightness mode: available if the path is kwnown
       if (brightness_path != null) {
         try {
           return getValue(brightness_path);
         } catch (Exception e) {
           throw new ScreenSenseException(
               "Error while getting screen brightness ( " + e.getMessage() + ")");
         }
       } else
         throw new ScreenSenseException(
             "Error while init screen brightness path (Current path: " + brightness_path + ")");
     }
   }
 }
 private void updateRotationCheckbox() {
   // Auto-rotate screen
   final boolean autoRotationEnabled =
       Settings.System.getInt(getContentResolver(), Settings.System.ACCELEROMETER_ROTATION, 0)
           != 0;
   mToggleAutoRotateScreenPreference.setChecked(autoRotationEnabled);
 }
  private void playSounds(boolean locked) {
    // User feedback for keyguard.

    if (mSuppressNextLockSound) {
      mSuppressNextLockSound = false;
      return;
    }

    final ContentResolver cr = mContext.getContentResolver();
    if (Settings.System.getInt(cr, Settings.System.LOCKSCREEN_SOUNDS_ENABLED, 1) == 1) {
      final String whichSound = locked ? Settings.System.LOCK_SOUND : Settings.System.UNLOCK_SOUND;
      final String soundPath = Settings.System.getString(cr, whichSound);
      if (soundPath != null) {
        final Uri soundUri = Uri.parse("file://" + soundPath);
        if (soundUri != null) {
          final Ringtone sfx = RingtoneManager.getRingtone(mContext, soundUri);
          if (sfx != null) {
            sfx.setStreamType(AudioManager.STREAM_SYSTEM);
            sfx.play();
          } else {
            Log.d(TAG, "playSounds: failed to load ringtone from uri: " + soundUri);
          }
        } else {
          Log.d(TAG, "playSounds: could not parse Uri: " + soundPath);
        }
      } else {
        Log.d(TAG, "playSounds: whichSound = " + whichSound + "; soundPath was null");
      }
    }
  }
Esempio n. 30
0
  int updateSleepPolicy() {
    ContentResolver cr = getContentResolver();
    int get =
        android.provider.Settings.System.getInt(
            cr, android.provider.Settings.System.WIFI_SLEEP_POLICY, -1);
    int set = get;
    boolean wlan = false, g3 = true, valid = false;
    for (int i = 0; i < SipdroidEngine.LINES; i++) {
      String j = (i != 0 ? "" + i : "");
      if (!settings.getString(PREF_USERNAME + j, "").equals("")
          && !settings.getString(PREF_SERVER + j, "").equals("")) {
        valid = true;
        wlan |= settings.getBoolean(PREF_WLAN + j, DEFAULT_WLAN);
        g3 &=
            settings.getBoolean(PREF_3G + j, DEFAULT_3G)
                || settings.getBoolean(PREF_EDGE + j, DEFAULT_EDGE);
      }
    }
    boolean ownwifi = settings.getBoolean(PREF_OWNWIFI, DEFAULT_OWNWIFI);

    if (g3 && valid && !ownwifi) {
      set = android.provider.Settings.System.WIFI_SLEEP_POLICY_DEFAULT;
    } else if (wlan || ownwifi) {
      set = android.provider.Settings.System.WIFI_SLEEP_POLICY_NEVER;
    }
    return set;
  }