Program: 2023
Project: 2023
Buggy source:
private void addSystemTiles(ViewGroup parent,LayoutInflater inflater){
  final QuickSettingsBasicTile wifiTile=new QuickSettingsBasicTile(mContext);
  wifiTile.setOnClickListener(new View.OnClickListener(){
    @Override public void onClick(    View v){
      startSettingsActivity(android.provider.Settings.ACTION_WIFI_SETTINGS);
    }
  }
);
  if (LONG_PRESS_TOGGLES) {
    wifiTile.setOnLongClickListener(new View.OnLongClickListener(){
      @Override public boolean onLongClick(      View v){
        final boolean enable=(mWifiManager.getWifiState() != WifiManager.WIFI_STATE_ENABLED);
        new AsyncTask<Void,Void,Void>(){
          @Override protected Void doInBackground(          Void... args){
            final int wifiApState=mWifiManager.getWifiApState();
            if (enable && ((wifiApState == WifiManager.WIFI_AP_STATE_ENABLING) || (wifiApState == WifiManager.WIFI_AP_STATE_ENABLED))) {
              mWifiManager.setWifiApEnabled(null,false);
            }
            mWifiManager.setWifiEnabled(enable);
            return null;
          }
        }
.execute();
        wifiTile.setPressed(false);
        return true;
      }
    }
);
  }
  mModel.addWifiTile(wifiTile,new QuickSettingsModel.RefreshCallback(){
    @Override public void refreshView(    QuickSettingsTileView unused,    State state){
      WifiState wifiState=(WifiState)state;
      wifiTile.setImageResource(wifiState.iconId);
      wifiTile.setText(wifiState.label);
      wifiTile.setContentDescription(mContext.getString(R.string.accessibility_quick_settings_wifi,wifiState.signalContentDescription,(wifiState.connected) ? wifiState.label : "String_Node_Str"));
    }
  }
);
  parent.addView(wifiTile);
  if (mModel.deviceHasMobileData()) {
    QuickSettingsTileView rssiTile=(QuickSettingsTileView)inflater.inflate(R.layout.quick_settings_tile,parent,false);
    rssiTile.setContent(R.layout.quick_settings_tile_rssi,inflater);
    rssiTile.setOnClickListener(new View.OnClickListener(){
      @Override public void onClick(      View v){
        Intent intent=new Intent();
        intent.setComponent(new ComponentName("String_Node_Str","String_Node_Str"));
        startSettingsActivity(intent);
      }
    }
);
    mModel.addRSSITile(rssiTile,new QuickSettingsModel.RefreshCallback(){
      @Override public void refreshView(      QuickSettingsTileView view,      State state){
        RSSIState rssiState=(RSSIState)state;
        ImageView iv=(ImageView)view.findViewById(R.id.rssi_image);
        ImageView iov=(ImageView)view.findViewById(R.id.rssi_overlay_image);
        TextView tv=(TextView)view.findViewById(R.id.rssi_textview);
        iv.setImageDrawable(null);
        iv.setImageResource(rssiState.signalIconId);
        if (rssiState.dataTypeIconId > 0) {
          iov.setImageResource(rssiState.dataTypeIconId);
        }
 else {
          iov.setImageDrawable(null);
        }
        tv.setText(state.label);
        view.setContentDescription(mContext.getResources().getString(R.string.accessibility_quick_settings_mobile,rssiState.signalContentDescription,rssiState.dataContentDescription,state.label));
      }
    }
);
    parent.addView(rssiTile);
  }
  if (mContext.getResources().getBoolean(R.bool.quick_settings_show_rotation_lock) || DEBUG_GONE_TILES) {
    final QuickSettingsBasicTile rotationLockTile=new QuickSettingsBasicTile(mContext);
    rotationLockTile.setOnClickListener(new View.OnClickListener(){
      @Override public void onClick(      View v){
        boolean locked=RotationPolicy.isRotationLocked(mContext);
        RotationPolicy.setRotationLock(mContext,!locked);
      }
    }
);
    mModel.addRotationLockTile(rotationLockTile,new QuickSettingsModel.BasicRefreshCallback(rotationLockTile));
    parent.addView(rotationLockTile);
  }
  final QuickSettingsBasicTile batteryTile=new QuickSettingsBasicTile(mContext);
  batteryTile.setOnClickListener(new View.OnClickListener(){
    @Override public void onClick(    View v){
      startSettingsActivity(Intent.ACTION_POWER_USAGE_SUMMARY);
    }
  }
);
  mModel.addBatteryTile(batteryTile,new QuickSettingsModel.RefreshCallback(){
    @Override public void refreshView(    QuickSettingsTileView unused,    State state){
      QuickSettingsModel.BatteryState batteryState=(QuickSettingsModel.BatteryState)state;
      Drawable d=batteryState.pluggedIn ? mChargingBatteryLevels : mBatteryLevels;
      String t;
      if (batteryState.batteryLevel == 100) {
        t=mContext.getString(R.string.quick_settings_battery_charged_label);
      }
 else {
        t=batteryState.pluggedIn ? mContext.getString(R.string.quick_settings_battery_charging_label,batteryState.batteryLevel) : mContext.getString(R.string.status_bar_settings_battery_meter_format,batteryState.batteryLevel);
      }
      d.setLevel(batteryState.batteryLevel);
      batteryTile.setImageDrawable(d);
      batteryTile.setText(t);
      batteryTile.setContentDescription(mContext.getString(R.string.accessibility_quick_settings_battery,t));
    }
  }
);
  parent.addView(batteryTile);
  final QuickSettingsBasicTile airplaneTile=new QuickSettingsBasicTile(mContext);
  mModel.addAirplaneModeTile(airplaneTile,new QuickSettingsModel.RefreshCallback(){
    @Override public void refreshView(    QuickSettingsTileView unused,    State state){
      airplaneTile.setImageResource(state.iconId);
      String airplaneState=mContext.getString((state.enabled) ? R.string.accessibility_desc_on : R.string.accessibility_desc_off);
      airplaneTile.setContentDescription(mContext.getString(R.string.accessibility_quick_settings_airplane,airplaneState));
      airplaneTile.setText(state.label);
    }
  }
);
  parent.addView(airplaneTile);
  if (mModel.deviceSupportsBluetooth() || DEBUG_GONE_TILES) {
    final QuickSettingsBasicTile bluetoothTile=new QuickSettingsBasicTile(mContext);
    bluetoothTile.setOnClickListener(new View.OnClickListener(){
      @Override public void onClick(      View v){
        startSettingsActivity(android.provider.Settings.ACTION_BLUETOOTH_SETTINGS);
      }
    }
);
    if (LONG_PRESS_TOGGLES) {
      bluetoothTile.setOnLongClickListener(new View.OnLongClickListener(){
        @Override public boolean onLongClick(        View v){
          if (mBluetoothAdapter.isEnabled()) {
            mBluetoothAdapter.disable();
          }
 else {
            mBluetoothAdapter.enable();
          }
          bluetoothTile.setPressed(false);
          return true;
        }
      }
);
    }
    mModel.addBluetoothTile(bluetoothTile,new QuickSettingsModel.RefreshCallback(){
      @Override public void refreshView(      QuickSettingsTileView unused,      State state){
        BluetoothState bluetoothState=(BluetoothState)state;
        bluetoothTile.setImageResource(state.iconId);
        bluetoothTile.setContentDescription(mContext.getString(R.string.accessibility_quick_settings_bluetooth,bluetoothState.stateContentDescription));
        bluetoothTile.setText(state.label);
      }
    }
);
    parent.addView(bluetoothTile);
  }
}

Fixed version (ground truth):
private void addSystemTiles(ViewGroup parent,LayoutInflater inflater){
  final QuickSettingsBasicTile wifiTile=new QuickSettingsBasicTile(mContext);
  wifiTile.setOnClickListener(new View.OnClickListener(){
    @Override public void onClick(    View v){
      startSettingsActivity(android.provider.Settings.ACTION_WIFI_SETTINGS);
    }
  }
);
  if (LONG_PRESS_TOGGLES) {
    wifiTile.setOnLongClickListener(new View.OnLongClickListener(){
      @Override public boolean onLongClick(      View v){
        final boolean enable=(mWifiManager.getWifiState() != WifiManager.WIFI_STATE_ENABLED);
        new AsyncTask<Void,Void,Void>(){
          @Override protected Void doInBackground(          Void... args){
            final int wifiApState=mWifiManager.getWifiApState();
            if (enable && ((wifiApState == WifiManager.WIFI_AP_STATE_ENABLING) || (wifiApState == WifiManager.WIFI_AP_STATE_ENABLED))) {
              mWifiManager.setWifiApEnabled(null,false);
            }
            mWifiManager.setWifiEnabled(enable);
            return null;
          }
        }
.execute();
        wifiTile.setPressed(false);
        return true;
      }
    }
);
  }
  mModel.addWifiTile(wifiTile,new QuickSettingsModel.RefreshCallback(){
    @Override public void refreshView(    QuickSettingsTileView unused,    State state){
      WifiState wifiState=(WifiState)state;
      wifiTile.setImageResource(wifiState.iconId);
      wifiTile.setText(wifiState.label);
      wifiTile.setContentDescription(mContext.getString(R.string.accessibility_quick_settings_wifi,wifiState.signalContentDescription,(wifiState.connected) ? wifiState.label : "String_Node_Str"));
    }
  }
);
  parent.addView(wifiTile);
  if (mModel.deviceHasMobileData()) {
    QuickSettingsTileView rssiTile=(QuickSettingsTileView)inflater.inflate(R.layout.quick_settings_tile,parent,false);
    rssiTile.setContent(R.layout.quick_settings_tile_rssi,inflater);
    rssiTile.setOnClickListener(new View.OnClickListener(){
      @Override public void onClick(      View v){
        Intent intent=new Intent();
        intent.setComponent(new ComponentName("String_Node_Str","String_Node_Str"));
        startSettingsActivity(intent);
      }
    }
);
    mModel.addRSSITile(rssiTile,new QuickSettingsModel.RefreshCallback(){
      @Override public void refreshView(      QuickSettingsTileView view,      State state){
        RSSIState rssiState=(RSSIState)state;
        ImageView iv=(ImageView)view.findViewById(R.id.rssi_image);
        ImageView iov=(ImageView)view.findViewById(R.id.rssi_overlay_image);
        TextView tv=(TextView)view.findViewById(R.id.rssi_textview);
        iv.setImageDrawable(null);
        iv.setImageResource(rssiState.signalIconId);
        if (rssiState.dataTypeIconId > 0) {
          iov.setImageResource(rssiState.dataTypeIconId);
        }
 else {
          iov.setImageDrawable(null);
        }
        tv.setText(state.label);
        view.setContentDescription(mContext.getResources().getString(R.string.accessibility_quick_settings_mobile,rssiState.signalContentDescription,rssiState.dataContentDescription,state.label));
      }
    }
);
    parent.addView(rssiTile);
  }
  if (mContext.getResources().getBoolean(R.bool.quick_settings_show_rotation_lock) || DEBUG_GONE_TILES) {
    final QuickSettingsBasicTile rotationLockTile=new QuickSettingsBasicTile(mContext);
    rotationLockTile.setOnClickListener(new View.OnClickListener(){
      @Override public void onClick(      View v){
        boolean locked=RotationPolicy.isRotationLocked(mContext);
        RotationPolicy.setRotationLock(mContext,!locked);
      }
    }
);
    mModel.addRotationLockTile(rotationLockTile,new QuickSettingsModel.BasicRefreshCallback(rotationLockTile));
    parent.addView(rotationLockTile);
  }
  final QuickSettingsBasicTile batteryTile=new QuickSettingsBasicTile(mContext);
  batteryTile.setOnClickListener(new View.OnClickListener(){
    @Override public void onClick(    View v){
      startSettingsActivity(Intent.ACTION_POWER_USAGE_SUMMARY);
    }
  }
);
  mModel.addBatteryTile(batteryTile,new QuickSettingsModel.RefreshCallback(){
    @Override public void refreshView(    QuickSettingsTileView unused,    State state){
      QuickSettingsModel.BatteryState batteryState=(QuickSettingsModel.BatteryState)state;
      Drawable d=batteryState.pluggedIn ? mChargingBatteryLevels : mBatteryLevels;
      String t;
      if (batteryState.batteryLevel == 100) {
        t=mContext.getString(R.string.quick_settings_battery_charged_label);
      }
 else {
        t=batteryState.pluggedIn ? mContext.getString(R.string.quick_settings_battery_charging_label,batteryState.batteryLevel) : mContext.getString(R.string.status_bar_settings_battery_meter_format,batteryState.batteryLevel);
      }
      batteryTile.setImageDrawable(d);
      batteryTile.getImageView().setImageLevel(batteryState.batteryLevel);
      batteryTile.setText(t);
      batteryTile.setContentDescription(mContext.getString(R.string.accessibility_quick_settings_battery,t));
    }
  }
);
  parent.addView(batteryTile);
  final QuickSettingsBasicTile airplaneTile=new QuickSettingsBasicTile(mContext);
  mModel.addAirplaneModeTile(airplaneTile,new QuickSettingsModel.RefreshCallback(){
    @Override public void refreshView(    QuickSettingsTileView unused,    State state){
      airplaneTile.setImageResource(state.iconId);
      String airplaneState=mContext.getString((state.enabled) ? R.string.accessibility_desc_on : R.string.accessibility_desc_off);
      airplaneTile.setContentDescription(mContext.getString(R.string.accessibility_quick_settings_airplane,airplaneState));
      airplaneTile.setText(state.label);
    }
  }
);
  parent.addView(airplaneTile);
  if (mModel.deviceSupportsBluetooth() || DEBUG_GONE_TILES) {
    final QuickSettingsBasicTile bluetoothTile=new QuickSettingsBasicTile(mContext);
    bluetoothTile.setOnClickListener(new View.OnClickListener(){
      @Override public void onClick(      View v){
        startSettingsActivity(android.provider.Settings.ACTION_BLUETOOTH_SETTINGS);
      }
    }
);
    if (LONG_PRESS_TOGGLES) {
      bluetoothTile.setOnLongClickListener(new View.OnLongClickListener(){
        @Override public boolean onLongClick(        View v){
          if (mBluetoothAdapter.isEnabled()) {
            mBluetoothAdapter.disable();
          }
 else {
            mBluetoothAdapter.enable();
          }
          bluetoothTile.setPressed(false);
          return true;
        }
      }
);
    }
    mModel.addBluetoothTile(bluetoothTile,new QuickSettingsModel.RefreshCallback(){
      @Override public void refreshView(      QuickSettingsTileView unused,      State state){
        BluetoothState bluetoothState=(BluetoothState)state;
        bluetoothTile.setImageResource(state.iconId);
        bluetoothTile.setContentDescription(mContext.getString(R.string.accessibility_quick_settings_bluetooth,bluetoothState.stateContentDescription));
        bluetoothTile.setText(state.label);
      }
    }
);
    parent.addView(bluetoothTile);
  }
}