-
Notifications
You must be signed in to change notification settings - Fork 282
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from so898/Pre-App
Pre-App Support 感谢 👍
- Loading branch information
Showing
15 changed files
with
553 additions
and
25 deletions.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.vm.shadowsocks.core; | ||
|
||
import android.graphics.drawable.Drawable; | ||
|
||
public class AppInfo { | ||
private Drawable appIcon; | ||
private String appLabel; | ||
private String pkgName; | ||
|
||
public AppInfo() { | ||
} | ||
|
||
public Drawable getAppIcon() { | ||
return this.appIcon; | ||
} | ||
|
||
public String getAppLabel() { | ||
return this.appLabel; | ||
} | ||
|
||
public String getPkgName() { | ||
return this.pkgName; | ||
} | ||
|
||
public void setAppIcon(Drawable var1) { | ||
this.appIcon = var1; | ||
} | ||
|
||
public void setAppLabel(String var1) { | ||
this.appLabel = var1; | ||
} | ||
|
||
public void setPkgName(String var1) { | ||
this.pkgName = var1; | ||
} | ||
} |
102 changes: 102 additions & 0 deletions
102
app/src/main/java/com/vm/shadowsocks/core/AppProxyManager.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,102 @@ | ||
package com.vm.shadowsocks.core; | ||
|
||
import android.content.Context; | ||
import android.content.SharedPreferences; | ||
import android.graphics.drawable.Drawable; | ||
import android.os.Build; | ||
|
||
import org.json.JSONArray; | ||
import org.json.JSONObject; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import static android.content.Context.MODE_PRIVATE; | ||
|
||
public class AppProxyManager { | ||
public static boolean isLollipopOrAbove = Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP; | ||
|
||
public static AppProxyManager Instance; | ||
private static final String PROXY_APPS = "PROXY_APPS"; | ||
private Context mContext; | ||
|
||
public List<AppInfo> mlistAppInfo = new ArrayList<AppInfo>(); | ||
public List<AppInfo> proxyAppInfo = new ArrayList<AppInfo>(); | ||
|
||
public AppProxyManager(Context context){ | ||
this.mContext = context; | ||
Instance = this; | ||
readProxyAppsList(); | ||
} | ||
|
||
public void removeProxyApp(String pkg){ | ||
for (AppInfo app : this.proxyAppInfo) { | ||
if (app.getPkgName().equals(pkg)){ | ||
proxyAppInfo.remove(app); | ||
break; | ||
} | ||
} | ||
writeProxyAppsList(); | ||
} | ||
|
||
public void addProxyApp(String pkg){ | ||
for (AppInfo app : this.mlistAppInfo) { | ||
if (app.getPkgName().equals(pkg)){ | ||
proxyAppInfo.add(app); | ||
break; | ||
} | ||
} | ||
writeProxyAppsList(); | ||
} | ||
|
||
public boolean isAppProxy(String pkg){ | ||
for (AppInfo app : this.proxyAppInfo) { | ||
if (app.getPkgName().equals(pkg)){ | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
private void readProxyAppsList() { | ||
SharedPreferences preferences = mContext.getSharedPreferences("shadowsocksProxyUrl", MODE_PRIVATE); | ||
String tmpString = preferences.getString(PROXY_APPS, ""); | ||
try { | ||
if (proxyAppInfo != null){ | ||
proxyAppInfo.clear(); | ||
} | ||
if (tmpString.isEmpty()){ | ||
return; | ||
} | ||
JSONArray jsonArray = new JSONArray(tmpString); | ||
for (int i = 0; i < jsonArray.length() ; i++){ | ||
JSONObject object = jsonArray.getJSONObject(i); | ||
AppInfo appInfo = new AppInfo(); | ||
appInfo.setAppLabel(object.getString("label")); | ||
appInfo.setPkgName(object.getString("pkg")); | ||
proxyAppInfo.add(appInfo); | ||
} | ||
} catch (Exception e){ | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
private void writeProxyAppsList() { | ||
SharedPreferences preferences = mContext.getSharedPreferences("shadowsocksProxyUrl", MODE_PRIVATE); | ||
try { | ||
JSONArray jsonArray = new JSONArray(); | ||
for (int i = 0; i < proxyAppInfo.size() ; i++){ | ||
JSONObject object = new JSONObject(); | ||
AppInfo appInfo = proxyAppInfo.get(i); | ||
object.put("label", appInfo.getAppLabel()); | ||
object.put("pkg", appInfo.getPkgName()); | ||
jsonArray.put(object); | ||
} | ||
SharedPreferences.Editor editor = preferences.edit(); | ||
editor.putString(PROXY_APPS, jsonArray.toString()); | ||
editor.apply(); | ||
} catch (Exception e){ | ||
e.printStackTrace(); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.