Skip to content

Commit

Permalink
feat:导入导出crt&key文件
Browse files Browse the repository at this point in the history
  • Loading branch information
Axixi2233 committed Jul 25, 2024
1 parent 73b1372 commit f793e06
Show file tree
Hide file tree
Showing 2 changed files with 139 additions and 12 deletions.
97 changes: 97 additions & 0 deletions app/src/main/java/com/limelight/preferences/StreamSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,28 @@ public boolean onPreferenceClick(Preference preference) {
}
});

findPreference("import_https_data_crt_file").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("*/*");
startActivityForResult(intent, READ_DATA_CRT_REQUEST_CODE);
return false;
}
});

findPreference("import_https_data_key_file").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("*/*");
startActivityForResult(intent, READ_DATA_KEY_REQUEST_CODE);
return false;
}
});

findPreference("import_special_button_file").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
Expand Down Expand Up @@ -776,6 +798,44 @@ public boolean onPreferenceClick(Preference preference) {
}
});

findPreference("export_https_data_crt_file").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
File dataFile=new File(getActivity().getFilesDir().getAbsolutePath()+ File.separator + "client.crt");
if(!dataFile.exists()){
return false;
}
Uri uri;
Intent intent = new Intent(Intent.ACTION_SEND);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
String authority= BuildConfig.APPLICATION_ID+".fileprovider";
uri= FileProvider.getUriForFile(getActivity(),authority,dataFile);
intent.putExtra(Intent.EXTRA_STREAM, uri);
intent.setType("*/*");
startActivity(Intent.createChooser(intent,"保存数据文件"));
return false;
}
});

findPreference("export_https_data_key_file").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
File dataFile=new File(getActivity().getFilesDir().getAbsolutePath()+ File.separator + "client.key");
if(!dataFile.exists()){
return false;
}
Uri uri;
Intent intent = new Intent(Intent.ACTION_SEND);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
String authority= BuildConfig.APPLICATION_ID+".fileprovider";
uri= FileProvider.getUriForFile(getActivity(),authority,dataFile);
intent.putExtra(Intent.EXTRA_STREAM, uri);
intent.setType("*/*");
startActivity(Intent.createChooser(intent,"保存数据文件"));
return false;
}
});


findPreference("pref_axi_test").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
Expand Down Expand Up @@ -841,6 +901,10 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {

int READ_DATABASE_REQUEST_CODE=1003;

int READ_DATA_CRT_REQUEST_CODE=1004;

int READ_DATA_KEY_REQUEST_CODE=1005;

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Expand Down Expand Up @@ -914,6 +978,39 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
}
return;
}

if (requestCode == READ_DATA_CRT_REQUEST_CODE && resultCode == Activity.RESULT_OK &&data.getData()!=null) {
try {
Uri uri = data.getData();
File dataBaseFile= null;
String displayName = "client.crt";
dataBaseFile=new File(getActivity().getFilesDir().getAbsolutePath(), displayName);
FileUriUtils.copyUriToInternalStorage(getActivity(),uri,dataBaseFile);
Toast.makeText(getActivity(),"导入成功!",Toast.LENGTH_SHORT).show();
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(getActivity(),"出错啦~"+e.getMessage(),Toast.LENGTH_SHORT).show();
}
return;

}

if (requestCode == READ_DATA_KEY_REQUEST_CODE && resultCode == Activity.RESULT_OK &&data.getData()!=null) {
try {
Uri uri = data.getData();
File dataBaseFile= null;
String displayName = "client.key";
dataBaseFile=new File(getActivity().getFilesDir().getAbsolutePath(), displayName);
FileUriUtils.copyUriToInternalStorage(getActivity(),uri,dataBaseFile);
Toast.makeText(getActivity(),"导入成功!",Toast.LENGTH_SHORT).show();
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(getActivity(),"出错啦~"+e.getMessage(),Toast.LENGTH_SHORT).show();
}
return;

}

}


Expand Down
54 changes: 42 additions & 12 deletions app/src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -515,18 +515,6 @@
android:summary="每次都会覆盖原来的,请注意备份。"
/>

<Preference
android:key="export_computers_data_file"
android:title="导出配对的电脑数据库文件"
android:summary="导出一个db格式的sqlite数据库文件"
/>

<Preference
android:key="import_computers_data_file"
android:title="导入配对的电脑数据库文件"
android:summary="选择db数据库文件,会覆盖更新原有的电脑列表,需要重新打开APP生效。"
/>

<com.limelight.preferences.WebLauncherPreference
android:title="软件版本更新"
android:summary="跳转到github获取releases"
Expand Down Expand Up @@ -598,6 +586,48 @@
/>

</PreferenceCategory>

<PreferenceCategory android:title="备份恢复数据【注意数据安全】"
android:key="category_axixi_back_data">

<Preference
android:key="export_computers_data_file"
android:title="导出配对的电脑数据库文件"
android:summary="导出一个db格式的sqlite数据库文件"
/>

<Preference
android:key="export_https_data_crt_file"
android:title="导出网络请求的证书文件"
android:summary="导出一个crt格式的证书文件"
/>

<Preference
android:key="export_https_data_key_file"
android:title="导出网络请求的key文件"
android:summary="导出一个key格式的验证文件"
/>

<Preference
android:key="import_computers_data_file"
android:title="导入配对的电脑数据库文件"
android:summary="选择db数据库文件,会覆盖更新原有的电脑列表,需要重新打开APP生效。"
/>

<Preference
android:key="import_https_data_crt_file"
android:title="导入网络请求的证书文件"
android:summary="导入一个crt格式的证书文件"
/>

<Preference
android:key="import_https_data_key_file"
android:title="导入网络请求的key文件"
android:summary="导入一个key格式的验证文件"
/>

</PreferenceCategory>

<!--PreferenceCategory android:title="@string/category_help"
android:key="category_help">
<com.limelight.preferences.WebLauncherPreference
Expand Down

0 comments on commit f793e06

Please sign in to comment.