forked from JoeSchubert/kernel_adiutor
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
5 changed files
with
109 additions
and
1 deletion.
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
84 changes: 84 additions & 0 deletions
84
app/src/main/java/com/kerneladiutormod/reborn/services/SELinuxQSTileService.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,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); | ||
} | ||
|
||
} |
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,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> |
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