NoPssDrm/app/src/main/java/com/psmreborn/nopsmdrm/Startup.java

105 lines
3.3 KiB
Java

package com.psmreborn.nopsmdrm;
import android.app.Activity;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Environment;
import android.os.Handler;
import android.widget.Button;
import android.widget.TextView;
import com.psmreborn.pscertified.PlayStationCertified;
import com.psmreborn.shared.Helper;
import com.psmreborn.shared.Root;
public class Startup extends AsyncTask<Void, Void, Void> {
private Activity ctx = null;
private Handler handler = null;
private boolean wasError = false;
private String errorMsg = "";
public static void updateNames(Activity activity) {
Button installButton = (Button) activity.findViewById(R.id.installPsm);
if(!PlayStationCertified.isPlaystationCertified(activity.getApplicationContext()))
installButton.setText("Install PS Certify");
else if(!Helper.isPsmInstalled(activity))
installButton.setText("Install PSM");
else if(Helper.isNoPsmDrmInstalled(activity))
installButton.setText("Update NoPsmDrm");
else
installButton.setText("Install NoPsmDrm");
}
public static void setPsmInstalled(Activity activity){
Button backupGamesButton = (Button) activity.findViewById(R.id.dumpGames);
Button takeOwnershipButton = (Button) activity.findViewById(R.id.takeOwnership);
backupGamesButton.setEnabled(true);
if(Build.VERSION.SDK_INT >= 30)
takeOwnershipButton.setEnabled(true);
updateNames(activity);
}
public Startup(Activity context) {
this.handler = new Handler(context.getMainLooper());
this.ctx = context;
}
@Override
protected Void doInBackground(Void... params) {
try {
if(!Root.init(ctx)){
wasError = true;
errorMsg = "Unable to get root permission.";
return null;
}
if(Helper.isPsmInstalled(ctx) && Helper.getPsmAppPkg(ctx).versionCode != 1170) {
wasError = true;
errorMsg = "PSM Application is installed, but an older version, please update to 1.7.0 (have: "+String.valueOf(Helper.getPsmAppPkg(ctx).versionCode)+")";
return null;
}
if(!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)){
wasError = true;
errorMsg = "No SD Card inserted.";
return null;
}
Permissions.requestPermissions(this.ctx);
Helper.killPsm(ctx);
} catch (Exception e) {
wasError = true;
errorMsg = e.getMessage();
}
return null;
}
@Override
protected void onPostExecute(Void result) {
TextView statusTV = (TextView) ((Activity)ctx).findViewById(R.id.errorMsg);
Button installButton = (Button) ((Activity)ctx).findViewById(R.id.installPsm);
if(!wasError) {
handler.post(() -> {
statusTV.setText("");
if(Helper.isNoPsmDrmInstalled(ctx)){
setPsmInstalled(ctx);
};
updateNames(ctx);
installButton.setEnabled(true);
});
}
else{
handler.post(() -> {
statusTV.setText("Error: " + errorMsg);
});
}
}
}