Ejemplo n.º 1
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    PackageManager pm = getPackageManager();
    ComponentName pluggedReceiver =
        new ComponentName(getApplicationContext(), PluggedReceiver.class);
    ComponentName unpluggedReceiver = new ComponentName(getApplication(), UnpluggedReceiver.class);
    pm.setComponentEnabledSetting(
        pluggedReceiver,
        PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
        PackageManager.DONT_KILL_APP);

    pm.setComponentEnabledSetting(
        unpluggedReceiver,
        PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
        PackageManager.DONT_KILL_APP);

    myListView = (ListView) findViewById(R.id.contactView);
    listItems = new ArrayList<String>();

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);

    Map<String, ?> keys = prefs.getAll();
    for (Map.Entry<String, ?> entry : keys.entrySet()) {
      listItems.add(entry.getKey().toString());
    }

    adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, listItems);
    myListView.setAdapter(adapter);
  }
 private void setLaunchFromBgEnabled(boolean enabled) {
   ComponentName componentName = new ComponentName(this, BackgroundTagActivity.class);
   PackageManager packageManager = getPackageManager();
   int newState = enabled ? COMPONENT_ENABLED_STATE_ENABLED : COMPONENT_ENABLED_STATE_DISABLED;
   packageManager.setComponentEnabledSetting(
       componentName, newState, PackageManager.DONT_KILL_APP);
 }
  private void startLocationService() {

    mAlarm = (AlarmManager) getSystemService(ALARM_SERVICE);

    Intent i = new Intent(this, LocationPoller.class);

    i.putExtra(LocationPoller.EXTRA_INTENT, new Intent(this, LocationReceiver.class));

    i.putExtra(LocationPoller.EXTRA_PROVIDER, LocationManager.GPS_PROVIDER);

    mPendingIntent = PendingIntent.getBroadcast(this, 0, i, 0);

    mAlarm.setInexactRepeating(
        AlarmManager.ELAPSED_REALTIME_WAKEUP,
        SystemClock.elapsedRealtime(),
        PERIOD,
        mPendingIntent);

    ComponentName receiver = new ComponentName(this, BootReceiver.class);
    PackageManager pm = getPackageManager();

    pm.setComponentEnabledSetting(
        receiver, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);

    DebugMode.logger(DEBUG_TAG, "Service initialized");
  }
  private static void setAppState(Context context, boolean install, int slotId) {
    if (context == null) {
      return;
    }
    PackageManager pm = context.getPackageManager();
    if (pm == null) {
      return;
    }

    ComponentName cName;

    // check that STK app package is known to the PackageManager
    if (slotId == 0) {
      cName = new ComponentName("com.android.stk", "com.android.stk.StkLauncherActivity");
    } else {
      cName = new ComponentName("com.android.stk", "com.android.stk.StkLauncherActivity2");
    }

    int state =
        install
            ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
            : PackageManager.COMPONENT_ENABLED_STATE_DISABLED;

    try {
      pm.setComponentEnabledSetting(cName, state, PackageManager.DONT_KILL_APP);
    } catch (Exception e) {
      CatLog.d("StkAppInstaller", "Could not change STK app state");
    }
  }
Ejemplo n.º 5
0
 @Override
 public void onTaskRemoved(Intent rootIntent) {
   super.onTaskRemoved(rootIntent);
   Log.i(TAG, "Unregistering receiver");
   PackageManager pm = getPackageManager();
   ComponentName component = new ComponentName(this, CalendarChangeReceiver.class);
   pm.setComponentEnabledSetting(
       component, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
 }
  private void disableComponent(Context context, String klass) {
    ComponentName name = new ComponentName(context, klass);
    PackageManager pm = context.getPackageManager();

    // We need the DONT_KILL_APP flag, otherwise we will be killed
    // immediately because we are in the same app.
    pm.setComponentEnabledSetting(
        name, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
  }
 public static void toggleComponent(Context context, Class componentClass, boolean enable) {
   ComponentName componentName = new ComponentName(context, componentClass);
   PackageManager pm = context.getPackageManager();
   pm.setComponentEnabledSetting(
       componentName,
       enable
           ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
           : PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
       PackageManager.DONT_KILL_APP);
 }
Ejemplo n.º 8
0
 private void toggleReceiver(boolean enable) {
   ComponentName receiver = new ComponentName(mContext, CancelReceiver.class);
   PackageManager pm = mContext.getPackageManager();
   pm.setComponentEnabledSetting(
       receiver,
       enable
           ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
           : PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
       PackageManager.DONT_KILL_APP);
 }
Ejemplo n.º 9
0
 private void enableComponents(Class<?>... components) {
   PackageManager packageManager = getPackageManager();
   for (Class<?> component : components) {
     ComponentName componentName = new ComponentName(this, component);
     packageManager.setComponentEnabledSetting(
         componentName,
         PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
         PackageManager.DONT_KILL_APP);
   }
 }
 private void triggerEasterEgg(
     boolean notReplyToOther, boolean hasEasterEggTriggerText, boolean hasEasterEggRestoreText) {
   final PackageManager pm = getPackageManager();
   final ComponentName main = new ComponentName(this, MainActivity.class);
   final ComponentName main2 = new ComponentName(this, MainHondaJOJOActivity.class);
   if (hasEasterEggTriggerText && notReplyToOther) {
     pm.setComponentEnabledSetting(
         main, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
     pm.setComponentEnabledSetting(
         main2, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
     showToast(R.string.easter_egg_triggered_message, Toast.LENGTH_SHORT);
   } else if (hasEasterEggRestoreText) {
     pm.setComponentEnabledSetting(
         main, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
     pm.setComponentEnabledSetting(
         main2, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
     showToast(R.string.icon_restored_message, Toast.LENGTH_SHORT);
   }
 }
Ejemplo n.º 11
0
  private static void enableService(final Context context, final String serviceName) {

    final PackageManager pm = (PackageManager) context.getPackageManager();
    final ComponentName componentName = new ComponentName(context.getPackageName(), serviceName);
    Log.d(LOG_TAG, "Enabling service: " + componentName);
    pm.setComponentEnabledSetting(
        componentName,
        PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
        PackageManager.DONT_KILL_APP);
  }
Ejemplo n.º 12
0
 /** Makes an attempt to connect to a data network. */
 public static void connectToDataNetwork(Context context) {
   // Enable the Connectivity Changed Receiver to listen for
   // connection to a network so we can send pending messages.
   PackageManager pm = context.getPackageManager();
   ComponentName connectivityReceiver =
       new ComponentName(context, ConnectivityChangedReceiver.class);
   pm.setComponentEnabledSetting(
       connectivityReceiver,
       PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
       PackageManager.DONT_KILL_APP);
 }
Ejemplo n.º 13
0
  public void startReceivers(View view) {
    PackageManager pm = getPackageManager();
    ComponentName pluggedReceiver =
        new ComponentName(getApplicationContext(), PluggedReceiver.class);
    ComponentName unpluggedReceiver = new ComponentName(getApplication(), UnpluggedReceiver.class);
    pm.setComponentEnabledSetting(
        pluggedReceiver,
        PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
        PackageManager.DONT_KILL_APP);

    pm.setComponentEnabledSetting(
        unpluggedReceiver,
        PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
        PackageManager.DONT_KILL_APP);

    Button startButton = (Button) findViewById(R.id.startReceivers);
    Button stopButton = (Button) findViewById(R.id.stopReceivers);
    stopButton.setEnabled(true);
    startButton.setEnabled(false);
  }
Ejemplo n.º 14
0
  public void disableBatteryBroadcastReceiver() {

    ComponentName receiver1 =
        new ComponentName(
            getApplicationContext(),
            project.metrodatacollector.Uploader.BatteryBroadcastHandler.class);

    PackageManager pm = getApplicationContext().getPackageManager();

    pm.setComponentEnabledSetting(
        receiver1, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
  }
 public void setHideAppIcon() {
   PackageManager packageManager = getPackageManager();
   ComponentName componentName = new ComponentName(AppSettingActivity.this, SplashActivity.class);
   int res = packageManager.getComponentEnabledSetting(componentName);
   if (res == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT
       || res == PackageManager.COMPONENT_ENABLED_STATE_ENABLED) {
     // 隐藏应用图标
     packageManager.setComponentEnabledSetting(
         componentName,
         PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
         PackageManager.DONT_KILL_APP);
     appLockApplication.appIconIsHided = true;
     LogUtil.e("colin", "隐藏应用图标");
   } else {
     // 显示应用图标
     packageManager.setComponentEnabledSetting(
         componentName,
         PackageManager.COMPONENT_ENABLED_STATE_DEFAULT,
         PackageManager.DONT_KILL_APP);
     appLockApplication.appIconIsHided = false;
     LogUtil.e("colin", "显示应用图标");
   }
 }
Ejemplo n.º 16
0
  static void register(PackageManager pm, boolean autostart) {
    System.out.println("Autostart is " + autostart);
    int enabled =
        autostart
            ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
            : PackageManager.COMPONENT_ENABLED_STATE_DISABLED;

    System.out.println("Setting to " + enabled);
    pm.setComponentEnabledSetting(
        new ComponentName(
            "de.yazo_games.mensaguthaben", "de.yazo_games.mensaguthaben.ActivityAlias"),
        enabled,
        PackageManager.DONT_KILL_APP);
  }
Ejemplo n.º 17
0
  private void setIcon(boolean enableAltIcon) {
    Context ctx = this;
    PackageManager pm = getPackageManager();
    ActivityManager am = (ActivityManager) getSystemService(Activity.ACTIVITY_SERVICE);

    // Enable/disable activity-aliases

    pm.setComponentEnabledSetting(
        new ComponentName(ctx, "org.witness.informacam.app.InformaActivity-Alt"),
        enableAltIcon
            ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
            : PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
        PackageManager.DONT_KILL_APP);

    pm.setComponentEnabledSetting(
        new ComponentName(ctx, "org.witness.informacam.app.InformaActivity"),
        (!enableAltIcon)
            ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
            : PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
        PackageManager.DONT_KILL_APP);

    // Find launcher and kill it

    Intent i = new Intent(Intent.ACTION_MAIN);
    i.addCategory(Intent.CATEGORY_HOME);
    i.addCategory(Intent.CATEGORY_DEFAULT);
    List<ResolveInfo> resolves = pm.queryIntentActivities(i, 0);
    for (ResolveInfo res : resolves) {
      if (res.activityInfo != null) {
        am.killBackgroundProcesses(res.activityInfo.packageName);
      }
    }

    // Change ActionBar icon

  }
  public static void unhide(Context ctx, List<ActionResult> lista, JSONObject options) {
    PreyLogger.i("started unhide");
    PreyWebServices.getInstance()
        .sendNotifyActionResultPreyHttp(
            ctx, UtilJson.makeMapParam("stop", "camouflage", "stopped"));
    PreyConfig.getPreyConfig(ctx).setCamouflageSet(false);

    ComponentName componentToEnabled =
        new ComponentName("com.prey", "com.prey.activities.LoginActivity");
    PackageManager pm = ctx.getApplicationContext().getPackageManager();
    pm.setComponentEnabledSetting(
        componentToEnabled,
        PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
        PackageManager.DONT_KILL_APP);
    PreyLogger.i("stopped unhide");
    PreyConfig.getPreyConfig(ctx).setLastEvent("camouflage_unhide");
  }
  private void removeLauncherIcon() {
    String className = MainActivity.class.getCanonicalName().replace(".MainActivity", ".Launcher");
    ComponentName componentName = new ComponentName(getPackageName(), className);
    PackageManager packageManager = getPackageManager();
    if (packageManager.getComponentEnabledSetting(componentName)
        != PackageManager.COMPONENT_ENABLED_STATE_DISABLED) {
      packageManager.setComponentEnabledSetting(
          componentName,
          PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
          PackageManager.DONT_KILL_APP);

      AlertDialog.Builder builder = new AlertDialog.Builder(this);
      builder.setIcon(android.R.drawable.ic_dialog_alert);
      builder.setMessage(getString(R.string.hidden_alert));
      builder.setPositiveButton(android.R.string.ok, null);
      builder.show();
    }
  }
  @Override
  public void onReceive(Context context, Intent intent) {
    boolean batteryLow = intent.getAction().equals(Intent.ACTION_BATTERY_LOW);

    PackageManager pm = context.getPackageManager();
    ComponentName passiveLocationReceiver =
        new ComponentName(context, PassiveLocationChangedReceiver.class);

    // Disable the passive location update receiver when the battery state is low.
    // Disabling the Receiver will prevent the app from initiating the background
    // downloads of nearby locations.
    pm.setComponentEnabledSetting(
        passiveLocationReceiver,
        batteryLow
            ? PackageManager.COMPONENT_ENABLED_STATE_DISABLED
            : PackageManager.COMPONENT_ENABLED_STATE_DEFAULT,
        PackageManager.DONT_KILL_APP);
  }
Ejemplo n.º 21
0
  public void setNextAlarm(Context context) {
    SharedPreferences prefs =
        PreferenceManager.getDefaultSharedPreferences(ApplicationScreen.getMainContext());

    pauseBetweenShotsVal = prefs.getInt(MainScreen.sPhotoTimeLapseCaptureIntervalPref, 5);
    if (pauseBetweenShotsVal == 0) {
      return;
    }

    pauseBetweenShots = pauseBetweenShotsVal;

    pauseBetweenShotsMeasurment =
        prefs.getInt(MainScreen.sPhotoTimeLapseCaptureIntervalMeasurmentPref, 0);

    switch (pauseBetweenShotsMeasurment) {
      case 0: // secs
        pauseBetweenShots = pauseBetweenShots * 1000;
        break;
      case 1: // mins
        pauseBetweenShots = pauseBetweenShots * 60000;
        break;
      case 2: // hours
        pauseBetweenShots = pauseBetweenShots * 60000 * 60;
        break;
      case 3: // days
        pauseBetweenShots = pauseBetweenShots * 60000 * 60 * 24;
        break;
      default:
        break;
    }

    Editor e = prefs.edit();
    e.putInt(MainScreen.sPhotoTimeLapseCount, prefs.getInt(MainScreen.sPhotoTimeLapseCount, 0) + 1);
    e.commit();
    this.setAlarm(context, pauseBetweenShots);

    ComponentName receiver = new ComponentName(context, AlarmReceiver.class);
    PackageManager pm = context.getPackageManager();

    pm.setComponentEnabledSetting(
        receiver, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);

    if (wakeLock != null) if (wakeLock.isHeld()) wakeLock.release();
  }
  @Override
  public void onReceive(Context context, Intent intent) {
    Intent serviceIntent = new Intent(context, WorkaroundDisableService.class);
    context.stopService(serviceIntent);

    /*
     * Re-enable fake authenticator for next boot.
     *
     * Note: there might be a race condition if the checker task is still running. It might disable the authenticator again.
     *
     * TODO: take care of this issue
     */
    PackageManager pm = context.getPackageManager();
    ComponentName authenticatorComponent = new ComponentName(context, AuthenticationService.class);
    Log.i(TAG, "re-enabling workaround authenticator");
    pm.setComponentEnabledSetting(
        authenticatorComponent,
        PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
        PackageManager.DONT_KILL_APP);
  }
Ejemplo n.º 23
0
Archivo: K9.java Proyecto: klonikar/k-9
  private static void setServicesEnabled(Context context, boolean enabled, Integer wakeLockId) {

    PackageManager pm = context.getPackageManager();

    if (!enabled
        && pm.getComponentEnabledSetting(new ComponentName(context, MailService.class))
            == PackageManager.COMPONENT_ENABLED_STATE_ENABLED) {
      /*
       * If no accounts now exist but the service is still enabled we're about to disable it
       * so we'll reschedule to kill off any existing alarms.
       */
      MailService.actionReset(context, wakeLockId);
    }
    Class<?>[] classes = {MessageCompose.class, BootReceiver.class, MailService.class};

    for (Class<?> clazz : classes) {

      boolean alreadyEnabled =
          pm.getComponentEnabledSetting(new ComponentName(context, clazz))
              == PackageManager.COMPONENT_ENABLED_STATE_ENABLED;

      if (enabled != alreadyEnabled) {
        pm.setComponentEnabledSetting(
            new ComponentName(context, clazz),
            enabled
                ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
                : PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
            PackageManager.DONT_KILL_APP);
      }
    }

    if (enabled
        && pm.getComponentEnabledSetting(new ComponentName(context, MailService.class))
            == PackageManager.COMPONENT_ENABLED_STATE_ENABLED) {
      /*
       * And now if accounts do exist then we've just enabled the service and we want to
       * schedule alarms for the new accounts.
       */
      MailService.actionReset(context, wakeLockId);
    }
  }
Ejemplo n.º 24
0
  @Override
  protected void onCreate(Bundle icicle) {
    super.onCreate(icicle);

    // Add a persistent setting to allow other apps to know the device has been provisioned.
    Settings.Global.putInt(getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 1);

    // Add a persistent setting to allow other apps to know the user has complete the
    // setup wizard. This value is used by some components of the system (like QuickSettings
    // or KeyguardSelector). This flag need to be set, before the provisioned bit was set.
    Settings.Secure.putInt(getContentResolver(), Settings.Secure.USER_SETUP_COMPLETE, 1);

    // remove this activity from the package manager.
    PackageManager pm = getPackageManager();
    ComponentName name = new ComponentName(this, DefaultActivity.class);
    pm.setComponentEnabledSetting(
        name, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);

    // terminate the activity.
    finish();
  }
Ejemplo n.º 25
0
  public static void hide(Context ctx, List<ActionResult> lista, JSONObject parameters) {
    PreyLogger.i("started hide");
    String messageId = null;
    try {
      messageId = parameters.getString(PreyConfig.MESSAGE_ID);
    } catch (Exception e) {
    }
    PreyWebServices.getInstance()
        .sendNotifyActionResultPreyHttp(
            ctx, UtilJson.makeMapParam("start", "camouflage", "started", null));
    PreyConfig.getPreyConfig(ctx).setCamouflageSet(true);

    ComponentName componentToDisabled =
        new ComponentName("com.prey", "com.prey.activities.LoginActivity");
    PackageManager pm = ctx.getPackageManager();
    pm.setComponentEnabledSetting(
        componentToDisabled,
        PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
        PackageManager.DONT_KILL_APP);
    PreyLogger.i("stopped hide");
    PreyConfig.getPreyConfig(ctx).setLastEvent("camouflage_hide");
  }
  public static void schedule(Context context, long interval) {
    ComponentName receiver = new ComponentName(context, SyncBroadcastReceiver.class);
    PackageManager pm = context.getPackageManager();
    pm.setComponentEnabledSetting(
        receiver, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);

    AlarmManager alarmMgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    Intent intent = new Intent(context, SyncBroadcastReceiver.class);
    PendingIntent alarmIntent = PendingIntent.getBroadcast(context, 0, intent, 0);

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
      alarmMgr.setExact(
          AlarmManager.ELAPSED_REALTIME_WAKEUP,
          SystemClock.elapsedRealtime() + interval,
          alarmIntent);
    } else {
      alarmMgr.setExactAndAllowWhileIdle(
          AlarmManager.ELAPSED_REALTIME_WAKEUP,
          SystemClock.elapsedRealtime() + interval,
          alarmIntent);
    }

    Log.d("DexcomShareDashclock", "Sync scheduled in " + (int) (interval / 60000) + " minutes");
  }
  /**
   * {@inheritDoc} Perform a checkin the specified venue. If the checkin fails, add it to the queue
   * and set an alarm to retry.
   *
   * <p>Query the checkin queue to see if there are pending checkins to be retried.
   */
  @Override
  protected void onHandleIntent(Intent intent) {
    // Retrieve the details for the checkin to perform.
    String reference = intent.getStringExtra(PlacesConstants.EXTRA_KEY_REFERENCE);
    String id = intent.getStringExtra(PlacesConstants.EXTRA_KEY_ID);
    long timeStamp = intent.getLongExtra(PlacesConstants.EXTRA_KEY_TIME_STAMP, 0);

    // Check if we're running in the foreground, if not, check if
    // we have permission to do background updates.
    boolean backgroundAllowed = cm.getBackgroundDataSetting();
    boolean inBackground =
        sharedPreferences.getBoolean(PlacesConstants.EXTRA_KEY_IN_BACKGROUND, true);

    if (reference != null && !backgroundAllowed && inBackground) {
      addToQueue(timeStamp, reference, id);
      return;
    }

    // Check to see if we are connected to a data network.
    NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
    boolean isConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting();

    // If we're not connected then disable the retry Alarm, enable the Connectivity Changed Receiver
    // and add the new checkin directly to the queue. The Connectivity Changed Receiver will listen
    // for when we connect to a network and start this service to retry the checkins.
    if (!isConnected) {
      // No connection so no point triggering an alarm to retry until we're connected.
      alarmManager.cancel(retryQueuedCheckinsPendingIntent);

      // Enable the Connectivity Changed Receiver to listen for connection to a network
      // so we can commit the pending checkins.
      PackageManager pm = getPackageManager();
      ComponentName connectivityReceiver =
          new ComponentName(this, ConnectivityChangedReceiver.class);
      pm.setComponentEnabledSetting(
          connectivityReceiver,
          PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
          PackageManager.DONT_KILL_APP);

      // Add this checkin to the queue.
      addToQueue(timeStamp, reference, id);
    } else {
      // Execute the checkin. If it fails, add it to the retry queue.
      if (reference != null) {
        if (!checkin(timeStamp, reference, id)) addToQueue(timeStamp, reference, id);
      }

      // Retry the queued checkins.
      ArrayList<String> successfulCheckins = new ArrayList<String>();
      Cursor queuedCheckins =
          contentResolver.query(QueuedCheckinsContentProvider.CONTENT_URI, null, null, null, null);
      try {
        // Retry each checkin.
        while (queuedCheckins.moveToNext()) {
          long queuedTimeStamp =
              queuedCheckins.getLong(
                  queuedCheckins.getColumnIndex(QueuedCheckinsContentProvider.KEY_TIME_STAMP));
          String queuedReference =
              queuedCheckins.getString(
                  queuedCheckins.getColumnIndex(QueuedCheckinsContentProvider.KEY_REFERENCE));
          String queuedId =
              queuedCheckins.getString(
                  queuedCheckins.getColumnIndex(QueuedCheckinsContentProvider.KEY_ID));
          if (queuedReference == null || checkin(queuedTimeStamp, queuedReference, queuedId))
            successfulCheckins.add(queuedReference);
        }

        // Delete the queued checkins that were successful.
        if (successfulCheckins.size() > 0) {
          StringBuilder sb =
              new StringBuilder(
                  "("
                      + QueuedCheckinsContentProvider.KEY_REFERENCE
                      + "='"
                      + successfulCheckins.get(0)
                      + "'");
          for (int i = 1; i < successfulCheckins.size(); i++)
            sb.append(
                " OR "
                    + QueuedCheckinsContentProvider.KEY_REFERENCE
                    + " = '"
                    + successfulCheckins.get(i)
                    + "'");
          sb.append(")");
          int deleteCount =
              contentResolver.delete(
                  QueuedCheckinsContentProvider.CONTENT_URI, sb.toString(), null);
          Log.d(TAG, "Deleted: " + deleteCount);
        }

        // If there are still queued checkins then set a non-waking alarm to retry them.
        queuedCheckins.requery();
        if (queuedCheckins.getCount() > 0) {
          long triggerAtTime = System.currentTimeMillis() + PlacesConstants.CHECKIN_RETRY_INTERVAL;
          alarmManager.set(
              AlarmManager.ELAPSED_REALTIME, triggerAtTime, retryQueuedCheckinsPendingIntent);
        } else alarmManager.cancel(retryQueuedCheckinsPendingIntent);
      } finally {
        queuedCheckins.close();
      }
    }
  }
  @Override
  public void onCreate() {
    if (BuildConfig.DEBUG) {
      StrictModeUtils.detectAllVmPolicy();
    }
    super.onCreate();
    initDebugMode();
    initBugReport();
    mHandler = new Handler();
    initializeAsyncTask();
    initAccountColor(this);

    final PackageManager pm = getPackageManager();
    final ComponentName main = new ComponentName(this, MainActivity.class);
    final ComponentName main2 = new ComponentName(this, MainHondaJOJOActivity.class);
    final boolean mainDisabled =
        pm.getComponentEnabledSetting(main) != PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
    final boolean main2Disabled =
        pm.getComponentEnabledSetting(main2) != PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
    final boolean noEntry = mainDisabled && main2Disabled;
    if (noEntry) {
      pm.setComponentEnabledSetting(
          main, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
    } else if (!mainDisabled) {
      pm.setComponentEnabledSetting(
          main2, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
    }
    if (!Utils.isComposeNowSupported(this)) {
      final ComponentName assist = new ComponentName(this, AssistLauncherActivity.class);
      pm.setComponentEnabledSetting(
          assist, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
    }

    migrateUsageStatisticsPreferences();
    startRefreshServiceIfNeeded(this);

    reloadConnectivitySettings();

    DependencyHolder holder = DependencyHolder.get(this);
    registerActivityLifecycleCallbacks(holder.getActivityTracker());

    final IntentFilter packageFilter = new IntentFilter();
    packageFilter.addAction(Intent.ACTION_PACKAGE_CHANGED);
    packageFilter.addAction(Intent.ACTION_PACKAGE_ADDED);
    packageFilter.addAction(Intent.ACTION_PACKAGE_REMOVED);
    packageFilter.addAction(Intent.ACTION_PACKAGE_REPLACED);
    registerReceiver(
        new BroadcastReceiver() {
          @Override
          public void onReceive(Context context, Intent intent) {
            final int uid = intent.getIntExtra(Intent.EXTRA_UID, -1);
            final String[] packages = getPackageManager().getPackagesForUid(uid);
            DependencyHolder holder = DependencyHolder.get(context);
            final ExternalThemeManager manager = holder.getExternalThemeManager();
            if (ArrayUtils.contains(packages, manager.getEmojiPackageName())) {
              manager.reloadEmojiPreferences();
            }
          }
        },
        packageFilter);
  }