-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Enable/Disable button; Toast on webconsole if not enabled; i2pdpath;on boot autostart;getDataPath/iniEditor preinit for setting * settings autostart switch Co-authored-by: R4SAS <r4sas@users.noreply.github.com>
- Loading branch information
1 parent
2e6a4c7
commit 17148b5
Showing
9 changed files
with
223 additions
and
9 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
108 changes: 108 additions & 0 deletions
108
app/src/main/java/org/purplei2p/i2pd/SettingsActivity.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,108 @@ | ||
package org.purplei2p.i2pd; | ||
|
||
import android.app.Activity; | ||
import android.content.ComponentName; | ||
import android.content.Intent; | ||
import android.content.pm.PackageManager; | ||
import android.content.pm.ResolveInfo; | ||
import android.net.Uri; | ||
import android.os.Build; | ||
import android.os.Bundle; | ||
import android.provider.Settings; | ||
import android.util.Log; | ||
import android.view.View; | ||
import android.widget.CompoundButton; | ||
import android.widget.Switch; | ||
import java.io.File; | ||
import java.util.List; | ||
|
||
|
||
import org.purplei2p.i2pd.iniedotr.IniEditor; | ||
public class SettingsActivity extends Activity { | ||
protected IniEditor iniedit = new IniEditor(); | ||
private String dataDir = DaemonWrapper.getDataDir();//for inieditor | ||
private String TAG = "i2pdSrvcSettings"; | ||
private File cacheDir; | ||
public static String onBootFileName="/onBoot"; // just file, empty, if exist the do autostart, if not then no. | ||
|
||
//https://gist.github.com/chandruark/3165a5ee3452f2b9ec7736cf1b4c5ea6 | ||
private void addAutoStartupswitch() { | ||
|
||
try { | ||
Intent intent = new Intent(); | ||
String manufacturer = android.os.Build.MANUFACTURER .toLowerCase(); | ||
|
||
switch (manufacturer){ | ||
case "xiaomi": | ||
intent.setComponent(new ComponentName("com.miui.securitycenter", "com.miui.permcenter.autostart.AutoStartManagementActivity")); | ||
break; | ||
case "oppo": | ||
intent.setComponent(new ComponentName("com.coloros.safecenter", "com.coloros.safecenter.permission.startup.StartupAppListActivity")); | ||
break; | ||
case "vivo": | ||
intent.setComponent(new ComponentName("com.vivo.permissionmanager", "com.vivo.permissionmanager.activity.BgStartUpManagerActivity")); | ||
break; | ||
case "Letv": | ||
intent.setComponent(new ComponentName("com.letv.android.letvsafe", "com.letv.android.letvsafe.AutobootManageActivity")); | ||
break; | ||
case "Honor": | ||
intent.setComponent(new ComponentName("com.huawei.systemmanager", "com.huawei.systemmanager.optimize.process.ProtectActivity")); | ||
break; | ||
case "oneplus": | ||
intent.setComponent(new ComponentName("com.oneplus.security", "com.oneplus.security.chainlaunch.view.ChainLaunchAppListActivity")); | ||
break; | ||
} | ||
|
||
List<ResolveInfo> list = getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); | ||
if (list.size() > 0) { | ||
startActivity(intent); | ||
} | ||
} catch (Exception e) { | ||
Log.e("exceptionAutostarti2pd" , String.valueOf(e)); | ||
} | ||
|
||
} | ||
//@Override | ||
private void requestPermission() { | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { | ||
if (!Settings.canDrawOverlays(this)) { | ||
Intent intent = new Intent( | ||
Settings.ACTION_MANAGE_OVERLAY_PERMISSION, | ||
Uri.parse("package:" + getPackageName()) | ||
); | ||
startActivityForResult(intent, 232); | ||
} else { | ||
//Permission Granted-System will work | ||
} | ||
} | ||
} | ||
public void onCreate(Bundle savedInstanceState) { | ||
Log.i(TAG, "onCreate"); | ||
super.onCreate(savedInstanceState); | ||
cacheDir = getApplicationContext().getCacheDir(); | ||
setContentView(R.layout.activity_settings); | ||
Switch autostart_switch = findViewById(R.id.autostart_enable); | ||
File onBoot= new File( cacheDir.getAbsolutePath()+onBootFileName); | ||
autostart_switch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { | ||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { | ||
// do something, the isChecked will be | ||
// true if the switch is in the On position | ||
if(isChecked){ | ||
if( !onBoot.exists() ) { | ||
requestPermission(); | ||
addAutoStartupswitch(); | ||
try { | ||
if( !onBoot.createNewFile()) Log.d(TAG, "Cant create new wile on: "+onBoot.getAbsolutePath()); | ||
} catch (Exception e) { | ||
Log.d(TAG, "error: " + e.toString()); | ||
} | ||
} | ||
}else{ | ||
if( onBoot.exists() ) | ||
onBoot.delete(); | ||
} | ||
} | ||
}); | ||
if(onBoot.exists()) autostart_switch.setChecked(true); | ||
} | ||
} |
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,62 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:id="@+id/settings_layout" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:orientation="vertical"> | ||
|
||
<TextView | ||
android:id="@+id/settings_section0" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:autoText="true" | ||
android:clickable="false" | ||
android:cursorVisible="false" | ||
android:text="@string/settings_section0" | ||
android:textColor="#282528" | ||
android:textStyle="bold|italic" | ||
android:verticalScrollbarPosition="defaultPosition" /> | ||
|
||
<Switch | ||
android:id="@+id/autostart_enable" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:text="@string/autostart_enabled" /> | ||
|
||
<View | ||
android:id="@+id/divider" | ||
android:layout_width="match_parent" | ||
android:layout_height="1dp" | ||
android:background="?android:attr/listDivider" /> | ||
<!-- | ||
<TextView | ||
android:id="@+id/settings_section2" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:autoText="true" | ||
android:clickable="false" | ||
android:cursorVisible="false" | ||
android:text="@string/settings_section_tunnels" | ||
android:textColor="#282528" | ||
android:textStyle="bold|italic" | ||
android:verticalScrollbarPosition="defaultPosition" /> | ||
<LinearLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:orientation="horizontal"> | ||
<TextView | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_weight="1" | ||
android:text="@string/add_tunnel" /> | ||
<Button | ||
android:id="@+id/add_tunnel_button" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="@string/add_tunnel_button" /> | ||
</LinearLayout> | ||
--> | ||
</LinearLayout> |
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