Skip to content

Commit

Permalink
1.1 RELEASE : Add Android 11 Support
Browse files Browse the repository at this point in the history
* Also clean up the code

Signed-off-by: IacobIonut01 <[email protected]>
  • Loading branch information
IacobIonut01 committed Jan 24, 2021
1 parent b7f3766 commit 6dfc888
Show file tree
Hide file tree
Showing 12 changed files with 117 additions and 124 deletions.
Binary file added app/release/DeviceIDChanger-1.1.apk
Binary file not shown.
2 changes: 2 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.iacob.idchanger">

<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
Expand Down
9 changes: 6 additions & 3 deletions app/src/main/java/com/iacob/idchanger/ItemRecyclerSpacer.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
import androidx.recyclerview.widget.RecyclerView;

public class ItemRecyclerSpacer extends RecyclerView.ItemDecoration {
private int left, right, top, bottom;
private int position;
private final int left;
private final int right;
private final int top;
private final int bottom;
private final int position;

public ItemRecyclerSpacer(int left, int right, int top, int bottom, int position) {
this.left = left;
Expand All @@ -21,7 +24,7 @@ public ItemRecyclerSpacer(int left, int right, int top, int bottom, int position
@Override
public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) {
int position = parent.getChildAdapterPosition(view);
if(position == this.position){
if (position == this.position) {
if (left != 0)
outRect.left = left;
if (right != 0)
Expand Down
92 changes: 43 additions & 49 deletions app/src/main/java/com/iacob/idchanger/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
package com.iacob.idchanger;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.snackbar.Snackbar;
import com.iacob.idchanger.app_parser.ApplicationAdapter;
import com.iacob.idchanger.app_parser.ApplicationModel;
import com.iacob.idchanger.id_parser.rootCheck;
Expand All @@ -28,29 +23,18 @@
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;

import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringReader;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
import java.util.function.Predicate;
import java.util.function.UnaryOperator;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import static android.content.pm.PackageManager.GET_META_DATA;

Expand All @@ -61,11 +45,30 @@ public class MainActivity extends AppCompatActivity {
static RecyclerView recyclerView;
static ApplicationAdapter adapter;
static ExtendedFloatingActionButton fab;
View.OnClickListener no_listener;
static View.OnClickListener listener;
static View.OnClickListener listenerReboot;
View.OnClickListener no_listener;
AppPreferences preferences;

public static void updateApp(ApplicationModel model) {
for (int i = 0; i < apps.size(); i++) {
ApplicationModel app = apps.get(i);
if (app.package_name.equals(model.package_name)) {
apps.set(i, model);
Toast.makeText(context, String.format("%s's ID has been changed", model.app_name), Toast.LENGTH_SHORT).show();
recyclerView.setLayoutManager(new LinearLayoutManager(context, RecyclerView.VERTICAL, false));
recyclerView.setAdapter(adapter);
fab.setOnClickListener(listener);
}
}
fab.setIconResource(R.drawable.ic_done);
fab.setText("Apply Changes");
}

private static String getValue(String tag, Node element) {
return element.getAttributes().getNamedItem(tag).getTextContent();
}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -78,7 +81,6 @@ protected void onCreate(Bundle savedInstanceState) {
recyclerView.addItemDecoration(new ItemRecyclerSpacer(0, 0, 0, 256, apps.size() - 1));
recyclerView.setLayoutManager(new LinearLayoutManager(this, RecyclerView.VERTICAL, false));
recyclerView.setAdapter(adapter);
//Snackbar.make(findViewById(R.id.action_fab), checkForRoot() ? "Root Access Granted" : "Root Access denied", Snackbar.LENGTH_SHORT).show();
fab = findViewById(R.id.action_fab);
fab.addTextChangedListener(new TextWatcher() {
@Override
Expand Down Expand Up @@ -113,49 +115,41 @@ public void run() {
fab.setText(checkForRoot() ? "Root Access Granted" : "Root Access denied");
findViewById(R.id.noRootContainer).setVisibility(checkForRoot() ? View.GONE : View.VISIBLE);
fab.setIconResource(R.drawable.ic_rootguard);
no_listener = view -> {};
listener = view -> {
fab.setIconResource(R.drawable.ic_randomize);
fab.setText("Reboot");
fab.setOnClickListener(listenerReboot);
IDManager.writeXMLToSystem(apps);
rootCheck.execute(IDManager.writeXMLToSystem(apps));
};
listenerReboot = view -> {
rootCheck.execute("reboot");
};
fab.setOnClickListener(no_listener);
}

public static void updateApp(ApplicationModel model) {
for (int i = 0; i < apps.size(); i++) {
ApplicationModel app = apps.get(i);
if (app.package_name.equals(model.package_name)) {
apps.set(i, model);
Toast.makeText(context, String.format("%s's ID has been changed", model.app_name), Toast.LENGTH_SHORT).show();
recyclerView.setLayoutManager(new LinearLayoutManager(context, RecyclerView.VERTICAL, false));
recyclerView.setAdapter(adapter);
fab.setOnClickListener(listener);
}
}
fab.setIconResource(R.drawable.ic_done);
fab.setText("Apply Changes");
fab.setOnClickListener(null);
}

public boolean checkForRoot() {
return rootCheck.IAmRoot();
}

private static String getValue(String tag, Node element) {
return element.getAttributes().getNamedItem(tag).getTextContent();
}

private ArrayList<ApplicationModel> getInstalledApps() {
ArrayList<ApplicationModel> res = new ArrayList<>();
try {
InputStream is = new ByteArrayInputStream(rootCheck.read("cat /data/system/users/0/settings_ssaid.xml").getBytes());
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(is);
BufferedReader r = new BufferedReader(new InputStreamReader(is));
Document doc;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
StringBuilder total = new StringBuilder();
for (String line; (line = r.readLine()) != null; ) {
total.append(line).append('\n');
}
String isStripped = total.toString().replace("<namespaceHashes />", "");
InputStream stream = new ByteArrayInputStream(isStripped.getBytes(StandardCharsets.UTF_8));
doc = dBuilder.parse(stream);
} else {
doc = dBuilder.parse(is);
}
Element element = doc.getDocumentElement();
element.normalize();
NodeList nList = doc.getElementsByTagName("setting");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.iacob.idchanger.app_parser;

import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand All @@ -21,7 +20,7 @@
public class ApplicationAdapter extends RecyclerView.Adapter<ApplicationAdapter.ViewHolder> {

public ArrayList<ApplicationModel> applicationModels;
private FragmentManager fm;
private final FragmentManager fm;

public ApplicationAdapter(ArrayList<ApplicationModel> applicationModels, FragmentManager fm) {
this.applicationModels = applicationModels;
Expand All @@ -42,7 +41,7 @@ public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
holder.appImage.setImageDrawable(app.getIcon());
holder.appID.setText(app.getID());
AppPreferences prefs = new AppPreferences(holder.itemView.getContext());
if (prefs.getModifiedIDs()!= null)
if (prefs.getModifiedIDs() != null)
holder.appModified.setText(prefs.getModifiedIDs().contains("packagename: " + app.getPackage_name()) ? "Modified ID" : "Original ID");
else
holder.appModified.setText("Original ID");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,28 +42,28 @@ public boolean isModified() {
return modified;
}

public void setModified(boolean modified) {
this.modified = modified;
}

public Drawable getIcon() {
return icon;
}

public String getApp_name() {
return app_name;
public void setIcon(Drawable icon) {
this.icon = icon;
}

public String getPackage_name() {
return package_name;
public String getApp_name() {
return app_name;
}

public void setApp_name(String app_name) {
this.app_name = app_name;
}

public void setIcon(Drawable icon) {
this.icon = icon;
}

public void setModified(boolean modified) {
this.modified = modified;
public String getPackage_name() {
return package_name;
}

public void setPackage_name(String package_name) {
Expand Down Expand Up @@ -93,14 +93,14 @@ public String getDefaultSysSet() {
return defaultSysSet;
}

public String getId() {
return id;
}

public void setDefaultSysSet(String defaultSysSet) {
this.defaultSysSet = defaultSysSet;
}

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.iacob.idchanger.fragments;

import android.content.pm.ApplicationInfo;
import android.os.Bundle;
import android.text.InputFilter;
import android.view.LayoutInflater;
Expand All @@ -21,13 +20,11 @@
import com.iacob.idchanger.utils.IDInputFilter;
import com.iacob.idchanger.utils.IDManager;

import java.util.Objects;

import studio.carbonylgroup.textfieldboxes.ExtendedEditText;

public class EditFragment extends RoundedSheetFragment {

private ApplicationModel applicationInfo;
private final ApplicationModel applicationInfo;

public EditFragment(ApplicationModel applicationInfo) {
this.applicationInfo = applicationInfo;
Expand Down Expand Up @@ -69,7 +66,7 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
applicationInfo.setID(currID.getText().toString());
applicationInfo.setDefID(defID.getText().toString());
prefs.addModifiedID(applicationInfo.package_name);
applicationInfo.modified=true;
applicationInfo.modified = true;
MainActivity.updateApp(applicationInfo);
dismiss();
});
Expand Down
56 changes: 28 additions & 28 deletions app/src/main/java/com/iacob/idchanger/id_parser/rootCheck.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,34 +53,6 @@ public static boolean IAmRoot() {
return retval;
}

public final boolean execute() {
boolean retval = false;
try {
ArrayList<String> commands = getCommandsToExecute();
if (null != commands && commands.size() > 0) {
Process suProcess = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(suProcess.getOutputStream());
for (String currCommand : commands) {
os.writeBytes(currCommand + "\n");
os.flush();
}
os.writeBytes("exit\n");
os.flush();
try {
int suProcessRetval = suProcess.waitFor();
retval = 255 != suProcessRetval;
} catch (Exception ex) {
Log.e("ROOT", "Error executing root action", ex);
}
}
} catch (IOException | SecurityException ex) {
Log.w("ROOT", "Can't get root access", ex);
} catch (Exception ex) {
Log.w("ROOT", "Error executing internal operation", ex);
}
return retval;
}

public static boolean execute(String command) {
boolean retval = false;
try {
Expand Down Expand Up @@ -128,5 +100,33 @@ public static String read(String paramString) {
return "";
}

public final boolean execute() {
boolean retval = false;
try {
ArrayList<String> commands = getCommandsToExecute();
if (null != commands && commands.size() > 0) {
Process suProcess = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(suProcess.getOutputStream());
for (String currCommand : commands) {
os.writeBytes(currCommand + "\n");
os.flush();
}
os.writeBytes("exit\n");
os.flush();
try {
int suProcessRetval = suProcess.waitFor();
retval = 255 != suProcessRetval;
} catch (Exception ex) {
Log.e("ROOT", "Error executing root action", ex);
}
}
} catch (IOException | SecurityException ex) {
Log.w("ROOT", "Can't get root access", ex);
} catch (Exception ex) {
Log.w("ROOT", "Error executing internal operation", ex);
}
return retval;
}

protected abstract ArrayList<String> getCommandsToExecute();
}
Loading

0 comments on commit 6dfc888

Please sign in to comment.