Add fix permissions button
This commit is contained in:
parent
295cd7458d
commit
076ec14d2b
59
app/src/main/java/com/psmreborn/nopsmdrm/FixPermissions.java
Normal file
59
app/src/main/java/com/psmreborn/nopsmdrm/FixPermissions.java
Normal file
|
@ -0,0 +1,59 @@
|
|||
package com.psmreborn.nopsmdrm;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.net.Uri;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.Environment;
|
||||
import android.os.Handler;
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import eu.chainfire.libsuperuser.Shell;
|
||||
|
||||
public class FixPermissions {
|
||||
public static void changePermissionsToPsm(Activity ctx) {
|
||||
ProgressDialog dialog = new ProgressDialog(ctx);
|
||||
dialog.setTitle("Fixing permissions ...");
|
||||
dialog.setMessage("Please Wait ...");
|
||||
dialog.setIndeterminate(true);
|
||||
dialog.setCancelable(false);
|
||||
dialog.show();
|
||||
|
||||
new Thread(() -> {
|
||||
Handler handler = new Handler(ctx.getMainLooper());
|
||||
|
||||
String androidDataFolder = new File(new File(Environment.getExternalStorageDirectory(), "Android"), "data").getAbsolutePath();
|
||||
try {
|
||||
String groupId = Root.getFileGroup(androidDataFolder);
|
||||
String userId = String.valueOf(Helper.getPsmAppInfo().uid);
|
||||
Root.chownRoot(new File(new File(new File(androidDataFolder, "com.playstation.psstore"), "files"), "psm").getAbsolutePath(), userId, groupId);
|
||||
|
||||
handler.post(() -> {
|
||||
dialog.dismiss();
|
||||
new AlertDialog.Builder((Activity)ctx)
|
||||
.setTitle("Success!")
|
||||
.setMessage("Successfully updated file permissions")
|
||||
.setCancelable(false)
|
||||
.setPositiveButton("Ok", null).show();
|
||||
});
|
||||
} catch (Exception e) {
|
||||
handler.post(() -> {
|
||||
dialog.dismiss();
|
||||
new AlertDialog.Builder((Activity)ctx)
|
||||
.setTitle("Failed.")
|
||||
.setMessage(e.toString())
|
||||
.setCancelable(false)
|
||||
.setPositiveButton("Ok", null).show();
|
||||
});
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
}
|
|
@ -13,6 +13,9 @@ import com.psmreborn.nopsmdrm.pscertified.PlayStationCertified;
|
|||
import com.psmreborn.nopsmdrm.pscertified.PsCertificatesInstaller;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import eu.chainfire.libsuperuser.Shell;
|
||||
|
||||
|
||||
public class MainActivity extends Activity {
|
||||
|
@ -36,9 +39,12 @@ public class MainActivity extends Activity {
|
|||
public static void setPsmInstalled(Activity activity){
|
||||
Button installButton = (Button) activity.findViewById(R.id.installPsm);
|
||||
Button backupGamesButton = (Button) activity.findViewById(R.id.dumpGames);
|
||||
Button takeOwnershipButton = (Button) activity.findViewById(R.id.takeOwnership);
|
||||
|
||||
|
||||
installButton.setText("Update NoPsmDrm");
|
||||
backupGamesButton.setEnabled(true);
|
||||
takeOwnershipButton .setEnabled(true);
|
||||
|
||||
}
|
||||
private void psCertifiedAlert(){
|
||||
|
@ -64,6 +70,19 @@ public class MainActivity extends Activity {
|
|||
}
|
||||
}
|
||||
|
||||
public void givePsmOwnership(View view){
|
||||
new AlertDialog.Builder((Activity)this)
|
||||
.setTitle("Fix permissions")
|
||||
.setMessage("On android 10+, games wont always show up in PSM when placed in \"com.playstation.psstore\" folder due to file permissions.\nWould you like to fix all the file permissions for PSM Games? (can take awhile)")
|
||||
.setCancelable(false)
|
||||
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
FixPermissions.changePermissionsToPsm(MainActivity.this);
|
||||
}
|
||||
})
|
||||
.setNegativeButton("No", null).show();
|
||||
}
|
||||
public void dumpAllRifs(View view){
|
||||
String rifOutput = new File(Environment.getExternalStorageDirectory(), "psm").getAbsolutePath();
|
||||
new AlertDialog.Builder((Activity)this)
|
||||
|
|
|
@ -41,6 +41,23 @@ public class Root {
|
|||
return new String[]{};
|
||||
}
|
||||
|
||||
public static void chownRoot(String filePath, String owner, String group) throws Shell.ShellDiedException, IOException {
|
||||
Log.i("ROOT", "ChownRoot: " + filePath);
|
||||
int res = Shell.Pool.SU.run(new String[] { busyboxBinary + " chown "+owner+":"+group+" -R '" + filePath +"'" });
|
||||
if(res != 0){
|
||||
Log.e("ROOT", "error (" + String.valueOf(res) +")");
|
||||
throw new IOException("Failed to chown: "+filePath + " ("+String.valueOf(res)+")");
|
||||
}
|
||||
}
|
||||
public static String getFileGroup(String filePath) throws Shell.ShellDiedException, IOException {
|
||||
ArrayList<String> results = new ArrayList<String>();
|
||||
int res = Shell.Pool.SU.run(new String[] { busyboxBinary + " stat '" + filePath + "' -c %g" }, results, null, true);
|
||||
if(res == 0) {
|
||||
return results.get(0);
|
||||
}
|
||||
Log.e("ROOT", "error (" + String.valueOf(res) +")");
|
||||
throw new IOException("failed to get group: "+filePath);
|
||||
}
|
||||
public static String getFileOwner(String filePath) throws Shell.ShellDiedException, IOException {
|
||||
ArrayList<String> results = new ArrayList<String>();
|
||||
int res = Shell.Pool.SU.run(new String[] { busyboxBinary + " stat '" + filePath + "' -c %u" }, results, null, true);
|
||||
|
|
|
@ -28,7 +28,16 @@
|
|||
android:enabled="false"
|
||||
android:layout_below="@+id/errorMsg"
|
||||
android:text="Install NoPsmDrm"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/takeOwnership"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="@color/black"
|
||||
android:onClick="givePsmOwnership"
|
||||
android:textSize="30sp"
|
||||
android:enabled="false"
|
||||
android:layout_below="@+id/installPsm"
|
||||
android:text="Fix permissions"/>
|
||||
<Button
|
||||
android:id="@+id/dumpGames"
|
||||
android:layout_width="match_parent"
|
||||
|
@ -37,7 +46,7 @@
|
|||
android:onClick="dumpAllRifs"
|
||||
android:textSize="30sp"
|
||||
android:enabled="false"
|
||||
android:layout_below="@+id/installPsm"
|
||||
android:layout_below="@+id/takeOwnership"
|
||||
android:text="Backup all licenses"/>
|
||||
|
||||
</RelativeLayout>
|
Loading…
Reference in New Issue
Block a user