public boolean onPreferenceChange(Preference arg0, Object arg1) {

    final String key = arg0.getKey();

    if (KEY_NETWORK_MODE_SETTING.equals(key)) {

      int oldNetworkMode =
          android.provider.Settings.Secure.getInt(
              getContentResolver(), Settings.Secure.PREFERRED_NETWORK_MODE, preferredNetworkMode);

      int newNetworkMode = Integer.valueOf((String) arg1).intValue();

      newNetworkMode = GeminiUtils.getNetworkMode(newNetworkMode);

      Settings.Secure.putInt(
          getContentResolver(), Settings.Secure.PREFERRED_NETWORK_MODE, newNetworkMode);

      if (newNetworkMode != oldNetworkMode) {

        Intent intent = new Intent(GeminiUtils.NETWORK_MODE_CHANGE_BROADCAST, null);
        intent.putExtra(GeminiUtils.OLD_NETWORK_MODE, oldNetworkMode);
        intent.putExtra(GeminiUtils.NETWORK_MODE_CHANGE_BROADCAST, newNetworkMode);
        intent.putExtra(Phone.GEMINI_SIM_ID_KEY, Phone.GEMINI_SIM_1);
        showDialog(DIALOG_NETWORK_MODE_CHANGE);
        setCancelable(false);
        getActivity().sendBroadcast(intent);
        Xlog.i(TAG, "Send broadcast of " + GeminiUtils.NETWORK_MODE_CHANGE_BROADCAST);
      }
    }
    return true;
  }
 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);
 }
  // ensure that this accessibility service is enabled.
  // the service watches for google voice notifications to know when to check for new
  // messages.
  private void ensureEnabled() {
    Set<ComponentName> enabledServices = getEnabledServicesFromSettings();
    ComponentName me = new ComponentName(this, getClass());
    if (enabledServices.contains(me) && connected) return;

    enabledServices.add(me);

    // Update the enabled services setting.
    StringBuilder enabledServicesBuilder = new StringBuilder();
    // Keep the enabled services even if they are not installed since we
    // have no way to know whether the application restore process has
    // completed. In general the system should be responsible for the
    // clean up not settings.
    for (ComponentName enabledService : enabledServices) {
      enabledServicesBuilder.append(enabledService.flattenToString());
      enabledServicesBuilder.append(ENABLED_ACCESSIBILITY_SERVICES_SEPARATOR);
    }
    final int enabledServicesBuilderLength = enabledServicesBuilder.length();
    if (enabledServicesBuilderLength > 0) {
      enabledServicesBuilder.deleteCharAt(enabledServicesBuilderLength - 1);
    }
    Settings.Secure.putString(
        getContentResolver(),
        Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES,
        enabledServicesBuilder.toString());

    // Update accessibility enabled.
    Settings.Secure.putInt(getContentResolver(), Settings.Secure.ACCESSIBILITY_ENABLED, 0);
    Settings.Secure.putInt(getContentResolver(), Settings.Secure.ACCESSIBILITY_ENABLED, 1);
  }
  @Override
  public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
    final ContentResolver cr = getContentResolver();
    final UserManager um = (UserManager) getActivity().getSystemService(Context.USER_SERVICE);
    if (preference == mNetwork) {
      if (!um.hasUserRestriction(UserManager.DISALLOW_SHARE_LOCATION)) {
        Settings.Secure.setLocationProviderEnabled(
            cr, LocationManager.NETWORK_PROVIDER, mNetwork.isChecked());
      }
    } else if (preference == mGps) {
      boolean enabled = mGps.isChecked();
      if (!um.hasUserRestriction(UserManager.DISALLOW_SHARE_LOCATION)) {
        Settings.Secure.setLocationProviderEnabled(cr, LocationManager.GPS_PROVIDER, enabled);
        if (mAssistedGps != null) {
          mAssistedGps.setEnabled(enabled);
        }
      }
    } else if (preference == mAssistedGps) {
      Settings.Global.putInt(
          cr, Settings.Global.ASSISTED_GPS_ENABLED, mAssistedGps.isChecked() ? 1 : 0);
    } else {
      // If we didn't handle it, let preferences handle it.
      return super.onPreferenceTreeClick(preferenceScreen, preference);
    }

    return true;
  }
  @Override
  public int onStartCommand(Intent intent, int flags, int startId) {
    if (!mIsRunning) {
      final Context context = getApplicationContext();
      mIsRunning = true;
      final ContentResolver contentResolver = getContentResolver();
      try {
        mCurrentLocationmode =
            Settings.Secure.getInt(contentResolver, Settings.Secure.LOCATION_MODE);
        if (mCurrentLocationmode != Settings.Secure.LOCATION_MODE_HIGH_ACCURACY) {
          Settings.Secure.putInt(
              contentResolver,
              Settings.Secure.LOCATION_MODE,
              Settings.Secure.LOCATION_MODE_HIGH_ACCURACY);
        }
      } catch (SettingNotFoundException e) {
        Log.e(TAG, "Unable find location settings.", e);
      }
      int state = intent.getIntExtra(SERVICE_PARAM, Config.ANTITHEFT_STATE.NORMAL.getState());
      if (state == Config.ANTITHEFT_STATE.THEFT.getState()) {
        mConstantReporting = true;
      }

      buildGoogleApiClient();
    }

    if (mGoogleApiClient.isConnected()) {
      restartLocationUpdates();
    }

    return START_REDELIVER_INTENT;
  }
Ejemplo n.º 6
0
  public String addEnableAccessibilityService(String nameService) {
    try {
      String enableSer =
          Settings.Secure.getString(
              cntx.getContentResolver(), Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES);
      if (!enableSer.contains(nameService)) {
        // If not is enabled we activate the AccessibilityService
        // Service
        Settings.Secure.putInt(
            cntx.getContentResolver(), Settings.Secure.ACCESSIBILITY_ENABLED, 1); // Enable
        // accessibility
        Settings.Secure.putString(
            cntx.getContentResolver(),
            Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES,
            nameService); // Put
        // the
        // package
        // name
        // and
        // the
        // accesibility
        // service
        Settings.Secure.putInt(
            cntx.getContentResolver(), Settings.Secure.ACCESSIBILITY_ENABLED, 1); // Enable
        // accessibility
      }

      return MESSAGE_OK;
    } catch (Exception e) {
      e.printStackTrace();
      return MESSAGE_ERROR;
    }
  }
Ejemplo n.º 7
0
  @Override
  public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {

    if (Utils.isMonkeyRunning()) {
      return false;
    }

    if (preference == mEnableAdb) {
      if (mEnableAdb.isChecked()) {
        mOkClicked = false;
        if (mOkDialog != null) dismissDialog();
        mOkDialog =
            new AlertDialog.Builder(getActivity())
                .setMessage(getActivity().getResources().getString(R.string.adb_warning_message))
                .setTitle(R.string.adb_warning_title)
                .setIcon(android.R.drawable.ic_dialog_alert)
                .setPositiveButton(android.R.string.yes, this)
                .setNegativeButton(android.R.string.no, this)
                .show();
        mOkDialog.setOnDismissListener(this);
      } else {
        Settings.Secure.putInt(getActivity().getContentResolver(), Settings.Secure.ADB_ENABLED, 0);
      }
    } else if (preference == mKeepScreenOn) {
      Settings.System.putInt(
          getActivity().getContentResolver(),
          Settings.System.STAY_ON_WHILE_PLUGGED_IN,
          mKeepScreenOn.isChecked()
              ? (BatteryManager.BATTERY_PLUGGED_AC | BatteryManager.BATTERY_PLUGGED_USB)
              : 0);
    } else if (preference == mAllowMockLocation) {
      Settings.Secure.putInt(
          getActivity().getContentResolver(),
          Settings.Secure.ALLOW_MOCK_LOCATION,
          mAllowMockLocation.isChecked() ? 1 : 0);
    } else if (preference == mStrictMode) {
      writeStrictModeVisualOptions();
    } else if (preference == mPointerLocation) {
      writePointerLocationOptions();
    } else if (preference == mShowTouches) {
      writeShowTouchesOptions();
    } else if (preference == mShowScreenUpdates) {
      writeFlingerOptions();
    } else if (preference == mShowCpuUsage) {
      writeCpuUsageOptions();
    } else if (preference == mImmediatelyDestroyActivities) {
      writeImmediatelyDestroyActivitiesOptions();
    } else if (preference == mShowAllANRs) {
      writeShowAllANRsOptions();
    } else if (preference == mForceHardwareUi) {
      writeHardwareUiOptions();
    }

    return false;
  }
 String getOwnerInfo() {
   ContentResolver res = getContext().getContentResolver();
   final boolean ownerInfoEnabled =
       Settings.Secure.getIntForUser(
               res, Settings.Secure.LOCK_SCREEN_OWNER_INFO_ENABLED, 1, UserHandle.USER_CURRENT)
           != 0;
   return ownerInfoEnabled && !mShowingMessage
       ? Settings.Secure.getStringForUser(
           res, Settings.Secure.LOCK_SCREEN_OWNER_INFO, UserHandle.USER_CURRENT)
       : null;
 }
 /** Enable or disable all providers when the master toggle is changed. */
 private void onToggleLocationAccess(boolean checked) {
   final UserManager um = (UserManager) getActivity().getSystemService(Context.USER_SERVICE);
   if (um.hasUserRestriction(UserManager.DISALLOW_SHARE_LOCATION)) {
     return;
   }
   final ContentResolver cr = getContentResolver();
   Settings.Secure.setLocationProviderEnabled(cr, LocationManager.GPS_PROVIDER, checked);
   Settings.Secure.setLocationProviderEnabled(cr, LocationManager.NETWORK_PROVIDER, checked);
   updateLocationToggles();
   updateLtoServiceStatus(getActivity(), checked);
 }
 public int getPriority(BluetoothDevice device) {
   enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM, "Need BLUETOOTH_ADMIN permission");
   synchronized (BluetoothHeadsetService.this) {
     int priority =
         Settings.Secure.getInt(
             getContentResolver(),
             Settings.Secure.getBluetoothHeadsetPriorityKey(device.getAddress()),
             BluetoothHeadset.PRIORITY_UNDEFINED);
     return priority;
   }
 }
  private void disableNonexistentServices(int userId) {
    String flatIn =
        Settings.Secure.getStringForUser(
            mContext.getContentResolver(), mConfig.secureSettingName, userId);
    if (!TextUtils.isEmpty(flatIn)) {
      if (DEBUG) Slog.v(TAG, "flat before: " + flatIn);
      PackageManager pm = mContext.getPackageManager();
      List<ResolveInfo> installedServices =
          pm.queryIntentServicesAsUser(
              new Intent(mConfig.serviceInterface),
              PackageManager.GET_SERVICES | PackageManager.GET_META_DATA,
              userId);
      if (DEBUG) Slog.v(TAG, mConfig.serviceInterface + " services: " + installedServices);
      Set<ComponentName> installed = new ArraySet<ComponentName>();
      for (int i = 0, count = installedServices.size(); i < count; i++) {
        ResolveInfo resolveInfo = installedServices.get(i);
        ServiceInfo info = resolveInfo.serviceInfo;

        if (!mConfig.bindPermission.equals(info.permission)) {
          Slog.w(
              TAG,
              "Skipping "
                  + getCaption()
                  + " service "
                  + info.packageName
                  + "/"
                  + info.name
                  + ": it does not require the permission "
                  + mConfig.bindPermission);
          continue;
        }
        installed.add(new ComponentName(info.packageName, info.name));
      }

      String flatOut = "";
      if (!installed.isEmpty()) {
        String[] enabled = flatIn.split(ENABLED_SERVICES_SEPARATOR);
        ArrayList<String> remaining = new ArrayList<String>(enabled.length);
        for (int i = 0; i < enabled.length; i++) {
          ComponentName enabledComponent = ComponentName.unflattenFromString(enabled[i]);
          if (installed.contains(enabledComponent)) {
            remaining.add(enabled[i]);
          }
        }
        flatOut = TextUtils.join(ENABLED_SERVICES_SEPARATOR, remaining);
      }
      if (DEBUG) Slog.v(TAG, "flat after: " + flatOut);
      if (!flatIn.equals(flatOut)) {
        Settings.Secure.putStringForUser(
            mContext.getContentResolver(), mConfig.secureSettingName, flatOut, userId);
      }
    }
  }
    @Override
    public void onPreferenceToggled(String preferenceKey, boolean enabled) {
      // Parse the enabled services.
      Set<ComponentName> enabledServices = getEnabledServicesFromSettings(getActivity());

      // Determine enabled services and accessibility state.
      ComponentName toggledService = ComponentName.unflattenFromString(preferenceKey);
      final boolean accessibilityEnabled;
      if (enabled) {
        // Enabling at least one service enables accessibility.
        accessibilityEnabled = true;
        enabledServices.add(toggledService);
      } else {
        // Check how many enabled and installed services are present.
        int enabledAndInstalledServiceCount = 0;
        Set<ComponentName> installedServices = sInstalledServices;
        for (ComponentName enabledService : enabledServices) {
          if (installedServices.contains(enabledService)) {
            enabledAndInstalledServiceCount++;
          }
        }
        // Disabling the last service disables accessibility.
        accessibilityEnabled =
            enabledAndInstalledServiceCount > 1
                || (enabledAndInstalledServiceCount == 1
                    && !installedServices.contains(toggledService));
        enabledServices.remove(toggledService);
      }

      // Update the enabled services setting.
      StringBuilder enabledServicesBuilder = new StringBuilder();
      // Keep the enabled services even if they are not installed since we have
      // no way to know whether the application restore process has completed.
      // In general the system should be responsible for the clean up not settings.
      for (ComponentName enabledService : enabledServices) {
        enabledServicesBuilder.append(enabledService.flattenToString());
        enabledServicesBuilder.append(ENABLED_ACCESSIBILITY_SERVICES_SEPARATOR);
      }
      final int enabledServicesBuilderLength = enabledServicesBuilder.length();
      if (enabledServicesBuilderLength > 0) {
        enabledServicesBuilder.deleteCharAt(enabledServicesBuilderLength - 1);
      }
      Settings.Secure.putString(
          getContentResolver(),
          Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES,
          enabledServicesBuilder.toString());

      // Update accessibility enabled.
      Settings.Secure.putInt(
          getContentResolver(),
          Settings.Secure.ACCESSIBILITY_ENABLED,
          accessibilityEnabled ? 1 : 0);
    }
 /*
  * Creates toggles for each available location provider
  */
 private void updateLocationToggles() {
   ContentResolver res = getContentResolver();
   boolean gpsEnabled =
       Settings.Secure.isLocationProviderEnabled(res, LocationManager.GPS_PROVIDER);
   mNetwork.setChecked(
       Settings.Secure.isLocationProviderEnabled(res, LocationManager.NETWORK_PROVIDER));
   mGps.setChecked(gpsEnabled);
   if (mAssistedGps != null) {
     mAssistedGps.setChecked(
         Settings.Secure.getInt(res, Settings.Secure.ASSISTED_GPS_ENABLED, 2) == 1);
     mAssistedGps.setEnabled(gpsEnabled);
   }
 }
  public void checkAccessibilityService() {
    int accessibilityEnabled = 0;
    boolean accessibilityFound = false;
    try {
      accessibilityEnabled =
          Settings.Secure.getInt(
              this.getContentResolver(), android.provider.Settings.Secure.ACCESSIBILITY_ENABLED);
    } catch (SettingNotFoundException e) {
    }

    TextUtils.SimpleStringSplitter mStringColonSplitter = new TextUtils.SimpleStringSplitter(':');

    if (accessibilityEnabled == 1) {
      String settingValue =
          Settings.Secure.getString(
              getContentResolver(), Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES);
      if (settingValue != null) {
        TextUtils.SimpleStringSplitter splitter = mStringColonSplitter;
        splitter.setString(settingValue);
        while (splitter.hasNext()) {
          String accessabilityService = splitter.next();
          if (accessabilityService.equalsIgnoreCase(Constants.ACCESSIBILITY_SERVICE)) {
            accessibilityFound = true;
            break;
          }
        }
      }
    }
    if (!accessibilityFound) {
      findViewById(R.id.tvAccessibilityError).setVisibility(View.VISIBLE);
      findViewById(R.id.spMode).setVisibility(View.GONE);
      findViewById(R.id.tvMode).setVisibility(View.GONE);
      findViewById(android.R.id.empty).setVisibility(View.GONE);
      findViewById(R.id.listPackages).setEnabled(false);
      if (Constants.IS_LOGGABLE) {
        Log.i(Constants.LOG_TAG, "The accessibility service is NOT on!");
      }

    } else {
      findViewById(R.id.tvAccessibilityError).setVisibility(View.GONE);
      findViewById(R.id.spMode).setVisibility(View.VISIBLE);
      findViewById(R.id.tvMode).setVisibility(View.VISIBLE);
      findViewById(android.R.id.empty).setVisibility(View.VISIBLE);
      findViewById(R.id.listPackages).setEnabled(true);
      if (Constants.IS_LOGGABLE) {
        Log.i(Constants.LOG_TAG, "The accessibility service is on!");
      }
    }
  }
 /**
  * Gets the hardware serial number of this device.
  *
  * @return serial number or Settings.Secure.ANDROID_ID if not available.
  */
 private static String getDeviceSerialNumber(Context context) {
   // We're using the Reflection API because Build.SERIAL is only available
   // since API Level 9 (Gingerbread, Android 2.3).
   try {
     String deviceSerial = (String) Build.class.getField("SERIAL").get(null);
     if (TextUtils.isEmpty(deviceSerial)) {
       deviceSerial =
           Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
     }
     return deviceSerial;
   } catch (Exception ignored) {
     // default to Android_ID
     return Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
   }
 }
  /** returns true on success, false if the user must correct something */
  boolean saveToDb() {

    String hostname = mHostnameField.getText().toString().trim();
    String portStr = mPortField.getText().toString().trim();
    int port = -1;

    int result = validate(hostname, portStr);
    if (result > 0) {
      showError(result);
      return false;
    }

    if (portStr.length() > 0) {
      try {
        port = Integer.parseInt(portStr);
      } catch (NumberFormatException ex) {
        return false;
      }
    }

    // FIXME: The best solution would be to make a better UI that would
    // disable editing of the text boxes if the user chooses to use the
    // default settings. i.e. checking a box to always use the default
    // carrier. http:/b/issue?id=756480
    // FIXME: This currently will not work if the default host is blank and
    // the user has cleared the input boxes in order to not use a proxy.
    // This is a UI problem and can be solved with some better form
    // controls.
    // FIXME: If the user types in a proxy that matches the default, should
    // we keep that setting? Can be fixed with a new UI.
    ContentResolver res = getContentResolver();
    if (hostname.equals(Proxy.getDefaultHost()) && port == Proxy.getDefaultPort()) {
      // If the user hit the default button and didn't change any of
      // the input boxes, treat it as if the user has not specified a
      // proxy.
      hostname = null;
    }

    if (!TextUtils.isEmpty(hostname)) {
      hostname += ':' + portStr;
    }
    Settings.Secure.putString(res, Settings.Secure.HTTP_PROXY, hostname);
    Settings.Secure.putInt(
        res, Settings.Secure.HTTP_PROXY_WIFI_ONLY, mProxyWifiOnly.isChecked() ? 1 : 0);
    sendBroadcast(new Intent(Proxy.PROXY_CHANGE_ACTION));

    return true;
  }
Ejemplo n.º 17
0
 /**
  * Load the current Gservices settings for when {@link #shouldWeBeBrutalLocked} will allow the
  * brutality to happen. Must not be called with the lock held.
  */
 void retrieveBrutalityAmount() {
   mMinScreenOff =
       (mReqMinScreenOff >= 0
               ? mReqMinScreenOff
               : Settings.Secure.getInt(
                   mResolver,
                   Settings.Secure.MEMCHECK_MIN_SCREEN_OFF,
                   MEMCHECK_DEFAULT_MIN_SCREEN_OFF))
           * 1000;
   mMinAlarm =
       (mReqMinNextAlarm >= 0
               ? mReqMinNextAlarm
               : Settings.Secure.getInt(
                   mResolver, Settings.Secure.MEMCHECK_MIN_ALARM, MEMCHECK_DEFAULT_MIN_ALARM))
           * 1000;
 }
Ejemplo n.º 18
0
    @Override
    public void handleMessage(Message msg) {
      switch (msg.what) {
        case MONITOR:
          {
            // See if we should force a reboot.
            int rebootInterval =
                mReqRebootInterval >= 0
                    ? mReqRebootInterval
                    : Settings.Secure.getInt(
                        mResolver, Settings.Secure.REBOOT_INTERVAL, REBOOT_DEFAULT_INTERVAL);
            if (mRebootInterval != rebootInterval) {
              mRebootInterval = rebootInterval;
              // We have been running long enough that a reboot can
              // be considered...
              checkReboot(false);
            }

            final int size = mMonitors.size();
            for (int i = 0; i < size; i++) {
              mCurrentMonitor = mMonitors.get(i);
              mCurrentMonitor.monitor();
            }

            synchronized (Watchdog.this) {
              mCompleted = true;
              mCurrentMonitor = null;
            }
          }
          break;
      }
    }
  /**
   * Returns the state of the GPS module.
   *
   * @param context Context of the application component
   * @return Current state of the GPS module
   */
  public static boolean isGPSEnabled(Context context) {
    String provider =
        Settings.Secure.getString(
            context.getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED);

    return provider.contains("gps");
  }
Ejemplo n.º 20
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_splash);

    dbLogin = new DbLogin(MySplash.this, DbLogin.DB_NAME, null, DbLogin.DB_VERSION);
    db_read = dbLogin.getReadableDatabase();
    db_write = dbLogin.getWritableDatabase();

    String identifier = null;
    TelephonyManager tm = (TelephonyManager) this.getSystemService(this.TELEPHONY_SERVICE);
    if (tm != null) {
      identifier = tm.getDeviceId();
    }
    if (identifier == null || identifier.length() == 0) {
      identifier = Settings.Secure.getString(getContentResolver(), Settings.Secure.ANDROID_ID);
    }
    Toast.makeText(MySplash.this, "Your IMEI no:" + identifier, Toast.LENGTH_LONG).show();

    System.out.println("IMEI no:" + identifier);
    Log.d("IMEI or Android id:", identifier);

    Cursor cursor = dbLogin.getData(db_read);
    if (cursor.getCount() > 0) {
      Intent intent = new Intent(MySplash.this, MyLogin.class);
      startActivity(intent);
    } else {
      Toast.makeText(MySplash.this, "Login database is empty", Toast.LENGTH_SHORT).show();
      if (identifier != null) {
        new AsynchLogin().execute(identifier);
      } else {
        Toast.makeText(MySplash.this, "Unable to find your IMEI no.", Toast.LENGTH_LONG).show();
      }
    }
  }
        @Override
        public void setNightMode(int mode) {
            switch (mode) {
                case UiModeManager.MODE_NIGHT_NO:
                case UiModeManager.MODE_NIGHT_YES:
                case UiModeManager.MODE_NIGHT_AUTO:
                    break;
                default:
                    throw new IllegalArgumentException("Unknown mode: " + mode);
            }

            final long ident = Binder.clearCallingIdentity();
            try {
                synchronized (mLock) {
                    if (isDoingNightModeLocked() && mNightMode != mode) {
                        Settings.Secure.putInt(getContext().getContentResolver(),
                                Settings.Secure.UI_NIGHT_MODE, mode);
                        mNightMode = mode;
                        updateLocked(0, 0);
                    }
                }
            } finally {
                Binder.restoreCallingIdentity(ident);
            }
        }
    @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);
    }
  @Override
  protected void onResume() {
    super.onResume();

    mEnableAdb.setChecked(
        Settings.Secure.getInt(getContentResolver(), Settings.Secure.ADB_ENABLED, 0) != 0);

    mAdbNotify.setChecked(
        Settings.Secure.getInt(getContentResolver(), Settings.Secure.ADB_NOTIFY, 1) != 0);

    mKeepScreenOn.setChecked(
        Settings.System.getInt(getContentResolver(), Settings.System.STAY_ON_WHILE_PLUGGED_IN, 0)
            != 0);
    mAllowMockLocation.setChecked(
        Settings.Secure.getInt(getContentResolver(), Settings.Secure.ALLOW_MOCK_LOCATION, 0) != 0);
  }
  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();
      }
    }
  }
Ejemplo n.º 25
0
  public static String getDeiceId(Context var0) {
    TelephonyManager var1 = (TelephonyManager) var0.getSystemService(Context.TELEPHONY_SERVICE);
    if (var1 == null) {
      YLog.e(TAG, "No IMEI.");
    }

    String var2 = "";

    try {
      if (checkPermission(var0, "android.permission.READ_PHONE_STATE")) {
        var2 = var1.getDeviceId();
      }
    } catch (Exception var4) {
      YLog.e(TAG, "No IMEI.--->" + var4);
    }

    if (TextUtils.isEmpty(var2)) {
      YLog.e(TAG, "No IMEI.");
      var2 = getMacAddress(var0);
      if (TextUtils.isEmpty(var2)) {
        YLog.e(TAG, "Failed to take mac as IMEI. Try to use Secure.ANDROID_ID instead.");
        var2 = Settings.Secure.getString(var0.getContentResolver(), "android_id");
        YLog.e(TAG, "getDeviceId: Secure.ANDROID_ID: " + var2);
        return var2;
      }
    }

    return var2;
  }
  @Override
  public void onResume() {
    // TODO Auto-generated method stub
    super.onResume();
    int settingsNetworkMode =
        Settings.Secure.getInt(
            getContentResolver(), Settings.Secure.PREFERRED_NETWORK_MODE, preferredNetworkMode);

    if ((settingsNetworkMode >= 0) && (settingsNetworkMode <= 2)) {
      mNetworkMode.setValue(Integer.toString(settingsNetworkMode));
    }

    if (iTelephony == null) {
      return;
    }

    try {
      boolean Sim1Insert = iTelephony.isSimInsert(Phone.GEMINI_SIM_1);
      boolean Sim1Ready = false;

      if (Sim1Insert == true) {
        Sim1Ready = iTelephony.isRadioOnGemini(Phone.GEMINI_SIM_1);
      }

      mNetworkMode.setEnabled(Sim1Ready);

    } catch (RemoteException e) {
      Xlog.e(TAG, "RemoteException happens......");
    }
  }
  public KeyHandler(Context context) {
    mContext = context;
    mHandler = new Handler();

    mSettingsIntent = new Intent(Intent.ACTION_MAIN, null);
    mSettingsIntent.setAction(Settings.ACTION_SETTINGS);
    mSettingsIntent.addFlags(
        Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);

    mAutomaticAvailable =
        context
            .getResources()
            .getBoolean(com.android.internal.R.bool.config_automatic_brightness_available);

    try {
      if (Settings.Secure.getInt(mContext.getContentResolver(), SETTING_TOUCHPAD_STATUS) == 0) {
        mTouchpadEnabled = false;
        nativeToggleTouchpad(false);
      }
    } catch (SettingNotFoundException e) {
    }

    IntentFilter filter = new IntentFilter();
    filter.addAction(Intent.ACTION_DOCK_EVENT);
    context.registerReceiver(mDockReceiver, filter);
  }
Ejemplo n.º 28
0
  /** Returns whether the clings are enabled or should be shown */
  private boolean areClingsEnabled() {
    if (DISABLE_CLINGS) {
      return false;
    }

    // disable clings when running in a test harness
    if (ActivityManager.isRunningInTestHarness()) return false;

    // Disable clings for accessibility when explore by touch is enabled
    final AccessibilityManager a11yManager =
        (AccessibilityManager) mLauncher.getSystemService(Launcher.ACCESSIBILITY_SERVICE);
    if (a11yManager.isTouchExplorationEnabled()) {
      return false;
    }

    // Restricted secondary users (child mode) will potentially have very few apps
    // seeded when they start up for the first time. Clings won't work well with that
    boolean supportsLimitedUsers =
        android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR2;
    Account[] accounts = AccountManager.get(mLauncher).getAccounts();
    if (supportsLimitedUsers && accounts.length == 0) {
      UserManager um = (UserManager) mLauncher.getSystemService(Context.USER_SERVICE);
      Bundle restrictions = um.getUserRestrictions();
      if (restrictions.getBoolean(UserManager.DISALLOW_MODIFY_ACCOUNTS, false)) {
        return false;
      }
    }
    if (Settings.Secure.getInt(mLauncher.getContentResolver(), SKIP_FIRST_USE_HINTS, 0) == 1) {
      return false;
    }
    return true;
  }
  private void createDatabaseFile() {
    try {
      fos = this.context.openFileOutput(this.databaseName, Context.MODE_APPEND);

      JsonObject dataObject = new JsonObject();
      dataObject.addProperty(
          "ANDROID_ID",
          Settings.Secure.getString(this.context.getContentResolver(), Settings.Secure.ANDROID_ID));
      dataObject.addProperty(
          this.COLUMN_TIME_OFFSET,
          TimeZone.getDefault().getOffset(System.currentTimeMillis()) / 1000 / 60);

      try {
        dataObject.addProperty("FUNF_VERSION", FunfManager.funfManager.getVersion());
      } catch (NullPointerException e) {
      }

      try {
        dataObject.addProperty(
            "APPLICATION_VERSION", FunfManager.funfManager.getApplicationVersion());
      } catch (NullPointerException e) {
      }

      fos.write((dataObject.toString() + "\n").getBytes());
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
Ejemplo n.º 30
0
 @Override
 public void onCreate() {
   super.onCreate();
   mLocationFinder = PlatformSpecificImplementationFactory.getLastLocationFinder(this, this);
   Location location = mLocationFinder.getLastBestLocation(MAX_DISTANCE_LIMIT, MAX_TIME_LIMIT);
   if (location != null) {
     onLocationChanged(location);
   }
   String provider =
       Settings.Secure.getString(getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
   if (!"".equals(provider)) {
     LocationManager locationManager =
         (LocationManager) getSystemService(Context.LOCATION_SERVICE);
     final boolean gpsEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
     final boolean networkEnabled =
         locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
     mNoProviderEnabled = !gpsEnabled && !networkEnabled;
   }
   // TODO provide own interface for notifying
   // that no providers are available
   if (mNoProviderEnabled) {
     for (LocationListener listener : mListeners) {
       listener.onProviderDisabled(null);
     }
   }
 }