diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 80ce158..5e0b3c6 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -78,22 +78,6 @@ android:value="true" /> - - - - - - - - - Off Camera in use - - Percentage-based charge control - Control when the device stops and starts charging - Use percentage-based charge control - Stop charging level - Stop charging when the set percentage is reached - Start charging level - Resume charging when the set percentage is reached - Stop level must be above start level! - Start level must be below stop level! - Charge control may interfere with adaptive charging. - Pixel torch A configurable flashlight tile and volume button service diff --git a/res/xml/charge_control.xml b/res/xml/charge_control.xml deleted file mode 100644 index 4352297..0000000 --- a/res/xml/charge_control.xml +++ /dev/null @@ -1,40 +0,0 @@ - - - - - - - - - - - - - - - diff --git a/sepolicy/pixelparts_app.te b/sepolicy/pixelparts_app.te index d669d4d..fed34e2 100644 --- a/sepolicy/pixelparts_app.te +++ b/sepolicy/pixelparts_app.te @@ -30,11 +30,9 @@ allow pixelparts_app system_app_data_file:{ file lnk_file } create_file_perms; allow pixelparts_app system_data_file:dir search; allow pixelparts_app { - sysfs_batteryinfo sysfs_leds }:file rw_file_perms; allow pixelparts_app { - sysfs_batteryinfo sysfs_leds }:dir r_dir_perms; diff --git a/src/org/evolution/pixelparts/Constants.java b/src/org/evolution/pixelparts/Constants.java index ce9cd48..48e2d40 100644 --- a/src/org/evolution/pixelparts/Constants.java +++ b/src/org/evolution/pixelparts/Constants.java @@ -7,15 +7,6 @@ package org.evolution.pixelparts; public class Constants { - // Charge control - public static final String KEY_CHARGE_CONTROL = "charge_control"; - public static final String KEY_STOP_CHARGING = "stop_charging"; - public static final String KEY_START_CHARGING = "start_charging"; - public static final String NODE_STOP_CHARGING = "/sys/devices/platform/google,charger/charge_stop_level"; - public static final String NODE_START_CHARGING = "/sys/devices/platform/google,charger/charge_start_level"; - public static final String DEFAULT_STOP_CHARGING = "100"; - public static final String DEFAULT_START_CHARGING = "0"; - // Pixel torch public static final String KEY_PIXEL_TORCH_CYCLE_MODES = "pixel_torch_cycle_modes"; public static final String KEY_PIXEL_TORCH_BUTTON_SERVICE = "pixel_torch_button_service"; diff --git a/src/org/evolution/pixelparts/Startup.java b/src/org/evolution/pixelparts/Startup.java index c6fd6ef..6240826 100644 --- a/src/org/evolution/pixelparts/Startup.java +++ b/src/org/evolution/pixelparts/Startup.java @@ -12,7 +12,6 @@ import android.content.Intent; import org.evolution.pixelparts.autohbm.AutoHbmActivity; import org.evolution.pixelparts.autohbm.AutoHbmFragment; import org.evolution.pixelparts.autohbm.AutoHbmTileService; -import org.evolution.pixelparts.chargecontrol.ChargeControlFragment; import org.evolution.pixelparts.pixeltorch.PixelTorchActivity; import org.evolution.pixelparts.pixeltorch.PixelTorchFragment; import org.evolution.pixelparts.pixeltorch.PixelTorchButtonService; @@ -42,10 +41,6 @@ public class Startup extends BroadcastReceiver { AutoHbmFragment.isHbmSupported(context) ); - // Charge control - ChargeControlFragment.restoreStartChargingSetting(context); - ChargeControlFragment.restoreStopChargingSetting(context); - // PixelTorch ComponentUtils.toggleComponent( context, diff --git a/src/org/evolution/pixelparts/chargecontrol/ChargeControlActivity.java b/src/org/evolution/pixelparts/chargecontrol/ChargeControlActivity.java deleted file mode 100644 index fdd7228..0000000 --- a/src/org/evolution/pixelparts/chargecontrol/ChargeControlActivity.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (C) 2023-2024 The Evolution X Project - * SPDX-License-Identifier: Apache-2.0 - */ - -package org.evolution.pixelparts.chargecontrol; - -import android.os.Bundle; - -import com.android.settingslib.collapsingtoolbar.CollapsingToolbarBaseActivity; - -public class ChargeControlActivity extends CollapsingToolbarBaseActivity { - - private static final String TAG = "ChargeControl"; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - getSupportFragmentManager().beginTransaction().replace(com.android.settingslib.collapsingtoolbar.R.id.content_frame, - new ChargeControlFragment(), TAG).commit(); - } -} diff --git a/src/org/evolution/pixelparts/chargecontrol/ChargeControlFragment.java b/src/org/evolution/pixelparts/chargecontrol/ChargeControlFragment.java deleted file mode 100644 index f0e60b6..0000000 --- a/src/org/evolution/pixelparts/chargecontrol/ChargeControlFragment.java +++ /dev/null @@ -1,160 +0,0 @@ -/* - * Copyright (C) 2023-2024 The Evolution X Project - * SPDX-License-Identifier: Apache-2.0 - */ - -package org.evolution.pixelparts.chargecontrol; - -import android.content.Context; -import android.content.SharedPreferences; -import android.os.Bundle; -import android.widget.CompoundButton; -import android.widget.CompoundButton.OnCheckedChangeListener; -import android.widget.Toast; - -import androidx.preference.Preference; -import androidx.preference.PreferenceFragmentCompat; -import androidx.preference.PreferenceManager; - -import com.android.settingslib.widget.MainSwitchPreference; - -import org.evolution.pixelparts.Constants; -import org.evolution.pixelparts.CustomSeekBarPreference; -import org.evolution.pixelparts.R; -import org.evolution.pixelparts.utils.FileUtils; - -public class ChargeControlFragment extends PreferenceFragmentCompat - implements OnCheckedChangeListener, Preference.OnPreferenceChangeListener { - - // Charge control preference - private MainSwitchPreference mChargeControlSwitch; - - // Stop/Start preferences - private CustomSeekBarPreference mStopChargingPreference; - private CustomSeekBarPreference mStartChargingPreference; - - @Override - public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { - setPreferencesFromResource(R.xml.charge_control, rootKey); - - SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(getContext()); - - // Charge control preference - mChargeControlSwitch = findPreference(Constants.KEY_CHARGE_CONTROL); - mChargeControlSwitch.setChecked(sharedPrefs.getBoolean(Constants.KEY_CHARGE_CONTROL, false)); - mChargeControlSwitch.addOnSwitchChangeListener(this); - - // Stop preference - mStopChargingPreference = findPreference(Constants.KEY_STOP_CHARGING); - if (FileUtils.isFileWritable(Constants.NODE_STOP_CHARGING)) { - mStopChargingPreference.setValue(sharedPrefs.getInt(Constants.KEY_STOP_CHARGING, - Integer.parseInt(FileUtils.getFileValue(Constants.NODE_STOP_CHARGING, Constants.DEFAULT_STOP_CHARGING)))); - mStopChargingPreference.setOnPreferenceChangeListener(this); - } else { - mStopChargingPreference.setSummary(getString(R.string.kernel_node_access_error)); - mStopChargingPreference.setEnabled(false); - } - mStopChargingPreference.setVisible(mChargeControlSwitch.isChecked()); - - // Start preference - mStartChargingPreference = findPreference(Constants.KEY_START_CHARGING); - if (FileUtils.isFileWritable(Constants.NODE_START_CHARGING)) { - mStartChargingPreference.setValue(sharedPrefs.getInt(Constants.KEY_START_CHARGING, - Integer.parseInt(FileUtils.getFileValue(Constants.NODE_START_CHARGING, Constants.DEFAULT_START_CHARGING)))); - mStartChargingPreference.setOnPreferenceChangeListener(this); - } else { - mStartChargingPreference.setSummary(getString(R.string.kernel_node_access_error)); - mStartChargingPreference.setEnabled(false); - } - mStartChargingPreference.setVisible(mChargeControlSwitch.isChecked()); - } - - @Override - public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - SharedPreferences.Editor prefChange = PreferenceManager.getDefaultSharedPreferences(getContext()).edit(); - - prefChange.putBoolean(Constants.KEY_CHARGE_CONTROL, isChecked).apply(); - - mStopChargingPreference.setVisible(isChecked); - mStartChargingPreference.setVisible(isChecked); - - if (!isChecked) { - // Stop preference - int defaultStopCharging = 100; - prefChange.putInt(Constants.KEY_STOP_CHARGING, defaultStopCharging).apply(); - FileUtils.writeValue(Constants.NODE_STOP_CHARGING, Integer.toString(defaultStopCharging)); - mStopChargingPreference.refresh(defaultStopCharging); - - // Start preference - int defaultStartCharging = 0; - prefChange.putInt(Constants.KEY_START_CHARGING, defaultStartCharging).apply(); - FileUtils.writeValue(Constants.NODE_START_CHARGING, Integer.toString(defaultStartCharging)); - mStartChargingPreference.refresh(defaultStartCharging); - } - } - - @Override - public boolean onPreferenceChange(Preference preference, Object newValue) { - // Stop preference - if (preference == mStopChargingPreference) { - SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(getContext()); - int value = Integer.parseInt(newValue.toString()); - int stopLevel = Integer.parseInt(newValue.toString()); - int startLevel = sharedPrefs.getInt(Constants.KEY_START_CHARGING, 0); - if (startLevel >= stopLevel) { - startLevel = stopLevel - 1; - sharedPrefs.edit().putInt(Constants.KEY_START_CHARGING, startLevel).apply(); - FileUtils.writeValue(Constants.NODE_START_CHARGING, String.valueOf(startLevel)); - mStartChargingPreference.refresh(startLevel); - Toast.makeText(getContext(), R.string.stop_below_start_error, Toast.LENGTH_SHORT).show(); - - } - sharedPrefs.edit().putInt(Constants.KEY_STOP_CHARGING, value).apply(); - FileUtils.writeValue(Constants.NODE_STOP_CHARGING, String.valueOf(value)); - return true; - } - // Start preference - else if (preference == mStartChargingPreference) { - SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(getContext()); - int value = Integer.parseInt(newValue.toString()); - int startLevel = Integer.parseInt(newValue.toString()); - int stopLevel = sharedPrefs.getInt(Constants.KEY_STOP_CHARGING, 100); - if (stopLevel <= startLevel) { - stopLevel = startLevel + 1; - sharedPrefs.edit().putInt(Constants.KEY_STOP_CHARGING, stopLevel).apply(); - FileUtils.writeValue(Constants.NODE_STOP_CHARGING, String.valueOf(stopLevel)); - mStopChargingPreference.refresh(stopLevel); - Toast.makeText(getContext(), R.string.start_above_stop_error, Toast.LENGTH_SHORT).show(); - } - sharedPrefs.edit().putInt(Constants.KEY_START_CHARGING, value).apply(); - FileUtils.writeValue(Constants.NODE_START_CHARGING, String.valueOf(value)); - return true; - } - - return false; - } - - // Stop preference - public static void restoreStopChargingSetting(Context context) { - SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context); - boolean chargeControlEnabled = sharedPrefs.getBoolean(Constants.KEY_CHARGE_CONTROL, true); - - if (chargeControlEnabled && FileUtils.isFileWritable(Constants.NODE_STOP_CHARGING)) { - int value = sharedPrefs.getInt(Constants.KEY_STOP_CHARGING, - Integer.parseInt(FileUtils.getFileValue(Constants.NODE_STOP_CHARGING, Constants.DEFAULT_STOP_CHARGING))); - FileUtils.writeValue(Constants.NODE_STOP_CHARGING, String.valueOf(value)); - } - } - - // Start preference - public static void restoreStartChargingSetting(Context context) { - SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context); - boolean chargeControlEnabled = sharedPrefs.getBoolean(Constants.KEY_CHARGE_CONTROL, true); - - if (chargeControlEnabled && FileUtils.isFileWritable(Constants.NODE_START_CHARGING)) { - int value = sharedPrefs.getInt(Constants.KEY_START_CHARGING, - Integer.parseInt(FileUtils.getFileValue(Constants.NODE_START_CHARGING, Constants.DEFAULT_START_CHARGING))); - FileUtils.writeValue(Constants.NODE_START_CHARGING, String.valueOf(value)); - } - } -}