Skip to content

Commit

Permalink
SELinux QSTile
Browse files Browse the repository at this point in the history
WIP

Added Tile in AndroidManifest.xml
Added string in strings.xml
Added Vector Image
Added SELinuxQSTileService.java
  • Loading branch information
millo1978 committed Apr 30, 2018
1 parent 8516f76 commit 731f55a
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 1 deletion.
15 changes: 14 additions & 1 deletion app/src/main/AndroidManifest.xml
Expand Up @@ -112,6 +112,19 @@
android:value="true" />
</service>

<!-- SELinux Tile -->
<service
android:name="com.kerneladiutormod.reborn.services.SELinuxQSTileService"
android:icon="@drawable/ic_selinux"
android:label="@string/selinux_tile"
android:permission="android.permission.BIND_QUICK_SETTINGS_TILE">
<intent-filter>
<action android:name="android.service.quicksettings.action.QS_TILE" />
</intent-filter>
<meta-data android:name="android.service.quicksettings.ACTIVE_TILE"
android:value="true" />
</service>

<!-- DashClock -->
<service
android:name="com.kerneladiutormod.reborn.services.DashClockService"
Expand Down Expand Up @@ -154,7 +167,7 @@
<receiver android:name="com.kerneladiutormod.reborn.services.HighBrightnessModeReceiver">
<intent-filter>
<action android:name="com.kerneladiutor.mod.action.HBM_ON" />
<action android:name="com.kerneladiutor.mod.action.HBM_OFF" />
<action android:name="com.kerneladiutor.mod.reborn.action.HBM_OFF" />
</intent-filter>
</receiver>

Expand Down
@@ -0,0 +1,84 @@
package com.kerneladiutormod.reborn.services;

import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.drawable.Icon;
import android.os.Build;
import android.service.quicksettings.Tile;
import android.service.quicksettings.TileService;
import android.support.annotation.RequiresApi;

import com.kerneladiutormod.reborn.R;
import com.kerneladiutormod.reborn.utils.root.Control;

import static com.kerneladiutormod.reborn.utils.Constants.SETENFORCE;
import static com.kerneladiutormod.reborn.utils.kernel.Misc.isSELinuxActive;

@RequiresApi(api = Build.VERSION_CODES.N)
public class SELinuxQSTileService extends TileService {

private Context context;

@RequiresApi(api = Build.VERSION_CODES.N)
@Override
public void onTileAdded() {
tileSELinuxUpdate(getQsTile());
}

@Override
public void onTileRemoved() {
}

@RequiresApi(api = Build.VERSION_CODES.N)
@Override
public void onClick() {
tileSELinuxToggle(getQsTile());
}

@RequiresApi(api = Build.VERSION_CODES.N)
@Override
public void onStartListening () {
tileSELinuxUpdate(getQsTile());
}

@Override
public void onStopListening () {

}
@TargetApi(Build.VERSION_CODES.N)
private void tileSELinuxUpdate (Tile qsTile) {
Icon icon = Icon.createWithResource(getApplicationContext(), R.drawable.ic_selinux);
if (isSELinuxActive()) {
if (qsTile.getState() == Tile.STATE_INACTIVE) {
qsTile.setState(Tile.STATE_ACTIVE);
}
}
if (!isSELinuxActive()) {
if (qsTile.getState() == Tile.STATE_ACTIVE) {
qsTile.setState(Tile.STATE_INACTIVE);
}
}
getQsTile().setIcon(icon);
getQsTile().updateTile();
}

@RequiresApi(api = Build.VERSION_CODES.N)
private void tileSELinuxToggle (Tile qsTile) {
if (isSELinuxActive() && qsTile.getState() == Tile.STATE_ACTIVE) {
Control.runCommand("0", SETENFORCE, Control.CommandType.SHELL, context);
}
else if (!isSELinuxActive() && qsTile.getState() == Tile.STATE_INACTIVE) {
Control.runCommand("1", SETENFORCE, Control.CommandType.SHELL, context);
}
try{
// Pause momentarily for sysfs changes
// This should be done differently, but this will work for now.
Thread.sleep(100);
}
catch(InterruptedException e){

}
tileSELinuxUpdate(qsTile);
}

}
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/ic_selinux.xml
@@ -0,0 +1,9 @@
<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="M12,1L3,5v6c0,5.55 3.84,10.74 9,12 5.16,-1.26 9,-6.45 9,-12L21,5l-9,-4zM12,11.99h7c-0.53,4.12 -3.28,7.79 -7,8.94L12,12L5,12L5,6.3l7,-3.11v8.8z"/>
</vector>
1 change: 1 addition & 0 deletions app/src/main/res/values-it/strings.xml
Expand Up @@ -999,5 +999,6 @@
<string name="modification_version_number">Versione %d</string>
<string name="accessibility_service_label">KA Per App Monitor</string>
<string name="accessibility_service_desc">Service to monitor when foreground app changes for per-app profile loading</string>
<string name="selinux_tile">SELinux</string>

</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Expand Up @@ -1005,5 +1005,6 @@

<string name="accessibility_service_label">KA Per App Monitor</string>
<string name="accessibility_service_desc">Service to monitor when foreground app changes for per-app profile loading</string>
<string name="selinux_tile">SELinux</string>

</resources>

0 comments on commit 731f55a

Please sign in to comment.