Skip to content

Commit

Permalink
优化了配置存储
Browse files Browse the repository at this point in the history
  • Loading branch information
cokkeijigen committed Apr 28, 2022
1 parent 34e914a commit 5ffb937
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 87 deletions.
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<!-- <category android:name="android.intent.category.LAUNCHER"/>-->
<category android:name="android.intent.category.LAUNCHER"/>
<category android:name="de.robv.android.xposed.category.MODULE_SETTINGS"/>
</intent-filter>
</activity>
Expand Down
2 changes: 0 additions & 2 deletions app/src/main/java/ss/colytitse/setappfull/AppInfoAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
Expand All @@ -12,7 +11,6 @@
import android.widget.ImageView;
import android.widget.Switch;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

Expand Down
19 changes: 10 additions & 9 deletions app/src/main/java/ss/colytitse/setappfull/AppSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public class AppSettings {
private static final String TAG = "test_";
private static final String config_name = "config";
private final SharedPreferences getPrefs;
public final static int SYSTEM_VIEW = 0;
public final static int USER_VIEW = 1;
private String content;

public AppSettings(Context context) {
Expand All @@ -39,26 +41,25 @@ public void savData(String pkgn){
StringBuilder data = new StringBuilder(content);
if(!content.contains("#" + pkgn + "#"))
data.append("#").append(pkgn).append("#");
getPrefs.edit().putString("content", data.toString()).commit();
SuperUser.copyConfigFile(false);
getPrefs.edit().putString("content", data.toString()).apply();
SuperUser.copyConfigFile(data.toString());
}

public void delData(String pkgn){
getPrefs.edit().putString("content", (this.content = content.replace("#" + pkgn + "#", ""))).commit();
SuperUser.copyConfigFile(false);
getPrefs.edit().putString("content", (this.content = content.replace("#" + pkgn + "#", ""))).apply();
SuperUser.copyConfigFile(content);
}

public boolean getData(String pkgn){
return content.contains("#" + pkgn + "#");
}

public boolean getOnSwitchListView() {
return getPrefs.getBoolean("onSwitchListView", true);
public static int getOnSwitchListView(Context context) {
return new AppSettings(context).getPrefs.getInt("onSwitchListView", USER_VIEW);
}

public void savonSwitch(boolean value) {
getPrefs.edit().putBoolean("onSwitchListView", value).commit();
SuperUser.copyConfigFile(false);
public void savonSwitch(int value) {
getPrefs.edit().putInt("onSwitchListView", value).apply();
}

public static void setStatusBarColor(Activity activity, int color){
Expand Down
72 changes: 40 additions & 32 deletions app/src/main/java/ss/colytitse/setappfull/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
Expand All @@ -18,22 +17,22 @@
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import java.util.ArrayList;
import java.util.List;

@SuppressLint({"UseSwitchCompatOrMaterialCode","UseCompatLoadingForDrawables","SetTextI18n"})
public class MainActivity extends Activity {

private static final String TAG = "test_";
public final Context mContext = this;
public List<PackageInfo> AllAppList;
List<PackageInfo> userAppList = new ArrayList<>();
List<PackageInfo> systemAppList = new ArrayList<>();
private List<PackageInfo> systemAppList;
private List<PackageInfo> userAppList;
private Context mContext;

private void initApplicationList() {
this.AllAppList = getPackageManager().getInstalledPackages(0);
for (PackageInfo app : AllAppList){
List<PackageInfo> allAppList = getPackageManager().getInstalledPackages(0);
systemAppList = new ArrayList<>();
userAppList = new ArrayList<>();
for (PackageInfo app : allAppList){
// 非系统应用
if ((app.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0)
userAppList.add(app);
Expand All @@ -45,15 +44,23 @@ private void initApplicationList() {
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try {
SuperUser.copyConfigFile(true);
Runtime.getRuntime().exec("su");
}catch (Throwable ignored){}
setContentView(R.layout.main_layout);
setActivityStatusBar(this);
setContentView(R.layout.main_layout);
mContext = getApplicationContext();
initApplicationList();
TextView setVersionName = findViewById(R.id.version_name);
setVersionName.setText("当前版本:" + getVersionName(mContext));
initMainActivityListView(new AppSettings(mContext).getOnSwitchListView() ? userAppList : systemAppList);
initMainActivity();
}

private void initMainActivity() {
int AppViewList = getOnSwitchListView(mContext);
TextView setVersionName = findViewById(R.id.version_name);
TextView appListName = findViewById(R.id.app_list_name);
setVersionName.setText(String.format("%s%s",
setVersionName.getText().toString().split("->")[0], getVersionName(mContext)));
appListName.setText(String.format("(%s)", AppViewList == USER_VIEW ? getResources().getString(R.string.list_user) : getResources().getString(R.string.list_system)));
initMainActivityListView(AppViewList == USER_VIEW ? userAppList : systemAppList);
}

public void initMainActivityListView(List<PackageInfo> appList){
Expand All @@ -70,20 +77,26 @@ public void initMainActivityListView(List<PackageInfo> appList){
onSwitch.setChecked(false);
new AppSettings(mContext).delData(text);
}
Toast.makeText(this,"保存成功,重启系统后生效!", Toast.LENGTH_SHORT).show();
// Log.d("test_", "已点击:" + text);
Toast.makeText(mContext,
getResources().getString(R.string.show_message),
Toast.LENGTH_SHORT
).show();
});
}

public void onSwitchListView(View view) {
if(new AppSettings(mContext).getOnSwitchListView()){
new AppSettings(mContext).savonSwitch(false);
initMainActivityListView(systemAppList);
Toast.makeText(this,"切换到系统应用", Toast.LENGTH_SHORT).show();
EditText edit_insearch = findViewById(R.id.edit_insearch);
String inText = edit_insearch.getText().toString();
boolean isSearchView = edit_insearch.getVisibility() == View.VISIBLE && inText.length() > 0;
TextView appListName = findViewById(R.id.app_list_name);
if(getOnSwitchListView(mContext) == USER_VIEW){
new AppSettings(mContext).savonSwitch(SYSTEM_VIEW);
initMainActivityListView(isSearchView ? searchAppView(inText) : systemAppList);
appListName.setText(String.format("(%s)", getResources().getString(R.string.list_system)));
}else {
new AppSettings(mContext).savonSwitch(true);
initMainActivityListView(userAppList);
Toast.makeText(this,"切换到用户应用", Toast.LENGTH_SHORT).show();
new AppSettings(mContext).savonSwitch(USER_VIEW);
initMainActivityListView(isSearchView ? searchAppView(inText) : userAppList);
appListName.setText(String.format("(%s)", getResources().getString(R.string.list_user)));
}
}

Expand All @@ -98,33 +111,28 @@ public void insearch(View view) {
((InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE))
.hideSoftInputFromWindow(view.getWindowToken(), 0);
String intext = textView.getText().toString();
if (intext.length() > 0)
initMainActivityListView(searchAppView(intext));
List<PackageInfo> result = searchAppView(intext);
if (result != null) initMainActivityListView(result);
return true;
}
return false;
});
return;
}
edit_insearch.setVisibility(View.GONE);
initMainActivityListView(new AppSettings(mContext).getOnSwitchListView() ? userAppList : systemAppList);
initMainActivityListView(getOnSwitchListView(mContext) == USER_VIEW ? userAppList : systemAppList);
edit_insearch.setText("");
((InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE))
.hideSoftInputFromWindow(view.getWindowToken(), 0);
btn_insearch.setImageDrawable(getResources().getDrawable(R.drawable.ic_baseline_search_24, getTheme()));
}

private List<PackageInfo> searchAppView(String intext) {
if (intext.length() < 1) return null;
List<PackageInfo> result = new ArrayList<>();
for (PackageInfo info : (new AppSettings(mContext).getOnSwitchListView() ? userAppList : systemAppList))
for (PackageInfo info : getOnSwitchListView(mContext) == USER_VIEW ? userAppList : systemAppList)
if (info.packageName.contains(intext) || getPackageManager().getApplicationLabel(info.applicationInfo).toString().contains(intext))
result.add(info);
return result;
}

@Override
protected void onDestroy() {
super.onDestroy();
SuperUser.delete();
}
}
4 changes: 1 addition & 3 deletions app/src/main/java/ss/colytitse/setappfull/MainHook.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@
import android.view.WindowManager;
import androidx.annotation.RequiresApi;
import java.io.File;
import java.io.FileNotFoundException;
import de.robv.android.xposed.IXposedHookLoadPackage;
import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XSharedPreferences;
import de.robv.android.xposed.XposedBridge;
import de.robv.android.xposed.callbacks.XC_LoadPackage;

public class MainHook implements IXposedHookLoadPackage {
Expand All @@ -30,7 +28,7 @@ public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam) {
if (!lpparam.packageName.equals(lpparam.processName) && !lpparam.packageName.equals("android"))
return;
Log.d(TAG, "SetAppFull: 运行成功!");

String configContent = loadConfig();
if (configContent.equals("")) return;

Expand Down
28 changes: 6 additions & 22 deletions app/src/main/java/ss/colytitse/setappfull/SuperUser.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package ss.colytitse.setappfull;

import android.os.Environment;
import android.util.Log;
import java.io.BufferedReader;
import java.io.IOException;
Expand All @@ -12,7 +11,7 @@ public class SuperUser {

public static String execShell(String cmd) {
StringBuilder result = new StringBuilder();
Process process = null;
Process process;
String line;
try {
process = Runtime.getRuntime().exec("su -c " + cmd);
Expand All @@ -26,27 +25,12 @@ public static String execShell(String cmd) {
return result.toString();
}

public static void copyConfigFile(boolean is){
String user_path = Environment.getDataDirectory() + "/data/" + BuildConfig.APPLICATION_ID + "/shared_prefs/";
public static void copyConfigFile(String content){
String sys_path = "/data/system/shared_prefs/";
String file = "config.xml";
String log = "";
if (is) {
log += execShell("mkdir " + user_path);
log += execShell(String.format("\\cp %s%s %s%s", sys_path, file, user_path, file));
file = String.format("%s%s", user_path,file);
}else {
log += execShell("mkdir " + sys_path);
log += execShell(String.format("\\cp %s%s %s%s", user_path, file, sys_path, file));
file = String.format("%s%s", sys_path, file);
}
log += execShell(String.format("chmod 644 %s", file));
String data = String.format("<?xml version='1.0' encoding='utf-8' standalone='yes' ?>" +
"<map><string name=\\\"content\\\">%s</string></map>", content);
String log = execShell("mkdir " + sys_path);
log += execShell("echo \"" + data + "\" > " + sys_path + "config.xml");
Log.d(TAG, "copyConfigFile: " + log);
}

public static void delete(){
String log = execShell(String.format("rm -f %s/data/%s/shared_prefs/config.xml",
Environment.getDataDirectory(),BuildConfig.APPLICATION_ID));
Log.d(TAG, "delete: " + log);
}
}
48 changes: 30 additions & 18 deletions app/src/main/res/layout/main_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,6 @@
android:background="@color/main_content"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical">
<!-- <androidx.appcompat.widget.Toolbar-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="?attr/actionBarSize"-->
<!-- android:background="#ff36A0F4"-->
<!-- app:title="@string/app_name"-->
<!-- app:titleTextColor="@color/white">-->
<!-- </androidx.appcompat.widget.Toolbar>-->
<androidx.appcompat.widget.Toolbar
android:id="@+id/main_toolbar"
android:layout_width="match_parent"
Expand All @@ -29,7 +22,7 @@
android:orientation="vertical"
android:paddingStart="10dp"
android:layout_height="match_parent"
tools:ignore="RtlSymmetry">
tools:ignore="RtlSymmetry,UselessParent">
<TextView
android:textColor="@color/toolbar_title"
android:text="@string/app_name"
Expand All @@ -38,26 +31,44 @@
android:textStyle="bold"
android:layout_width="match_parent"
android:layout_height="30dp"/>
<TextView
android:layout_marginTop="2dp"
android:id="@+id/version_name"
android:text="当前版本:ver.11.45.14"
android:textSize="12sp"

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"/>
android:layout_height="match_parent"
android:orientation="horizontal">

<TextView
android:id="@+id/version_name"
android:layout_width="200dp"
android:gravity="start|center"
android:layout_height="match_parent"
android:layout_marginTop="2dp"
android:text="@string/this_version"
android:textSize="12sp" />

<TextView
android:id="@+id/app_list_name"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="(哼啊,啊啊啊....)"
android:layout_marginTop="15dp"
android:paddingEnd="20dp"
android:gravity="end|center"
android:textSize="9sp"
tools:ignore="SmallSp" />
</LinearLayout>
</LinearLayout>

</LinearLayout>
<ImageButton
android:layout_width="30dp"
android:layout_height="match_parent"
android:layout_gravity="end"
android:layout_marginEnd="10dp"
android:layout_marginEnd="15dp"
android:background="#00000000"
android:onClick="onSwitchListView"
android:src="@drawable/ic_baseline_swap_horiz_24"
tools:ignore="ContentDescription"/>

<ImageButton
android:id="@+id/btn_insearch"
android:layout_width="30dp"
Expand All @@ -71,14 +82,15 @@
</androidx.appcompat.widget.Toolbar>
<EditText
android:layout_margin="15dp"
android:hint="输入内容搜索...."
android:hint="@string/search_text"
android:id="@+id/edit_insearch"
android:singleLine="true"
android:textSize="15sp"
android:visibility="gone"
android:layout_width="match_parent"
android:background="@drawable/edit_text_background"
android:layout_height="50dp"/>
android:layout_height="50dp"
tools:ignore="Autofill,TextFields" />

<ListView
android:id="@+id/app_items"
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
<resources>
<string name="app_name">设置应用全屏</string>
<string name="xposeddescription">将应用突破次元壁,覆盖异形屏幕限制全面显示_(:з」∠)_</string>
<string name="this_version">当前版本:-> ver.11.45.14</string>
<string name="list_system">系统应用</string>
<string name="list_user">用户应用</string>
<string name="show_message">保存成功,重启系统后生效!</string>
<string name="search_text">搜索…</string>
</resources>
5 changes: 5 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
<resources>
<string name="app_name">SetAppFull</string>
<string name="xposeddescription">set app to full screen run.</string>
<string name="this_version">VersionName:-> ver.11.45.14</string>
<string name="list_system">SystemApp</string>
<string name="list_user">UserApp</string>
<string name="show_message">Saved successfully, Effective after system restart!</string>
<string name="search_text">Search…</string>
<string-array name="xposedscope">
<item>android</item>
</string-array>
Expand Down

0 comments on commit 5ffb937

Please sign in to comment.