public void resume() {
   final ContentResolver cr = mContext.getContentResolver();
   cr.registerContentObserver(
       Settings.Secure.getUriFor(Settings.Secure.DEFAULT_INPUT_METHOD), false, this);
   cr.registerContentObserver(
       Settings.Secure.getUriFor(Settings.Secure.SELECTED_INPUT_METHOD_SUBTYPE), false, this);
 }
  private class SettingsObserver extends ContentObserver {
    private final Uri mSecureSettingsUri = Settings.Secure.getUriFor(mConfig.secureSettingName);

    private SettingsObserver(Handler handler) {
      super(handler);
    }

    private void observe() {
      ContentResolver resolver = mContext.getContentResolver();
      resolver.registerContentObserver(mSecureSettingsUri, false, this, UserHandle.USER_ALL);
      update(null);
    }

    @Override
    public void onChange(boolean selfChange, Uri uri) {
      update(uri);
    }

    private void update(Uri uri) {
      if (uri == null || mSecureSettingsUri.equals(uri)) {
        if (DEBUG)
          Slog.d(
              TAG, "Setting changed: mSecureSettingsUri=" + mSecureSettingsUri + " / uri=" + uri);
        rebindServices();
      }
    }
  }
示例#3
0
  public NetworkAdbTile(Context context, QuickSettingsController qsc) {
    super(context, qsc);

    mOnClick =
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            Settings.Secure.putIntForUser(
                mContext.getContentResolver(),
                Settings.Secure.ADB_PORT,
                isEnabled() ? -1 : 5555,
                UserHandle.USER_CURRENT);
          }
        };
    mOnLongClick =
        new View.OnLongClickListener() {
          @Override
          public boolean onLongClick(View v) {
            startSettingsActivity(Settings.ACTION_APPLICATION_DEVELOPMENT_SETTINGS);
            return true;
          }
        };

    qsc.registerObservedContent(Settings.Secure.getUriFor(Settings.Secure.ADB_PORT), this);
    updateResources();
  }
  @Override
  public void onCreate() {
    super.onCreate();

    final Resources res = getResources();
    mGranularityTypes = res.getStringArray(R.array.granularity_types);
    mGranularitySet = res.getString(R.string.set_granularity);
    mActionTypes = res.getStringArray(R.array.action_types);
    mActionSet = res.getString(R.string.set_action);
    mAltString = res.getString(R.string.alt_pressed);
    mShiftString = res.getString(R.string.shift_pressed);

    mPreviousDpadDownEvent = null;
    mWasUpDownPressed = false;

    mUserCommandHandler = new UserCommandHandler(this);
    mAccessibilityManager = (AccessibilityManager) getSystemService(ACCESSIBILITY_SERVICE);

    // Register content observer to receive accessibility status changes.
    getContentResolver()
        .registerContentObserver(
            Settings.Secure.getUriFor(Settings.Secure.ACCESSIBILITY_ENABLED),
            false,
            mAccessibilityObserver);

    updateAccessibilityState();
  }
 void registerObserver() {
   getContext()
       .getContentResolver()
       .registerContentObserver(
           Settings.Secure.getUriFor(Settings.Secure.APP_IDLE_DURATION),
           false,
           this,
           UserHandle.USER_OWNER);
 }
  private void registerFingerSwitchObserver() {
    readFingerprintSwitchValue();

    mContext
        .getContentResolver()
        .registerContentObserver(
            Settings.Secure.getUriFor(FINGERPRINT_FOR_UNLOCK_SWITCH_KEY),
            false,
            new FingerSwitchContentObserver(mFingerHandler));
  }
 void observe() {
   ContentResolver resolver = mContext.getContentResolver();
   resolver.registerContentObserver(
       Settings.Secure.getUriFor(Settings.Secure.QS_SHOW_BRIGHTNESS_SLIDER),
       false,
       this,
       UserHandle.USER_ALL);
   resolver.registerContentObserver(
       Settings.Secure.getUriFor(Settings.System.QUICK_SETTINGS_TILES_VIBRATE),
       false,
       this,
       UserHandle.USER_ALL);
   resolver.registerContentObserver(
       Settings.Secure.getUriFor(Settings.Secure.QS_USE_FOUR_COLUMNS),
       false,
       this,
       UserHandle.USER_ALL);
   update();
 }
 public void register() {
   if (mRegistered) {
     mContext.getContentResolver().unregisterContentObserver(this);
   }
   mContext
       .getContentResolver()
       .registerContentObserver(
           Settings.Secure.getUriFor(Settings.Secure.QS_TILES),
           false,
           this,
           mUserTracker.getCurrentUserId());
   mContext
       .getContentResolver()
       .registerContentObserver(
           Settings.Secure.getUriFor(Settings.Secure.QS_USE_MAIN_TILES),
           false,
           this,
           mUserTracker.getCurrentUserId());
   mRegistered = true;
 }
  public AssistManager(BaseStatusBar bar, Context context) {
    mContext = context;
    mBar = bar;
    mWindowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
    mAssistUtils = new AssistUtils(context);

    mContext
        .getContentResolver()
        .registerContentObserver(
            Settings.Secure.getUriFor(Settings.Secure.ASSISTANT), false, mAssistSettingsObserver);
    mAssistSettingsObserver.onChange(false);
    mAssistDisclosure = new AssistDisclosure(context, new Handler());
  }
    public UsbHandler(Looper looper) {
      super(looper);
      try {
        // Restore default functions.
        mCurrentFunctions = SystemProperties.get(USB_CONFIG_PROPERTY, UsbManager.USB_FUNCTION_NONE);
        if (UsbManager.USB_FUNCTION_NONE.equals(mCurrentFunctions)) {
          mCurrentFunctions = UsbManager.USB_FUNCTION_MTP;
        }
        mCurrentFunctionsApplied =
            mCurrentFunctions.equals(SystemProperties.get(USB_STATE_PROPERTY));
        mAdbEnabled =
            UsbManager.containsFunction(getDefaultFunctions(), UsbManager.USB_FUNCTION_ADB);
        setEnabledFunctions(null, false);

        String state = FileUtils.readTextFile(new File(STATE_PATH), 0, null).trim();
        updateState(state);

        // register observer to listen for settings changes
        mContentResolver.registerContentObserver(
            Settings.Global.getUriFor(Settings.Global.ADB_ENABLED),
            false,
            new AdbSettingsObserver());
        mContentResolver.registerContentObserver(
            Settings.Secure.getUriFor(Settings.Secure.ADB_NOTIFY),
            false,
            new ContentObserver(null) {
              public void onChange(boolean selfChange) {
                updateAdbNotification();
              }
            });

        // Watch for USB configuration changes
        mUEventObserver.startObserving(USB_STATE_MATCH);
        mUEventObserver.startObserving(ACCESSORY_START_MATCH);
      } catch (Exception e) {
        Slog.e(TAG, "Error initializing UsbHandler", e);
      }
    }
    public UsbHandler(Looper looper) {
      super(looper);
      try {
        // persist.sys.usb.config should never be unset.  But if it is, set it to "adb"
        // so we have a chance of debugging what happened.
        mDefaultFunctions = SystemProperties.get("persist.sys.usb.config", "adb");

        // Check if USB mode needs to be overridden depending on OEM specific bootmode.
        mDefaultFunctions = processOemUsbOverride(mDefaultFunctions);

        // sanity check the sys.usb.config system property
        // this may be necessary if we crashed while switching USB configurations
        String config = SystemProperties.get("sys.usb.config", "none");
        if (!config.equals(mDefaultFunctions)) {
          Slog.w(TAG, "resetting config to persistent property: " + mDefaultFunctions);
          SystemProperties.set("sys.usb.config", mDefaultFunctions);
        }

        mCurrentFunctions = mDefaultFunctions;
        String state = FileUtils.readTextFile(new File(STATE_PATH), 0, null).trim();
        updateState(state);
        mAdbEnabled = containsFunction(mCurrentFunctions, UsbManager.USB_FUNCTION_ADB);

        // Upgrade step for previous versions that used persist.service.adb.enable
        String value = SystemProperties.get("persist.service.adb.enable", "");
        if (value.length() > 0) {
          char enable = value.charAt(0);
          if (enable == '1') {
            setAdbEnabled(true);
          } else if (enable == '0') {
            setAdbEnabled(false);
          }
          SystemProperties.set("persist.service.adb.enable", "");
        }

        // register observer to listen for settings changes
        mContentResolver.registerContentObserver(
            Settings.Global.getUriFor(Settings.Global.ADB_ENABLED),
            false,
            new AdbSettingsObserver());
        mContentResolver.registerContentObserver(
            Settings.Secure.getUriFor(Settings.Secure.ADB_NOTIFY),
            false,
            new ContentObserver(null) {
              public void onChange(boolean selfChange) {
                updateAdbNotification();
              }
            });

        // Watch for USB configuration changes
        mUEventObserver.startObserving(USB_STATE_MATCH);
        mUEventObserver.startObserving(ACCESSORY_START_MATCH);

        mContext.registerReceiver(
            mBootCompletedReceiver, new IntentFilter(Intent.ACTION_BOOT_COMPLETED));
        mContext.registerReceiver(
            mUserSwitchedReceiver, new IntentFilter(Intent.ACTION_USER_SWITCHED));
      } catch (Exception e) {
        Slog.e(TAG, "Error initializing UsbHandler", e);
      }
    }
 @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
 private void registerTouchSettingObserver() {
   final Uri uri = Settings.Secure.getUriFor(Settings.Secure.TOUCH_EXPLORATION_ENABLED);
   getContentResolver().registerContentObserver(uri, false, mTouchExploreObserver);
 }