예제 #1
0
 @RequestMapping("/admin/updateType")
 @ResponseBody
 public String updateType(
     HttpSession session,
     String mm_manager_id,
     String mm_manager_is_use,
     String mm_manager_nickname) {
   try {
     Admin manager = (Admin) session.getAttribute(ACCOUNT_KEY);
     Object[] params = new Object[] {mm_manager_id, mm_manager_is_use};
     // mm_manager_is_use :0 1 是禁止和启动管理员 2是删除管理员
     if ("2".equals(mm_manager_is_use)) {
       // 删除
       adminServiceDelete.delete(mm_manager_id);
     } else {
       // 更改管理员状态
       adminUpdateService.update(params);
     }
     // 日志记录
     switch (Integer.parseInt(mm_manager_is_use)) {
       case 0:
         logoService.save(new LogoObj("禁用管理员:" + mm_manager_nickname, manager.getMm_manager_id()));
         break;
       case 1:
         logoService.save(new LogoObj("启用管理员:" + mm_manager_nickname, manager.getMm_manager_id()));
         break;
       case 2:
         logoService.save(new LogoObj("删除管理员:" + mm_manager_nickname, manager.getMm_manager_id()));
         break;
     }
     return toJSONString(SUCCESS);
   } catch (ServiceException e) {
     return toJSONString(ERROR_1);
   }
 }
예제 #2
0
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {

    switch (requestCode) {
      case REQUEST_PREFS:
        // The automatic update settings may have changed, so reschedule (or
        // unschedule) the service accordingly. It's cheap, so no need to
        // check if the particular setting has actually been changed.
        UpdateService.schedule(getBaseContext());

        if ((resultCode & PreferencesActivity.RESULT_RESTART) != 0) {
          ((FDroidApp) getApplication()).reloadTheme();
          final Intent intent = getIntent();
          overridePendingTransition(0, 0);
          intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
          finish();
          overridePendingTransition(0, 0);
          startActivity(intent);
        }
        break;
      case REQUEST_ENABLE_BLUETOOTH:
        fdroidApp.sendViaBluetooth(this, resultCode, "org.fdroid.fdroid");
        break;
    }
  }
예제 #3
0
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {

    switch (item.getItemId()) {
      case R.id.action_update_repo:
        UpdateService.updateNow(this);
        return true;

      case R.id.action_manage_repos:
        startActivity(new Intent(this, ManageReposActivity.class));
        return true;

      case R.id.action_settings:
        Intent prefs = new Intent(getBaseContext(), PreferencesActivity.class);
        startActivityForResult(prefs, REQUEST_PREFS);
        return true;

      case R.id.action_swap:
        startActivity(new Intent(this, SwapWorkflowActivity.class));
        return true;

      case R.id.action_bluetooth_apk:
        /*
         * If Bluetooth has not been enabled/turned on, then enabling
         * device discoverability will automatically enable Bluetooth
         */
        Intent discoverBt = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
        discoverBt.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 121);
        startActivityForResult(discoverBt, REQUEST_ENABLE_BLUETOOTH);
        // if this is successful, the Bluetooth transfer is started
        return true;

      case R.id.action_about:
        View view = LayoutInflater.from(this).inflate(R.layout.about, null);

        String versionName = Utils.getVersionName(this);
        if (versionName != null) {
          ((TextView) view.findViewById(R.id.version)).setText(versionName);
        }

        AlertDialog alrt = new AlertDialog.Builder(this).setView(view).create();
        alrt.setTitle(R.string.about_title);
        alrt.setButton(
            AlertDialog.BUTTON_NEGATIVE,
            getString(R.string.ok),
            new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int whichButton) {}
            });
        alrt.show();
        return true;
    }
    return super.onOptionsItemSelected(item);
  }
예제 #4
0
  /**
   * The dependent service is available and the bundle will start.
   *
   * @param dependentService the UIService this activator is waiting.
   */
  @Override
  public void start(Object dependentService) {
    if (logger.isDebugEnabled()) logger.debug("Update checker [STARTED]");

    ConfigurationService cfg = getConfiguration();

    if (OSUtils.IS_WINDOWS) {
      updateService = new Update();

      bundleContext.registerService(UpdateService.class.getName(), updateService, null);

      // Register the "Check for Updates" menu item if
      // the "Check for Updates" property isn't disabled.
      if (!cfg.getBoolean(CHECK_FOR_UPDATES_MENU_DISABLED_PROP, false)) {
        // Register the "Check for Updates" menu item.
        CheckForUpdatesMenuItemComponent checkForUpdatesMenuItemComponent =
            new CheckForUpdatesMenuItemComponent(Container.CONTAINER_HELP_MENU);

        Hashtable<String, String> toolsMenuFilter = new Hashtable<String, String>();
        toolsMenuFilter.put(Container.CONTAINER_ID, Container.CONTAINER_HELP_MENU.getID());

        bundleContext.registerService(
            PluginComponent.class.getName(), checkForUpdatesMenuItemComponent, toolsMenuFilter);
      }

      // Check for software update upon startup if enabled.
      if (cfg.getBoolean(UPDATE_ENABLED, true)) updateService.checkForUpdates(false);
    }

    if (cfg.getBoolean(CHECK_FOR_UPDATES_DAILY_ENABLED_PROP, false)) {
      logger.info("Scheduled update checking enabled");

      // Schedule a "check for updates" task that will run once a day
      int hoursToWait = calcHoursToWait();
      Runnable updateRunnable =
          new Runnable() {
            public void run() {
              logger.debug("Performing scheduled update check");
              getUpdateService().checkForUpdates(false);
            }
          };

      mUpdateExecutor = Executors.newSingleThreadScheduledExecutor();
      mUpdateExecutor.scheduleAtFixedRate(
          updateRunnable, hoursToWait, 24 * 60 * 60, TimeUnit.SECONDS);
    }

    if (logger.isDebugEnabled()) logger.debug("Update checker [REGISTERED]");
  }
예제 #5
0
  public void updateQueuePosition(long podcastId, Integer newPosition) {
    SQLiteDatabase db = _dbAdapter.getWritableDatabase();

    // get the old position
    Cursor c =
        db.query(
            "podcasts",
            new String[] {"queuePosition"},
            "_id = ?",
            new String[] {String.valueOf(podcastId)},
            null,
            null,
            null);
    c.moveToFirst();
    Integer oldPosition = null;
    if (!c.isNull(0)) oldPosition = c.getInt(0);
    c.close();

    // no need to remove from queue if it's not in queue
    if (oldPosition == null && newPosition == null) return;

    if (oldPosition == null && newPosition != null) {
      // new at 3: 1 2 3 4 5 do: 3++ 4++ 5++
      db.execSQL(
          "UPDATE podcasts SET queuePosition = queuePosition + 1 " + "WHERE queuePosition >= ?",
          new Object[] {newPosition});

      // download the newly added podcast
      UpdateService.downloadPodcastsSilently(getContext());
    } else if (oldPosition != null && newPosition == null) {
      // remove 3: 1 2 3 4 5 do: 4-- 5--
      db.execSQL(
          "UPDATE podcasts SET queuePosition = queuePosition - 1 " + "WHERE queuePosition > ?",
          new Object[] {oldPosition});

      // delete the podcast's file
      deleteDownload(getContext(), podcastId);
    } else if (oldPosition != newPosition) {
      // moving up: 1 2 3 4 5 2 -> 4: 3-- 4-- 2->4
      if (oldPosition < newPosition)
        db.execSQL(
            "UPDATE podcasts SET queuePosition = queuePosition - 1 "
                + "WHERE queuePosition > ? AND queuePosition <= ?",
            new Object[] {oldPosition, newPosition});
      // moving down: 1 2 3 4 5 4 -> 2: 2++ 3++ 4->2
      if (newPosition < oldPosition)
        db.execSQL(
            "UPDATE podcasts SET queuePosition = queuePosition + 1 "
                + "WHERE queuePosition >= ? AND queuePosition < ?",
            new Object[] {newPosition, oldPosition});
    }

    // if new position is max_value, put the podcast at the end
    if (newPosition != null && newPosition == Integer.MAX_VALUE) {
      Cursor max = db.rawQuery("SELECT COALESCE(MAX(queuePosition) + 1, 0) FROM podcasts", null);
      max.moveToFirst();
      newPosition = max.getInt(0);
      max.close();
    }

    // update specified podcast
    db.execSQL(
        "UPDATE podcasts SET queuePosition = ? WHERE _id = ?",
        new Object[] {newPosition, podcastId});
    getContext().getContentResolver().notifyChange(QUEUE_URI, null);
  }
예제 #6
0
  @TargetApi(9)
  @Override
  public void onCreate() {
    if (Build.VERSION.SDK_INT >= 9 && BuildConfig.DEBUG) {
      StrictMode.setThreadPolicy(
          new StrictMode.ThreadPolicy.Builder().detectAll().penaltyLog().build());
      StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectAll().penaltyLog().build());
    }
    updateLanguage();
    super.onCreate();
    ACRA.init(this);

    // Needs to be setup before anything else tries to access it.
    // Perhaps the constructor is a better place, but then again,
    // it is more deterministic as to when this gets called...
    Preferences.setup(this);

    // Apply the Google PRNG fixes to properly seed SecureRandom
    PRNGFixes.apply();

    // Check that the installed app cache hasn't gotten out of sync somehow.
    // e.g. if we crashed/ran out of battery half way through responding
    // to a package installed intent. It doesn't really matter where
    // we put this in the bootstrap process, because it runs on a different
    // thread, which will be delayed by some seconds to avoid an error where
    // the database is locked due to the database updater.
    InstalledAppCacheUpdater.updateInBackground(getApplicationContext());

    // If the user changes the preference to do with filtering rooted apps,
    // it is easier to just notify a change in the app provider,
    // so that the newly updated list will correctly filter relevant apps.
    Preferences.get()
        .registerAppsRequiringRootChangeListener(
            new Preferences.ChangeListener() {
              @Override
              public void onPreferenceChange() {
                getContentResolver().notifyChange(AppProvider.getContentUri(), null);
              }
            });

    // This is added so that the bluetooth:// scheme we use for URLs the BluetoothDownloader
    // understands is not treated as invalid by the java.net.URL class. The actual Handler does
    // nothing, but its presence is enough.
    URL.setURLStreamHandlerFactory(
        new URLStreamHandlerFactory() {
          @Override
          public URLStreamHandler createURLStreamHandler(String protocol) {
            return TextUtils.equals(protocol, "bluetooth") ? new Handler() : null;
          }
        });

    final Context context = this;
    Preferences.get()
        .registerUnstableUpdatesChangeListener(
            new Preferences.ChangeListener() {
              @Override
              public void onPreferenceChange() {
                AppProvider.Helper.calcDetailsFromIndex(context);
              }
            });

    // Clear cached apk files. We used to just remove them after they'd
    // been installed, but this causes problems for proprietary gapps
    // users since the introduction of verification (on pre-4.2 Android),
    // because the install intent says it's finished when it hasn't.
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
    curTheme = Theme.valueOf(prefs.getString(Preferences.PREF_THEME, Preferences.DEFAULT_THEME));
    Utils.deleteFiles(Utils.getApkDownloadDir(this), null, ".apk");
    if (!Preferences.get().shouldCacheApks()) {
      Utils.deleteFiles(Utils.getApkCacheDir(this), null, ".apk");
    }

    // Index files which downloaded, but were not removed (e.g. due to F-Droid being force
    // closed during processing of the file, before getting a chance to delete). This may
    // include both "index-*-downloaded" and "index-*-extracted.xml" files. The first is from
    // either signed or unsigned repos, and the later is from signed repos.
    Utils.deleteFiles(getCacheDir(), "index-", null);

    // As above, but for legacy F-Droid clients that downloaded under a different name, and
    // extracted to the files directory rather than the cache directory.
    // TODO: This can be removed in a a few months or a year (e.g. 2016) because people will
    // have upgraded their clients, this code will have executed, and they will not have any
    // left over files any more. Even if they do hold off upgrading until this code is removed,
    // the only side effect is that they will have a few more MiB of storage taken up on their
    // device until they uninstall and re-install F-Droid.
    Utils.deleteFiles(getCacheDir(), "dl-", null);
    Utils.deleteFiles(getFilesDir(), "index-", null);

    UpdateService.schedule(getApplicationContext());
    bluetoothAdapter = getBluetoothAdapter();

    ImageLoaderConfiguration config =
        new ImageLoaderConfiguration.Builder(getApplicationContext())
            .imageDownloader(new IconDownloader(getApplicationContext()))
            .diskCache(
                new LimitedAgeDiskCache(
                    new File(
                        StorageUtils.getCacheDirectory(getApplicationContext(), true), "icons"),
                    null,
                    new FileNameGenerator() {
                      @Override
                      public String generate(String imageUri) {
                        return imageUri.substring(imageUri.lastIndexOf('/') + 1);
                      }
                    },
                    // 30 days in secs: 30*24*60*60 = 2592000
                    2592000))
            .threadPoolSize(4)
            .threadPriority(Thread.NORM_PRIORITY - 2) // Default is NORM_PRIORITY - 1
            .build();
    ImageLoader.getInstance().init(config);

    // TODO reintroduce PinningTrustManager and MemorizingTrustManager

    // initialized the local repo information
    FDroidApp.initWifiSettings();
    startService(new Intent(this, WifiStateChangeService.class));
    // if the HTTPS pref changes, then update all affected things
    Preferences.get()
        .registerLocalRepoHttpsListeners(
            new ChangeListener() {
              @Override
              public void onPreferenceChange() {
                startService(new Intent(FDroidApp.this, WifiStateChangeService.class));
              }
            });
  }