Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
base: Implement Lineage health service
Change-Id: I772ccf6d323c24d681aa8468bf4318c7b73bd3f5 Signed-off-by: Mohammad Hasan Keramat J <ikeramat@protonmail.com>
- Loading branch information
1 parent
fd66587
commit d0bf39e
Showing
13 changed files
with
1,481 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
269 changes: 269 additions & 0 deletions
269
core/java/com/android/internal/lineage/health/HealthInterface.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,269 @@ | ||
/* | ||
* Copyright (C) 2023 The LineageOS Project | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.android.internal.lineage.health; | ||
|
||
import android.content.Context; | ||
import android.os.IBinder; | ||
import android.os.RemoteException; | ||
import android.os.ServiceManager; | ||
import android.util.Log; | ||
|
||
import com.android.internal.lineage.app.LineageContextConstants; | ||
|
||
public class HealthInterface { | ||
/** | ||
* No config set. This value is invalid and does not have any effects | ||
*/ | ||
public static final int MODE_NONE = 0; | ||
|
||
/** | ||
* Automatic config | ||
*/ | ||
public static final int MODE_AUTO = 1; | ||
|
||
/** | ||
* Manual config mode | ||
*/ | ||
public static final int MODE_MANUAL = 2; | ||
|
||
/** | ||
* Limit config mode | ||
*/ | ||
public static final int MODE_LIMIT = 3; | ||
|
||
private static final String TAG = "HealthInterface"; | ||
private static IHealthInterface sService; | ||
private static HealthInterface sInstance; | ||
private Context mContext; | ||
private HealthInterface(Context context) { | ||
Context appContext = context.getApplicationContext(); | ||
mContext = appContext == null ? context : appContext; | ||
sService = getService(); | ||
} | ||
/** | ||
* Get or create an instance of the {@link lineageos.health.HealthInterface} | ||
* | ||
* @param context Used to get the service | ||
* @return {@link HealthInterface} | ||
*/ | ||
public static synchronized HealthInterface getInstance(Context context) { | ||
if (sInstance == null) { | ||
sInstance = new HealthInterface(context); | ||
} | ||
return sInstance; | ||
} | ||
/** @hide **/ | ||
public static IHealthInterface getService() { | ||
if (sService != null) { | ||
return sService; | ||
} | ||
IBinder b = ServiceManager.getService(LineageContextConstants.LINEAGE_HEALTH_INTERFACE); | ||
sService = IHealthInterface.Stub.asInterface(b); | ||
if (sService == null) { | ||
Log.e(TAG, "null health service, SAD!"); | ||
return null; | ||
} | ||
return sService; | ||
} | ||
|
||
/** | ||
* @return true if service is valid | ||
*/ | ||
private boolean checkService() { | ||
if (sService == null) { | ||
Log.w(TAG, "not connected to LineageHardwareManagerService"); | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
/** | ||
* Returns whether charging control is supported | ||
* | ||
* @return true if charging control is supported | ||
*/ | ||
public boolean isChargingControlSupported() { | ||
try { | ||
return checkService() && sService.isChargingControlSupported(); | ||
} catch (RemoteException e) { | ||
Log.e(TAG, e.getLocalizedMessage(), e); | ||
} | ||
|
||
return false; | ||
} | ||
|
||
/** | ||
* Returns the charging control enabled status | ||
* | ||
* @return whether charging control has been enabled | ||
*/ | ||
public boolean getEnabled() { | ||
try { | ||
return checkService() && sService.getChargingControlEnabled(); | ||
} catch (RemoteException e) { | ||
return false; | ||
} | ||
} | ||
|
||
/** | ||
* Set charging control enable status | ||
* | ||
* @param enabled whether charging control should be enabled | ||
* @return true if the enabled status was successfully set | ||
*/ | ||
public boolean setEnabled(boolean enabled) { | ||
try { | ||
return checkService() && sService.setChargingControlEnabled(enabled); | ||
} catch (RemoteException e) { | ||
return false; | ||
} | ||
} | ||
|
||
/** | ||
* Returns the current charging control mode | ||
* | ||
* @return id of the charging control mode | ||
*/ | ||
public int getMode() { | ||
try { | ||
return checkService() ? sService.getChargingControlMode() : MODE_NONE; | ||
} catch (RemoteException e) { | ||
return MODE_NONE; | ||
} | ||
} | ||
|
||
/** | ||
* Selects the new charging control mode | ||
* | ||
* @param mode the new charging control mode | ||
* @return true if the mode was successfully set | ||
*/ | ||
public boolean setMode(int mode) { | ||
try { | ||
return checkService() && sService.setChargingControlMode(mode); | ||
} catch (RemoteException e) { | ||
return false; | ||
} | ||
} | ||
|
||
/** | ||
* Gets the charging control start time | ||
* | ||
* @return the seconds of the day of the start time | ||
*/ | ||
public int getStartTime() { | ||
try { | ||
return checkService() ? sService.getChargingControlStartTime() : 0; | ||
} catch (RemoteException e) { | ||
return 0; | ||
} | ||
} | ||
|
||
/** | ||
* Sets the charging control start time | ||
* | ||
* @param time the seconds of the day of the start time | ||
* @return true if the start time was successfully set | ||
*/ | ||
public boolean setStartTime(int time) { | ||
try { | ||
return checkService() && sService.setChargingControlStartTime(time); | ||
} catch (RemoteException e) { | ||
return false; | ||
} | ||
} | ||
|
||
/** | ||
* Gets the charging control target time | ||
* | ||
* @return the seconds of the day of the target time | ||
*/ | ||
public int getTargetTime() { | ||
try { | ||
return checkService() ? sService.getChargingControlTargetTime() : 0; | ||
} catch (RemoteException e) { | ||
return 0; | ||
} | ||
} | ||
|
||
/** | ||
* Sets the charging control target time | ||
* | ||
* @param time the seconds of the day of the target time | ||
* @return true if the target time was successfully set | ||
*/ | ||
public boolean setTargetTime(int time) { | ||
try { | ||
return checkService() && sService.setChargingControlTargetTime(time); | ||
} catch (RemoteException e) { | ||
return false; | ||
} | ||
} | ||
|
||
/** | ||
* Gets the charging control limit | ||
* | ||
* @return the charging control limit | ||
*/ | ||
public int getLimit() { | ||
try { | ||
return checkService() ? sService.getChargingControlLimit() : 100; | ||
} catch (RemoteException e) { | ||
return 0; | ||
} | ||
} | ||
|
||
/** | ||
* Sets the charging control limit | ||
* | ||
* @param limit the charging control limit | ||
* @return true if the limit was successfully set | ||
*/ | ||
public boolean setLimit(int limit) { | ||
try { | ||
return checkService() && sService.setChargingControlLimit(limit); | ||
} catch (RemoteException e) { | ||
return false; | ||
} | ||
} | ||
|
||
/** | ||
* Resets the charging control setting to default | ||
* | ||
* @return true if the setting was successfully reset | ||
*/ | ||
public boolean reset() { | ||
try { | ||
return checkService() && sService.resetChargingControl(); | ||
} catch (RemoteException e) { | ||
return false; | ||
} | ||
} | ||
|
||
/** | ||
* Returns whether the device's battery control bypasses battery | ||
* | ||
* @return true if the charging control bypasses battery | ||
*/ | ||
public boolean allowFineGrainedSettings() { | ||
try { | ||
return checkService() && sService.allowFineGrainedSettings(); | ||
} catch (RemoteException e) { | ||
return false; | ||
} | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
core/java/com/android/internal/lineage/health/IHealthInterface.aidl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/** | ||
* Copyright (c) 2023 The LineageOS Project | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.android.internal.lineage.health; | ||
|
||
/** @hide */ | ||
interface IHealthInterface { | ||
boolean isChargingControlSupported(); | ||
|
||
boolean getChargingControlEnabled(); | ||
boolean setChargingControlEnabled(boolean enabled); | ||
|
||
int getChargingControlMode(); | ||
boolean setChargingControlMode(int mode); | ||
|
||
int getChargingControlStartTime(); | ||
boolean setChargingControlStartTime(int time); | ||
|
||
int getChargingControlTargetTime(); | ||
boolean setChargingControlTargetTime(int time); | ||
|
||
int getChargingControlLimit(); | ||
boolean setChargingControlLimit(int limit); | ||
|
||
boolean resetChargingControl(); | ||
boolean allowFineGrainedSettings(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<!-- | ||
Copyright (C) 2018 The Android Open Source Project | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
--> | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="24dp" | ||
android:height="24dp" | ||
android:viewportWidth="24.0" | ||
android:viewportHeight="24.0"> | ||
<path | ||
android:fillColor="#FF000000" | ||
android:pathData="M16.2,22.5H7.8c-1.3,0 -2.3,-1 -2.3,-2.3V5.8c0,-1.3 1,-2.3 2.3,-2.3h0.7v-2h7v2h0.7c1.3,0 2.3,1.1 2.3,2.3v14.3C18.5,21.5 17.5,22.5 16.2,22.5zM7.8,5.5c-0.2,0 -0.3,0.2 -0.3,0.3v14.3c0,0.2 0.2,0.3 0.3,0.3h8.3c0.2,0 0.3,-0.1 0.3,-0.3V5.8c0,-0.2 -0.1,-0.3 -0.3,-0.3h-2.7v-2h-3v2H7.8z"/> | ||
<path | ||
android:fillColor="#FF000000" | ||
android:pathData="M11.17,18.42v-4.58H9.5l3.33,-6.25v4.58h1.67L11.17,18.42z"/> | ||
</vector> |
Oops, something went wrong.